Permalink
Browse files

+ add premultiplied_alpha method to image_reader

  * tiff - TIFFTAG_EXTRASAMPLES
  * png  - non-premultiplied alpha (http://www.libpng.org/pub/png/spec/1.1/PNG-Rationale.html)
  * jpeg - no-alpha channel, ensure pre-multiplied model
  • Loading branch information...
1 parent 02e7aef commit 77e585895fc8a7e4e178808fa6f5641736986603 @artemp artemp committed Sep 28, 2012
Showing with 21 additions and 2 deletions.
  1. +1 −0 include/mapnik/image_reader.hpp
  2. +1 −0 src/jpeg_reader.cpp
  3. +1 −0 src/png_reader.cpp
  4. +18 −2 src/tiff_reader.cpp
@@ -53,6 +53,7 @@ struct MAPNIK_DECL image_reader
{
virtual unsigned width() const=0;
virtual unsigned height() const=0;
+ virtual bool premultiplied_alpha() const=0;
virtual void read(unsigned x,unsigned y,image_data_32& image)=0;
virtual ~image_reader() {}
};
View
@@ -50,6 +50,7 @@ class JpegReader : public image_reader, boost::noncopyable
~JpegReader();
unsigned width() const;
unsigned height() const;
+ inline bool premultiplied_alpha() const { return true ;}
void read(unsigned x,unsigned y,image_data_32& image);
private:
void init();
View
@@ -46,6 +46,7 @@ class png_reader : public image_reader, boost::noncopyable
~png_reader();
unsigned width() const;
unsigned height() const;
+ 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:
void init();
View
@@ -64,7 +64,7 @@ class tiff_reader : public image_reader
int tile_width_;
int tile_height_;
tiff_ptr tif_;
-
+ bool premultiplied_alpha_;
public:
enum TiffType {
generic=1,
@@ -75,6 +75,7 @@ class tiff_reader : public image_reader
virtual ~tiff_reader();
unsigned width() const;
unsigned height() const;
+ bool premultiplied_alpha() const;
void read(unsigned x,unsigned y,image_data_32& image);
private:
tiff_reader(const tiff_reader&);
@@ -103,7 +104,8 @@ tiff_reader::tiff_reader(std::string const& file_name)
height_(0),
rows_per_strip_(0),
tile_width_(0),
- tile_height_(0)
+ tile_height_(0),
+ premultiplied_alpha_(false)
{
init();
}
@@ -132,6 +134,16 @@ void tiff_reader::init()
{
read_method_=stripped;
}
+ //TIFFTAG_EXTRASAMPLES
+ uint16 extrasamples;
+ uint16* sampleinfo;
+ TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
+ &extrasamples, &sampleinfo);
+ if (extrasamples == 1 &&
+ sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA)
+ {
+ premultiplied_alpha_ = true;
@springmeyer

springmeyer Sep 29, 2012

Owner

It looks like assuming this is correct may cause more trouble than we will like because gdal apparently has been mis-setting this for a long time: http://lists.osgeo.org/pipermail/gdal-dev/2012-May/032984.html. Ugh.

@springmeyer

springmeyer Sep 29, 2012

Owner

So, I think there is no problem with keeping this handling code. But we may be best off not acting upon it.

+ }
}
else
{
@@ -156,6 +168,10 @@ unsigned tiff_reader::height() const
return height_;
}
+bool tiff_reader::premultiplied_alpha() const
+{
+ return premultiplied_alpha_;
+}
void tiff_reader::read(unsigned x,unsigned y,image_data_32& image)
{

1 comment on commit 77e5858

Owner

springmeyer commented on 77e5858 Sep 28, 2012

see #1508, #1511, #1512

Please sign in to comment.