Add Tests and support for Planar Tiff Images

This commit is contained in:
Konstantin Kopachev 2020-05-23 09:24:41 -07:00 committed by Eric Soroos
parent e405ab300b
commit 0018685a8e
9 changed files with 220 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -856,6 +856,52 @@ class TestFileLibTiff(LibTiffTestCase):
with Image.open(infile) as im: with Image.open(infile) as im:
assert_image_similar_tofile(im, "Tests/images/flower.jpg", 0.5) 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") @pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
def test_old_style_jpeg(self): def test_old_style_jpeg(self):
infile = "Tests/images/old-style-jpeg-compression.tif" infile = "Tests/images/old-style-jpeg-compression.tif"

View File

@ -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", "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", "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): 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("RGBA", "LA", 2, (1, 1, 1, 2), (3, 3, 3, 4), (5, 5, 5, 6))
self.assert_unpack( 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", "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", "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): def test_RGBa(self):
self.assert_unpack( self.assert_unpack(
"RGBa", "RGBa", 4, (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12) "RGBa", "RGBa", 4, (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)

View File

@ -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 { static struct {
const char *mode; const char *mode;
const char *rawmode; const char *rawmode;
@ -1448,6 +1536,12 @@ static struct {
{"RGB", "R", 8, band0}, {"RGB", "R", 8, band0},
{"RGB", "G", 8, band1}, {"RGB", "G", 8, band1},
{"RGB", "B", 8, band2}, {"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 */ /* true colour w. alpha */
{"RGBA", "LA", 16, unpackRGBALA}, {"RGBA", "LA", 16, unpackRGBALA},
@ -1476,17 +1570,42 @@ static struct {
{"RGBA", "G", 8, band1}, {"RGBA", "G", 8, band1},
{"RGBA", "B", 8, band2}, {"RGBA", "B", 8, band2},
{"RGBA", "A", 8, band3}, {"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 #ifdef WORDS_BIGENDIAN
{"RGB", "RGB;16N", 48, unpackRGB16B}, {"RGB", "RGB;16N", 48, unpackRGB16B},
{"RGBA", "RGBa;16N", 64, unpackRGBa16B}, {"RGBA", "RGBa;16N", 64, unpackRGBa16B},
{"RGBA", "RGBA;16N", 64, unpackRGBA16B}, {"RGBA", "RGBA;16N", 64, unpackRGBA16B},
{"RGBX", "RGBX;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 #else
{"RGB", "RGB;16N", 48, unpackRGB16L}, {"RGB", "RGB;16N", 48, unpackRGB16L},
{"RGBA", "RGBa;16N", 64, unpackRGBa16L}, {"RGBA", "RGBa;16N", 64, unpackRGBa16L},
{"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 #endif
/* true colour w. alpha premultiplied */ /* true colour w. alpha premultiplied */