mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 18:36:17 +03:00
Added sRGB and cHRM chunks to PngInfo, added tests for #2782
This commit is contained in:
parent
1ea128c8a7
commit
25d961238c
|
@ -387,12 +387,31 @@ class PngStream(ChunkStream):
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def chunk_gAMA(self, pos, length):
|
def chunk_gAMA(self, pos, length):
|
||||||
|
|
||||||
# gamma setting
|
# gamma setting
|
||||||
s = ImageFile._safe_read(self.fp, length)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
self.im_info["gamma"] = i32(s) / 100000.0
|
self.im_info["gamma"] = i32(s) / 100000.0
|
||||||
return s
|
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):
|
def chunk_pHYs(self, pos, length):
|
||||||
|
|
||||||
# pixels per unit
|
# pixels per unit
|
||||||
|
|
|
@ -53,8 +53,7 @@ class TestFilePng(PillowTestCase):
|
||||||
chunks = []
|
chunks = []
|
||||||
with open(filename, "rb") as fp:
|
with open(filename, "rb") as fp:
|
||||||
fp.read(8)
|
fp.read(8)
|
||||||
png = PngImagePlugin.PngStream(fp)
|
while PngImagePlugin.PngStream(fp) as png:
|
||||||
while True:
|
|
||||||
cid, pos, length = png.read()
|
cid, pos, length = png.read()
|
||||||
chunks.append(cid)
|
chunks.append(cid)
|
||||||
try:
|
try:
|
||||||
|
@ -516,22 +515,7 @@ class TestFilePng(PillowTestCase):
|
||||||
test_file = self.tempfile("temp.png")
|
test_file = self.tempfile("temp.png")
|
||||||
im.convert("P").save(test_file, dpi=(100, 100))
|
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)
|
chunks = self.get_chunks(test_file)
|
||||||
>>>>>>> refactor out get_chunks
|
|
||||||
|
|
||||||
# https://www.w3.org/TR/PNG/#5ChunkOrdering
|
# https://www.w3.org/TR/PNG/#5ChunkOrdering
|
||||||
# IHDR - shall be first
|
# IHDR - shall be first
|
||||||
|
|
Loading…
Reference in New Issue
Block a user