+ 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
This commit is contained in:
parent
02e7aef9c9
commit
77e585895f
4 changed files with 21 additions and 2 deletions
|
@ -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() {}
|
||||
};
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
~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();
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
~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();
|
||||
|
|
|
@ -64,7 +64,7 @@ private:
|
|||
int tile_width_;
|
||||
int tile_height_;
|
||||
tiff_ptr tif_;
|
||||
|
||||
bool premultiplied_alpha_;
|
||||
public:
|
||||
enum TiffType {
|
||||
generic=1,
|
||||
|
@ -75,6 +75,7 @@ public:
|
|||
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;
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue