Merge pull request #6197 from radarhere/endian

Fixed behaviour change from endian fix
This commit is contained in:
Hugo van Kemenade 2022-06-10 19:02:54 +03:00 committed by GitHub
commit f7ec22f518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

BIN
Tests/images/issue_6194.j2k Normal file

Binary file not shown.

View File

@ -298,6 +298,11 @@ def test_16bit_jp2_roundtrips():
assert_image_equal(im, jp2)
def test_issue_6194():
with Image.open("Tests/images/issue_6194.j2k") as im:
assert im.getpixel((5, 5)) == 31
def test_unbound_local():
# prepatch, a malformed jp2 file could cause an UnboundLocalError exception.
with pytest.raises(OSError):

View File

@ -180,11 +180,13 @@ j2ku_gray_i(
case 2:
for (y = 0; y < h; ++y) {
const UINT16 *data = (const UINT16 *)&tiledata[2 * y * w];
UINT8 *row = (UINT8 *)im->image[y0 + y] + x0;
UINT16 *row = (UINT16 *)im->image[y0 + y] + x0;
for (x = 0; x < w; ++x) {
UINT16 pixel = j2ku_shift(offset + *data++, shift);
#ifdef WORDS_BIGENDIAN
pixel = (pixel >> 8) | (pixel << 8);
#endif
*row++ = pixel;
*row++ = pixel >> 8;
}
}
break;