diff --git a/include/mapnik/image_reader.hpp b/include/mapnik/image_reader.hpp index a3a6545e7..e571ba0b1 100644 --- a/include/mapnik/image_reader.hpp +++ b/include/mapnik/image_reader.hpp @@ -57,6 +57,7 @@ struct MAPNIK_DECL image_reader : private mapnik::noncopyable { virtual unsigned width() const=0; virtual unsigned height() const=0; + virtual bool has_alpha() const=0; virtual bool premultiplied_alpha() const=0; virtual void read(unsigned x,unsigned y,image_data_32& image)=0; virtual ~image_reader() {} diff --git a/src/jpeg_reader.cpp b/src/jpeg_reader.cpp index efcf4373c..6e52b308e 100644 --- a/src/jpeg_reader.cpp +++ b/src/jpeg_reader.cpp @@ -80,6 +80,7 @@ public: ~jpeg_reader(); unsigned width() const; unsigned height() const; + inline bool has_alpha() const { return false; } inline bool premultiplied_alpha() const { return true; } void read(unsigned x,unsigned y,image_data_32& image); private: diff --git a/src/png_reader.cpp b/src/png_reader.cpp index 93631d3a7..eaa8a7483 100644 --- a/src/png_reader.cpp +++ b/src/png_reader.cpp @@ -69,12 +69,14 @@ private: unsigned height_; int bit_depth_; int color_type_; + bool has_alpha_; public: explicit png_reader(std::string const& file_name); png_reader(char const* data, std::size_t size); ~png_reader(); unsigned width() const; unsigned height() const; + inline bool has_alpha() const { return has_alpha_; } bool premultiplied_alpha() const { return false; } //http://www.libpng.org/pub/png/spec/1.1/PNG-Rationale.html void read(unsigned x,unsigned y,image_data_32& image); private: @@ -129,7 +131,8 @@ png_reader::png_reader(std::string const& file_name) width_(0), height_(0), bit_depth_(0), - color_type_(0) + color_type_(0), + has_alpha_(false) { if (!source_.is_open()) throw image_reader_exception("PNG reader: cannot open file '"+ file_name + "'"); if (!stream_) throw image_reader_exception("PNG reader: cannot open file '"+ file_name + "'"); @@ -143,7 +146,8 @@ png_reader::png_reader(char const* data, std::size_t size) width_(0), height_(0), bit_depth_(0), - color_type_(0) + color_type_(0), + has_alpha_(false) { if (!stream_) throw image_reader_exception("PNG reader: cannot open image stream"); @@ -193,7 +197,7 @@ void png_reader::init() png_uint_32 width, height; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth_, &color_type_,0,0,0); - + has_alpha_ = (color_type_ & PNG_COLOR_MASK_ALPHA) || png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS); width_=width; height_=height; diff --git a/src/tiff_reader.cpp b/src/tiff_reader.cpp index 7b3fad6a3..f0756bd29 100644 --- a/src/tiff_reader.cpp +++ b/src/tiff_reader.cpp @@ -139,6 +139,7 @@ public: virtual ~tiff_reader(); unsigned width() const; unsigned height() const; + inline bool has_alpha() const { return false; /*FIXME*/ } bool premultiplied_alpha() const; void read(unsigned x,unsigned y,image_data_32& image); private: diff --git a/src/webp_reader.cpp b/src/webp_reader.cpp index dbb86fee2..fd88d84e8 100644 --- a/src/webp_reader.cpp +++ b/src/webp_reader.cpp @@ -108,12 +108,14 @@ private: size_t size_; unsigned width_; unsigned height_; + bool has_alpha_; public: explicit webp_reader(char const* data, std::size_t size); explicit webp_reader(std::string const& filename); ~webp_reader(); unsigned width() const; unsigned height() const; + inline bool has_alpha() const { return has_alpha_; } bool premultiplied_alpha() const { return false; } void read(unsigned x,unsigned y,image_data_32& image); private: @@ -143,7 +145,8 @@ template webp_reader::webp_reader(char const* data, std::size_t size) : buffer_(new buffer_policy_type(reinterpret_cast(data), size)), width_(0), - height_(0) + height_(0), + has_alpha_(false) { init(); } @@ -153,7 +156,8 @@ webp_reader::webp_reader(std::string const& filename) : buffer_(nullptr), size_(0), width_(0), - height_(0) + height_(0), + has_alpha_(false) { std::ifstream file(filename.c_str(), std::ios::binary); if (!file) @@ -199,6 +203,10 @@ void webp_reader::init() height_ = config.input.height; has_alpha_ = config.input.has_alpha; } + else + { + throw image_reader_exception("WEBP reader: WebPGetFeatures failed"); + } } template