mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Add Tests and support for Planar Tiff Images
This commit is contained in:
parent
e405ab300b
commit
0018685a8e
BIN
Tests/images/tiff_strip_planar_16bit_RGB.tiff
Normal file
BIN
Tests/images/tiff_strip_planar_16bit_RGB.tiff
Normal file
Binary file not shown.
BIN
Tests/images/tiff_strip_planar_16bit_RGBa.tiff
Normal file
BIN
Tests/images/tiff_strip_planar_16bit_RGBa.tiff
Normal file
Binary file not shown.
BIN
Tests/images/tiff_strip_planar_lzw.tiff
Normal file
BIN
Tests/images/tiff_strip_planar_lzw.tiff
Normal file
Binary file not shown.
BIN
Tests/images/tiff_tiled_planar_16bit_RGB.tiff
Normal file
BIN
Tests/images/tiff_tiled_planar_16bit_RGB.tiff
Normal file
Binary file not shown.
BIN
Tests/images/tiff_tiled_planar_16bit_RGBa.tiff
Normal file
BIN
Tests/images/tiff_tiled_planar_16bit_RGBa.tiff
Normal file
Binary file not shown.
BIN
Tests/images/tiff_tiled_planar_lzw.tiff
Normal file
BIN
Tests/images/tiff_tiled_planar_lzw.tiff
Normal file
Binary file not shown.
|
@ -856,6 +856,52 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
with Image.open(infile) as im:
|
||||
assert_image_similar_tofile(im, "Tests/images/flower.jpg", 0.5)
|
||||
|
||||
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
|
||||
def test_strip_planar_rgb(self):
|
||||
# gdal_translate -co TILED=no -co INTERLEAVE=BAND -co COMPRESS=LZW \
|
||||
# tiff_strip_raw.tif tiff_strip_planar_lzw.tiff
|
||||
infile = "Tests/images/tiff_strip_planar_lzw.tiff"
|
||||
with Image.open(infile) as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")
|
||||
|
||||
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
|
||||
def test_tiled_planar_rgb(self):
|
||||
# gdal_translate -co TILED=yes -co INTERLEAVE=BAND -co COMPRESS=LZW \
|
||||
# tiff_tiled_raw.tif tiff_tiled_planar_lzw.tiff
|
||||
infile = "Tests/images/tiff_tiled_planar_lzw.tiff"
|
||||
with Image.open(infile) as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")
|
||||
|
||||
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
|
||||
def test_tiled_planar_16bit_RGB(self):
|
||||
# gdal_translate -co TILED=yes -co INTERLEAVE=BAND -co COMPRESS=LZW \
|
||||
# tiff_16bit_RGB.tiff tiff_tiled_planar_16bit_RGB.tiff
|
||||
with Image.open("Tests/images/tiff_tiled_planar_16bit_RGB.tiff") as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/tiff_16bit_RGB_target.png")
|
||||
|
||||
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
|
||||
def test_strip_planar_16bit_RGB(self):
|
||||
# gdal_translate -co TILED=no -co INTERLEAVE=BAND -co COMPRESS=LZW \
|
||||
# tiff_16bit_RGB.tiff tiff_strip_planar_16bit_RGB.tiff
|
||||
with Image.open("Tests/images/tiff_strip_planar_16bit_RGB.tiff") as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/tiff_16bit_RGB_target.png")
|
||||
|
||||
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
|
||||
def test_tiled_planar_16bit_RGBa(self):
|
||||
# gdal_translate -co TILED=yes \
|
||||
# -co INTERLEAVE=BAND -co COMPRESS=LZW -co ALPHA=PREMULTIPLIED \
|
||||
# tiff_16bit_RGBa.tiff tiff_tiled_planar_16bit_RGBa.tiff
|
||||
with Image.open("Tests/images/tiff_tiled_planar_16bit_RGBa.tiff") as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/tiff_16bit_RGBa_target.png")
|
||||
|
||||
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
|
||||
def test_strip_planar_16bit_RGBa(self):
|
||||
# gdal_translate -co TILED=no \
|
||||
# -co INTERLEAVE=BAND -co COMPRESS=LZW -co ALPHA=PREMULTIPLIED \
|
||||
# tiff_16bit_RGBa.tiff tiff_strip_planar_16bit_RGBa.tiff
|
||||
with Image.open("Tests/images/tiff_strip_planar_16bit_RGBa.tiff") as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/tiff_16bit_RGBa_target.png")
|
||||
|
||||
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
|
||||
def test_old_style_jpeg(self):
|
||||
infile = "Tests/images/old-style-jpeg-compression.tif"
|
||||
|
|
|
@ -320,6 +320,23 @@ class TestLibUnpack:
|
|||
self.assert_unpack("RGB", "G", 1, (0, 1, 0), (0, 2, 0), (0, 3, 0))
|
||||
self.assert_unpack("RGB", "B", 1, (0, 0, 1), (0, 0, 2), (0, 0, 3))
|
||||
|
||||
self.assert_unpack("RGB", "R;16B", 2, (1, 0, 0), (3, 0, 0), (5, 0, 0))
|
||||
self.assert_unpack("RGB", "G;16B", 2, (0, 1, 0), (0, 3, 0), (0, 5, 0))
|
||||
self.assert_unpack("RGB", "B;16B", 2, (0, 0, 1), (0, 0, 3), (0, 0, 5))
|
||||
|
||||
self.assert_unpack("RGB", "R;16L", 2, (2, 0, 0), (4, 0, 0), (6, 0, 0))
|
||||
self.assert_unpack("RGB", "G;16L", 2, (0, 2, 0), (0, 4, 0), (0, 6, 0))
|
||||
self.assert_unpack("RGB", "B;16L", 2, (0, 0, 2), (0, 0, 4), (0, 0, 6))
|
||||
|
||||
if sys.byteorder == "little":
|
||||
self.assert_unpack("RGB", "R;16N", 2, (2, 0, 0), (4, 0, 0), (6, 0, 0))
|
||||
self.assert_unpack("RGB", "G;16N", 2, (0, 2, 0), (0, 4, 0), (0, 6, 0))
|
||||
self.assert_unpack("RGB", "B;16N", 2, (0, 0, 2), (0, 0, 4), (0, 0, 6))
|
||||
else:
|
||||
self.assert_unpack("RGB", "R;16N", 2, (1, 0, 0), (3, 0, 0), (5, 0, 0))
|
||||
self.assert_unpack("RGB", "G;16N", 2, (0, 1, 0), (0, 3, 0), (0, 5, 0))
|
||||
self.assert_unpack("RGB", "B;16N", 2, (0, 0, 1), (0, 0, 3), (0, 0, 5))
|
||||
|
||||
def test_RGBA(self):
|
||||
self.assert_unpack("RGBA", "LA", 2, (1, 1, 1, 2), (3, 3, 3, 4), (5, 5, 5, 6))
|
||||
self.assert_unpack(
|
||||
|
@ -450,6 +467,43 @@ class TestLibUnpack:
|
|||
self.assert_unpack("RGBA", "B", 1, (0, 0, 1, 0), (0, 0, 2, 0), (0, 0, 3, 0))
|
||||
self.assert_unpack("RGBA", "A", 1, (0, 0, 0, 1), (0, 0, 0, 2), (0, 0, 0, 3))
|
||||
|
||||
self.assert_unpack("RGBA", "R;16B", 2, (1, 0, 0, 0), (3, 0, 0, 0), (5, 0, 0, 0))
|
||||
self.assert_unpack("RGBA", "G;16B", 2, (0, 1, 0, 0), (0, 3, 0, 0), (0, 5, 0, 0))
|
||||
self.assert_unpack("RGBA", "B;16B", 2, (0, 0, 1, 0), (0, 0, 3, 0), (0, 0, 5, 0))
|
||||
self.assert_unpack("RGBA", "A;16B", 2, (0, 0, 0, 1), (0, 0, 0, 3), (0, 0, 0, 5))
|
||||
|
||||
self.assert_unpack("RGBA", "R;16L", 2, (2, 0, 0, 0), (4, 0, 0, 0), (6, 0, 0, 0))
|
||||
self.assert_unpack("RGBA", "G;16L", 2, (0, 2, 0, 0), (0, 4, 0, 0), (0, 6, 0, 0))
|
||||
self.assert_unpack("RGBA", "B;16L", 2, (0, 0, 2, 0), (0, 0, 4, 0), (0, 0, 6, 0))
|
||||
self.assert_unpack("RGBA", "A;16L", 2, (0, 0, 0, 2), (0, 0, 0, 4), (0, 0, 0, 6))
|
||||
|
||||
if sys.byteorder == "little":
|
||||
self.assert_unpack(
|
||||
"RGBA", "R;16N", 2, (2, 0, 0, 0), (4, 0, 0, 0), (6, 0, 0, 0)
|
||||
)
|
||||
self.assert_unpack(
|
||||
"RGBA", "G;16N", 2, (0, 2, 0, 0), (0, 4, 0, 0), (0, 6, 0, 0)
|
||||
)
|
||||
self.assert_unpack(
|
||||
"RGBA", "B;16N", 2, (0, 0, 2, 0), (0, 0, 4, 0), (0, 0, 6, 0)
|
||||
)
|
||||
self.assert_unpack(
|
||||
"RGBA", "A;16N", 2, (0, 0, 0, 2), (0, 0, 0, 4), (0, 0, 0, 6)
|
||||
)
|
||||
else:
|
||||
self.assert_unpack(
|
||||
"RGBA", "R;16N", 2, (1, 0, 0, 0), (3, 0, 0, 0), (5, 0, 0, 0)
|
||||
)
|
||||
self.assert_unpack(
|
||||
"RGBA", "G;16N", 2, (0, 1, 0, 0), (0, 3, 0, 0), (0, 5, 0, 0)
|
||||
)
|
||||
self.assert_unpack(
|
||||
"RGBA", "B;16N", 2, (0, 0, 1, 0), (0, 0, 3, 0), (0, 0, 5, 0)
|
||||
)
|
||||
self.assert_unpack(
|
||||
"RGBA", "A;16N", 2, (0, 0, 0, 1), (0, 0, 0, 3), (0, 0, 0, 5)
|
||||
)
|
||||
|
||||
def test_RGBa(self):
|
||||
self.assert_unpack(
|
||||
"RGBa", "RGBa", 4, (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)
|
||||
|
|
|
@ -1363,6 +1363,94 @@ band3I(UINT8 *out, const UINT8 *in, int pixels) {
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
band016B(UINT8* out, const UINT8* in, int pixels)
|
||||
{
|
||||
int i;
|
||||
/* band 0 only, big endian */
|
||||
for (i = 0; i < pixels; i++) {
|
||||
out[0] = in[0];
|
||||
out += 4; in += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
band116B(UINT8* out, const UINT8* in, int pixels)
|
||||
{
|
||||
int i;
|
||||
/* band 1 only, big endian */
|
||||
for (i = 0; i < pixels; i++) {
|
||||
out[1] = in[0];
|
||||
out += 4; in += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
band216B(UINT8* out, const UINT8* in, int pixels)
|
||||
{
|
||||
int i;
|
||||
/* band 2 only, big endian */
|
||||
for (i = 0; i < pixels; i++) {
|
||||
out[2] = in[0];
|
||||
out += 4; in += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
band316B(UINT8* out, const UINT8* in, int pixels)
|
||||
{
|
||||
int i;
|
||||
/* band 3 only, big endian */
|
||||
for (i = 0; i < pixels; i++) {
|
||||
out[3] = in[0];
|
||||
out += 4; in += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
band016L(UINT8* out, const UINT8* in, int pixels)
|
||||
{
|
||||
int i;
|
||||
/* band 0 only, little endian */
|
||||
for (i = 0; i < pixels; i++) {
|
||||
out[0] = in[1];
|
||||
out += 4; in += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
band116L(UINT8* out, const UINT8* in, int pixels)
|
||||
{
|
||||
int i;
|
||||
/* band 1 only, little endian */
|
||||
for (i = 0; i < pixels; i++) {
|
||||
out[1] = in[1];
|
||||
out += 4; in += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
band216L(UINT8* out, const UINT8* in, int pixels)
|
||||
{
|
||||
int i;
|
||||
/* band 2 only, little endian */
|
||||
for (i = 0; i < pixels; i++) {
|
||||
out[2] = in[1];
|
||||
out += 4; in += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
band316L(UINT8* out, const UINT8* in, int pixels)
|
||||
{
|
||||
int i;
|
||||
/* band 3 only, little endian */
|
||||
for (i = 0; i < pixels; i++) {
|
||||
out[3] = in[1];
|
||||
out += 4; in += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static struct {
|
||||
const char *mode;
|
||||
const char *rawmode;
|
||||
|
@ -1448,6 +1536,12 @@ static struct {
|
|||
{"RGB", "R", 8, band0},
|
||||
{"RGB", "G", 8, band1},
|
||||
{"RGB", "B", 8, band2},
|
||||
{"RGB", "R;16L", 16, band016L},
|
||||
{"RGB", "G;16L", 16, band116L},
|
||||
{"RGB", "B;16L", 16, band216L},
|
||||
{"RGB", "R;16B", 16, band016B},
|
||||
{"RGB", "G;16B", 16, band116B},
|
||||
{"RGB", "B;16B", 16, band216B},
|
||||
|
||||
/* true colour w. alpha */
|
||||
{"RGBA", "LA", 16, unpackRGBALA},
|
||||
|
@ -1476,17 +1570,42 @@ static struct {
|
|||
{"RGBA", "G", 8, band1},
|
||||
{"RGBA", "B", 8, band2},
|
||||
{"RGBA", "A", 8, band3},
|
||||
{"RGBA", "R;16L", 16, band016L},
|
||||
{"RGBA", "G;16L", 16, band116L},
|
||||
{"RGBA", "B;16L", 16, band216L},
|
||||
{"RGBA", "A;16L", 16, band316L},
|
||||
{"RGBA", "R;16B", 16, band016B},
|
||||
{"RGBA", "G;16B", 16, band116B},
|
||||
{"RGBA", "B;16B", 16, band216B},
|
||||
{"RGBA", "A;16B", 16, band316B},
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
{"RGB", "RGB;16N", 48, unpackRGB16B},
|
||||
{"RGBA", "RGBa;16N", 64, unpackRGBa16B},
|
||||
{"RGBA", "RGBA;16N", 64, unpackRGBA16B},
|
||||
{"RGBX", "RGBX;16N", 64, unpackRGBA16B},
|
||||
{"RGB", "R;16N", 16, band016B},
|
||||
{"RGB", "G;16N", 16, band116B},
|
||||
{"RGB", "B;16N", 16, band216B},
|
||||
|
||||
{"RGBA", "R;16N", 16, band016B},
|
||||
{"RGBA", "G;16N", 16, band116B},
|
||||
{"RGBA", "B;16N", 16, band216B},
|
||||
{"RGBA", "A;16N", 16, band316B},
|
||||
#else
|
||||
{"RGB", "RGB;16N", 48, unpackRGB16L},
|
||||
{"RGBA", "RGBa;16N", 64, unpackRGBa16L},
|
||||
{"RGBA", "RGBA;16N", 64, unpackRGBA16L},
|
||||
{"RGBX", "RGBX;16N", 64, unpackRGBA16B},
|
||||
{"RGBX", "RGBX;16N", 64, unpackRGBA16L},
|
||||
{"RGB", "R;16N", 16, band016L},
|
||||
{"RGB", "G;16N", 16, band116L},
|
||||
{"RGB", "B;16N", 16, band216L},
|
||||
|
||||
|
||||
{"RGBA", "R;16N", 16, band016L},
|
||||
{"RGBA", "G;16N", 16, band116L},
|
||||
{"RGBA", "B;16N", 16, band216L},
|
||||
{"RGBA", "A;16N", 16, band316L},
|
||||
#endif
|
||||
|
||||
/* true colour w. alpha premultiplied */
|
||||
|
|
Loading…
Reference in New Issue
Block a user