} /* XXX The generator botches this one. Here's a quick hack to fix it. */ /* XXX The generator botches this one. Here's a quick hack to fix it. */ static PyObject *gl_getmatrix(PyObject *self, PyObject *args){ Matrix arg1; PyObject *v, *w; int i, j; getmatrix( arg1 ); v = PyList_New(16); if (v == NULL) { return PyErr_NoMemory(); } for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) { w = mknewfloatobject(arg1[i][j]); if (w == NULL) { Py_DECREF(v); return NULL; } PyList_SetItem(v, i*4+j, w); } return v;} /* Here's an alternate version that returns a 4x4 matrix instead of a vector. Unfortunately it is incompatible with loadmatrix and multmatrix... */ static PyObject *gl_altgetmatrix(PyObject *self, PyObject *args){ Matrix arg1; PyObject *v, *w; int i, j; getmatrix( arg1 ); v = PyList_New(4); if (v == NULL) { return NULL; } for (i = 0; i < 4; i++) { w = PyList_New(4); if (w == NULL) { Py_DECREF(v); return NULL; } PyList_SetItem(v, i, w); } for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { w = mknewfloatobject(arg1[i][j]); if (w == NULL) { Py_DECREF(v); return NULL; } PyList_SetItem(PyList_GetItem(v, i), j, w); } } return v;} static PyObject *gl_lrectwrite(PyObject *self, PyObject *args){ short x1 ; short y1 ; short x2 ; short y2 ; string parray ; PyObject *s;#if 0 int pixcount;#endif if (!PyArg_GetShort(args, 5, 0, &x1)) return NULL; if (!PyArg_GetShort(args, 5, 1, &y1)) return NULL; if (!PyArg_GetShort(args, 5, 2, &x2)) return NULL; if (!PyArg_GetShort(args, 5, 3, &y2)) return NULL; if (!PyArg_GetString(args, 5, 4, &parray)) return NULL; if (!PyArg_GetObject(args, 5, 4, &s)) return NULL;#if 0/* Don't check this, it breaks experiments with pixmode(PM_SIZE, ...) */ pixcount = (long)(x2+1-x1) * (long)(y2+1-y1); if (!PyString_Check(s) || PyString_Size(s) != pixcount*sizeof(long)) { PyErr_SetString(PyExc_RuntimeError, "string arg to lrectwrite has wrong size"); return NULL; }#endif lrectwrite( x1 , y1 , x2 , y2 , (unsigned long *) parray ); Py_INCREF(Py_None); return Py_None;} static PyObject *gl_lrectread(PyObject *self, PyObject *args){ short x1 ; short y1 ; short x2 ; short y2 ; PyObject *parray; int pixcount; if (!PyArg_GetShort(args, 4, 0, &x1)) return NULL; if (!PyArg_GetShort(args, 4, 1, &y1)) return NULL; if (!PyArg_GetShort(args, 4, 2, &x2)) return NULL; if (!PyArg_GetShort(args, 4, 3, &y2)) return NULL; pixcount = (long)(x2+1-x1) * (long)(y2+1-y1); parray = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long)); if (parray == NULL) return NULL; /* No memory */ lrectread(x1, y1, x2, y2, (unsigned long *) PyString_AsString(parray)); return parray;} static PyObject *gl_readdisplay(PyObject *self, PyObject *args){ short x1, y1, x2, y2; unsigned long *parray, hints; long size, size_ret; PyObject *rv; if ( !PyArg_Parse(args, "hhhhl", &x1, &y1, &x2, &y2, &hints) ) return 0; size = (long)(x2+1-x1) * (long)(y2+1-y1); rv = PyString_FromStringAndSize((char *)NULL, size*sizeof(long)); if ( rv == NULL ) return NULL; parray = (unsigned long *)PyString_AsString(rv); size_ret = readdisplay(x1, y1, x2, y2, parray, hints); if ( size_ret != size ) { printf("gl_readdisplay: got %ld pixels, expected %ld\n", size_ret, size); PyErr_SetString(PyExc_RuntimeError, "readdisplay returned unexpected length"); return NULL; } return rv;} /* Desperately needed, here are tools to compress and decompress the data manipulated by lrectread/lrectwrite. gl.packrect(width, height, packfactor, bigdata) --> smalldata makes 'bigdata' 4*(packfactor**2) times smaller by: - turning it into B/W (a factor 4) - replacing squares of size pacfactor by one representative gl.unpackrect(width, height, packfactor, smalldata) --> bigdata is the inverse; the numeric arguments must be *the same*. Both work best if width and height are multiples of packfactor (in fact unpackrect will leave garbage bytes).*/ static PyObject *gl_packrect(PyObject *self, PyObject *args){ long width, height, packfactor; char *s; PyObject *unpacked, *packed; int pixcount, packedcount, x, y, r, g, b; unsigned long pixel; unsigned char *p; unsigned long *parray; if (!PyArg_GetLong(args, 4, 0, &width)) return NULL; if (!PyArg_GetLong(args, 4, 1, &height)) return NULL; if (!PyArg_GetLong(args, 4, 2, &packfactor)) return NULL; if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */ return NULL; if (!PyArg_GetObject(args, 4, 3, &unpacked)) return NULL; if (width <= 0 || height <= 0 || packfactor <= 0) { PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0"); return NULL; } pixcount = width*height; packedcount = ((width+packfactor-1)/packfactor) * ((height+packfactor-1)/packfactor); if (PyString_Size(unpacked) != pixcount*sizeof(long)) { PyErr_SetString(PyExc_RuntimeError, "string arg to packrect has wrong size"); return NULL; } packed = PyString_FromStringAndSize((char *)NULL, packedcount); if (packed == NULL) return NULL; parray = (unsigned long *) PyString_AsString(unpacked); p = (unsigned char *) PyString_AsString(packed); for (y = 0; y < height; y += packfactor, parray += packfactor*width) { for (x = 0; x < width; x += packfactor) { pixel = parray[x]; r = pixel & 0xff; g = (pixel >> 8) & 0xff; b = (pixel >> 16) & 0xff; *p++ = (30*r+59*g+11*b) / 100; } } return packed;} static unsigned long unpacktab[256];static int unpacktab_inited = 0; static PyObject *gl_unpackrect(PyObject *self, PyObject *args){ long width, height, packfactor; char *s; PyObject *unpacked, *packed; int pixcount, packedcount; register unsigned char *p; register unsigned long *parray; if (!unpacktab_inited) { register int white; for (white = 256; --white >= 0; ) unpacktab[white] = white * 0x010101L; unpacktab_inited++; } if (!PyArg_GetLong(args, 4, 0, &width)) return NULL; if (!PyArg_GetLong(args, 4, 1, &height)) return NULL; if (!PyArg_GetLong(args, 4, 2, &packfactor)) return NULL; if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */ return NULL; if (!PyArg_GetObject(args, 4, 3, &packed)) return NULL; if (width <= 0 || height <= 0 || packfactor <= 0) { PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0"); return NULL; } pixcount = width*height; packedcount = ((width+packfactor-1)/packfactor) * ((height+packfactor-1)/packfactor); if (PyString_Size(packed) != packedcount) { PyErr_SetString(PyExc_RuntimeError, "string arg to unpackrect has wrong size"); return NULL; } unpacked = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long)); if (unpacked == NULL) return NULL; parray = (unsigned long *) PyString_AsString(unpacked); p = (unsigned char *) PyString_AsString(packed); if (packfactor == 1 && width*height > 0) { /* Just expand bytes to longs */ register int x = width * height; do { *parray++ = unpacktab[*p++]; } while (--x >= 0); } else { register int y; for (y = 0; y < height-packfactor+1; y += packfactor, parray += packfactor*width) { register int x; for (x = 0; x < width-packfactor+1; x += packfactor) { register unsigned long pixel = unpacktab[*p++]; register int i; for (i = packfactor*width; (i-=width) >= 0;) { register int j; for (j = packfactor; --j >= 0; ) parray[i+x+j] = pixel; } } } } return unpacked;} static PyObject *gl_gversion(PyObject *self, PyObject *args){ char buf[20]; gversion(buf); return PyString_FromString(buf);} /* void clear - Manual because of clash with termcap */static PyObject *gl_clear(PyObject *self, PyObject *args){ __GLclear( ); Py_INCREF(Py_None); return Py_None;} /* End of manually written stubs */ /* long getshade */ static PyObject *gl_getshade(PyObject *self, PyObject *args){ long retval; retval = getshade( ); return mknewlongobject(retval);} /* void devport short s long s */ static PyObject *gl_devport(PyObject *self, PyObject *args){ short arg1 ; long arg2 ; if (!getishortarg(args, 2, 0, &arg1)) return NULL; if (!getilongarg(args, 2, 1, &arg2)) return NULL; devport( arg1 , arg2 ); Py_INCREF(Py_None); return Py_None;} /* void rdr2i long s long s */ static PyObject *gl_rdr2i(PyObject *self, PyObject *args){ long arg1 ; long arg2 ; if (!getilongarg(args, 2, 0, &arg1)) return NULL; if (!getilongarg(args, 2, 1, &arg2)) return NULL; rdr2i( arg1 , arg2 ); Py_INCREF(Py_None); return Py_None;} /* void rectfs short s short s short s short s */ static PyObject *gl_rectfs(PyObject *self, PyObject *args){ short arg1 ; short arg2 ; short arg3 ; short arg4 ; if (!getishortarg(args, 4, 0, &arg1)) return NULL; if (!getishortarg(args, 4, 1, &arg2)) return NULL; if (!getishortarg(args, 4, 2, &arg3)) return NULL; if (!getishortarg(args, 4, 3, &arg4)) return NULL; rectfs( arg1 , arg2 , arg3 , arg4 ); Py_INCREF(Py_None); return Py_None;} /* void rects short s short s short s short s */ static PyObject *gl_rects(PyObject *self, PyObject *args){ short arg1 ; short arg2 ; short arg3 ; short arg4 ; if (!getishortarg(args, 4, 0, &arg1)) return NULL; if (!getishortarg(args, 4, 1, &arg2)) return NULL; if (!getishortarg(args, 4, 2, &arg3)) return NULL; if (!getishortarg(args, 4, 3, &arg4)) return NULL; rects( arg1 , arg2 , arg3 , arg4 ); Py_INCREF(Py_None); return Py_None;} /* void rmv2i long s long s */ static PyObject *gl_rmv2i(PyObject *self, PyObject *args){ long arg1 ; long arg2 ; if (!getilongarg(args, 2, 0, &arg1)) return NULL; if (!getilongarg(args, 2, 1, &arg2)) return NULL; rmv2i( arg1 , arg2 ); Py_INCREF(Py_None); return Py_None;} /* void noport */ static PyObject *gl_noport(PyObject *self, PyObject *args){ noport( ); Py_INCREF(Py_None); return Py_None;} /* void popviewport */ static PyObject *gl_popviewport(PyObject *self, PyObject *args){ popviewport( ); Py_INCREF(Py_None); return Py_None;} /* void clearhitcode */ static PyObject *gl_clearhitcode(PyObject *self, PyObject *args){ clearhitcode( ); Py_INCREF(Py_None); return Py_None;} /* void closeobj */ static PyObject *gl_closeobj(PyObject *self, PyObject *args){ closeobj( ); Py_INCREF(Py_None); return Py_None;} /* void cursoff */ static PyObject *gl_cursoff(PyObject *self, PyObject *args){ cursoff( ); Py_INCREF(Py_None); return Py_None;} /* void curson */ static PyObject *gl_curson(PyObject *self, PyObject *args){ curson( ); Py_INCREF(Py_None); return Py_None;} /* void doublebuffer */ static PyObject *gl_doublebuffer(PyObject *self, PyObject *args){ doublebuffer( ); Py_INCREF(Py_None); return Py_None;} /* void finish */ static PyObject *gl_finish(PyObject *self, PyObject *args){ finish( ); Py_INCREF(Py_None); return Py_None;} /* void gconfig */Lines 501–1000 of 7628. Previous lines Load more
} /* XXX The generator botches this one. Here's a quick hack to fix it. */ /* XXX The generator botches this one. Here's a quick hack to fix it. */ static PyObject * gl_getmatrix(PyObject *self, PyObject *args) { Matrix arg1; PyObject *v, *w; int i, j; getmatrix( arg1 ); v = PyList_New(16); if (v == NULL) { return PyErr_NoMemory(); } for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) { w = mknewfloatobject(arg1[i][j]); if (w == NULL) { Py_DECREF(v); return NULL; } PyList_SetItem(v, i*4+j, w); } return v; } /* Here's an alternate version that returns a 4x4 matrix instead of a vector. Unfortunately it is incompatible with loadmatrix and multmatrix... */ static PyObject * gl_altgetmatrix(PyObject *self, PyObject *args) { Matrix arg1; PyObject *v, *w; int i, j; getmatrix( arg1 ); v = PyList_New(4); if (v == NULL) { return NULL; } for (i = 0; i < 4; i++) { w = PyList_New(4); if (w == NULL) { Py_DECREF(v); return NULL; } PyList_SetItem(v, i, w); } for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { w = mknewfloatobject(arg1[i][j]); if (w == NULL) { Py_DECREF(v); return NULL; } PyList_SetItem(PyList_GetItem(v, i), j, w); } } return v; } static PyObject * gl_lrectwrite(PyObject *self, PyObject *args) { short x1 ; short y1 ; short x2 ; short y2 ; string parray ; PyObject *s; #if 0 int pixcount; #endif if (!PyArg_GetShort(args, 5, 0, &x1)) return NULL; if (!PyArg_GetShort(args, 5, 1, &y1)) return NULL; if (!PyArg_GetShort(args, 5, 2, &x2)) return NULL; if (!PyArg_GetShort(args, 5, 3, &y2)) return NULL; if (!PyArg_GetString(args, 5, 4, &parray)) return NULL; if (!PyArg_GetObject(args, 5, 4, &s)) return NULL; #if 0 /* Don't check this, it breaks experiments with pixmode(PM_SIZE, ...) */ pixcount = (long)(x2+1-x1) * (long)(y2+1-y1); if (!PyString_Check(s) || PyString_Size(s) != pixcount*sizeof(long)) { PyErr_SetString(PyExc_RuntimeError, "string arg to lrectwrite has wrong size"); return NULL; } #endif lrectwrite( x1 , y1 , x2 , y2 , (unsigned long *) parray ); Py_INCREF(Py_None); return Py_None; } static PyObject * gl_lrectread(PyObject *self, PyObject *args) { short x1 ; short y1 ; short x2 ; short y2 ; PyObject *parray; int pixcount; if (!PyArg_GetShort(args, 4, 0, &x1)) return NULL; if (!PyArg_GetShort(args, 4, 1, &y1)) return NULL; if (!PyArg_GetShort(args, 4, 2, &x2)) return NULL; if (!PyArg_GetShort(args, 4, 3, &y2)) return NULL; pixcount = (long)(x2+1-x1) * (long)(y2+1-y1); parray = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long)); if (parray == NULL) return NULL; /* No memory */ lrectread(x1, y1, x2, y2, (unsigned long *) PyString_AsString(parray)); return parray; } static PyObject * gl_readdisplay(PyObject *self, PyObject *args) { short x1, y1, x2, y2; unsigned long *parray, hints; long size, size_ret; PyObject *rv; if ( !PyArg_Parse(args, "hhhhl", &x1, &y1, &x2, &y2, &hints) ) return 0; size = (long)(x2+1-x1) * (long)(y2+1-y1); rv = PyString_FromStringAndSize((char *)NULL, size*sizeof(long)); if ( rv == NULL ) return NULL; parray = (unsigned long *)PyString_AsString(rv); size_ret = readdisplay(x1, y1, x2, y2, parray, hints); if ( size_ret != size ) { printf("gl_readdisplay: got %ld pixels, expected %ld\n", size_ret, size); PyErr_SetString(PyExc_RuntimeError, "readdisplay returned unexpected length"); return NULL; } return rv; } /* Desperately needed, here are tools to compress and decompress the data manipulated by lrectread/lrectwrite. gl.packrect(width, height, packfactor, bigdata) --> smalldata makes 'bigdata' 4*(packfactor**2) times smaller by: - turning it into B/W (a factor 4) - replacing squares of size pacfactor by one representative gl.unpackrect(width, height, packfactor, smalldata) --> bigdata is the inverse; the numeric arguments must be *the same*. Both work best if width and height are multiples of packfactor (in fact unpackrect will leave garbage bytes). */ static PyObject * gl_packrect(PyObject *self, PyObject *args) { long width, height, packfactor; char *s; PyObject *unpacked, *packed; int pixcount, packedcount, x, y, r, g, b; unsigned long pixel; unsigned char *p; unsigned long *parray; if (!PyArg_GetLong(args, 4, 0, &width)) return NULL; if (!PyArg_GetLong(args, 4, 1, &height)) return NULL; if (!PyArg_GetLong(args, 4, 2, &packfactor)) return NULL; if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */ return NULL; if (!PyArg_GetObject(args, 4, 3, &unpacked)) return NULL; if (width <= 0 || height <= 0 || packfactor <= 0) { PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0"); return NULL; } pixcount = width*height; packedcount = ((width+packfactor-1)/packfactor) * ((height+packfactor-1)/packfactor); if (PyString_Size(unpacked) != pixcount*sizeof(long)) { PyErr_SetString(PyExc_RuntimeError, "string arg to packrect has wrong size"); return NULL; } packed = PyString_FromStringAndSize((char *)NULL, packedcount); if (packed == NULL) return NULL; parray = (unsigned long *) PyString_AsString(unpacked); p = (unsigned char *) PyString_AsString(packed); for (y = 0; y < height; y += packfactor, parray += packfactor*width) { for (x = 0; x < width; x += packfactor) { pixel = parray[x]; r = pixel & 0xff; g = (pixel >> 8) & 0xff; b = (pixel >> 16) & 0xff; *p++ = (30*r+59*g+11*b) / 100; } } return packed; } static unsigned long unpacktab[256]; static int unpacktab_inited = 0; static PyObject * gl_unpackrect(PyObject *self, PyObject *args) { long width, height, packfactor; char *s; PyObject *unpacked, *packed; int pixcount, packedcount; register unsigned char *p; register unsigned long *parray; if (!unpacktab_inited) { register int white; for (white = 256; --white >= 0; ) unpacktab[white] = white * 0x010101L; unpacktab_inited++; } if (!PyArg_GetLong(args, 4, 0, &width)) return NULL; if (!PyArg_GetLong(args, 4, 1, &height)) return NULL; if (!PyArg_GetLong(args, 4, 2, &packfactor)) return NULL; if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */ return NULL; if (!PyArg_GetObject(args, 4, 3, &packed)) return NULL; if (width <= 0 || height <= 0 || packfactor <= 0) { PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0"); return NULL; } pixcount = width*height; packedcount = ((width+packfactor-1)/packfactor) * ((height+packfactor-1)/packfactor); if (PyString_Size(packed) != packedcount) { PyErr_SetString(PyExc_RuntimeError, "string arg to unpackrect has wrong size"); return NULL; } unpacked = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long)); if (unpacked == NULL) return NULL; parray = (unsigned long *) PyString_AsString(unpacked); p = (unsigned char *) PyString_AsString(packed); if (packfactor == 1 && width*height > 0) { /* Just expand bytes to longs */ register int x = width * height; do { *parray++ = unpacktab[*p++]; } while (--x >= 0); } else { register int y; for (y = 0; y < height-packfactor+1; y += packfactor, parray += packfactor*width) { register int x; for (x = 0; x < width-packfactor+1; x += packfactor) { register unsigned long pixel = unpacktab[*p++]; register int i; for (i = packfactor*width; (i-=width) >= 0;) { register int j; for (j = packfactor; --j >= 0; ) parray[i+x+j] = pixel; } } } } return unpacked; } static PyObject * gl_gversion(PyObject *self, PyObject *args) { char buf[20]; gversion(buf); return PyString_FromString(buf); } /* void clear - Manual because of clash with termcap */ static PyObject * gl_clear(PyObject *self, PyObject *args) { __GLclear( ); Py_INCREF(Py_None); return Py_None; } /* End of manually written stubs */ /* long getshade */ static PyObject * gl_getshade(PyObject *self, PyObject *args) { long retval; retval = getshade( ); return mknewlongobject(retval); } /* void devport short s long s */ static PyObject * gl_devport(PyObject *self, PyObject *args) { short arg1 ; long arg2 ; if (!getishortarg(args, 2, 0, &arg1)) return NULL; if (!getilongarg(args, 2, 1, &arg2)) return NULL; devport( arg1 , arg2 ); Py_INCREF(Py_None); return Py_None; } /* void rdr2i long s long s */ static PyObject * gl_rdr2i(PyObject *self, PyObject *args) { long arg1 ; long arg2 ; if (!getilongarg(args, 2, 0, &arg1)) return NULL; if (!getilongarg(args, 2, 1, &arg2)) return NULL; rdr2i( arg1 , arg2 ); Py_INCREF(Py_None); return Py_None; } /* void rectfs short s short s short s short s */ static PyObject * gl_rectfs(PyObject *self, PyObject *args) { short arg1 ; short arg2 ; short arg3 ; short arg4 ; if (!getishortarg(args, 4, 0, &arg1)) return NULL; if (!getishortarg(args, 4, 1, &arg2)) return NULL; if (!getishortarg(args, 4, 2, &arg3)) return NULL; if (!getishortarg(args, 4, 3, &arg4)) return NULL; rectfs( arg1 , arg2 , arg3 , arg4 ); Py_INCREF(Py_None); return Py_None; } /* void rects short s short s short s short s */ static PyObject * gl_rects(PyObject *self, PyObject *args) { short arg1 ; short arg2 ; short arg3 ; short arg4 ; if (!getishortarg(args, 4, 0, &arg1)) return NULL; if (!getishortarg(args, 4, 1, &arg2)) return NULL; if (!getishortarg(args, 4, 2, &arg3)) return NULL; if (!getishortarg(args, 4, 3, &arg4)) return NULL; rects( arg1 , arg2 , arg3 , arg4 ); Py_INCREF(Py_None); return Py_None; } /* void rmv2i long s long s */ static PyObject * gl_rmv2i(PyObject *self, PyObject *args) { long arg1 ; long arg2 ; if (!getilongarg(args, 2, 0, &arg1)) return NULL; if (!getilongarg(args, 2, 1, &arg2)) return NULL; rmv2i( arg1 , arg2 ); Py_INCREF(Py_None); return Py_None; } /* void noport */ static PyObject * gl_noport(PyObject *self, PyObject *args) { noport( ); Py_INCREF(Py_None); return Py_None; } /* void popviewport */ static PyObject * gl_popviewport(PyObject *self, PyObject *args) { popviewport( ); Py_INCREF(Py_None); return Py_None; } /* void clearhitcode */ static PyObject * gl_clearhitcode(PyObject *self, PyObject *args) { clearhitcode( ); Py_INCREF(Py_None); return Py_None; } /* void closeobj */ static PyObject * gl_closeobj(PyObject *self, PyObject *args) { closeobj( ); Py_INCREF(Py_None); return Py_None; } /* void cursoff */ static PyObject * gl_cursoff(PyObject *self, PyObject *args) { cursoff( ); Py_INCREF(Py_None); return Py_None; } /* void curson */ static PyObject * gl_curson(PyObject *self, PyObject *args) { curson( ); Py_INCREF(Py_None); return Py_None; } /* void doublebuffer */ static PyObject * gl_doublebuffer(PyObject *self, PyObject *args) { doublebuffer( ); Py_INCREF(Py_None); return Py_None; } /* void finish */ static PyObject * gl_finish(PyObject *self, PyObject *args) { finish( ); Py_INCREF(Py_None); return Py_None; } /* void gconfig */