From 69f315a58551361547ecde0660d306b7a3c7b754 Mon Sep 17 00:00:00 2001 From: Konstantin Kopachev Date: Wed, 26 Sep 2018 09:44:45 -0700 Subject: [PATCH] PR feedback: simplified key construct for fillorder=2; indentation fixes --- src/PIL/TiffImagePlugin.py | 9 +++------ src/libImaging/TiffDecode.c | 12 ++++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index fa8f984f4..50746688e 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1256,11 +1256,8 @@ class TiffImageFile(ImageFile.ImageFile): # bits, so stripes of the image are reversed. See # https://github.com/python-pillow/Pillow/issues/279 if fillorder == 2: - key = ( - self.tag_v2.prefix, photo, sampleFormat, 1, - self.tag_v2.get(BITSPERSAMPLE, (1,)), - self.tag_v2.get(EXTRASAMPLES, ()) - ) + # Replace fillorder with fillorder=1 + key = key[:3] + (1,) + key[4:] if DEBUG: print("format key:", key) # this should always work, since all the @@ -1315,7 +1312,7 @@ class TiffImageFile(ImageFile.ImageFile): self.tile.append( (self._compression, (x, y, min(x+w, xsize), min(y+h, ysize)), - offset, a)) + offset, a)) x = x + w if x >= self.size[0]: x, y = 0, y + h diff --git a/src/libImaging/TiffDecode.c b/src/libImaging/TiffDecode.c index 8722278da..98302389b 100644 --- a/src/libImaging/TiffDecode.c +++ b/src/libImaging/TiffDecode.c @@ -236,14 +236,14 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int TIFFSetField(tiff, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB); - if (TIFFIsTiled(tiff)) { - uint32 x, y, tile_y; + if (TIFFIsTiled(tiff)) { + uint32 x, y, tile_y; uint32 tileWidth, tileLength; UINT8 *new_data; - state->bytes = TIFFTileSize(tiff); + state->bytes = TIFFTileSize(tiff); - /* overflow check for malloc */ + /* overflow check for malloc */ if (state->bytes > INT_MAX - 1) { state->errcode = IMAGING_CODEC_MEMORY; TIFFClose(tiff); @@ -285,8 +285,8 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int // TRACE(("chars: %x%x%x%x\n", ((UINT8 *)bbb)[0], ((UINT8 *)bbb)[1], ((UINT8 *)bbb)[2], ((UINT8 *)bbb)[3])); state->shuffle((UINT8*) im->image[tile_y + y] + x * im->pixelsize, - state->buffer + tile_y * (state->bytes / tileLength), - min(tileWidth, state->xsize - x) + state->buffer + tile_y * (state->bytes / tileLength), + min(tileWidth, state->xsize - x) ); } }