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

Renamed.

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