Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improved BCn overflow check #9043

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

Open
radarhere wants to merge 1 commit into python-pillow:main
base: main
Choose a base branch
Loading
from radarhere:bcn
Open

Conversation

Copy link
Member

@radarhere radarhere commented Jun 27, 2025

While checking for BCn overflow, dst is advanced by 8 bytes every loop.

It is advanced by an additional 8 bytes under these conditions in the code.

if (n == 5) {
 ...
 dst += 8;
 ...
} else {
 if (n == 2 || n == 3) {
 if (has_alpha_channel) {
 ...
 dst += 8;
 } else {
 for (int i = 0; i < 8; i++) {
 *dst++ = ...;
 }
 }
 }

So when n is 1, it is only advanced by 8 each loop, not 16. In format terms, this is DXT1, also known as BC1.

https://learn.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-block-compression#bc2

BC1
...
the BC1 format reduces the memory required from 48 bytes (16 colors ×ばつ 3 components/color ×ばつ 1 byte/component) to 8 bytes of memory.
...
BC2
...
this compression technique reduces the memory required from 64 bytes (16 colors ×ばつ 4 components/color ×ばつ 1 byte/component) to 16 bytes of memory.
...
BC3
...
this compression technique reduces the memory required from 64 bytes (16 colors ×ばつ 4 components/color ×ばつ 1 byte/component) to 16 bytes of memory.
...
BC5
...
this compression technique reduces the memory required from 32 bytes (16 colors ×ばつ 2 components/color ×ばつ 1 byte/component) to 16 bytes.

This means we can change the check to look for 8 bytes if n is 1, rather than 16 bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /