make bounding_box return optional<box2d<double>> to be consistent with current behavour
This commit is contained in:
parent
2efde962aa
commit
74c96f0bda
5 changed files with 36 additions and 13 deletions
|
@ -60,7 +60,7 @@ struct MAPNIK_DECL image_reader : private mapnik::noncopyable
|
|||
virtual unsigned height() const = 0;
|
||||
virtual bool has_alpha() const = 0;
|
||||
virtual bool premultiplied_alpha() const = 0;
|
||||
virtual box2d<double> bounding_box() const = 0;
|
||||
virtual boost::optional<box2d<double> > bounding_box() const = 0;
|
||||
virtual void read(unsigned x,unsigned y,image_data_rgba8& image) = 0;
|
||||
virtual image_data_any read(unsigned x, unsigned y, unsigned width, unsigned height) = 0;
|
||||
virtual ~image_reader() {}
|
||||
|
|
|
@ -83,7 +83,7 @@ public:
|
|||
~jpeg_reader();
|
||||
unsigned width() const final;
|
||||
unsigned height() const final;
|
||||
box2d<double> bounding_box() const final;
|
||||
boost::optional<box2d<double> > bounding_box() const final;
|
||||
inline bool has_alpha() const final { return false; }
|
||||
inline bool premultiplied_alpha() const final { return true; }
|
||||
void read(unsigned x,unsigned y,image_data_rgba8& image) final;
|
||||
|
@ -260,9 +260,9 @@ unsigned jpeg_reader<T>::height() const
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
box2d<double> jpeg_reader<T>::bounding_box() const
|
||||
boost::optional<box2d<double> > jpeg_reader<T>::bounding_box() const
|
||||
{
|
||||
return box2d<double>(0, 0, width_, height_);
|
||||
return boost::optional<box2d<double> >();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
~png_reader();
|
||||
unsigned width() const final;
|
||||
unsigned height() const final;
|
||||
box2d<double> bounding_box() const final;
|
||||
boost::optional<box2d<double> > bounding_box() const final;
|
||||
inline bool has_alpha() const final { return has_alpha_; }
|
||||
bool premultiplied_alpha() const final { return false; } //http://www.libpng.org/pub/png/spec/1.1/PNG-Rationale.html
|
||||
void read(unsigned x,unsigned y,image_data_rgba8& image) final;
|
||||
|
@ -221,9 +221,9 @@ unsigned png_reader<T>::height() const
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
box2d<double> png_reader<T>::bounding_box() const
|
||||
boost::optional<box2d<double> > png_reader<T>::bounding_box() const
|
||||
{
|
||||
return box2d<double>(0, 0, width_, height_);
|
||||
return boost::optional<box2d<double> >();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -130,6 +130,7 @@ private:
|
|||
int tile_height_;
|
||||
std::size_t width_;
|
||||
std::size_t height_;
|
||||
boost::optional<box2d<double> > bbox_;
|
||||
unsigned bps_;
|
||||
unsigned photometric_;
|
||||
unsigned bands_;
|
||||
|
@ -150,7 +151,7 @@ public:
|
|||
virtual ~tiff_reader();
|
||||
unsigned width() const final;
|
||||
unsigned height() const final;
|
||||
box2d<double> bounding_box() const final;
|
||||
boost::optional<box2d<double> > bounding_box() const final;
|
||||
inline bool has_alpha() const final { return has_alpha_; }
|
||||
bool premultiplied_alpha() const final;
|
||||
void read(unsigned x,unsigned y,image_data_rgba8& image) final;
|
||||
|
@ -312,6 +313,28 @@ void tiff_reader<T>::init()
|
|||
premultiplied_alpha_ = true;
|
||||
}
|
||||
}
|
||||
// Try extracting bounding box from geoTIFF tags
|
||||
{
|
||||
uint16 count = 0;
|
||||
double *pixelscale;
|
||||
double *tilepoint;
|
||||
if (TIFFGetField(tif, 33550, &count, &pixelscale) == 1 && count == 3
|
||||
&& 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) << "TilePoint:" << tilepoint[0] << "," << tilepoint[1] << "," << tilepoint[2];
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << " " << tilepoint[3] << "," << tilepoint[4] << "," << tilepoint[5];
|
||||
|
||||
// assuming upper-left
|
||||
double lox = tilepoint[3];
|
||||
double loy = tilepoint[4];
|
||||
double hix = lox + pixelscale[0] * width_;
|
||||
double hiy = loy + pixelscale[1] * height_;
|
||||
bbox_.reset(box2d<double>(lox, loy, hix, hiy));
|
||||
MAPNIK_LOG_DEBUG(tiff_reader) << "Bounding Box:" << *bbox_;
|
||||
}
|
||||
|
||||
}
|
||||
if (!is_tiled_ &&
|
||||
compression_ == COMPRESSION_NONE &&
|
||||
planar_config_ == PLANARCONFIG_CONTIG)
|
||||
|
@ -348,9 +371,9 @@ unsigned tiff_reader<T>::height() const
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
box2d<double> tiff_reader<T>::bounding_box() const
|
||||
boost::optional<box2d<double> > tiff_reader<T>::bounding_box() const
|
||||
{
|
||||
return box2d<double>(0, 0, width_, height_);
|
||||
return bbox_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -122,7 +122,7 @@ public:
|
|||
~webp_reader();
|
||||
unsigned width() const final;
|
||||
unsigned height() const final;
|
||||
box2d<double> bounding_box() const final;
|
||||
boost::optional<box2d<double> > bounding_box() const final;
|
||||
inline bool has_alpha() const final { return has_alpha_; }
|
||||
bool premultiplied_alpha() const final { return false; }
|
||||
void read(unsigned x,unsigned y,image_data_rgba8& image) final;
|
||||
|
@ -231,9 +231,9 @@ unsigned webp_reader<T>::height() const
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
box2d<double> webp_reader<T>::bounding_box() const
|
||||
boost::optional<box2d<double> > webp_reader<T>::bounding_box() const
|
||||
{
|
||||
return box2d<double>(0, 0, width_, height_);
|
||||
return boost::optional<box2d<double> >();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
Loading…
Add table
Reference in a new issue