@@ -561,6 +561,216 @@ gl_altgetmatrix(self, args)
561561 return v;
562562}
563563
564+ % lrectwrite
565+
566+ static object *
567+ gl_lrectwrite(self, args)
568+ object *self;
569+ object *args;
570+ {
571+ short x1 ;
572+ short y1 ;
573+ short x2 ;
574+ short y2 ;
575+ string parray ;
576+ object *s;
577+ int pixcount;
578+ if (!getishortarg(args, 5, 0, &x1))
579+ return NULL;
580+ if (!getishortarg(args, 5, 1, &y1))
581+ return NULL;
582+ if (!getishortarg(args, 5, 2, &x2))
583+ return NULL;
584+ if (!getishortarg(args, 5, 3, &y2))
585+ return NULL;
586+ if (!getistringarg(args, 5, 4, &parray))
587+ return NULL;
588+ if (!getiobjectarg(args, 5, 4, &s))
589+ return NULL;
590+ pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
591+ if (!is_stringobject(s) || getstringsize(s) != pixcount*sizeof(long)) {
592+ fprintf(stderr, "string arg to lrectwrite has wrong size\n");
593+ err_badarg();
594+ return NULL;
595+ }
596+ lrectwrite( x1 , y1 , x2 , y2 , (unsigned long *) parray );
597+ INCREF(None);
598+ return None;
599+ }
600+
601+ % lrectread
602+
603+ static object *
604+ gl_lrectread(self, args)
605+ object *self;
606+ object *args;
607+ {
608+ short x1 ;
609+ short y1 ;
610+ short x2 ;
611+ short y2 ;
612+ object *parray;
613+ int pixcount;
614+ if (!getishortarg(args, 4, 0, &x1))
615+ return NULL;
616+ if (!getishortarg(args, 4, 1, &y1))
617+ return NULL;
618+ if (!getishortarg(args, 4, 2, &x2))
619+ return NULL;
620+ if (!getishortarg(args, 4, 3, &y2))
621+ return NULL;
622+ pixcount = (long)(x2+1-x1) * (long)(y2+1-y1);
623+ parray = newsizedstringobject((char *)NULL, pixcount*sizeof(long));
624+ if (parray == NULL)
625+ return NULL; /* No memory */
626+ lrectread(x1, y1, x2, y2, (unsigned long *) getstringvalue(parray));
627+ return parray;
628+ }
629+
630+ /* Desperately needed, here are tools to compress and decompress
631+ the data manipulated by lrectread/lrectwrite.
632+
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+
639+ gl.unpackrect(width, height, packfactor, smalldata) --> bigdata
640+ is the inverse; the numeric arguments must be *the same*.
641+
642+ Both work best if width and height are multiples of packfactor
643+ (in fact unpackrect will leave garbage bytes).
644+ */
645+
646+ % packrect
647+
648+ static object *
649+ gl_packrect(self, args)
650+ object *self;
651+ object *args;
652+ {
653+ long width, height, packfactor;
654+ char *s;
655+ object *unpacked, *packed;
656+ int pixcount, packedcount, x, y, r, g, b;
657+ unsigned long pixel;
658+ unsigned char *p;
659+ unsigned long *parray;
660+ if (!getilongarg(args, 4, 0, &width))
661+ return NULL;
662+ if (!getilongarg(args, 4, 1, &height))
663+ return NULL;
664+ if (!getilongarg(args, 4, 2, &packfactor))
665+ return NULL;
666+ if (!getistringarg(args, 4, 3, &s)) /* For type checking only */
667+ return NULL;
668+ if (!getiobjectarg(args, 4, 3, &unpacked))
669+ return NULL;
670+ if (width <= 0 || height <= 0 || packfactor <= 0) {
671+ err_setstr(RuntimeError, "packrect args must be > 0");
672+ return NULL;
673+ }
674+ pixcount = width*height;
675+ packedcount = ((width+packfactor-1)/packfactor) *
676+ ((height+packfactor-1)/packfactor);
677+ if (getstringsize(unpacked) != pixcount*sizeof(long)) {
678+ fprintf(stderr, "string arg to packrect has wrong size\n");
679+ err_badarg();
680+ return NULL;
681+ }
682+ packed = newsizedstringobject((char *)NULL, packedcount);
683+ if (packed == NULL)
684+ return NULL;
685+ parray = (unsigned long *) getstringvalue(unpacked);
686+ p = getstringvalue(packed);
687+ for (y = 0; y < height; y += packfactor, parray += packfactor*width) {
688+ for (x = 0; x < width; x += packfactor) {
689+ pixel = parray[x];
690+ r = pixel & 0xff;
691+ g = (pixel >> 8) & 0xff;
692+ b = (pixel >> 16) & 0xff;
693+ *p++ = (r+g+b) / 3;
694+ }
695+ }
696+ return packed;
697+ }
698+
699+ % unpackrect
700+
701+ static unsigned long unpacktab[256];
702+ static int unpacktab_inited = 0;
703+
704+ static object *
705+ gl_unpackrect(self, args)
706+ object *self;
707+ object *args;
708+ {
709+ long width, height, packfactor;
710+ char *s;
711+ object *unpacked, *packed;
712+ int pixcount, packedcount, y;
713+ register unsigned char *p;
714+ register unsigned long *parray;
715+ if (!unpacktab_inited) {
716+ register int white;
717+ for (white = 256; --white >= 0; )
718+ unpacktab[white] = white * 0x010101L;
719+ unpacktab_inited++;
720+ }
721+ if (!getilongarg(args, 4, 0, &width))
722+ return NULL;
723+ if (!getilongarg(args, 4, 1, &height))
724+ return NULL;
725+ if (!getilongarg(args, 4, 2, &packfactor))
726+ return NULL;
727+ if (!getistringarg(args, 4, 3, &s)) /* For type checking only */
728+ return NULL;
729+ if (!getiobjectarg(args, 4, 3, &packed))
730+ return NULL;
731+ if (width <= 0 || height <= 0 || packfactor <= 0) {
732+ err_setstr(RuntimeError, "packrect args must be > 0");
733+ return NULL;
734+ }
735+ pixcount = width*height;
736+ packedcount = ((width+packfactor-1)/packfactor) *
737+ ((height+packfactor-1)/packfactor);
738+ if (getstringsize(packed) != packedcount) {
739+ fprintf(stderr, "string arg to unpackrect has wrong size\n");
740+ err_badarg();
741+ return NULL;
742+ }
743+ unpacked = newsizedstringobject((char *)NULL, pixcount*sizeof(long));
744+ if (unpacked == NULL)
745+ return NULL;
746+ parray = (unsigned long *) getstringvalue(unpacked);
747+ p = (unsigned char *) getstringvalue(packed);
748+ if (packfactor == 1 && width*height > 0) {
749+ /* Just expand bytes to longs */
750+ register int x = width * height;
751+ do {
752+ *parray++ = unpacktab[*p++];
753+ } while (--x >= 0);
754+ }
755+ else {
756+ register int y;
757+ for (y = 0; y < height-packfactor+1;
758+ y += packfactor, parray += packfactor*width) {
759+ register int x;
760+ for (x = 0; x < width-packfactor+1; x += packfactor) {
761+ register unsigned long pixel = unpacktab[*p++];
762+ register int i;
763+ for (i = packfactor*width; (i-=width) >= 0;) {
764+ register int j;
765+ for (j = packfactor; --j >= 0; )
766+ parray[i+x+j] = pixel;
767+ }
768+ }
769+ }
770+ }
771+ return unpacked;
772+ }
773+
564774/* End of manually written stubs */
565775
566776%%
@@ -828,7 +1038,7 @@ void splfi long s long s[3*arg1] short s[arg1]
8281038void splf2i long s long s[2*arg1] short s[arg1]
8291039void splfs long s short s[3*arg1] short s[arg1]
8301040void splf2s long s short s[2*arg1] short s[arg1]
831- void defpattern short s short s short s[arg2*arg2/16]
1041+ ### void defpattern short s short s short s[arg2*arg2/16]
8321042#
8331043void rpatch float s[16] float s[16] float s[16] float s[16]
8341044#
@@ -922,22 +1132,22 @@ void winposition long s long s long s long s
9221132void gRGBcolor short r short r short r
9231133void gRGBmask short r short r short r
9241134void getscrmask short r short r short r short r
925- void gRGBcursor short r short r short r short r short r short r short r short r long *
1135+ ### void gRGBcursor short r short r short r short r short r short r short r short r
9261136void getmcolor short s short r short r short r
9271137void mapw long s short s short s float r float r float r float r float r float r
9281138void mapw2 long s short s short s float r float r
929- void defrasterfont short s short s short s Fontchar s[arg3] short s short s[4*arg5]
1139+ ### void defrasterfont short s short s short s Fontchar s[arg3] short s short s[4*arg5]
9301140long qread short r
9311141void getcursor short r short r short r long r
9321142#
9331143# For these we receive arrays of stuff
9341144#
935- void getdev long s short s[arg1] short r[arg1]
1145+ ### void getdev long s short s[arg1] short r[arg1]
9361146#XXX not generated correctly yet
9371147#void getmatrix float r[16]
938- long readpixels short s short r[retval]
939- long readRGB short s char r[retval] char r[retval] char r[retval]
940- long blkqread short s short r[arg1]
1148+ ### long readpixels short s short r[retval]
1149+ ### long readRGB short s char r[retval] char r[retval] char r[retval]
1150+ ### long blkqread short s short r[arg1]
9411151#
9421152# New 4D routines
9431153#
@@ -1000,10 +1210,11 @@ void lRGBrange short s short s short s short s short s short s long s long s
10001210void linesmooth long s
10011211void lmcolor long s
10021212void logicop long s
1003- long lrectread short s short s short s short s long r[retval]
1004- void lrectwrite short s short s short s short s long s[(arg2-arg1+1)*(arg4-arg3+1)]
1005- long rectread short s short s short s short s short r[retval]
1006- void rectwrite short s short s short s short s short s[(arg2-arg1+1)*(arg4-arg3+1)]
1213+ ###long lrectread short s short s short s short s long r[retval]
1214+ ###void lrectwrite short s short s short s short s long s[(arg2-arg1+1)*(arg4-arg3+1)]
1215+ ### Now manual, with string last arg
1216+ ###long rectread short s short s short s short s short r[retval]
1217+ ###void rectwrite short s short s short s short s short s[(arg2-arg1+1)*(arg4-arg3+1)]
10071218void lsetdepth long s long s
10081219void lshaderange short s short s long s long s
10091220void n3f float s[3]
@@ -1045,3 +1256,7 @@ void zwritemask long s
10451256void v2d double s[2]
10461257void v3d double s[3]
10471258void v4d double s[4]
1259+ #
1260+ # Why isn't this here?
1261+ #
1262+ void pixmode long s long s
0 commit comments