Skip to content
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

Fixed I;16 conversion on big endian #5900

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions Tests/test_file_png.py
Expand Up @@ -13,7 +13,6 @@
assert_image_equal,
assert_image_equal_tofile,
hopper,
is_big_endian,
is_win32,
mark_if_feature_version,
skip_unless_feature,
Expand Down Expand Up @@ -77,7 +76,6 @@ def get_chunks(self, filename):
png.crc(cid, s)
return chunks

@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
def test_sanity(self, tmp_path):

# internal version number
Expand Down
7 changes: 7 additions & 0 deletions src/libImaging/Convert.c
Expand Up @@ -963,10 +963,17 @@ static struct {

{"HSV", "RGB", hsv2rgb},

#ifdef WORDS_BIGENDIAN
{"I", "I;16", I_I16B},
{"I;16", "I", I16B_I},
{"L", "I;16", L_I16B},
{"I;16", "L", I16B_L},
#else
{"I", "I;16", I_I16L},
{"I;16", "I", I16L_I},
{"L", "I;16", L_I16L},
{"I;16", "L", I16L_L},
#endif

{"I", "I;16L", I_I16L},
{"I;16L", "I", I16L_I},
Expand Down
14 changes: 2 additions & 12 deletions src/libImaging/GetBBox.c
Expand Up @@ -181,21 +181,11 @@ ImagingGetExtrema(Imaging im, void *extrema) {
case IMAGING_TYPE_SPECIAL:
if (strcmp(im->mode, "I;16") == 0) {
UINT16 v;
UINT8 *pixel = *im->image8;
#ifdef WORDS_BIGENDIAN
v = pixel[0] + (pixel[1] << 8);
#else
memcpy(&v, pixel, sizeof(v));
#endif
memcpy(&v, *im->image8, sizeof(v));
imin = imax = v;
for (y = 0; y < im->ysize; y++) {
for (x = 0; x < im->xsize; x++) {
pixel = (UINT8 *)im->image[y] + x * sizeof(v);
#ifdef WORDS_BIGENDIAN
v = pixel[0] + (pixel[1] << 8);
#else
memcpy(&v, pixel, sizeof(v));
#endif
memcpy(&v, im->image[y] + x * sizeof(v), sizeof(v));
if (imin > v) {
imin = v;
} else if (imax < v) {
Expand Down