Skip to content

Do not convert BC1 LUT to UINT32 #8837

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

Merged
merged 1 commit into from
Mar 27, 2025
Merged

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Mar 27, 2025

#define LOAD32(p) (p)[0] | ((p)[1] << 8) | ((p)[2] << 16) | ((p)[3] << 24)
static void
bc1_color_load(bc1_color *dst, const UINT8 *src) {
dst->c0 = LOAD16(src);
dst->c1 = LOAD16(src + 2);
dst->lut = LOAD32(src + 4);

for (n = 0; n < 16; n++) {
cw = 3 & (col.lut >> (2 * n));
dst[n] = p[cw];
}

With a little maths and changing the loop of size 16 to two range loops of size 4 each, this code can be changed to avoid the UINT32. If you think that changing the size of the loop is misleading to the reality of the image, it's not - looking at https://learn.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-block-compression#bc1, you can see that the LUT is actually representing a 4x4 block.

@radarhere radarhere merged commit fecb53b into python-pillow:main Mar 27, 2025
56 checks passed
@radarhere radarhere deleted the bcn_decode branch March 27, 2025 12:14
radarhere added a commit to radarhere/Pillow that referenced this pull request Mar 29, 2025
radarhere added a commit to radarhere/Pillow that referenced this pull request Mar 29, 2025
radarhere added a commit to radarhere/Pillow that referenced this pull request Mar 29, 2025
radarhere added a commit to radarhere/Pillow that referenced this pull request Mar 29, 2025
hugovk pushed a commit that referenced this pull request Mar 29, 2025
Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant