Skip to content

Use correct bands for two band histograms #9054

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
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

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.

Image.histogram() gives wrong result on images of mode "LA"
1 participant