From aac0869ca7a5542936ed5944b789bdec6ccb14d8 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 28 Aug 2017 19:02:15 +0300 Subject: [PATCH] Revert little-endian byte order for "I" and "F" rawmodes --- Tests/test_lib_pack.py | 9 ++++++--- Tests/test_mode_i16.py | 4 +++- libImaging/Pack.c | 4 ++-- libImaging/Unpack.c | 6 ++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Tests/test_lib_pack.py b/Tests/test_lib_pack.py index b4c8b6a56..f07452de7 100644 --- a/Tests/test_lib_pack.py +++ b/Tests/test_lib_pack.py @@ -146,31 +146,34 @@ class TestLibPack(PillowTestCase): self.assert_pack("HSV", "V", 1, (9,9,1), (9,9,2), (9,9,3)) def test_I(self): - self.assert_pack("I", "I", 4, 0x04030201, 0x08070605) self.assert_pack("I", "I;16B", 2, 0x0102, 0x0304) self.assert_pack("I", "I;32S", b'\x83\x00\x00\x01\x01\x00\x00\x83', 0x01000083, -2097151999) if sys.byteorder == 'little': + self.assert_pack("I", "I", 4, 0x04030201, 0x08070605) self.assert_pack("I", "I;32NS", b'\x83\x00\x00\x01\x01\x00\x00\x83', 0x01000083, -2097151999) else: + self.assert_pack("I", "I", 4, 0x01020304, 0x05060708) self.assert_pack("I", "I;32NS", b'\x83\x00\x00\x01\x01\x00\x00\x83', -2097151999, 0x01000083) def test_F_float(self): - self.assert_pack("F", "F", 4, - 1.539989614439558e-36, 4.063216068939723e-34) self.assert_pack("F", "F;32F", 4, 1.539989614439558e-36, 4.063216068939723e-34) if sys.byteorder == 'little': + self.assert_pack("F", "F", 4, + 1.539989614439558e-36, 4.063216068939723e-34) self.assert_pack("F", "F;32NF", 4, 1.539989614439558e-36, 4.063216068939723e-34) else: + self.assert_pack("F", "F", 4, + 2.387939260590663e-38, 6.301941157072183e-36) self.assert_pack("F", "F;32NF", 4, 2.387939260590663e-38, 6.301941157072183e-36) diff --git a/Tests/test_mode_i16.py b/Tests/test_mode_i16.py index 53bbce572..d51847199 100644 --- a/Tests/test_mode_i16.py +++ b/Tests/test_mode_i16.py @@ -87,10 +87,12 @@ class TestModeI16(PillowTestCase): def tobytes(mode): return Image.new(mode, (1, 1), 1).tobytes() + order = 1 if Image._ENDIAN == '<' else -1 + self.assertEqual(tobytes("L"), b"\x01") self.assertEqual(tobytes("I;16"), b"\x01\x00") self.assertEqual(tobytes("I;16B"), b"\x00\x01") - self.assertEqual(tobytes("I"), b"\x01\x00\x00\x00") + self.assertEqual(tobytes("I"), b"\x01\x00\x00\x00"[::order]) def test_convert(self): diff --git a/libImaging/Pack.c b/libImaging/Pack.c index b9d1d6a2a..0810f51f1 100644 --- a/libImaging/Pack.c +++ b/libImaging/Pack.c @@ -599,13 +599,13 @@ static struct { {"HSV", "V", 8, band2}, /* integer */ - {"I", "I", 32, packI32S}, + {"I", "I", 32, copy4}, {"I", "I;16B", 16, packI16B}, {"I", "I;32S", 32, packI32S}, {"I", "I;32NS", 32, copy4}, /* floating point */ - {"F", "F", 32, packI32S}, + {"F", "F", 32, copy4}, {"F", "F;32F", 32, packI32S}, {"F", "F;32NF", 32, copy4}, diff --git a/libImaging/Unpack.c b/libImaging/Unpack.c index b0fba0a79..ce47a5727 100644 --- a/libImaging/Unpack.c +++ b/libImaging/Unpack.c @@ -1176,6 +1176,8 @@ static struct { endian byte order (default is little endian); "L" line interleave, "S" signed, "F" floating point */ + /* exception: rawmodes "I" and "F" are always native endian byte order */ + /* bilevel */ {"1", "1", 1, unpack1}, {"1", "1;I", 1, unpack1I}, @@ -1318,7 +1320,7 @@ static struct { {"HSV", "V", 8, band2}, /* integer variations */ - {"I", "I", 32, unpackI32}, + {"I", "I", 32, copy4}, {"I", "I;8", 8, unpackI8}, {"I", "I;8S", 8, unpackI8S}, {"I", "I;16", 16, unpackI16}, @@ -1335,7 +1337,7 @@ static struct { {"I", "I;32NS", 32, unpackI32NS}, /* floating point variations */ - {"F", "F", 32, unpackI32}, + {"F", "F", 32, copy4}, {"F", "F;8", 8, unpackF8}, {"F", "F;8S", 8, unpackF8S}, {"F", "F;16", 16, unpackF16},