Skip to content

Commit

Permalink
Added RGB*;16N Unpackers
Browse files Browse the repository at this point in the history
  • Loading branch information
wiredfool committed Dec 20, 2017
1 parent c816932 commit 768668c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion PIL/TiffImagePlugin.py
Expand Up @@ -1278,8 +1278,13 @@ def _setup(self):
# we're expecting image byte order. So, if the rawmode
# contains I;16, we need to convert from native to image
# byte order.
if self.mode in ('I;16B', 'I;16') and 'I;16' in rawmode:
if rawmode == 'I;16':
rawmode = 'I;16N'
if '16B' in rawmode:
rawmode = rawmode.replace('16B', '16N')
if '16L' in rawmode:
rawmode = rawmode.replace('16L', '16N')


# Offset in the tile tuple is 0, we go from 0,0 to
# w,h, and we only do this once -- eds
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_libtiff.py
Expand Up @@ -577,7 +577,7 @@ def test_16bit_RGBa_tiff(self):

self.assertEqual(im.mode, "RGBA")
self.assertEqual(im.size, (100, 40))
self.assertEqual(im.tile, [('tiff_lzw', (0, 0, 100, 40), 0, ('RGBa;16B', 'tiff_lzw', False))])
self.assertEqual(im.tile, [('tiff_lzw', (0, 0, 100, 40), 0, ('RGBa;16N', 'tiff_lzw', False))])
im.load()

self.assert_image_equal_tofile(im, "Tests/images/tiff_16bit_RGBa_target.png")
Expand Down
13 changes: 13 additions & 0 deletions libImaging/Unpack.c
Expand Up @@ -1301,6 +1301,19 @@ static struct {
{"RGBA", "B", 8, band2},
{"RGBA", "A", 8, band3},

#ifdef WORDS_BIGENDIAN
{"RGB", "RGB;16N", 64, unpackRGB16B},
{"RGBA", "RGBa;16N", 64, unpackRGBa16B},
{"RGBA", "RGBA;16N", 64, unpackRGBA16B},
{"RGBX", "RGBX;16N", 64, unpackRGBA16B},
#else
{"RGB", "RGB;16N", 64, unpackRGB16L},
{"RGBA", "RGBa;16N", 64, unpackRGBa16L},
{"RGBA", "RGBA;16N", 64, unpackRGBA16L},
{"RGBX", "RGBX;16N", 64, unpackRGBA16B},
#endif


/* true colour w. alpha premultiplied */
{"RGBa", "RGBa", 32, copy4},
{"RGBa", "BGRa", 32, unpackBGRA},
Expand Down

0 comments on commit 768668c

Please sign in to comment.