mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-29 09:29:46 +03:00
use mode structs in encode.c and decode.c
This commit is contained in:
parent
a37f53c949
commit
a12dc30dc0
103
src/decode.c
103
src/decode.c
|
@ -266,7 +266,7 @@ static PyTypeObject ImagingDecoderType = {
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
get_unpacker(ImagingDecoderObject *decoder, const char *mode, const char *rawmode) {
|
get_unpacker(ImagingDecoderObject *decoder, const Mode *mode, const RawMode *rawmode) {
|
||||||
int bits;
|
int bits;
|
||||||
ImagingShuffler unpack;
|
ImagingShuffler unpack;
|
||||||
|
|
||||||
|
@ -436,12 +436,14 @@ PyObject *
|
||||||
PyImaging_HexDecoderNew(PyObject *self, PyObject *args) {
|
PyImaging_HexDecoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingDecoderObject *decoder;
|
ImagingDecoderObject *decoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name, *rawmode_name;
|
||||||
char *rawmode;
|
if (!PyArg_ParseTuple(args, "ss", &mode_name, &rawmode_name)) {
|
||||||
if (!PyArg_ParseTuple(args, "ss", &mode, &rawmode)) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
decoder = PyImaging_DecoderNew(0);
|
decoder = PyImaging_DecoderNew(0);
|
||||||
if (decoder == NULL) {
|
if (decoder == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -469,16 +471,19 @@ PyImaging_HexDecoderNew(PyObject *self, PyObject *args) {
|
||||||
PyObject *
|
PyObject *
|
||||||
PyImaging_LibTiffDecoderNew(PyObject *self, PyObject *args) {
|
PyImaging_LibTiffDecoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingDecoderObject *decoder;
|
ImagingDecoderObject *decoder;
|
||||||
char *mode;
|
char *mode_name;
|
||||||
char *rawmode;
|
char *rawmode_name;
|
||||||
char *compname;
|
char *compname;
|
||||||
int fp;
|
int fp;
|
||||||
uint32_t ifdoffset;
|
uint32_t ifdoffset;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "sssiI", &mode, &rawmode, &compname, &fp, &ifdoffset)) {
|
if (!PyArg_ParseTuple(args, "sssiI", &mode_name, &rawmode_name, &compname, &fp, &ifdoffset)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
TRACE(("new tiff decoder %s\n", compname));
|
TRACE(("new tiff decoder %s\n", compname));
|
||||||
|
|
||||||
decoder = PyImaging_DecoderNew(sizeof(TIFFSTATE));
|
decoder = PyImaging_DecoderNew(sizeof(TIFFSTATE));
|
||||||
|
@ -511,12 +516,15 @@ PyObject *
|
||||||
PyImaging_PackbitsDecoderNew(PyObject *self, PyObject *args) {
|
PyImaging_PackbitsDecoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingDecoderObject *decoder;
|
ImagingDecoderObject *decoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name;
|
||||||
char *rawmode;
|
char *rawmode_name;
|
||||||
if (!PyArg_ParseTuple(args, "ss", &mode, &rawmode)) {
|
if (!PyArg_ParseTuple(args, "ss", &mode_name, &rawmode_name)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
decoder = PyImaging_DecoderNew(0);
|
decoder = PyImaging_DecoderNew(0);
|
||||||
if (decoder == NULL) {
|
if (decoder == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -545,7 +553,7 @@ PyImaging_PcdDecoderNew(PyObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unpack from PhotoYCC to RGB */
|
/* Unpack from PhotoYCC to RGB */
|
||||||
if (get_unpacker(decoder, "RGB", "YCC;P") < 0) {
|
if (get_unpacker(decoder, IMAGING_MODE_RGB, IMAGING_RAWMODE_YCC_P) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,13 +570,15 @@ PyObject *
|
||||||
PyImaging_PcxDecoderNew(PyObject *self, PyObject *args) {
|
PyImaging_PcxDecoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingDecoderObject *decoder;
|
ImagingDecoderObject *decoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name, *rawmode_name;
|
||||||
char *rawmode;
|
|
||||||
int stride;
|
int stride;
|
||||||
if (!PyArg_ParseTuple(args, "ssi", &mode, &rawmode, &stride)) {
|
if (!PyArg_ParseTuple(args, "ssi", &mode_name, &rawmode_name, &stride)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
decoder = PyImaging_DecoderNew(0);
|
decoder = PyImaging_DecoderNew(0);
|
||||||
if (decoder == NULL) {
|
if (decoder == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -593,14 +603,16 @@ PyObject *
|
||||||
PyImaging_RawDecoderNew(PyObject *self, PyObject *args) {
|
PyImaging_RawDecoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingDecoderObject *decoder;
|
ImagingDecoderObject *decoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name, *rawmode_name;
|
||||||
char *rawmode;
|
|
||||||
int stride = 0;
|
int stride = 0;
|
||||||
int ystep = 1;
|
int ystep = 1;
|
||||||
if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &stride, &ystep)) {
|
if (!PyArg_ParseTuple(args, "ss|ii", &mode_name, &rawmode_name, &stride, &ystep)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
decoder = PyImaging_DecoderNew(sizeof(RAWSTATE));
|
decoder = PyImaging_DecoderNew(sizeof(RAWSTATE));
|
||||||
if (decoder == NULL) {
|
if (decoder == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -627,14 +639,16 @@ PyObject *
|
||||||
PyImaging_SgiRleDecoderNew(PyObject *self, PyObject *args) {
|
PyImaging_SgiRleDecoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingDecoderObject *decoder;
|
ImagingDecoderObject *decoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name, *rawmode_name;
|
||||||
char *rawmode;
|
|
||||||
int ystep = 1;
|
int ystep = 1;
|
||||||
int bpc = 1;
|
int bpc = 1;
|
||||||
if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &ystep, &bpc)) {
|
if (!PyArg_ParseTuple(args, "ss|ii", &mode_name, &rawmode_name, &ystep, &bpc)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
decoder = PyImaging_DecoderNew(sizeof(SGISTATE));
|
decoder = PyImaging_DecoderNew(sizeof(SGISTATE));
|
||||||
if (decoder == NULL) {
|
if (decoder == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -661,12 +675,14 @@ PyObject *
|
||||||
PyImaging_SunRleDecoderNew(PyObject *self, PyObject *args) {
|
PyImaging_SunRleDecoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingDecoderObject *decoder;
|
ImagingDecoderObject *decoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name, *rawmode_name;
|
||||||
char *rawmode;
|
if (!PyArg_ParseTuple(args, "ss", &mode_name, &rawmode_name)) {
|
||||||
if (!PyArg_ParseTuple(args, "ss", &mode, &rawmode)) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
decoder = PyImaging_DecoderNew(0);
|
decoder = PyImaging_DecoderNew(0);
|
||||||
if (decoder == NULL) {
|
if (decoder == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -689,14 +705,16 @@ PyObject *
|
||||||
PyImaging_TgaRleDecoderNew(PyObject *self, PyObject *args) {
|
PyImaging_TgaRleDecoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingDecoderObject *decoder;
|
ImagingDecoderObject *decoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name, *rawmode_name;
|
||||||
char *rawmode;
|
|
||||||
int ystep = 1;
|
int ystep = 1;
|
||||||
int depth = 8;
|
int depth = 8;
|
||||||
if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &ystep, &depth)) {
|
if (!PyArg_ParseTuple(args, "ss|ii", &mode_name, &rawmode_name, &ystep, &depth)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
decoder = PyImaging_DecoderNew(0);
|
decoder = PyImaging_DecoderNew(0);
|
||||||
if (decoder == NULL) {
|
if (decoder == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -727,7 +745,7 @@ PyImaging_XbmDecoderNew(PyObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_unpacker(decoder, "1", "1;R") < 0) {
|
if (get_unpacker(decoder, IMAGING_MODE_1, IMAGING_RAWMODE_1_R) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,13 +766,15 @@ PyObject *
|
||||||
PyImaging_ZipDecoderNew(PyObject *self, PyObject *args) {
|
PyImaging_ZipDecoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingDecoderObject *decoder;
|
ImagingDecoderObject *decoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name, *rawmode_name;
|
||||||
char *rawmode;
|
|
||||||
int interlaced = 0;
|
int interlaced = 0;
|
||||||
if (!PyArg_ParseTuple(args, "ss|i", &mode, &rawmode, &interlaced)) {
|
if (!PyArg_ParseTuple(args, "ss|i", &mode_name, &rawmode_name, &interlaced)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
decoder = PyImaging_DecoderNew(sizeof(ZIPSTATE));
|
decoder = PyImaging_DecoderNew(sizeof(ZIPSTATE));
|
||||||
if (decoder == NULL) {
|
if (decoder == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -798,16 +818,19 @@ PyObject *
|
||||||
PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) {
|
PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingDecoderObject *decoder;
|
ImagingDecoderObject *decoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name;
|
||||||
char *rawmode; /* what we want from the decoder */
|
char *rawmode_name; /* what we want from the decoder */
|
||||||
char *jpegmode; /* what's in the file */
|
char *jpegmode; /* what's in the file */
|
||||||
int scale = 1;
|
int scale = 1;
|
||||||
int draft = 0;
|
int draft = 0;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "ssz|ii", &mode, &rawmode, &jpegmode, &scale, &draft)) {
|
if (!PyArg_ParseTuple(args, "ssz|ii", &mode_name, &rawmode_name, &jpegmode, &scale, &draft)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
if (!jpegmode) {
|
if (!jpegmode) {
|
||||||
jpegmode = "";
|
jpegmode = "";
|
||||||
}
|
}
|
||||||
|
@ -820,8 +843,8 @@ PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) {
|
||||||
// libjpeg-turbo supports different output formats.
|
// libjpeg-turbo supports different output formats.
|
||||||
// We are choosing Pillow's native format (3 color bytes + 1 padding)
|
// We are choosing Pillow's native format (3 color bytes + 1 padding)
|
||||||
// to avoid extra conversion in Unpack.c.
|
// to avoid extra conversion in Unpack.c.
|
||||||
if (ImagingJpegUseJCSExtensions() && strcmp(rawmode, "RGB") == 0) {
|
if (ImagingJpegUseJCSExtensions() && rawmode == IMAGING_RAWMODE_RGB) {
|
||||||
rawmode = "RGBX";
|
rawmode = IMAGING_RAWMODE_RGBX;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_unpacker(decoder, mode, rawmode) < 0) {
|
if (get_unpacker(decoder, mode, rawmode) < 0) {
|
||||||
|
@ -831,11 +854,13 @@ PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) {
|
||||||
decoder->decode = ImagingJpegDecode;
|
decoder->decode = ImagingJpegDecode;
|
||||||
decoder->cleanup = ImagingJpegDecodeCleanup;
|
decoder->cleanup = ImagingJpegDecodeCleanup;
|
||||||
|
|
||||||
strncpy(((JPEGSTATE *)decoder->state.context)->rawmode, rawmode, 8);
|
JPEGSTATE *jpeg_decoder_state_context = (JPEGSTATE *)decoder->state.context;
|
||||||
strncpy(((JPEGSTATE *)decoder->state.context)->jpegmode, jpegmode, 8);
|
|
||||||
|
|
||||||
((JPEGSTATE *)decoder->state.context)->scale = scale;
|
jpeg_decoder_state_context->rawmode = rawmode;
|
||||||
((JPEGSTATE *)decoder->state.context)->draft = draft;
|
strncpy(jpeg_decoder_state_context->jpegmode, jpegmode, 8);
|
||||||
|
|
||||||
|
jpeg_decoder_state_context->scale = scale;
|
||||||
|
jpeg_decoder_state_context->draft = draft;
|
||||||
|
|
||||||
return (PyObject *)decoder;
|
return (PyObject *)decoder;
|
||||||
}
|
}
|
||||||
|
|
94
src/encode.c
94
src/encode.c
|
@ -334,14 +334,19 @@ static PyTypeObject ImagingEncoderType = {
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
get_packer(ImagingEncoderObject *encoder, const char *mode, const char *rawmode) {
|
get_packer(ImagingEncoderObject *encoder, const Mode *mode, const RawMode *rawmode) {
|
||||||
int bits;
|
int bits;
|
||||||
ImagingShuffler pack;
|
ImagingShuffler pack;
|
||||||
|
|
||||||
pack = ImagingFindPacker(mode, rawmode, &bits);
|
pack = ImagingFindPacker(mode, rawmode, &bits);
|
||||||
if (!pack) {
|
if (!pack) {
|
||||||
Py_DECREF(encoder);
|
Py_DECREF(encoder);
|
||||||
PyErr_Format(PyExc_ValueError, "No packer found from %s to %s", mode, rawmode);
|
PyErr_Format(
|
||||||
|
PyExc_ValueError,
|
||||||
|
"No packer found from %s to %s",
|
||||||
|
mode->name,
|
||||||
|
rawmode->name
|
||||||
|
);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,11 +407,11 @@ PyObject *
|
||||||
PyImaging_GifEncoderNew(PyObject *self, PyObject *args) {
|
PyImaging_GifEncoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingEncoderObject *encoder;
|
ImagingEncoderObject *encoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name;
|
||||||
char *rawmode;
|
char *rawmode_name;
|
||||||
Py_ssize_t bits = 8;
|
Py_ssize_t bits = 8;
|
||||||
Py_ssize_t interlace = 0;
|
Py_ssize_t interlace = 0;
|
||||||
if (!PyArg_ParseTuple(args, "ss|nn", &mode, &rawmode, &bits, &interlace)) {
|
if (!PyArg_ParseTuple(args, "ss|nn", &mode_name, &rawmode_name, &bits, &interlace)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,6 +420,9 @@ PyImaging_GifEncoderNew(PyObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
if (get_packer(encoder, mode, rawmode) < 0) {
|
if (get_packer(encoder, mode, rawmode) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -435,11 +443,11 @@ PyObject *
|
||||||
PyImaging_PcxEncoderNew(PyObject *self, PyObject *args) {
|
PyImaging_PcxEncoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingEncoderObject *encoder;
|
ImagingEncoderObject *encoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name;
|
||||||
char *rawmode;
|
char *rawmode_name;
|
||||||
Py_ssize_t bits = 8;
|
Py_ssize_t bits = 8;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "ss|n", &mode, &rawmode, &bits)) {
|
if (!PyArg_ParseTuple(args, "ss|n", &mode_name, &rawmode_name, &bits)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,6 +456,9 @@ PyImaging_PcxEncoderNew(PyObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
if (get_packer(encoder, mode, rawmode) < 0) {
|
if (get_packer(encoder, mode, rawmode) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -465,12 +476,12 @@ PyObject *
|
||||||
PyImaging_RawEncoderNew(PyObject *self, PyObject *args) {
|
PyImaging_RawEncoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingEncoderObject *encoder;
|
ImagingEncoderObject *encoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name;
|
||||||
char *rawmode;
|
char *rawmode_name;
|
||||||
Py_ssize_t stride = 0;
|
Py_ssize_t stride = 0;
|
||||||
Py_ssize_t ystep = 1;
|
Py_ssize_t ystep = 1;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "ss|nn", &mode, &rawmode, &stride, &ystep)) {
|
if (!PyArg_ParseTuple(args, "ss|nn", &mode_name, &rawmode_name, &stride, &ystep)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,6 +490,9 @@ PyImaging_RawEncoderNew(PyObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
if (get_packer(encoder, mode, rawmode) < 0) {
|
if (get_packer(encoder, mode, rawmode) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -499,11 +513,11 @@ PyObject *
|
||||||
PyImaging_TgaRleEncoderNew(PyObject *self, PyObject *args) {
|
PyImaging_TgaRleEncoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingEncoderObject *encoder;
|
ImagingEncoderObject *encoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name;
|
||||||
char *rawmode;
|
char *rawmode_name;
|
||||||
Py_ssize_t ystep = 1;
|
Py_ssize_t ystep = 1;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "ss|n", &mode, &rawmode, &ystep)) {
|
if (!PyArg_ParseTuple(args, "ss|n", &mode_name, &rawmode_name, &ystep)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,6 +526,9 @@ PyImaging_TgaRleEncoderNew(PyObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
if (get_packer(encoder, mode, rawmode) < 0) {
|
if (get_packer(encoder, mode, rawmode) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -536,7 +553,7 @@ PyImaging_XbmEncoderNew(PyObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_packer(encoder, "1", "1;R") < 0) {
|
if (get_packer(encoder, IMAGING_MODE_1, IMAGING_RAWMODE_1_R) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,8 +574,8 @@ PyObject *
|
||||||
PyImaging_ZipEncoderNew(PyObject *self, PyObject *args) {
|
PyImaging_ZipEncoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingEncoderObject *encoder;
|
ImagingEncoderObject *encoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name;
|
||||||
char *rawmode;
|
char *rawmode_name;
|
||||||
Py_ssize_t optimize = 0;
|
Py_ssize_t optimize = 0;
|
||||||
Py_ssize_t compress_level = -1;
|
Py_ssize_t compress_level = -1;
|
||||||
Py_ssize_t compress_type = -1;
|
Py_ssize_t compress_type = -1;
|
||||||
|
@ -567,8 +584,8 @@ PyImaging_ZipEncoderNew(PyObject *self, PyObject *args) {
|
||||||
if (!PyArg_ParseTuple(
|
if (!PyArg_ParseTuple(
|
||||||
args,
|
args,
|
||||||
"ss|nnny#",
|
"ss|nnny#",
|
||||||
&mode,
|
&mode_name,
|
||||||
&rawmode,
|
&rawmode_name,
|
||||||
&optimize,
|
&optimize,
|
||||||
&compress_level,
|
&compress_level,
|
||||||
&compress_type,
|
&compress_type,
|
||||||
|
@ -597,6 +614,9 @@ PyImaging_ZipEncoderNew(PyObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
if (get_packer(encoder, mode, rawmode) < 0) {
|
if (get_packer(encoder, mode, rawmode) < 0) {
|
||||||
free(dictionary);
|
free(dictionary);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -605,7 +625,7 @@ PyImaging_ZipEncoderNew(PyObject *self, PyObject *args) {
|
||||||
encoder->encode = ImagingZipEncode;
|
encoder->encode = ImagingZipEncode;
|
||||||
encoder->cleanup = ImagingZipEncodeCleanup;
|
encoder->cleanup = ImagingZipEncodeCleanup;
|
||||||
|
|
||||||
if (rawmode[0] == 'P') {
|
if (rawmode == IMAGING_RAWMODE_P || rawmode == IMAGING_RAWMODE_PA) {
|
||||||
/* disable filtering */
|
/* disable filtering */
|
||||||
((ZIPSTATE *)encoder->state.context)->mode = ZIP_PNG_PALETTE;
|
((ZIPSTATE *)encoder->state.context)->mode = ZIP_PNG_PALETTE;
|
||||||
}
|
}
|
||||||
|
@ -634,8 +654,8 @@ PyObject *
|
||||||
PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
|
PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingEncoderObject *encoder;
|
ImagingEncoderObject *encoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name;
|
||||||
char *rawmode;
|
char *rawmode_name;
|
||||||
char *compname;
|
char *compname;
|
||||||
char *filename;
|
char *filename;
|
||||||
Py_ssize_t fp;
|
Py_ssize_t fp;
|
||||||
|
@ -655,7 +675,15 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
|
||||||
PyObject *item;
|
PyObject *item;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(
|
if (!PyArg_ParseTuple(
|
||||||
args, "sssnsOO", &mode, &rawmode, &compname, &fp, &filename, &tags, &types
|
args,
|
||||||
|
"sssnsOO",
|
||||||
|
&mode_name,
|
||||||
|
&rawmode_name,
|
||||||
|
&compname,
|
||||||
|
&fp,
|
||||||
|
&filename,
|
||||||
|
&tags,
|
||||||
|
&types
|
||||||
)) {
|
)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -693,6 +721,9 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * const rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
if (get_packer(encoder, mode, rawmode) < 0) {
|
if (get_packer(encoder, mode, rawmode) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1076,8 +1107,8 @@ PyObject *
|
||||||
PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
|
PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
|
||||||
ImagingEncoderObject *encoder;
|
ImagingEncoderObject *encoder;
|
||||||
|
|
||||||
char *mode;
|
char *mode_name;
|
||||||
char *rawmode;
|
char *rawmode_name;
|
||||||
Py_ssize_t quality = 0;
|
Py_ssize_t quality = 0;
|
||||||
Py_ssize_t progressive = 0;
|
Py_ssize_t progressive = 0;
|
||||||
Py_ssize_t smooth = 0;
|
Py_ssize_t smooth = 0;
|
||||||
|
@ -1101,8 +1132,8 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
|
||||||
if (!PyArg_ParseTuple(
|
if (!PyArg_ParseTuple(
|
||||||
args,
|
args,
|
||||||
"ss|nnnnpn(nn)nnnOz#y#y#",
|
"ss|nnnnpn(nn)nnnOz#y#y#",
|
||||||
&mode,
|
&mode_name,
|
||||||
&rawmode,
|
&rawmode_name,
|
||||||
&quality,
|
&quality,
|
||||||
&progressive,
|
&progressive,
|
||||||
&smooth,
|
&smooth,
|
||||||
|
@ -1130,11 +1161,14 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Mode * const mode = findMode(mode_name);
|
||||||
|
const RawMode * rawmode = findRawMode(rawmode_name);
|
||||||
|
|
||||||
// libjpeg-turbo supports different output formats.
|
// libjpeg-turbo supports different output formats.
|
||||||
// We are choosing Pillow's native format (3 color bytes + 1 padding)
|
// We are choosing Pillow's native format (3 color bytes + 1 padding)
|
||||||
// to avoid extra conversion in Pack.c.
|
// to avoid extra conversion in Pack.c.
|
||||||
if (ImagingJpegUseJCSExtensions() && strcmp(rawmode, "RGB") == 0) {
|
if (ImagingJpegUseJCSExtensions() && rawmode == IMAGING_RAWMODE_RGB) {
|
||||||
rawmode = "RGBX";
|
rawmode = IMAGING_RAWMODE_RGBX;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_packer(encoder, mode, rawmode) < 0) {
|
if (get_packer(encoder, mode, rawmode) < 0) {
|
||||||
|
@ -1192,7 +1226,7 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
|
||||||
encoder->encode = ImagingJpegEncode;
|
encoder->encode = ImagingJpegEncode;
|
||||||
|
|
||||||
JPEGENCODERSTATE *jpeg_encoder_state = (JPEGENCODERSTATE *)encoder->state.context;
|
JPEGENCODERSTATE *jpeg_encoder_state = (JPEGENCODERSTATE *)encoder->state.context;
|
||||||
strncpy(jpeg_encoder_state->rawmode, rawmode, 8);
|
jpeg_encoder_state->rawmode = rawmode;
|
||||||
jpeg_encoder_state->keep_rgb = keep_rgb;
|
jpeg_encoder_state->keep_rgb = keep_rgb;
|
||||||
jpeg_encoder_state->quality = quality;
|
jpeg_encoder_state->quality = quality;
|
||||||
jpeg_encoder_state->qtables = qarrays;
|
jpeg_encoder_state->qtables = qarrays;
|
||||||
|
|
|
@ -31,9 +31,9 @@ typedef struct {
|
||||||
/* Jpeg file mode (empty if not known) */
|
/* Jpeg file mode (empty if not known) */
|
||||||
char jpegmode[8 + 1];
|
char jpegmode[8 + 1];
|
||||||
|
|
||||||
/* Converter output mode (input to the shuffler). If empty,
|
/* Converter output mode (input to the shuffler) */
|
||||||
convert conversions are disabled */
|
/* If NULL, convert conversions are disabled */
|
||||||
char rawmode[8 + 1];
|
const RawMode *rawmode;
|
||||||
|
|
||||||
/* If set, trade quality for speed */
|
/* If set, trade quality for speed */
|
||||||
int draft;
|
int draft;
|
||||||
|
@ -91,7 +91,7 @@ typedef struct {
|
||||||
unsigned int restart_marker_rows;
|
unsigned int restart_marker_rows;
|
||||||
|
|
||||||
/* Converter input mode (input to the shuffler) */
|
/* Converter input mode (input to the shuffler) */
|
||||||
char rawmode[8 + 1];
|
const RawMode *rawmode;
|
||||||
|
|
||||||
/* Custom quantization tables () */
|
/* Custom quantization tables () */
|
||||||
unsigned int *qtables;
|
unsigned int *qtables;
|
||||||
|
|
|
@ -43,6 +43,7 @@ typedef struct {
|
||||||
const char * const name;
|
const char * const name;
|
||||||
} RawMode;
|
} RawMode;
|
||||||
|
|
||||||
|
// Non-rawmode aliases.
|
||||||
extern const RawMode * const IMAGING_RAWMODE_1;
|
extern const RawMode * const IMAGING_RAWMODE_1;
|
||||||
extern const RawMode * const IMAGING_RAWMODE_CMYK;
|
extern const RawMode * const IMAGING_RAWMODE_CMYK;
|
||||||
extern const RawMode * const IMAGING_RAWMODE_F;
|
extern const RawMode * const IMAGING_RAWMODE_F;
|
||||||
|
@ -60,16 +61,22 @@ extern const RawMode * const IMAGING_RAWMODE_RGBX;
|
||||||
extern const RawMode * const IMAGING_RAWMODE_RGBa;
|
extern const RawMode * const IMAGING_RAWMODE_RGBa;
|
||||||
extern const RawMode * const IMAGING_RAWMODE_YCbCr;
|
extern const RawMode * const IMAGING_RAWMODE_YCbCr;
|
||||||
|
|
||||||
|
// BGR modes.
|
||||||
extern const RawMode * const IMAGING_RAWMODE_BGR_15;
|
extern const RawMode * const IMAGING_RAWMODE_BGR_15;
|
||||||
extern const RawMode * const IMAGING_RAWMODE_BGR_16;
|
extern const RawMode * const IMAGING_RAWMODE_BGR_16;
|
||||||
extern const RawMode * const IMAGING_RAWMODE_BGR_24;
|
extern const RawMode * const IMAGING_RAWMODE_BGR_24;
|
||||||
extern const RawMode * const IMAGING_RAWMODE_BGR_32;
|
extern const RawMode * const IMAGING_RAWMODE_BGR_32;
|
||||||
|
|
||||||
|
// I;16 modes.
|
||||||
extern const RawMode * const IMAGING_RAWMODE_I_16;
|
extern const RawMode * const IMAGING_RAWMODE_I_16;
|
||||||
extern const RawMode * const IMAGING_RAWMODE_I_16L;
|
extern const RawMode * const IMAGING_RAWMODE_I_16L;
|
||||||
extern const RawMode * const IMAGING_RAWMODE_I_16B;
|
extern const RawMode * const IMAGING_RAWMODE_I_16B;
|
||||||
extern const RawMode * const IMAGING_RAWMODE_I_16N;
|
extern const RawMode * const IMAGING_RAWMODE_I_16N;
|
||||||
|
|
||||||
|
// Rawmodes
|
||||||
|
extern const RawMode * const IMAGING_RAWMODE_1_R;
|
||||||
|
extern const RawMode * const IMAGING_RAWMODE_YCC_P;
|
||||||
|
|
||||||
const RawMode * findRawMode(const char * const name);
|
const RawMode * findRawMode(const char * const name);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user