Added sRGB and cHRM chunks to PngInfo, added tests for #2782

This commit is contained in:
Eric Soroos 2017-12-20 11:28:50 +00:00
parent 1ea128c8a7
commit 25d961238c
2 changed files with 21 additions and 18 deletions

View File

@ -387,12 +387,31 @@ class PngStream(ChunkStream):
return s
def chunk_gAMA(self, pos, length):
# gamma setting
s = ImageFile._safe_read(self.fp, length)
self.im_info["gamma"] = i32(s) / 100000.0
return s
def chunk_cHRM(self, pos, length):
# chromaticity, 8 unsigned ints, actual value is scaled by 100000
# WP x,y, Red x,y, Green x,y Blue x,y
s = ImageFile._safe_read(self.fp, length)
raw_vals = struct.unpack('>%dI' % (len(s) // 4), s)
self.im_info['chromaticity'] = tuple(elt/100000.0 for elt in raw_vals)
return s
def chunk_sRGB(self, pos, length):
# srgb rendering intent, 1 byte
# 0 perceptual
# 1 relative folorimetric
# 2 saturation
# 3 absolute colorimetric
s = ImageFile._safe_read(self.fp, length)
self.im_info['srgb'] = i8(s)
return s
def chunk_pHYs(self, pos, length):
# pixels per unit

View File

@ -53,8 +53,7 @@ class TestFilePng(PillowTestCase):
chunks = []
with open(filename, "rb") as fp:
fp.read(8)
png = PngImagePlugin.PngStream(fp)
while True:
while PngImagePlugin.PngStream(fp) as png:
cid, pos, length = png.read()
chunks.append(cid)
try:
@ -516,22 +515,7 @@ class TestFilePng(PillowTestCase):
test_file = self.tempfile("temp.png")
im.convert("P").save(test_file, dpi=(100, 100))
<<<<<<< 1cf2deba3bdb3ea93fdd859c0f052dfcea898c52
chunks = []
with open(test_file, "rb") as fp:
fp.read(8)
with PngImagePlugin.PngStream(fp) as png:
while True:
cid, pos, length = png.read()
chunks.append(cid)
try:
s = png.call(cid, pos, length)
except EOFError:
break
png.crc(cid, s)
=======
chunks = self.get_chunks(test_file)
>>>>>>> refactor out get_chunks
# https://www.w3.org/TR/PNG/#5ChunkOrdering
# IHDR - shall be first