Commit 30a0fd24 authored by Roger E. Masse's avatar Roger E. Masse

Renamed.

parent 9870380e
...@@ -35,47 +35,46 @@ PERFORMANCE OF THIS SOFTWARE. ...@@ -35,47 +35,46 @@ PERFORMANCE OF THIS SOFTWARE.
#define signed #define signed
#endif #endif
#include "allobjects.h" #include "Python.h"
#include "modsupport.h"
#define CHARP(cp, xmax, x, y) ((char *)(cp+y*xmax+x)) #define CHARP(cp, xmax, x, y) ((char *)(cp+y*xmax+x))
#define SHORTP(cp, xmax, x, y) ((short *)(cp+2*(y*xmax+x))) #define SHORTP(cp, xmax, x, y) ((short *)(cp+2*(y*xmax+x)))
#define LONGP(cp, xmax, x, y) ((long *)(cp+4*(y*xmax+x))) #define LONGP(cp, xmax, x, y) ((long *)(cp+4*(y*xmax+x)))
static object *ImageopError; static PyObject *ImageopError;
static object * static PyObject *
imageop_crop(self, args) imageop_crop(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
char *cp, *ncp; char *cp, *ncp;
short *nsp; short *nsp;
long *nlp; long *nlp;
int len, size, x, y, newx1, newx2, newy1, newy2; int len, size, x, y, newx1, newx2, newy1, newy2;
int ix, iy, xstep, ystep; int ix, iy, xstep, ystep;
object *rv; PyObject *rv;
if ( !getargs(args, "(s#iiiiiii)", &cp, &len, &size, &x, &y, if ( !PyArg_Parse(args, "(s#iiiiiii)", &cp, &len, &size, &x, &y,
&newx1, &newy1, &newx2, &newy2) ) &newx1, &newy1, &newx2, &newy2) )
return 0; return 0;
if ( size != 1 && size != 2 && size != 4 ) { if ( size != 1 && size != 2 && size != 4 ) {
err_setstr(ImageopError, "Size should be 1, 2 or 4"); PyErr_SetString(ImageopError, "Size should be 1, 2 or 4");
return 0; return 0;
} }
if ( len != size*x*y ) { if ( len != size*x*y ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
xstep = (newx1 < newx2)? 1 : -1; xstep = (newx1 < newx2)? 1 : -1;
ystep = (newy1 < newy2)? 1 : -1; ystep = (newy1 < newy2)? 1 : -1;
rv = newsizedstringobject(NULL, rv = PyString_FromStringAndSize(NULL,
(abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size); (abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (char *)getstringvalue(rv); ncp = (char *)PyString_AsString(rv);
nsp = (short *)ncp; nsp = (short *)ncp;
nlp = (long *)ncp; nlp = (long *)ncp;
newy2 += ystep; newy2 += ystep;
...@@ -83,22 +82,27 @@ imageop_crop(self, args) ...@@ -83,22 +82,27 @@ imageop_crop(self, args)
for( iy = newy1; iy != newy2; iy+=ystep ) { for( iy = newy1; iy != newy2; iy+=ystep ) {
for ( ix = newx1; ix != newx2; ix+=xstep ) { for ( ix = newx1; ix != newx2; ix+=xstep ) {
if ( iy < 0 || iy >= y || ix < 0 || ix >= x ) { if ( iy < 0 || iy >= y || ix < 0 || ix >= x ) {
if ( size == 1 ) *ncp++ = 0; if ( size == 1 )
else *nlp++ = 0; *ncp++ = 0;
else
*nlp++ = 0;
} else { } else {
if ( size == 1 ) *ncp++ = *CHARP(cp, x, ix, iy); if ( size == 1 )
else if ( size == 2 ) *nsp++ = *SHORTP(cp, x, ix, iy); *ncp++ = *CHARP(cp, x, ix, iy);
else *nlp++ = *LONGP(cp, x, ix, iy); else if ( size == 2 )
*nsp++ = *SHORTP(cp, x, ix, iy);
else
*nlp++ = *LONGP(cp, x, ix, iy);
} }
} }
} }
return rv; return rv;
} }
static object * static PyObject *
imageop_scale(self, args) imageop_scale(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
char *cp, *ncp; char *cp, *ncp;
short *nsp; short *nsp;
...@@ -106,33 +110,37 @@ imageop_scale(self, args) ...@@ -106,33 +110,37 @@ imageop_scale(self, args)
int len, size, x, y, newx, newy; int len, size, x, y, newx, newy;
int ix, iy; int ix, iy;
int oix, oiy; int oix, oiy;
object *rv; PyObject *rv;
if ( !getargs(args, "(s#iiiii)", &cp, &len, &size, &x, &y, &newx, &newy) ) if ( !PyArg_Parse(args, "(s#iiiii)",
&cp, &len, &size, &x, &y, &newx, &newy) )
return 0; return 0;
if ( size != 1 && size != 2 && size != 4 ) { if ( size != 1 && size != 2 && size != 4 ) {
err_setstr(ImageopError, "Size should be 1, 2 or 4"); PyErr_SetString(ImageopError, "Size should be 1, 2 or 4");
return 0; return 0;
} }
if ( len != size*x*y ) { if ( len != size*x*y ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, newx*newy*size); rv = PyString_FromStringAndSize(NULL, newx*newy*size);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (char *)getstringvalue(rv); ncp = (char *)PyString_AsString(rv);
nsp = (short *)ncp; nsp = (short *)ncp;
nlp = (long *)ncp; nlp = (long *)ncp;
for( iy = 0; iy < newy; iy++ ) { for( iy = 0; iy < newy; iy++ ) {
for ( ix = 0; ix < newx; ix++ ) { for ( ix = 0; ix < newx; ix++ ) {
oix = ix * x / newx; oix = ix * x / newx;
oiy = iy * y / newy; oiy = iy * y / newy;
if ( size == 1 ) *ncp++ = *CHARP(cp, x, oix, oiy); if ( size == 1 )
else if ( size == 2 ) *nsp++ = *SHORTP(cp, x, oix, oiy); *ncp++ = *CHARP(cp, x, oix, oiy);
else *nlp++ = *LONGP(cp, x, oix, oiy); else if ( size == 2 )
*nsp++ = *SHORTP(cp, x, oix, oiy);
else
*nlp++ = *LONGP(cp, x, oix, oiy);
} }
} }
return rv; return rv;
...@@ -140,34 +148,34 @@ imageop_scale(self, args) ...@@ -140,34 +148,34 @@ imageop_scale(self, args)
/* Note: this routine can use a bit of optimizing */ /* Note: this routine can use a bit of optimizing */
static object * static PyObject *
imageop_tovideo(self, args) imageop_tovideo(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int maxx, maxy, x, y, len; int maxx, maxy, x, y, len;
int i; int i;
unsigned char *cp, *ncp; unsigned char *cp, *ncp;
int width; int width;
object *rv; PyObject *rv;
if ( !getargs(args, "(s#iii)", &cp, &len, &width, &maxx, &maxy) ) if ( !PyArg_Parse(args, "(s#iii)", &cp, &len, &width, &maxx, &maxy) )
return 0; return 0;
if ( width != 1 && width != 4 ) { if ( width != 1 && width != 4 ) {
err_setstr(ImageopError, "Size should be 1 or 4"); PyErr_SetString(ImageopError, "Size should be 1 or 4");
return 0; return 0;
} }
if ( maxx*maxy*width != len ) { if ( maxx*maxy*width != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, len); rv = PyString_FromStringAndSize(NULL, len);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
if ( width == 1 ) { if ( width == 1 ) {
memcpy(ncp, cp, maxx); /* Copy first line */ memcpy(ncp, cp, maxx); /* Copy first line */
...@@ -196,30 +204,30 @@ imageop_tovideo(self, args) ...@@ -196,30 +204,30 @@ imageop_tovideo(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_grey2mono(self, args) imageop_grey2mono(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int tres, x, y, len; int tres, x, y, len;
unsigned char *cp, *ncp; unsigned char *cp, *ncp;
unsigned char ovalue; unsigned char ovalue;
object *rv; PyObject *rv;
int i, bit; int i, bit;
if ( !getargs(args, "(s#iii)", &cp, &len, &x, &y, &tres) ) if ( !PyArg_Parse(args, "(s#iii)", &cp, &len, &x, &y, &tres) )
return 0; return 0;
if ( x*y != len ) { if ( x*y != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, (len+7)/8); rv = PyString_FromStringAndSize(NULL, (len+7)/8);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
bit = 0x80; bit = 0x80;
ovalue = 0; ovalue = 0;
...@@ -238,31 +246,31 @@ imageop_grey2mono(self, args) ...@@ -238,31 +246,31 @@ imageop_grey2mono(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_grey2grey4(self, args) imageop_grey2grey4(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int x, y, len; int x, y, len;
unsigned char *cp, *ncp; unsigned char *cp, *ncp;
unsigned char ovalue; unsigned char ovalue;
object *rv; PyObject *rv;
int i; int i;
int pos; int pos;
if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
if ( x*y != len ) { if ( x*y != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, (len+1)/2); rv = PyString_FromStringAndSize(NULL, (len+1)/2);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
pos = 0; pos = 0;
ovalue = 0; ovalue = 0;
for ( i=0; i < len; i++ ) { for ( i=0; i < len; i++ ) {
...@@ -279,31 +287,31 @@ imageop_grey2grey4(self, args) ...@@ -279,31 +287,31 @@ imageop_grey2grey4(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_grey2grey2(self, args) imageop_grey2grey2(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int x, y, len; int x, y, len;
unsigned char *cp, *ncp; unsigned char *cp, *ncp;
unsigned char ovalue; unsigned char ovalue;
object *rv; PyObject *rv;
int i; int i;
int pos; int pos;
if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
if ( x*y != len ) { if ( x*y != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, (len+3)/4); rv = PyString_FromStringAndSize(NULL, (len+3)/4);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
pos = 0; pos = 0;
ovalue = 0; ovalue = 0;
for ( i=0; i < len; i++ ) { for ( i=0; i < len; i++ ) {
...@@ -320,30 +328,30 @@ imageop_grey2grey2(self, args) ...@@ -320,30 +328,30 @@ imageop_grey2grey2(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_dither2mono(self, args) imageop_dither2mono(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int sum, x, y, len; int sum, x, y, len;
unsigned char *cp, *ncp; unsigned char *cp, *ncp;
unsigned char ovalue; unsigned char ovalue;
object *rv; PyObject *rv;
int i, bit; int i, bit;
if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
if ( x*y != len ) { if ( x*y != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, (len+7)/8); rv = PyString_FromStringAndSize(NULL, (len+7)/8);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
bit = 0x80; bit = 0x80;
ovalue = 0; ovalue = 0;
...@@ -366,32 +374,32 @@ imageop_dither2mono(self, args) ...@@ -366,32 +374,32 @@ imageop_dither2mono(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_dither2grey2(self, args) imageop_dither2grey2(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int x, y, len; int x, y, len;
unsigned char *cp, *ncp; unsigned char *cp, *ncp;
unsigned char ovalue; unsigned char ovalue;
object *rv; PyObject *rv;
int i; int i;
int pos; int pos;
int sum = 0, nvalue; int sum = 0, nvalue;
if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
if ( x*y != len ) { if ( x*y != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, (len+3)/4); rv = PyString_FromStringAndSize(NULL, (len+3)/4);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
pos = 1; pos = 1;
ovalue = 0; ovalue = 0;
for ( i=0; i < len; i++ ) { for ( i=0; i < len; i++ ) {
...@@ -411,29 +419,29 @@ imageop_dither2grey2(self, args) ...@@ -411,29 +419,29 @@ imageop_dither2grey2(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_mono2grey(self, args) imageop_mono2grey(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int v0, v1, x, y, len, nlen; int v0, v1, x, y, len, nlen;
unsigned char *cp, *ncp; unsigned char *cp, *ncp;
object *rv; PyObject *rv;
int i, bit; int i, bit;
if ( !getargs(args, "(s#iiii)", &cp, &len, &x, &y, &v0, &v1) ) if ( !PyArg_Parse(args, "(s#iiii)", &cp, &len, &x, &y, &v0, &v1) )
return 0; return 0;
nlen = x*y; nlen = x*y;
if ( (nlen+7)/8 != len ) { if ( (nlen+7)/8 != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, nlen); rv = PyString_FromStringAndSize(NULL, nlen);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
bit = 0x80; bit = 0x80;
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
...@@ -450,29 +458,29 @@ imageop_mono2grey(self, args) ...@@ -450,29 +458,29 @@ imageop_mono2grey(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_grey22grey(self, args) imageop_grey22grey(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int x, y, len, nlen; int x, y, len, nlen;
unsigned char *cp, *ncp; unsigned char *cp, *ncp;
object *rv; PyObject *rv;
int i, pos, value = 0, nvalue; int i, pos, value = 0, nvalue;
if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
nlen = x*y; nlen = x*y;
if ( (nlen+3)/4 != len ) { if ( (nlen+3)/4 != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, nlen); rv = PyString_FromStringAndSize(NULL, nlen);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
pos = 0; pos = 0;
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
...@@ -482,34 +490,35 @@ imageop_grey22grey(self, args) ...@@ -482,34 +490,35 @@ imageop_grey22grey(self, args)
} }
pos -= 2; pos -= 2;
nvalue = (value >> pos) & 0x03; nvalue = (value >> pos) & 0x03;
*ncp++ = nvalue | (nvalue << 2) | (nvalue << 4) | (nvalue << 6); *ncp++ = nvalue | (nvalue << 2) |
(nvalue << 4) | (nvalue << 6);
} }
return rv; return rv;
} }
static object * static PyObject *
imageop_grey42grey(self, args) imageop_grey42grey(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int x, y, len, nlen; int x, y, len, nlen;
unsigned char *cp, *ncp; unsigned char *cp, *ncp;
object *rv; PyObject *rv;
int i, pos, value = 0, nvalue; int i, pos, value = 0, nvalue;
if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
nlen = x*y; nlen = x*y;
if ( (nlen+1)/2 != len ) { if ( (nlen+1)/2 != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, nlen); rv = PyString_FromStringAndSize(NULL, nlen);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
pos = 0; pos = 0;
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
...@@ -524,31 +533,31 @@ imageop_grey42grey(self, args) ...@@ -524,31 +533,31 @@ imageop_grey42grey(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_rgb2rgb8(self, args) imageop_rgb2rgb8(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int x, y, len, nlen; int x, y, len, nlen;
unsigned long *cp; unsigned long *cp;
unsigned char *ncp; unsigned char *ncp;
object *rv; PyObject *rv;
int i, r, g, b; int i, r, g, b;
unsigned long value, nvalue; unsigned long value, nvalue;
if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
nlen = x*y; nlen = x*y;
if ( nlen*4 != len ) { if ( nlen*4 != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, nlen); rv = PyString_FromStringAndSize(NULL, nlen);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
/* Bits in source: aaaaaaaa BBbbbbbb GGGggggg RRRrrrrr */ /* Bits in source: aaaaaaaa BBbbbbbb GGGggggg RRRrrrrr */
...@@ -568,31 +577,31 @@ imageop_rgb2rgb8(self, args) ...@@ -568,31 +577,31 @@ imageop_rgb2rgb8(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_rgb82rgb(self, args) imageop_rgb82rgb(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int x, y, len, nlen; int x, y, len, nlen;
unsigned char *cp; unsigned char *cp;
unsigned long *ncp; unsigned long *ncp;
object *rv; PyObject *rv;
int i, r, g, b; int i, r, g, b;
unsigned long value, nvalue; unsigned long value, nvalue;
if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
nlen = x*y; nlen = x*y;
if ( nlen != len ) { if ( nlen != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, nlen*4); rv = PyString_FromStringAndSize(NULL, nlen*4);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned long *)getstringvalue(rv); ncp = (unsigned long *)PyString_AsString(rv);
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
/* Bits in source: RRRBBGGG /* Bits in source: RRRBBGGG
...@@ -611,31 +620,31 @@ imageop_rgb82rgb(self, args) ...@@ -611,31 +620,31 @@ imageop_rgb82rgb(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_rgb2grey(self, args) imageop_rgb2grey(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int x, y, len, nlen; int x, y, len, nlen;
unsigned long *cp; unsigned long *cp;
unsigned char *ncp; unsigned char *ncp;
object *rv; PyObject *rv;
int i, r, g, b; int i, r, g, b;
unsigned long value, nvalue; unsigned long value, nvalue;
if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
nlen = x*y; nlen = x*y;
if ( nlen*4 != len ) { if ( nlen*4 != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, nlen); rv = PyString_FromStringAndSize(NULL, nlen);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned char *)getstringvalue(rv); ncp = (unsigned char *)PyString_AsString(rv);
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
value = *cp++; value = *cp++;
...@@ -649,31 +658,31 @@ imageop_rgb2grey(self, args) ...@@ -649,31 +658,31 @@ imageop_rgb2grey(self, args)
return rv; return rv;
} }
static object * static PyObject *
imageop_grey2rgb(self, args) imageop_grey2rgb(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int x, y, len, nlen; int x, y, len, nlen;
unsigned char *cp; unsigned char *cp;
unsigned long *ncp; unsigned long *ncp;
object *rv; PyObject *rv;
int i; int i;
unsigned long value; unsigned long value;
if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) if ( !PyArg_Parse(args, "(s#ii)", &cp, &len, &x, &y) )
return 0; return 0;
nlen = x*y; nlen = x*y;
if ( nlen != len ) { if ( nlen != len ) {
err_setstr(ImageopError, "String has incorrect length"); PyErr_SetString(ImageopError, "String has incorrect length");
return 0; return 0;
} }
rv = newsizedstringobject(NULL, nlen*4); rv = PyString_FromStringAndSize(NULL, nlen*4);
if ( rv == 0 ) if ( rv == 0 )
return 0; return 0;
ncp = (unsigned long *)getstringvalue(rv); ncp = (unsigned long *)PyString_AsString(rv);
for ( i=0; i < nlen; i++ ) { for ( i=0; i < nlen; i++ ) {
value = *cp++; value = *cp++;
...@@ -686,7 +695,7 @@ imageop_grey2rgb(self, args) ...@@ -686,7 +695,7 @@ imageop_grey2rgb(self, args)
static object * static object *
imageop_mul(self, args) imageop_mul(self, args)
object *self; object *self;
object *args; object *args;
{ {
char *cp, *ncp; char *cp, *ncp;
int len, size, x, y; int len, size, x, y;
...@@ -717,7 +726,7 @@ imageop_mul(self, args) ...@@ -717,7 +726,7 @@ imageop_mul(self, args)
} }
*/ */
static struct methodlist imageop_methods[] = { static PyMethodDef imageop_methods[] = {
{ "crop", imageop_crop }, { "crop", imageop_crop },
{ "scale", imageop_scale }, { "scale", imageop_scale },
{ "grey2mono", imageop_grey2mono }, { "grey2mono", imageop_grey2mono },
...@@ -740,10 +749,11 @@ static struct methodlist imageop_methods[] = { ...@@ -740,10 +749,11 @@ static struct methodlist imageop_methods[] = {
void void
initimageop() initimageop()
{ {
object *m, *d; PyObject *m, *d;
m = initmodule("imageop", imageop_methods); m = Py_InitModule("imageop", imageop_methods);
d = getmoduledict(m); d = PyModule_GetDict(m);
ImageopError = newstringobject("imageop.error"); ImageopError = PyString_FromString("imageop.error");
if ( ImageopError == NULL || dictinsert(d,"error",ImageopError) ) if ( ImageopError == NULL ||
fatal("can't define imageop.error"); PyDict_SetItemString(d,"error",ImageopError) )
Py_FatalError("can't define imageop.error");
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment