Skip to content

Commit

Permalink
Tiff: report correct image size after opening
Browse files Browse the repository at this point in the history
  • Loading branch information
homm committed Aug 12, 2024
1 parent 22377a3 commit 1d77bfe
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,8 @@ def seek(self, frame):
# Create a new core image object on second and
# subsequent frames in the image. Image may be
# different size/mode.
Image._decompression_bomb_check(self.size)
self.im = Image.core.new(self.mode, self.size)
Image._decompression_bomb_check(self._tile_size)
self.im = Image.core.new(self.mode, self._tile_size)

def _seek(self, frame):
self.fp = self._fp
Expand Down Expand Up @@ -1202,6 +1202,12 @@ def load(self):
return self._load_libtiff()
return super().load()

def load_prepare(self):
# Restore self.size during image allocation
self._size, old_size = self._tile_size, self._size
super().load_prepare()
self._size = old_size

def load_end(self):
if self._tile_orientation:
method = {
Expand Down Expand Up @@ -1354,10 +1360,16 @@ def _setup(self):
logger.debug(f"- fill_order: {fillorder}")
logger.debug(f"- YCbCr subsampling: {self.tag.get(YCBCRSUBSAMPLING)}")

self._tile_orientation = self.tag_v2.get(0x0112)

# size
xsize = int(self.tag_v2.get(IMAGEWIDTH))
ysize = int(self.tag_v2.get(IMAGELENGTH))
self._size = xsize, ysize
self._tile_size = xsize, ysize
if self._tile_orientation in (5, 6, 7, 8):
self._size = ysize, xsize
else:
self._size = xsize, ysize

logger.debug(f"- size: {self.size}")

Expand Down Expand Up @@ -1500,7 +1512,7 @@ def _setup(self):
if STRIPOFFSETS in self.tag_v2:
offsets = self.tag_v2[STRIPOFFSETS]
h = self.tag_v2.get(ROWSPERSTRIP, ysize)
w = self.size[0]
w = xsize
else:
# tiled image
offsets = self.tag_v2[TILEOFFSETS]
Expand Down Expand Up @@ -1530,9 +1542,9 @@ def _setup(self):
)
)
x = x + w
if x >= self.size[0]:
if x >= xsize:
x, y = 0, y + h
if y >= self.size[1]:
if y >= ysize:
x = y = 0
layer += 1
else:
Expand All @@ -1550,9 +1562,6 @@ def _setup(self):
palette = [o8(b // 256) for b in self.tag_v2[COLORMAP]]
self.palette = ImagePalette.raw("RGB;L", b"".join(palette))

self._tile_orientation = self.tag_v2.get(0x0112)


#
# --------------------------------------------------------------------
# Write TIFF files
Expand Down

0 comments on commit 1d77bfe

Please sign in to comment.