📄 cstubs
字号:
PyErr_SetString(PyExc_RuntimeError,
"pick/gselect: already picking/selecting");
return NULL;
}
if ((pickbuffer = PyMem_NEW(short, pickbuffersize)) == NULL) {
return PyErr_NoMemory();
}
(*func)(pickbuffer, pickbuffersize);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
endpick_select(args, func)
PyObject *args;
long (*func)();
{
PyObject *v, *w;
int i, nhits, n;
if (!PyArg_NoArgs(args))
return NULL;
if (pickbuffer == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"endpick/endselect: not in pick/select mode");
return NULL;
}
nhits = (*func)(pickbuffer);
if (nhits < 0) {
nhits = -nhits; /* How to report buffer overflow otherwise? */
}
/* Scan the buffer to see how many integers */
n = 0;
for (; nhits > 0; nhits--) {
n += 1 + pickbuffer[n];
}
v = PyList_New(n);
if (v == NULL)
return NULL;
/* XXX Could do it nicer and interpret the data structure here,
returning a list of lists. But this can be done in Python... */
for (i = 0; i < n; i++) {
w = PyInt_FromLong((long)pickbuffer[i]);
if (w == NULL) {
Py_DECREF(v);
return NULL;
}
PyList_SetItem(v, i, w);
}
PyMem_DEL(pickbuffer);
pickbuffer = NULL;
return v;
}
extern void pick(), gselect();
extern long endpick(), endselect();
%pick
static PyObject *gl_pick(self, args) PyObject *self, *args; {
return pick_select(args, pick);
}
%endpick
static PyObject *gl_endpick(self, args) PyObject *self, *args; {
return endpick_select(args, endpick);
}
%gselect
static PyObject *gl_gselect(self, args) PyObject *self, *args; {
return pick_select(args, gselect);
}
%endselect
static PyObject *gl_endselect(self, args) PyObject *self, *args; {
return endpick_select(args, endselect);
}
/* 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. */
% getmatrix float r[16]
static PyObject *
gl_getmatrix(self, args)
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... */
% altgetmatrix float r[4][4]
static PyObject *
gl_altgetmatrix(self, args)
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;
}
% lrectwrite
static PyObject *
gl_lrectwrite(self, args)
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;
}
% lrectread
static PyObject *
gl_lrectread(self, args)
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;
}
% readdisplay
static PyObject *
gl_readdisplay(self, args)
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).
*/
% packrect
static PyObject *
gl_packrect(self, args)
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;
}
% unpackrect
static unsigned long unpacktab[256];
static int unpacktab_inited = 0;
static PyObject *
gl_unpackrect(self, args)
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;
}
% gversion
static PyObject *
gl_gversion(self, args)
PyObject *self;
PyObject *args;
{
char buf[20];
gversion(buf);
return PyString_FromString(buf);
}
/* void clear - Manual because of clash with termcap */
%clear
static PyObject *
gl_clear(self, args)
PyObject *self;
PyObject *args;
{
__GLclear( );
Py_INCREF(Py_None);
return Py_None;
}
/* End of manually written stubs */
%%
long getshade
if !solaris void devport short s long s
void rdr2i long s long s
void rectfs short s short s short s short s
void rects short s short s short s short s
void rmv2i long s long s
void noport
void popviewport
void clearhitcode
void closeobj
void cursoff
void curson
void doublebuffer
void finish
void gconfig
void ginit
void greset
void multimap
void onemap
void popattributes
void popmatrix
void pushattributes
void pushmatrix
void pushviewport
void qreset
void RGBmode
void singlebuffer
void swapbuffers
void gsync
void gflush
void tpon
void tpoff
void clkon
void clkoff
void ringbell
#void callfunc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -