Merge pull request #6132 from radarhere/fillorder

This commit is contained in:
Hugo van Kemenade 2022-03-26 19:47:14 +02:00 committed by GitHub
commit 8107098657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 0 deletions

BIN
Tests/images/16bit.r.tif Normal file

Binary file not shown.

View File

@ -225,6 +225,15 @@ class TestFileTiff:
assert b[0] == ord(b"\x01")
assert b[1] == ord(b"\xe0")
def test_16bit_r(self):
with Image.open("Tests/images/16bit.r.tif") as im:
assert im.getpixel((0, 0)) == 480
assert im.mode == "I;16"
b = im.tobytes()
assert b[0] == ord(b"\xe0")
assert b[1] == ord(b"\x01")
def test_16bit_s(self):
with Image.open("Tests/images/16bit.s.tif") as im:
im.load()

View File

@ -175,6 +175,7 @@ OPEN_INFO = {
(II, 1, (1,), 1, (12,), ()): ("I;16", "I;12"),
(II, 1, (1,), 1, (16,), ()): ("I;16", "I;16"),
(MM, 1, (1,), 1, (16,), ()): ("I;16B", "I;16B"),
(II, 1, (1,), 2, (16,), ()): ("I;16", "I;16R"),
(II, 1, (2,), 1, (16,), ()): ("I", "I;16S"),
(MM, 1, (2,), 1, (16,), ()): ("I", "I;16BS"),
(II, 0, (3,), 1, (32,), ()): ("F", "F;32F"),

View File

@ -1124,6 +1124,16 @@ unpackI16N_I16(UINT8 *out, const UINT8 *in, int pixels) {
tmp += 2;
}
}
static void
unpackI16R_I16(UINT8 *out, const UINT8 *in, int pixels) {
int i;
for (i = 0; i < pixels; i++) {
out[0] = BITFLIP[in[0]];
out[1] = BITFLIP[in[1]];
in += 2;
out += 2;
}
}
static void
unpackI12_I16(UINT8 *out, const UINT8 *in, int pixels) {
@ -1731,6 +1741,8 @@ static struct {
{"I;16L", "I;16N", 16, unpackI16N_I16}, // LibTiff native->image endian.
{"I;16B", "I;16N", 16, unpackI16N_I16B},
{"I;16", "I;16R", 16, unpackI16R_I16},
{"I;16", "I;12", 12, unpackI12_I16}, // 12 bit Tiffs stored in 16bits.
{NULL} /* sentinel */