mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-05 06:00:58 +03:00
GIF: Support transparency in the native decoder.
Allow the transparency index to be passed to the native decoder. If not -1, pixels with this index will be left at their previous value. This only adds the decoder support and isn't active yet.
This commit is contained in:
parent
8064e04e96
commit
a4a314f765
|
@ -251,7 +251,7 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
bits = self.fp.read(1)[0]
|
bits = self.fp.read(1)[0]
|
||||||
self.__offset = self.fp.tell()
|
self.__offset = self.fp.tell()
|
||||||
self.tile = [
|
self.tile = [
|
||||||
("gif", (x0, y0, x1, y1), self.__offset, (bits, interlace))
|
("gif", (x0, y0, x1, y1), self.__offset, (bits, interlace, -1))
|
||||||
]
|
]
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -430,7 +430,8 @@ PyImaging_GifDecoderNew(PyObject *self, PyObject *args) {
|
||||||
char *mode;
|
char *mode;
|
||||||
int bits = 8;
|
int bits = 8;
|
||||||
int interlace = 0;
|
int interlace = 0;
|
||||||
if (!PyArg_ParseTuple(args, "s|ii", &mode, &bits, &interlace)) {
|
int transparency = -1;
|
||||||
|
if (!PyArg_ParseTuple(args, "s|iii", &mode, &bits, &interlace, &transparency)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,6 +449,7 @@ PyImaging_GifDecoderNew(PyObject *self, PyObject *args) {
|
||||||
|
|
||||||
((GIFDECODERSTATE *)decoder->state.context)->bits = bits;
|
((GIFDECODERSTATE *)decoder->state.context)->bits = bits;
|
||||||
((GIFDECODERSTATE *)decoder->state.context)->interlace = interlace;
|
((GIFDECODERSTATE *)decoder->state.context)->interlace = interlace;
|
||||||
|
((GIFDECODERSTATE *)decoder->state.context)->transparency = transparency;
|
||||||
|
|
||||||
return (PyObject *)decoder;
|
return (PyObject *)decoder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ typedef struct {
|
||||||
*/
|
*/
|
||||||
int interlace;
|
int interlace;
|
||||||
|
|
||||||
|
/* The transparent palette index, or -1 for no transparency. */
|
||||||
|
int transparency;
|
||||||
|
|
||||||
/* PRIVATE CONTEXT (set by decoder) */
|
/* PRIVATE CONTEXT (set by decoder) */
|
||||||
|
|
||||||
/* Interlace parameters */
|
/* Interlace parameters */
|
||||||
|
|
|
@ -248,8 +248,8 @@ ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t
|
||||||
/* To squeeze some extra pixels out of this loop, we test for
|
/* To squeeze some extra pixels out of this loop, we test for
|
||||||
some common cases and handle them separately. */
|
some common cases and handle them separately. */
|
||||||
|
|
||||||
/* FIXME: should we handle the transparency index in here??? */
|
/* If we have transparency, we need to use the regular loop. */
|
||||||
|
if (context->transparency == -1) {
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
if (state->x < state->xsize - 1) {
|
if (state->x < state->xsize - 1) {
|
||||||
/* Single pixel, not at the end of the line. */
|
/* Single pixel, not at the end of the line. */
|
||||||
|
@ -267,10 +267,14 @@ ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* No shortcut, copy pixel by pixel */
|
/* No shortcut, copy pixel by pixel */
|
||||||
for (c = 0; c < i; c++) {
|
for (c = 0; c < i; c++) {
|
||||||
*out++ = p[c];
|
if (p[c] != context->transparency) {
|
||||||
|
*out = p[c];
|
||||||
|
}
|
||||||
|
out++;
|
||||||
if (++state->x >= state->xsize) {
|
if (++state->x >= state->xsize) {
|
||||||
NEWLINE(state, context);
|
NEWLINE(state, context);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user