Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for reading I;16R TIFF images #6132

Merged
merged 1 commit into from Mar 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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