Allow multipage CCITT group 4 TIFF images
This commit is contained in:
parent
a628ed22f9
commit
ba5a9a1dfc
1 changed files with 50 additions and 39 deletions
|
@ -861,6 +861,30 @@ def read_images(rawdata, colorspace, first_frame_only=False):
|
||||||
return [(color, ndpi, imgformat, pngidat, imgwidthpx, imgheightpx,
|
return [(color, ndpi, imgformat, pngidat, imgwidthpx, imgheightpx,
|
||||||
palette, False)]
|
palette, False)]
|
||||||
|
|
||||||
|
# If our input is not JPEG or PNG, then we might have a format that
|
||||||
|
# supports multiple frames (like TIFF or GIF), so we need a loop to
|
||||||
|
# iterate through all frames of the image.
|
||||||
|
#
|
||||||
|
# Each frame gets compressed using PNG compression *except* if:
|
||||||
|
#
|
||||||
|
# * The image is monochrome => encode using CCITT group 4
|
||||||
|
#
|
||||||
|
# * The image is CMYK => zip plain RGB data
|
||||||
|
#
|
||||||
|
# * We are handling a CCITT encoded TIFF frame => embed data
|
||||||
|
|
||||||
|
result = []
|
||||||
|
img_page_count = 0
|
||||||
|
# loop through all frames of the image (example: multipage TIFF)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
imgdata.seek(img_page_count)
|
||||||
|
except EOFError:
|
||||||
|
break
|
||||||
|
|
||||||
|
if first_frame_only and img_page_count > 0:
|
||||||
|
break
|
||||||
|
|
||||||
# We can directly copy the data out of a CCITT Group 4 encoded TIFF, if it
|
# We can directly copy the data out of a CCITT Group 4 encoded TIFF, if it
|
||||||
# only contains a single strip
|
# only contains a single strip
|
||||||
if imgformat == ImageFormat.TIFF \
|
if imgformat == ImageFormat.TIFF \
|
||||||
|
@ -878,7 +902,6 @@ def read_images(rawdata, colorspace, first_frame_only=False):
|
||||||
offset, length = ccitt_payload_location_from_pil(imgdata)
|
offset, length = ccitt_payload_location_from_pil(imgdata)
|
||||||
im.seek(offset)
|
im.seek(offset)
|
||||||
rawdata = im.read(length)
|
rawdata = im.read(length)
|
||||||
im.close()
|
|
||||||
fillorder = imgdata.tag_v2.get(TiffImagePlugin.FILLORDER)
|
fillorder = imgdata.tag_v2.get(TiffImagePlugin.FILLORDER)
|
||||||
if fillorder is None:
|
if fillorder is None:
|
||||||
# no FillOrder: nothing to do
|
# no FillOrder: nothing to do
|
||||||
|
@ -896,22 +919,10 @@ def read_images(rawdata, colorspace, first_frame_only=False):
|
||||||
else:
|
else:
|
||||||
raise ValueError("unsupported FillOrder: %d" % fillorder)
|
raise ValueError("unsupported FillOrder: %d" % fillorder)
|
||||||
logging.debug("read_images() embeds a TIFF")
|
logging.debug("read_images() embeds a TIFF")
|
||||||
return [(color, ndpi, ImageFormat.CCITTGroup4, rawdata, imgwidthpx,
|
result.append((color, ndpi, ImageFormat.CCITTGroup4, rawdata,
|
||||||
imgheightpx, [], inverted)]
|
imgwidthpx, imgheightpx, [], inverted))
|
||||||
|
img_page_count += 1
|
||||||
# Everything else has to be encoded
|
continue
|
||||||
|
|
||||||
result = []
|
|
||||||
img_page_count = 0
|
|
||||||
# loop through all frames of the image (example: multipage TIFF)
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
imgdata.seek(img_page_count)
|
|
||||||
except EOFError:
|
|
||||||
break
|
|
||||||
|
|
||||||
if first_frame_only and img_page_count > 0:
|
|
||||||
break
|
|
||||||
|
|
||||||
logging.debug("Converting frame: %d" % img_page_count)
|
logging.debug("Converting frame: %d" % img_page_count)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue