Fixed behaviour change from #5901 endian fix

This commit is contained in:
Andrew Murray 2022-04-12 23:12:45 +10:00
parent a04d6919e1
commit 950d0ad1d3
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;