fixup tiff alpha handling cxx tests
This commit is contained in:
parent
66e65666ae
commit
a706cdb000
8 changed files with 85 additions and 34 deletions
|
@ -15,54 +15,31 @@ std::unique_ptr<mapnik::image_reader> open(std::string const& filename)
|
||||||
mapnik::tiff_reader<boost::iostreams::file_source> tiff_reader(filename); \
|
mapnik::tiff_reader<boost::iostreams::file_source> tiff_reader(filename); \
|
||||||
REQUIRE( tiff_reader.width() == 256 ); \
|
REQUIRE( tiff_reader.width() == 256 ); \
|
||||||
REQUIRE( tiff_reader.height() == 256 ); \
|
REQUIRE( tiff_reader.height() == 256 ); \
|
||||||
REQUIRE( tiff_reader.has_alpha() == false ); \
|
|
||||||
REQUIRE( tiff_reader.premultiplied_alpha() == false ); \
|
|
||||||
auto reader = open(filename); \
|
auto reader = open(filename); \
|
||||||
REQUIRE( reader->width() == 256 ); \
|
REQUIRE( reader->width() == 256 ); \
|
||||||
REQUIRE( reader->height() == 256 ); \
|
REQUIRE( reader->height() == 256 ); \
|
||||||
|
|
||||||
|
#define TIFF_ASSERT_ALPHA \
|
||||||
|
REQUIRE( tiff_reader.has_alpha() == true ); \
|
||||||
|
REQUIRE( tiff_reader.premultiplied_alpha() == false ); \
|
||||||
|
REQUIRE( reader->has_alpha() == true ); \
|
||||||
|
REQUIRE( reader->premultiplied_alpha() == false ); \
|
||||||
|
|
||||||
|
#define TIFF_ASSERT_NO_ALPHA \
|
||||||
|
REQUIRE( tiff_reader.has_alpha() == false ); \
|
||||||
|
REQUIRE( tiff_reader.premultiplied_alpha() == false ); \
|
||||||
REQUIRE( reader->has_alpha() == false ); \
|
REQUIRE( reader->has_alpha() == false ); \
|
||||||
REQUIRE( reader->premultiplied_alpha() == false ); \
|
REQUIRE( reader->premultiplied_alpha() == false ); \
|
||||||
|
|
||||||
TEST_CASE("tiff io") {
|
TEST_CASE("tiff io") {
|
||||||
|
|
||||||
SECTION("gray8 striped") {
|
|
||||||
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray8_striped.tif")
|
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
|
||||||
REQUIRE( tiff_reader.is_tiled() == false );
|
|
||||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
|
||||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("gray8 tiled") {
|
|
||||||
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray8_tiled.tif")
|
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
|
||||||
REQUIRE( tiff_reader.is_tiled() == true );
|
|
||||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
|
||||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("gray16 striped") {
|
|
||||||
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray16_striped.tif")
|
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
|
||||||
REQUIRE( tiff_reader.is_tiled() == false );
|
|
||||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
|
||||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("gray16 tiled") {
|
|
||||||
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray16_tiled.tif")
|
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
|
||||||
REQUIRE( tiff_reader.is_tiled() == true );
|
|
||||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
|
||||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("rgba8 striped") {
|
SECTION("rgba8 striped") {
|
||||||
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_rgba8_striped.tif")
|
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_rgba8_striped.tif")
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
REQUIRE( tiff_reader.is_tiled() == false );
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
|
TIFF_ASSERT_ALPHA
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("rgba8 tiled") {
|
SECTION("rgba8 tiled") {
|
||||||
|
@ -71,6 +48,61 @@ SECTION("rgba8 tiled") {
|
||||||
REQUIRE( tiff_reader.is_tiled() == true );
|
REQUIRE( tiff_reader.is_tiled() == true );
|
||||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||||
|
TIFF_ASSERT_ALPHA
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("rgb8 striped") {
|
||||||
|
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_rgb8_striped.tif")
|
||||||
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
|
TIFF_ASSERT_NO_ALPHA
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("rgb8 tiled") {
|
||||||
|
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_rgb8_tiled.tif")
|
||||||
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
|
REQUIRE( tiff_reader.is_tiled() == true );
|
||||||
|
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||||
|
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||||
|
TIFF_ASSERT_NO_ALPHA
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("gray8 striped") {
|
||||||
|
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray8_striped.tif")
|
||||||
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
|
TIFF_ASSERT_NO_ALPHA
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("gray8 tiled") {
|
||||||
|
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray8_tiled.tif")
|
||||||
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
|
REQUIRE( tiff_reader.is_tiled() == true );
|
||||||
|
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||||
|
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||||
|
TIFF_ASSERT_NO_ALPHA
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("gray16 striped") {
|
||||||
|
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray16_striped.tif")
|
||||||
|
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
||||||
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
|
TIFF_ASSERT_NO_ALPHA
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("gray16 tiled") {
|
||||||
|
TIFF_ASSERT("./tests/data/tiff/ndvi_256x256_gray16_tiled.tif")
|
||||||
|
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
||||||
|
REQUIRE( tiff_reader.is_tiled() == true );
|
||||||
|
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||||
|
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||||
|
TIFF_ASSERT_NO_ALPHA
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("gray32f striped") {
|
SECTION("gray32f striped") {
|
||||||
|
@ -79,6 +111,7 @@ SECTION("gray32f striped") {
|
||||||
REQUIRE( tiff_reader.is_tiled() == false );
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
|
TIFF_ASSERT_NO_ALPHA
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("gray32f tiled") {
|
SECTION("gray32f tiled") {
|
||||||
|
@ -87,6 +120,7 @@ SECTION("gray32f tiled") {
|
||||||
REQUIRE( tiff_reader.is_tiled() == true );
|
REQUIRE( tiff_reader.is_tiled() == true );
|
||||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||||
|
TIFF_ASSERT_NO_ALPHA
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
4
tests/data/tiff/README.md
Normal file
4
tests/data/tiff/README.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
striped images created with rio
|
||||||
|
tiled images created with:
|
||||||
|
|
||||||
|
tiffcp -t -w256 -l256 -c lzw input.tiff output.tif
|
BIN
tests/data/tiff/ndvi_256x256_rgb.tiff
Normal file
BIN
tests/data/tiff/ndvi_256x256_rgb.tiff
Normal file
Binary file not shown.
BIN
tests/data/tiff/ndvi_256x256_rgb8_striped.tif
Normal file
BIN
tests/data/tiff/ndvi_256x256_rgb8_striped.tif
Normal file
Binary file not shown.
BIN
tests/data/tiff/ndvi_256x256_rgb8_tiled.tif
Normal file
BIN
tests/data/tiff/ndvi_256x256_rgb8_tiled.tif
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -12,6 +12,19 @@ def setup():
|
||||||
# from another directory we need to chdir()
|
# from another directory we need to chdir()
|
||||||
os.chdir(execution_path('.'))
|
os.chdir(execution_path('.'))
|
||||||
|
|
||||||
|
def test_tiff_rgb8_compare():
|
||||||
|
filepath1 = '../data/tiff/ndvi_256x256_rgb8_striped.tif'
|
||||||
|
filepath2 = '/tmp/mapnik-tiff-rgb8.tiff'
|
||||||
|
im = mapnik.Image.open(filepath1)
|
||||||
|
im.save(filepath2,'tiff')
|
||||||
|
im2 = mapnik.Image.open(filepath2)
|
||||||
|
eq_(im.width(),im2.width())
|
||||||
|
eq_(im.height(),im2.height())
|
||||||
|
eq_(len(im.tostring()),len(im2.tostring()))
|
||||||
|
eq_(len(im.tostring('tiff')),len(im2.tostring('tiff')))
|
||||||
|
# should not be a blank image
|
||||||
|
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||||
|
|
||||||
def test_tiff_rgba8_compare():
|
def test_tiff_rgba8_compare():
|
||||||
filepath1 = '../data/tiff/ndvi_256x256_rgba8_striped.tif'
|
filepath1 = '../data/tiff/ndvi_256x256_rgba8_striped.tif'
|
||||||
filepath2 = '/tmp/mapnik-tiff-rgba8.tiff'
|
filepath2 = '/tmp/mapnik-tiff-rgba8.tiff'
|
||||||
|
|
Loading…
Reference in a new issue