-
-
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
Added reading DDS BGR;15 images #7574
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -148,15 +148,17 @@ def _open(self): | |||||
self.tile = [("raw", (0, 0) + self.size, 0, (self.mode, 0, 1))] | ||||||
elif pfflags & DDPF_RGB: | ||||||
# Texture contains uncompressed RGB data | ||||||
masks = {mask: ["R", "G", "B", "A"][i] for i, mask in enumerate(masks)} | ||||||
rawmode = "" | ||||||
if pfflags & DDPF_ALPHAPIXELS: | ||||||
rawmode += masks[0xFF000000] | ||||||
else: | ||||||
if not pfflags & DDPF_ALPHAPIXELS: | ||||||
self._mode = "RGB" | ||||||
rawmode += masks[0xFF0000] + masks[0xFF00] + masks[0xFF] | ||||||
if masks[:3] == (31744, 992, 31) and self.mode == "RGB": | ||||||
rawmode = "BGR;15" | ||||||
else: | ||||||
masks = {mask: ["R", "G", "B", "A"][i] for i, mask in enumerate(masks)} | ||||||
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.
Suggested change
would be more efficient, since the (possibly-mutable-but-the-interpreter-can't-tell) list doesn't need to regenerated for every call of this function, but it could use the same 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. I've added a version of this. |
||||||
rawmode = masks[0xFF] + masks[0xFF00] + masks[0xFF0000] | ||||||
if self.mode == "RGBA": | ||||||
rawmode += masks[0xFF000000] | ||||||
|
||||||
self.tile = [("raw", (0, 0) + self.size, 0, (rawmode[::-1], 0, 1))] | ||||||
self.tile = [("raw", (0, 0) + self.size, 0, (rawmode, 0, 1))] | ||||||
elif pfflags & DDPF_PALETTEINDEXED8: | ||||||
self._mode = "P" | ||||||
self.palette = ImagePalette.raw("RGBA", self.fp.read(1024)) | ||||||
|
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.
The magic numbers here could use some explanation if you ask me.
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 know what you're said sounds like a perfectly straightforward request, but I can't think of a short way to explain it that isn't just explaining what masks are, or what BGR;15 is.
There are 4 bit masks - https://learn.microsoft.com/en-us/windows/win32/direct3ddds/dds-pixelformat - R, G, B and A.
Each mask filters the pixel values to transform them into the value for each channel.
These masks are filtering 5 bits for R, 5 bits for G and 5 bits for B - BGR;15.
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.
That looks like great material for a code comment right there :)
You could also replace the decimal constants with those binary constants – then it's immediately more clear for a reader.
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.
Clearer, yes, it just feels verbose... I've pushed a commit.