mixed 8 ch tabs + spaces -> spaces

This commit is contained in:
wiredfool 2014-03-03 20:43:47 -08:00
parent fe5372c867
commit b0f8f49880

191
encode.c
View File

@ -33,13 +33,13 @@
#endif #endif
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Common */ /* Common */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
int (*encode)(Imaging im, ImagingCodecState state, int (*encode)(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes); UINT8* buffer, int bytes);
struct ImagingCodecStateInstance state; struct ImagingCodecStateInstance state;
Imaging im; Imaging im;
PyObject* lock; PyObject* lock;
@ -58,21 +58,21 @@ PyImaging_EncoderNew(int contextsize)
encoder = PyObject_New(ImagingEncoderObject, &ImagingEncoderType); encoder = PyObject_New(ImagingEncoderObject, &ImagingEncoderType);
if (encoder == NULL) if (encoder == NULL)
return NULL; return NULL;
/* Clear the encoder state */ /* Clear the encoder state */
memset(&encoder->state, 0, sizeof(encoder->state)); memset(&encoder->state, 0, sizeof(encoder->state));
/* Allocate encoder context */ /* Allocate encoder context */
if (contextsize > 0) { if (contextsize > 0) {
context = (void*) calloc(1, contextsize); context = (void*) calloc(1, contextsize);
if (!context) { if (!context) {
Py_DECREF(encoder); Py_DECREF(encoder);
(void) PyErr_NoMemory(); (void) PyErr_NoMemory();
return NULL; return NULL;
} }
} else } else
context = 0; context = 0;
/* Initialize encoder context */ /* Initialize encoder context */
encoder->state.context = context; encoder->state.context = context;
@ -105,14 +105,14 @@ _encode(ImagingEncoderObject* encoder, PyObject* args)
int bufsize = 16384; int bufsize = 16384;
if (!PyArg_ParseTuple(args, "|i", &bufsize)) if (!PyArg_ParseTuple(args, "|i", &bufsize))
return NULL; return NULL;
buf = PyBytes_FromStringAndSize(NULL, bufsize); buf = PyBytes_FromStringAndSize(NULL, bufsize);
if (!buf) if (!buf)
return NULL; return NULL;
status = encoder->encode(encoder->im, &encoder->state, status = encoder->encode(encoder->im, &encoder->state,
(UINT8*) PyBytes_AsString(buf), bufsize); (UINT8*) PyBytes_AsString(buf), bufsize);
/* adjust string length to avoid slicing in encoder */ /* adjust string length to avoid slicing in encoder */
if (_PyBytes_Resize(&buf, (status > 0) ? status : 0) < 0) if (_PyBytes_Resize(&buf, (status > 0) ? status : 0) < 0)
@ -138,28 +138,28 @@ _encode_to_file(ImagingEncoderObject* encoder, PyObject* args)
int bufsize = 16384; int bufsize = 16384;
if (!PyArg_ParseTuple(args, "i|i", &fh, &bufsize)) if (!PyArg_ParseTuple(args, "i|i", &fh, &bufsize))
return NULL; return NULL;
/* Allocate an encoder buffer */ /* Allocate an encoder buffer */
buf = (UINT8*) malloc(bufsize); buf = (UINT8*) malloc(bufsize);
if (!buf) if (!buf)
return PyErr_NoMemory(); return PyErr_NoMemory();
ImagingSectionEnter(&cookie); ImagingSectionEnter(&cookie);
do { do {
/* This replaces the inner loop in the ImageFile _save /* This replaces the inner loop in the ImageFile _save
function. */ function. */
status = encoder->encode(encoder->im, &encoder->state, buf, bufsize); status = encoder->encode(encoder->im, &encoder->state, buf, bufsize);
if (status > 0) if (status > 0)
if (write(fh, buf, status) < 0) { if (write(fh, buf, status) < 0) {
ImagingSectionLeave(&cookie); ImagingSectionLeave(&cookie);
free(buf); free(buf);
return PyErr_SetFromErrno(PyExc_IOError); return PyErr_SetFromErrno(PyExc_IOError);
} }
} while (encoder->state.errcode == 0); } while (encoder->state.errcode == 0);
@ -186,39 +186,39 @@ _setimage(ImagingEncoderObject* encoder, PyObject* args)
/* FIXME: should publish the ImagingType descriptor */ /* FIXME: should publish the ImagingType descriptor */
if (!PyArg_ParseTuple(args, "O|(iiii)", &op, &x0, &y0, &x1, &y1)) if (!PyArg_ParseTuple(args, "O|(iiii)", &op, &x0, &y0, &x1, &y1))
return NULL; return NULL;
im = PyImaging_AsImaging(op); im = PyImaging_AsImaging(op);
if (!im) if (!im)
return NULL; return NULL;
encoder->im = im; encoder->im = im;
state = &encoder->state; state = &encoder->state;
if (x0 == 0 && x1 == 0) { if (x0 == 0 && x1 == 0) {
state->xsize = im->xsize; state->xsize = im->xsize;
state->ysize = im->ysize; state->ysize = im->ysize;
} else { } else {
state->xoff = x0; state->xoff = x0;
state->yoff = y0; state->yoff = y0;
state->xsize = x1 - x0; state->xsize = x1 - x0;
state->ysize = y1 - y0; state->ysize = y1 - y0;
} }
if (state->xsize <= 0 || if (state->xsize <= 0 ||
state->xsize + state->xoff > im->xsize || state->xsize + state->xoff > im->xsize ||
state->ysize <= 0 || state->ysize <= 0 ||
state->ysize + state->yoff > im->ysize) { state->ysize + state->yoff > im->ysize) {
PyErr_SetString(PyExc_SystemError, "tile cannot extend outside image"); PyErr_SetString(PyExc_SystemError, "tile cannot extend outside image");
return NULL; return NULL;
} }
/* Allocate memory buffer (if bits field is set) */ /* Allocate memory buffer (if bits field is set) */
if (state->bits > 0) { if (state->bits > 0) {
state->bytes = (state->bits * state->xsize+7)/8; state->bytes = (state->bits * state->xsize+7)/8;
state->buffer = (UINT8*) malloc(state->bytes); state->buffer = (UINT8*) malloc(state->bytes);
if (!state->buffer) if (!state->buffer)
return PyErr_NoMemory(); return PyErr_NoMemory();
} }
/* Keep a reference to the image object, to make sure it doesn't /* Keep a reference to the image object, to make sure it doesn't
@ -239,13 +239,13 @@ static struct PyMethodDef methods[] = {
}; };
static PyTypeObject ImagingEncoderType = { static PyTypeObject ImagingEncoderType = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"ImagingEncoder", /*tp_name*/ "ImagingEncoder", /*tp_name*/
sizeof(ImagingEncoderObject), /*tp_size*/ sizeof(ImagingEncoderObject), /*tp_size*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
/* methods */ /* methods */
(destructor)_dealloc, /*tp_dealloc*/ (destructor)_dealloc, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
0, /*tp_compare*/ 0, /*tp_compare*/
@ -283,9 +283,9 @@ get_packer(ImagingEncoderObject* encoder, const char* mode,
pack = ImagingFindPacker(mode, rawmode, &bits); pack = ImagingFindPacker(mode, rawmode, &bits);
if (!pack) { if (!pack) {
Py_DECREF(encoder); Py_DECREF(encoder);
PyErr_SetString(PyExc_SystemError, "unknown raw mode"); PyErr_SetString(PyExc_SystemError, "unknown raw mode");
return -1; return -1;
} }
encoder->state.shuffle = pack; encoder->state.shuffle = pack;
@ -296,7 +296,7 @@ get_packer(ImagingEncoderObject* encoder, const char* mode,
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* EPS */ /* EPS */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject* PyObject*
@ -306,7 +306,7 @@ PyImaging_EpsEncoderNew(PyObject* self, PyObject* args)
encoder = PyImaging_EncoderNew(0); encoder = PyImaging_EncoderNew(0);
if (encoder == NULL) if (encoder == NULL)
return NULL; return NULL;
encoder->encode = ImagingEpsEncode; encoder->encode = ImagingEpsEncode;
@ -315,7 +315,7 @@ PyImaging_EpsEncoderNew(PyObject* self, PyObject* args)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* GIF */ /* GIF */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject* PyObject*
@ -328,14 +328,14 @@ PyImaging_GifEncoderNew(PyObject* self, PyObject* args)
int bits = 8; int bits = 8;
int interlace = 0; int interlace = 0;
if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &bits, &interlace)) if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &bits, &interlace))
return NULL; return NULL;
encoder = PyImaging_EncoderNew(sizeof(GIFENCODERSTATE)); encoder = PyImaging_EncoderNew(sizeof(GIFENCODERSTATE));
if (encoder == NULL) if (encoder == NULL)
return NULL; return NULL;
if (get_packer(encoder, mode, rawmode) < 0) if (get_packer(encoder, mode, rawmode) < 0)
return NULL; return NULL;
encoder->encode = ImagingGifEncode; encoder->encode = ImagingGifEncode;
@ -347,7 +347,7 @@ PyImaging_GifEncoderNew(PyObject* self, PyObject* args)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* PCX */ /* PCX */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject* PyObject*
@ -358,15 +358,19 @@ PyImaging_PcxEncoderNew(PyObject* self, PyObject* args)
char *mode; char *mode;
char *rawmode; char *rawmode;
int bits = 8; int bits = 8;
if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &bits))
return NULL; if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &bits)) {
return NULL;
}
encoder = PyImaging_EncoderNew(0); encoder = PyImaging_EncoderNew(0);
if (encoder == NULL) if (encoder == NULL) {
return NULL; return NULL;
}
if (get_packer(encoder, mode, rawmode) < 0) if (get_packer(encoder, mode, rawmode) < 0) {
return NULL; return NULL;
}
encoder->encode = ImagingPcxEncode; encoder->encode = ImagingPcxEncode;
@ -375,7 +379,7 @@ PyImaging_PcxEncoderNew(PyObject* self, PyObject* args)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* RAW */ /* RAW */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject* PyObject*
@ -389,14 +393,14 @@ PyImaging_RawEncoderNew(PyObject* self, PyObject* args)
int ystep = 1; int ystep = 1;
if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &stride, &ystep)) if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &stride, &ystep))
return NULL; return NULL;
encoder = PyImaging_EncoderNew(0); encoder = PyImaging_EncoderNew(0);
if (encoder == NULL) if (encoder == NULL)
return NULL; return NULL;
if (get_packer(encoder, mode, rawmode) < 0) if (get_packer(encoder, mode, rawmode) < 0)
return NULL; return NULL;
encoder->encode = ImagingRawEncode; encoder->encode = ImagingRawEncode;
@ -408,7 +412,7 @@ PyImaging_RawEncoderNew(PyObject* self, PyObject* args)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* XBM */ /* XBM */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject* PyObject*
@ -418,10 +422,10 @@ PyImaging_XbmEncoderNew(PyObject* self, PyObject* args)
encoder = PyImaging_EncoderNew(0); encoder = PyImaging_EncoderNew(0);
if (encoder == NULL) if (encoder == NULL)
return NULL; return NULL;
if (get_packer(encoder, "1", "1;R") < 0) if (get_packer(encoder, "1", "1;R") < 0)
return NULL; return NULL;
encoder->encode = ImagingXbmEncode; encoder->encode = ImagingXbmEncode;
@ -430,7 +434,7 @@ PyImaging_XbmEncoderNew(PyObject* self, PyObject* args)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* ZIP */ /* ZIP */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
@ -469,16 +473,16 @@ PyImaging_ZipEncoderNew(PyObject* self, PyObject* args)
encoder = PyImaging_EncoderNew(sizeof(ZIPSTATE)); encoder = PyImaging_EncoderNew(sizeof(ZIPSTATE));
if (encoder == NULL) if (encoder == NULL)
return NULL; return NULL;
if (get_packer(encoder, mode, rawmode) < 0) if (get_packer(encoder, mode, rawmode) < 0)
return NULL; return NULL;
encoder->encode = ImagingZipEncode; encoder->encode = ImagingZipEncode;
if (rawmode[0] == 'P') if (rawmode[0] == 'P')
/* disable filtering */ /* disable filtering */
((ZIPSTATE*)encoder->state.context)->mode = ZIP_PNG_PALETTE; ((ZIPSTATE*)encoder->state.context)->mode = ZIP_PNG_PALETTE;
((ZIPSTATE*)encoder->state.context)->optimize = optimize; ((ZIPSTATE*)encoder->state.context)->optimize = optimize;
((ZIPSTATE*)encoder->state.context)->compress_level = compress_level; ((ZIPSTATE*)encoder->state.context)->compress_level = compress_level;
@ -492,7 +496,7 @@ PyImaging_ZipEncoderNew(PyObject* self, PyObject* args)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* JPEG */ /* JPEG */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
#ifdef HAVE_LIBJPEG #ifdef HAVE_LIBJPEG
@ -500,15 +504,15 @@ PyImaging_ZipEncoderNew(PyObject* self, PyObject* args)
/* We better define this encoder last in this file, so the following /* We better define this encoder last in this file, so the following
undef's won't mess things up for the Imaging library proper. */ undef's won't mess things up for the Imaging library proper. */
#undef HAVE_PROTOTYPES #undef HAVE_PROTOTYPES
#undef HAVE_STDDEF_H #undef HAVE_STDDEF_H
#undef HAVE_STDLIB_H #undef HAVE_STDLIB_H
#undef UINT8 #undef UINT8
#undef UINT16 #undef UINT16
#undef UINT32 #undef UINT32
#undef INT8 #undef INT8
#undef INT16 #undef INT16
#undef INT32 #undef INT32
#include "Jpeg.h" #include "Jpeg.h"
@ -601,14 +605,14 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
&progressive, &smooth, &optimize, &streamtype, &progressive, &smooth, &optimize, &streamtype,
&xdpi, &ydpi, &subsampling, &qtables, &extra, &extra_size, &xdpi, &ydpi, &subsampling, &qtables, &extra, &extra_size,
&rawExif, &rawExifLen)) &rawExif, &rawExifLen))
return NULL; return NULL;
encoder = PyImaging_EncoderNew(sizeof(JPEGENCODERSTATE)); encoder = PyImaging_EncoderNew(sizeof(JPEGENCODERSTATE));
if (encoder == NULL) if (encoder == NULL)
return NULL; return NULL;
if (get_packer(encoder, mode, rawmode) < 0) if (get_packer(encoder, mode, rawmode) < 0)
return NULL; return NULL;
qarrays = get_qtables_arrays(qtables); qarrays = get_qtables_arrays(qtables);
@ -718,11 +722,11 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
return NULL; return NULL;
} }
// While failes on 64 bit machines, complains that pos is an int instead of a Py_ssize_t // While failes on 64 bit machines, complains that pos is an int instead of a Py_ssize_t
// while (PyDict_Next(dir, &pos, &key, &value)) { // while (PyDict_Next(dir, &pos, &key, &value)) {
for (pos=0;pos<d_size;pos++){ for (pos=0;pos<d_size;pos++){
key = PyList_GetItem(keys,pos); key = PyList_GetItem(keys,pos);
value = PyList_GetItem(values,pos); value = PyList_GetItem(values,pos);
status = 0; status = 0;
TRACE(("Attempting to set key: %d\n", (int)PyInt_AsLong(key))); TRACE(("Attempting to set key: %d\n", (int)PyInt_AsLong(key)));
if (PyInt_Check(value)) { if (PyInt_Check(value)) {
@ -793,3 +797,4 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
#endif #endif