Skip to content

Conversation

@radarhere
Copy link
Member

Resolves #9050

For an image32 image without a mask, histogram values are generated with

h->histogram[(*in++)]++;
h->histogram[(*in++) + 256]++;
h->histogram[(*in++) + 512]++;
h->histogram[(*in++) + 768]++;

However, this doesn't consider that some images (PA, LA and La) only have two bands

} else if (strcmp(mode, "PA") == 0) {
/* 8-bit palette with alpha */
im->bands = 2;

Pillow/src/_imaging.c

Lines 1360 to 1361 in 37cd041

/* Build an integer list containing the histogram */
list = PyList_New(h->bands * 256);

meaning that two band histograms only have 512 values, rather than 1024. So this PR skips the middle two bands when assigning values.

@hugovk hugovk merged commit 162836a into python-pillow:main Jul 31, 2025
59 checks passed
@radarhere radarhere deleted the histogram branch July 31, 2025 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants