/Modules/cstubs

http://unladen-swallow.googlecode.com/ · #! · 1364 lines · 1278 code · 86 blank · 0 comment · 0 complexity · 04288c744b58aabff36df171541427ae MD5 · raw file

  1. /*
  2. Input used to generate the Python module "glmodule.c".
  3. The stub generator is a Python script called "cgen.py".
  4. Each definition must be contained on one line:
  5. <returntype> <name> <type> <arg> <type> <arg>
  6. <returntype> can be: void, short, long (XXX maybe others?)
  7. <type> can be: char, string, short, float, long, or double
  8. string indicates a null terminated string;
  9. if <type> is char and <arg> begins with a *, the * is stripped
  10. and <type> is changed into string
  11. <arg> has the form <mode> or <mode>[<subscript>]
  12. where <mode> can be
  13. s: arg is sent
  14. r: arg is received (arg is a pointer)
  15. and <subscript> can be (N and I are numbers):
  16. N
  17. argI
  18. retval
  19. N*argI
  20. N*I
  21. N*retval
  22. In the case where the subscript consists of two parts
  23. separated by *, the first part is the width of the matrix, and
  24. the second part is the length of the matrix. This order is
  25. opposite from the order used in C to declare a two-dimensional
  26. matrix.
  27. */
  28. /*
  29. * An attempt has been made to make this module switch threads on qread
  30. * calls. It is far from safe, though.
  31. */
  32. #include <gl.h>
  33. #include <device.h>
  34. #ifdef __sgi
  35. extern int devport();
  36. extern int textwritemask();
  37. extern int pagewritemask();
  38. extern int gewrite();
  39. extern int gettp();
  40. #endif
  41. #include "Python.h"
  42. #include "cgensupport.h"
  43. /*
  44. Some stubs are too complicated for the stub generator.
  45. We can include manually written versions of them here.
  46. A line starting with '%' gives the name of the function so the stub
  47. generator can include it in the table of functions.
  48. */
  49. % qread
  50. static PyObject *
  51. gl_qread(self, args)
  52. PyObject *self;
  53. PyObject *args;
  54. {
  55. long retval;
  56. short arg1 ;
  57. Py_BEGIN_ALLOW_THREADS
  58. retval = qread( & arg1 );
  59. Py_END_ALLOW_THREADS
  60. { PyObject *v = PyTuple_New( 2 );
  61. if (v == NULL) return NULL;
  62. PyTuple_SetItem(v, 0, mknewlongobject(retval));
  63. PyTuple_SetItem(v, 1, mknewshortobject(arg1));
  64. return v;
  65. }
  66. }
  67. /*
  68. varray -- an array of v.. calls.
  69. The argument is an array (maybe list or tuple) of points.
  70. Each point must be a tuple or list of coordinates (x, y, z).
  71. The points may be 2- or 3-dimensional but must all have the
  72. same dimension. Float and int values may be mixed however.
  73. The points are always converted to 3D double precision points
  74. by assuming z=0.0 if necessary (as indicated in the man page),
  75. and for each point v3d() is called.
  76. */
  77. % varray
  78. static PyObject *
  79. gl_varray(self, args)
  80. PyObject *self;
  81. PyObject *args;
  82. {
  83. PyObject *v, *w=NULL;
  84. int i, n, width;
  85. double vec[3];
  86. PyObject * (*getitem)(PyObject *, int);
  87. if (!PyArg_GetObject(args, 1, 0, &v))
  88. return NULL;
  89. if (PyList_Check(v)) {
  90. n = PyList_Size(v);
  91. getitem = PyList_GetItem;
  92. }
  93. else if (PyTuple_Check(v)) {
  94. n = PyTuple_Size(v);
  95. getitem = PyTuple_GetItem;
  96. }
  97. else {
  98. PyErr_BadArgument();
  99. return NULL;
  100. }
  101. if (n == 0) {
  102. Py_INCREF(Py_None);
  103. return Py_None;
  104. }
  105. if (n > 0)
  106. w = (*getitem)(v, 0);
  107. width = 0;
  108. if (w == NULL) {
  109. }
  110. else if (PyList_Check(w)) {
  111. width = PyList_Size(w);
  112. }
  113. else if (PyTuple_Check(w)) {
  114. width = PyTuple_Size(w);
  115. }
  116. switch (width) {
  117. case 2:
  118. vec[2] = 0.0;
  119. /* Fall through */
  120. case 3:
  121. break;
  122. default:
  123. PyErr_BadArgument();
  124. return NULL;
  125. }
  126. for (i = 0; i < n; i++) {
  127. w = (*getitem)(v, i);
  128. if (!PyArg_GetDoubleArray(w, 1, 0, width, vec))
  129. return NULL;
  130. v3d(vec);
  131. }
  132. Py_INCREF(Py_None);
  133. return Py_None;
  134. }
  135. /*
  136. vnarray, nvarray -- an array of n3f and v3f calls.
  137. The argument is an array (list or tuple) of pairs of points and normals.
  138. Each pair is a tuple (NOT a list) of a point and a normal for that point.
  139. Each point or normal must be a tuple (NOT a list) of coordinates (x, y, z).
  140. Three coordinates must be given. Float and int values may be mixed.
  141. For each pair, n3f() is called for the normal, and then v3f() is called
  142. for the vector.
  143. vnarray and nvarray differ only in the order of the vector and normal in
  144. the pair: vnarray expects (v, n) while nvarray expects (n, v).
  145. */
  146. static PyObject *gen_nvarray(); /* Forward */
  147. % nvarray
  148. static PyObject *
  149. gl_nvarray(self, args)
  150. PyObject *self;
  151. PyObject *args;
  152. {
  153. return gen_nvarray(args, 0);
  154. }
  155. % vnarray
  156. static PyObject *
  157. gl_vnarray(self, args)
  158. PyObject *self;
  159. PyObject *args;
  160. {
  161. return gen_nvarray(args, 1);
  162. }
  163. /* Generic, internal version of {nv,nv}array: inorm indicates the
  164. argument order, 0: normal first, 1: vector first. */
  165. static PyObject *
  166. gen_nvarray(args, inorm)
  167. PyObject *args;
  168. int inorm;
  169. {
  170. PyObject *v, *w, *wnorm, *wvec;
  171. int i, n;
  172. float norm[3], vec[3];
  173. PyObject * (*getitem)(PyObject *, int);
  174. if (!PyArg_GetObject(args, 1, 0, &v))
  175. return NULL;
  176. if (PyList_Check(v)) {
  177. n = PyList_Size(v);
  178. getitem = PyList_GetItem;
  179. }
  180. else if (PyTuple_Check(v)) {
  181. n = PyTuple_Size(v);
  182. getitem = PyTuple_GetItem;
  183. }
  184. else {
  185. PyErr_BadArgument();
  186. return NULL;
  187. }
  188. for (i = 0; i < n; i++) {
  189. w = (*getitem)(v, i);
  190. if (!PyTuple_Check(w) || PyTuple_Size(w) != 2) {
  191. PyErr_BadArgument();
  192. return NULL;
  193. }
  194. wnorm = PyTuple_GetItem(w, inorm);
  195. wvec = PyTuple_GetItem(w, 1 - inorm);
  196. if (!PyArg_GetFloatArray(wnorm, 1, 0, 3, norm) ||
  197. !PyArg_GetFloatArray(wvec, 1, 0, 3, vec))
  198. return NULL;
  199. n3f(norm);
  200. v3f(vec);
  201. }
  202. Py_INCREF(Py_None);
  203. return Py_None;
  204. }
  205. /* nurbssurface(s_knots[], t_knots[], ctl[][], s_order, t_order, type).
  206. The dimensions of ctl[] are computed as follows:
  207. [len(s_knots) - s_order], [len(t_knots) - t_order]
  208. */
  209. % nurbssurface
  210. static PyObject *
  211. gl_nurbssurface(self, args)
  212. PyObject *self;
  213. PyObject *args;
  214. {
  215. long arg1 ;
  216. double * arg2 ;
  217. long arg3 ;
  218. double * arg4 ;
  219. double *arg5 ;
  220. long arg6 ;
  221. long arg7 ;
  222. long arg8 ;
  223. long ncoords;
  224. long s_byte_stride, t_byte_stride;
  225. long s_nctl, t_nctl;
  226. long s, t;
  227. PyObject *v, *w, *pt;
  228. double *pnext;
  229. if (!PyArg_GetLongArraySize(args, 6, 0, &arg1))
  230. return NULL;
  231. if ((arg2 = PyMem_NEW(double, arg1 )) == NULL) {
  232. return PyErr_NoMemory();
  233. }
  234. if (!PyArg_GetDoubleArray(args, 6, 0, arg1 , arg2))
  235. return NULL;
  236. if (!PyArg_GetLongArraySize(args, 6, 1, &arg3))
  237. return NULL;
  238. if ((arg4 = PyMem_NEW(double, arg3 )) == NULL) {
  239. return PyErr_NoMemory();
  240. }
  241. if (!PyArg_GetDoubleArray(args, 6, 1, arg3 , arg4))
  242. return NULL;
  243. if (!PyArg_GetLong(args, 6, 3, &arg6))
  244. return NULL;
  245. if (!PyArg_GetLong(args, 6, 4, &arg7))
  246. return NULL;
  247. if (!PyArg_GetLong(args, 6, 5, &arg8))
  248. return NULL;
  249. if (arg8 == N_XYZ)
  250. ncoords = 3;
  251. else if (arg8 == N_XYZW)
  252. ncoords = 4;
  253. else {
  254. PyErr_BadArgument();
  255. return NULL;
  256. }
  257. s_nctl = arg1 - arg6;
  258. t_nctl = arg3 - arg7;
  259. if (!PyArg_GetObject(args, 6, 2, &v))
  260. return NULL;
  261. if (!PyList_Check(v) || PyList_Size(v) != s_nctl) {
  262. PyErr_BadArgument();
  263. return NULL;
  264. }
  265. if ((arg5 = PyMem_NEW(double, s_nctl*t_nctl*ncoords )) == NULL) {
  266. return PyErr_NoMemory();
  267. }
  268. pnext = arg5;
  269. for (s = 0; s < s_nctl; s++) {
  270. w = PyList_GetItem(v, s);
  271. if (w == NULL || !PyList_Check(w) ||
  272. PyList_Size(w) != t_nctl) {
  273. PyErr_BadArgument();
  274. return NULL;
  275. }
  276. for (t = 0; t < t_nctl; t++) {
  277. pt = PyList_GetItem(w, t);
  278. if (!PyArg_GetDoubleArray(pt, 1, 0, ncoords, pnext))
  279. return NULL;
  280. pnext += ncoords;
  281. }
  282. }
  283. s_byte_stride = sizeof(double) * ncoords;
  284. t_byte_stride = s_byte_stride * s_nctl;
  285. nurbssurface( arg1 , arg2 , arg3 , arg4 ,
  286. s_byte_stride , t_byte_stride , arg5 , arg6 , arg7 , arg8 );
  287. PyMem_DEL(arg2);
  288. PyMem_DEL(arg4);
  289. PyMem_DEL(arg5);
  290. Py_INCREF(Py_None);
  291. return Py_None;
  292. }
  293. /* nurbscurve(knots, ctlpoints, order, type).
  294. The length of ctlpoints is len(knots)-order. */
  295. %nurbscurve
  296. static PyObject *
  297. gl_nurbscurve(self, args)
  298. PyObject *self;
  299. PyObject *args;
  300. {
  301. long arg1 ;
  302. double * arg2 ;
  303. long arg3 ;
  304. double * arg4 ;
  305. long arg5 ;
  306. long arg6 ;
  307. int ncoords, npoints;
  308. int i;
  309. PyObject *v;
  310. double *pnext;
  311. if (!PyArg_GetLongArraySize(args, 4, 0, &arg1))
  312. return NULL;
  313. if ((arg2 = PyMem_NEW(double, arg1 )) == NULL) {
  314. return PyErr_NoMemory();
  315. }
  316. if (!PyArg_GetDoubleArray(args, 4, 0, arg1 , arg2))
  317. return NULL;
  318. if (!PyArg_GetLong(args, 4, 2, &arg5))
  319. return NULL;
  320. if (!PyArg_GetLong(args, 4, 3, &arg6))
  321. return NULL;
  322. if (arg6 == N_ST)
  323. ncoords = 2;
  324. else if (arg6 == N_STW)
  325. ncoords = 3;
  326. else {
  327. PyErr_BadArgument();
  328. return NULL;
  329. }
  330. npoints = arg1 - arg5;
  331. if (!PyArg_GetObject(args, 4, 1, &v))
  332. return NULL;
  333. if (!PyList_Check(v) || PyList_Size(v) != npoints) {
  334. PyErr_BadArgument();
  335. return NULL;
  336. }
  337. if ((arg4 = PyMem_NEW(double, npoints*ncoords )) == NULL) {
  338. return PyErr_NoMemory();
  339. }
  340. pnext = arg4;
  341. for (i = 0; i < npoints; i++) {
  342. if (!PyArg_GetDoubleArray(PyList_GetItem(v, i), 1, 0, ncoords, pnext))
  343. return NULL;
  344. pnext += ncoords;
  345. }
  346. arg3 = (sizeof(double)) * ncoords;
  347. nurbscurve( arg1 , arg2 , arg3 , arg4 , arg5 , arg6 );
  348. PyMem_DEL(arg2);
  349. PyMem_DEL(arg4);
  350. Py_INCREF(Py_None);
  351. return Py_None;
  352. }
  353. /* pwlcurve(points, type).
  354. Points is a list of points. Type must be N_ST. */
  355. %pwlcurve
  356. static PyObject *
  357. gl_pwlcurve(self, args)
  358. PyObject *self;
  359. PyObject *args;
  360. {
  361. PyObject *v;
  362. long type;
  363. double *data, *pnext;
  364. long npoints, ncoords;
  365. int i;
  366. if (!PyArg_GetObject(args, 2, 0, &v))
  367. return NULL;
  368. if (!PyArg_GetLong(args, 2, 1, &type))
  369. return NULL;
  370. if (!PyList_Check(v)) {
  371. PyErr_BadArgument();
  372. return NULL;
  373. }
  374. npoints = PyList_Size(v);
  375. if (type == N_ST)
  376. ncoords = 2;
  377. else {
  378. PyErr_BadArgument();
  379. return NULL;
  380. }
  381. if ((data = PyMem_NEW(double, npoints*ncoords)) == NULL) {
  382. return PyErr_NoMemory();
  383. }
  384. pnext = data;
  385. for (i = 0; i < npoints; i++) {
  386. if (!PyArg_GetDoubleArray(PyList_GetItem(v, i), 1, 0, ncoords, pnext))
  387. return NULL;
  388. pnext += ncoords;
  389. }
  390. pwlcurve(npoints, data, sizeof(double)*ncoords, type);
  391. PyMem_DEL(data);
  392. Py_INCREF(Py_None);
  393. return Py_None;
  394. }
  395. /* Picking and Selecting */
  396. static short *pickbuffer = NULL;
  397. static long pickbuffersize;
  398. static PyObject *
  399. pick_select(args, func)
  400. PyObject *args;
  401. void (*func)();
  402. {
  403. if (!PyArg_GetLong(args, 1, 0, &pickbuffersize))
  404. return NULL;
  405. if (pickbuffer != NULL) {
  406. PyErr_SetString(PyExc_RuntimeError,
  407. "pick/gselect: already picking/selecting");
  408. return NULL;
  409. }
  410. if ((pickbuffer = PyMem_NEW(short, pickbuffersize)) == NULL) {
  411. return PyErr_NoMemory();
  412. }
  413. (*func)(pickbuffer, pickbuffersize);
  414. Py_INCREF(Py_None);
  415. return Py_None;
  416. }
  417. static PyObject *
  418. endpick_select(args, func)
  419. PyObject *args;
  420. long (*func)();
  421. {
  422. PyObject *v, *w;
  423. int i, nhits, n;
  424. if (!PyArg_NoArgs(args))
  425. return NULL;
  426. if (pickbuffer == NULL) {
  427. PyErr_SetString(PyExc_RuntimeError,
  428. "endpick/endselect: not in pick/select mode");
  429. return NULL;
  430. }
  431. nhits = (*func)(pickbuffer);
  432. if (nhits < 0) {
  433. nhits = -nhits; /* How to report buffer overflow otherwise? */
  434. }
  435. /* Scan the buffer to see how many integers */
  436. n = 0;
  437. for (; nhits > 0; nhits--) {
  438. n += 1 + pickbuffer[n];
  439. }
  440. v = PyList_New(n);
  441. if (v == NULL)
  442. return NULL;
  443. /* XXX Could do it nicer and interpret the data structure here,
  444. returning a list of lists. But this can be done in Python... */
  445. for (i = 0; i < n; i++) {
  446. w = PyInt_FromLong((long)pickbuffer[i]);
  447. if (w == NULL) {
  448. Py_DECREF(v);
  449. return NULL;
  450. }
  451. PyList_SetItem(v, i, w);
  452. }
  453. PyMem_DEL(pickbuffer);
  454. pickbuffer = NULL;
  455. return v;
  456. }
  457. extern void pick(), gselect();
  458. extern long endpick(), endselect();
  459. %pick
  460. static PyObject *gl_pick(self, args) PyObject *self, *args; {
  461. return pick_select(args, pick);
  462. }
  463. %endpick
  464. static PyObject *gl_endpick(self, args) PyObject *self, *args; {
  465. return endpick_select(args, endpick);
  466. }
  467. %gselect
  468. static PyObject *gl_gselect(self, args) PyObject *self, *args; {
  469. return pick_select(args, gselect);
  470. }
  471. %endselect
  472. static PyObject *gl_endselect(self, args) PyObject *self, *args; {
  473. return endpick_select(args, endselect);
  474. }
  475. /* XXX The generator botches this one. Here's a quick hack to fix it. */
  476. /* XXX The generator botches this one. Here's a quick hack to fix it. */
  477. % getmatrix float r[16]
  478. static PyObject *
  479. gl_getmatrix(self, args)
  480. PyObject *self;
  481. PyObject *args;
  482. {
  483. Matrix arg1;
  484. PyObject *v, *w;
  485. int i, j;
  486. getmatrix( arg1 );
  487. v = PyList_New(16);
  488. if (v == NULL) {
  489. return PyErr_NoMemory();
  490. }
  491. for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) {
  492. w = mknewfloatobject(arg1[i][j]);
  493. if (w == NULL) {
  494. Py_DECREF(v);
  495. return NULL;
  496. }
  497. PyList_SetItem(v, i*4+j, w);
  498. }
  499. return v;
  500. }
  501. /* Here's an alternate version that returns a 4x4 matrix instead of
  502. a vector. Unfortunately it is incompatible with loadmatrix and
  503. multmatrix... */
  504. % altgetmatrix float r[4][4]
  505. static PyObject *
  506. gl_altgetmatrix(self, args)
  507. PyObject *self;
  508. PyObject *args;
  509. {
  510. Matrix arg1;
  511. PyObject *v, *w;
  512. int i, j;
  513. getmatrix( arg1 );
  514. v = PyList_New(4);
  515. if (v == NULL) {
  516. return NULL;
  517. }
  518. for (i = 0; i < 4; i++) {
  519. w = PyList_New(4);
  520. if (w == NULL) {
  521. Py_DECREF(v);
  522. return NULL;
  523. }
  524. PyList_SetItem(v, i, w);
  525. }
  526. for (i = 0; i < 4; i++) {
  527. for (j = 0; j < 4; j++) {
  528. w = mknewfloatobject(arg1[i][j]);
  529. if (w == NULL) {
  530. Py_DECREF(v);
  531. return NULL;
  532. }
  533. PyList_SetItem(PyList_GetItem(v, i), j, w);
  534. }
  535. }
  536. return v;
  537. }
  538. % lrectwrite
  539. static PyObject *
  540. gl_lrectwrite(self, args)
  541. PyObject *self;
  542. PyObject *args;
  543. {
  544. short x1 ;
  545. short y1 ;
  546. short x2 ;
  547. short y2 ;
  548. string parray ;
  549. PyObject *s;
  550. #if 0
  551. int pixcount;
  552. #endif
  553. if (!PyArg_GetShort(args, 5, 0, &x1))
  554. return NULL;
  555. if (!PyArg_GetShort(args, 5, 1, &y1))
  556. return NULL;
  557. if (!PyArg_GetShort(args, 5, 2, &x2))
  558. return NULL;
  559. if (!PyArg_GetShort(args, 5, 3, &y2))
  560. return NULL;
  561. if (!PyArg_GetString(args, 5, 4, &parray))
  562. return NULL;
  563. if (!PyArg_GetObject(args, 5, 4, &s))
  564. return NULL;
  565. #if 0
  566. /* Don't check this, it breaks experiments with pixmode(PM_SIZE, ...) */
  567. pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
  568. if (!PyString_Check(s) || PyString_Size(s) != pixcount*sizeof(long)) {
  569. PyErr_SetString(PyExc_RuntimeError,
  570. "string arg to lrectwrite has wrong size");
  571. return NULL;
  572. }
  573. #endif
  574. lrectwrite( x1 , y1 , x2 , y2 , (unsigned long *) parray );
  575. Py_INCREF(Py_None);
  576. return Py_None;
  577. }
  578. % lrectread
  579. static PyObject *
  580. gl_lrectread(self, args)
  581. PyObject *self;
  582. PyObject *args;
  583. {
  584. short x1 ;
  585. short y1 ;
  586. short x2 ;
  587. short y2 ;
  588. PyObject *parray;
  589. int pixcount;
  590. if (!PyArg_GetShort(args, 4, 0, &x1))
  591. return NULL;
  592. if (!PyArg_GetShort(args, 4, 1, &y1))
  593. return NULL;
  594. if (!PyArg_GetShort(args, 4, 2, &x2))
  595. return NULL;
  596. if (!PyArg_GetShort(args, 4, 3, &y2))
  597. return NULL;
  598. pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
  599. parray = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
  600. if (parray == NULL)
  601. return NULL; /* No memory */
  602. lrectread(x1, y1, x2, y2, (unsigned long *) PyString_AsString(parray));
  603. return parray;
  604. }
  605. % readdisplay
  606. static PyObject *
  607. gl_readdisplay(self, args)
  608. PyObject *self;
  609. PyObject *args;
  610. {
  611. short x1, y1, x2, y2;
  612. unsigned long *parray, hints;
  613. long size, size_ret;
  614. PyObject *rv;
  615. if ( !PyArg_Parse(args, "hhhhl", &x1, &y1, &x2, &y2, &hints) )
  616. return 0;
  617. size = (long)(x2+1-x1) * (long)(y2+1-y1);
  618. rv = PyString_FromStringAndSize((char *)NULL, size*sizeof(long));
  619. if ( rv == NULL )
  620. return NULL;
  621. parray = (unsigned long *)PyString_AsString(rv);
  622. size_ret = readdisplay(x1, y1, x2, y2, parray, hints);
  623. if ( size_ret != size ) {
  624. printf("gl_readdisplay: got %ld pixels, expected %ld\n",
  625. size_ret, size);
  626. PyErr_SetString(PyExc_RuntimeError, "readdisplay returned unexpected length");
  627. return NULL;
  628. }
  629. return rv;
  630. }
  631. /* Desperately needed, here are tools to compress and decompress
  632. the data manipulated by lrectread/lrectwrite.
  633. gl.packrect(width, height, packfactor, bigdata) --> smalldata
  634. makes 'bigdata' 4*(packfactor**2) times smaller by:
  635. - turning it into B/W (a factor 4)
  636. - replacing squares of size pacfactor by one
  637. representative
  638. gl.unpackrect(width, height, packfactor, smalldata) --> bigdata
  639. is the inverse; the numeric arguments must be *the same*.
  640. Both work best if width and height are multiples of packfactor
  641. (in fact unpackrect will leave garbage bytes).
  642. */
  643. % packrect
  644. static PyObject *
  645. gl_packrect(self, args)
  646. PyObject *self;
  647. PyObject *args;
  648. {
  649. long width, height, packfactor;
  650. char *s;
  651. PyObject *unpacked, *packed;
  652. int pixcount, packedcount, x, y, r, g, b;
  653. unsigned long pixel;
  654. unsigned char *p;
  655. unsigned long *parray;
  656. if (!PyArg_GetLong(args, 4, 0, &width))
  657. return NULL;
  658. if (!PyArg_GetLong(args, 4, 1, &height))
  659. return NULL;
  660. if (!PyArg_GetLong(args, 4, 2, &packfactor))
  661. return NULL;
  662. if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */
  663. return NULL;
  664. if (!PyArg_GetObject(args, 4, 3, &unpacked))
  665. return NULL;
  666. if (width <= 0 || height <= 0 || packfactor <= 0) {
  667. PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0");
  668. return NULL;
  669. }
  670. pixcount = width*height;
  671. packedcount = ((width+packfactor-1)/packfactor) *
  672. ((height+packfactor-1)/packfactor);
  673. if (PyString_Size(unpacked) != pixcount*sizeof(long)) {
  674. PyErr_SetString(PyExc_RuntimeError,
  675. "string arg to packrect has wrong size");
  676. return NULL;
  677. }
  678. packed = PyString_FromStringAndSize((char *)NULL, packedcount);
  679. if (packed == NULL)
  680. return NULL;
  681. parray = (unsigned long *) PyString_AsString(unpacked);
  682. p = (unsigned char *) PyString_AsString(packed);
  683. for (y = 0; y < height; y += packfactor, parray += packfactor*width) {
  684. for (x = 0; x < width; x += packfactor) {
  685. pixel = parray[x];
  686. r = pixel & 0xff;
  687. g = (pixel >> 8) & 0xff;
  688. b = (pixel >> 16) & 0xff;
  689. *p++ = (30*r+59*g+11*b) / 100;
  690. }
  691. }
  692. return packed;
  693. }
  694. % unpackrect
  695. static unsigned long unpacktab[256];
  696. static int unpacktab_inited = 0;
  697. static PyObject *
  698. gl_unpackrect(self, args)
  699. PyObject *self;
  700. PyObject *args;
  701. {
  702. long width, height, packfactor;
  703. char *s;
  704. PyObject *unpacked, *packed;
  705. int pixcount, packedcount;
  706. register unsigned char *p;
  707. register unsigned long *parray;
  708. if (!unpacktab_inited) {
  709. register int white;
  710. for (white = 256; --white >= 0; )
  711. unpacktab[white] = white * 0x010101L;
  712. unpacktab_inited++;
  713. }
  714. if (!PyArg_GetLong(args, 4, 0, &width))
  715. return NULL;
  716. if (!PyArg_GetLong(args, 4, 1, &height))
  717. return NULL;
  718. if (!PyArg_GetLong(args, 4, 2, &packfactor))
  719. return NULL;
  720. if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */
  721. return NULL;
  722. if (!PyArg_GetObject(args, 4, 3, &packed))
  723. return NULL;
  724. if (width <= 0 || height <= 0 || packfactor <= 0) {
  725. PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0");
  726. return NULL;
  727. }
  728. pixcount = width*height;
  729. packedcount = ((width+packfactor-1)/packfactor) *
  730. ((height+packfactor-1)/packfactor);
  731. if (PyString_Size(packed) != packedcount) {
  732. PyErr_SetString(PyExc_RuntimeError,
  733. "string arg to unpackrect has wrong size");
  734. return NULL;
  735. }
  736. unpacked = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
  737. if (unpacked == NULL)
  738. return NULL;
  739. parray = (unsigned long *) PyString_AsString(unpacked);
  740. p = (unsigned char *) PyString_AsString(packed);
  741. if (packfactor == 1 && width*height > 0) {
  742. /* Just expand bytes to longs */
  743. register int x = width * height;
  744. do {
  745. *parray++ = unpacktab[*p++];
  746. } while (--x >= 0);
  747. }
  748. else {
  749. register int y;
  750. for (y = 0; y < height-packfactor+1;
  751. y += packfactor, parray += packfactor*width) {
  752. register int x;
  753. for (x = 0; x < width-packfactor+1; x += packfactor) {
  754. register unsigned long pixel = unpacktab[*p++];
  755. register int i;
  756. for (i = packfactor*width; (i-=width) >= 0;) {
  757. register int j;
  758. for (j = packfactor; --j >= 0; )
  759. parray[i+x+j] = pixel;
  760. }
  761. }
  762. }
  763. }
  764. return unpacked;
  765. }
  766. % gversion
  767. static PyObject *
  768. gl_gversion(self, args)
  769. PyObject *self;
  770. PyObject *args;
  771. {
  772. char buf[20];
  773. gversion(buf);
  774. return PyString_FromString(buf);
  775. }
  776. /* void clear - Manual because of clash with termcap */
  777. %clear
  778. static PyObject *
  779. gl_clear(self, args)
  780. PyObject *self;
  781. PyObject *args;
  782. {
  783. __GLclear( );
  784. Py_INCREF(Py_None);
  785. return Py_None;
  786. }
  787. /* End of manually written stubs */
  788. %%
  789. long getshade
  790. if !solaris void devport short s long s
  791. void rdr2i long s long s
  792. void rectfs short s short s short s short s
  793. void rects short s short s short s short s
  794. void rmv2i long s long s
  795. void noport
  796. void popviewport
  797. void clearhitcode
  798. void closeobj
  799. void cursoff
  800. void curson
  801. void doublebuffer
  802. void finish
  803. void gconfig
  804. void ginit
  805. void greset
  806. void multimap
  807. void onemap
  808. void popattributes
  809. void popmatrix
  810. void pushattributes
  811. void pushmatrix
  812. void pushviewport
  813. void qreset
  814. void RGBmode
  815. void singlebuffer
  816. void swapbuffers
  817. void gsync
  818. void gflush
  819. void tpon
  820. void tpoff
  821. void clkon
  822. void clkoff
  823. void ringbell
  824. #void callfunc
  825. void gbegin
  826. void textinit
  827. void initnames
  828. void pclos
  829. void popname
  830. if !solaris void spclos
  831. void zclear
  832. void screenspace
  833. void reshapeviewport
  834. void winpush
  835. void winpop
  836. void foreground
  837. void endfullscrn
  838. if !solaris void endpupmode
  839. void fullscrn
  840. if !solaris void pupmode
  841. void winconstraints
  842. void pagecolor short s
  843. void textcolor short s
  844. void color short s
  845. void curveit short s
  846. void font short s
  847. void linewidth short s
  848. void setlinestyle short s
  849. void setmap short s
  850. void swapinterval short s
  851. void writemask short s
  852. if !solaris void textwritemask short s
  853. void qdevice short s
  854. void unqdevice short s
  855. void curvebasis short s
  856. void curveprecision short s
  857. void loadname short s
  858. void passthrough short s
  859. void pushname short s
  860. void setmonitor short s
  861. if !solaris void setshade short s
  862. void setpattern short s
  863. if !solaris void pagewritemask short s
  864. #
  865. void callobj long s
  866. void delobj long s
  867. void editobj long s
  868. void makeobj long s
  869. void maketag long s
  870. void chunksize long s
  871. void compactify long s
  872. void deltag long s
  873. void lsrepeat long s
  874. void objinsert long s
  875. void objreplace long s
  876. void winclose long s
  877. void blanktime long s
  878. void freepup long s
  879. # This is not in the library!?
  880. ###void pupcolor long s
  881. #
  882. void backbuffer long s
  883. void frontbuffer long s
  884. if !solaris void lsbackup long s
  885. void resetls long s
  886. void lampon long s
  887. void lampoff long s
  888. void setbell long s
  889. void blankscreen long s
  890. void depthcue long s
  891. void zbuffer long s
  892. void backface long s
  893. #
  894. void cmov2i long s long s
  895. void draw2i long s long s
  896. void move2i long s long s
  897. void pnt2i long s long s
  898. void patchbasis long s long s
  899. void patchprecision long s long s
  900. void pdr2i long s long s
  901. void pmv2i long s long s
  902. void rpdr2i long s long s
  903. void rpmv2i long s long s
  904. void xfpt2i long s long s
  905. void objdelete long s long s
  906. void patchcurves long s long s
  907. void minsize long s long s
  908. void maxsize long s long s
  909. void keepaspect long s long s
  910. void prefsize long s long s
  911. void stepunit long s long s
  912. void fudge long s long s
  913. void winmove long s long s
  914. #
  915. void attachcursor short s short s
  916. void deflinestyle short s short s
  917. void noise short s short s
  918. void picksize short s short s
  919. void qenter short s short s
  920. void setdepth short s short s
  921. void cmov2s short s short s
  922. void draw2s short s short s
  923. void move2s short s short s
  924. void pdr2s short s short s
  925. void pmv2s short s short s
  926. void pnt2s short s short s
  927. void rdr2s short s short s
  928. void rmv2s short s short s
  929. void rpdr2s short s short s
  930. void rpmv2s short s short s
  931. void xfpt2s short s short s
  932. #
  933. void cmov2 float s float s
  934. void draw2 float s float s
  935. void move2 float s float s
  936. void pnt2 float s float s
  937. void pdr2 float s float s
  938. void pmv2 float s float s
  939. void rdr2 float s float s
  940. void rmv2 float s float s
  941. void rpdr2 float s float s
  942. void rpmv2 float s float s
  943. void xfpt2 float s float s
  944. #
  945. void loadmatrix float s[4*4]
  946. # Really [4][4]
  947. void multmatrix float s[4*4]
  948. # Really [4][4]
  949. void crv float s[3*4]
  950. # Really [4][3]
  951. void rcrv float s[4*4]
  952. # Really [4][4]
  953. #
  954. # Methods that have strings.
  955. #
  956. void addtopup long s char *s long s
  957. void charstr char *s
  958. void getport char *s
  959. long strwidth char *s
  960. long winopen char *s
  961. void wintitle char *s
  962. #
  963. # Methods that have 1 long (# of elements) and an array
  964. #
  965. void polf long s float s[3*arg1]
  966. void polf2 long s float s[2*arg1]
  967. void poly long s float s[3*arg1]
  968. void poly2 long s float s[2*arg1]
  969. void crvn long s float s[3*arg1]
  970. void rcrvn long s float s[4*arg1]
  971. #
  972. void polf2i long s long s[2*arg1]
  973. void polfi long s long s[3*arg1]
  974. void poly2i long s long s[2*arg1]
  975. void polyi long s long s[3*arg1]
  976. #
  977. void polf2s long s short s[2*arg1]
  978. void polfs long s short s[3*arg1]
  979. void polys long s short s[3*arg1]
  980. void poly2s long s short s[2*arg1]
  981. #
  982. void defcursor short s u_short s[128]
  983. # Is this useful?
  984. void writepixels short s u_short s[arg1]
  985. # Should be unsigned short...
  986. void defbasis long s float s[4*4]
  987. if !solaris void gewrite short s short s[arg1]
  988. #
  989. void rotate short s char s
  990. # This is not in the library!?
  991. ###void setbutton short s char s
  992. void rot float s char s
  993. #
  994. void circfi long s long s long s
  995. void circi long s long s long s
  996. void cmovi long s long s long s
  997. void drawi long s long s long s
  998. void movei long s long s long s
  999. void pnti long s long s long s
  1000. void newtag long s long s long s
  1001. void pdri long s long s long s
  1002. void pmvi long s long s long s
  1003. void rdri long s long s long s
  1004. void rmvi long s long s long s
  1005. void rpdri long s long s long s
  1006. void rpmvi long s long s long s
  1007. void xfpti long s long s long s
  1008. #
  1009. void circ float s float s float s
  1010. void circf float s float s float s
  1011. void cmov float s float s float s
  1012. void draw float s float s float s
  1013. void move float s float s float s
  1014. void pnt float s float s float s
  1015. void scale float s float s float s
  1016. void translate float s float s float s
  1017. void pdr float s float s float s
  1018. void pmv float s float s float s
  1019. void rdr float s float s float s
  1020. void rmv float s float s float s
  1021. void rpdr float s float s float s
  1022. void rpmv float s float s float s
  1023. void xfpt float s float s float s
  1024. #
  1025. void RGBcolor short s short s short s
  1026. void RGBwritemask short s short s short s
  1027. void setcursor short s short s short s
  1028. void tie short s short s short s
  1029. void circfs short s short s short s
  1030. void circs short s short s short s
  1031. void cmovs short s short s short s
  1032. void draws short s short s short s
  1033. void moves short s short s short s
  1034. void pdrs short s short s short s
  1035. void pmvs short s short s short s
  1036. void pnts short s short s short s
  1037. void rdrs short s short s short s
  1038. void rmvs short s short s short s
  1039. void rpdrs short s short s short s
  1040. void rpmvs short s short s short s
  1041. void xfpts short s short s short s
  1042. void curorigin short s short s short s
  1043. void cyclemap short s short s short s
  1044. #
  1045. void patch float s[4*4] float s[4*4] float s[4*4]
  1046. void splf long s float s[3*arg1] u_short s[arg1]
  1047. void splf2 long s float s[2*arg1] u_short s[arg1]
  1048. void splfi long s long s[3*arg1] u_short s[arg1]
  1049. void splf2i long s long s[2*arg1] u_short s[arg1]
  1050. void splfs long s short s[3*arg1] u_short s[arg1]
  1051. void splf2s long s short s[2*arg1] u_short s[arg1]
  1052. ###void defpattern short s short s u_short s[arg2*arg2/16]
  1053. #
  1054. void rpatch float s[4*4] float s[4*4] float s[4*4] float s[4*4]
  1055. #
  1056. # routines that send 4 floats
  1057. #
  1058. void ortho2 float s float s float s float s
  1059. void rect float s float s float s float s
  1060. void rectf float s float s float s float s
  1061. void xfpt4 float s float s float s float s
  1062. #
  1063. void textport short s short s short s short s
  1064. void mapcolor short s short s short s short s
  1065. void scrmask short s short s short s short s
  1066. void setvaluator short s short s short s short s
  1067. void viewport short s short s short s short s
  1068. void shaderange short s short s short s short s
  1069. void xfpt4s short s short s short s short s
  1070. void rectfi long s long s long s long s
  1071. void recti long s long s long s long s
  1072. void xfpt4i long s long s long s long s
  1073. void prefposition long s long s long s long s
  1074. #
  1075. void arc float s float s float s short s short s
  1076. void arcf float s float s float s short s short s
  1077. void arcfi long s long s long s short s short s
  1078. void arci long s long s long s short s short s
  1079. #
  1080. void bbox2 short s short s float s float s float s float s
  1081. void bbox2i short s short s long s long s long s long s
  1082. void bbox2s short s short s short s short s short s short s
  1083. void blink short s short s short s short s short s
  1084. void ortho float s float s float s float s float s float s
  1085. void window float s float s float s float s float s float s
  1086. void lookat float s float s float s float s float s float s short s
  1087. #
  1088. void perspective short s float s float s float s
  1089. void polarview float s short s short s short s
  1090. # XXX getichararray not supported
  1091. #void writeRGB short s char s[arg1] char s[arg1] char s[arg1]
  1092. #
  1093. void arcfs short s short s short s short s short s
  1094. void arcs short s short s short s short s short s
  1095. void rectcopy short s short s short s short s short s short s
  1096. if !solaris void RGBcursor short s short s short s short s short s short s short s
  1097. #
  1098. long getbutton short s
  1099. long getcmmode
  1100. long getlsbackup
  1101. long getresetls
  1102. long getdcm
  1103. long getzbuffer
  1104. long ismex
  1105. long isobj long s
  1106. long isqueued short s
  1107. long istag long s
  1108. #
  1109. long genobj
  1110. long gentag
  1111. long getbuffer
  1112. long getcolor
  1113. long getdisplaymode
  1114. long getfont
  1115. long getheight
  1116. long gethitcode
  1117. long getlstyle
  1118. long getlwidth
  1119. long getmap
  1120. long getplanes
  1121. long getwritemask
  1122. long qtest
  1123. long getlsrepeat
  1124. long getmonitor
  1125. long getopenobj
  1126. long getpattern
  1127. long winget
  1128. long winattach
  1129. long getothermonitor
  1130. long newpup
  1131. #
  1132. long getvaluator short s
  1133. void winset long s
  1134. long dopup long s
  1135. void getdepth short r short r
  1136. void getcpos short r short r
  1137. void getsize long r long r
  1138. void getorigin long r long r
  1139. void getviewport short r short r short r short r
  1140. if !solaris void gettp short r short r short r short r
  1141. void getgpos float r float r float r float r
  1142. void winposition long s long s long s long s
  1143. void gRGBcolor short r short r short r
  1144. void gRGBmask short r short r short r
  1145. void getscrmask short r short r short r short r
  1146. ###void gRGBcursor short r short r short r short r short r short r short r short r
  1147. void getmcolor short s short r short r short r
  1148. void mapw long s short s short s float r float r float r float r float r float r
  1149. void mapw2 long s short s short s float r float r
  1150. ###void defrasterfont short s short s short s Fontchar s[arg3] short s short s[4*arg5]
  1151. ###long qread short r
  1152. void getcursor short r u_short r u_short r long r
  1153. #
  1154. # For these we receive arrays of stuff
  1155. #
  1156. ###void getdev long s short s[arg1] short r[arg1]
  1157. #XXX not generated correctly yet
  1158. #void getmatrix float r[16]
  1159. ###long readpixels short s short r[retval]
  1160. ###long readRGB short s char r[retval] char r[retval] char r[retval]
  1161. ###long blkqread short s short r[arg1]
  1162. #
  1163. # New 4D routines
  1164. #
  1165. void cmode
  1166. void concave long s
  1167. void curstype long s
  1168. void drawmode long s
  1169. void gammaramp short s[256] short s[256] short s[256]
  1170. long getbackface
  1171. long getdescender
  1172. long getdrawmode
  1173. long getmmode
  1174. long getsm
  1175. long getvideo long s
  1176. void imakebackground
  1177. void lmbind short s short s
  1178. void lmdef long s long s long s float s[arg3]
  1179. void mmode long s
  1180. void normal float s[3]
  1181. void overlay long s
  1182. void RGBrange short s short s short s short s short s short s short s short s
  1183. if !solaris void setvideo long s long s
  1184. void shademodel long s
  1185. void underlay long s
  1186. #
  1187. # New Personal Iris/GT Routines
  1188. #
  1189. void bgnclosedline
  1190. void bgnline
  1191. void bgnpoint
  1192. void bgnpolygon
  1193. void bgnsurface
  1194. void bgntmesh
  1195. void bgntrim
  1196. void endclosedline
  1197. void endline
  1198. void endpoint
  1199. void endpolygon
  1200. void endsurface
  1201. void endtmesh
  1202. void endtrim
  1203. void blendfunction long s long s
  1204. void c3f float s[3]
  1205. void c3i long s[3]
  1206. void c3s short s[3]
  1207. void c4f float s[4]
  1208. void c4i long s[4]
  1209. void c4s short s[4]
  1210. void colorf float s
  1211. void cpack long s
  1212. void czclear long s long s
  1213. void dglclose long s
  1214. long dglopen char *s long s
  1215. long getgdesc long s
  1216. void getnurbsproperty long s float r
  1217. void glcompat long s long s
  1218. void iconsize long s long s
  1219. void icontitle char *s
  1220. void lRGBrange short s short s short s short s short s short s long s long s
  1221. void linesmooth long s
  1222. void lmcolor long s
  1223. void logicop long s
  1224. ###long lrectread short s short s short s short s long r[retval]
  1225. ###void lrectwrite short s short s short s short s long s[(arg2-arg1+1)*(arg4-arg3+1)]
  1226. ### Now manual, with string last arg
  1227. ###long rectread short s short s short s short s short r[retval]
  1228. ###void rectwrite short s short s short s short s short s[(arg2-arg1+1)*(arg4-arg3+1)]
  1229. void lsetdepth long s long s
  1230. void lshaderange short s short s long s long s
  1231. void n3f float s[3]
  1232. void noborder
  1233. void pntsmooth long s
  1234. void readsource long s
  1235. void rectzoom float s float s
  1236. void sbox float s float s float s float s
  1237. void sboxi long s long s long s long s
  1238. void sboxs short s short s short s short s
  1239. void sboxf float s float s float s float s
  1240. void sboxfi long s long s long s long s
  1241. void sboxfs short s short s short s short s
  1242. void setnurbsproperty long s float s
  1243. void setpup long s long s long s
  1244. void smoothline long s
  1245. void subpixel long s
  1246. void swaptmesh
  1247. long swinopen long s
  1248. void v2f float s[2]
  1249. void v2i long s[2]
  1250. void v2s short s[2]
  1251. void v3f float s[3]
  1252. void v3i long s[3]
  1253. void v3s short s[3]
  1254. void v4f float s[4]
  1255. void v4i long s[4]
  1256. void v4s short s[4]
  1257. void videocmd long s
  1258. long windepth long s
  1259. void wmpack long s
  1260. void zdraw long s
  1261. void zfunction long s
  1262. void zsource long s
  1263. void zwritemask long s
  1264. #
  1265. # uses doubles
  1266. #
  1267. void v2d double s[2]
  1268. void v3d double s[3]
  1269. void v4d double s[4]
  1270. #
  1271. # Why isn't this here?
  1272. #
  1273. void pixmode long s long s
  1274. #
  1275. # New in IRIX 4.0
  1276. #
  1277. long qgetfd
  1278. void dither long s