Skip to content

Commit

Permalink
Fixed behaviour change from python-pillow#5901 endian fix
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Apr 12, 2022
1 parent a04d691 commit 950d0ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Binary file added Tests/images/issue_6194.j2k
Binary file not shown.
5 changes: 5 additions & 0 deletions Tests/test_file_jpeg2k.py
Expand Up @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions src/libImaging/Jpeg2KDecode.c
Expand Up @@ -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;
Expand Down

0 comments on commit 950d0ad

Please sign in to comment.