Skip to content

Commit

Permalink
Merge pull request #6132 from radarhere/fillorder
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Mar 26, 2022
2 parents b624aaf + ebdb47e commit 8107098
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Binary file added Tests/images/16bit.r.tif
Binary file not shown.
9 changes: 9 additions & 0 deletions Tests/test_file_tiff.py
Expand Up @@ -225,6 +225,15 @@ def test_big_endian(self):
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()
Expand Down
1 change: 1 addition & 0 deletions src/PIL/TiffImagePlugin.py
Expand Up @@ -175,6 +175,7 @@
(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"),
Expand Down
12 changes: 12 additions & 0 deletions src/libImaging/Unpack.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 8107098

Please sign in to comment.