mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-18 19:24:47 +03:00
Fixed reading 10-bit PGM
This commit is contained in:
parent
38f4660d9e
commit
72b738768b
BIN
Tests/images/10_bit_binary.pgm
Normal file
BIN
Tests/images/10_bit_binary.pgm
Normal file
Binary file not shown.
BIN
Tests/images/10_bit_binary_pgm.png
Normal file
BIN
Tests/images/10_bit_binary_pgm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -20,6 +20,16 @@ def test_sanity():
|
|||
assert im.get_format_mimetype() == "image/x-portable-pixmap"
|
||||
|
||||
|
||||
def test_10bit_pgm():
|
||||
with Image.open("Tests/images/10_bit_binary.pgm") as im:
|
||||
im.load()
|
||||
assert im.mode == "I"
|
||||
assert im.size == (128, 128)
|
||||
assert im.get_format_mimetype() == "image/x-portable-graymap"
|
||||
|
||||
assert_image_equal_tofile(im, "Tests/images/10_bit_binary_pgm.png")
|
||||
|
||||
|
||||
def test_16bit_pgm():
|
||||
with Image.open("Tests/images/16_bit_binary.pgm") as im:
|
||||
im.load()
|
||||
|
|
|
@ -113,9 +113,12 @@ class PpmImageFile(ImageFile.ImageFile):
|
|||
elif ix == 2: # token is maxval
|
||||
maxval = token
|
||||
if maxval > 255:
|
||||
if not mode == "L":
|
||||
if mode != "L":
|
||||
raise ValueError(f"Too many colors for band: {token}")
|
||||
if maxval < 2**16:
|
||||
if maxval == 1023:
|
||||
self.mode = "I"
|
||||
rawmode = "I;10B"
|
||||
elif maxval < 2**16:
|
||||
self.mode = "I"
|
||||
rawmode = "I;16B"
|
||||
else:
|
||||
|
|
|
@ -1182,6 +1182,23 @@ unpackI12_I16(UINT8 *out, const UINT8 *in, int pixels) {
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unpackI10B(UINT8 *out, const UINT8 *in, int pixels) {
|
||||
int i, pixel;
|
||||
for (i = 0; i < pixels; i++) {
|
||||
pixel = ((in[0] << 8) + in[1]) << 6;
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
out[2] = pixel >> 8;
|
||||
out[3] = pixel;
|
||||
#else
|
||||
out[0] = pixel;
|
||||
out[1] = pixel >> 8;
|
||||
#endif
|
||||
in += 2;
|
||||
out += 4;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
copy1(UINT8 *out, const UINT8 *in, int pixels) {
|
||||
/* L, P */
|
||||
|
@ -1684,6 +1701,7 @@ static struct {
|
|||
{"I", "I", 32, copy4},
|
||||
{"I", "I;8", 8, unpackI8},
|
||||
{"I", "I;8S", 8, unpackI8S},
|
||||
{"I", "I;10B", 16, unpackI10B},
|
||||
{"I", "I;16", 16, unpackI16},
|
||||
{"I", "I;16S", 16, unpackI16S},
|
||||
{"I", "I;16B", 16, unpackI16B},
|
||||
|
|
Loading…
Reference in New Issue
Block a user