src/img2pdf.py: work around PIL not reporting a colorspace for 16bit grayscale PNGs
This commit is contained in:
parent
ccca845606
commit
c0ed810036
1 changed files with 10 additions and 1 deletions
|
@ -688,7 +688,16 @@ def get_imgmetadata(imgdata, imgformat, default_dpi, colorspace, rawdata=None):
|
||||||
if c.name == ics:
|
if c.name == ics:
|
||||||
color = c
|
color = c
|
||||||
if color is None:
|
if color is None:
|
||||||
color = Colorspace.other
|
# PIL does not provide the information about the original
|
||||||
|
# colorspace for 16bit grayscale PNG images. Thus, we retrieve
|
||||||
|
# that info manually by looking at byte 10 in the IHDR chunk. We
|
||||||
|
# know where to find that in the file because the IHDR chunk must
|
||||||
|
# be the first chunk
|
||||||
|
if rawdata is not None and imgformat == ImageFormat.PNG \
|
||||||
|
and rawdata[25] == 0:
|
||||||
|
color = Colorspace.L
|
||||||
|
else:
|
||||||
|
raise ValueError("unknown colorspace")
|
||||||
if color == Colorspace.CMYK and imgformat == ImageFormat.JPEG:
|
if color == Colorspace.CMYK and imgformat == ImageFormat.JPEG:
|
||||||
# Adobe inverts CMYK JPEGs for some reason, and others
|
# Adobe inverts CMYK JPEGs for some reason, and others
|
||||||
# have followed suit as well. Some software assumes the
|
# have followed suit as well. Some software assumes the
|
||||||
|
|
Loading…
Reference in a new issue