-
Notifications
You must be signed in to change notification settings - Fork 294
/
cstubs
1364 lines (1278 loc) · 32.4 KB
/
cstubs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Input used to generate the Python module "glmodule.c".
The stub generator is a Python script called "cgen.py".
Each definition must be contained on one line:
<returntype> <name> <type> <arg> <type> <arg>
<returntype> can be: void, short, long (XXX maybe others?)
<type> can be: char, string, short, float, long, or double
string indicates a null terminated string;
if <type> is char and <arg> begins with a *, the * is stripped
and <type> is changed into string
<arg> has the form <mode> or <mode>[<subscript>]
where <mode> can be
s: arg is sent
r: arg is received (arg is a pointer)
and <subscript> can be (N and I are numbers):
N
argI
retval
N*argI
N*I
N*retval
In the case where the subscript consists of two parts
separated by *, the first part is the width of the matrix, and
the second part is the length of the matrix. This order is
opposite from the order used in C to declare a two-dimensional
matrix.
*/
/*
* An attempt has been made to make this module switch threads on qread
* calls. It is far from safe, though.
*/
#include <gl.h>
#include <device.h>
#ifdef __sgi
extern int devport();
extern int textwritemask();
extern int pagewritemask();
extern int gewrite();
extern int gettp();
#endif
#include "Python.h"
#include "cgensupport.h"
/*
Some stubs are too complicated for the stub generator.
We can include manually written versions of them here.
A line starting with '%' gives the name of the function so the stub
generator can include it in the table of functions.
*/
% qread
static PyObject *
gl_qread(self, args)
PyObject *self;
PyObject *args;
{
long retval;
short arg1 ;
Py_BEGIN_ALLOW_THREADS
retval = qread( & arg1 );
Py_END_ALLOW_THREADS
{ PyObject *v = PyTuple_New( 2 );
if (v == NULL) return NULL;
PyTuple_SetItem(v, 0, mknewlongobject(retval));
PyTuple_SetItem(v, 1, mknewshortobject(arg1));
return v;
}
}
/*
varray -- an array of v.. calls.
The argument is an array (maybe list or tuple) of points.
Each point must be a tuple or list of coordinates (x, y, z).
The points may be 2- or 3-dimensional but must all have the
same dimension. Float and int values may be mixed however.
The points are always converted to 3D double precision points
by assuming z=0.0 if necessary (as indicated in the man page),
and for each point v3d() is called.
*/
% varray
static PyObject *
gl_varray(self, args)
PyObject *self;
PyObject *args;
{
PyObject *v, *w=NULL;
int i, n, width;
double vec[3];
PyObject * (*getitem)(PyObject *, int);
if (!PyArg_GetObject(args, 1, 0, &v))
return NULL;
if (PyList_Check(v)) {
n = PyList_Size(v);
getitem = PyList_GetItem;
}
else if (PyTuple_Check(v)) {
n = PyTuple_Size(v);
getitem = PyTuple_GetItem;
}
else {
PyErr_BadArgument();
return NULL;
}
if (n == 0) {
Py_INCREF(Py_None);
return Py_None;
}
if (n > 0)
w = (*getitem)(v, 0);
width = 0;
if (w == NULL) {
}
else if (PyList_Check(w)) {
width = PyList_Size(w);
}
else if (PyTuple_Check(w)) {
width = PyTuple_Size(w);
}
switch (width) {
case 2:
vec[2] = 0.0;
/* Fall through */
case 3:
break;
default:
PyErr_BadArgument();
return NULL;
}
for (i = 0; i < n; i++) {
w = (*getitem)(v, i);
if (!PyArg_GetDoubleArray(w, 1, 0, width, vec))
return NULL;
v3d(vec);
}
Py_INCREF(Py_None);
return Py_None;
}
/*
vnarray, nvarray -- an array of n3f and v3f calls.
The argument is an array (list or tuple) of pairs of points and normals.
Each pair is a tuple (NOT a list) of a point and a normal for that point.
Each point or normal must be a tuple (NOT a list) of coordinates (x, y, z).
Three coordinates must be given. Float and int values may be mixed.
For each pair, n3f() is called for the normal, and then v3f() is called
for the vector.
vnarray and nvarray differ only in the order of the vector and normal in
the pair: vnarray expects (v, n) while nvarray expects (n, v).
*/
static PyObject *gen_nvarray(); /* Forward */
% nvarray
static PyObject *
gl_nvarray(self, args)
PyObject *self;
PyObject *args;
{
return gen_nvarray(args, 0);
}
% vnarray
static PyObject *
gl_vnarray(self, args)
PyObject *self;
PyObject *args;
{
return gen_nvarray(args, 1);
}
/* Generic, internal version of {nv,nv}array: inorm indicates the
argument order, 0: normal first, 1: vector first. */
static PyObject *
gen_nvarray(args, inorm)
PyObject *args;
int inorm;
{
PyObject *v, *w, *wnorm, *wvec;
int i, n;
float norm[3], vec[3];
PyObject * (*getitem)(PyObject *, int);
if (!PyArg_GetObject(args, 1, 0, &v))
return NULL;
if (PyList_Check(v)) {
n = PyList_Size(v);
getitem = PyList_GetItem;
}
else if (PyTuple_Check(v)) {
n = PyTuple_Size(v);
getitem = PyTuple_GetItem;
}
else {
PyErr_BadArgument();
return NULL;
}
for (i = 0; i < n; i++) {
w = (*getitem)(v, i);
if (!PyTuple_Check(w) || PyTuple_Size(w) != 2) {
PyErr_BadArgument();
return NULL;
}
wnorm = PyTuple_GetItem(w, inorm);
wvec = PyTuple_GetItem(w, 1 - inorm);
if (!PyArg_GetFloatArray(wnorm, 1, 0, 3, norm) ||
!PyArg_GetFloatArray(wvec, 1, 0, 3, vec))
return NULL;
n3f(norm);
v3f(vec);
}
Py_INCREF(Py_None);
return Py_None;
}
/* nurbssurface(s_knots[], t_knots[], ctl[][], s_order, t_order, type).
The dimensions of ctl[] are computed as follows:
[len(s_knots) - s_order], [len(t_knots) - t_order]
*/
% nurbssurface
static PyObject *
gl_nurbssurface(self, args)
PyObject *self;
PyObject *args;
{
long arg1 ;
double * arg2 ;
long arg3 ;
double * arg4 ;
double *arg5 ;
long arg6 ;
long arg7 ;
long arg8 ;
long ncoords;
long s_byte_stride, t_byte_stride;
long s_nctl, t_nctl;
long s, t;
PyObject *v, *w, *pt;
double *pnext;
if (!PyArg_GetLongArraySize(args, 6, 0, &arg1))
return NULL;
if ((arg2 = PyMem_NEW(double, arg1 )) == NULL) {
return PyErr_NoMemory();
}
if (!PyArg_GetDoubleArray(args, 6, 0, arg1 , arg2))
return NULL;
if (!PyArg_GetLongArraySize(args, 6, 1, &arg3))
return NULL;
if ((arg4 = PyMem_NEW(double, arg3 )) == NULL) {
return PyErr_NoMemory();
}
if (!PyArg_GetDoubleArray(args, 6, 1, arg3 , arg4))
return NULL;
if (!PyArg_GetLong(args, 6, 3, &arg6))
return NULL;
if (!PyArg_GetLong(args, 6, 4, &arg7))
return NULL;
if (!PyArg_GetLong(args, 6, 5, &arg8))
return NULL;
if (arg8 == N_XYZ)
ncoords = 3;
else if (arg8 == N_XYZW)
ncoords = 4;
else {
PyErr_BadArgument();
return NULL;
}
s_nctl = arg1 - arg6;
t_nctl = arg3 - arg7;
if (!PyArg_GetObject(args, 6, 2, &v))
return NULL;
if (!PyList_Check(v) || PyList_Size(v) != s_nctl) {
PyErr_BadArgument();
return NULL;
}
if ((arg5 = PyMem_NEW(double, s_nctl*t_nctl*ncoords )) == NULL) {
return PyErr_NoMemory();
}
pnext = arg5;
for (s = 0; s < s_nctl; s++) {
w = PyList_GetItem(v, s);
if (w == NULL || !PyList_Check(w) ||
PyList_Size(w) != t_nctl) {
PyErr_BadArgument();
return NULL;
}
for (t = 0; t < t_nctl; t++) {
pt = PyList_GetItem(w, t);
if (!PyArg_GetDoubleArray(pt, 1, 0, ncoords, pnext))
return NULL;
pnext += ncoords;
}
}
s_byte_stride = sizeof(double) * ncoords;
t_byte_stride = s_byte_stride * s_nctl;
nurbssurface( arg1 , arg2 , arg3 , arg4 ,
s_byte_stride , t_byte_stride , arg5 , arg6 , arg7 , arg8 );
PyMem_DEL(arg2);
PyMem_DEL(arg4);
PyMem_DEL(arg5);
Py_INCREF(Py_None);
return Py_None;
}
/* nurbscurve(knots, ctlpoints, order, type).
The length of ctlpoints is len(knots)-order. */
%nurbscurve
static PyObject *
gl_nurbscurve(self, args)
PyObject *self;
PyObject *args;
{
long arg1 ;
double * arg2 ;
long arg3 ;
double * arg4 ;
long arg5 ;
long arg6 ;
int ncoords, npoints;
int i;
PyObject *v;
double *pnext;
if (!PyArg_GetLongArraySize(args, 4, 0, &arg1))
return NULL;
if ((arg2 = PyMem_NEW(double, arg1 )) == NULL) {
return PyErr_NoMemory();
}
if (!PyArg_GetDoubleArray(args, 4, 0, arg1 , arg2))
return NULL;
if (!PyArg_GetLong(args, 4, 2, &arg5))
return NULL;
if (!PyArg_GetLong(args, 4, 3, &arg6))
return NULL;
if (arg6 == N_ST)
ncoords = 2;
else if (arg6 == N_STW)
ncoords = 3;
else {
PyErr_BadArgument();
return NULL;
}
npoints = arg1 - arg5;
if (!PyArg_GetObject(args, 4, 1, &v))
return NULL;
if (!PyList_Check(v) || PyList_Size(v) != npoints) {
PyErr_BadArgument();
return NULL;
}
if ((arg4 = PyMem_NEW(double, npoints*ncoords )) == NULL) {
return PyErr_NoMemory();
}
pnext = arg4;
for (i = 0; i < npoints; i++) {
if (!PyArg_GetDoubleArray(PyList_GetItem(v, i), 1, 0, ncoords, pnext))
return NULL;
pnext += ncoords;
}
arg3 = (sizeof(double)) * ncoords;
nurbscurve( arg1 , arg2 , arg3 , arg4 , arg5 , arg6 );
PyMem_DEL(arg2);
PyMem_DEL(arg4);
Py_INCREF(Py_None);
return Py_None;
}
/* pwlcurve(points, type).
Points is a list of points. Type must be N_ST. */
%pwlcurve
static PyObject *
gl_pwlcurve(self, args)
PyObject *self;
PyObject *args;
{
PyObject *v;
long type;
double *data, *pnext;
long npoints, ncoords;
int i;
if (!PyArg_GetObject(args, 2, 0, &v))
return NULL;
if (!PyArg_GetLong(args, 2, 1, &type))
return NULL;
if (!PyList_Check(v)) {
PyErr_BadArgument();
return NULL;
}
npoints = PyList_Size(v);
if (type == N_ST)
ncoords = 2;
else {
PyErr_BadArgument();
return NULL;
}
if ((data = PyMem_NEW(double, npoints*ncoords)) == NULL) {
return PyErr_NoMemory();
}
pnext = data;
for (i = 0; i < npoints; i++) {
if (!PyArg_GetDoubleArray(PyList_GetItem(v, i), 1, 0, ncoords, pnext))
return NULL;
pnext += ncoords;
}
pwlcurve(npoints, data, sizeof(double)*ncoords, type);
PyMem_DEL(data);
Py_INCREF(Py_None);
return Py_None;
}
/* Picking and Selecting */
static short *pickbuffer = NULL;
static long pickbuffersize;
static PyObject *
pick_select(args, func)
PyObject *args;
void (*func)();
{
if (!PyArg_GetLong(args, 1, 0, &pickbuffersize))
return NULL;
if (pickbuffer != NULL) {
PyErr_SetString(PyExc_RuntimeError,
"pick/gselect: already picking/selecting");
return NULL;
}
if ((pickbuffer = PyMem_NEW(short, pickbuffersize)) == NULL) {
return PyErr_NoMemory();
}
(*func)(pickbuffer, pickbuffersize);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
endpick_select(args, func)
PyObject *args;
long (*func)();
{
PyObject *v, *w;
int i, nhits, n;
if (!PyArg_NoArgs(args))
return NULL;
if (pickbuffer == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"endpick/endselect: not in pick/select mode");
return NULL;
}
nhits = (*func)(pickbuffer);
if (nhits < 0) {
nhits = -nhits; /* How to report buffer overflow otherwise? */
}
/* Scan the buffer to see how many integers */
n = 0;
for (; nhits > 0; nhits--) {
n += 1 + pickbuffer[n];
}
v = PyList_New(n);
if (v == NULL)
return NULL;
/* XXX Could do it nicer and interpret the data structure here,
returning a list of lists. But this can be done in Python... */
for (i = 0; i < n; i++) {
w = PyInt_FromLong((long)pickbuffer[i]);
if (w == NULL) {
Py_DECREF(v);
return NULL;
}
PyList_SetItem(v, i, w);
}
PyMem_DEL(pickbuffer);
pickbuffer = NULL;
return v;
}
extern void pick(), gselect();
extern long endpick(), endselect();
%pick
static PyObject *gl_pick(self, args) PyObject *self, *args; {
return pick_select(args, pick);
}
%endpick
static PyObject *gl_endpick(self, args) PyObject *self, *args; {
return endpick_select(args, endpick);
}
%gselect
static PyObject *gl_gselect(self, args) PyObject *self, *args; {
return pick_select(args, gselect);
}
%endselect
static PyObject *gl_endselect(self, args) PyObject *self, *args; {
return endpick_select(args, endselect);
}
/* XXX The generator botches this one. Here's a quick hack to fix it. */
/* XXX The generator botches this one. Here's a quick hack to fix it. */
% getmatrix float r[16]
static PyObject *
gl_getmatrix(self, args)
PyObject *self;
PyObject *args;
{
Matrix arg1;
PyObject *v, *w;
int i, j;
getmatrix( arg1 );
v = PyList_New(16);
if (v == NULL) {
return PyErr_NoMemory();
}
for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) {
w = mknewfloatobject(arg1[i][j]);
if (w == NULL) {
Py_DECREF(v);
return NULL;
}
PyList_SetItem(v, i*4+j, w);
}
return v;
}
/* Here's an alternate version that returns a 4x4 matrix instead of
a vector. Unfortunately it is incompatible with loadmatrix and
multmatrix... */
% altgetmatrix float r[4][4]
static PyObject *
gl_altgetmatrix(self, args)
PyObject *self;
PyObject *args;
{
Matrix arg1;
PyObject *v, *w;
int i, j;
getmatrix( arg1 );
v = PyList_New(4);
if (v == NULL) {
return NULL;
}
for (i = 0; i < 4; i++) {
w = PyList_New(4);
if (w == NULL) {
Py_DECREF(v);
return NULL;
}
PyList_SetItem(v, i, w);
}
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
w = mknewfloatobject(arg1[i][j]);
if (w == NULL) {
Py_DECREF(v);
return NULL;
}
PyList_SetItem(PyList_GetItem(v, i), j, w);
}
}
return v;
}
% lrectwrite
static PyObject *
gl_lrectwrite(self, args)
PyObject *self;
PyObject *args;
{
short x1 ;
short y1 ;
short x2 ;
short y2 ;
string parray ;
PyObject *s;
#if 0
int pixcount;
#endif
if (!PyArg_GetShort(args, 5, 0, &x1))
return NULL;
if (!PyArg_GetShort(args, 5, 1, &y1))
return NULL;
if (!PyArg_GetShort(args, 5, 2, &x2))
return NULL;
if (!PyArg_GetShort(args, 5, 3, &y2))
return NULL;
if (!PyArg_GetString(args, 5, 4, &parray))
return NULL;
if (!PyArg_GetObject(args, 5, 4, &s))
return NULL;
#if 0
/* Don't check this, it breaks experiments with pixmode(PM_SIZE, ...) */
pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
if (!PyString_Check(s) || PyString_Size(s) != pixcount*sizeof(long)) {
PyErr_SetString(PyExc_RuntimeError,
"string arg to lrectwrite has wrong size");
return NULL;
}
#endif
lrectwrite( x1 , y1 , x2 , y2 , (unsigned long *) parray );
Py_INCREF(Py_None);
return Py_None;
}
% lrectread
static PyObject *
gl_lrectread(self, args)
PyObject *self;
PyObject *args;
{
short x1 ;
short y1 ;
short x2 ;
short y2 ;
PyObject *parray;
int pixcount;
if (!PyArg_GetShort(args, 4, 0, &x1))
return NULL;
if (!PyArg_GetShort(args, 4, 1, &y1))
return NULL;
if (!PyArg_GetShort(args, 4, 2, &x2))
return NULL;
if (!PyArg_GetShort(args, 4, 3, &y2))
return NULL;
pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
parray = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
if (parray == NULL)
return NULL; /* No memory */
lrectread(x1, y1, x2, y2, (unsigned long *) PyString_AsString(parray));
return parray;
}
% readdisplay
static PyObject *
gl_readdisplay(self, args)
PyObject *self;
PyObject *args;
{
short x1, y1, x2, y2;
unsigned long *parray, hints;
long size, size_ret;
PyObject *rv;
if ( !PyArg_Parse(args, "hhhhl", &x1, &y1, &x2, &y2, &hints) )
return 0;
size = (long)(x2+1-x1) * (long)(y2+1-y1);
rv = PyString_FromStringAndSize((char *)NULL, size*sizeof(long));
if ( rv == NULL )
return NULL;
parray = (unsigned long *)PyString_AsString(rv);
size_ret = readdisplay(x1, y1, x2, y2, parray, hints);
if ( size_ret != size ) {
printf("gl_readdisplay: got %ld pixels, expected %ld\n",
size_ret, size);
PyErr_SetString(PyExc_RuntimeError, "readdisplay returned unexpected length");
return NULL;
}
return rv;
}
/* Desperately needed, here are tools to compress and decompress
the data manipulated by lrectread/lrectwrite.
gl.packrect(width, height, packfactor, bigdata) --> smalldata
makes 'bigdata' 4*(packfactor**2) times smaller by:
- turning it into B/W (a factor 4)
- replacing squares of size pacfactor by one
representative
gl.unpackrect(width, height, packfactor, smalldata) --> bigdata
is the inverse; the numeric arguments must be *the same*.
Both work best if width and height are multiples of packfactor
(in fact unpackrect will leave garbage bytes).
*/
% packrect
static PyObject *
gl_packrect(self, args)
PyObject *self;
PyObject *args;
{
long width, height, packfactor;
char *s;
PyObject *unpacked, *packed;
int pixcount, packedcount, x, y, r, g, b;
unsigned long pixel;
unsigned char *p;
unsigned long *parray;
if (!PyArg_GetLong(args, 4, 0, &width))
return NULL;
if (!PyArg_GetLong(args, 4, 1, &height))
return NULL;
if (!PyArg_GetLong(args, 4, 2, &packfactor))
return NULL;
if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */
return NULL;
if (!PyArg_GetObject(args, 4, 3, &unpacked))
return NULL;
if (width <= 0 || height <= 0 || packfactor <= 0) {
PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0");
return NULL;
}
pixcount = width*height;
packedcount = ((width+packfactor-1)/packfactor) *
((height+packfactor-1)/packfactor);
if (PyString_Size(unpacked) != pixcount*sizeof(long)) {
PyErr_SetString(PyExc_RuntimeError,
"string arg to packrect has wrong size");
return NULL;
}
packed = PyString_FromStringAndSize((char *)NULL, packedcount);
if (packed == NULL)
return NULL;
parray = (unsigned long *) PyString_AsString(unpacked);
p = (unsigned char *) PyString_AsString(packed);
for (y = 0; y < height; y += packfactor, parray += packfactor*width) {
for (x = 0; x < width; x += packfactor) {
pixel = parray[x];
r = pixel & 0xff;
g = (pixel >> 8) & 0xff;
b = (pixel >> 16) & 0xff;
*p++ = (30*r+59*g+11*b) / 100;
}
}
return packed;
}
% unpackrect
static unsigned long unpacktab[256];
static int unpacktab_inited = 0;
static PyObject *
gl_unpackrect(self, args)
PyObject *self;
PyObject *args;
{
long width, height, packfactor;
char *s;
PyObject *unpacked, *packed;
int pixcount, packedcount;
register unsigned char *p;
register unsigned long *parray;
if (!unpacktab_inited) {
register int white;
for (white = 256; --white >= 0; )
unpacktab[white] = white * 0x010101L;
unpacktab_inited++;
}
if (!PyArg_GetLong(args, 4, 0, &width))
return NULL;
if (!PyArg_GetLong(args, 4, 1, &height))
return NULL;
if (!PyArg_GetLong(args, 4, 2, &packfactor))
return NULL;
if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */
return NULL;
if (!PyArg_GetObject(args, 4, 3, &packed))
return NULL;
if (width <= 0 || height <= 0 || packfactor <= 0) {
PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0");
return NULL;
}
pixcount = width*height;
packedcount = ((width+packfactor-1)/packfactor) *
((height+packfactor-1)/packfactor);
if (PyString_Size(packed) != packedcount) {
PyErr_SetString(PyExc_RuntimeError,
"string arg to unpackrect has wrong size");
return NULL;
}
unpacked = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
if (unpacked == NULL)
return NULL;
parray = (unsigned long *) PyString_AsString(unpacked);
p = (unsigned char *) PyString_AsString(packed);
if (packfactor == 1 && width*height > 0) {
/* Just expand bytes to longs */
register int x = width * height;
do {
*parray++ = unpacktab[*p++];
} while (--x >= 0);
}
else {
register int y;
for (y = 0; y < height-packfactor+1;
y += packfactor, parray += packfactor*width) {
register int x;
for (x = 0; x < width-packfactor+1; x += packfactor) {
register unsigned long pixel = unpacktab[*p++];
register int i;
for (i = packfactor*width; (i-=width) >= 0;) {
register int j;
for (j = packfactor; --j >= 0; )
parray[i+x+j] = pixel;
}
}
}
}
return unpacked;
}
% gversion
static PyObject *
gl_gversion(self, args)
PyObject *self;
PyObject *args;
{
char buf[20];
gversion(buf);
return PyString_FromString(buf);
}
/* void clear - Manual because of clash with termcap */
%clear
static PyObject *
gl_clear(self, args)
PyObject *self;
PyObject *args;
{
__GLclear( );
Py_INCREF(Py_None);
return Py_None;
}
/* End of manually written stubs */
%%
long getshade
if !solaris void devport short s long s
void rdr2i long s long s
void rectfs short s short s short s short s
void rects short s short s short s short s
void rmv2i long s long s
void noport
void popviewport
void clearhitcode
void closeobj
void cursoff
void curson
void doublebuffer
void finish
void gconfig
void ginit
void greset
void multimap
void onemap
void popattributes
void popmatrix
void pushattributes
void pushmatrix
void pushviewport
void qreset
void RGBmode
void singlebuffer
void swapbuffers
void gsync
void gflush
void tpon
void tpoff
void clkon
void clkoff
void ringbell
#void callfunc
void gbegin
void textinit
void initnames
void pclos
void popname
if !solaris void spclos
void zclear
void screenspace
void reshapeviewport
void winpush
void winpop
void foreground
void endfullscrn
if !solaris void endpupmode
void fullscrn
if !solaris void pupmode
void winconstraints
void pagecolor short s
void textcolor short s
void color short s
void curveit short s
void font short s
void linewidth short s
void setlinestyle short s
void setmap short s
void swapinterval short s
void writemask short s
if !solaris void textwritemask short s
void qdevice short s
void unqdevice short s
void curvebasis short s
void curveprecision short s
void loadname short s
void passthrough short s
void pushname short s
void setmonitor short s
if !solaris void setshade short s
void setpattern short s
if !solaris void pagewritemask short s
#
void callobj long s
void delobj long s
void editobj long s
void makeobj long s
void maketag long s
void chunksize long s
void compactify long s
void deltag long s
void lsrepeat long s
void objinsert long s
void objreplace long s
void winclose long s
void blanktime long s
void freepup long s
# This is not in the library!?
###void pupcolor long s
#
void backbuffer long s
void frontbuffer long s
if !solaris void lsbackup long s
void resetls long s
void lampon long s
void lampoff long s
void setbell long s
void blankscreen long s
void depthcue long s
void zbuffer long s
void backface long s
#
void cmov2i long s long s
void draw2i long s long s
void move2i long s long s
void pnt2i long s long s
void patchbasis long s long s
void patchprecision long s long s
void pdr2i long s long s
void pmv2i long s long s
void rpdr2i long s long s
void rpmv2i long s long s
void xfpt2i long s long s
void objdelete long s long s
void patchcurves long s long s
void minsize long s long s
void maxsize long s long s
void keepaspect long s long s
void prefsize long s long s
void stepunit long s long s
void fudge long s long s
void winmove long s long s
#