mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 19:45:56 +03:00
Merge pull request #4457 from radarhere/endian
Fixed endian handling for I;16 getextrema
This commit is contained in:
commit
332e3923cb
|
@ -1,10 +1,8 @@
|
||||||
import pytest
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import hopper, is_big_endian, on_ci
|
from .helper import hopper
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(is_big_endian() and on_ci(), reason="Fails on big-endian")
|
|
||||||
def test_extrema():
|
def test_extrema():
|
||||||
def extrema(mode):
|
def extrema(mode):
|
||||||
return hopper(mode).getextrema()
|
return hopper(mode).getextrema()
|
||||||
|
@ -20,7 +18,6 @@ def test_extrema():
|
||||||
assert extrema("I;16") == (1, 255)
|
assert extrema("I;16") == (1, 255)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(is_big_endian() and on_ci(), reason="Fails on big-endian")
|
|
||||||
def test_true_16():
|
def test_true_16():
|
||||||
with Image.open("Tests/images/16_bit_noise.tif") as im:
|
with Image.open("Tests/images/16_bit_noise.tif") as im:
|
||||||
assert im.mode == "I;16"
|
assert im.mode == "I;16"
|
||||||
|
|
|
@ -177,11 +177,21 @@ ImagingGetExtrema(Imaging im, void *extrema)
|
||||||
case IMAGING_TYPE_SPECIAL:
|
case IMAGING_TYPE_SPECIAL:
|
||||||
if (strcmp(im->mode, "I;16") == 0) {
|
if (strcmp(im->mode, "I;16") == 0) {
|
||||||
UINT16 v;
|
UINT16 v;
|
||||||
memcpy(&v, *im->image8, sizeof(v));
|
UINT8* pixel = *im->image8;
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
v = pixel[0] + (pixel[1] << 8);
|
||||||
|
#else
|
||||||
|
memcpy(&v, pixel, sizeof(v));
|
||||||
|
#endif
|
||||||
imin = imax = v;
|
imin = imax = v;
|
||||||
for (y = 0; y < im->ysize; y++) {
|
for (y = 0; y < im->ysize; y++) {
|
||||||
for (x = 0; x < im->xsize; x++) {
|
for (x = 0; x < im->xsize; x++) {
|
||||||
memcpy(&v, im->image[y] + x * sizeof(v), sizeof(v));
|
pixel = im->image[y] + x * sizeof(v);
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
v = pixel[0] + (pixel[1] << 8);
|
||||||
|
#else
|
||||||
|
memcpy(&v, pixel, sizeof(v));
|
||||||
|
#endif
|
||||||
if (imin > v)
|
if (imin > v)
|
||||||
imin = v;
|
imin = v;
|
||||||
else if (imax < v)
|
else if (imax < v)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user