-
-
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
Support arbitrary masks for uncompressed RGB DDS images #7589
Conversation
Co-authored-by: Aarni Koskela <[email protected]>
|
||
data = bytearray() | ||
bytecount = bitcount // 8 | ||
while len(data) < self.state.xsize * self.state.ysize * len(masks): |
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.
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):
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: |
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.
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
while len(data) < self.state.xsize * self.state.ysize * bands: |
src/PIL/DdsImagePlugin.py
Outdated
value = self.fd.read(bytecount) | ||
int_value = sum(value[i] << i * 8 for i in range(bytecount)) |
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.
int.from_bytes
?
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.
Thanks, I've pushed a commit.
for more information, see https://pre-commit.ci
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.