parent
99a7fa5044
commit
185d788ea4
4 changed files with 522 additions and 305 deletions
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of Mapnik (c++ mapping toolkit)
|
* This file is part of Mapnik (c++ mapping toolkit)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Artem Pavlenko
|
* Copyright (C) 2017 Artem Pavlenko
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -162,8 +162,12 @@ private:
|
||||||
tiff_reader(const tiff_reader&);
|
tiff_reader(const tiff_reader&);
|
||||||
tiff_reader& operator=(const tiff_reader&);
|
tiff_reader& operator=(const tiff_reader&);
|
||||||
void init();
|
void init();
|
||||||
void read_generic(std::size_t x,std::size_t y,image_rgba8& image);
|
|
||||||
void read_stripped(std::size_t x,std::size_t y,image_rgba8& image);
|
template <typename ImageData>
|
||||||
|
void read_generic(std::size_t x,std::size_t y, ImageData & image);
|
||||||
|
|
||||||
|
template <typename ImageData>
|
||||||
|
void read_stripped(std::size_t x,std::size_t y, ImageData & image);
|
||||||
|
|
||||||
template <typename ImageData>
|
template <typename ImageData>
|
||||||
void read_tiled(std::size_t x,std::size_t y, ImageData & image);
|
void read_tiled(std::size_t x,std::size_t y, ImageData & image);
|
||||||
|
@ -257,25 +261,24 @@ void tiff_reader<T>::init()
|
||||||
TIFFGetField(tif,TIFFTAG_PHOTOMETRIC,&photometric_);
|
TIFFGetField(tif,TIFFTAG_PHOTOMETRIC,&photometric_);
|
||||||
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &bands_);
|
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &bands_);
|
||||||
|
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "bits per sample: " << bps_;
|
MAPNIK_LOG_DEBUG(tiff_reader) << "bits per sample: " << bps_ ;
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "sample format: " << sample_format_;
|
MAPNIK_LOG_DEBUG(tiff_reader) << "sample format: " << sample_format_ ;
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "photometric: " << photometric_;
|
MAPNIK_LOG_DEBUG(tiff_reader) << "photometric: " << photometric_ ;
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "bands: " << bands_;
|
MAPNIK_LOG_DEBUG(tiff_reader) << "bands: " << bands_ ;
|
||||||
|
|
||||||
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width_);
|
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width_);
|
||||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height_);
|
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height_);
|
||||||
|
|
||||||
TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planar_config_);
|
TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planar_config_);
|
||||||
TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression_ );
|
TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression_ );
|
||||||
TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rows_per_strip_);
|
|
||||||
|
|
||||||
std::uint16_t orientation;
|
std::uint16_t orientation;
|
||||||
if (TIFFGetField(tif, TIFFTAG_ORIENTATION, &orientation) == 0)
|
if (TIFFGetField(tif, TIFFTAG_ORIENTATION, &orientation) == 0)
|
||||||
{
|
{
|
||||||
orientation = 1;
|
orientation = 1;
|
||||||
}
|
}
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "orientation: " << orientation;
|
MAPNIK_LOG_DEBUG(tiff_reader) << "orientation: " << orientation ;
|
||||||
|
MAPNIK_LOG_DEBUG(tiff_reader) << "planar-config: " << planar_config_ ;
|
||||||
is_tiled_ = TIFFIsTiled(tif);
|
is_tiled_ = TIFFIsTiled(tif);
|
||||||
|
|
||||||
if (is_tiled_)
|
if (is_tiled_)
|
||||||
|
@ -285,7 +288,7 @@ void tiff_reader<T>::init()
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "tiff is tiled";
|
MAPNIK_LOG_DEBUG(tiff_reader) << "tiff is tiled";
|
||||||
read_method_ = tiled;
|
read_method_ = tiled;
|
||||||
}
|
}
|
||||||
else if (TIFFGetField(tif,TIFFTAG_ROWSPERSTRIP,&rows_per_strip_)!=0)
|
else if (TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rows_per_strip_) != 0)
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "tiff is stripped";
|
MAPNIK_LOG_DEBUG(tiff_reader) << "tiff is stripped";
|
||||||
read_method_ = stripped;
|
read_method_ = stripped;
|
||||||
|
@ -311,9 +314,9 @@ void tiff_reader<T>::init()
|
||||||
if (TIFFGetField(tif, 33550, &count, &pixelscale) == 1 && count == 3
|
if (TIFFGetField(tif, 33550, &count, &pixelscale) == 1 && count == 3
|
||||||
&& TIFFGetField(tif, 33922 , &count, &tilepoint) == 1 && count == 6)
|
&& TIFFGetField(tif, 33922 , &count, &tilepoint) == 1 && count == 6)
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "PixelScale:" << pixelscale[0] << "," << pixelscale[1] << "," << pixelscale[2];
|
MAPNIK_LOG_DEBUG(tiff_reader) << "PixelScale:" << pixelscale[0] << "," << pixelscale[1] << "," << pixelscale[2] ;
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "TilePoint:" << tilepoint[0] << "," << tilepoint[1] << "," << tilepoint[2];
|
MAPNIK_LOG_DEBUG(tiff_reader) << "TilePoint:" << tilepoint[0] << "," << tilepoint[1] << "," << tilepoint[2] ;
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << " " << tilepoint[3] << "," << tilepoint[4] << "," << tilepoint[5];
|
MAPNIK_LOG_DEBUG(tiff_reader) << " " << tilepoint[3] << "," << tilepoint[4] << "," << tilepoint[5] ;
|
||||||
|
|
||||||
// assuming upper-left
|
// assuming upper-left
|
||||||
double lox = tilepoint[3];
|
double lox = tilepoint[3];
|
||||||
|
@ -321,7 +324,7 @@ void tiff_reader<T>::init()
|
||||||
double hix = lox + pixelscale[0] * width_;
|
double hix = lox + pixelscale[0] * width_;
|
||||||
double hiy = loy - pixelscale[1] * height_;
|
double hiy = loy - pixelscale[1] * height_;
|
||||||
bbox_.reset(box2d<double>(lox, loy, hix, hiy));
|
bbox_.reset(box2d<double>(lox, loy, hix, hiy));
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "Bounding Box:" << *bbox_;
|
MAPNIK_LOG_DEBUG(tiff_reader) << "Bounding Box:" << *bbox_ ;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -391,10 +394,17 @@ image_any tiff_reader<T>::read_any_gray(std::size_t x0, std::size_t y0, std::siz
|
||||||
using pixel_type = typename image_type::pixel_type;
|
using pixel_type = typename image_type::pixel_type;
|
||||||
if (read_method_ == tiled)
|
if (read_method_ == tiled)
|
||||||
{
|
{
|
||||||
image_type data(width,height);
|
image_type data(width, height);
|
||||||
read_tiled<image_type>(x0, y0, data);
|
read_tiled<image_type>(x0, y0, data);
|
||||||
return image_any(std::move(data));
|
return image_any(std::move(data));
|
||||||
}
|
}
|
||||||
|
// TODO: temp disable and default to `scanline` method for stripped images.
|
||||||
|
else if (read_method_ == stripped)
|
||||||
|
{
|
||||||
|
image_type data(width, height);
|
||||||
|
read_stripped<image_type>(x0, y0, data);
|
||||||
|
return image_any(std::move(data));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TIFF* tif = open(stream_);
|
TIFF* tif = open(stream_);
|
||||||
|
@ -407,14 +417,52 @@ image_any tiff_reader<T>::read_any_gray(std::size_t x0, std::size_t y0, std::siz
|
||||||
std::size_t start_x = x0;
|
std::size_t start_x = x0;
|
||||||
std::size_t end_x = std::min(x0 + width, width_);
|
std::size_t end_x = std::min(x0 + width, width_);
|
||||||
std::size_t element_size = sizeof(pixel_type);
|
std::size_t element_size = sizeof(pixel_type);
|
||||||
|
MAPNIK_LOG_DEBUG(tiff_reader) << "SCANLINE SIZE=" << TIFFScanlineSize(tif);
|
||||||
std::size_t size_to_allocate = (TIFFScanlineSize(tif) + element_size - 1)/element_size;
|
std::size_t size_to_allocate = (TIFFScanlineSize(tif) + element_size - 1)/element_size;
|
||||||
const std::unique_ptr<pixel_type[]> scanline(new pixel_type[size_to_allocate]);
|
std::unique_ptr<pixel_type[]> const scanline(new pixel_type[size_to_allocate]);
|
||||||
for (std::size_t y = start_y; y < end_y; ++y)
|
if (planar_config_ == PLANARCONFIG_CONTIG)
|
||||||
{
|
{
|
||||||
if (-1 != TIFFReadScanline(tif, scanline.get(), y) && (y >= y0))
|
for (std::size_t y = start_y; y < end_y; ++y)
|
||||||
{
|
{
|
||||||
pixel_type * row = data.get_row(y - y0);
|
// we have to read all scanlines sequentially from start_y
|
||||||
std::transform(scanline.get() + start_x, scanline.get() + end_x, row, [](pixel_type const& p) { return p;});
|
// to be able to use scanline interface with compressed blocks.
|
||||||
|
if (-1 != TIFFReadScanline(tif, scanline.get(), y) && (y >= y0))
|
||||||
|
{
|
||||||
|
pixel_type * row = data.get_row(y - y0);
|
||||||
|
if (bands_ == 1)
|
||||||
|
{
|
||||||
|
std::transform(scanline.get() + start_x, scanline.get() + end_x, row, [](pixel_type const& p) { return p;});
|
||||||
|
}
|
||||||
|
else if (size_to_allocate == bands_ * width_)
|
||||||
|
{
|
||||||
|
// bands_ > 1 => packed bands in grayscale image e.g an extra alpha channel.
|
||||||
|
// Just pick first one for now.
|
||||||
|
pixel_type * buf = scanline.get() + start_x * bands_;
|
||||||
|
std::size_t x_index = 0;
|
||||||
|
for (std::size_t j = 0; j < end_x * bands_; ++j)
|
||||||
|
{
|
||||||
|
if (x_index >= width) break;
|
||||||
|
if (j % bands_ == 0)
|
||||||
|
{
|
||||||
|
row[x_index++] = buf[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (planar_config_ == PLANARCONFIG_SEPARATE)
|
||||||
|
{
|
||||||
|
for (std::size_t s = 0 ; s < bands_ ; ++s)
|
||||||
|
{
|
||||||
|
for (std::size_t y = start_y; y < end_y; ++y)
|
||||||
|
{
|
||||||
|
if (-1 != TIFFReadScanline(tif, scanline.get(), y) && (y >= y0))
|
||||||
|
{
|
||||||
|
pixel_type * row = data.get_row(y - y0);
|
||||||
|
std::transform(scanline.get() + start_x, scanline.get() + end_x, row, [](pixel_type const& p) { return p;});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return image_any(std::move(data));
|
return image_any(std::move(data));
|
||||||
|
@ -446,9 +494,17 @@ struct tiff_reader_traits
|
||||||
{
|
{
|
||||||
using image_type = T;
|
using image_type = T;
|
||||||
using pixel_type = typename image_type::pixel_type;
|
using pixel_type = typename image_type::pixel_type;
|
||||||
|
|
||||||
|
constexpr static bool reverse = false;
|
||||||
static bool read_tile(TIFF * tif, std::size_t x, std::size_t y, pixel_type* buf, std::size_t tile_width, std::size_t tile_height)
|
static bool read_tile(TIFF * tif, std::size_t x, std::size_t y, pixel_type* buf, std::size_t tile_width, std::size_t tile_height)
|
||||||
{
|
{
|
||||||
return (TIFFReadEncodedTile(tif, TIFFComputeTile(tif, x,y,0,0), buf, tile_width * tile_height * sizeof(pixel_type)) != -1);
|
std::uint32_t tile_size = TIFFTileSize(tif);
|
||||||
|
return (TIFFReadEncodedTile(tif, TIFFComputeTile(tif, x, y, 0, 0), buf, tile_size) != -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool read_strip(TIFF * tif, std::size_t y, std::size_t rows_per_strip, std::size_t strip_width, pixel_type * buf)
|
||||||
|
{
|
||||||
|
return (TIFFReadEncodedStrip(tif, y/rows_per_strip, buf, -1) != -1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -456,18 +512,17 @@ struct tiff_reader_traits
|
||||||
template <>
|
template <>
|
||||||
struct tiff_reader_traits<image_rgba8>
|
struct tiff_reader_traits<image_rgba8>
|
||||||
{
|
{
|
||||||
|
using image_type = image_rgba8;
|
||||||
using pixel_type = std::uint32_t;
|
using pixel_type = std::uint32_t;
|
||||||
|
constexpr static bool reverse = true;
|
||||||
static bool read_tile(TIFF * tif, std::size_t x0, std::size_t y0, pixel_type* buf, std::size_t tile_width, std::size_t tile_height)
|
static bool read_tile(TIFF * tif, std::size_t x0, std::size_t y0, pixel_type* buf, std::size_t tile_width, std::size_t tile_height)
|
||||||
{
|
{
|
||||||
if (TIFFReadRGBATile(tif, x0, y0, buf) != -1)
|
return (TIFFReadRGBATile(tif, x0, y0, buf) != 0);
|
||||||
{
|
}
|
||||||
for (std::size_t y = 0; y < tile_height/2; ++y)
|
|
||||||
{
|
static bool read_strip(TIFF * tif, std::size_t y, std::size_t rows_per_strip, std::size_t strip_width, pixel_type * buf)
|
||||||
std::swap_ranges(buf + y * tile_width, buf + (y + 1) * tile_width, buf + (tile_height - y - 1) * tile_width);
|
{
|
||||||
}
|
return (TIFFReadRGBAStrip(tif, y, buf) != 0);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -591,7 +646,8 @@ image_any tiff_reader<T>::read(unsigned x, unsigned y, unsigned width, unsigned
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void tiff_reader<T>::read_generic(std::size_t, std::size_t, image_rgba8&)
|
template <typename ImageData>
|
||||||
|
void tiff_reader<T>::read_generic(std::size_t, std::size_t, ImageData &)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("tiff_reader: TODO - tiff is not stripped or tiled");
|
throw std::runtime_error("tiff_reader: TODO - tiff is not stripped or tiled");
|
||||||
}
|
}
|
||||||
|
@ -605,7 +661,8 @@ void tiff_reader<T>::read_tiled(std::size_t x0,std::size_t y0, ImageData & image
|
||||||
TIFF* tif = open(stream_);
|
TIFF* tif = open(stream_);
|
||||||
if (tif)
|
if (tif)
|
||||||
{
|
{
|
||||||
std::unique_ptr<pixel_type[]> buf(new pixel_type[tile_width_*tile_height_]);
|
std::uint32_t tile_size = TIFFTileSize(tif);
|
||||||
|
std::unique_ptr<pixel_type[]> tile(new pixel_type[tile_size]);
|
||||||
std::size_t width = image.width();
|
std::size_t width = image.width();
|
||||||
std::size_t height = image.height();
|
std::size_t height = image.height();
|
||||||
std::size_t start_y = (y0 / tile_height_) * tile_height_;
|
std::size_t start_y = (y0 / tile_height_) * tile_height_;
|
||||||
|
@ -614,7 +671,7 @@ void tiff_reader<T>::read_tiled(std::size_t x0,std::size_t y0, ImageData & image
|
||||||
std::size_t end_x = ((x0 + width) / tile_width_ + 1) * tile_width_;
|
std::size_t end_x = ((x0 + width) / tile_width_ + 1) * tile_width_;
|
||||||
end_y = std::min(end_y, height_);
|
end_y = std::min(end_y, height_);
|
||||||
end_x = std::min(end_x, width_);
|
end_x = std::min(end_x, width_);
|
||||||
|
bool pick_first_band = (bands_ > 1) && (tile_size / (tile_width_ * tile_height_ * sizeof(pixel_type)) == bands_);
|
||||||
for (std::size_t y = start_y; y < end_y; y += tile_height_)
|
for (std::size_t y = start_y; y < end_y; y += tile_height_)
|
||||||
{
|
{
|
||||||
std::size_t ty0 = std::max(y0, y) - y;
|
std::size_t ty0 = std::max(y0, y) - y;
|
||||||
|
@ -622,56 +679,98 @@ void tiff_reader<T>::read_tiled(std::size_t x0,std::size_t y0, ImageData & image
|
||||||
|
|
||||||
for (std::size_t x = start_x; x < end_x; x += tile_width_)
|
for (std::size_t x = start_x; x < end_x; x += tile_width_)
|
||||||
{
|
{
|
||||||
if (!detail::tiff_reader_traits<ImageData>::read_tile(tif, x, y, buf.get(), tile_width_, tile_height_))
|
if (!detail::tiff_reader_traits<ImageData>::read_tile(tif, x, y, tile.get(), tile_width_, tile_height_))
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "read_tile(...) failed at " << x << "/" << y << " for " << width_ << "/" << height_ << "\n";
|
MAPNIK_LOG_DEBUG(tiff_reader) << "read_tile(...) failed at " << x << "/" << y << " for " << width_ << "/" << height_ << "\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (pick_first_band)
|
||||||
|
{
|
||||||
|
std::uint32_t size = tile_width_ * tile_height_ * sizeof(pixel_type);
|
||||||
|
for (std::uint32_t n = 0; n < size; ++n)
|
||||||
|
{
|
||||||
|
tile[n] = tile[n * bands_];
|
||||||
|
}
|
||||||
|
}
|
||||||
std::size_t tx0 = std::max(x0, x);
|
std::size_t tx0 = std::max(x0, x);
|
||||||
std::size_t tx1 = std::min(width + x0, x + tile_width_);
|
std::size_t tx1 = std::min(width + x0, x + tile_width_);
|
||||||
std::size_t row = y + ty0 - y0;
|
std::size_t row_index = y + ty0 - y0;
|
||||||
for (std::size_t ty = ty0; ty < ty1; ++ty, ++row)
|
|
||||||
|
if (detail::tiff_reader_traits<ImageData>::reverse)
|
||||||
{
|
{
|
||||||
image.set_row(row, tx0 - x0, tx1 - x0, &buf[ty * tile_width_ + tx0 - x]);
|
for (std::size_t ty = ty0; ty < ty1; ++ty, ++row_index)
|
||||||
|
{
|
||||||
|
// This is in reverse because the TIFFReadRGBATile reads are inverted
|
||||||
|
image.set_row(row_index, tx0 - x0, tx1 - x0, &tile[(tile_height_ - ty - 1) * tile_width_ + tx0 - x]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (std::size_t ty = ty0; ty < ty1; ++ty, ++row_index)
|
||||||
|
{
|
||||||
|
image.set_row(row_index, tx0 - x0, tx1 - x0, &tile[ty * tile_width_ + tx0 - x]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void tiff_reader<T>::read_stripped(std::size_t x0,std::size_t y0,image_rgba8& image)
|
template <typename ImageData>
|
||||||
|
void tiff_reader<T>::read_stripped(std::size_t x0, std::size_t y0, ImageData & image)
|
||||||
{
|
{
|
||||||
|
using pixel_type = typename detail::tiff_reader_traits<ImageData>::pixel_type;
|
||||||
TIFF* tif = open(stream_);
|
TIFF* tif = open(stream_);
|
||||||
if (tif)
|
if (tif)
|
||||||
{
|
{
|
||||||
image_rgba8 strip(width_,rows_per_strip_,false);
|
std::uint32_t strip_size = TIFFStripSize(tif);
|
||||||
std::size_t width=image.width();
|
std::unique_ptr<pixel_type[]> strip(new pixel_type[strip_size]);
|
||||||
std::size_t height=image.height();
|
std::size_t width = image.width();
|
||||||
|
std::size_t height = image.height();
|
||||||
|
|
||||||
std::size_t start_y=(y0/rows_per_strip_)*rows_per_strip_;
|
std::size_t start_y = (y0 / rows_per_strip_) * rows_per_strip_;
|
||||||
std::size_t end_y=std::min(y0+height, height_);
|
std::size_t end_y = std::min(y0 + height, height_);
|
||||||
std::size_t tx0,tx1,ty0,ty1;
|
std::size_t tx0, tx1, ty0, ty1;
|
||||||
|
|
||||||
tx0=x0;
|
tx0 = x0;
|
||||||
tx1=std::min(width+x0,width_);
|
tx1 = std::min(width + x0, width_);
|
||||||
std::size_t row = 0;
|
std::size_t row = 0;
|
||||||
for (std::size_t y=start_y; y < end_y; y+=rows_per_strip_)
|
bool pick_first_band = (bands_ > 1) && (strip_size / (width_ * rows_per_strip_ * sizeof(pixel_type)) == bands_);
|
||||||
|
for (std::size_t y = start_y; y < end_y; y += rows_per_strip_)
|
||||||
{
|
{
|
||||||
ty0 = std::max(y0,y)-y;
|
ty0 = std::max(y0, y) - y;
|
||||||
ty1 = std::min(end_y,y+rows_per_strip_)-y;
|
ty1 = std::min(end_y, y + rows_per_strip_) - y;
|
||||||
|
|
||||||
if (!TIFFReadRGBAStrip(tif,y,strip.data()))
|
if (!detail::tiff_reader_traits<ImageData>::read_strip(tif, y, rows_per_strip_, width_, strip.get()))
|
||||||
{
|
{
|
||||||
MAPNIK_LOG_DEBUG(tiff_reader) << "TIFFReadRGBAStrip failed at " << y << " for " << width_ << "/" << height_ << "\n";
|
MAPNIK_LOG_DEBUG(tiff_reader) << "TIFFRead(Encoded|RGBA)Strip failed at " << y << " for " << width_ << "/" << height_ << "\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// This is in reverse because the TIFFReadRGBAStrip reads inverted
|
if (pick_first_band)
|
||||||
for (std::size_t ty = ty1; ty > ty0; --ty)
|
|
||||||
{
|
{
|
||||||
image.set_row(row,tx0-x0,tx1-x0,&strip.data()[(ty-1)*width_+tx0]);
|
std::uint32_t size = width_ * rows_per_strip_ * sizeof(pixel_type);
|
||||||
++row;
|
for (std::uint32_t n = 0; n < size; ++n)
|
||||||
|
{
|
||||||
|
strip[n] = strip[bands_ * n];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detail::tiff_reader_traits<ImageData>::reverse)
|
||||||
|
{
|
||||||
|
std::size_t num_rows = std::min(end_y - y, static_cast<std::size_t>(rows_per_strip_));
|
||||||
|
for (std::size_t ty = ty0; ty < ty1; ++ty)
|
||||||
|
{
|
||||||
|
// This is in reverse because the TIFFReadRGBAStrip reads are inverted
|
||||||
|
image.set_row(row++, tx0 - x0, tx1 - x0, &strip[(num_rows - ty - 1) * width_ + tx0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (std::size_t ty = ty0; ty < ty1; ++ty)
|
||||||
|
{
|
||||||
|
image.set_row(row++, tx0 - x0, tx1 - x0, &strip[ty * width_ + tx0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4035e34534d6f0ad7060fc4a2f5f6018c61d7a1b
|
Subproject commit da43561d111b3539c09dbb9622fb0743e2d99973
|
|
@ -1 +1 @@
|
||||||
Subproject commit 34648ac6941c09b19919822c867378d1f30915c9
|
Subproject commit c3879224d25d01571e8e803180ae15c31bbf6b24
|
|
@ -5,280 +5,398 @@
|
||||||
|
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
#include <mapnik/color.hpp>
|
||||||
|
#include <mapnik/image_util.hpp>
|
||||||
|
#include <mapnik/image_view.hpp>
|
||||||
#include <mapnik/image_reader.hpp>
|
#include <mapnik/image_reader.hpp>
|
||||||
#include <mapnik/util/file_io.hpp>
|
#include <mapnik/util/file_io.hpp>
|
||||||
|
#include <mapnik/util/fs.hpp>
|
||||||
|
|
||||||
#include "../../../src/tiff_reader.cpp"
|
#include "../../../src/tiff_reader.cpp"
|
||||||
|
|
||||||
#define TIFF_ASSERT(filename) \
|
#define TIFF_ASSERT(filename) \
|
||||||
mapnik::tiff_reader<std::filebuf> tiff_reader(filename); \
|
mapnik::tiff_reader<std::filebuf> 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.planar_config() == PLANARCONFIG_CONTIG ); \
|
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG ); \
|
||||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff")); \
|
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff")); \
|
||||||
REQUIRE( reader->width() == 256 ); \
|
REQUIRE( reader->width() == 256 ); \
|
||||||
REQUIRE( reader->height() == 256 ); \
|
REQUIRE( reader->height() == 256 ); \
|
||||||
mapnik::util::file file(filename); \
|
mapnik::util::file file(filename); \
|
||||||
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size()); \
|
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size()); \
|
||||||
REQUIRE( tiff_reader2.width() == 256 ); \
|
REQUIRE( tiff_reader2.width() == 256 ); \
|
||||||
REQUIRE( tiff_reader2.height() == 256 ); \
|
REQUIRE( tiff_reader2.height() == 256 ); \
|
||||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size())); \
|
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size())); \
|
||||||
REQUIRE( reader2->width() == 256 ); \
|
REQUIRE( reader2->width() == 256 ); \
|
||||||
REQUIRE( reader2->height() == 256 ); \
|
REQUIRE( reader2->height() == 256 ); \
|
||||||
|
|
||||||
#define TIFF_ASSERT_ALPHA( data ) \
|
#define TIFF_ASSERT_ALPHA( data ) \
|
||||||
REQUIRE( tiff_reader.has_alpha() == true ); \
|
REQUIRE( tiff_reader.has_alpha() == true ); \
|
||||||
REQUIRE( reader->has_alpha() == true ); \
|
REQUIRE( reader->has_alpha() == true ); \
|
||||||
REQUIRE( tiff_reader2.has_alpha() == true ); \
|
REQUIRE( tiff_reader2.has_alpha() == true ); \
|
||||||
REQUIRE( reader2->has_alpha() == true ); \
|
REQUIRE( reader2->has_alpha() == true ); \
|
||||||
REQUIRE( data.get_premultiplied() == true ); \
|
REQUIRE( data.get_premultiplied() == true ); \
|
||||||
|
|
||||||
#define TIFF_ASSERT_NO_ALPHA_RGB( data ) \
|
#define TIFF_ASSERT_NO_ALPHA_RGB( data ) \
|
||||||
REQUIRE( tiff_reader.has_alpha() == false ); \
|
REQUIRE( tiff_reader.has_alpha() == false ); \
|
||||||
REQUIRE( reader->has_alpha() == false ); \
|
REQUIRE( reader->has_alpha() == false ); \
|
||||||
REQUIRE( tiff_reader2.has_alpha() == false ); \
|
REQUIRE( tiff_reader2.has_alpha() == false ); \
|
||||||
REQUIRE( reader2->has_alpha() == false ); \
|
REQUIRE( reader2->has_alpha() == false ); \
|
||||||
REQUIRE( data.get_premultiplied() == true ); \
|
REQUIRE( data.get_premultiplied() == true ); \
|
||||||
|
|
||||||
#define TIFF_ASSERT_NO_ALPHA_GRAY( data ) \
|
#define TIFF_ASSERT_NO_ALPHA_GRAY( data ) \
|
||||||
REQUIRE( tiff_reader.has_alpha() == false ); \
|
REQUIRE( tiff_reader.has_alpha() == false ); \
|
||||||
REQUIRE( reader->has_alpha() == false ); \
|
REQUIRE( reader->has_alpha() == false ); \
|
||||||
REQUIRE( tiff_reader2.has_alpha() == false ); \
|
REQUIRE( tiff_reader2.has_alpha() == false ); \
|
||||||
REQUIRE( reader2->has_alpha() == false ); \
|
REQUIRE( reader2->has_alpha() == false ); \
|
||||||
REQUIRE( data.get_premultiplied() == false ); \
|
REQUIRE( data.get_premultiplied() == false ); \
|
||||||
|
|
||||||
#define TIFF_ASSERT_SIZE( data,reader ) \
|
#define TIFF_ASSERT_SIZE( data,reader ) \
|
||||||
REQUIRE( data.width() == reader->width() ); \
|
REQUIRE( data.width() == reader->width() ); \
|
||||||
REQUIRE( data.height() == reader->height() ); \
|
REQUIRE( data.height() == reader->height() ); \
|
||||||
|
|
||||||
#define TIFF_READ_ONE_PIXEL \
|
#define TIFF_READ_ONE_PIXEL \
|
||||||
mapnik::image_any subimage = reader->read(1, 1, 1, 1); \
|
mapnik::image_any subimage = reader->read(1, 1, 1, 1); \
|
||||||
REQUIRE( subimage.width() == 1 ); \
|
REQUIRE( subimage.width() == 1 ); \
|
||||||
REQUIRE( subimage.height() == 1 ); \
|
REQUIRE( subimage.height() == 1 ); \
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
template <typename Image>
|
||||||
|
struct test_image_traits
|
||||||
|
{
|
||||||
|
using value_type = mapnik::color;
|
||||||
|
static value_type const& get_value(mapnik::color const& c)
|
||||||
|
{
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct test_image_traits<mapnik::image_gray8>
|
||||||
|
{
|
||||||
|
using value_type = std::uint8_t;
|
||||||
|
static value_type get_value(mapnik::color const& c)
|
||||||
|
{
|
||||||
|
return c.green(); // use green channel for gray scale images
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Image>
|
||||||
|
Image generate_test_image()
|
||||||
|
{
|
||||||
|
|
||||||
|
std::size_t tile_size = 16;
|
||||||
|
Image im(64, 64);
|
||||||
|
mapnik::color colors[] = {{mapnik::color("red")},
|
||||||
|
{mapnik::color("blue")},
|
||||||
|
{mapnik::color("green")},
|
||||||
|
{mapnik::color("yellow")}};
|
||||||
|
std::size_t index = 0;
|
||||||
|
for (std::size_t j = 0; j < im.height()/tile_size; ++j)
|
||||||
|
{
|
||||||
|
++index;
|
||||||
|
for (std::size_t i = 0; i < im.width()/tile_size; ++i)
|
||||||
|
{
|
||||||
|
++index;
|
||||||
|
for (std::size_t x = 0; x < tile_size; ++x)
|
||||||
|
{
|
||||||
|
for (std::size_t y = 0; y < tile_size; ++y)
|
||||||
|
{
|
||||||
|
auto value = test_image_traits<Image>::get_value(colors[index % 4]);
|
||||||
|
mapnik::set_pixel(im, i * tile_size + x, j * tile_size + y, value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return im;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Image1, typename Image2>
|
||||||
|
bool identical(Image1 const& im1, Image2 const& im2)
|
||||||
|
{
|
||||||
|
if ((im1.width() != im2.width()) || (im1.height() != im2.height()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < im1.width(); ++i)
|
||||||
|
{
|
||||||
|
for (std::size_t j = 0; j < im1.height(); ++j)
|
||||||
|
{
|
||||||
|
if (im1(i,j) != im2(i,j)) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Image>
|
||||||
|
void test_tiff_reader(std::string const& pattern)
|
||||||
|
{
|
||||||
|
// generate expected image (rgba8 or gray8)
|
||||||
|
auto im = generate_test_image<Image>();
|
||||||
|
|
||||||
|
for (auto const& path : mapnik::util::list_directory("test/data/tiff/"))
|
||||||
|
{
|
||||||
|
if (boost::iends_with(path,".tif")
|
||||||
|
&& boost::istarts_with(mapnik::util::basename(path), pattern))
|
||||||
|
{
|
||||||
|
mapnik::tiff_reader<std::filebuf> tiff_reader(path);
|
||||||
|
auto width = tiff_reader.width();
|
||||||
|
auto height = tiff_reader.height();
|
||||||
|
{
|
||||||
|
// whole image
|
||||||
|
auto tiff = tiff_reader.read(0, 0, width, height);
|
||||||
|
CHECK(tiff.is<Image>());
|
||||||
|
auto im2 = tiff.get<Image>();
|
||||||
|
REQUIRE(identical(im, im2));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// portion
|
||||||
|
auto tiff = tiff_reader.read(11, 13, width - 11, height - 13);
|
||||||
|
CHECK(tiff.is<Image>());
|
||||||
|
auto im2 = tiff.get<Image>();
|
||||||
|
auto view = mapnik::image_view<Image>(11, 13, width, height, im);
|
||||||
|
REQUIRE(identical(view, im2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("tiff io")
|
TEST_CASE("tiff io")
|
||||||
{
|
{
|
||||||
|
SECTION("tiff-reader rgb8+rgba8")
|
||||||
|
{
|
||||||
|
test_tiff_reader<mapnik::image_rgba8>("tiff_rgb");
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("scan rgb8 striped")
|
SECTION("tiff-reader gray8")
|
||||||
{
|
{
|
||||||
std::string filename("./test/data/tiff/scan_512x512_rgb8_striped.tif");
|
test_tiff_reader<mapnik::image_gray8>("tiff_gray");
|
||||||
mapnik::tiff_reader<std::filebuf> tiff_reader(filename);
|
}
|
||||||
REQUIRE( tiff_reader.width() == 512 );
|
|
||||||
REQUIRE( tiff_reader.height() == 512 );
|
|
||||||
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG );
|
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 16 );
|
|
||||||
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 );
|
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_PALETTE );
|
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
|
||||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff"));
|
|
||||||
REQUIRE( reader->width() == 512 );
|
|
||||||
REQUIRE( reader->height() == 512 );
|
|
||||||
mapnik::util::file file(filename);
|
|
||||||
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size());
|
|
||||||
REQUIRE( tiff_reader2.width() == 512 );
|
|
||||||
REQUIRE( tiff_reader2.height() == 512 );
|
|
||||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size()));
|
|
||||||
REQUIRE( reader2->width() == 512 );
|
|
||||||
REQUIRE( reader2->height() == 512 );
|
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
|
||||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
|
||||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
|
||||||
TIFF_READ_ONE_PIXEL
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("scan rgb8 tiled") {
|
SECTION("scan rgb8 striped")
|
||||||
std::string filename("./test/data/tiff/scan_512x512_rgb8_tiled.tif");
|
{
|
||||||
mapnik::tiff_reader<std::filebuf> tiff_reader(filename);
|
std::string filename("./test/data/tiff/scan_512x512_rgb8_striped.tif");
|
||||||
REQUIRE( tiff_reader.width() == 512 );
|
mapnik::tiff_reader<std::filebuf> tiff_reader(filename);
|
||||||
REQUIRE( tiff_reader.height() == 512 );
|
REQUIRE( tiff_reader.width() == 512 );
|
||||||
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG );
|
REQUIRE( tiff_reader.height() == 512 );
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG );
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
REQUIRE( tiff_reader.rows_per_strip() == 16 );
|
||||||
REQUIRE( tiff_reader.is_tiled() == true );
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_PALETTE );
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_PALETTE );
|
||||||
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff"));
|
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||||
REQUIRE( reader->width() == 512 );
|
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff"));
|
||||||
REQUIRE( reader->height() == 512 );
|
REQUIRE( reader->width() == 512 );
|
||||||
mapnik::util::file file(filename);
|
REQUIRE( reader->height() == 512 );
|
||||||
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size());
|
mapnik::util::file file(filename);
|
||||||
REQUIRE( tiff_reader2.width() == 512 );
|
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size());
|
||||||
REQUIRE( tiff_reader2.height() == 512 );
|
REQUIRE( tiff_reader2.width() == 512 );
|
||||||
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size()));
|
REQUIRE( tiff_reader2.height() == 512 );
|
||||||
REQUIRE( reader2->width() == 512 );
|
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size()));
|
||||||
REQUIRE( reader2->height() == 512 );
|
REQUIRE( reader2->width() == 512 );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
REQUIRE( reader2->height() == 512 );
|
||||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
TIFF_READ_ONE_PIXEL
|
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||||
}
|
TIFF_READ_ONE_PIXEL
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("rgba8 striped") {
|
SECTION("scan rgb8 tiled") {
|
||||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgba8_striped.tif")
|
std::string filename("./test/data/tiff/scan_512x512_rgb8_tiled.tif");
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 1 );
|
mapnik::tiff_reader<std::filebuf> tiff_reader(filename);
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
REQUIRE( tiff_reader.width() == 512 );
|
||||||
REQUIRE( tiff_reader.is_tiled() == false );
|
REQUIRE( tiff_reader.height() == 512 );
|
||||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
REQUIRE( tiff_reader.planar_config() == PLANARCONFIG_CONTIG );
|
||||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_ADOBE_DEFLATE );
|
REQUIRE( tiff_reader.is_tiled() == true );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_PALETTE );
|
||||||
TIFF_ASSERT_ALPHA( data );
|
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||||
TIFF_READ_ONE_PIXEL
|
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"tiff"));
|
||||||
}
|
REQUIRE( reader->width() == 512 );
|
||||||
|
REQUIRE( reader->height() == 512 );
|
||||||
|
mapnik::util::file file(filename);
|
||||||
|
mapnik::tiff_reader<mapnik::util::char_array_buffer> tiff_reader2(file.data().get(),file.size());
|
||||||
|
REQUIRE( tiff_reader2.width() == 512 );
|
||||||
|
REQUIRE( tiff_reader2.height() == 512 );
|
||||||
|
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(file.data().get(),file.size()));
|
||||||
|
REQUIRE( reader2->width() == 512 );
|
||||||
|
REQUIRE( reader2->height() == 512 );
|
||||||
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
|
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||||
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
|
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||||
|
TIFF_READ_ONE_PIXEL
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("rgba8 tiled") {
|
SECTION("rgba8 striped") {
|
||||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgba8_tiled.tif")
|
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgba8_striped.tif")
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
REQUIRE( tiff_reader.rows_per_strip() == 1 );
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
REQUIRE( tiff_reader.is_tiled() == true );
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
REQUIRE( tiff_reader.compression() == COMPRESSION_ADOBE_DEFLATE );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
TIFF_ASSERT_ALPHA( data );
|
TIFF_ASSERT_ALPHA( data );
|
||||||
TIFF_READ_ONE_PIXEL
|
TIFF_READ_ONE_PIXEL
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("rgb8 striped") {
|
SECTION("rgba8 tiled") {
|
||||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgb8_striped.tif")
|
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgba8_tiled.tif")
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 10 );
|
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||||
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() == true );
|
||||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
TIFF_ASSERT_ALPHA( data );
|
||||||
TIFF_READ_ONE_PIXEL
|
TIFF_READ_ONE_PIXEL
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("rgb8 tiled") {
|
SECTION("rgb8 striped") {
|
||||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgb8_tiled.tif")
|
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgb8_striped.tif")
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
REQUIRE( tiff_reader.rows_per_strip() == 10 );
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
REQUIRE( tiff_reader.is_tiled() == true );
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||||
TIFF_READ_ONE_PIXEL
|
TIFF_READ_ONE_PIXEL
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("gray8 striped") {
|
SECTION("rgb8 tiled") {
|
||||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray8_striped.tif")
|
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_rgb8_tiled.tif")
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 32 );
|
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||||
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() == true );
|
||||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
REQUIRE( tiff_reader.tile_width() == 32 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
REQUIRE( tiff_reader.tile_height() == 32 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_RGB );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
REQUIRE( data.is<mapnik::image_gray8>() == true );
|
REQUIRE( data.is<mapnik::image_rgba8>() == true );
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||||
TIFF_READ_ONE_PIXEL
|
TIFF_READ_ONE_PIXEL
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("gray8 tiled") {
|
SECTION("gray8 striped") {
|
||||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray8_tiled.tif")
|
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray8_striped.tif")
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
REQUIRE( tiff_reader.rows_per_strip() == 32 );
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
REQUIRE( tiff_reader.is_tiled() == true );
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
REQUIRE( data.is<mapnik::image_gray8>() == true );
|
REQUIRE( data.is<mapnik::image_gray8>() == true );
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||||
TIFF_READ_ONE_PIXEL
|
TIFF_READ_ONE_PIXEL
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("gray16 striped") {
|
SECTION("gray8 tiled") {
|
||||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray16_striped.tif")
|
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray8_tiled.tif")
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 16 );
|
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
REQUIRE( tiff_reader.bits_per_sample() == 8 );
|
||||||
REQUIRE( tiff_reader.is_tiled() == false );
|
REQUIRE( tiff_reader.is_tiled() == true );
|
||||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
REQUIRE( data.is<mapnik::image_gray16>() == true );
|
REQUIRE( data.is<mapnik::image_gray8>() == true );
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||||
TIFF_READ_ONE_PIXEL
|
TIFF_READ_ONE_PIXEL
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("gray16 tiled") {
|
SECTION("gray16 striped") {
|
||||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray16_tiled.tif")
|
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray16_striped.tif")
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
REQUIRE( tiff_reader.rows_per_strip() == 16 );
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
||||||
REQUIRE( tiff_reader.is_tiled() == true );
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
REQUIRE( data.is<mapnik::image_gray16>() == true );
|
REQUIRE( data.is<mapnik::image_gray16>() == true );
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||||
TIFF_READ_ONE_PIXEL
|
TIFF_READ_ONE_PIXEL
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("gray32f striped") {
|
SECTION("gray16 tiled") {
|
||||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray32f_striped.tif")
|
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray16_tiled.tif")
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 8 );
|
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 32 );
|
REQUIRE( tiff_reader.bits_per_sample() == 16 );
|
||||||
REQUIRE( tiff_reader.is_tiled() == false );
|
REQUIRE( tiff_reader.is_tiled() == true );
|
||||||
REQUIRE( tiff_reader.tile_width() == 0 );
|
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 0 );
|
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
REQUIRE( data.is<mapnik::image_gray32f>() == true );
|
REQUIRE( data.is<mapnik::image_gray16>() == true );
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||||
TIFF_READ_ONE_PIXEL
|
TIFF_READ_ONE_PIXEL
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("gray32f tiled") {
|
SECTION("gray32f striped") {
|
||||||
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray32f_tiled.tif")
|
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray32f_striped.tif")
|
||||||
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
REQUIRE( tiff_reader.rows_per_strip() == 8 );
|
||||||
REQUIRE( tiff_reader.bits_per_sample() == 32 );
|
REQUIRE( tiff_reader.bits_per_sample() == 32 );
|
||||||
REQUIRE( tiff_reader.is_tiled() == true );
|
REQUIRE( tiff_reader.is_tiled() == false );
|
||||||
REQUIRE( tiff_reader.tile_width() == 256 );
|
REQUIRE( tiff_reader.tile_width() == 0 );
|
||||||
REQUIRE( tiff_reader.tile_height() == 256 );
|
REQUIRE( tiff_reader.tile_height() == 0 );
|
||||||
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||||
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
REQUIRE( tiff_reader.compression() == COMPRESSION_NONE );
|
||||||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
REQUIRE( data.is<mapnik::image_gray32f>() == true );
|
REQUIRE( data.is<mapnik::image_gray32f>() == true );
|
||||||
TIFF_ASSERT_SIZE( data,reader );
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||||
TIFF_READ_ONE_PIXEL
|
TIFF_READ_ONE_PIXEL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("gray32f tiled") {
|
||||||
|
TIFF_ASSERT("./test/data/tiff/ndvi_256x256_gray32f_tiled.tif")
|
||||||
|
REQUIRE( tiff_reader.rows_per_strip() == 0 );
|
||||||
|
REQUIRE( tiff_reader.bits_per_sample() == 32 );
|
||||||
|
REQUIRE( tiff_reader.is_tiled() == true );
|
||||||
|
REQUIRE( tiff_reader.tile_width() == 256 );
|
||||||
|
REQUIRE( tiff_reader.tile_height() == 256 );
|
||||||
|
REQUIRE( tiff_reader.photometric() == PHOTOMETRIC_MINISBLACK );
|
||||||
|
REQUIRE( tiff_reader.compression() == COMPRESSION_LZW );
|
||||||
|
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||||
|
REQUIRE( data.is<mapnik::image_gray32f>() == true );
|
||||||
|
TIFF_ASSERT_SIZE( data,reader );
|
||||||
|
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||||
|
TIFF_READ_ONE_PIXEL
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue