Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Tests/test_file_jpeg2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
assert_image_equal,
assert_image_similar,
assert_image_similar_tofile,
is_big_endian,
skip_unless_feature,
)

Expand Down Expand Up @@ -234,13 +233,11 @@ def test_16bit_monochrome_has_correct_mode():
assert jp2.mode == "I;16"


@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
def test_16bit_monochrome_jp2_like_tiff():
with Image.open("Tests/images/16bit.cropped.tif") as tiff_16bit:
assert_image_similar_tofile(tiff_16bit, "Tests/images/16bit.cropped.jp2", 1e-3)


@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
def test_16bit_monochrome_j2k_like_tiff():
with Image.open("Tests/images/16bit.cropped.tif") as tiff_16bit:
assert_image_similar_tofile(tiff_16bit, "Tests/images/16bit.cropped.j2k", 1e-3)
Expand Down
2 changes: 0 additions & 2 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
assert_image_equal,
assert_image_equal_tofile,
hopper,
is_big_endian,
is_win32,
mark_if_feature_version,
skip_unless_feature,
Expand Down Expand Up @@ -77,7 +76,6 @@ def get_chunks(self, filename):
png.crc(cid, s)
return chunks

@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
def test_sanity(self, tmp_path):

# internal version number
Expand Down
6 changes: 4 additions & 2 deletions src/libImaging/Jpeg2KDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ j2ku_gray_i(
case 2:
for (y = 0; y < h; ++y) {
const UINT16 *data = (const UINT16 *)&tiledata[2 * y * w];
UINT16 *row = (UINT16 *)im->image[y0 + y] + x0;
UINT8 *row = (UINT8 *)im->image[y0 + y] + x0;
for (x = 0; x < w; ++x) {
*row++ = j2ku_shift(offset + *data++, shift);
UINT16 pixel = j2ku_shift(offset + *data++, shift);
*row++ = pixel;
*row++ = pixel >> 8;
}
}
break;
Expand Down
19 changes: 10 additions & 9 deletions src/libImaging/Jpeg2KEncode.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,15 @@ j2k_pack_i16(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsig
for (y = 0; y < h; ++y) {
UINT8 *data = (UINT8 *)(im->image[y + y0] + x0);
for (x = 0; x < w; ++x) {
*ptr++ = *data++;
*ptr++ = *data++;
#ifdef WORDS_BIGENDIAN
ptr[0] = data[1];
ptr[1] = data[0];
#else
ptr[0] = data[0];
ptr[1] = data[1];
#endif
ptr += 2;
data += 2;
}
}
}
Expand Down Expand Up @@ -301,13 +308,7 @@ j2k_encode_entry(Imaging im, ImagingCodecState state) {
components = 1;
color_space = OPJ_CLRSPC_GRAY;
pack = j2k_pack_l;
} else if (strcmp(im->mode, "I;16") == 0) {
components = 1;
color_space = OPJ_CLRSPC_GRAY;
pack = j2k_pack_i16;
prec = 16;
bpp = 12;
} else if (strcmp(im->mode, "I;16B") == 0) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a functional change, it's just cleaning up some duplicate code.

} else if (strcmp(im->mode, "I;16") == 0 || strcmp(im->mode, "I;16B") == 0) {
components = 1;
color_space = OPJ_CLRSPC_GRAY;
pack = j2k_pack_i16;
Expand Down
4 changes: 4 additions & 0 deletions src/libImaging/Pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,11 @@ static struct {

/* storage modes */
{"I;16", "I;16", 16, copy2},
#ifdef WORDS_BIGENDIAN
{"I;16", "I;16B", 16, packI16N_I16},
#else
{"I;16", "I;16B", 16, packI16N_I16B},
#endif
{"I;16B", "I;16B", 16, copy2},
{"I;16L", "I;16L", 16, copy2},
{"I;16", "I;16N", 16, packI16N_I16}, // LibTiff native->image endian.
Expand Down