-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#2790 + tests #2898
Merged
Merged
#2790 + tests #2898
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1cf2deb
Fix #2782
stuxcrystal 1ea128c
refactor out get_chunks
wiredfool 25d9612
Added sRGB and cHRM chunks to PngInfo, added tests for #2782
wiredfool a96ac32
merge error
wiredfool e5ff9db
typo
wiredfool 03150c2
docs for new info items
wiredfool 27bc13d
typos
wiredfool File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -387,12 +387,31 @@ def chunk_tRNS(self, pos, length): | |
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 colorimetric | ||
# 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 | ||
|
@@ -731,7 +750,9 @@ def _save(im, fp, filename, chunk=putchunk): | |
name = b"ICC Profile" | ||
data = name + b"\0\0" + zlib.compress(icc) | ||
chunk(fp, b"iCCP", data) | ||
else: | ||
|
||
# You must either have sRGB or iCCP. | ||
# Disallow sRGB chunks when a iCCP-chunk has been emitted. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> "when an iCCP-chunk" |
||
chunks.remove(b"sRGB") | ||
|
||
info = im.encoderinfo.get("pnginfo") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -408,9 +408,22 @@ PIL identifies, reads, and writes PNG files containing ``1``, ``L``, ``P``, | |
The :py:meth:`~PIL.Image.Image.open` method sets the following | ||
:py:attr:`~PIL.Image.Image.info` properties, when appropriate: | ||
|
||
**chromaticity** | ||
The chromaticity points, as an 8 tuple of floats. (``White Point | ||
X``, ``White Point Y``, ``Red X``, ``Red Y``, ``Green X``, ``Green | ||
Y``, ``Blue X``, ``Blue Y``) | ||
|
||
**gamma** | ||
Gamma, given as a floating point number. | ||
|
||
**srgb** | ||
The sRGB rendering intent as a integer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> "as an integer" |
||
|
||
* 0 Perceptual | ||
* 1 Relative Colorimetric | ||
* 2 Saturation | ||
* 3 Absolute Colorimetric | ||
|
||
**transparency** | ||
For ``P`` images: Either the palette index for full transparent pixels, | ||
or a byte string with alpha values for each palette entry. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"100000" -> "100,000" or "100 000"