Skip to content

Commit f7ec22f

Browse files
authored
Merge pull request #6197 from radarhere/endian
Fixed behaviour change from endian fix
2 parents 31b98bb + 950d0ad commit f7ec22f

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Tests/images/issue_6194.j2k

318 Bytes
Binary file not shown.

Tests/test_file_jpeg2k.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ def test_16bit_jp2_roundtrips():
298298
assert_image_equal(im, jp2)
299299

300300

301+
def test_issue_6194():
302+
with Image.open("Tests/images/issue_6194.j2k") as im:
303+
assert im.getpixel((5, 5)) == 31
304+
305+
301306
def test_unbound_local():
302307
# prepatch, a malformed jp2 file could cause an UnboundLocalError exception.
303308
with pytest.raises(OSError):

src/libImaging/Jpeg2KDecode.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,13 @@ j2ku_gray_i(
180180
case 2:
181181
for (y = 0; y < h; ++y) {
182182
const UINT16 *data = (const UINT16 *)&tiledata[2 * y * w];
183-
UINT8 *row = (UINT8 *)im->image[y0 + y] + x0;
183+
UINT16 *row = (UINT16 *)im->image[y0 + y] + x0;
184184
for (x = 0; x < w; ++x) {
185185
UINT16 pixel = j2ku_shift(offset + *data++, shift);
186+
#ifdef WORDS_BIGENDIAN
187+
pixel = (pixel >> 8) | (pixel << 8);
188+
#endif
186189
*row++ = pixel;
187-
*row++ = pixel >> 8;
188190
}
189191
}
190192
break;

0 commit comments

Comments
 (0)