blob: 53bd4ab310698b171b34d3cdd35f6e3a6d8113ac [file] [log] [blame]
Guido van Rossumb6775db1994-08-01 11:34:53 +00001
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00002/*
3Input used to generate the Python module "glmodule.c".
Guido van Rossumb3165151991-08-16 08:59:21 +00004The stub generator is a Python script called "cgen.py".
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00005
6Each definition must be contained on one line:
7
8<returntype> <name> <type> <arg> <type> <arg>
9
10<returntype> can be: void, short, long (XXX maybe others?)
11
12<type> can be: char, string, short, float, long, or double
13 string indicates a null terminated string;
14 if <type> is char and <arg> begins with a *, the * is stripped
15 and <type> is changed into string
16
17<arg> has the form <mode> or <mode>[<subscript>]
18 where <mode> can be
19 s: arg is sent
20 r: arg is received (arg is a pointer)
21 and <subscript> can be (N and I are numbers):
22 N
23 argI
24 retval
25 N*argI
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +000026 N*I
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000027 N*retval
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +000028 In the case where the subscript consists of two parts
29 separated by *, the first part is the width of the matrix, and
30 the second part is the length of the matrix. This order is
31 opposite from the order used in C to declare a two-dimensional
32 matrix.
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000033*/
34
Jack Jansen743db361992-08-13 14:13:11 +000035/*
36 * An attempt has been made to make this module switch threads on qread
37 * calls. It is far from safe, though.
38 */
39
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000040#include <gl.h>
41#include <device.h>
Guido van Rossum3f5da241990-12-20 15:06:42 +000042
Guido van Rossumece35bc1996-12-09 18:52:11 +000043#ifdef __sgi
44extern int devport();
45extern int textwritemask();
46extern int pagewritemask();
47extern int gewrite();
48extern int gettp();
49#endif
50
Guido van Rossum0a3eaf01997-04-29 15:39:28 +000051#include "Python.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000052#include "cgensupport.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000053
54/*
55Some stubs are too complicated for the stub generator.
56We can include manually written versions of them here.
57A line starting with '%' gives the name of the function so the stub
58generator can include it in the table of functions.
59*/
60
Jack Jansen743db361992-08-13 14:13:11 +000061% qread
62
Guido van Rossum0a3eaf01997-04-29 15:39:28 +000063static PyObject *
Jack Jansen743db361992-08-13 14:13:11 +000064gl_qread(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +000065 PyObject *self;
66 PyObject *args;
Jack Jansen743db361992-08-13 14:13:11 +000067{
68 long retval;
69 short arg1 ;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +000070 Py_BEGIN_ALLOW_THREADS
Jack Jansen743db361992-08-13 14:13:11 +000071 retval = qread( & arg1 );
Guido van Rossum0a3eaf01997-04-29 15:39:28 +000072 Py_END_ALLOW_THREADS
73 { PyObject *v = PyTuple_New( 2 );
Jack Jansen743db361992-08-13 14:13:11 +000074 if (v == NULL) return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +000075 PyTuple_SetItem(v, 0, mknewlongobject(retval));
76 PyTuple_SetItem(v, 1, mknewshortobject(arg1));
Jack Jansen743db361992-08-13 14:13:11 +000077 return v;
78 }
79}
80
81
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000082/*
83varray -- an array of v.. calls.
84The argument is an array (maybe list or tuple) of points.
85Each point must be a tuple or list of coordinates (x, y, z).
86The points may be 2- or 3-dimensional but must all have the
87same dimension. Float and int values may be mixed however.
88The points are always converted to 3D double precision points
89by assuming z=0.0 if necessary (as indicated in the man page),
90and for each point v3d() is called.
91*/
92
93% varray
94
Guido van Rossum0a3eaf01997-04-29 15:39:28 +000095static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000096gl_varray(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +000097 PyObject *self;
98 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000099{
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000100 PyObject *v, *w=NULL;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000101 int i, n, width;
102 double vec[3];
Sjoerd Mullenderf28b8982000-08-18 10:00:28 +0000103 PyObject * (*getitem)(PyObject *, int);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000104
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000105 if (!PyArg_GetObject(args, 1, 0, &v))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000106 return NULL;
107
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000108 if (PyList_Check(v)) {
109 n = PyList_Size(v);
110 getitem = PyList_GetItem;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000111 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000112 else if (PyTuple_Check(v)) {
113 n = PyTuple_Size(v);
114 getitem = PyTuple_GetItem;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000115 }
116 else {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000117 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000118 return NULL;
119 }
120
121 if (n == 0) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000122 Py_INCREF(Py_None);
123 return Py_None;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000124 }
125 if (n > 0)
126 w = (*getitem)(v, 0);
127
128 width = 0;
129 if (w == NULL) {
130 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000131 else if (PyList_Check(w)) {
132 width = PyList_Size(w);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000133 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000134 else if (PyTuple_Check(w)) {
135 width = PyTuple_Size(w);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000136 }
137
138 switch (width) {
139 case 2:
140 vec[2] = 0.0;
141 /* Fall through */
142 case 3:
143 break;
144 default:
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000145 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000146 return NULL;
147 }
148
149 for (i = 0; i < n; i++) {
150 w = (*getitem)(v, i);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000151 if (!PyArg_GetDoubleArray(w, 1, 0, width, vec))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000152 return NULL;
153 v3d(vec);
154 }
155
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000156 Py_INCREF(Py_None);
157 return Py_None;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000158}
159
160/*
161vnarray, nvarray -- an array of n3f and v3f calls.
162The argument is an array (list or tuple) of pairs of points and normals.
163Each pair is a tuple (NOT a list) of a point and a normal for that point.
164Each point or normal must be a tuple (NOT a list) of coordinates (x, y, z).
165Three coordinates must be given. Float and int values may be mixed.
166For each pair, n3f() is called for the normal, and then v3f() is called
167for the vector.
168
169vnarray and nvarray differ only in the order of the vector and normal in
170the pair: vnarray expects (v, n) while nvarray expects (n, v).
171*/
172
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000173static PyObject *gen_nvarray(); /* Forward */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000174
175% nvarray
176
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000177static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000178gl_nvarray(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000179 PyObject *self;
180 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000181{
182 return gen_nvarray(args, 0);
183}
184
185% vnarray
186
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000187static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000188gl_vnarray(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000189 PyObject *self;
190 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000191{
192 return gen_nvarray(args, 1);
193}
194
195/* Generic, internal version of {nv,nv}array: inorm indicates the
196 argument order, 0: normal first, 1: vector first. */
197
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000198static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000199gen_nvarray(args, inorm)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000200 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000201 int inorm;
202{
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000203 PyObject *v, *w, *wnorm, *wvec;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000204 int i, n;
205 float norm[3], vec[3];
Sjoerd Mullenderf28b8982000-08-18 10:00:28 +0000206 PyObject * (*getitem)(PyObject *, int);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000207
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000208 if (!PyArg_GetObject(args, 1, 0, &v))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000209 return NULL;
210
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000211 if (PyList_Check(v)) {
212 n = PyList_Size(v);
213 getitem = PyList_GetItem;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000214 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000215 else if (PyTuple_Check(v)) {
216 n = PyTuple_Size(v);
217 getitem = PyTuple_GetItem;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000218 }
219 else {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000220 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000221 return NULL;
222 }
223
224 for (i = 0; i < n; i++) {
225 w = (*getitem)(v, i);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000226 if (!PyTuple_Check(w) || PyTuple_Size(w) != 2) {
227 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000228 return NULL;
229 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000230 wnorm = PyTuple_GetItem(w, inorm);
231 wvec = PyTuple_GetItem(w, 1 - inorm);
232 if (!PyArg_GetFloatArray(wnorm, 1, 0, 3, norm) ||
233 !PyArg_GetFloatArray(wvec, 1, 0, 3, vec))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000234 return NULL;
235 n3f(norm);
236 v3f(vec);
237 }
238
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000239 Py_INCREF(Py_None);
240 return Py_None;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000241}
242
243/* nurbssurface(s_knots[], t_knots[], ctl[][], s_order, t_order, type).
244 The dimensions of ctl[] are computed as follows:
245 [len(s_knots) - s_order], [len(t_knots) - t_order]
246*/
247
248% nurbssurface
249
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000250static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000251gl_nurbssurface(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000252 PyObject *self;
253 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000254{
255 long arg1 ;
256 double * arg2 ;
257 long arg3 ;
258 double * arg4 ;
259 double *arg5 ;
260 long arg6 ;
261 long arg7 ;
262 long arg8 ;
263 long ncoords;
264 long s_byte_stride, t_byte_stride;
265 long s_nctl, t_nctl;
266 long s, t;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000267 PyObject *v, *w, *pt;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000268 double *pnext;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000269 if (!PyArg_GetLongArraySize(args, 6, 0, &arg1))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000270 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000271 if ((arg2 = PyMem_NEW(double, arg1 )) == NULL) {
272 return PyErr_NoMemory();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000273 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000274 if (!PyArg_GetDoubleArray(args, 6, 0, arg1 , arg2))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000275 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000276 if (!PyArg_GetLongArraySize(args, 6, 1, &arg3))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000277 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000278 if ((arg4 = PyMem_NEW(double, arg3 )) == NULL) {
279 return PyErr_NoMemory();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000280 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000281 if (!PyArg_GetDoubleArray(args, 6, 1, arg3 , arg4))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000282 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000283 if (!PyArg_GetLong(args, 6, 3, &arg6))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000284 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000285 if (!PyArg_GetLong(args, 6, 4, &arg7))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000286 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000287 if (!PyArg_GetLong(args, 6, 5, &arg8))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000288 return NULL;
289 if (arg8 == N_XYZ)
290 ncoords = 3;
291 else if (arg8 == N_XYZW)
292 ncoords = 4;
293 else {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000294 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000295 return NULL;
296 }
297 s_nctl = arg1 - arg6;
298 t_nctl = arg3 - arg7;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000299 if (!PyArg_GetObject(args, 6, 2, &v))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000300 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000301 if (!PyList_Check(v) || PyList_Size(v) != s_nctl) {
302 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000303 return NULL;
304 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000305 if ((arg5 = PyMem_NEW(double, s_nctl*t_nctl*ncoords )) == NULL) {
306 return PyErr_NoMemory();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000307 }
308 pnext = arg5;
309 for (s = 0; s < s_nctl; s++) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000310 w = PyList_GetItem(v, s);
311 if (w == NULL || !PyList_Check(w) ||
312 PyList_Size(w) != t_nctl) {
313 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000314 return NULL;
315 }
316 for (t = 0; t < t_nctl; t++) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000317 pt = PyList_GetItem(w, t);
318 if (!PyArg_GetDoubleArray(pt, 1, 0, ncoords, pnext))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000319 return NULL;
320 pnext += ncoords;
321 }
322 }
323 s_byte_stride = sizeof(double) * ncoords;
324 t_byte_stride = s_byte_stride * s_nctl;
325 nurbssurface( arg1 , arg2 , arg3 , arg4 ,
326 s_byte_stride , t_byte_stride , arg5 , arg6 , arg7 , arg8 );
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000327 PyMem_DEL(arg2);
328 PyMem_DEL(arg4);
329 PyMem_DEL(arg5);
330 Py_INCREF(Py_None);
331 return Py_None;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000332}
333
334/* nurbscurve(knots, ctlpoints, order, type).
335 The length of ctlpoints is len(knots)-order. */
336
337%nurbscurve
338
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000339static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000340gl_nurbscurve(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000341 PyObject *self;
342 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000343{
344 long arg1 ;
345 double * arg2 ;
346 long arg3 ;
347 double * arg4 ;
348 long arg5 ;
349 long arg6 ;
350 int ncoords, npoints;
351 int i;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000352 PyObject *v;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000353 double *pnext;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000354 if (!PyArg_GetLongArraySize(args, 4, 0, &arg1))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000355 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000356 if ((arg2 = PyMem_NEW(double, arg1 )) == NULL) {
357 return PyErr_NoMemory();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000358 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000359 if (!PyArg_GetDoubleArray(args, 4, 0, arg1 , arg2))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000360 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000361 if (!PyArg_GetLong(args, 4, 2, &arg5))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000362 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000363 if (!PyArg_GetLong(args, 4, 3, &arg6))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000364 return NULL;
365 if (arg6 == N_ST)
366 ncoords = 2;
367 else if (arg6 == N_STW)
368 ncoords = 3;
369 else {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000370 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000371 return NULL;
372 }
373 npoints = arg1 - arg5;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000374 if (!PyArg_GetObject(args, 4, 1, &v))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000375 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000376 if (!PyList_Check(v) || PyList_Size(v) != npoints) {
377 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000378 return NULL;
379 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000380 if ((arg4 = PyMem_NEW(double, npoints*ncoords )) == NULL) {
381 return PyErr_NoMemory();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000382 }
383 pnext = arg4;
384 for (i = 0; i < npoints; i++) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000385 if (!PyArg_GetDoubleArray(PyList_GetItem(v, i), 1, 0, ncoords, pnext))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000386 return NULL;
387 pnext += ncoords;
388 }
389 arg3 = (sizeof(double)) * ncoords;
390 nurbscurve( arg1 , arg2 , arg3 , arg4 , arg5 , arg6 );
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000391 PyMem_DEL(arg2);
392 PyMem_DEL(arg4);
393 Py_INCREF(Py_None);
394 return Py_None;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000395}
396
397/* pwlcurve(points, type).
398 Points is a list of points. Type must be N_ST. */
399
400%pwlcurve
401
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000402static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000403gl_pwlcurve(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000404 PyObject *self;
405 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000406{
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000407 PyObject *v;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000408 long type;
409 double *data, *pnext;
410 long npoints, ncoords;
411 int i;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000412 if (!PyArg_GetObject(args, 2, 0, &v))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000413 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000414 if (!PyArg_GetLong(args, 2, 1, &type))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000415 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000416 if (!PyList_Check(v)) {
417 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000418 return NULL;
419 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000420 npoints = PyList_Size(v);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000421 if (type == N_ST)
422 ncoords = 2;
423 else {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000424 PyErr_BadArgument();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000425 return NULL;
426 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000427 if ((data = PyMem_NEW(double, npoints*ncoords)) == NULL) {
428 return PyErr_NoMemory();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000429 }
430 pnext = data;
431 for (i = 0; i < npoints; i++) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000432 if (!PyArg_GetDoubleArray(PyList_GetItem(v, i), 1, 0, ncoords, pnext))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000433 return NULL;
434 pnext += ncoords;
435 }
436 pwlcurve(npoints, data, sizeof(double)*ncoords, type);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000437 PyMem_DEL(data);
438 Py_INCREF(Py_None);
439 return Py_None;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000440}
441
442
443/* Picking and Selecting */
444
445static short *pickbuffer = NULL;
446static long pickbuffersize;
447
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000448static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000449pick_select(args, func)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000450 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000451 void (*func)();
452{
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000453 if (!PyArg_GetLong(args, 1, 0, &pickbuffersize))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000454 return NULL;
455 if (pickbuffer != NULL) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000456 PyErr_SetString(PyExc_RuntimeError,
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000457 "pick/gselect: already picking/selecting");
458 return NULL;
459 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000460 if ((pickbuffer = PyMem_NEW(short, pickbuffersize)) == NULL) {
461 return PyErr_NoMemory();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000462 }
463 (*func)(pickbuffer, pickbuffersize);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000464 Py_INCREF(Py_None);
465 return Py_None;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000466}
467
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000468static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000469endpick_select(args, func)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000470 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000471 long (*func)();
472{
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000473 PyObject *v, *w;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000474 int i, nhits, n;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000475 if (!PyArg_NoArgs(args))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000476 return NULL;
477 if (pickbuffer == NULL) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000478 PyErr_SetString(PyExc_RuntimeError,
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000479 "endpick/endselect: not in pick/select mode");
480 return NULL;
481 }
482 nhits = (*func)(pickbuffer);
483 if (nhits < 0) {
484 nhits = -nhits; /* How to report buffer overflow otherwise? */
485 }
486 /* Scan the buffer to see how many integers */
487 n = 0;
488 for (; nhits > 0; nhits--) {
489 n += 1 + pickbuffer[n];
490 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000491 v = PyList_New(n);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000492 if (v == NULL)
493 return NULL;
494 /* XXX Could do it nicer and interpret the data structure here,
495 returning a list of lists. But this can be done in Python... */
496 for (i = 0; i < n; i++) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000497 w = PyInt_FromLong((long)pickbuffer[i]);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000498 if (w == NULL) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000499 Py_DECREF(v);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000500 return NULL;
501 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000502 PyList_SetItem(v, i, w);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000503 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000504 PyMem_DEL(pickbuffer);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000505 pickbuffer = NULL;
506 return v;
507}
508
509extern void pick(), gselect();
510extern long endpick(), endselect();
511
512%pick
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000513static PyObject *gl_pick(self, args) PyObject *self, *args; {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000514 return pick_select(args, pick);
515}
516
517%endpick
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000518static PyObject *gl_endpick(self, args) PyObject *self, *args; {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000519 return endpick_select(args, endpick);
520}
521
522%gselect
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000523static PyObject *gl_gselect(self, args) PyObject *self, *args; {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000524 return pick_select(args, gselect);
525}
526
527%endselect
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000528static PyObject *gl_endselect(self, args) PyObject *self, *args; {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000529 return endpick_select(args, endselect);
530}
531
532
533/* XXX The generator botches this one. Here's a quick hack to fix it. */
534
Guido van Rossumb3165151991-08-16 08:59:21 +0000535/* XXX The generator botches this one. Here's a quick hack to fix it. */
536
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000537% getmatrix float r[16]
538
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000539static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000540gl_getmatrix(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000541 PyObject *self;
542 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000543{
Sjoerd Mullender3bb8a051993-10-22 12:04:32 +0000544 Matrix arg1;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000545 PyObject *v, *w;
Sjoerd Mullender3bb8a051993-10-22 12:04:32 +0000546 int i, j;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000547 getmatrix( arg1 );
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000548 v = PyList_New(16);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000549 if (v == NULL) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000550 return PyErr_NoMemory();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000551 }
Sjoerd Mullender3bb8a051993-10-22 12:04:32 +0000552 for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) {
553 w = mknewfloatobject(arg1[i][j]);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000554 if (w == NULL) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000555 Py_DECREF(v);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000556 return NULL;
557 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000558 PyList_SetItem(v, i*4+j, w);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000559 }
560 return v;
561}
562
Guido van Rossumb3165151991-08-16 08:59:21 +0000563/* Here's an alternate version that returns a 4x4 matrix instead of
564 a vector. Unfortunately it is incompatible with loadmatrix and
565 multmatrix... */
566
567% altgetmatrix float r[4][4]
568
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000569static PyObject *
Guido van Rossumb3165151991-08-16 08:59:21 +0000570gl_altgetmatrix(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000571 PyObject *self;
572 PyObject *args;
Guido van Rossumb3165151991-08-16 08:59:21 +0000573{
Sjoerd Mullender3bb8a051993-10-22 12:04:32 +0000574 Matrix arg1;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000575 PyObject *v, *w;
Guido van Rossumb3165151991-08-16 08:59:21 +0000576 int i, j;
577 getmatrix( arg1 );
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000578 v = PyList_New(4);
Guido van Rossumb3165151991-08-16 08:59:21 +0000579 if (v == NULL) {
580 return NULL;
581 }
582 for (i = 0; i < 4; i++) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000583 w = PyList_New(4);
Guido van Rossumb3165151991-08-16 08:59:21 +0000584 if (w == NULL) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000585 Py_DECREF(v);
Guido van Rossumb3165151991-08-16 08:59:21 +0000586 return NULL;
587 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000588 PyList_SetItem(v, i, w);
Guido van Rossumb3165151991-08-16 08:59:21 +0000589 }
590 for (i = 0; i < 4; i++) {
591 for (j = 0; j < 4; j++) {
592 w = mknewfloatobject(arg1[i][j]);
593 if (w == NULL) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000594 Py_DECREF(v);
Guido van Rossumb3165151991-08-16 08:59:21 +0000595 return NULL;
596 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000597 PyList_SetItem(PyList_GetItem(v, i), j, w);
Guido van Rossumb3165151991-08-16 08:59:21 +0000598 }
599 }
600 return v;
601}
602
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000603% lrectwrite
604
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000605static PyObject *
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000606gl_lrectwrite(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000607 PyObject *self;
608 PyObject *args;
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000609{
610 short x1 ;
611 short y1 ;
612 short x2 ;
613 short y2 ;
614 string parray ;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000615 PyObject *s;
Guido van Rossumece35bc1996-12-09 18:52:11 +0000616#if 0
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000617 int pixcount;
Guido van Rossumece35bc1996-12-09 18:52:11 +0000618#endif
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000619 if (!PyArg_GetShort(args, 5, 0, &x1))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000620 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000621 if (!PyArg_GetShort(args, 5, 1, &y1))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000622 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000623 if (!PyArg_GetShort(args, 5, 2, &x2))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000624 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000625 if (!PyArg_GetShort(args, 5, 3, &y2))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000626 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000627 if (!PyArg_GetString(args, 5, 4, &parray))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000628 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000629 if (!PyArg_GetObject(args, 5, 4, &s))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000630 return NULL;
Guido van Rossum6d0b5a71991-11-12 15:41:00 +0000631#if 0
632/* Don't check this, it breaks experiments with pixmode(PM_SIZE, ...) */
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000633 pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000634 if (!PyString_Check(s) || PyString_Size(s) != pixcount*sizeof(long)) {
635 PyErr_SetString(PyExc_RuntimeError,
Guido van Rossum6d0b5a71991-11-12 15:41:00 +0000636 "string arg to lrectwrite has wrong size");
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000637 return NULL;
638 }
Guido van Rossum6d0b5a71991-11-12 15:41:00 +0000639#endif
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000640 lrectwrite( x1 , y1 , x2 , y2 , (unsigned long *) parray );
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000641 Py_INCREF(Py_None);
642 return Py_None;
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000643}
644
645% lrectread
646
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000647static PyObject *
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000648gl_lrectread(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000649 PyObject *self;
650 PyObject *args;
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000651{
652 short x1 ;
653 short y1 ;
654 short x2 ;
655 short y2 ;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000656 PyObject *parray;
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000657 int pixcount;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000658 if (!PyArg_GetShort(args, 4, 0, &x1))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000659 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000660 if (!PyArg_GetShort(args, 4, 1, &y1))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000661 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000662 if (!PyArg_GetShort(args, 4, 2, &x2))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000663 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000664 if (!PyArg_GetShort(args, 4, 3, &y2))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000665 return NULL;
666 pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000667 parray = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000668 if (parray == NULL)
669 return NULL; /* No memory */
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000670 lrectread(x1, y1, x2, y2, (unsigned long *) PyString_AsString(parray));
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000671 return parray;
672}
673
Jack Jansen5fc67731993-02-16 09:25:15 +0000674% readdisplay
675
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000676static PyObject *
Jack Jansen5fc67731993-02-16 09:25:15 +0000677gl_readdisplay(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000678 PyObject *self;
679 PyObject *args;
Jack Jansen5fc67731993-02-16 09:25:15 +0000680{
681 short x1, y1, x2, y2;
682 unsigned long *parray, hints;
683 long size, size_ret;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000684 PyObject *rv;
Jack Jansen5fc67731993-02-16 09:25:15 +0000685
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000686 if ( !PyArg_Parse(args, "hhhhl", &x1, &y1, &x2, &y2, &hints) )
Jack Jansen5fc67731993-02-16 09:25:15 +0000687 return 0;
688 size = (long)(x2+1-x1) * (long)(y2+1-y1);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000689 rv = PyString_FromStringAndSize((char *)NULL, size*sizeof(long));
Jack Jansen5fc67731993-02-16 09:25:15 +0000690 if ( rv == NULL )
691 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000692 parray = (unsigned long *)PyString_AsString(rv);
Jack Jansen5fc67731993-02-16 09:25:15 +0000693 size_ret = readdisplay(x1, y1, x2, y2, parray, hints);
694 if ( size_ret != size ) {
Guido van Rossumece35bc1996-12-09 18:52:11 +0000695 printf("gl_readdisplay: got %ld pixels, expected %ld\n",
Jack Jansen5fc67731993-02-16 09:25:15 +0000696 size_ret, size);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000697 PyErr_SetString(PyExc_RuntimeError, "readdisplay returned unexpected length");
Jack Jansen5fc67731993-02-16 09:25:15 +0000698 return NULL;
699 }
700 return rv;
701}
702
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000703/* Desperately needed, here are tools to compress and decompress
704 the data manipulated by lrectread/lrectwrite.
705
706 gl.packrect(width, height, packfactor, bigdata) --> smalldata
707 makes 'bigdata' 4*(packfactor**2) times smaller by:
708 - turning it into B/W (a factor 4)
709 - replacing squares of size pacfactor by one
710 representative
711
712 gl.unpackrect(width, height, packfactor, smalldata) --> bigdata
713 is the inverse; the numeric arguments must be *the same*.
714
715 Both work best if width and height are multiples of packfactor
716 (in fact unpackrect will leave garbage bytes).
717*/
718
719% packrect
720
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000721static PyObject *
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000722gl_packrect(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000723 PyObject *self;
724 PyObject *args;
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000725{
726 long width, height, packfactor;
727 char *s;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000728 PyObject *unpacked, *packed;
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000729 int pixcount, packedcount, x, y, r, g, b;
730 unsigned long pixel;
731 unsigned char *p;
732 unsigned long *parray;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000733 if (!PyArg_GetLong(args, 4, 0, &width))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000734 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000735 if (!PyArg_GetLong(args, 4, 1, &height))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000736 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000737 if (!PyArg_GetLong(args, 4, 2, &packfactor))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000738 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000739 if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000740 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000741 if (!PyArg_GetObject(args, 4, 3, &unpacked))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000742 return NULL;
743 if (width <= 0 || height <= 0 || packfactor <= 0) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000744 PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0");
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000745 return NULL;
746 }
747 pixcount = width*height;
748 packedcount = ((width+packfactor-1)/packfactor) *
749 ((height+packfactor-1)/packfactor);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000750 if (PyString_Size(unpacked) != pixcount*sizeof(long)) {
751 PyErr_SetString(PyExc_RuntimeError,
Guido van Rossum6d0b5a71991-11-12 15:41:00 +0000752 "string arg to packrect has wrong size");
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000753 return NULL;
754 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000755 packed = PyString_FromStringAndSize((char *)NULL, packedcount);
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000756 if (packed == NULL)
757 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000758 parray = (unsigned long *) PyString_AsString(unpacked);
759 p = (unsigned char *) PyString_AsString(packed);
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000760 for (y = 0; y < height; y += packfactor, parray += packfactor*width) {
761 for (x = 0; x < width; x += packfactor) {
762 pixel = parray[x];
763 r = pixel & 0xff;
764 g = (pixel >> 8) & 0xff;
765 b = (pixel >> 16) & 0xff;
Guido van Rossum6d0b5a71991-11-12 15:41:00 +0000766 *p++ = (30*r+59*g+11*b) / 100;
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000767 }
768 }
769 return packed;
770}
771
772% unpackrect
773
774static unsigned long unpacktab[256];
775static int unpacktab_inited = 0;
776
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000777static PyObject *
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000778gl_unpackrect(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000779 PyObject *self;
780 PyObject *args;
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000781{
782 long width, height, packfactor;
783 char *s;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000784 PyObject *unpacked, *packed;
Guido van Rossumece35bc1996-12-09 18:52:11 +0000785 int pixcount, packedcount;
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000786 register unsigned char *p;
787 register unsigned long *parray;
788 if (!unpacktab_inited) {
789 register int white;
790 for (white = 256; --white >= 0; )
791 unpacktab[white] = white * 0x010101L;
792 unpacktab_inited++;
793 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000794 if (!PyArg_GetLong(args, 4, 0, &width))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000795 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000796 if (!PyArg_GetLong(args, 4, 1, &height))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000797 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000798 if (!PyArg_GetLong(args, 4, 2, &packfactor))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000799 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000800 if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000801 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000802 if (!PyArg_GetObject(args, 4, 3, &packed))
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000803 return NULL;
804 if (width <= 0 || height <= 0 || packfactor <= 0) {
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000805 PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0");
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000806 return NULL;
807 }
808 pixcount = width*height;
809 packedcount = ((width+packfactor-1)/packfactor) *
810 ((height+packfactor-1)/packfactor);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000811 if (PyString_Size(packed) != packedcount) {
812 PyErr_SetString(PyExc_RuntimeError,
Guido van Rossum6d0b5a71991-11-12 15:41:00 +0000813 "string arg to unpackrect has wrong size");
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000814 return NULL;
815 }
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000816 unpacked = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000817 if (unpacked == NULL)
818 return NULL;
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000819 parray = (unsigned long *) PyString_AsString(unpacked);
820 p = (unsigned char *) PyString_AsString(packed);
Guido van Rossumd26d9ed1991-10-20 20:13:40 +0000821 if (packfactor == 1 && width*height > 0) {
822 /* Just expand bytes to longs */
823 register int x = width * height;
824 do {
825 *parray++ = unpacktab[*p++];
826 } while (--x >= 0);
827 }
828 else {
829 register int y;
830 for (y = 0; y < height-packfactor+1;
831 y += packfactor, parray += packfactor*width) {
832 register int x;
833 for (x = 0; x < width-packfactor+1; x += packfactor) {
834 register unsigned long pixel = unpacktab[*p++];
835 register int i;
836 for (i = packfactor*width; (i-=width) >= 0;) {
837 register int j;
838 for (j = packfactor; --j >= 0; )
839 parray[i+x+j] = pixel;
840 }
841 }
842 }
843 }
844 return unpacked;
845}
846
Guido van Rossumaee08791992-09-08 09:05:33 +0000847% gversion
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000848static PyObject *
Guido van Rossumaee08791992-09-08 09:05:33 +0000849gl_gversion(self, args)
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000850 PyObject *self;
851 PyObject *args;
Guido van Rossumaee08791992-09-08 09:05:33 +0000852{
853 char buf[20];
854 gversion(buf);
Guido van Rossum0a3eaf01997-04-29 15:39:28 +0000855 return PyString_FromString(buf);
Guido van Rossumaee08791992-09-08 09:05:33 +0000856}
857
858
Guido van Rossum5c069fd1998-04-28 16:09:16 +0000859/* void clear - Manual because of clash with termcap */
860%clear
861static PyObject *
862gl_clear(self, args)
863 PyObject *self;
864 PyObject *args;
865{
866 __GLclear( );
867 Py_INCREF(Py_None);
868 return Py_None;
869}
870
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000871/* End of manually written stubs */
872
873%%
874
875long getshade
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +0000876if !solaris void devport short s long s
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000877void rdr2i long s long s
878void rectfs short s short s short s short s
879void rects short s short s short s short s
880void rmv2i long s long s
881void noport
882void popviewport
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000883void clearhitcode
884void closeobj
885void cursoff
886void curson
887void doublebuffer
888void finish
889void gconfig
890void ginit
891void greset
892void multimap
893void onemap
894void popattributes
895void popmatrix
896void pushattributes
897void pushmatrix
898void pushviewport
899void qreset
900void RGBmode
901void singlebuffer
902void swapbuffers
903void gsync
Guido van Rossum06a67021992-02-26 15:19:45 +0000904void gflush
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000905void tpon
906void tpoff
907void clkon
908void clkoff
909void ringbell
910#void callfunc
911void gbegin
912void textinit
913void initnames
914void pclos
915void popname
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +0000916if !solaris void spclos
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000917void zclear
918void screenspace
919void reshapeviewport
920void winpush
921void winpop
922void foreground
923void endfullscrn
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +0000924if !solaris void endpupmode
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000925void fullscrn
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +0000926if !solaris void pupmode
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000927void winconstraints
928void pagecolor short s
929void textcolor short s
930void color short s
931void curveit short s
932void font short s
933void linewidth short s
934void setlinestyle short s
935void setmap short s
936void swapinterval short s
937void writemask short s
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +0000938if !solaris void textwritemask short s
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000939void qdevice short s
940void unqdevice short s
941void curvebasis short s
942void curveprecision short s
943void loadname short s
944void passthrough short s
945void pushname short s
946void setmonitor short s
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +0000947if !solaris void setshade short s
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000948void setpattern short s
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +0000949if !solaris void pagewritemask short s
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000950#
951void callobj long s
952void delobj long s
953void editobj long s
954void makeobj long s
955void maketag long s
956void chunksize long s
957void compactify long s
958void deltag long s
959void lsrepeat long s
960void objinsert long s
961void objreplace long s
962void winclose long s
963void blanktime long s
964void freepup long s
965# This is not in the library!?
966###void pupcolor long s
967#
968void backbuffer long s
969void frontbuffer long s
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +0000970if !solaris void lsbackup long s
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000971void resetls long s
972void lampon long s
973void lampoff long s
974void setbell long s
975void blankscreen long s
976void depthcue long s
977void zbuffer long s
978void backface long s
979#
980void cmov2i long s long s
981void draw2i long s long s
982void move2i long s long s
983void pnt2i long s long s
984void patchbasis long s long s
985void patchprecision long s long s
986void pdr2i long s long s
987void pmv2i long s long s
988void rpdr2i long s long s
989void rpmv2i long s long s
990void xfpt2i long s long s
991void objdelete long s long s
992void patchcurves long s long s
993void minsize long s long s
994void maxsize long s long s
995void keepaspect long s long s
996void prefsize long s long s
997void stepunit long s long s
998void fudge long s long s
999void winmove long s long s
1000#
1001void attachcursor short s short s
1002void deflinestyle short s short s
1003void noise short s short s
1004void picksize short s short s
1005void qenter short s short s
1006void setdepth short s short s
1007void cmov2s short s short s
1008void draw2s short s short s
1009void move2s short s short s
1010void pdr2s short s short s
1011void pmv2s short s short s
1012void pnt2s short s short s
1013void rdr2s short s short s
1014void rmv2s short s short s
1015void rpdr2s short s short s
1016void rpmv2s short s short s
1017void xfpt2s short s short s
1018#
1019void cmov2 float s float s
1020void draw2 float s float s
1021void move2 float s float s
1022void pnt2 float s float s
1023void pdr2 float s float s
1024void pmv2 float s float s
1025void rdr2 float s float s
1026void rmv2 float s float s
1027void rpdr2 float s float s
1028void rpmv2 float s float s
1029void xfpt2 float s float s
1030#
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001031void loadmatrix float s[4*4]
Guido van Rossumb3165151991-08-16 08:59:21 +00001032# Really [4][4]
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001033void multmatrix float s[4*4]
Guido van Rossumb3165151991-08-16 08:59:21 +00001034# Really [4][4]
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001035void crv float s[3*4]
Guido van Rossumb3165151991-08-16 08:59:21 +00001036# Really [4][3]
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001037void rcrv float s[4*4]
Guido van Rossumb3165151991-08-16 08:59:21 +00001038# Really [4][4]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001039#
1040# Methods that have strings.
1041#
1042void addtopup long s char *s long s
1043void charstr char *s
1044void getport char *s
1045long strwidth char *s
1046long winopen char *s
1047void wintitle char *s
1048#
1049# Methods that have 1 long (# of elements) and an array
1050#
1051void polf long s float s[3*arg1]
1052void polf2 long s float s[2*arg1]
1053void poly long s float s[3*arg1]
1054void poly2 long s float s[2*arg1]
1055void crvn long s float s[3*arg1]
1056void rcrvn long s float s[4*arg1]
1057#
1058void polf2i long s long s[2*arg1]
1059void polfi long s long s[3*arg1]
1060void poly2i long s long s[2*arg1]
1061void polyi long s long s[3*arg1]
1062#
1063void polf2s long s short s[2*arg1]
1064void polfs long s short s[3*arg1]
1065void polys long s short s[3*arg1]
1066void poly2s long s short s[2*arg1]
1067#
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001068void defcursor short s u_short s[128]
Guido van Rossumb3165151991-08-16 08:59:21 +00001069# Is this useful?
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001070void writepixels short s u_short s[arg1]
Guido van Rossumb3165151991-08-16 08:59:21 +00001071# Should be unsigned short...
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001072void defbasis long s float s[4*4]
1073if !solaris void gewrite short s short s[arg1]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001074#
1075void rotate short s char s
1076# This is not in the library!?
1077###void setbutton short s char s
1078void rot float s char s
1079#
1080void circfi long s long s long s
1081void circi long s long s long s
1082void cmovi long s long s long s
1083void drawi long s long s long s
1084void movei long s long s long s
1085void pnti long s long s long s
1086void newtag long s long s long s
1087void pdri long s long s long s
1088void pmvi long s long s long s
1089void rdri long s long s long s
1090void rmvi long s long s long s
1091void rpdri long s long s long s
1092void rpmvi long s long s long s
1093void xfpti long s long s long s
1094#
1095void circ float s float s float s
1096void circf float s float s float s
1097void cmov float s float s float s
1098void draw float s float s float s
1099void move float s float s float s
1100void pnt float s float s float s
1101void scale float s float s float s
1102void translate float s float s float s
1103void pdr float s float s float s
1104void pmv float s float s float s
1105void rdr float s float s float s
1106void rmv float s float s float s
1107void rpdr float s float s float s
1108void rpmv float s float s float s
1109void xfpt float s float s float s
1110#
1111void RGBcolor short s short s short s
1112void RGBwritemask short s short s short s
1113void setcursor short s short s short s
1114void tie short s short s short s
1115void circfs short s short s short s
1116void circs short s short s short s
1117void cmovs short s short s short s
1118void draws short s short s short s
1119void moves short s short s short s
1120void pdrs short s short s short s
1121void pmvs short s short s short s
1122void pnts short s short s short s
1123void rdrs short s short s short s
1124void rmvs short s short s short s
1125void rpdrs short s short s short s
1126void rpmvs short s short s short s
1127void xfpts short s short s short s
1128void curorigin short s short s short s
1129void cyclemap short s short s short s
1130#
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001131void patch float s[4*4] float s[4*4] float s[4*4]
1132void splf long s float s[3*arg1] u_short s[arg1]
1133void splf2 long s float s[2*arg1] u_short s[arg1]
1134void splfi long s long s[3*arg1] u_short s[arg1]
1135void splf2i long s long s[2*arg1] u_short s[arg1]
1136void splfs long s short s[3*arg1] u_short s[arg1]
1137void splf2s long s short s[2*arg1] u_short s[arg1]
1138###void defpattern short s short s u_short s[arg2*arg2/16]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001139#
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001140void rpatch float s[4*4] float s[4*4] float s[4*4] float s[4*4]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001141#
1142# routines that send 4 floats
1143#
1144void ortho2 float s float s float s float s
1145void rect float s float s float s float s
1146void rectf float s float s float s float s
1147void xfpt4 float s float s float s float s
1148#
1149void textport short s short s short s short s
1150void mapcolor short s short s short s short s
1151void scrmask short s short s short s short s
1152void setvaluator short s short s short s short s
1153void viewport short s short s short s short s
1154void shaderange short s short s short s short s
1155void xfpt4s short s short s short s short s
1156void rectfi long s long s long s long s
1157void recti long s long s long s long s
1158void xfpt4i long s long s long s long s
1159void prefposition long s long s long s long s
1160#
1161void arc float s float s float s short s short s
1162void arcf float s float s float s short s short s
1163void arcfi long s long s long s short s short s
1164void arci long s long s long s short s short s
1165#
1166void bbox2 short s short s float s float s float s float s
1167void bbox2i short s short s long s long s long s long s
1168void bbox2s short s short s short s short s short s short s
1169void blink short s short s short s short s short s
1170void ortho float s float s float s float s float s float s
1171void window float s float s float s float s float s float s
1172void lookat float s float s float s float s float s float s short s
1173#
1174void perspective short s float s float s float s
1175void polarview float s short s short s short s
1176# XXX getichararray not supported
1177#void writeRGB short s char s[arg1] char s[arg1] char s[arg1]
1178#
1179void arcfs short s short s short s short s short s
1180void arcs short s short s short s short s short s
1181void rectcopy short s short s short s short s short s short s
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001182if !solaris void RGBcursor short s short s short s short s short s short s short s
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001183#
1184long getbutton short s
1185long getcmmode
1186long getlsbackup
1187long getresetls
1188long getdcm
1189long getzbuffer
1190long ismex
1191long isobj long s
1192long isqueued short s
1193long istag long s
1194#
1195long genobj
1196long gentag
1197long getbuffer
1198long getcolor
1199long getdisplaymode
1200long getfont
1201long getheight
1202long gethitcode
1203long getlstyle
1204long getlwidth
1205long getmap
1206long getplanes
1207long getwritemask
1208long qtest
1209long getlsrepeat
1210long getmonitor
1211long getopenobj
1212long getpattern
1213long winget
1214long winattach
1215long getothermonitor
1216long newpup
1217#
1218long getvaluator short s
1219void winset long s
1220long dopup long s
1221void getdepth short r short r
1222void getcpos short r short r
1223void getsize long r long r
1224void getorigin long r long r
1225void getviewport short r short r short r short r
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001226if !solaris void gettp short r short r short r short r
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001227void getgpos float r float r float r float r
1228void winposition long s long s long s long s
1229void gRGBcolor short r short r short r
1230void gRGBmask short r short r short r
1231void getscrmask short r short r short r short r
Guido van Rossumd26d9ed1991-10-20 20:13:40 +00001232###void gRGBcursor short r short r short r short r short r short r short r short r
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001233void getmcolor short s short r short r short r
1234void mapw long s short s short s float r float r float r float r float r float r
1235void mapw2 long s short s short s float r float r
Guido van Rossumd26d9ed1991-10-20 20:13:40 +00001236###void defrasterfont short s short s short s Fontchar s[arg3] short s short s[4*arg5]
Guido van Rossum39789031992-08-13 14:23:56 +00001237###long qread short r
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001238void getcursor short r u_short r u_short r long r
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001239#
1240# For these we receive arrays of stuff
1241#
Guido van Rossumd26d9ed1991-10-20 20:13:40 +00001242###void getdev long s short s[arg1] short r[arg1]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001243#XXX not generated correctly yet
1244#void getmatrix float r[16]
Guido van Rossumd26d9ed1991-10-20 20:13:40 +00001245###long readpixels short s short r[retval]
1246###long readRGB short s char r[retval] char r[retval] char r[retval]
1247###long blkqread short s short r[arg1]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001248#
1249# New 4D routines
1250#
1251void cmode
1252void concave long s
1253void curstype long s
1254void drawmode long s
1255void gammaramp short s[256] short s[256] short s[256]
1256long getbackface
1257long getdescender
1258long getdrawmode
1259long getmmode
1260long getsm
1261long getvideo long s
1262void imakebackground
1263void lmbind short s short s
1264void lmdef long s long s long s float s[arg3]
1265void mmode long s
1266void normal float s[3]
1267void overlay long s
1268void RGBrange short s short s short s short s short s short s short s short s
Sjoerd Mullenderc4f169c1993-12-21 17:06:12 +00001269if !solaris void setvideo long s long s
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001270void shademodel long s
1271void underlay long s
1272#
1273# New Personal Iris/GT Routines
1274#
1275void bgnclosedline
1276void bgnline
1277void bgnpoint
1278void bgnpolygon
1279void bgnsurface
1280void bgntmesh
1281void bgntrim
1282void endclosedline
1283void endline
1284void endpoint
1285void endpolygon
1286void endsurface
1287void endtmesh
1288void endtrim
1289void blendfunction long s long s
1290void c3f float s[3]
1291void c3i long s[3]
1292void c3s short s[3]
1293void c4f float s[4]
1294void c4i long s[4]
1295void c4s short s[4]
1296void colorf float s
1297void cpack long s
1298void czclear long s long s
1299void dglclose long s
1300long dglopen char *s long s
1301long getgdesc long s
1302void getnurbsproperty long s float r
1303void glcompat long s long s
1304void iconsize long s long s
1305void icontitle char *s
1306void lRGBrange short s short s short s short s short s short s long s long s
1307void linesmooth long s
1308void lmcolor long s
1309void logicop long s
Guido van Rossumd26d9ed1991-10-20 20:13:40 +00001310###long lrectread short s short s short s short s long r[retval]
1311###void lrectwrite short s short s short s short s long s[(arg2-arg1+1)*(arg4-arg3+1)]
1312### Now manual, with string last arg
1313###long rectread short s short s short s short s short r[retval]
1314###void rectwrite short s short s short s short s short s[(arg2-arg1+1)*(arg4-arg3+1)]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001315void lsetdepth long s long s
1316void lshaderange short s short s long s long s
1317void n3f float s[3]
1318void noborder
1319void pntsmooth long s
1320void readsource long s
1321void rectzoom float s float s
1322void sbox float s float s float s float s
1323void sboxi long s long s long s long s
1324void sboxs short s short s short s short s
1325void sboxf float s float s float s float s
1326void sboxfi long s long s long s long s
1327void sboxfs short s short s short s short s
1328void setnurbsproperty long s float s
1329void setpup long s long s long s
1330void smoothline long s
1331void subpixel long s
1332void swaptmesh
1333long swinopen long s
1334void v2f float s[2]
1335void v2i long s[2]
1336void v2s short s[2]
1337void v3f float s[3]
1338void v3i long s[3]
1339void v3s short s[3]
1340void v4f float s[4]
1341void v4i long s[4]
1342void v4s short s[4]
1343void videocmd long s
1344long windepth long s
1345void wmpack long s
1346void zdraw long s
1347void zfunction long s
1348void zsource long s
1349void zwritemask long s
1350#
1351# uses doubles
1352#
1353void v2d double s[2]
1354void v3d double s[3]
1355void v4d double s[4]
Guido van Rossumd26d9ed1991-10-20 20:13:40 +00001356#
1357# Why isn't this here?
1358#
1359void pixmode long s long s
Guido van Rossumdd9ed831992-06-29 17:10:40 +00001360#
1361# New in IRIX 4.0
1362#
1363long qgetfd
Jack Jansenfa1b9f61993-02-19 12:53:12 +00001364void dither long s