mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
MM and II 16 bit integer tiffs pack/write properly using libtiff on bigendian platform
This commit is contained in:
parent
6f8d968cbb
commit
3128a76495
|
@ -1040,6 +1040,14 @@ def _save(im, fp, filename):
|
|||
pass
|
||||
if Image.DEBUG:
|
||||
print (atts)
|
||||
|
||||
# libtiff always returns the bytes in native order.
|
||||
# we're expecting image byte order. So, if the rawmode
|
||||
# contains I;16, we need to convert from native to image
|
||||
# byte order.
|
||||
if im.mode in ('I;16B', 'I;16'):
|
||||
rawmode = 'I;16N'
|
||||
|
||||
a = (rawmode, compression, _fp, filename, atts)
|
||||
e = Image._getencoder(im.mode, compression, a, im.encoderconfig)
|
||||
e.setimage(im.im, (0,0)+im.size)
|
||||
|
|
|
@ -115,6 +115,16 @@ def test_little_endian():
|
|||
assert_equal(b[0], b'\xe0')
|
||||
assert_equal(b[1], b'\x01')
|
||||
|
||||
out = tempfile("temp.tif")
|
||||
out = "temp.le.tif"
|
||||
im.save(out)
|
||||
reread = Image.open(out)
|
||||
|
||||
assert_equal(reread.info['compression'], im.info['compression'])
|
||||
assert_equal(reread.getpixel((0,0)), 480)
|
||||
# UNDONE - libtiff defaults to writing in native endian, so
|
||||
# on big endian, we'll get back mode = 'I;16B' here.
|
||||
|
||||
def test_big_endian():
|
||||
im = Image.open('Tests/images/12bit.MM.deflate.tif')
|
||||
|
||||
|
@ -127,3 +137,10 @@ def test_big_endian():
|
|||
assert_equal(b[0], b'\x01')
|
||||
assert_equal(b[1], b'\xe0')
|
||||
|
||||
out = tempfile("temp.tif")
|
||||
im.save(out)
|
||||
reread = Image.open(out)
|
||||
|
||||
assert_equal(reread.info['compression'], im.info['compression'])
|
||||
assert_equal(reread.getpixel((0,0)), 480)
|
||||
|
||||
|
|
|
@ -361,6 +361,27 @@ packI16B(UINT8* out, const UINT8* in_, int pixels)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
packI16N_I16B(UINT8* out, const UINT8* in, int pixels){
|
||||
int i;
|
||||
UINT8* tmp = (UINT8*) in;
|
||||
for (i = 0; i < pixels; i++) {
|
||||
C16B;
|
||||
out += 2; tmp += 2;
|
||||
}
|
||||
|
||||
}
|
||||
static void
|
||||
packI16N_I16(UINT8* out, const UINT8* in, int pixels){
|
||||
int i;
|
||||
UINT8* tmp = (UINT8*) in;
|
||||
for (i = 0; i < pixels; i++) {
|
||||
C16L;
|
||||
out += 2; tmp += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
packI32S(UINT8* out, const UINT8* in, int pixels)
|
||||
{
|
||||
|
@ -560,6 +581,9 @@ static struct {
|
|||
{"I;16", "I;16", 16, copy2},
|
||||
{"I;16B", "I;16B", 16, copy2},
|
||||
{"I;16L", "I;16L", 16, copy2},
|
||||
{"I;16", "I;16N", 16, packI16N_I16}, // LibTiff native->image endian.
|
||||
{"I;16L", "I;16N", 16, packI16N_I16},
|
||||
{"I;16B", "I;16N", 16, packI16N_I16B},
|
||||
{"BGR;15", "BGR;15", 16, copy2},
|
||||
{"BGR;16", "BGR;16", 16, copy2},
|
||||
{"BGR;24", "BGR;24", 24, copy3},
|
||||
|
|
Loading…
Reference in New Issue
Block a user