PyObject* PyImaging_RawDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; int stride = 0; int ystep = 1; if (!PyArg_ParseTuple(args, "ss|ii", &mode, &rawmode, &stride, &ystep)) return NULL; decoder = PyImaging_DecoderNew(sizeof(RAWSTATE)); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingRawDecode; decoder->state.ystep = ystep; ((RAWSTATE*)decoder->state.context)->stride = stride; return (PyObject*) decoder; }
PyObject* PyImaging_LibTiffDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; char* compname; int fp; int ifdoffset; if (! PyArg_ParseTuple(args, "sssii", &mode, &rawmode, &compname, &fp, &ifdoffset)) return NULL; TRACE(("new tiff decoder %s\n", compname)); decoder = PyImaging_DecoderNew(sizeof(TIFFSTATE)); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; if (! ImagingLibTiffInit(&decoder->state, fp, ifdoffset)) { Py_DECREF(decoder); PyErr_SetString(PyExc_RuntimeError, "tiff codec initialization failed"); return NULL; } decoder->decode = ImagingLibTiffDecode; return (PyObject*) decoder; }
PyObject* PyImaging_GifDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; int bits = 8; int interlace = 0; if (!PyArg_ParseTuple(args, "s|ii", &mode, &bits, &interlace)) return NULL; if (strcmp(mode, "L") != 0 && strcmp(mode, "P") != 0) { PyErr_SetString(PyExc_ValueError, "bad image mode"); return NULL; } decoder = PyImaging_DecoderNew(sizeof(GIFDECODERSTATE)); if (decoder == NULL) return NULL; decoder->decode = ImagingGifDecode; ((GIFDECODERSTATE*)decoder->state.context)->bits = bits; ((GIFDECODERSTATE*)decoder->state.context)->interlace = interlace; return (PyObject*) decoder; }
PyObject* PyImaging_BitDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; int bits = 8; int pad = 8; int fill = 0; int sign = 0; int ystep = 1; if (!PyArg_ParseTuple(args, "s|iiiii", &mode, &bits, &pad, &fill, &sign, &ystep)) return NULL; if (strcmp(mode, "F") != 0) { PyErr_SetString(PyExc_ValueError, "bad image mode"); return NULL; } decoder = PyImaging_DecoderNew(sizeof(BITSTATE)); if (decoder == NULL) return NULL; decoder->decode = ImagingBitDecode; decoder->state.ystep = ystep; ((BITSTATE*)decoder->state.context)->bits = bits; ((BITSTATE*)decoder->state.context)->pad = pad; ((BITSTATE*)decoder->state.context)->fill = fill; ((BITSTATE*)decoder->state.context)->sign = sign; return (PyObject*) decoder; }
PyObject* PyImaging_LibTiffDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; char* compname; int compression; int fp; if (! PyArg_ParseTuple(args, "sssi", &mode, &rawmode, &compname, &fp)) return NULL; TRACE(("new tiff decoder %s\n", compname)); /* UNDONE -- we can probably do almost any arbitrary compression here, * since we're effective passing in the whole file in one shot and * getting back the data row by row. V2 maybe */ if (strcasecmp(compname, "tiff_ccitt") == 0) { compression = COMPRESSION_CCITTRLE; } else if (strcasecmp(compname, "group3") == 0) { compression = COMPRESSION_CCITTFAX3; } else if (strcasecmp(compname, "group4") == 0) { compression = COMPRESSION_CCITTFAX4; } else if (strcasecmp(compname, "tiff_raw_16") == 0) { compression = COMPRESSION_CCITTRLEW; } else { PyErr_SetString(PyExc_ValueError, "unknown compession"); return NULL; } decoder = PyImaging_DecoderNew(sizeof(TIFFSTATE)); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; if (! ImagingLibTiffInit(&decoder->state, compression, fp)) { Py_DECREF(decoder); PyErr_SetString(PyExc_RuntimeError, "tiff codec initialization failed"); return NULL; } decoder->decode = ImagingLibTiffDecode; return (PyObject*) decoder; }
PyObject* PyImaging_FliDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; decoder->decode = ImagingFliDecode; return (PyObject*) decoder; }
PyObject* PyImaging_XbmDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; if (get_unpacker(decoder, "1", "1;R") < 0) return NULL; decoder->decode = ImagingXbmDecode; return (PyObject*) decoder; }
PyObject* PyImaging_PcdDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; /* Unpack from PhotoYCC to RGB */ if (get_unpacker(decoder, "RGB", "YCC;P") < 0) return NULL; decoder->decode = ImagingPcdDecode; return (PyObject*) decoder; }
PyObject* PyImaging_Jpeg2KDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; JPEG2KDECODESTATE *context; char* mode; char* format; OPJ_CODEC_FORMAT codec_format; int reduce = 0; int layers = 0; int fd = -1; PY_LONG_LONG length = -1; if (!PyArg_ParseTuple(args, "ss|iiiL", &mode, &format, &reduce, &layers, &fd, &length)) return NULL; if (strcmp(format, "j2k") == 0) codec_format = OPJ_CODEC_J2K; else if (strcmp(format, "jpt") == 0) codec_format = OPJ_CODEC_JPT; else if (strcmp(format, "jp2") == 0) codec_format = OPJ_CODEC_JP2; else return NULL; decoder = PyImaging_DecoderNew(sizeof(JPEG2KDECODESTATE)); if (decoder == NULL) return NULL; decoder->handles_eof = 1; decoder->pulls_fd = 1; decoder->decode = ImagingJpeg2KDecode; decoder->cleanup = ImagingJpeg2KDecodeCleanup; context = (JPEG2KDECODESTATE *)decoder->state.context; context->fd = fd; context->length = (off_t)length; context->format = codec_format; context->reduce = reduce; context->layers = layers; return (PyObject*) decoder; }
PyObject* PyImaging_BcnDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* actual; int n = 0; int ystep = 1; if (!PyArg_ParseTuple(args, "s|ii", &mode, &n, &ystep)) return NULL; switch (n) { case 1: /* BC1: 565 color, 1-bit alpha */ case 2: /* BC2: 565 color, 4-bit alpha */ case 3: /* BC3: 565 color, 2-endpoint 8-bit interpolated alpha */ case 5: /* BC5: 2-channel 8-bit via 2 BC3 alpha blocks */ case 7: /* BC7: 4-channel 8-bit via everything */ actual = "RGBA"; break; case 4: /* BC4: 1-channel 8-bit via 1 BC3 alpha block */ actual = "L"; break; case 6: /* BC6: 3-channel 16-bit float */ /* TODO: support 4-channel floating point images */ actual = "RGBAF"; break; default: PyErr_SetString(PyExc_ValueError, "block compression type unknown"); return NULL; } if (strcmp(mode, actual) != 0) { PyErr_SetString(PyExc_ValueError, "bad image mode"); return NULL; } decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; decoder->decode = ImagingBcnDecode; decoder->state.state = n; decoder->state.ystep = ystep; return (PyObject*) decoder; }
PyObject* PyImaging_JpegDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; /* what we want from the decoder */ char* jpegmode; /* what's in the file */ int scale = 1; int draft = 0; if (!PyArg_ParseTuple(args, "ssz|ii", &mode, &rawmode, &jpegmode, &scale, &draft)) return NULL; if (!jpegmode) jpegmode = ""; decoder = PyImaging_DecoderNew(sizeof(JPEGSTATE)); if (decoder == NULL) return NULL; // libjpeg-turbo supports different output formats. // We are choosing Pillow's native format (3 color bytes + 1 padding) // to avoid extra conversion in Unpack.c. if (ImagingJpegUseJCSExtensions() && strcmp(rawmode, "RGB") == 0) { rawmode = "RGBX"; } if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingJpegDecode; decoder->cleanup = ImagingJpegDecodeCleanup; strncpy(((JPEGSTATE*)decoder->state.context)->rawmode, rawmode, 8); strncpy(((JPEGSTATE*)decoder->state.context)->jpegmode, jpegmode, 8); ((JPEGSTATE*)decoder->state.context)->scale = scale; ((JPEGSTATE*)decoder->state.context)->draft = draft; return (PyObject*) decoder; }
PyObject* PyImaging_SunRleDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; if (!PyArg_ParseTuple(args, "ss", &mode, &rawmode)) return NULL; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingSunRleDecode; return (PyObject*) decoder; }
PyObject* PyImaging_ZipDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; int interlaced = 0; if (!PyArg_ParseTuple(args, "ss|i", &mode, &rawmode, &interlaced)) return NULL; decoder = PyImaging_DecoderNew(sizeof(ZIPSTATE)); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingZipDecode; ((ZIPSTATE*)decoder->state.context)->interlaced = interlaced; return (PyObject*) decoder; }
PyObject* PyImaging_PcxDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; int stride; if (!PyArg_ParseTuple(args, "ssi", &mode, &rawmode, &stride)) return NULL; decoder = PyImaging_DecoderNew(0); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->state.bytes = stride; decoder->decode = ImagingPcxDecode; return (PyObject*) decoder; }
PyObject* PyImaging_TiffLzwDecoderNew(PyObject* self, PyObject* args) { ImagingDecoderObject* decoder; char* mode; char* rawmode; int filter = 0; if (!PyArg_ParseTuple(args, "ss|i", &mode, &rawmode, &filter)) return NULL; decoder = PyImaging_DecoderNew(sizeof(LZWSTATE)); if (decoder == NULL) return NULL; if (get_unpacker(decoder, mode, rawmode) < 0) return NULL; decoder->decode = ImagingLzwDecode; ((LZWSTATE*)decoder->state.context)->filter = filter; return (PyObject*) decoder; }