From 60e29e5e8d10f44b15f39aaa3877e9dda1009d7e Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Wed, 20 Dec 2017 14:36:39 +0000 Subject: [PATCH] dropping tiff_lzw implementation --- _imaging.c | 2 - decode.c | 30 ------ libImaging/Imaging.h | 2 - libImaging/Lzw.h | 52 ---------- libImaging/LzwDecode.c | 230 ----------------------------------------- setup.py | 2 +- 6 files changed, 1 insertion(+), 317 deletions(-) delete mode 100644 libImaging/Lzw.h delete mode 100644 libImaging/LzwDecode.c diff --git a/_imaging.c b/_imaging.c index 44eb2dbb7..d90f23477 100644 --- a/_imaging.c +++ b/_imaging.c @@ -3480,7 +3480,6 @@ extern PyObject* PyImaging_GifDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_HexDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_JpegDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_Jpeg2KDecoderNew(PyObject* self, PyObject* args); -extern PyObject* PyImaging_TiffLzwDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_LibTiffDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_PackbitsDecoderNew(PyObject* self, PyObject* args); extern PyObject* PyImaging_PcdDecoderNew(PyObject* self, PyObject* args); @@ -3553,7 +3552,6 @@ static PyMethodDef functions[] = { {"jpeg2k_decoder", (PyCFunction)PyImaging_Jpeg2KDecoderNew, 1}, {"jpeg2k_encoder", (PyCFunction)PyImaging_Jpeg2KEncoderNew, 1}, #endif - {"tiff_lzw_decoder", (PyCFunction)PyImaging_TiffLzwDecoderNew, 1}, #ifdef HAVE_LIBTIFF {"libtiff_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, {"libtiff_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, diff --git a/decode.c b/decode.c index bfd19faa4..be1b503e6 100644 --- a/decode.c +++ b/decode.c @@ -35,7 +35,6 @@ #include "py3.h" #include "Gif.h" -#include "Lzw.h" #include "Raw.h" #include "Bit.h" #include "Sgi.h" @@ -484,35 +483,6 @@ PyImaging_HexDecoderNew(PyObject* self, PyObject* args) } -/* -------------------------------------------------------------------- */ -/* LZW */ -/* -------------------------------------------------------------------- */ - -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; -} - /* -------------------------------------------------------------------- */ /* LibTiff */ /* -------------------------------------------------------------------- */ diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index fe8d796a2..aa59fe18c 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -440,8 +440,6 @@ extern int ImagingJpeg2KEncode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); extern int ImagingJpeg2KEncodeCleanup(ImagingCodecState state); #endif -extern int ImagingLzwDecode(Imaging im, ImagingCodecState state, - UINT8* buffer, int bytes); #ifdef HAVE_LIBTIFF extern int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes); diff --git a/libImaging/Lzw.h b/libImaging/Lzw.h deleted file mode 100644 index 8fc30bd7f..000000000 --- a/libImaging/Lzw.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The Python Imaging Library. - * $Id$ - * - * declarations for the TIFF LZW decoder. - * - * Copyright (c) Fredrik Lundh 1995-96. - */ - - -/* Max size for LZW code words */ - -#define LZWBITS 12 - -#define LZWTABLE (1< -#include /* memcpy() */ - -#include "Lzw.h" - - -int -ImagingLzwDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) -{ - UINT8* p; - int c, i; - int thiscode; - LZWSTATE* context = (LZWSTATE*) state->context; - - unsigned char *ptr = buf; - - if (!state->state) { - - /* Clear code */ - context->clear = 1 << 8; - - /* End code */ - context->end = context->clear + 1; - - state->state = 1; - } - - for (;;) { - - if (state->state == 1) { - - /* First free entry in table */ - context->next = context->clear + 2; - - /* Initial code size */ - context->codesize = 8 + 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 = LZWBUFFER; - - state->state = 2; - } - - if (context->bufferindex < LZWBUFFER) { - - /* Return whole buffer in one chunk */ - i = LZWBUFFER - context->bufferindex; - p = &context->buffer[context->bufferindex]; - - context->bufferindex = LZWBUFFER; - - } else { - - /* Get current symbol */ - while (context->bitcount < context->codesize) { - - if (bytes < 1) - return ptr - buf;; - - /* Read next byte */ - c = *ptr++; bytes--; - - /* New bits are shifted in from from the right. */ - context->bitbuffer = (context->bitbuffer << 8) | c; - context->bitcount += 8; - - } - - /* Extract current symbol from bit buffer. */ - c = (context->bitbuffer >> (context->bitcount - - context->codesize)) - & context->codemask; - - /* Adjust buffer */ - 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 == context->clear) { - if (state->state != 2) - state->state = 1; - continue; - } - - if (c == context->end) - break; - - i = 1; - p = &context->lastdata; - - if (state->state == 2) { - - /* 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; - - } else { - - thiscode = c; - - if (c > context->next) { - state->errcode = IMAGING_CODEC_BROKEN; - return -1; - } - - if (c == context->next) { - - /* c == next is allowed, by some strange reason */ - if (context->bufferindex <= 0) { - state->errcode = IMAGING_CODEC_BROKEN; - return -1; - } - - context->buffer[--context->bufferindex] = context->lastdata; - c = context->lastcode; - } - - while (c >= context->clear) { - - /* Copy data string to buffer (beginning from right) */ - - if (context->bufferindex <= 0 || c >= LZWTABLE) { - state->errcode = IMAGING_CODEC_BROKEN; - return -1; - } - - context->buffer[--context->bufferindex] = - context->data[c]; - c = context->link[c]; - } - - context->lastdata = c; - - if (context->next < LZWTABLE) { - - /* While we still have room for it, add this - symbol to the table. */ - context->data[context->next] = c; - context->link[context->next] = context->lastcode; - - context->next++; - - if (context->next == context->codemask && - context->codesize < LZWBITS) { - - /* Expand code size */ - context->codesize++; - context->codemask = (1 << context->codesize) - 1; - - } - } - context->lastcode = thiscode; - } - } - - /* Update the output image */ - for (c = 0; c < i; c++) { - - state->buffer[state->x] = p[c]; - - if (++state->x >= state->bytes) { - - int x, bpp; - - /* Apply filter */ - switch (context->filter) { - case 2: - /* Horizontal differing ("prior") */ - bpp = (state->bits + 7) / 8; - for (x = bpp; x < state->bytes; x++) - state->buffer[x] += state->buffer[x-bpp]; - } - - /* 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; - } - } - } - - return ptr - buf; -} diff --git a/setup.py b/setup.py index 202266139..8b4433081 100755 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ _LIB_IMAGING = ( "Blend", "Chops", "Convert", "ConvertYCbCr", "Copy", "Crc32", "Crop", "Dib", "Draw", "Effects", "EpsEncode", "File", "Fill", "Filter", "FliDecode", "Geometry", "GetBBox", "GifDecode", "GifEncode", "HexDecode", - "Histo", "JpegDecode", "JpegEncode", "LzwDecode", "Matrix", "ModeFilter", + "Histo", "JpegDecode", "JpegEncode", "Matrix", "ModeFilter", "Negative", "Offset", "Pack", "PackDecode", "Palette", "Paste", "Quant", "QuantOctree", "QuantHash", "QuantHeap", "PcdDecode", "PcxDecode", "PcxEncode", "Point", "RankFilter", "RawDecode", "RawEncode", "Storage",