Support arbitrary masks for uncompressed RGB DDS images#7589
Merged
hugovk merged 5 commits intopython-pillow:mainfrom Dec 31, 2023
Merged
Support arbitrary masks for uncompressed RGB DDS images#7589hugovk merged 5 commits intopython-pillow:mainfrom
hugovk merged 5 commits intopython-pillow:mainfrom
Conversation
This was referenced Nov 30, 2023
akx
reviewed
Dec 1, 2023
Co-authored-by: Aarni Koskela <[email protected]>
akx
reviewed
Dec 1, 2023
|
|
||
| data = bytearray() | ||
| bytecount = bitcount // 8 | ||
| while len(data) < self.state.xsize * self.state.ysize * len(masks): |
Contributor
There was a problem hiding this comment.
Might be worth it to precalculate the total here to avoid that extra multiplication every loop (since we know the value can't possibly change):
Suggested change
| while len(data) < self.state.xsize * self.state.ysize * len(masks): | |
| total_size = self.state.xsize * self.state.ysize * len(masks) | |
| while len(data) < total_size: |
Member
Author
There was a problem hiding this comment.
I personally think the current version is simpler to read, and expect the performance difference to be negligible.
The current version is also used in a few other places in Pillow - but at the same time, that's probably because I wrote them.
Pillow/src/PIL/QoiImagePlugin.py
Line 55 in 316f397
src/PIL/DdsImagePlugin.py
Outdated
Comment on lines
261
to
262
| value = self.fd.read(bytecount) | ||
| int_value = sum(value[i] << i * 8 for i in range(bytecount)) |
Member
Author
There was a problem hiding this comment.
Thanks, I've pushed a commit.
This was referenced Dec 2, 2023
for more information, see https://pre-commit.ci
radarhere
added a commit
to radarhere/Pillow
that referenced
this pull request
Jan 1, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #7517
When DDS images contain uncompressed RGB data, they have red, green, blue (and possibly alpha) masks to filter the bits of each pixel into the final value for the channel.
Currently, Pillow only supports masks giving 8 bits per channel.
Pillow/src/PIL/DdsImagePlugin.py
Lines 150 to 157 in e1291b8
The linked issue has found an image with masks that use 5 bits per channel. So this PR adds support for arbitrary masks by adding a dedicated Python decoder.