This commit is contained in:
Andrew Murray 2025-07-08 17:02:05 +00:00 committed by GitHub
commit 7741942393
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 5 deletions

View File

@ -10,9 +10,12 @@ def test_histogram() -> None:
assert histogram("1") == (256, 0, 10994) assert histogram("1") == (256, 0, 10994)
assert histogram("L") == (256, 0, 662) assert histogram("L") == (256, 0, 662)
assert histogram("LA") == (512, 0, 16384)
assert histogram("La") == (512, 0, 16384)
assert histogram("I") == (256, 0, 662) assert histogram("I") == (256, 0, 662)
assert histogram("F") == (256, 0, 662) assert histogram("F") == (256, 0, 662)
assert histogram("P") == (256, 0, 1551) assert histogram("P") == (256, 0, 1551)
assert histogram("PA") == (512, 0, 16384)
assert histogram("RGB") == (768, 4, 675) assert histogram("RGB") == (768, 4, 675)
assert histogram("RGBA") == (1024, 0, 16384) assert histogram("RGBA") == (1024, 0, 16384)
assert histogram("CMYK") == (1024, 0, 16384) assert histogram("CMYK") == (1024, 0, 16384)

View File

@ -132,11 +132,15 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void *minmax) {
ImagingSectionEnter(&cookie); ImagingSectionEnter(&cookie);
for (y = 0; y < im->ysize; y++) { for (y = 0; y < im->ysize; y++) {
UINT8 *in = (UINT8 *)im->image[y]; UINT8 *in = (UINT8 *)im->image[y];
for (x = 0; x < im->xsize; x++) { for (x = 0; x < im->xsize; x++, in += 4) {
h->histogram[(*in++)]++; h->histogram[*in]++;
h->histogram[(*in++) + 256]++; if (im->bands == 2) {
h->histogram[(*in++) + 512]++; h->histogram[*(in + 3) + 256]++;
h->histogram[(*in++) + 768]++; } else {
h->histogram[*(in + 1) + 256]++;
h->histogram[*(in + 2) + 512]++;
h->histogram[*(in + 3) + 768]++;
}
} }
} }
ImagingSectionLeave(&cookie); ImagingSectionLeave(&cookie);