home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / Python2 / Python20_source / Modules / imageop.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-25  |  14.3 KB  |  709 lines

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