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 behaviour change from endian fix #6197

Merged
merged 1 commit into from Jun 10, 2022
Merged
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
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