Replaced tabs with spaces

This commit is contained in:
Andrew Murray 2020-05-01 22:08:57 +10:00
parent 51f31f3f5b
commit ae43af61da
43 changed files with 2182 additions and 2181 deletions

View File

@ -4,8 +4,8 @@
* tkinter hooks
*
* history:
* 99-07-26 fl created
* 99-08-15 fl moved to its own support module
* 99-07-26 fl created
* 99-08-15 fl moved to its own support module
*
* Copyright (c) Secret Labs AB 1999.
*
@ -45,8 +45,8 @@ _tkinit(PyObject* self, PyObject* args)
interp = (Tcl_Interp*)PyLong_AsVoidPtr(arg);
else {
TkappObject* app;
/* Do it the hard way. This will break if the TkappObject
layout changes */
/* Do it the hard way. This will break if the TkappObject
layout changes */
app = (TkappObject*)PyLong_AsVoidPtr(arg);
interp = app->interp;
}

View File

@ -836,7 +836,7 @@ void addAnimFlagToModule(PyObject* m) {
void addTransparencyFlagToModule(PyObject* m) {
PyModule_AddObject(m, "HAVE_TRANSPARENCY",
PyBool_FromLong(!WebPDecoderBuggyAlpha()));
PyBool_FromLong(!WebPDecoderBuggyAlpha()));
}
static int setup_module(PyObject* m) {

View File

@ -28,7 +28,7 @@
#include "Imaging.h"
/* -------------------------------------------------------------------- */
/* Windows DIB support */
/* Windows DIB support */
#ifdef _WIN32
@ -57,12 +57,12 @@ _new(const char* mode, int xsize, int ysize)
display = PyObject_New(ImagingDisplayObject, &ImagingDisplayType);
if (display == NULL)
return NULL;
return NULL;
display->dib = ImagingNewDIB(mode, xsize, ysize);
if (!display->dib) {
Py_DECREF(display);
return NULL;
Py_DECREF(display);
return NULL;
}
return display;
@ -72,7 +72,7 @@ static void
_delete(ImagingDisplayObject* display)
{
if (display->dib)
ImagingDeleteDIB(display->dib);
ImagingDeleteDIB(display->dib);
PyObject_Del(display);
}
@ -81,7 +81,7 @@ _expose(ImagingDisplayObject* display, PyObject* args)
{
HDC hdc;
if (!PyArg_ParseTuple(args, F_HANDLE, &hdc))
return NULL;
return NULL;
ImagingExposeDIB(display->dib, hdc);
@ -98,7 +98,7 @@ _draw(ImagingDisplayObject* display, PyObject* args)
if (!PyArg_ParseTuple(args, F_HANDLE "(iiii)(iiii)", &hdc,
dst+0, dst+1, dst+2, dst+3,
src+0, src+1, src+2, src+3))
return NULL;
return NULL;
ImagingDrawDIB(display->dib, hdc, dst, src);
@ -117,15 +117,15 @@ _paste(ImagingDisplayObject* display, PyObject* args)
int xy[4];
xy[0] = xy[1] = xy[2] = xy[3] = 0;
if (!PyArg_ParseTuple(args, "O|(iiii)", &op, xy+0, xy+1, xy+2, xy+3))
return NULL;
return NULL;
im = PyImaging_AsImaging(op);
if (!im)
return NULL;
return NULL;
if (xy[2] <= xy[0])
xy[2] = xy[0] + im->xsize;
xy[2] = xy[0] + im->xsize;
if (xy[3] <= xy[1])
xy[3] = xy[1] + im->ysize;
xy[3] = xy[1] + im->ysize;
ImagingPasteDIB(display->dib, im, xy);
@ -140,7 +140,7 @@ _query_palette(ImagingDisplayObject* display, PyObject* args)
int status;
if (!PyArg_ParseTuple(args, F_HANDLE, &hdc))
return NULL;
return NULL;
status = ImagingQueryPaletteDIB(display->dib, hdc);
@ -154,7 +154,7 @@ _getdc(ImagingDisplayObject* display, PyObject* args)
HDC dc;
if (!PyArg_ParseTuple(args, F_HANDLE, &window))
return NULL;
return NULL;
dc = GetDC(window);
if (!dc) {
@ -172,7 +172,7 @@ _releasedc(ImagingDisplayObject* display, PyObject* args)
HDC dc;
if (!PyArg_ParseTuple(args, F_HANDLE F_HANDLE, &window, &dc))
return NULL;
return NULL;
ReleaseDC(window, dc);
@ -228,13 +228,13 @@ static struct PyMethodDef methods[] = {
static PyObject*
_getattr_mode(ImagingDisplayObject* self, void* closure)
{
return Py_BuildValue("s", self->dib->mode);
return Py_BuildValue("s", self->dib->mode);
}
static PyObject*
_getattr_size(ImagingDisplayObject* self, void* closure)
{
return Py_BuildValue("ii", self->dib->xsize, self->dib->ysize);
return Py_BuildValue("ii", self->dib->xsize, self->dib->ysize);
}
static struct PyGetSetDef getsetters[] = {
@ -244,13 +244,13 @@ static struct PyGetSetDef getsetters[] = {
};
static PyTypeObject ImagingDisplayType = {
PyVarObject_HEAD_INIT(NULL, 0)
"ImagingDisplay", /*tp_name*/
sizeof(ImagingDisplayObject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
(destructor)_delete, /*tp_dealloc*/
0, /*tp_print*/
PyVarObject_HEAD_INIT(NULL, 0)
"ImagingDisplay", /*tp_name*/
sizeof(ImagingDisplayObject),/*tp_size*/
0, /*tp_itemsize*/
/* methods */
(destructor)_delete, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
@ -285,11 +285,11 @@ PyImaging_DisplayWin32(PyObject* self, PyObject* args)
int xsize, ysize;
if (!PyArg_ParseTuple(args, "s(ii)", &mode, &xsize, &ysize))
return NULL;
return NULL;
display = _new(mode, xsize, ysize);
if (display == NULL)
return NULL;
return NULL;
return (PyObject*) display;
}
@ -647,7 +647,7 @@ PyImaging_CreateWindowWin32(PyObject* self, PyObject* args)
PyObject* callback;
int width = 0, height = 0;
if (!PyArg_ParseTuple(args, "sO|ii", &title, &callback, &width, &height))
return NULL;
return NULL;
if (width <= 0)
width = CW_USEDEFAULT;
@ -817,7 +817,7 @@ error:
#endif /* _WIN32 */
/* -------------------------------------------------------------------- */
/* X11 support */
/* X11 support */
#ifdef HAVE_XCB
#include <xcb/xcb.h>

View File

@ -1095,7 +1095,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
/* -------------------------------------------------------------------- */
/* JPEG 2000 */
/* JPEG 2000 */
/* -------------------------------------------------------------------- */
#ifdef HAVE_OPENJPEG

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
* decoder for packed bitfields (converts to floating point)
*
* history:
* 97-05-31 fl created (much more than originally intended)
* 97-05-31 fl created (much more than originally intended)
*
* Copyright (c) Fredrik Lundh 1997.
* Copyright (c) Secret Labs AB 1997.
@ -27,18 +27,18 @@ ImagingBitDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
if (state->state == 0) {
/* Initialize context variables */
/* Initialize context variables */
/* this decoder only works for float32 image buffers */
if (im->type != IMAGING_TYPE_FLOAT32) {
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}
/* sanity check */
if (bitstate->bits < 1 || bitstate->bits >= 32) {
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}
bitstate->mask = (1<<bitstate->bits)-1;
@ -46,14 +46,14 @@ ImagingBitDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
if (bitstate->sign)
bitstate->signmask = (1<<(bitstate->bits-1));
/* check image orientation */
if (state->ystep < 0) {
state->y = state->ysize-1;
state->ystep = -1;
} else
state->ystep = 1;
/* check image orientation */
if (state->ystep < 0) {
state->y = state->ysize-1;
state->ystep = -1;
} else
state->ystep = 1;
state->state = 1;
state->state = 1;
}
@ -119,7 +119,7 @@ ImagingBitDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
*(FLOAT32*)(&im->image32[state->y][state->x]) = pixel;
/* step forward */
if (++state->x >= state->xsize) {
if (++state->x >= state->xsize) {
/* new line */
state->y += state->ystep;
if (state->y < 0 || state->y >= state->ysize) {

View File

@ -5,9 +5,9 @@
* interpolate between two existing images
*
* history:
* 96-03-20 fl Created
* 96-05-18 fl Simplified blend expression
* 96-10-05 fl Fixed expression bug, special case for interpolation
* 96-03-20 fl Created
* 96-05-18 fl Simplified blend expression
* 96-10-05 fl Fixed expression bug, special case for interpolation
*
* Copyright (c) Fredrik Lundh 1996.
* Copyright (c) Secret Labs AB 1997.
@ -32,48 +32,48 @@ ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha)
return ImagingError_ModeError();
if (imIn1->type != imIn2->type ||
imIn1->bands != imIn2->bands ||
imIn1->xsize != imIn2->xsize ||
imIn1->ysize != imIn2->ysize)
return ImagingError_Mismatch();
imIn1->bands != imIn2->bands ||
imIn1->xsize != imIn2->xsize ||
imIn1->ysize != imIn2->ysize)
return ImagingError_Mismatch();
/* Shortcuts */
if (alpha == 0.0)
return ImagingCopy(imIn1);
return ImagingCopy(imIn1);
else if (alpha == 1.0)
return ImagingCopy(imIn2);
return ImagingCopy(imIn2);
imOut = ImagingNewDirty(imIn1->mode, imIn1->xsize, imIn1->ysize);
if (!imOut)
return NULL;
return NULL;
if (alpha >= 0 && alpha <= 1.0) {
/* Interpolate between bands */
for (y = 0; y < imIn1->ysize; y++) {
UINT8* in1 = (UINT8*) imIn1->image[y];
UINT8* in2 = (UINT8*) imIn2->image[y];
UINT8* out = (UINT8*) imOut->image[y];
for (x = 0; x < imIn1->linesize; x++)
out[x] = (UINT8)
((int) in1[x] + alpha * ((int) in2[x] - (int) in1[x]));
}
/* Interpolate between bands */
for (y = 0; y < imIn1->ysize; y++) {
UINT8* in1 = (UINT8*) imIn1->image[y];
UINT8* in2 = (UINT8*) imIn2->image[y];
UINT8* out = (UINT8*) imOut->image[y];
for (x = 0; x < imIn1->linesize; x++)
out[x] = (UINT8)
((int) in1[x] + alpha * ((int) in2[x] - (int) in1[x]));
}
} else {
/* Extrapolation; must make sure to clip resulting values */
for (y = 0; y < imIn1->ysize; y++) {
UINT8* in1 = (UINT8*) imIn1->image[y];
UINT8* in2 = (UINT8*) imIn2->image[y];
UINT8* out = (UINT8*) imOut->image[y];
for (x = 0; x < imIn1->linesize; x++) {
float temp = (float)
((int) in1[x] + alpha * ((int) in2[x] - (int) in1[x]));
if (temp <= 0.0)
out[x] = 0;
else if (temp >= 255.0)
out[x] = 255;
else
out[x] = (UINT8) temp;
}
}
/* Extrapolation; must make sure to clip resulting values */
for (y = 0; y < imIn1->ysize; y++) {
UINT8* in1 = (UINT8*) imIn1->image[y];
UINT8* in2 = (UINT8*) imIn2->image[y];
UINT8* out = (UINT8*) imOut->image[y];
for (x = 0; x < imIn1->linesize; x++) {
float temp = (float)
((int) in1[x] + alpha * ((int) in2[x] - (int) in1[x]));
if (temp <= 0.0)
out[x] = 0;
else if (temp >= 255.0)
out[x] = 255;
else
out[x] = (UINT8) temp;
}
}
}
return imOut;

View File

@ -5,7 +5,7 @@
* code to convert YCbCr data
*
* history:
* 98-07-01 hk Created
* 98-07-01 hk Created
*
* Copyright (c) Secret Labs AB 1998
*

View File

@ -26,7 +26,7 @@ _copy(Imaging imOut, Imaging imIn)
int y;
if (!imIn)
return (Imaging) ImagingError_ValueError(NULL);
return (Imaging) ImagingError_ValueError(NULL);
imOut = ImagingNew2Dirty(imIn->mode, imOut, imIn);
if (!imOut)
@ -36,7 +36,7 @@ _copy(Imaging imOut, Imaging imIn)
ImagingSectionEnter(&cookie);
if (imIn->block != NULL && imOut->block != NULL)
memcpy(imOut->block, imIn->block, imIn->ysize * imIn->linesize);
memcpy(imOut->block, imIn->block, imIn->ysize * imIn->linesize);
else
for (y = 0; y < imIn->ysize; y++)
memcpy(imOut->image[y], imIn->image[y], imIn->linesize);

View File

@ -5,9 +5,9 @@
* cut region from image
*
* history:
* 95-11-27 fl Created
* 98-07-10 fl Fixed "null result" error
* 99-02-05 fl Rewritten to use Paste primitive
* 95-11-27 fl Created
* 98-07-10 fl Fixed "null result" error
* 99-02-05 fl Rewritten to use Paste primitive
*
* Copyright (c) Secret Labs AB 1997-99.
* Copyright (c) Fredrik Lundh 1995.
@ -28,7 +28,7 @@ ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1)
INT32 zero = 0;
if (!imIn)
return (Imaging) ImagingError_ModeError();
return (Imaging) ImagingError_ModeError();
xsize = sx1 - sx0;
if (xsize < 0)
@ -39,12 +39,12 @@ ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1)
imOut = ImagingNewDirty(imIn->mode, xsize, ysize);
if (!imOut)
return NULL;
return NULL;
ImagingCopyPalette(imOut, imIn);
if (sx0 < 0 || sy0 < 0 || sx1 > imIn->xsize || sy1 > imIn->ysize)
(void) ImagingFill(imOut, &zero);
(void) ImagingFill(imOut, &zero);
dx0 = -sx0;
dy0 = -sy0;

View File

@ -5,11 +5,11 @@
* encoder for EPS hex data
*
* history:
* 96-04-19 fl created
* 96-06-27 fl don't drop last block of encoded data
* 96-04-19 fl created
* 96-06-27 fl don't drop last block of encoded data
*
* notes:
* FIXME: rename to HexEncode.c ??
* FIXME: rename to HexEncode.c ??
*
* Copyright (c) Fredrik Lundh 1996.
* Copyright (c) Secret Labs AB 1997.
@ -31,47 +31,47 @@ ImagingEpsEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
UINT8* in, i;
if (!state->state) {
state->state = HEXBYTE;
state->xsize *= im->pixelsize; /* Hack! */
state->state = HEXBYTE;
state->xsize *= im->pixelsize; /* Hack! */
}
in = (UINT8*) im->image[state->y];
for (;;) {
if (state->state == NEWLINE) {
if (bytes < 1)
break;
*ptr++ = '\n';
bytes--;
state->state = HEXBYTE;
}
if (state->state == NEWLINE) {
if (bytes < 1)
break;
*ptr++ = '\n';
bytes--;
state->state = HEXBYTE;
}
if (bytes < 2)
break;
if (bytes < 2)
break;
i = in[state->x++];
*ptr++ = hex[(i>>4)&15];
*ptr++ = hex[i&15];
bytes -= 2;
i = in[state->x++];
*ptr++ = hex[(i>>4)&15];
*ptr++ = hex[i&15];
bytes -= 2;
/* Skip junk bytes */
if (im->bands == 3 && (state->x & 3) == 3)
state->x++;
/* Skip junk bytes */
if (im->bands == 3 && (state->x & 3) == 3)
state->x++;
if (++state->count >= 79/2) {
state->state = NEWLINE;
state->count = 0;
}
if (++state->count >= 79/2) {
state->state = NEWLINE;
state->count = 0;
}
if (state->x >= state->xsize) {
state->x = 0;
if (++state->y >= state->ysize) {
state->errcode = IMAGING_CODEC_END;
break;
}
in = (UINT8*) im->image[state->y];
}
if (state->x >= state->xsize) {
state->x = 0;
if (++state->y >= state->ysize) {
state->errcode = IMAGING_CODEC_END;
break;
}
in = (UINT8*) im->image[state->y];
}
}

View File

@ -57,7 +57,7 @@ void *
ImagingError_ValueError(const char *message)
{
if (!message)
message = "exception: bad argument to function";
message = "exception: bad argument to function";
fprintf(stderr, "*** %s\n", message);
return NULL;
}

View File

@ -5,9 +5,9 @@
* fill image with constant pixel value
*
* history:
* 95-11-26 fl moved from Imaging.c
* 96-05-17 fl added radial fill, renamed wedge to linear
* 98-06-23 fl changed ImageFill signature
* 95-11-26 fl moved from Imaging.c
* 96-05-17 fl added radial fill, renamed wedge to linear
* 98-06-23 fl changed ImageFill signature
*
* Copyright (c) Secret Labs AB 1997-98. All rights reserved.
* Copyright (c) Fredrik Lundh 1995-96.

View File

@ -5,8 +5,8 @@
* decoder for Autodesk Animator FLI/FLC animations
*
* history:
* 97-01-03 fl Created
* 97-01-17 fl Added SS2 support (FLC)
* 97-01-03 fl Created
* 97-01-17 fl Added SS2 support (FLC)
*
* Copyright (c) Fredrik Lundh 1997.
* Copyright (c) Secret Labs AB 1997.
@ -18,10 +18,10 @@
#include "Imaging.h"
#define I16(ptr)\
#define I16(ptr)\
((ptr)[0] + ((ptr)[1] << 8))
#define I32(ptr)\
#define I32(ptr)\
((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24))
#define ERR_IF_DATA_OOB(offset) \
@ -29,7 +29,7 @@
state->errcode = IMAGING_CODEC_OVERRUN; \
return -1; \
}
int
ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
{
@ -42,7 +42,7 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
/* If not even the chunk size is present, we'd better leave */
if (bytes < 4)
return 0;
return 0;
/* We don't decode anything unless we have a full chunk in the
input buffer */
@ -51,7 +51,7 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
framesize = I32(ptr);
if (framesize < I32(ptr))
return 0;
return 0;
/* Make sure this is a frame chunk. The Python driver takes
case of other chunk types. */
@ -61,8 +61,8 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
return -1;
}
if (I16(ptr+4) != 0xF1FA) {
state->errcode = IMAGING_CODEC_UNKNOWN;
return -1;
state->errcode = IMAGING_CODEC_UNKNOWN;
return -1;
}
chunks = I16(ptr+6);
@ -71,173 +71,173 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
/* Process subchunks */
for (c = 0; c < chunks; c++) {
UINT8* data;
if (bytes < 10) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
data = ptr + 6;
switch (I16(ptr+4)) {
case 4: case 11:
/* FLI COLOR chunk */
break; /* ignored; handled by Python code */
case 7:
/* FLI SS2 chunk (word delta) */
/* OOB ok, we've got 4 bytes min on entry */
lines = I16(data); data += 2;
for (l = y = 0; l < lines && y < state->ysize; l++, y++) {
UINT8* local_buf = (UINT8*) im->image[y];
int p, packets;
ERR_IF_DATA_OOB(2)
packets = I16(data); data += 2;
while (packets & 0x8000) {
/* flag word */
if (packets & 0x4000) {
y += 65536 - packets; /* skip lines */
if (y >= state->ysize) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
local_buf = (UINT8*) im->image[y];
} else {
/* store last byte (used if line width is odd) */
local_buf[state->xsize-1] = (UINT8) packets;
}
ERR_IF_DATA_OOB(2)
packets = I16(data); data += 2;
}
for (p = x = 0; p < packets; p++) {
ERR_IF_DATA_OOB(2)
x += data[0]; /* pixel skip */
if (data[1] >= 128) {
ERR_IF_DATA_OOB(4)
i = 256-data[1]; /* run */
if (x + i + i > state->xsize)
break;
for (j = 0; j < i; j++) {
local_buf[x++] = data[2];
local_buf[x++] = data[3];
}
data += 2 + 2;
} else {
i = 2 * (int) data[1]; /* chunk */
if (x + i > state->xsize)
break;
ERR_IF_DATA_OOB(2+i)
memcpy(local_buf + x, data + 2, i);
data += 2 + i;
x += i;
}
}
if (p < packets)
break; /* didn't process all packets */
}
if (l < lines) {
/* didn't process all lines */
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
break;
case 12:
/* FLI LC chunk (byte delta) */
/* OOB Check ok, we have 4 bytes min here */
y = I16(data); ymax = y + I16(data+2); data += 4;
for (; y < ymax && y < state->ysize; y++) {
UINT8* out = (UINT8*) im->image[y];
ERR_IF_DATA_OOB(1)
int p, packets = *data++;
for (p = x = 0; p < packets; p++, x += i) {
ERR_IF_DATA_OOB(2)
x += data[0]; /* skip pixels */
if (data[1] & 0x80) {
i = 256-data[1]; /* run */
if (x + i > state->xsize)
break;
ERR_IF_DATA_OOB(3)
memset(out + x, data[2], i);
data += 3;
} else {
i = data[1]; /* chunk */
if (x + i > state->xsize)
break;
ERR_IF_DATA_OOB(2+i)
memcpy(out + x, data + 2, i);
data += i + 2;
}
}
if (p < packets)
break; /* didn't process all packets */
}
if (y < ymax) {
/* didn't process all lines */
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
break;
case 13:
/* FLI BLACK chunk */
for (y = 0; y < state->ysize; y++)
memset(im->image[y], 0, state->xsize);
break;
case 15:
/* FLI BRUN chunk */
/* OOB, ok, we've got 4 bytes min on entry */
for (y = 0; y < state->ysize; y++) {
UINT8* out = (UINT8*) im->image[y];
data += 1; /* ignore packetcount byte */
for (x = 0; x < state->xsize; x += i) {
ERR_IF_DATA_OOB(2)
if (data[0] & 0x80) {
i = 256 - data[0];
if (x + i > state->xsize) {
break; /* safety first */
}
ERR_IF_DATA_OOB(i+1)
memcpy(out + x, data + 1, i);
data += i + 1;
} else {
i = data[0];
if (x + i > state->xsize)
break; /* safety first */
memset(out + x, data[1], i);
data += 2;
}
}
if (x != state->xsize) {
/* didn't unpack whole line */
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
}
break;
case 16:
/* COPY chunk */
if (state->xsize > bytes/state->ysize) {
/* not enough data for frame */
return ptr - buf; /* bytes consumed */
}
for (y = 0; y < state->ysize; y++) {
UINT8* local_buf = (UINT8*) im->image[y];
memcpy(local_buf, data, state->xsize);
data += state->xsize;
}
break;
case 18:
/* PSTAMP chunk */
break; /* ignored */
default:
/* unknown chunk */
/* printf("unknown FLI/FLC chunk: %d\n", I16(ptr+4)); */
state->errcode = IMAGING_CODEC_UNKNOWN;
return -1;
}
advance = I32(ptr);
if (advance < 0 || advance > bytes) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
ptr += advance;
bytes -= advance;
UINT8* data;
if (bytes < 10) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
data = ptr + 6;
switch (I16(ptr+4)) {
case 4: case 11:
/* FLI COLOR chunk */
break; /* ignored; handled by Python code */
case 7:
/* FLI SS2 chunk (word delta) */
/* OOB ok, we've got 4 bytes min on entry */
lines = I16(data); data += 2;
for (l = y = 0; l < lines && y < state->ysize; l++, y++) {
UINT8* local_buf = (UINT8*) im->image[y];
int p, packets;
ERR_IF_DATA_OOB(2)
packets = I16(data); data += 2;
while (packets & 0x8000) {
/* flag word */
if (packets & 0x4000) {
y += 65536 - packets; /* skip lines */
if (y >= state->ysize) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
local_buf = (UINT8*) im->image[y];
} else {
/* store last byte (used if line width is odd) */
local_buf[state->xsize-1] = (UINT8) packets;
}
ERR_IF_DATA_OOB(2)
packets = I16(data); data += 2;
}
for (p = x = 0; p < packets; p++) {
ERR_IF_DATA_OOB(2)
x += data[0]; /* pixel skip */
if (data[1] >= 128) {
ERR_IF_DATA_OOB(4)
i = 256-data[1]; /* run */
if (x + i + i > state->xsize)
break;
for (j = 0; j < i; j++) {
local_buf[x++] = data[2];
local_buf[x++] = data[3];
}
data += 2 + 2;
} else {
i = 2 * (int) data[1]; /* chunk */
if (x + i > state->xsize)
break;
ERR_IF_DATA_OOB(2+i)
memcpy(local_buf + x, data + 2, i);
data += 2 + i;
x += i;
}
}
if (p < packets)
break; /* didn't process all packets */
}
if (l < lines) {
/* didn't process all lines */
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
break;
case 12:
/* FLI LC chunk (byte delta) */
/* OOB Check ok, we have 4 bytes min here */
y = I16(data); ymax = y + I16(data+2); data += 4;
for (; y < ymax && y < state->ysize; y++) {
UINT8* out = (UINT8*) im->image[y];
ERR_IF_DATA_OOB(1)
int p, packets = *data++;
for (p = x = 0; p < packets; p++, x += i) {
ERR_IF_DATA_OOB(2)
x += data[0]; /* skip pixels */
if (data[1] & 0x80) {
i = 256-data[1]; /* run */
if (x + i > state->xsize)
break;
ERR_IF_DATA_OOB(3)
memset(out + x, data[2], i);
data += 3;
} else {
i = data[1]; /* chunk */
if (x + i > state->xsize)
break;
ERR_IF_DATA_OOB(2+i)
memcpy(out + x, data + 2, i);
data += i + 2;
}
}
if (p < packets)
break; /* didn't process all packets */
}
if (y < ymax) {
/* didn't process all lines */
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
break;
case 13:
/* FLI BLACK chunk */
for (y = 0; y < state->ysize; y++)
memset(im->image[y], 0, state->xsize);
break;
case 15:
/* FLI BRUN chunk */
/* OOB, ok, we've got 4 bytes min on entry */
for (y = 0; y < state->ysize; y++) {
UINT8* out = (UINT8*) im->image[y];
data += 1; /* ignore packetcount byte */
for (x = 0; x < state->xsize; x += i) {
ERR_IF_DATA_OOB(2)
if (data[0] & 0x80) {
i = 256 - data[0];
if (x + i > state->xsize) {
break; /* safety first */
}
ERR_IF_DATA_OOB(i+1)
memcpy(out + x, data + 1, i);
data += i + 1;
} else {
i = data[0];
if (x + i > state->xsize)
break; /* safety first */
memset(out + x, data[1], i);
data += 2;
}
}
if (x != state->xsize) {
/* didn't unpack whole line */
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
}
break;
case 16:
/* COPY chunk */
if (state->xsize > bytes/state->ysize) {
/* not enough data for frame */
return ptr - buf; /* bytes consumed */
}
for (y = 0; y < state->ysize; y++) {
UINT8* local_buf = (UINT8*) im->image[y];
memcpy(local_buf, data, state->xsize);
data += state->xsize;
}
break;
case 18:
/* PSTAMP chunk */
break; /* ignored */
default:
/* unknown chunk */
/* printf("unknown FLI/FLC chunk: %d\n", I16(ptr+4)); */
state->errcode = IMAGING_CODEC_UNKNOWN;
return -1;
}
advance = I32(ptr);
if (advance < 0 || advance > bytes) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
ptr += advance;
bytes -= advance;
}
return -1; /* end of frame */

View File

@ -33,47 +33,47 @@ ImagingGetBBox(Imaging im, int bbox[4])
bbox[1] = -1;
bbox[2] = bbox[3] = 0;
#define GETBBOX(image, mask)\
#define GETBBOX(image, mask)\
for (y = 0; y < im->ysize; y++) {\
has_data = 0;\
for (x = 0; x < im->xsize; x++)\
if (im->image[y][x] & mask) {\
has_data = 1;\
if (x < bbox[0])\
bbox[0] = x;\
if (x >= bbox[2])\
bbox[2] = x+1;\
}\
if (has_data) {\
if (bbox[1] < 0)\
bbox[1] = y;\
bbox[3] = y+1;\
}\
has_data = 0;\
for (x = 0; x < im->xsize; x++)\
if (im->image[y][x] & mask) {\
has_data = 1;\
if (x < bbox[0])\
bbox[0] = x;\
if (x >= bbox[2])\
bbox[2] = x+1;\
}\
if (has_data) {\
if (bbox[1] < 0)\
bbox[1] = y;\
bbox[3] = y+1;\
}\
}
if (im->image8) {
GETBBOX(image8, 0xff);
GETBBOX(image8, 0xff);
} else {
INT32 mask = 0xffffffff;
if (im->bands == 3) {
((UINT8*) &mask)[3] = 0;
} else if (strcmp(im->mode, "RGBa") == 0 ||
strcmp(im->mode, "RGBA") == 0 ||
strcmp(im->mode, "La") == 0 ||
strcmp(im->mode, "LA") == 0 ||
strcmp(im->mode, "PA") == 0) {
INT32 mask = 0xffffffff;
if (im->bands == 3) {
((UINT8*) &mask)[3] = 0;
} else if (strcmp(im->mode, "RGBa") == 0 ||
strcmp(im->mode, "RGBA") == 0 ||
strcmp(im->mode, "La") == 0 ||
strcmp(im->mode, "LA") == 0 ||
strcmp(im->mode, "PA") == 0) {
#ifdef WORDS_BIGENDIAN
mask = 0x000000ff;
mask = 0x000000ff;
#else
mask = 0xff000000;
mask = 0xff000000;
#endif
}
GETBBOX(image32, mask);
}
GETBBOX(image32, mask);
}
/* Check that we got a box */
if (bbox[1] < 0)
return 0; /* no data */
return 0; /* no data */
return 1; /* ok */
}
@ -91,25 +91,25 @@ ImagingGetProjection(Imaging im, UINT8* xproj, UINT8* yproj)
memset(xproj, 0, im->xsize);
memset(yproj, 0, im->ysize);
#define GETPROJ(image, mask)\
for (y = 0; y < im->ysize; y++) {\
has_data = 0;\
for (x = 0; x < im->xsize; x++)\
if (im->image[y][x] & mask) {\
has_data = 1;\
xproj[x] = 1;\
}\
if (has_data)\
yproj[y] = 1;\
}
#define GETPROJ(image, mask)\
for (y = 0; y < im->ysize; y++) {\
has_data = 0;\
for (x = 0; x < im->xsize; x++)\
if (im->image[y][x] & mask) {\
has_data = 1;\
xproj[x] = 1;\
}\
if (has_data)\
yproj[y] = 1;\
}
if (im->image8) {
GETPROJ(image8, 0xff);
GETPROJ(image8, 0xff);
} else {
INT32 mask = 0xffffffff;
if (im->bands == 3)
((UINT8*) &mask)[3] = 0;
GETPROJ(image32, mask);
INT32 mask = 0xffffffff;
if (im->bands == 3)
((UINT8*) &mask)[3] = 0;
GETPROJ(image32, mask);
}
return 1; /* ok */
@ -124,7 +124,7 @@ ImagingGetExtrema(Imaging im, void *extrema)
FLOAT32 fmin, fmax;
if (im->bands != 1) {
(void) ImagingError_ModeError();
(void) ImagingError_ModeError();
return -1; /* mismatch */
}
@ -202,11 +202,11 @@ ImagingGetExtrema(Imaging im, void *extrema)
memcpy(extrema, &v, sizeof(v));
v = (UINT16) imax;
memcpy(((char*)extrema) + sizeof(v), &v, sizeof(v));
break;
break;
}
/* FALL THROUGH */
default:
(void) ImagingError_ModeError();
(void) ImagingError_ModeError();
return -1;
}
return 1; /* ok */
@ -265,14 +265,14 @@ getcolors32(Imaging im, int maxcolors, int* size)
/* printf("code_poly=%d\n", code_poly); */
if (!code_size)
return ImagingError_MemoryError(); /* just give up */
return ImagingError_MemoryError(); /* just give up */
if (!im->image32)
return ImagingError_ModeError();
return ImagingError_ModeError();
table = calloc(code_size + 1, sizeof(ImagingColorItem));
if (!table)
return ImagingError_MemoryError();
return ImagingError_MemoryError();
pixel_mask = 0xffffffff;
if (im->bands == 3)

View File

@ -10,10 +10,10 @@
/* Max size for a LZW code word. */
#define GIFBITS 12
#define GIFBITS 12
#define GIFTABLE (1<<GIFBITS)
#define GIFBUFFER (1<<GIFBITS)
#define GIFTABLE (1<<GIFBITS)
#define GIFBUFFER (1<<GIFBITS)
typedef struct {

View File

@ -5,15 +5,15 @@
* a fast, suspendable GIF decoder
*
* history:
* 95-09-03 fl Created
* 95-09-05 fl Fixed sign problem on 16-bit platforms
* 95-09-13 fl Added some storage shortcuts
* 96-03-28 fl Revised API, integrated with PIL
* 96-12-10 fl Added interlace support
* 96-12-16 fl Fixed premature termination bug introduced by last fix
* 97-01-05 fl Don't mess up on bogus configuration
* 97-01-17 fl Don't mess up on very small, interlaced files
* 99-02-07 fl Minor speedups
* 95-09-03 fl Created
* 95-09-05 fl Fixed sign problem on 16-bit platforms
* 95-09-13 fl Added some storage shortcuts
* 96-03-28 fl Revised API, integrated with PIL
* 96-12-10 fl Added interlace support
* 96-12-16 fl Fixed premature termination bug introduced by last fix
* 97-01-05 fl Don't mess up on bogus configuration
* 97-01-17 fl Don't mess up on very small, interlaced files
* 99-02-07 fl Minor speedups
*
* Copyright (c) Secret Labs AB 1997-99.
* Copyright (c) Fredrik Lundh 1995-97.
@ -25,7 +25,7 @@
#include "Imaging.h"
#include <stdio.h>
#include <memory.h> /* memcpy() */
#include <memory.h> /* memcpy() */
#include "Gif.h"
@ -34,23 +34,23 @@
state->x = 0;\
state->y += context->step;\
while (state->y >= state->ysize)\
switch (context->interlace) {\
case 1:\
context->repeat = state->y = 4;\
context->interlace = 2;\
break;\
case 2:\
context->step = 4;\
context->repeat = state->y = 2;\
context->interlace = 3;\
break;\
case 3:\
context->step = 2;\
context->repeat = state->y = 1;\
context->interlace = 0;\
break;\
default:\
return -1;\
switch (context->interlace) {\
case 1:\
context->repeat = state->y = 4;\
context->interlace = 2;\
break;\
case 2:\
context->step = 4;\
context->repeat = state->y = 2;\
context->interlace = 3;\
break;\
case 3:\
context->step = 2;\
context->repeat = state->y = 1;\
context->interlace = 0;\
break;\
default:\
return -1;\
}\
if (state->y < state->ysize)\
out = im->image8[state->y + state->yoff] + state->xoff;\
@ -70,227 +70,227 @@ ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8* buffer, Py_ssize_t
if (!state->state) {
/* Initialise state */
if (context->bits < 0 || context->bits > 12) {
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}
/* Initialise state */
if (context->bits < 0 || context->bits > 12) {
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}
/* Clear code */
context->clear = 1 << context->bits;
/* Clear code */
context->clear = 1 << context->bits;
/* End code */
context->end = context->clear + 1;
/* End code */
context->end = context->clear + 1;
/* Interlace */
if (context->interlace) {
context->interlace = 1;
context->step = context->repeat = 8;
} else
context->step = 1;
/* Interlace */
if (context->interlace) {
context->interlace = 1;
context->step = context->repeat = 8;
} else
context->step = 1;
state->state = 1;
state->state = 1;
}
out = im->image8[state->y + state->yoff] + state->xoff + state->x;
for (;;) {
if (state->state == 1) {
if (state->state == 1) {
/* First free entry in table */
context->next = context->clear + 2;
/* First free entry in table */
context->next = context->clear + 2;
/* Initial code size */
context->codesize = context->bits + 1;
context->codemask = (1 << context->codesize) - 1;
/* Initial code size */
context->codesize = context->bits + 1;
context->codemask = (1 << context->codesize) - 1;
/* Buffer pointer. We fill the buffer from right, which
allows us to return all of it in one operation. */
context->bufferindex = GIFBUFFER;
/* Buffer pointer. We fill the buffer from right, which
allows us to return all of it in one operation. */
context->bufferindex = GIFBUFFER;
state->state = 2;
}
state->state = 2;
}
if (context->bufferindex < GIFBUFFER) {
if (context->bufferindex < GIFBUFFER) {
/* Return whole buffer in one chunk */
i = GIFBUFFER - context->bufferindex;
p = &context->buffer[context->bufferindex];
/* Return whole buffer in one chunk */
i = GIFBUFFER - context->bufferindex;
p = &context->buffer[context->bufferindex];
context->bufferindex = GIFBUFFER;
context->bufferindex = GIFBUFFER;
} else {
} else {
/* Get current symbol */
/* Get current symbol */
while (context->bitcount < context->codesize) {
while (context->bitcount < context->codesize) {
if (context->blocksize > 0) {
if (context->blocksize > 0) {
/* Read next byte */
c = *ptr++; bytes--;
/* Read next byte */
c = *ptr++; bytes--;
context->blocksize--;
context->blocksize--;
/* New bits are shifted in from from the left. */
context->bitbuffer |= (INT32) c << context->bitcount;
context->bitcount += 8;
/* New bits are shifted in from from the left. */
context->bitbuffer |= (INT32) c << context->bitcount;
context->bitcount += 8;
} else {
} else {
/* New GIF block */
/* New GIF block */
/* We don't start decoding unless we have a full block */
if (bytes < 1)
return ptr - buffer;
c = *ptr;
if (bytes < c+1)
return ptr - buffer;
/* We don't start decoding unless we have a full block */
if (bytes < 1)
return ptr - buffer;
c = *ptr;
if (bytes < c+1)
return ptr - buffer;
context->blocksize = c;
context->blocksize = c;
ptr++; bytes--;
ptr++; bytes--;
}
}
}
}
/* Extract current symbol from bit buffer. */
c = (int) context->bitbuffer & context->codemask;
/* Extract current symbol from bit buffer. */
c = (int) context->bitbuffer & context->codemask;
/* Adjust buffer */
context->bitbuffer >>= context->codesize;
context->bitcount -= context->codesize;
/* Adjust buffer */
context->bitbuffer >>= context->codesize;
context->bitcount -= context->codesize;
/* If c is less than "clear", it's a data byte. Otherwise,
it's either clear/end or a code symbol which should be
expanded. */
/* If c is less than "clear", it's a data byte. Otherwise,
it's either clear/end or a code symbol which should be
expanded. */
if (c == context->clear) {
if (state->state != 2)
state->state = 1;
continue;
}
if (c == context->clear) {
if (state->state != 2)
state->state = 1;
continue;
}
if (c == context->end)
break;
if (c == context->end)
break;
i = 1;
p = &context->lastdata;
i = 1;
p = &context->lastdata;
if (state->state == 2) {
if (state->state == 2) {
/* First valid symbol after clear; use as is */
if (c > context->clear) {
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
/* First valid symbol after clear; use as is */
if (c > context->clear) {
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
context->lastdata = context->lastcode = c;
state->state = 3;
context->lastdata = context->lastcode = c;
state->state = 3;
} else {
} else {
thiscode = c;
thiscode = c;
if (c > context->next) {
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
if (c > context->next) {
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
if (c == context->next) {
if (c == context->next) {
/* c == next is allowed. not sure why. */
/* c == next is allowed. not sure why. */
if (context->bufferindex <= 0) {
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
if (context->bufferindex <= 0) {
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
context->buffer[--context->bufferindex] =
context->lastdata;
context->buffer[--context->bufferindex] =
context->lastdata;
c = context->lastcode;
c = context->lastcode;
}
}
while (c >= context->clear) {
while (c >= context->clear) {
/* Copy data string to buffer (beginning from right) */
/* Copy data string to buffer (beginning from right) */
if (context->bufferindex <= 0 || c >= GIFTABLE) {
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
if (context->bufferindex <= 0 || c >= GIFTABLE) {
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
context->buffer[--context->bufferindex] =
context->data[c];
context->buffer[--context->bufferindex] =
context->data[c];
c = context->link[c];
}
c = context->link[c];
}
context->lastdata = c;
context->lastdata = c;
if (context->next < GIFTABLE) {
if (context->next < GIFTABLE) {
/* We'll only add this symbol if we have room
for it (take advise, Netscape!) */
context->data[context->next] = c;
context->link[context->next] = context->lastcode;
/* We'll only add this symbol if we have room
for it (take advise, Netscape!) */
context->data[context->next] = c;
context->link[context->next] = context->lastcode;
if (context->next == context->codemask &&
context->codesize < GIFBITS) {
if (context->next == context->codemask &&
context->codesize < GIFBITS) {
/* Expand code size */
context->codesize++;
context->codemask = (1 << context->codesize) - 1;
}
/* Expand code size */
context->codesize++;
context->codemask = (1 << context->codesize) - 1;
}
context->next++;
context->next++;
}
}
context->lastcode = thiscode;
context->lastcode = thiscode;
}
}
}
}
/* Copy the bytes into the image */
if (state->y >= state->ysize) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
/* Copy the bytes into the image */
if (state->y >= state->ysize) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
/* To squeeze some extra pixels out of this loop, we test for
some common cases and handle them separately. */
/* To squeeze some extra pixels out of this loop, we test for
some common cases and handle them separately. */
/* FIXME: should we handle the transparency index in here??? */
/* FIXME: should we handle the transparency index in here??? */
if (i == 1) {
if (state->x < state->xsize-1) {
/* Single pixel, not at the end of the line. */
*out++ = p[0];
state->x++;
continue;
}
} else if (state->x + i <= state->xsize) {
/* This string fits into current line. */
memcpy(out, p, i);
out += i;
state->x += i;
if (state->x == state->xsize) {
NEWLINE(state, context);
}
continue;
}
if (i == 1) {
if (state->x < state->xsize-1) {
/* Single pixel, not at the end of the line. */
*out++ = p[0];
state->x++;
continue;
}
} else if (state->x + i <= state->xsize) {
/* This string fits into current line. */
memcpy(out, p, i);
out += i;
state->x += i;
if (state->x == state->xsize) {
NEWLINE(state, context);
}
continue;
}
/* No shortcut, copy pixel by pixel */
for (c = 0; c < i; c++) {
*out++ = p[c];
if (++state->x >= state->xsize) {
NEWLINE(state, context);
}
}
/* No shortcut, copy pixel by pixel */
for (c = 0; c < i; c++) {
*out++ = p[c];
if (++state->x >= state->xsize) {
NEWLINE(state, context);
}
}
}
return ptr - buffer;

View File

@ -5,11 +5,11 @@
* encoder for uncompressed GIF data
*
* history:
* 97-01-05 fl created (writes uncompressed data)
* 97-08-27 fl fixed off-by-one error in buffer size test
* 98-07-09 fl added interlace write support
* 99-02-07 fl rewritten, now uses a run-length encoding strategy
* 99-02-08 fl improved run-length encoding for long runs
* 97-01-05 fl created (writes uncompressed data)
* 97-08-27 fl fixed off-by-one error in buffer size test
* 98-07-09 fl added interlace write support
* 99-02-07 fl rewritten, now uses a run-length encoding strategy
* 99-02-08 fl improved run-length encoding for long runs
*
* Copyright (c) Secret Labs AB 1997-99.
* Copyright (c) Fredrik Lundh 1997.
@ -145,17 +145,17 @@ ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
if (!state->state) {
/* place a clear code in the output buffer */
context->bitbuffer = CLEAR_CODE;
context->bitcount = 9;
/* place a clear code in the output buffer */
context->bitbuffer = CLEAR_CODE;
context->bitcount = 9;
state->count = FIRST_CODE;
state->count = FIRST_CODE;
if (context->interlace) {
context->interlace = 1;
context->step = 8;
} else
context->step = 1;
if (context->interlace) {
context->interlace = 1;
context->step = 8;
} else
context->step = 1;
context->last = -1;
@ -169,152 +169,152 @@ ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
for (;;)
switch (state->state) {
switch (state->state) {
case INIT:
case ENCODE:
case INIT:
case ENCODE:
/* identify and store a run of pixels */
/* identify and store a run of pixels */
if (state->x == 0 || state->x >= state->xsize) {
if (state->x == 0 || state->x >= state->xsize) {
if (!context->interlace && state->y >= state->ysize) {
state->state = ENCODE_EOF;
break;
}
if (context->flush) {
state->state = FLUSH;
break;
}
/* get another line of data */
state->shuffle(
state->buffer,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize
);
state->x = 0;
if (state->state == INIT) {
/* preload the run-length buffer and get going */
context->last = state->buffer[0];
context->count = state->x = 1;
state->state = ENCODE;
}
/* step forward, according to the interlace settings */
state->y += context->step;
while (context->interlace && state->y >= state->ysize)
switch (context->interlace) {
case 1:
state->y = 4;
context->interlace = 2;
if (!context->interlace && state->y >= state->ysize) {
state->state = ENCODE_EOF;
break;
case 2:
context->step = 4;
state->y = 2;
context->interlace = 3;
break;
case 3:
context->step = 2;
state->y = 1;
context->interlace = 0;
break;
default:
/* just make sure we don't loop forever */
context->interlace = 0;
}
}
if (context->flush) {
state->state = FLUSH;
break;
}
this = state->buffer[state->x++];
/* get another line of data */
state->shuffle(
state->buffer,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize
);
if (this == context->last)
context->count++;
else {
EMIT_RUN(label1);
context->last = this;
context->count = 1;
}
break;
state->x = 0;
if (state->state == INIT) {
/* preload the run-length buffer and get going */
context->last = state->buffer[0];
context->count = state->x = 1;
state->state = ENCODE;
}
case ENCODE_EOF:
/* step forward, according to the interlace settings */
state->y += context->step;
while (context->interlace && state->y >= state->ysize)
switch (context->interlace) {
case 1:
state->y = 4;
context->interlace = 2;
break;
case 2:
context->step = 4;
state->y = 2;
context->interlace = 3;
break;
case 3:
context->step = 2;
state->y = 1;
context->interlace = 0;
break;
default:
/* just make sure we don't loop forever */
context->interlace = 0;
}
/* write the final run */
EMIT_RUN(label2);
/* write an end of image marker */
EMIT(EOF_CODE);
/* empty the bit buffer */
while (context->bitcount > 0) {
if (!emit(context, (UINT8) context->bitbuffer)) {
state->errcode = IMAGING_CODEC_MEMORY;
return 0;
}
context->bitbuffer >>= 8;
context->bitcount -= 8;
}
/* flush the last block, and exit */
if (context->block) {
GIFENCODERBLOCK* block;
block = context->flush;
while (block && block->next)
block = block->next;
if (block)
block->next = context->block;
else
context->flush = context->block;
context->block = NULL;
}
this = state->buffer[state->x++];
state->state = EXIT;
if (this == context->last)
context->count++;
else {
EMIT_RUN(label1);
context->last = this;
context->count = 1;
}
break;
/* fall through... */
case EXIT:
case FLUSH:
case ENCODE_EOF:
while (context->flush) {
/* write the final run */
EMIT_RUN(label2);
/* get a block from the flush queue */
block = context->flush;
/* write an end of image marker */
EMIT(EOF_CODE);
if (block->size > 0) {
/* empty the bit buffer */
while (context->bitcount > 0) {
if (!emit(context, (UINT8) context->bitbuffer)) {
state->errcode = IMAGING_CODEC_MEMORY;
return 0;
}
context->bitbuffer >>= 8;
context->bitcount -= 8;
}
/* make sure it fits into the output buffer */
if (bytes < block->size+1)
/* flush the last block, and exit */
if (context->block) {
GIFENCODERBLOCK* block;
block = context->flush;
while (block && block->next)
block = block->next;
if (block)
block->next = context->block;
else
context->flush = context->block;
context->block = NULL;
}
state->state = EXIT;
/* fall through... */
case EXIT:
case FLUSH:
while (context->flush) {
/* get a block from the flush queue */
block = context->flush;
if (block->size > 0) {
/* make sure it fits into the output buffer */
if (bytes < block->size+1)
return ptr - buf;
ptr[0] = block->size;
memcpy(ptr+1, block->data, block->size);
ptr += block->size+1;
bytes -= block->size+1;
}
context->flush = block->next;
if (context->free)
free(context->free);
context->free = block;
}
if (state->state == EXIT) {
/* this was the last block! */
if (context->free)
free(context->free);
state->errcode = IMAGING_CODEC_END;
return ptr - buf;
}
ptr[0] = block->size;
memcpy(ptr+1, block->data, block->size);
ptr += block->size+1;
bytes -= block->size+1;
}
context->flush = block->next;
if (context->free)
free(context->free);
context->free = block;
}
if (state->state == EXIT) {
/* this was the last block! */
if (context->free)
free(context->free);
state->errcode = IMAGING_CODEC_END;
return ptr - buf;
}
state->state = ENCODE;
break;
}
state->state = ENCODE;
break;
}
}

View File

@ -5,7 +5,7 @@
* decoder for hex encoded image data
*
* history:
* 96-05-16 fl Created
* 96-05-16 fl Created
*
* Copyright (c) Fredrik Lundh 1996.
* Copyright (c) Secret Labs AB 1997.
@ -16,9 +16,9 @@
#include "Imaging.h"
#define HEX(v) ((v >= '0' && v <= '9') ? v - '0' :\
(v >= 'a' && v <= 'f') ? v - 'a' + 10 :\
(v >= 'A' && v <= 'F') ? v - 'A' + 10 : -1)
#define HEX(v) ((v >= '0' && v <= '9') ? v - '0' :\
(v >= 'a' && v <= 'f') ? v - 'a' + 10 :\
(v >= 'A' && v <= 'F') ? v - 'A' + 10 : -1)
int
ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
@ -30,38 +30,38 @@ ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
for (;;) {
if (bytes < 2)
return ptr - buf;
if (bytes < 2)
return ptr - buf;
a = HEX(ptr[0]);
b = HEX(ptr[1]);
a = HEX(ptr[0]);
b = HEX(ptr[1]);
if (a < 0 || b < 0) {
if (a < 0 || b < 0) {
ptr++;
bytes--;
ptr++;
bytes--;
} else {
} else {
ptr += 2;
bytes -= 2;
ptr += 2;
bytes -= 2;
state->buffer[state->x] = (a<<4) + b;
state->buffer[state->x] = (a<<4) + b;
if (++state->x >= state->bytes) {
if (++state->x >= state->bytes) {
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y], state->buffer,
state->xsize);
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y], state->buffer,
state->xsize);
state->x = 0;
state->x = 0;
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
}
}
}
}

View File

@ -30,7 +30,7 @@ void
ImagingHistogramDelete(ImagingHistogram h)
{
if (h->histogram)
free(h->histogram);
free(h->histogram);
free(h);
}
@ -60,115 +60,115 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax)
FLOAT32 fmin, fmax, scale;
if (!im)
return ImagingError_ModeError();
return ImagingError_ModeError();
if (imMask) {
/* Validate mask */
if (im->xsize != imMask->xsize || im->ysize != imMask->ysize)
return ImagingError_Mismatch();
if (strcmp(imMask->mode, "1") != 0 && strcmp(imMask->mode, "L") != 0)
return ImagingError_ValueError("bad transparency mask");
/* Validate mask */
if (im->xsize != imMask->xsize || im->ysize != imMask->ysize)
return ImagingError_Mismatch();
if (strcmp(imMask->mode, "1") != 0 && strcmp(imMask->mode, "L") != 0)
return ImagingError_ValueError("bad transparency mask");
}
h = ImagingHistogramNew(im);
if (imMask) {
/* mask */
if (im->image8) {
ImagingSectionEnter(&cookie);
for (y = 0; y < im->ysize; y++)
for (x = 0; x < im->xsize; x++)
if (imMask->image8[y][x] != 0)
h->histogram[im->image8[y][x]]++;
ImagingSectionLeave(&cookie);
} else { /* yes, we need the braces. C isn't Python! */
/* mask */
if (im->image8) {
ImagingSectionEnter(&cookie);
for (y = 0; y < im->ysize; y++)
for (x = 0; x < im->xsize; x++)
if (imMask->image8[y][x] != 0)
h->histogram[im->image8[y][x]]++;
ImagingSectionLeave(&cookie);
} else { /* yes, we need the braces. C isn't Python! */
if (im->type != IMAGING_TYPE_UINT8) {
ImagingHistogramDelete(h);
return ImagingError_ModeError();
}
ImagingSectionEnter(&cookie);
for (y = 0; y < im->ysize; y++) {
UINT8* in = (UINT8*) im->image32[y];
for (x = 0; x < im->xsize; x++)
if (imMask->image8[y][x] != 0) {
h->histogram[(*in++)]++;
h->histogram[(*in++)+256]++;
h->histogram[(*in++)+512]++;
h->histogram[(*in++)+768]++;
} else
in += 4;
}
ImagingSectionLeave(&cookie);
}
} else {
/* mask not given; process pixels in image */
if (im->image8) {
ImagingSectionEnter(&cookie);
for (y = 0; y < im->ysize; y++)
for (x = 0; x < im->xsize; x++)
h->histogram[im->image8[y][x]]++;
ImagingSectionLeave(&cookie);
} else {
switch (im->type) {
case IMAGING_TYPE_UINT8:
ImagingSectionEnter(&cookie);
for (y = 0; y < im->ysize; y++) {
UINT8* in = (UINT8*) im->image[y];
for (x = 0; x < im->xsize; x++) {
for (y = 0; y < im->ysize; y++) {
UINT8* in = (UINT8*) im->image32[y];
for (x = 0; x < im->xsize; x++)
if (imMask->image8[y][x] != 0) {
h->histogram[(*in++)]++;
h->histogram[(*in++)+256]++;
h->histogram[(*in++)+512]++;
h->histogram[(*in++)+768]++;
}
}
ImagingSectionLeave(&cookie);
break;
case IMAGING_TYPE_INT32:
if (!minmax) {
ImagingHistogramDelete(h);
return ImagingError_ValueError("min/max not given");
}
if (!im->xsize || !im->ysize)
break;
memcpy(&imin, minmax, sizeof(imin));
memcpy(&imax, ((char*)minmax) + sizeof(imin), sizeof(imax));
if (imin >= imax)
break;
} else
in += 4;
}
ImagingSectionLeave(&cookie);
}
} else {
/* mask not given; process pixels in image */
if (im->image8) {
ImagingSectionEnter(&cookie);
scale = 255.0F / (imax - imin);
for (y = 0; y < im->ysize; y++) {
INT32* in = im->image32[y];
for (x = 0; x < im->xsize; x++) {
i = (int) (((*in++)-imin)*scale);
if (i >= 0 && i < 256)
h->histogram[i]++;
for (y = 0; y < im->ysize; y++)
for (x = 0; x < im->xsize; x++)
h->histogram[im->image8[y][x]]++;
ImagingSectionLeave(&cookie);
} else {
switch (im->type) {
case IMAGING_TYPE_UINT8:
ImagingSectionEnter(&cookie);
for (y = 0; y < im->ysize; y++) {
UINT8* in = (UINT8*) im->image[y];
for (x = 0; x < im->xsize; x++) {
h->histogram[(*in++)]++;
h->histogram[(*in++)+256]++;
h->histogram[(*in++)+512]++;
h->histogram[(*in++)+768]++;
}
}
}
ImagingSectionLeave(&cookie);
break;
case IMAGING_TYPE_FLOAT32:
if (!minmax) {
ImagingHistogramDelete(h);
return ImagingError_ValueError("min/max not given");
}
if (!im->xsize || !im->ysize)
ImagingSectionLeave(&cookie);
break;
memcpy(&fmin, minmax, sizeof(fmin));
memcpy(&fmax, ((char*)minmax) + sizeof(fmin), sizeof(fmax));
if (fmin >= fmax)
break;
ImagingSectionEnter(&cookie);
scale = 255.0F / (fmax - fmin);
for (y = 0; y < im->ysize; y++) {
FLOAT32* in = (FLOAT32*) im->image32[y];
for (x = 0; x < im->xsize; x++) {
i = (int) (((*in++)-fmin)*scale);
if (i >= 0 && i < 256)
h->histogram[i]++;
case IMAGING_TYPE_INT32:
if (!minmax) {
ImagingHistogramDelete(h);
return ImagingError_ValueError("min/max not given");
}
}
ImagingSectionLeave(&cookie);
break;
if (!im->xsize || !im->ysize)
break;
memcpy(&imin, minmax, sizeof(imin));
memcpy(&imax, ((char*)minmax) + sizeof(imin), sizeof(imax));
if (imin >= imax)
break;
ImagingSectionEnter(&cookie);
scale = 255.0F / (imax - imin);
for (y = 0; y < im->ysize; y++) {
INT32* in = im->image32[y];
for (x = 0; x < im->xsize; x++) {
i = (int) (((*in++)-imin)*scale);
if (i >= 0 && i < 256)
h->histogram[i]++;
}
}
ImagingSectionLeave(&cookie);
break;
case IMAGING_TYPE_FLOAT32:
if (!minmax) {
ImagingHistogramDelete(h);
return ImagingError_ValueError("min/max not given");
}
if (!im->xsize || !im->ysize)
break;
memcpy(&fmin, minmax, sizeof(fmin));
memcpy(&fmax, ((char*)minmax) + sizeof(fmin), sizeof(fmax));
if (fmin >= fmax)
break;
ImagingSectionEnter(&cookie);
scale = 255.0F / (fmax - fmin);
for (y = 0; y < im->ysize; y++) {
FLOAT32* in = (FLOAT32*) im->image32[y];
for (x = 0; x < im->xsize; x++) {
i = (int) (((*in++)-fmin)*scale);
if (i >= 0 && i < 256)
h->histogram[i]++;
}
}
ImagingSectionLeave(&cookie);
break;
}
}
}

View File

@ -39,41 +39,41 @@
/* For System that are not Windows, we'll need to define these. */
#if SIZEOF_SHORT == 2
#define INT16 short
#define INT16 short
#elif SIZEOF_INT == 2
#define INT16 int
#define INT16 int
#else
#define INT16 short /* most things works just fine anyway... */
#define INT16 short /* most things works just fine anyway... */
#endif
#if SIZEOF_SHORT == 4
#define INT32 short
#define INT32 short
#elif SIZEOF_INT == 4
#define INT32 int
#define INT32 int
#elif SIZEOF_LONG == 4
#define INT32 long
#define INT32 long
#else
#error Cannot find required 32-bit integer type
#endif
#if SIZEOF_LONG == 8
#define INT64 long
#define INT64 long
#elif SIZEOF_LONG_LONG == 8
#define INT64 long
#define INT64 long
#endif
#define INT8 signed char
#define UINT8 unsigned char
#define INT8 signed char
#define UINT8 unsigned char
#define UINT16 unsigned INT16
#define UINT32 unsigned INT32
#define UINT16 unsigned INT16
#define UINT32 unsigned INT32
#endif
/* assume IEEE; tweak if necessary (patches are welcome) */
#define FLOAT16 UINT16
#define FLOAT32 float
#define FLOAT64 double
#define FLOAT16 UINT16
#define FLOAT32 float
#define FLOAT64 double
#ifdef _MSC_VER
typedef signed __int64 int64_t;

View File

@ -14,13 +14,13 @@
typedef struct {
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
} JPEGERROR;
/* -------------------------------------------------------------------- */
/* Decoder */
/* Decoder */
typedef struct {
struct jpeg_source_mgr pub;
@ -56,7 +56,7 @@ typedef struct {
/* -------------------------------------------------------------------- */
/* Encoder */
/* Encoder */
typedef struct {
struct jpeg_destination_mgr pub;

View File

@ -14,7 +14,7 @@
#define BUFFER_SIZE OPJ_J2K_STREAM_CHUNK_SIZE
/* -------------------------------------------------------------------- */
/* Decoder */
/* Decoder */
/* -------------------------------------------------------------------- */
typedef struct {
@ -44,7 +44,7 @@ typedef struct {
} JPEG2KDECODESTATE;
/* -------------------------------------------------------------------- */
/* Encoder */
/* Encoder */
/* -------------------------------------------------------------------- */
typedef struct {

View File

@ -301,14 +301,14 @@ ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t by
/* -------------------------------------------------------------------- */
int ImagingJpegDecodeCleanup(ImagingCodecState state){
/* called to free the decompression engine when the decode terminates
due to a corrupt or truncated image
*/
/* called to free the decompression engine when the decode terminates
due to a corrupt or truncated image
*/
JPEGSTATE* context = (JPEGSTATE*) state->context;
/* Clean up */
jpeg_destroy_decompress(&context->cinfo);
return -1;
/* Clean up */
jpeg_destroy_decompress(&context->cinfo);
return -1;
}
#endif

View File

@ -78,7 +78,7 @@ error(j_common_ptr cinfo)
/* -------------------------------------------------------------------- */
/* Encoder */
/* Encoder */
/* -------------------------------------------------------------------- */
int
@ -88,24 +88,24 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
int ok;
if (setjmp(context->error.setjmp_buffer)) {
/* JPEG error handler */
jpeg_destroy_compress(&context->cinfo);
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
/* JPEG error handler */
jpeg_destroy_compress(&context->cinfo);
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
if (!state->state) {
/* Setup compression context (very similar to the decoder) */
context->cinfo.err = jpeg_std_error(&context->error.pub);
context->error.pub.error_exit = error;
jpeg_create_compress(&context->cinfo);
jpeg_buffer_dest(&context->cinfo, &context->destination);
/* Setup compression context (very similar to the decoder) */
context->cinfo.err = jpeg_std_error(&context->error.pub);
context->error.pub.error_exit = error;
jpeg_create_compress(&context->cinfo);
jpeg_buffer_dest(&context->cinfo, &context->destination);
context->extra_offset = 0;
/* Ready to encode */
state->state = 1;
/* Ready to encode */
state->state = 1;
}
@ -115,212 +115,212 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
switch (state->state) {
case 1:
case 1:
context->cinfo.image_width = state->xsize;
context->cinfo.image_height = state->ysize;
context->cinfo.image_width = state->xsize;
context->cinfo.image_height = state->ysize;
switch (state->bits) {
case 8:
context->cinfo.input_components = 1;
context->cinfo.in_color_space = JCS_GRAYSCALE;
break;
case 24:
context->cinfo.input_components = 3;
if (strcmp(im->mode, "YCbCr") == 0)
context->cinfo.in_color_space = JCS_YCbCr;
else
context->cinfo.in_color_space = JCS_RGB;
break;
case 32:
context->cinfo.input_components = 4;
context->cinfo.in_color_space = JCS_CMYK;
#ifdef JCS_EXTENSIONS
if (strcmp(context->rawmode, "RGBX") == 0)
context->cinfo.in_color_space = JCS_EXT_RGBX;
#endif
break;
default:
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}
switch (state->bits) {
case 8:
context->cinfo.input_components = 1;
context->cinfo.in_color_space = JCS_GRAYSCALE;
break;
case 24:
context->cinfo.input_components = 3;
if (strcmp(im->mode, "YCbCr") == 0)
context->cinfo.in_color_space = JCS_YCbCr;
else
context->cinfo.in_color_space = JCS_RGB;
break;
case 32:
context->cinfo.input_components = 4;
context->cinfo.in_color_space = JCS_CMYK;
#ifdef JCS_EXTENSIONS
if (strcmp(context->rawmode, "RGBX") == 0)
context->cinfo.in_color_space = JCS_EXT_RGBX;
#endif
break;
default:
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}
/* Compressor configuration */
jpeg_set_defaults(&context->cinfo);
/* Compressor configuration */
jpeg_set_defaults(&context->cinfo);
/* Use custom quantization tables */
if (context->qtables) {
int i;
int quality = 100;
int last_q = 0;
if (context->quality != -1) {
quality = context->quality;
}
for (i = 0; i < context->qtablesLen; i++) {
// TODO: Should add support for none baseline
jpeg_add_quant_table(&context->cinfo, i, &context->qtables[i * DCTSIZE2],
quality, TRUE);
context->cinfo.comp_info[i].quant_tbl_no = i;
last_q = i;
}
if (context->qtablesLen == 1) {
// jpeg_set_defaults created two qtables internally, but we only wanted one.
jpeg_add_quant_table(&context->cinfo, 1, &context->qtables[0],
quality, TRUE);
}
for (i = last_q; i < context->cinfo.num_components; i++) {
context->cinfo.comp_info[i].quant_tbl_no = last_q;
}
} else if (context->quality != -1) {
jpeg_set_quality(&context->cinfo, context->quality, 1);
}
/* Use custom quantization tables */
if (context->qtables) {
int i;
int quality = 100;
int last_q = 0;
if (context->quality != -1) {
quality = context->quality;
}
for (i = 0; i < context->qtablesLen; i++) {
// TODO: Should add support for none baseline
jpeg_add_quant_table(&context->cinfo, i, &context->qtables[i * DCTSIZE2],
quality, TRUE);
context->cinfo.comp_info[i].quant_tbl_no = i;
last_q = i;
}
if (context->qtablesLen == 1) {
// jpeg_set_defaults created two qtables internally, but we only wanted one.
jpeg_add_quant_table(&context->cinfo, 1, &context->qtables[0],
quality, TRUE);
}
for (i = last_q; i < context->cinfo.num_components; i++) {
context->cinfo.comp_info[i].quant_tbl_no = last_q;
}
} else if (context->quality != -1) {
jpeg_set_quality(&context->cinfo, context->quality, 1);
}
/* Set subsampling options */
switch (context->subsampling)
{
case 0: /* 1x1 1x1 1x1 (4:4:4) : None */
{
context->cinfo.comp_info[0].h_samp_factor = 1;
context->cinfo.comp_info[0].v_samp_factor = 1;
context->cinfo.comp_info[1].h_samp_factor = 1;
context->cinfo.comp_info[1].v_samp_factor = 1;
context->cinfo.comp_info[2].h_samp_factor = 1;
context->cinfo.comp_info[2].v_samp_factor = 1;
break;
}
case 1: /* 2x1, 1x1, 1x1 (4:2:2) : Medium */
{
context->cinfo.comp_info[0].h_samp_factor = 2;
context->cinfo.comp_info[0].v_samp_factor = 1;
context->cinfo.comp_info[1].h_samp_factor = 1;
context->cinfo.comp_info[1].v_samp_factor = 1;
context->cinfo.comp_info[2].h_samp_factor = 1;
context->cinfo.comp_info[2].v_samp_factor = 1;
break;
}
case 2: /* 2x2, 1x1, 1x1 (4:2:0) : High */
{
context->cinfo.comp_info[0].h_samp_factor = 2;
context->cinfo.comp_info[0].v_samp_factor = 2;
context->cinfo.comp_info[1].h_samp_factor = 1;
context->cinfo.comp_info[1].v_samp_factor = 1;
context->cinfo.comp_info[2].h_samp_factor = 1;
context->cinfo.comp_info[2].v_samp_factor = 1;
break;
}
default:
{
/* Use the lib's default */
break;
}
}
if (context->progressive)
jpeg_simple_progression(&context->cinfo);
context->cinfo.smoothing_factor = context->smooth;
context->cinfo.optimize_coding = (boolean) context->optimize;
if (context->xdpi > 0 && context->ydpi > 0) {
context->cinfo.density_unit = 1; /* dots per inch */
context->cinfo.X_density = context->xdpi;
context->cinfo.Y_density = context->ydpi;
}
switch (context->streamtype) {
case 1:
/* tables only -- not yet implemented */
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
case 2:
/* image only */
jpeg_suppress_tables(&context->cinfo, TRUE);
jpeg_start_compress(&context->cinfo, FALSE);
/* suppress extra section */
context->extra_offset = context->extra_size;
break;
default:
/* interchange stream */
jpeg_start_compress(&context->cinfo, TRUE);
break;
}
state->state++;
/* fall through */
/* Set subsampling options */
switch (context->subsampling)
{
case 0: /* 1x1 1x1 1x1 (4:4:4) : None */
{
context->cinfo.comp_info[0].h_samp_factor = 1;
context->cinfo.comp_info[0].v_samp_factor = 1;
context->cinfo.comp_info[1].h_samp_factor = 1;
context->cinfo.comp_info[1].v_samp_factor = 1;
context->cinfo.comp_info[2].h_samp_factor = 1;
context->cinfo.comp_info[2].v_samp_factor = 1;
break;
}
case 1: /* 2x1, 1x1, 1x1 (4:2:2) : Medium */
{
context->cinfo.comp_info[0].h_samp_factor = 2;
context->cinfo.comp_info[0].v_samp_factor = 1;
context->cinfo.comp_info[1].h_samp_factor = 1;
context->cinfo.comp_info[1].v_samp_factor = 1;
context->cinfo.comp_info[2].h_samp_factor = 1;
context->cinfo.comp_info[2].v_samp_factor = 1;
break;
}
case 2: /* 2x2, 1x1, 1x1 (4:2:0) : High */
{
context->cinfo.comp_info[0].h_samp_factor = 2;
context->cinfo.comp_info[0].v_samp_factor = 2;
context->cinfo.comp_info[1].h_samp_factor = 1;
context->cinfo.comp_info[1].v_samp_factor = 1;
context->cinfo.comp_info[2].h_samp_factor = 1;
context->cinfo.comp_info[2].v_samp_factor = 1;
break;
}
default:
{
/* Use the lib's default */
break;
}
}
if (context->progressive)
jpeg_simple_progression(&context->cinfo);
context->cinfo.smoothing_factor = context->smooth;
context->cinfo.optimize_coding = (boolean) context->optimize;
if (context->xdpi > 0 && context->ydpi > 0) {
context->cinfo.density_unit = 1; /* dots per inch */
context->cinfo.X_density = context->xdpi;
context->cinfo.Y_density = context->ydpi;
}
switch (context->streamtype) {
case 1:
/* tables only -- not yet implemented */
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
case 2:
/* image only */
jpeg_suppress_tables(&context->cinfo, TRUE);
jpeg_start_compress(&context->cinfo, FALSE);
/* suppress extra section */
context->extra_offset = context->extra_size;
break;
default:
/* interchange stream */
jpeg_start_compress(&context->cinfo, TRUE);
break;
}
state->state++;
/* fall through */
case 2:
// check for exif len + 'APP1' header bytes
if (context->rawExifLen + 5 > context->destination.pub.free_in_buffer){
break;
}
//add exif header
if (context->rawExifLen > 0){
jpeg_write_marker(&context->cinfo, JPEG_APP0+1,
(unsigned char*)context->rawExif, context->rawExifLen);
}
state->state++;
/* fall through */
case 3:
if (context->extra) {
/* copy extra buffer to output buffer */
unsigned int n = context->extra_size - context->extra_offset;
if (n > context->destination.pub.free_in_buffer)
n = context->destination.pub.free_in_buffer;
memcpy(context->destination.pub.next_output_byte,
context->extra + context->extra_offset, n);
context->destination.pub.next_output_byte += n;
context->destination.pub.free_in_buffer -= n;
context->extra_offset += n;
if (context->extra_offset >= context->extra_size)
state->state++;
else
case 2:
// check for exif len + 'APP1' header bytes
if (context->rawExifLen + 5 > context->destination.pub.free_in_buffer){
break;
} else
state->state++;
}
//add exif header
if (context->rawExifLen > 0){
jpeg_write_marker(&context->cinfo, JPEG_APP0+1,
(unsigned char*)context->rawExif, context->rawExifLen);
}
case 4:
if (1024 > context->destination.pub.free_in_buffer){
state->state++;
/* fall through */
case 3:
if (context->extra) {
/* copy extra buffer to output buffer */
unsigned int n = context->extra_size - context->extra_offset;
if (n > context->destination.pub.free_in_buffer)
n = context->destination.pub.free_in_buffer;
memcpy(context->destination.pub.next_output_byte,
context->extra + context->extra_offset, n);
context->destination.pub.next_output_byte += n;
context->destination.pub.free_in_buffer -= n;
context->extra_offset += n;
if (context->extra_offset >= context->extra_size)
state->state++;
else
break;
} else
state->state++;
case 4:
if (1024 > context->destination.pub.free_in_buffer){
break;
}
ok = 1;
while (state->y < state->ysize) {
state->shuffle(state->buffer,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize);
ok = jpeg_write_scanlines(&context->cinfo, &state->buffer, 1);
if (ok != 1)
break;
state->y++;
}
if (ok != 1)
break;
state->state++;
/* fall through */
case 5:
/* Finish compression */
if (context->destination.pub.free_in_buffer < 100)
break;
jpeg_finish_compress(&context->cinfo);
/* Clean up */
if (context->extra) {
free(context->extra);
context->extra = NULL;
}
if (context->rawExif) {
free(context->rawExif);
context->rawExif = NULL;
}
if (context->qtables) {
free(context->qtables);
context->qtables = NULL;
}
jpeg_destroy_compress(&context->cinfo);
/* if (jerr.pub.num_warnings) return BROKEN; */
state->errcode = IMAGING_CODEC_END;
break;
}
ok = 1;
while (state->y < state->ysize) {
state->shuffle(state->buffer,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize);
ok = jpeg_write_scanlines(&context->cinfo, &state->buffer, 1);
if (ok != 1)
break;
state->y++;
}
if (ok != 1)
break;
state->state++;
/* fall through */
case 5:
/* Finish compression */
if (context->destination.pub.free_in_buffer < 100)
break;
jpeg_finish_compress(&context->cinfo);
/* Clean up */
if (context->extra) {
free(context->extra);
context->extra = NULL;
}
if (context->rawExif) {
free(context->rawExif);
context->rawExif = NULL;
}
if (context->qtables) {
free(context->qtables);
context->qtables = NULL;
}
jpeg_destroy_compress(&context->cinfo);
/* if (jerr.pub.num_warnings) return BROKEN; */
state->errcode = IMAGING_CODEC_END;
break;
}

View File

@ -17,7 +17,7 @@
#include "Imaging.h"
#define CLIPF(v) ((v <= 0.0) ? 0 : (v >= 255.0F) ? 255 : (UINT8) v)
#define CLIPF(v) ((v <= 0.0) ? 0 : (v >= 255.0F) ? 255 : (UINT8) v)
Imaging
@ -28,47 +28,47 @@ ImagingConvertMatrix(Imaging im, const char *mode, float m[])
/* Assume there's enough data in the buffer */
if (!im)
return (Imaging) ImagingError_ModeError();
return (Imaging) ImagingError_ModeError();
if (strcmp(mode, "L") == 0 && im->bands == 3) {
imOut = ImagingNewDirty("L", im->xsize, im->ysize);
if (!imOut)
return NULL;
imOut = ImagingNewDirty("L", im->xsize, im->ysize);
if (!imOut)
return NULL;
for (y = 0; y < im->ysize; y++) {
UINT8* in = (UINT8*) im->image[y];
UINT8* out = (UINT8*) imOut->image[y];
for (y = 0; y < im->ysize; y++) {
UINT8* in = (UINT8*) im->image[y];
UINT8* out = (UINT8*) imOut->image[y];
for (x = 0; x < im->xsize; x++) {
float v = m[0]*in[0] + m[1]*in[1] + m[2]*in[2] + m[3] + 0.5;
out[x] = CLIPF(v);
in += 4;
}
}
for (x = 0; x < im->xsize; x++) {
float v = m[0]*in[0] + m[1]*in[1] + m[2]*in[2] + m[3] + 0.5;
out[x] = CLIPF(v);
in += 4;
}
}
} else if (strlen(mode) == 3 && im->bands == 3) {
imOut = ImagingNewDirty(mode, im->xsize, im->ysize);
if (!imOut)
return NULL;
imOut = ImagingNewDirty(mode, im->xsize, im->ysize);
if (!imOut)
return NULL;
for (y = 0; y < im->ysize; y++) {
UINT8* in = (UINT8*) im->image[y];
UINT8* out = (UINT8*) imOut->image[y];
for (y = 0; y < im->ysize; y++) {
UINT8* in = (UINT8*) im->image[y];
UINT8* out = (UINT8*) imOut->image[y];
for (x = 0; x < im->xsize; x++) {
float v0 = m[0]*in[0] + m[1]*in[1] + m[2]*in[2] + m[3] + 0.5;
float v1 = m[4]*in[0] + m[5]*in[1] + m[6]*in[2] + m[7] + 0.5;
float v2 = m[8]*in[0] + m[9]*in[1] + m[10]*in[2] + m[11] + 0.5;
out[0] = CLIPF(v0);
out[1] = CLIPF(v1);
out[2] = CLIPF(v2);
in += 4; out += 4;
}
}
for (x = 0; x < im->xsize; x++) {
float v0 = m[0]*in[0] + m[1]*in[1] + m[2]*in[2] + m[3] + 0.5;
float v1 = m[4]*in[0] + m[5]*in[1] + m[6]*in[2] + m[7] + 0.5;
float v2 = m[8]*in[0] + m[9]*in[1] + m[10]*in[2] + m[11] + 0.5;
out[0] = CLIPF(v0);
out[1] = CLIPF(v1);
out[2] = CLIPF(v2);
in += 4; out += 4;
}
}
} else
return (Imaging) ImagingError_ModeError();
return (Imaging) ImagingError_ModeError();
return imOut;
}

View File

@ -8,7 +8,7 @@
* FIXME: Maybe this should be implemented using ImagingPoint()
*
* history:
* 95-11-27 fl: Created
* 95-11-27 fl: Created
*
* Copyright (c) Fredrik Lundh 1995.
* Copyright (c) Secret Labs AB 1997.
@ -27,15 +27,15 @@ ImagingNegative(Imaging im)
int x, y;
if (!im)
return (Imaging) ImagingError_ModeError();
return (Imaging) ImagingError_ModeError();
imOut = ImagingNewDirty(im->mode, im->xsize, im->ysize);
if (!imOut)
return NULL;
return NULL;
for (y = 0; y < im->ysize; y++)
for (x = 0; x < im->linesize; x++)
imOut->image[y][x] = ~im->image[y][x];
for (x = 0; x < im->linesize; x++)
imOut->image[y][x] = ~im->image[y][x];
return imOut;
}

View File

@ -5,7 +5,7 @@
* offset an image in x and y directions
*
* history:
* 96-07-22 fl: Created
* 96-07-22 fl: Created
* 98-11-01 cgw@pgt.com: Fixed negative-array index bug
*
* Copyright (c) Fredrik Lundh 1996.
@ -25,11 +25,11 @@ ImagingOffset(Imaging im, int xoffset, int yoffset)
Imaging imOut;
if (!im)
return (Imaging) ImagingError_ModeError();
return (Imaging) ImagingError_ModeError();
imOut = ImagingNewDirty(im->mode, im->xsize, im->ysize);
if (!imOut)
return NULL;
return NULL;
ImagingCopyPalette(imOut, im);
@ -37,25 +37,25 @@ ImagingOffset(Imaging im, int xoffset, int yoffset)
xoffset %= im->xsize;
xoffset = im->xsize - xoffset;
if (xoffset < 0)
xoffset += im->xsize;
xoffset += im->xsize;
yoffset %= im->ysize;
yoffset = im->ysize - yoffset;
if (yoffset < 0)
yoffset += im->ysize;
yoffset += im->ysize;
#define OFFSET(image)\
#define OFFSET(image)\
for (y = 0; y < im->ysize; y++)\
for (x = 0; x < im->xsize; x++) {\
int yi = (y + yoffset) % im->ysize;\
int xi = (x + xoffset) % im->xsize;\
imOut->image[y][x] = im->image[yi][xi];\
}
for (x = 0; x < im->xsize; x++) {\
int yi = (y + yoffset) % im->ysize;\
int xi = (x + xoffset) % im->xsize;\
imOut->image[y][x] = im->image[yi][xi];\
}
if (im->image8)
OFFSET(image8)
OFFSET(image8)
else
OFFSET(image32)
OFFSET(image32)
return imOut;
}

View File

@ -5,7 +5,7 @@
* decoder for PackBits image data.
*
* history:
* 96-04-19 fl Created
* 96-04-19 fl Created
*
* Copyright (c) Fredrik Lundh 1996.
* Copyright (c) Secret Labs AB 1997.
@ -18,7 +18,7 @@
int
ImagingPackbitsDecode(Imaging im, ImagingCodecState state,
UINT8* buf, Py_ssize_t bytes)
UINT8* buf, Py_ssize_t bytes)
{
UINT8 n;
UINT8* ptr;
@ -28,65 +28,65 @@ ImagingPackbitsDecode(Imaging im, ImagingCodecState state,
for (;;) {
if (bytes < 1)
return ptr - buf;
if (bytes < 1)
return ptr - buf;
if (ptr[0] & 0x80) {
if (ptr[0] & 0x80) {
if (ptr[0] == 0x80) {
/* Nop */
ptr++; bytes--;
continue;
}
if (ptr[0] == 0x80) {
/* Nop */
ptr++; bytes--;
continue;
}
/* Run */
if (bytes < 2)
return ptr - buf;
/* Run */
if (bytes < 2)
return ptr - buf;
for (n = 257 - ptr[0]; n > 0; n--) {
if (state->x >= state->bytes) {
/* state->errcode = IMAGING_CODEC_OVERRUN; */
break;
}
state->buffer[state->x++] = ptr[1];
}
for (n = 257 - ptr[0]; n > 0; n--) {
if (state->x >= state->bytes) {
/* state->errcode = IMAGING_CODEC_OVERRUN; */
break;
}
state->buffer[state->x++] = ptr[1];
}
ptr += 2; bytes -= 2;
ptr += 2; bytes -= 2;
} else {
} else {
/* Literal */
n = ptr[0]+2;
/* Literal */
n = ptr[0]+2;
if (bytes < n)
return ptr - buf;
if (bytes < n)
return ptr - buf;
for (i = 1; i < n; i++) {
if (state->x >= state->bytes) {
/* state->errcode = IMAGING_CODEC_OVERRUN; */
break;
}
state->buffer[state->x++] = ptr[i];
}
for (i = 1; i < n; i++) {
if (state->x >= state->bytes) {
/* state->errcode = IMAGING_CODEC_OVERRUN; */
break;
}
state->buffer[state->x++] = ptr[i];
}
ptr += n; bytes -= n;
ptr += n; bytes -= n;
}
}
if (state->x >= state->bytes) {
if (state->x >= state->bytes) {
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->buffer,
state->xsize);
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->buffer,
state->xsize);
state->x = 0;
state->x = 0;
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
}
}

View File

@ -5,13 +5,13 @@
* decoder for uncompressed PCD image data.
*
* history:
* 96-05-10 fl Created
* 96-05-18 fl New tables
* 97-01-25 fl Use PhotoYCC unpacker
* 96-05-10 fl Created
* 96-05-18 fl New tables
* 97-01-25 fl Use PhotoYCC unpacker
*
* notes:
* This driver supports uncompressed PCD modes only
* (resolutions up to 768x512).
* This driver supports uncompressed PCD modes only
* (resolutions up to 768x512).
*
* Copyright (c) Fredrik Lundh 1996-97.
* Copyright (c) Secret Labs AB 1997.
@ -37,42 +37,42 @@ ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
for (;;) {
/* We need data for two full lines before we can do anything */
if (bytes < chunk)
return ptr - buf;
/* We need data for two full lines before we can do anything */
if (bytes < chunk)
return ptr - buf;
/* Unpack first line */
out = state->buffer;
for (x = 0; x < state->xsize; x++) {
out[0] = ptr[x];
out[1] = ptr[(x+4*state->xsize)/2];
out[2] = ptr[(x+5*state->xsize)/2];
out += 3;
}
/* Unpack first line */
out = state->buffer;
for (x = 0; x < state->xsize; x++) {
out[0] = ptr[x];
out[1] = ptr[(x+4*state->xsize)/2];
out[2] = ptr[(x+5*state->xsize)/2];
out += 3;
}
state->shuffle((UINT8*) im->image[state->y],
state->buffer, state->xsize);
state->shuffle((UINT8*) im->image[state->y],
state->buffer, state->xsize);
if (++state->y >= state->ysize)
return -1; /* This can hardly happen */
if (++state->y >= state->ysize)
return -1; /* This can hardly happen */
/* Unpack second line */
out = state->buffer;
for (x = 0; x < state->xsize; x++) {
out[0] = ptr[x+state->xsize];
out[1] = ptr[(x+4*state->xsize)/2];
out[2] = ptr[(x+5*state->xsize)/2];
out += 3;
}
/* Unpack second line */
out = state->buffer;
for (x = 0; x < state->xsize; x++) {
out[0] = ptr[x+state->xsize];
out[1] = ptr[(x+4*state->xsize)/2];
out[2] = ptr[(x+5*state->xsize)/2];
out += 3;
}
state->shuffle((UINT8*) im->image[state->y],
state->buffer, state->xsize);
state->shuffle((UINT8*) im->image[state->y],
state->buffer, state->xsize);
if (++state->y >= state->ysize)
return -1;
if (++state->y >= state->ysize)
return -1;
ptr += chunk;
bytes -= chunk;
ptr += chunk;
bytes -= chunk;
}
}

View File

@ -5,7 +5,7 @@
* decoder for PCX image data.
*
* history:
* 95-09-14 fl Created
* 95-09-14 fl Created
*
* Copyright (c) Fredrik Lundh 1995.
* Copyright (c) Secret Labs AB 1997.
@ -31,59 +31,59 @@ ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
for (;;) {
if (bytes < 1)
return ptr - buf;
if (bytes < 1)
return ptr - buf;
if ((*ptr & 0xC0) == 0xC0) {
if ((*ptr & 0xC0) == 0xC0) {
/* Run */
if (bytes < 2)
return ptr - buf;
/* Run */
if (bytes < 2)
return ptr - buf;
n = ptr[0] & 0x3F;
n = ptr[0] & 0x3F;
while (n > 0) {
if (state->x >= state->bytes) {
state->errcode = IMAGING_CODEC_OVERRUN;
break;
}
state->buffer[state->x++] = ptr[1];
n--;
}
while (n > 0) {
if (state->x >= state->bytes) {
state->errcode = IMAGING_CODEC_OVERRUN;
break;
}
state->buffer[state->x++] = ptr[1];
n--;
}
ptr += 2; bytes -= 2;
ptr += 2; bytes -= 2;
} else {
} else {
/* Literal */
state->buffer[state->x++] = ptr[0];
ptr++; bytes--;
/* Literal */
state->buffer[state->x++] = ptr[0];
ptr++; bytes--;
}
}
if (state->x >= state->bytes) {
if (state->bytes % state->xsize && state->bytes > state->xsize) {
int bands = state->bytes / state->xsize;
int stride = state->bytes / bands;
int i;
for (i=1; i< bands; i++) { // note -- skipping first band
memmove(&state->buffer[i*state->xsize],
&state->buffer[i*stride],
state->xsize);
if (state->x >= state->bytes) {
if (state->bytes % state->xsize && state->bytes > state->xsize) {
int bands = state->bytes / state->xsize;
int stride = state->bytes / bands;
int i;
for (i=1; i< bands; i++) { // note -- skipping first band
memmove(&state->buffer[i*state->xsize],
&state->buffer[i*stride],
state->xsize);
}
}
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->buffer,
state->xsize);
state->x = 0;
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->buffer,
state->xsize);
state->x = 0;
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
}
}

View File

@ -139,7 +139,7 @@ ImagingPoint(Imaging imIn, const char* mode, const void* table)
void (*point)(Imaging imIn, Imaging imOut, im_point_context* context);
if (!imIn)
return (Imaging) ImagingError_ModeError();
return (Imaging) ImagingError_ModeError();
if (!mode)
mode = imIn->mode;
@ -152,7 +152,7 @@ ImagingPoint(Imaging imIn, const char* mode, const void* table)
imOut = ImagingNew(mode, imIn->xsize, imIn->ysize);
if (!imOut)
return NULL;
return NULL;
/* find appropriate handler */
if (imIn->type == IMAGING_TYPE_UINT8) {
@ -210,11 +210,11 @@ ImagingPointTransform(Imaging imIn, double scale, double offset)
if (!imIn || (strcmp(imIn->mode, "I") != 0 &&
strcmp(imIn->mode, "I;16") != 0 &&
strcmp(imIn->mode, "F") != 0))
return (Imaging) ImagingError_ModeError();
return (Imaging) ImagingError_ModeError();
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
if (!imOut)
return NULL;
return NULL;
switch (imIn->type) {
case IMAGING_TYPE_INT32:
@ -254,7 +254,7 @@ ImagingPointTransform(Imaging imIn, double scale, double offset)
}
ImagingSectionLeave(&cookie);
break;
}
}
/* FALL THROUGH */
default:
ImagingDelete(imOut);

View File

@ -5,7 +5,7 @@
* decoder for raw (uncompressed) image data
*
* history:
* 96-03-07 fl rewritten
* 96-03-07 fl rewritten
*
* Copyright (c) Fredrik Lundh 1996.
* Copyright (c) Secret Labs AB 1997.
@ -29,28 +29,28 @@ ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
if (state->state == 0) {
/* Initialize context variables */
/* Initialize context variables */
/* get size of image data and padding */
state->bytes = (state->xsize * state->bits + 7) / 8;
if (rawstate->stride) {
rawstate->skip = rawstate->stride - state->bytes;
if (rawstate->skip < 0) {
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}
} else {
rawstate->skip = 0;
}
/* get size of image data and padding */
state->bytes = (state->xsize * state->bits + 7) / 8;
if (rawstate->stride) {
rawstate->skip = rawstate->stride - state->bytes;
if (rawstate->skip < 0) {
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}
} else {
rawstate->skip = 0;
}
/* check image orientation */
if (state->ystep < 0) {
state->y = state->ysize-1;
state->ystep = -1;
} else
state->ystep = 1;
/* check image orientation */
if (state->ystep < 0) {
state->y = state->ysize-1;
state->ystep = -1;
} else
state->ystep = 1;
state->state = LINE;
state->state = LINE;
}
@ -58,38 +58,38 @@ ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
for (;;) {
if (state->state == SKIP) {
if (state->state == SKIP) {
/* Skip padding between lines */
/* Skip padding between lines */
if (bytes < rawstate->skip)
return ptr - buf;
if (bytes < rawstate->skip)
return ptr - buf;
ptr += rawstate->skip;
bytes -= rawstate->skip;
ptr += rawstate->skip;
bytes -= rawstate->skip;
state->state = LINE;
state->state = LINE;
}
}
if (bytes < state->bytes)
return ptr - buf;
if (bytes < state->bytes)
return ptr - buf;
/* Unpack data */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, ptr, state->xsize);
/* Unpack data */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, ptr, state->xsize);
ptr += state->bytes;
bytes -= state->bytes;
ptr += state->bytes;
bytes -= state->bytes;
state->y += state->ystep;
state->y += state->ystep;
if (state->y < 0 || state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
if (state->y < 0 || state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
state->state = SKIP;
state->state = SKIP;
}

View File

@ -9,8 +9,8 @@
* in ImageFile.py, but it should be solved here instead.
*
* history:
* 96-04-30 fl created
* 97-01-03 fl fixed padding
* 96-04-30 fl created
* 97-01-03 fl fixed padding
*
* Copyright (c) Fredrik Lundh 1996-97.
* Copyright (c) Secret Labs AB 1997.
@ -27,60 +27,60 @@ ImagingRawEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
if (!state->state) {
/* The "count" field holds the stride, if specified. Fix
things up so "bytes" is the full size, and "count" the
packed size */
/* The "count" field holds the stride, if specified. Fix
things up so "bytes" is the full size, and "count" the
packed size */
if (state->count > 0) {
int bytes = state->count;
if (state->count > 0) {
int bytes = state->count;
/* stride must not be less than real size */
if (state->count < state->bytes) {
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}
state->count = state->bytes;
state->bytes = bytes;
} else
state->count = state->bytes;
/* stride must not be less than real size */
if (state->count < state->bytes) {
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
}
state->count = state->bytes;
state->bytes = bytes;
} else
state->count = state->bytes;
/* The "ystep" field specifies the orientation */
/* The "ystep" field specifies the orientation */
if (state->ystep < 0) {
state->y = state->ysize-1;
state->ystep = -1;
} else
state->ystep = 1;
if (state->ystep < 0) {
state->y = state->ysize-1;
state->ystep = -1;
} else
state->ystep = 1;
state->state = 1;
state->state = 1;
}
if (bytes < state->bytes) {
state->errcode = IMAGING_CODEC_CONFIG;
return 0;
state->errcode = IMAGING_CODEC_CONFIG;
return 0;
}
ptr = buf;
while (bytes >= state->bytes) {
state->shuffle(ptr, (UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize);
state->shuffle(ptr, (UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize);
if (state->bytes > state->count)
/* zero-pad the buffer, if necessary */
memset(ptr + state->count, 0, state->bytes - state->count);
if (state->bytes > state->count)
/* zero-pad the buffer, if necessary */
memset(ptr + state->count, 0, state->bytes - state->count);
ptr += state->bytes;
bytes -= state->bytes;
ptr += state->bytes;
bytes -= state->bytes;
state->y += state->ystep;
state->y += state->ystep;
if (state->y < 0 || state->y >= state->ysize) {
state->errcode = IMAGING_CODEC_END;
break;
}
if (state->y < 0 || state->y >= state->ysize) {
state->errcode = IMAGING_CODEC_END;
break;
}
}

View File

@ -6,7 +6,7 @@
*
* history:
* 2017-07-28 mb fixed for images larger than 64KB
* 2017-07-20 mb created
* 2017-07-20 mb created
*
* Copyright (c) Mickael Bonfill 2017.
*
@ -101,7 +101,7 @@ static int expandrow2(UINT8* dest, const UINT8* src, int n, int z, int xsize)
int
ImagingSgiRleDecode(Imaging im, ImagingCodecState state,
UINT8* buf, Py_ssize_t bytes)
UINT8* buf, Py_ssize_t bytes)
{
UINT8 *ptr;
SGISTATE *c;

View File

@ -5,8 +5,8 @@
* decoder for Targa RLE data.
*
* history:
* 97-01-04 fl created
* 98-09-11 fl don't one byte per pixel; take orientation into account
* 97-01-04 fl created
* 98-09-11 fl don't one byte per pixel; take orientation into account
*
* Copyright (c) Fredrik Lundh 1997.
* Copyright (c) Secret Labs AB 1997-98.
@ -20,7 +20,7 @@
int
ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
UINT8* buf, Py_ssize_t bytes)
UINT8* buf, Py_ssize_t bytes)
{
int n, depth;
UINT8* ptr;
@ -29,14 +29,14 @@ ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
if (state->state == 0) {
/* check image orientation */
if (state->ystep < 0) {
state->y = state->ysize-1;
state->ystep = -1;
} else
state->ystep = 1;
/* check image orientation */
if (state->ystep < 0) {
state->y = state->ysize-1;
state->ystep = -1;
} else
state->ystep = 1;
state->state = 1;
state->state = 1;
}
@ -44,22 +44,22 @@ ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
for (;;) {
if (bytes < 1)
return ptr - buf;
if (bytes < 1)
return ptr - buf;
if (ptr[0] & 0x80) {
if (ptr[0] & 0x80) {
/* Run (1 + pixelsize bytes) */
/* Run (1 + pixelsize bytes) */
if (bytes < 1 + depth)
break;
if (bytes < 1 + depth)
break;
n = depth * ((ptr[0] & 0x7f) + 1);
n = depth * ((ptr[0] & 0x7f) + 1);
if (state->x + n > state->bytes) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
if (state->x + n > state->bytes) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
if (depth == 1)
memset(state->buffer + state->x, ptr[1], n);
@ -70,38 +70,38 @@ ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
}
ptr += 1 + depth;
bytes -= 1 + depth;
bytes -= 1 + depth;
} else {
} else {
/* Literal (1+n+1 bytes block) */
n = depth * (ptr[0] + 1);
/* Literal (1+n+1 bytes block) */
n = depth * (ptr[0] + 1);
if (bytes < 1 + n)
break;
if (bytes < 1 + n)
break;
if (state->x + n > state->bytes) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
if (state->x + n > state->bytes) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
memcpy(state->buffer + state->x, ptr + 1, n);
memcpy(state->buffer + state->x, ptr + 1, n);
ptr += 1 + n;
bytes -= 1 + n;
ptr += 1 + n;
bytes -= 1 + n;
}
}
state->x += n;
state->x += n;
if (state->x >= state->bytes) {
if (state->x >= state->bytes) {
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->buffer,
state->xsize);
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->buffer,
state->xsize);
state->x = 0;
state->x = 0;
state->y += state->ystep;
@ -110,7 +110,7 @@ ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
return -1;
}
}
}
}

View File

@ -28,17 +28,17 @@
#define _PIL_LIBTIFF_
typedef struct {
tdata_t data; /* tdata_t == void* */
toff_t loc; /* toff_t == uint32 */
tsize_t size; /* tsize_t == int32 */
int fp;
tdata_t data; /* tdata_t == void* */
toff_t loc; /* toff_t == uint32 */
tsize_t size; /* tsize_t == int32 */
int fp;
uint32 ifd; /* offset of the ifd, used for multipage
* Should be uint32 for libtiff 3.9.x
* uint64 for libtiff 4.0.x
*/
TIFF *tiff; /* Used in write */
toff_t eof;
int flrealloc;/* may we realloc */
TIFF *tiff; /* Used in write */
toff_t eof;
int flrealloc;/* may we realloc */
} TIFFSTATE;
@ -55,7 +55,7 @@ extern int ImagingLibTiffSetField(ImagingCodecState state, ttag_t tag, ...);
*/
/*
#define VA_ARGS(...) __VA_ARGS__
#define VA_ARGS(...) __VA_ARGS__
#define TRACE(args) fprintf(stderr, VA_ARGS args)
*/

View File

@ -998,7 +998,7 @@ unpackI16N_I16B(UINT8* out, const UINT8* in, int pixels){
UINT8* tmp = (UINT8*) out;
for (i = 0; i < pixels; i++) {
C16B;
in += 2; tmp += 2;
in += 2; tmp += 2;
}
}
@ -1008,7 +1008,7 @@ unpackI16N_I16(UINT8* out, const UINT8* in, int pixels){
UINT8* tmp = (UINT8*) out;
for (i = 0; i < pixels; i++) {
C16L;
in += 2; tmp += 2;
in += 2; tmp += 2;
}
}
@ -1053,7 +1053,7 @@ unpackI12_I16(UINT8* out, const UINT8* in, int pixels){
memcpy(out, &pixel, sizeof(pixel));
#endif
in += 3; out+=2;
in += 3; out+=2;
}
if (i == pixels-1) {
pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4);
@ -1306,7 +1306,7 @@ static struct {
/* greyscale w. alpha */
{"LA", "LA", 16, unpackLA},
{"LA", "LA;L", 16, unpackLAL},
/* greyscale w. alpha premultiplied */
{"La", "La", 16, unpackLA},
@ -1447,16 +1447,16 @@ static struct {
{"YCbCr", "YCbCrK", 32, copy4},
/* LAB Color */
{"LAB", "LAB", 24, ImagingUnpackLAB},
{"LAB", "L", 8, band0},
{"LAB", "A", 8, band1},
{"LAB", "B", 8, band2},
{"LAB", "LAB", 24, ImagingUnpackLAB},
{"LAB", "L", 8, band0},
{"LAB", "A", 8, band1},
{"LAB", "B", 8, band2},
/* HSV Color */
{"HSV", "HSV", 24, ImagingUnpackRGB},
{"HSV", "H", 8, band0},
{"HSV", "S", 8, band1},
{"HSV", "V", 8, band2},
{"HSV", "HSV", 24, ImagingUnpackRGB},
{"HSV", "H", 8, band0},
{"HSV", "S", 8, band1},
{"HSV", "V", 8, band2},
/* integer variations */
{"I", "I", 32, copy4},
@ -1505,11 +1505,11 @@ static struct {
{"I;16B", "I;16B", 16, copy2},
{"I;16L", "I;16L", 16, copy2},
{"I;16", "I;16N", 16, unpackI16N_I16}, // LibTiff native->image endian.
{"I;16L", "I;16N", 16, unpackI16N_I16}, // LibTiff native->image endian.
{"I;16B", "I;16N", 16, unpackI16N_I16B},
{"I;16", "I;16N", 16, unpackI16N_I16}, // LibTiff native->image endian.
{"I;16L", "I;16N", 16, unpackI16N_I16}, // LibTiff native->image endian.
{"I;16B", "I;16N", 16, unpackI16N_I16B},
{"I;16", "I;12", 12, unpackI12_I16}, // 12 bit Tiffs stored in 16bits.
{"I;16", "I;12", 12, unpackI12_I16}, // 12 bit Tiffs stored in 16bits.
{NULL} /* sentinel */
};

View File

@ -5,7 +5,7 @@
* code to convert and unpack PhotoYCC data
*
* history:
* 97-01-25 fl Moved from PcdDecode.c
* 97-01-25 fl Moved from PcdDecode.c
*
* Copyright (c) Fredrik Lundh 1996-97.
* Copyright (c) Secret Labs AB 1997.
@ -116,12 +116,12 @@ static INT16 GR[] = { 127, 126, 125, 124, 123, 122, 121, 121, 120, 119,
-85, -86, -87, -88, -89, -90, -91, -92, -93, -94, -94, -95, -96, -97,
-98, -99, -100, -101, -102, -103, -104, -105, -106, -107, -107, -108 };
#define R 0
#define G 1
#define B 2
#define A 3
#define R 0
#define G 1
#define B 2
#define A 3
#define YCC2RGB(rgb, y, cb, cr) {\
#define YCC2RGB(rgb, y, cb, cr) {\
int l = L[y];\
int r = l + CR[cr];\
int g = l + GR[cr] + GB[cb];\
@ -137,9 +137,9 @@ ImagingUnpackYCC(UINT8* out, const UINT8* in, int pixels)
int i;
/* PhotoYCC triplets */
for (i = 0; i < pixels; i++) {
YCC2RGB(out, in[0], in[1], in[2]);
out[A] = 255;
out += 4; in += 3;
YCC2RGB(out, in[0], in[1], in[2]);
out[A] = 255;
out += 4; in += 3;
}
}
@ -149,14 +149,14 @@ ImagingUnpackYCCA(UINT8* out, const UINT8* in, int pixels)
int i;
/* PhotoYCC triplets plus premultiplied alpha */
for (i = 0; i < pixels; i++) {
/* Divide by alpha */
UINT8 rgb[3];
rgb[0] = (in[3] == 0) ? 0 : (((int) in[0] * 255) / in[3]);
rgb[1] = (in[3] == 0) ? 0 : (((int) in[1] * 255) / in[3]);
rgb[2] = (in[3] == 0) ? 0 : (((int) in[2] * 255) / in[3]);
/* Convert non-multiplied data to RGB */
YCC2RGB(out, rgb[0], rgb[1], rgb[2]);
out[A] = in[3];
out += 4; in += 4;
/* Divide by alpha */
UINT8 rgb[3];
rgb[0] = (in[3] == 0) ? 0 : (((int) in[0] * 255) / in[3]);
rgb[1] = (in[3] == 0) ? 0 : (((int) in[1] * 255) / in[3]);
rgb[2] = (in[3] == 0) ? 0 : (((int) in[2] * 255) / in[3]);
/* Convert non-multiplied data to RGB */
YCC2RGB(out, rgb[0], rgb[1], rgb[2]);
out[A] = in[3];
out += 4; in += 4;
}
}

View File

@ -5,7 +5,7 @@
* decoder for XBM hex image data
*
* history:
* 96-04-13 fl Created
* 96-04-13 fl Created
*
* Copyright (c) Fredrik Lundh 1996.
* Copyright (c) Secret Labs AB 1997.
@ -16,9 +16,9 @@
#include "Imaging.h"
#define HEX(v) ((v >= '0' && v <= '9') ? v - '0' :\
(v >= 'a' && v <= 'f') ? v - 'a' + 10 :\
(v >= 'A' && v <= 'F') ? v - 'A' + 10 : 0)
#define HEX(v) ((v >= '0' && v <= '9') ? v - '0' :\
(v >= 'a' && v <= 'f') ? v - 'a' + 10 :\
(v >= 'A' && v <= 'F') ? v - 'A' + 10 : 0)
int
ImagingXbmDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes)
@ -28,53 +28,53 @@ ImagingXbmDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
UINT8* ptr;
if (!state->state)
state->state = SKIP;
state->state = SKIP;
ptr = buf;
for (;;) {
if (state->state == SKIP) {
if (state->state == SKIP) {
/* Skip forward until next 'x' */
/* Skip forward until next 'x' */
while (bytes > 0) {
if (*ptr == 'x')
break;
ptr++;
bytes--;
}
while (bytes > 0) {
if (*ptr == 'x')
break;
ptr++;
bytes--;
}
if (bytes == 0)
return ptr - buf;
if (bytes == 0)
return ptr - buf;
state->state = BYTE;
state->state = BYTE;
}
}
if (bytes < 3)
return ptr - buf;
if (bytes < 3)
return ptr - buf;
state->buffer[state->x] = (HEX(ptr[1])<<4) + HEX(ptr[2]);
state->buffer[state->x] = (HEX(ptr[1])<<4) + HEX(ptr[2]);
if (++state->x >= state->bytes) {
if (++state->x >= state->bytes) {
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y], state->buffer,
state->xsize);
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y], state->buffer,
state->xsize);
state->x = 0;
state->x = 0;
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
ptr += 3;
bytes -= 3;
ptr += 3;
bytes -= 3;
state->state = SKIP;
state->state = SKIP;
}

View File

@ -5,7 +5,7 @@
* encoder for Xbm data
*
* history:
* 96-11-01 fl created
* 96-11-01 fl created
*
* Copyright (c) Fredrik Lundh 1996.
* Copyright (c) Secret Labs AB 1997.
@ -27,79 +27,79 @@ ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
if (!state->state) {
/* 8 pixels are stored in no more than 6 bytes */
state->bytes = 6*(state->xsize+7)/8;
/* 8 pixels are stored in no more than 6 bytes */
state->bytes = 6*(state->xsize+7)/8;
state->state = 1;
state->state = 1;
}
if (bytes < state->bytes) {
state->errcode = IMAGING_CODEC_MEMORY;
return 0;
state->errcode = IMAGING_CODEC_MEMORY;
return 0;
}
ptr = buf;
while (bytes >= state->bytes) {
state->shuffle(state->buffer,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize);
state->shuffle(state->buffer,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize);
if (state->y < state->ysize-1) {
if (state->y < state->ysize-1) {
/* any line but the last */
for (n = 0; n < state->xsize; n += 8) {
/* any line but the last */
for (n = 0; n < state->xsize; n += 8) {
i = state->buffer[n/8];
i = state->buffer[n/8];
*ptr++ = '0';
*ptr++ = 'x';
*ptr++ = hex[(i>>4)&15];
*ptr++ = hex[i&15];
*ptr++ = ',';
bytes -= 5;
*ptr++ = '0';
*ptr++ = 'x';
*ptr++ = hex[(i>>4)&15];
*ptr++ = hex[i&15];
*ptr++ = ',';
bytes -= 5;
if (++state->count >= 79/5) {
*ptr++ = '\n';
bytes--;
state->count = 0;
}
if (++state->count >= 79/5) {
*ptr++ = '\n';
bytes--;
state->count = 0;
}
}
}
state->y++;
state->y++;
} else {
} else {
/* last line */
for (n = 0; n < state->xsize; n += 8) {
/* last line */
for (n = 0; n < state->xsize; n += 8) {
i = state->buffer[n/8];
i = state->buffer[n/8];
*ptr++ = '0';
*ptr++ = 'x';
*ptr++ = hex[(i>>4)&15];
*ptr++ = hex[i&15];
*ptr++ = '0';
*ptr++ = 'x';
*ptr++ = hex[(i>>4)&15];
*ptr++ = hex[i&15];
if (n < state->xsize-8) {
*ptr++ = ',';
if (++state->count >= 79/5) {
*ptr++ = '\n';
bytes--;
state->count = 0;
}
} else
*ptr++ = '\n';
if (n < state->xsize-8) {
*ptr++ = ',';
if (++state->count >= 79/5) {
*ptr++ = '\n';
bytes--;
state->count = 0;
}
} else
*ptr++ = '\n';
bytes -= 5;
bytes -= 5;
}
}
state->errcode = IMAGING_CODEC_END;
break;
}
state->errcode = IMAGING_CODEC_END;
break;
}
}
return ptr - buf;

View File

@ -12,10 +12,10 @@
/* modes */
#define ZIP_PNG 0 /* continuous, filtered image data */
#define ZIP_PNG_PALETTE 1 /* non-continuous data, disable filtering */
#define ZIP_TIFF_PREDICTOR 2 /* TIFF, with predictor */
#define ZIP_TIFF 3 /* TIFF, without predictor */
#define ZIP_PNG 0 /* continuous, filtered image data */
#define ZIP_PNG_PALETTE 1 /* non-continuous data, disable filtering */
#define ZIP_TIFF_PREDICTOR 2 /* TIFF, with predictor */
#define ZIP_TIFF 3 /* TIFF, without predictor */
typedef struct {
@ -39,24 +39,24 @@ typedef struct {
/* PRIVATE CONTEXT (set by decoder/encoder) */
z_stream z_stream; /* (de)compression stream */
z_stream z_stream; /* (de)compression stream */
UINT8* previous; /* previous line (allocated) */
UINT8* previous; /* previous line (allocated) */
int last_output; /* # bytes last output by inflate */
int last_output; /* # bytes last output by inflate */
/* Compressor specific stuff */
UINT8* prior; /* filter storage (allocated) */
UINT8* prior; /* filter storage (allocated) */
UINT8* up;
UINT8* average;
UINT8* paeth;
UINT8* output; /* output data */
UINT8* output; /* output data */
int prefix; /* size of filter prefix (0 for TIFF data) */
int prefix; /* size of filter prefix (0 for TIFF data) */
int interlaced; /* is the image interlaced? (PNG) */
int interlaced; /* is the image interlaced? (PNG) */
int pass; /* current pass of the interlaced image (PNG) */
int pass; /* current pass of the interlaced image (PNG) */
} ZIPSTATE;

View File

@ -23,7 +23,7 @@
/* -------------------------------------------------------------------- */
/* Class */
/* Class */
typedef struct {
PyObject_HEAD
@ -44,7 +44,7 @@ _outline_new(void)
self = PyObject_New(OutlineObject, &OutlineType);
if (self == NULL)
return NULL;
return NULL;
self->outline = ImagingOutlineNew();
@ -69,7 +69,7 @@ PyOutline_AsOutline(PyObject* outline)
/* -------------------------------------------------------------------- */
/* Factories */
/* Factories */
PyObject*
PyOutline_Create(PyObject* self, PyObject* args)
@ -82,14 +82,14 @@ PyOutline_Create(PyObject* self, PyObject* args)
/* -------------------------------------------------------------------- */
/* Methods */
/* Methods */
static PyObject*
_outline_move(OutlineObject* self, PyObject* args)
{
float x0, y0;
if (!PyArg_ParseTuple(args, "ff", &x0, &y0))
return NULL;
return NULL;
ImagingOutlineMove(self->outline, x0, y0);
@ -102,7 +102,7 @@ _outline_line(OutlineObject* self, PyObject* args)
{
float x1, y1;
if (!PyArg_ParseTuple(args, "ff", &x1, &y1))
return NULL;
return NULL;
ImagingOutlineLine(self->outline, x1, y1);
@ -115,7 +115,7 @@ _outline_curve(OutlineObject* self, PyObject* args)
{
float x1, y1, x2, y2, x3, y3;
if (!PyArg_ParseTuple(args, "ffffff", &x1, &y1, &x2, &y2, &x3, &y3))
return NULL;
return NULL;
ImagingOutlineCurve(self->outline, x1, y1, x2, y2, x3, y3);
@ -158,35 +158,35 @@ static struct PyMethodDef _outline_methods[] = {
};
static PyTypeObject OutlineType = {
PyVarObject_HEAD_INIT(NULL, 0)
"Outline", /*tp_name*/
sizeof(OutlineObject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
(destructor)_outline_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number */
0, /*tp_as_sequence */
0, /*tp_as_mapping */
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
0, /*tp_doc*/
0, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
_outline_methods, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
PyVarObject_HEAD_INIT(NULL, 0)
"Outline", /*tp_name*/
sizeof(OutlineObject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
(destructor)_outline_dealloc,/*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number */
0, /*tp_as_sequence */
0, /*tp_as_mapping */
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
0, /*tp_doc*/
0, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
_outline_methods, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
};