home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Modules / imageop.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-28  |  16.3 KB  |  750 lines  |  [TEXT/CWIE]

  1. /***********************************************************
  2. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  3. The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI or Corporation for National Research Initiatives or
  13. CNRI not be used in advertising or publicity pertaining to
  14. distribution of the software without specific, written prior
  15. permission.
  16.  
  17. While CWI is the initial source for this software, a modified version
  18. is made available by the Corporation for National Research Initiatives
  19. (CNRI) at the Internet address ftp://ftp.python.org.
  20.  
  21. STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
  22. REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  23. MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
  24. CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  25. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  26. PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  27. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  28. PERFORMANCE OF THIS SOFTWARE.
  29.  
  30. ******************************************************************/
  31.  
  32. /* imageopmodule - Various operations on pictures */
  33.  
  34. #ifdef sun
  35. #define signed
  36. #endif
  37.  
  38. #include "allobjects.h"
  39. #include "modsupport.h"
  40.  
  41. #define CHARP(cp, xmax, x, y) ((char *)(cp+y*xmax+x))
  42. #define SHORTP(cp, xmax, x, y) ((short *)(cp+2*(y*xmax+x)))
  43. #define LONGP(cp, xmax, x, y) ((long *)(cp+4*(y*xmax+x)))
  44.  
  45. static object *ImageopError;
  46.  
  47. static object *
  48. imageop_crop(self, args)
  49.     object *self;
  50.     object *args;
  51. {
  52.     char *cp, *ncp;
  53.     short *nsp;
  54.     long *nlp;
  55.     int len, size, x, y, newx1, newx2, newy1, newy2;
  56.     int ix, iy, xstep, ystep;
  57.     object *rv;
  58.  
  59.     if ( !getargs(args, "(s#iiiiiii)", &cp, &len, &size, &x, &y,
  60.           &newx1, &newy1, &newx2, &newy2) )
  61.       return 0;
  62.     
  63.     if ( size != 1 && size != 2 && size != 4 ) {
  64.     err_setstr(ImageopError, "Size should be 1, 2 or 4");
  65.     return 0;
  66.     }
  67.     if ( len != size*x*y ) {
  68.     err_setstr(ImageopError, "String has incorrect length");
  69.     return 0;
  70.     }
  71.     xstep = (newx1 < newx2)? 1 : -1;
  72.     ystep = (newy1 < newy2)? 1 : -1;
  73.     
  74.     rv = newsizedstringobject(NULL,
  75.                   (abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size);
  76.     if ( rv == 0 )
  77.       return 0;
  78.     ncp = (char *)getstringvalue(rv);
  79.     nsp = (short *)ncp;
  80.     nlp = (long *)ncp;
  81.     newy2 += ystep;
  82.     newx2 += xstep;
  83.     for( iy = newy1; iy != newy2; iy+=ystep ) {
  84.     for ( ix = newx1; ix != newx2; ix+=xstep ) {
  85.         if ( iy < 0 || iy >= y || ix < 0 || ix >= x ) {
  86.           if ( size == 1 ) *ncp++ = 0;
  87.           else             *nlp++ = 0;
  88.         } else {
  89.         if      ( size == 1 ) *ncp++ = *CHARP(cp, x, ix, iy);
  90.         else if ( size == 2 ) *nsp++ = *SHORTP(cp, x, ix, iy);
  91.         else                  *nlp++ = *LONGP(cp, x, ix, iy);
  92.         }
  93.     }
  94.     }
  95.     return rv;
  96. }
  97.  
  98. static object *
  99. imageop_scale(self, args)
  100.     object *self;
  101.     object *args;
  102. {
  103.     char *cp, *ncp;
  104.     short *nsp;
  105.     long *nlp;
  106.     int len, size, x, y, newx, newy;
  107.     int ix, iy;
  108.     int oix, oiy;
  109.     object *rv;
  110.  
  111.     if ( !getargs(args, "(s#iiiii)", &cp, &len, &size, &x, &y, &newx, &newy) )
  112.       return 0;
  113.     
  114.     if ( size != 1 && size != 2 && size != 4 ) {
  115.     err_setstr(ImageopError, "Size should be 1, 2 or 4");
  116.     return 0;
  117.     }
  118.     if ( len != size*x*y ) {
  119.     err_setstr(ImageopError, "String has incorrect length");
  120.     return 0;
  121.     }
  122.     
  123.     rv = newsizedstringobject(NULL, newx*newy*size);
  124.     if ( rv == 0 )
  125.       return 0;
  126.     ncp = (char *)getstringvalue(rv);
  127.     nsp = (short *)ncp;
  128.     nlp = (long *)ncp;
  129.     for( iy = 0; iy < newy; iy++ ) {
  130.     for ( ix = 0; ix < newx; ix++ ) {
  131.         oix = ix * x / newx;
  132.         oiy = iy * y / newy;
  133.         if      ( size == 1 ) *ncp++ = *CHARP(cp, x, oix, oiy);
  134.         else if ( size == 2 ) *nsp++ = *SHORTP(cp, x, oix, oiy);
  135.         else                  *nlp++ = *LONGP(cp, x, oix, oiy);
  136.     }
  137.     }
  138.     return rv;
  139. }
  140.  
  141. /* Note: this routine can use a bit of optimizing */
  142.  
  143. static object *
  144. imageop_tovideo(self, args)
  145.     object *self;
  146.     object *args;
  147. {
  148.     int maxx, maxy, x, y, len;
  149.     int i;
  150.     unsigned char *cp, *ncp;
  151.     int width;
  152.     object *rv;
  153.    
  154.     
  155.     if ( !getargs(args, "(s#iii)", &cp, &len, &width, &maxx, &maxy) )
  156.       return 0;
  157.  
  158.     if ( width != 1 && width != 4 ) {
  159.     err_setstr(ImageopError, "Size should be 1 or 4");
  160.     return 0;
  161.     }
  162.     if ( maxx*maxy*width != len ) {
  163.     err_setstr(ImageopError, "String has incorrect length");
  164.     return 0;
  165.     }
  166.     
  167.     rv = newsizedstringobject(NULL, len);
  168.     if ( rv == 0 )
  169.       return 0;
  170.     ncp = (unsigned char *)getstringvalue(rv);
  171.  
  172.     if ( width == 1 ) {
  173.     memcpy(ncp, cp, maxx);        /* Copy first line */
  174.     ncp += maxx;
  175.     for (y=1; y<maxy; y++) {    /* Interpolate other lines */
  176.         for(x=0; x<maxx; x++) {
  177.         i = y*maxx + x;
  178.         *ncp++ = ((int)cp[i] + (int)cp[i-maxx]) >> 1;
  179.         }
  180.     }
  181.     } else {
  182.     memcpy(ncp, cp, maxx*4);        /* Copy first line */
  183.     ncp += maxx*4;
  184.     for (y=1; y<maxy; y++) {    /* Interpolate other lines */
  185.         for(x=0; x<maxx; x++) {
  186.         i = (y*maxx + x)*4 + 1;
  187.         *ncp++ = 0;    /* Skip alfa comp */
  188.         *ncp++ = ((int)cp[i] + (int)cp[i-4*maxx]) >> 1;
  189.         i++;
  190.         *ncp++ = ((int)cp[i] + (int)cp[i-4*maxx]) >> 1;
  191.         i++;
  192.         *ncp++ = ((int)cp[i] + (int)cp[i-4*maxx]) >> 1;
  193.         }
  194.     }
  195.     }
  196.     return rv;
  197. }
  198.  
  199. static object *
  200. imageop_grey2mono(self, args)
  201.     object *self;
  202.     object *args;
  203. {
  204.     int tres, x, y, len;
  205.     unsigned char *cp, *ncp;
  206.     unsigned char ovalue;
  207.     object *rv;
  208.     int i, bit;
  209.    
  210.     
  211.     if ( !getargs(args, "(s#iii)", &cp, &len, &x, &y, &tres) )
  212.       return 0;
  213.  
  214.     if ( x*y != len ) {
  215.     err_setstr(ImageopError, "String has incorrect length");
  216.     return 0;
  217.     }
  218.     
  219.     rv = newsizedstringobject(NULL, (len+7)/8);
  220.     if ( rv == 0 )
  221.       return 0;
  222.     ncp = (unsigned char *)getstringvalue(rv);
  223.  
  224.     bit = 0x80;
  225.     ovalue = 0;
  226.     for ( i=0; i < len; i++ ) {
  227.     if ( (int)cp[i] > tres )
  228.       ovalue |= bit;
  229.     bit >>= 1;
  230.     if ( bit == 0 ) {
  231.         *ncp++ = ovalue;
  232.         bit = 0x80;
  233.         ovalue = 0;
  234.     }
  235.     }
  236.     if ( bit != 0x80 )
  237.       *ncp++ = ovalue;
  238.     return rv;
  239. }
  240.  
  241. static object *
  242. imageop_grey2grey4(self, args)
  243.     object *self;
  244.     object *args;
  245. {
  246.     int x, y, len;
  247.     unsigned char *cp, *ncp;
  248.     unsigned char ovalue;
  249.     object *rv;
  250.     int i;
  251.     int pos;
  252.    
  253.     
  254.     if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) )
  255.       return 0;
  256.  
  257.     if ( x*y != len ) {
  258.     err_setstr(ImageopError, "String has incorrect length");
  259.     return 0;
  260.     }
  261.     
  262.     rv = newsizedstringobject(NULL, (len+1)/2);
  263.     if ( rv == 0 )
  264.       return 0;
  265.     ncp = (unsigned char *)getstringvalue(rv);
  266.     pos = 0;
  267.     ovalue = 0;
  268.     for ( i=0; i < len; i++ ) {
  269.     ovalue |= ((int)cp[i] & 0xf0) >> pos;
  270.     pos += 4;
  271.     if ( pos == 8 ) {
  272.         *ncp++ = ovalue;
  273.         ovalue = 0;
  274.         pos = 0;
  275.     }
  276.     }
  277.     if ( pos != 0 )
  278.       *ncp++ = ovalue;
  279.     return rv;
  280. }
  281.  
  282. static object *
  283. imageop_grey2grey2(self, args)
  284.     object *self;
  285.     object *args;
  286. {
  287.     int x, y, len;
  288.     unsigned char *cp, *ncp;
  289.     unsigned char ovalue;
  290.     object *rv;
  291.     int i;
  292.     int pos;
  293.    
  294.     
  295.     if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) )
  296.       return 0;
  297.  
  298.     if ( x*y != len ) {
  299.     err_setstr(ImageopError, "String has incorrect length");
  300.     return 0;
  301.     }
  302.     
  303.     rv = newsizedstringobject(NULL, (len+3)/4);
  304.     if ( rv == 0 )
  305.       return 0;
  306.     ncp = (unsigned char *)getstringvalue(rv);
  307.     pos = 0;
  308.     ovalue = 0;
  309.     for ( i=0; i < len; i++ ) {
  310.     ovalue |= ((int)cp[i] & 0xc0) >> pos;
  311.     pos += 2;
  312.     if ( pos == 8 ) {
  313.         *ncp++ = ovalue;
  314.         ovalue = 0;
  315.         pos = 0;
  316.     }
  317.     }
  318.     if ( pos != 0 )
  319.       *ncp++ = ovalue;
  320.     return rv;
  321. }
  322.  
  323. static object *
  324. imageop_dither2mono(self, args)
  325.     object *self;
  326.     object *args;
  327. {
  328.     int sum, x, y, len;
  329.     unsigned char *cp, *ncp;
  330.     unsigned char ovalue;
  331.     object *rv;
  332.     int i, bit;
  333.    
  334.     
  335.     if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) )
  336.       return 0;
  337.  
  338.     if ( x*y != len ) {
  339.     err_setstr(ImageopError, "String has incorrect length");
  340.     return 0;
  341.     }
  342.     
  343.     rv = newsizedstringobject(NULL, (len+7)/8);
  344.     if ( rv == 0 )
  345.       return 0;
  346.     ncp = (unsigned char *)getstringvalue(rv);
  347.  
  348.     bit = 0x80;
  349.     ovalue = 0;
  350.     sum = 0;
  351.     for ( i=0; i < len; i++ ) {
  352.     sum += cp[i];
  353.     if ( sum >= 256 ) {
  354.         sum -= 256;
  355.         ovalue |= bit;
  356.     }
  357.     bit >>= 1;
  358.     if ( bit == 0 ) {
  359.         *ncp++ = ovalue;
  360.         bit = 0x80;
  361.         ovalue = 0;
  362.     }
  363.     }
  364.     if ( bit != 0x80 )
  365.       *ncp++ = ovalue;
  366.     return rv;
  367. }
  368.  
  369. static object *
  370. imageop_dither2grey2(self, args)
  371.     object *self;
  372.     object *args;
  373. {
  374.     int x, y, len;
  375.     unsigned char *cp, *ncp;
  376.     unsigned char ovalue;
  377.     object *rv;
  378.     int i;
  379.     int pos;
  380.     int sum = 0, nvalue;
  381.    
  382.     
  383.     if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) )
  384.       return 0;
  385.  
  386.     if ( x*y != len ) {
  387.     err_setstr(ImageopError, "String has incorrect length");
  388.     return 0;
  389.     }
  390.     
  391.     rv = newsizedstringobject(NULL, (len+3)/4);
  392.     if ( rv == 0 )
  393.       return 0;
  394.     ncp = (unsigned char *)getstringvalue(rv);
  395.     pos = 1;
  396.     ovalue = 0;
  397.     for ( i=0; i < len; i++ ) {
  398.     sum += cp[i];
  399.     nvalue = sum & 0x180;
  400.     sum -= nvalue;
  401.     ovalue |= nvalue >> pos;
  402.     pos += 2;
  403.     if ( pos == 9 ) {
  404.         *ncp++ = ovalue;
  405.         ovalue = 0;
  406.         pos = 1;
  407.     }
  408.     }
  409.     if ( pos != 0 )
  410.       *ncp++ = ovalue;
  411.     return rv;
  412. }
  413.  
  414. static object *
  415. imageop_mono2grey(self, args)
  416.     object *self;
  417.     object *args;
  418. {
  419.     int v0, v1, x, y, len, nlen;
  420.     unsigned char *cp, *ncp;
  421.     object *rv;
  422.     int i, bit;
  423.     
  424.     if ( !getargs(args, "(s#iiii)", &cp, &len, &x, &y, &v0, &v1) )
  425.       return 0;
  426.  
  427.     nlen = x*y;
  428.     if ( (nlen+7)/8 != len ) {
  429.     err_setstr(ImageopError, "String has incorrect length");
  430.     return 0;
  431.     }
  432.     
  433.     rv = newsizedstringobject(NULL, nlen);
  434.     if ( rv == 0 )
  435.       return 0;
  436.     ncp = (unsigned char *)getstringvalue(rv);
  437.  
  438.     bit = 0x80;
  439.     for ( i=0; i < nlen; i++ ) {
  440.     if ( *cp & bit )
  441.       *ncp++ = v1;
  442.     else
  443.       *ncp++ = v0;
  444.     bit >>= 1;
  445.     if ( bit == 0 ) {
  446.         bit = 0x80;
  447.         cp++;
  448.     }
  449.     }
  450.     return rv;
  451. }
  452.  
  453. static object *
  454. imageop_grey22grey(self, args)
  455.     object *self;
  456.     object *args;
  457. {
  458.     int x, y, len, nlen;
  459.     unsigned char *cp, *ncp;
  460.     object *rv;
  461.     int i, pos, value, nvalue;
  462.     
  463.     if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) )
  464.       return 0;
  465.  
  466.     nlen = x*y;
  467.     if ( (nlen+3)/4 != len ) {
  468.     err_setstr(ImageopError, "String has incorrect length");
  469.     return 0;
  470.     }
  471.     
  472.     rv = newsizedstringobject(NULL, nlen);
  473.     if ( rv == 0 )
  474.       return 0;
  475.     ncp = (unsigned char *)getstringvalue(rv);
  476.  
  477.     pos = 0;
  478.     for ( i=0; i < nlen; i++ ) {
  479.     if ( pos == 0 ) {
  480.         value = *cp++;
  481.         pos = 8;
  482.     }
  483.     pos -= 2;
  484.     nvalue = (value >> pos) & 0x03;
  485.     *ncp++ = nvalue | (nvalue << 2) | (nvalue << 4) | (nvalue << 6);
  486.     }
  487.     return rv;
  488. }
  489.  
  490. static object *
  491. imageop_grey42grey(self, args)
  492.     object *self;
  493.     object *args;
  494. {
  495.     int x, y, len, nlen;
  496.     unsigned char *cp, *ncp;
  497.     object *rv;
  498.     int i, pos, value, nvalue;
  499.     
  500.     if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) )
  501.       return 0;
  502.  
  503.     nlen = x*y;
  504.     if ( (nlen+1)/2 != len ) {
  505.     err_setstr(ImageopError, "String has incorrect length");
  506.     return 0;
  507.     }
  508.     
  509.     rv = newsizedstringobject(NULL, nlen);
  510.     if ( rv == 0 )
  511.       return 0;
  512.     ncp = (unsigned char *)getstringvalue(rv);
  513.  
  514.     pos = 0;
  515.     for ( i=0; i < nlen; i++ ) {
  516.     if ( pos == 0 ) {
  517.         value = *cp++;
  518.         pos = 8;
  519.     }
  520.     pos -= 4;
  521.     nvalue = (value >> pos) & 0x0f;
  522.     *ncp++ = nvalue | (nvalue << 4);
  523.     }
  524.     return rv;
  525. }
  526.  
  527. static object *
  528. imageop_rgb2rgb8(self, args)
  529.     object *self;
  530.     object *args;
  531. {
  532.     int x, y, len, nlen;
  533.     unsigned long *cp;
  534.     unsigned char *ncp;
  535.     object *rv;
  536.     int i, r, g, b;
  537.     unsigned long value, nvalue;
  538.     
  539.     if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) )
  540.       return 0;
  541.  
  542.     nlen = x*y;
  543.     if ( nlen*4 != len ) {
  544.     err_setstr(ImageopError, "String has incorrect length");
  545.     return 0;
  546.     }
  547.     
  548.     rv = newsizedstringobject(NULL, nlen);
  549.     if ( rv == 0 )
  550.       return 0;
  551.     ncp = (unsigned char *)getstringvalue(rv);
  552.  
  553.     for ( i=0; i < nlen; i++ ) {
  554.     /* Bits in source: aaaaaaaa BBbbbbbb GGGggggg RRRrrrrr */
  555.     value = *cp++;
  556. #if 0
  557.     r = (value >>  5) & 7;
  558.     g = (value >> 13) & 7;
  559.     b = (value >> 22) & 3;
  560. #else
  561.     r = (int) ((value & 0xff) / 255. * 7. + .5);
  562.     g = (int) (((value >> 8) & 0xff) / 255. * 7. + .5);
  563.     b = (int) (((value >> 16) & 0xff) / 255. * 3. + .5);
  564. #endif
  565.     nvalue = (r<<5) | (b<<3) | g;
  566.     *ncp++ = nvalue;
  567.     }
  568.     return rv;
  569. }
  570.  
  571. static object *
  572. imageop_rgb82rgb(self, args)
  573.     object *self;
  574.     object *args;
  575. {
  576.     int x, y, len, nlen;
  577.     unsigned char *cp;
  578.     unsigned long *ncp;
  579.     object *rv;
  580.     int i, r, g, b;
  581.     unsigned long value, nvalue;
  582.     
  583.     if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) )
  584.       return 0;
  585.  
  586.     nlen = x*y;
  587.     if ( nlen != len ) {
  588.     err_setstr(ImageopError, "String has incorrect length");
  589.     return 0;
  590.     }
  591.     
  592.     rv = newsizedstringobject(NULL, nlen*4);
  593.     if ( rv == 0 )
  594.       return 0;
  595.     ncp = (unsigned long *)getstringvalue(rv);
  596.  
  597.     for ( i=0; i < nlen; i++ ) {
  598.     /* Bits in source: RRRBBGGG
  599.     ** Red and Green are multiplied by 36.5, Blue by 85
  600.     */
  601.     value = *cp++;
  602.     r = (value >> 5) & 7;
  603.     g = (value     ) & 7;
  604.     b = (value >> 3) & 3;
  605.     r = (r<<5) | (r<<3) | (r>>1);
  606.     g = (g<<5) | (g<<3) | (g>>1);
  607.     b = (b<<6) | (b<<4) | (b<<2) | b;
  608.     nvalue = r | (g<<8) | (b<<16);
  609.     *ncp++ = nvalue;
  610.     }
  611.     return rv;
  612. }
  613.  
  614. static object *
  615. imageop_rgb2grey(self, args)
  616.     object *self;
  617.     object *args;
  618. {
  619.     int x, y, len, nlen;
  620.     unsigned long *cp;
  621.     unsigned char *ncp;
  622.     object *rv;
  623.     int i, r, g, b;
  624.     unsigned long value, nvalue;
  625.     
  626.     if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) )
  627.       return 0;
  628.  
  629.     nlen = x*y;
  630.     if ( nlen*4 != len ) {
  631.     err_setstr(ImageopError, "String has incorrect length");
  632.     return 0;
  633.     }
  634.     
  635.     rv = newsizedstringobject(NULL, nlen);
  636.     if ( rv == 0 )
  637.       return 0;
  638.     ncp = (unsigned char *)getstringvalue(rv);
  639.  
  640.     for ( i=0; i < nlen; i++ ) {
  641.     value = *cp++;
  642.     r = (value      ) & 0xff;
  643.     g = (value >>  8) & 0xff;
  644.     b = (value >> 16) & 0xff;
  645.     nvalue = (int)(0.30*r + 0.59*g + 0.11*b);
  646.     if ( nvalue > 255 ) nvalue = 255;
  647.     *ncp++ = nvalue;
  648.     }
  649.     return rv;
  650. }
  651.  
  652. static object *
  653. imageop_grey2rgb(self, args)
  654.     object *self;
  655.     object *args;
  656. {
  657.     int x, y, len, nlen;
  658.     unsigned char *cp;
  659.     unsigned long *ncp;
  660.     object *rv;
  661.     int i;
  662.     unsigned long value;
  663.     
  664.     if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) )
  665.       return 0;
  666.  
  667.     nlen = x*y;
  668.     if ( nlen != len ) {
  669.     err_setstr(ImageopError, "String has incorrect length");
  670.     return 0;
  671.     }
  672.     
  673.     rv = newsizedstringobject(NULL, nlen*4);
  674.     if ( rv == 0 )
  675.       return 0;
  676.     ncp = (unsigned long *)getstringvalue(rv);
  677.  
  678.     for ( i=0; i < nlen; i++ ) {
  679.     value = *cp++;
  680.     *ncp++ = value | (value << 8 ) | (value << 16);
  681.     }
  682.     return rv;
  683. }
  684.  
  685. /*
  686. static object *
  687. imageop_mul(self, args)
  688.     object *self;
  689.     object *args;
  690. {
  691.     char *cp, *ncp;
  692.     int len, size, x, y;
  693.     object *rv;
  694.     int i;
  695.  
  696.     if ( !getargs(args, "(s#iii)", &cp, &len, &size, &x, &y) )
  697.       return 0;
  698.     
  699.     if ( size != 1 && size != 4 ) {
  700.     err_setstr(ImageopError, "Size should be 1 or 4");
  701.     return 0;
  702.     }
  703.     if ( len != size*x*y ) {
  704.     err_setstr(ImageopError, "String has incorrect length");
  705.     return 0;
  706.     }
  707.     
  708.     rv = newsizedstringobject(NULL, XXXX);
  709.     if ( rv == 0 )
  710.       return 0;
  711.     ncp = (char *)getstringvalue(rv);
  712.     
  713.     
  714.     for ( i=0; i < len; i += size ) {
  715.     }
  716.     return rv;
  717. }
  718. */
  719.  
  720. static struct methodlist imageop_methods[] = {
  721.     { "crop",        imageop_crop },
  722.     { "scale",        imageop_scale },
  723.     { "grey2mono",    imageop_grey2mono },
  724.     { "grey2grey2",    imageop_grey2grey2 },
  725.     { "grey2grey4",    imageop_grey2grey4 },
  726.     { "dither2mono",    imageop_dither2mono },
  727.     { "dither2grey2",    imageop_dither2grey2 },
  728.     { "mono2grey",    imageop_mono2grey },
  729.     { "grey22grey",    imageop_grey22grey },
  730.     { "grey42grey",    imageop_grey42grey },
  731.     { "tovideo",    imageop_tovideo },
  732.     { "rgb2rgb8",    imageop_rgb2rgb8 },
  733.     { "rgb82rgb",    imageop_rgb82rgb },
  734.     { "rgb2grey",    imageop_rgb2grey },
  735.     { "grey2rgb",    imageop_grey2rgb },
  736.     { 0,          0 }
  737. };
  738.  
  739.  
  740. void
  741. initimageop()
  742. {
  743.     object *m, *d;
  744.     m = initmodule("imageop", imageop_methods);
  745.     d = getmoduledict(m);
  746.     ImageopError = newstringobject("imageop.error");
  747.     if ( ImageopError == NULL || dictinsert(d,"error",ImageopError) )
  748.         fatal("can't define imageop.error");
  749. }
  750.