Skip to content

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
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