|
@ -57,17 +57,39 @@ void export_color ()
|
|||
"and an alpha value.\n"
|
||||
"All values between 0 and 255.\n")
|
||||
)
|
||||
.def(init<int,int,int,int,bool>(
|
||||
( arg("r"), arg("g"), arg("b"), arg("a"), arg("premultiplied") ),
|
||||
"Creates a new color from its RGB components\n"
|
||||
"and an alpha value.\n"
|
||||
"All values between 0 and 255.\n")
|
||||
)
|
||||
.def(init<int,int,int>(
|
||||
( arg("r"), arg("g"), arg("b") ),
|
||||
"Creates a new color from its RGB components.\n"
|
||||
"All values between 0 and 255.\n")
|
||||
)
|
||||
.def(init<uint32_t>(
|
||||
( arg("val") ),
|
||||
"Creates a new color from an unsigned integer.\n"
|
||||
"All values between 0 and 2^32-1\n")
|
||||
)
|
||||
.def(init<uint32_t, bool>(
|
||||
( arg("val"), arg("premultiplied") ),
|
||||
"Creates a new color from an unsigned integer.\n"
|
||||
"All values between 0 and 2^32-1\n")
|
||||
)
|
||||
.def(init<std::string>(
|
||||
( arg("color_string") ),
|
||||
"Creates a new color from its CSS string representation.\n"
|
||||
"The string may be a CSS color name (e.g. 'blue')\n"
|
||||
"or a hex color string (e.g. '#0000ff').\n")
|
||||
)
|
||||
.def(init<std::string, bool>(
|
||||
( arg("color_string"), arg("premultiplied") ),
|
||||
"Creates a new color from its CSS string representation.\n"
|
||||
"The string may be a CSS color name (e.g. 'blue')\n"
|
||||
"or a hex color string (e.g. '#0000ff').\n")
|
||||
)
|
||||
.add_property("r",
|
||||
&color::red,
|
||||
&color::set_red,
|
||||
|
@ -92,6 +114,10 @@ void export_color ()
|
|||
.def(self != self)
|
||||
.def_pickle(color_pickle_suite())
|
||||
.def("__str__",&color::to_string)
|
||||
.def("set_premultiplied",&color::set_premultiplied)
|
||||
.def("get_premultiplied",&color::get_premultiplied)
|
||||
.def("premultiply",&color::premultiply)
|
||||
.def("demultiply",&color::demultiply)
|
||||
.def("packed",&color::rgba)
|
||||
.def("to_hex_string",&color::to_hex_string,
|
||||
"Returns the hexadecimal representation of this color.\n"
|
||||
|
|
|
@ -131,9 +131,9 @@ void background(mapnik::image_any & im, mapnik::color const& c)
|
|||
mapnik::fill(im, c);
|
||||
}
|
||||
|
||||
uint32_t get_pixel(mapnik::image_any const& im, int x, int y)
|
||||
uint32_t get_pixel(mapnik::image_any const& im, unsigned x, unsigned y)
|
||||
{
|
||||
if (x < static_cast<int>(im.width()) && y < static_cast<int>(im.height()))
|
||||
if (x < static_cast<unsigned>(im.width()) && y < static_cast<unsigned>(im.height()))
|
||||
{
|
||||
return mapnik::get_pixel<mapnik::image_any, uint32_t>(im, x, y);
|
||||
}
|
||||
|
@ -142,8 +142,25 @@ uint32_t get_pixel(mapnik::image_any const& im, int x, int y)
|
|||
return 0;
|
||||
}
|
||||
|
||||
mapnik::color get_pixel_color(mapnik::image_any const& im, unsigned x, unsigned y)
|
||||
{
|
||||
if (x < static_cast<unsigned>(im.width()) && y < static_cast<unsigned>(im.height()))
|
||||
{
|
||||
return mapnik::get_pixel<mapnik::image_any, mapnik::color>(im, x, y);
|
||||
}
|
||||
PyErr_SetString(PyExc_IndexError, "invalid x,y for image dimensions");
|
||||
boost::python::throw_error_already_set();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set_pixel(mapnik::image_any & im, unsigned x, unsigned y, mapnik::color const& c)
|
||||
{
|
||||
if (x >= static_cast<int>(im.width()) && y >= static_cast<int>(im.height()))
|
||||
{
|
||||
PyErr_SetString(PyExc_IndexError, "invalid x,y for image dimensions");
|
||||
boost::python::throw_error_already_set();
|
||||
return;
|
||||
}
|
||||
mapnik::set_pixel(im, x, y, c);
|
||||
}
|
||||
|
||||
|
@ -290,7 +307,18 @@ void export_image()
|
|||
.value("divide", mapnik::divide)
|
||||
;
|
||||
|
||||
class_<image_any,std::shared_ptr<image_any>, boost::noncopyable >("Image","This class represents a 32 bit RGBA image.",init<int,int>())
|
||||
enum_<mapnik::image_dtype>("ImageType")
|
||||
.value("rgba8", mapnik::image_dtype_rgba8)
|
||||
.value("gray8", mapnik::image_dtype_gray8)
|
||||
.value("gray16", mapnik::image_dtype_gray16)
|
||||
.value("gray32f", mapnik::image_dtype_gray32f)
|
||||
;
|
||||
|
||||
class_<image_any,std::shared_ptr<image_any>, boost::noncopyable >("Image","This class represents a image.",init<int,int>())
|
||||
.def(init<int,int,mapnik::image_dtype>())
|
||||
.def(init<int,int,mapnik::image_dtype,bool>())
|
||||
.def(init<int,int,mapnik::image_dtype,bool,bool>())
|
||||
.def(init<int,int,mapnik::image_dtype,bool,bool,bool>())
|
||||
.def("width",&image_any::width)
|
||||
.def("height",&image_any::height)
|
||||
.def("view",&get_view)
|
||||
|
@ -313,6 +341,7 @@ void export_image()
|
|||
.def("demultiply",&demultiply)
|
||||
.def("set_pixel",&set_pixel)
|
||||
.def("get_pixel",&get_pixel)
|
||||
.def("get_pixel_color",&get_pixel_color)
|
||||
.def("clear",&clear)
|
||||
//TODO(haoyu) The method name 'tostring' might be confusing since they actually return bytes in Python 3
|
||||
|
||||
|
|
|
@ -44,29 +44,39 @@ private:
|
|||
std::uint8_t green_;
|
||||
std::uint8_t blue_;
|
||||
std::uint8_t alpha_;
|
||||
|
||||
bool premultiplied_;
|
||||
public:
|
||||
// default ctor
|
||||
color()
|
||||
: red_(0xff),
|
||||
green_(0xff),
|
||||
blue_(0xff),
|
||||
alpha_(0xff)
|
||||
alpha_(0xff),
|
||||
premultiplied_(false)
|
||||
{}
|
||||
|
||||
color(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha = 0xff)
|
||||
color(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha = 0xff, bool premultiplied = false)
|
||||
: red_(red),
|
||||
green_(green),
|
||||
blue_(blue),
|
||||
alpha_(alpha)
|
||||
alpha_(alpha),
|
||||
premultiplied_(premultiplied)
|
||||
{}
|
||||
|
||||
color(std::uint32_t rgba, bool premultiplied = false)
|
||||
: red_(rgba & 0xff),
|
||||
green_((rgba >> 8) & 0xff),
|
||||
blue_((rgba >> 16) & 0xff),
|
||||
alpha_((rgba >> 24) & 0xff),
|
||||
premultiplied_(premultiplied) {}
|
||||
|
||||
// copy ctor
|
||||
color(const color& rhs)
|
||||
: red_(rhs.red_),
|
||||
green_(rhs.green_),
|
||||
blue_(rhs.blue_),
|
||||
alpha_(rhs.alpha_)
|
||||
alpha_(rhs.alpha_),
|
||||
premultiplied_(rhs.premultiplied_)
|
||||
{}
|
||||
|
||||
// move ctor
|
||||
|
@ -74,14 +84,15 @@ public:
|
|||
: red_(std::move(rhs.red_)),
|
||||
green_(std::move(rhs.green_)),
|
||||
blue_(std::move(rhs.blue_)),
|
||||
alpha_(std::move(rhs.alpha_)) {}
|
||||
alpha_(std::move(rhs.alpha_)),
|
||||
premultiplied_(std::move(rhs.premultiplied_)) {}
|
||||
|
||||
color( std::string const& str);
|
||||
color( std::string const& str, bool premultiplied = false);
|
||||
|
||||
std::string to_string() const;
|
||||
std::string to_hex_string() const;
|
||||
void premultiply();
|
||||
void demultiply();
|
||||
bool premultiply();
|
||||
bool demultiply();
|
||||
|
||||
color& operator=(color rhs)
|
||||
{
|
||||
|
@ -135,6 +146,14 @@ public:
|
|||
{
|
||||
alpha_ = alpha;
|
||||
}
|
||||
inline bool get_premultiplied() const
|
||||
{
|
||||
return premultiplied_;
|
||||
}
|
||||
inline void set_premultiplied(bool status)
|
||||
{
|
||||
premultiplied_ = status;
|
||||
}
|
||||
|
||||
inline unsigned rgba() const
|
||||
{
|
||||
|
|
|
@ -84,6 +84,10 @@ public:
|
|||
{
|
||||
return height_;
|
||||
}
|
||||
inline const pixel_type& operator() (std::size_t i, std::size_t j) const
|
||||
{
|
||||
return data_(i,j);
|
||||
}
|
||||
|
||||
inline unsigned getSize() const
|
||||
{
|
||||
|
@ -110,6 +114,11 @@ public:
|
|||
return data_;
|
||||
}
|
||||
|
||||
inline bool get_premultiplied() const
|
||||
{
|
||||
return data_.get_premultiplied();
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned x_;
|
||||
unsigned y_;
|
||||
|
|
|
@ -39,8 +39,6 @@ extern "C"
|
|||
#define TIFF_WRITE_STRIPPED 1
|
||||
#define TIFF_WRITE_TILED 2
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
static inline tsize_t tiff_write_proc(thandle_t fd, tdata_t buf, tsize_t size)
|
||||
|
@ -181,7 +179,7 @@ struct tiff_config
|
|||
|
||||
struct tag_setter
|
||||
{
|
||||
tag_setter(TIFF * output, tiff_config & config)
|
||||
tag_setter(TIFF * output, tiff_config const& config)
|
||||
: output_(output),
|
||||
config_(config) {}
|
||||
|
||||
|
@ -265,10 +263,10 @@ struct tag_setter
|
|||
|
||||
private:
|
||||
TIFF * output_;
|
||||
tiff_config config_;
|
||||
tiff_config const& config_;
|
||||
};
|
||||
|
||||
inline void set_tiff_config(TIFF* output, tiff_config & config)
|
||||
inline void set_tiff_config(TIFF* output, tiff_config const& config)
|
||||
{
|
||||
// Set some constant tiff information that doesn't vary based on type of data
|
||||
// or image size
|
||||
|
@ -289,7 +287,7 @@ inline void set_tiff_config(TIFF* output, tiff_config & config)
|
|||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
void save_as_tiff(T1 & file, T2 const& image, tiff_config & config)
|
||||
void save_as_tiff(T1 & file, T2 const& image, tiff_config const& config)
|
||||
{
|
||||
using pixel_type = typename T2::pixel_type;
|
||||
|
||||
|
@ -319,7 +317,6 @@ void save_as_tiff(T1 & file, T2 const& image, tiff_config & config)
|
|||
// Set tags that vary based on the type of data being provided.
|
||||
tag_setter set(output, config);
|
||||
set(image);
|
||||
//util::apply_visitor(set, image);
|
||||
|
||||
// Use specific types of writing methods.
|
||||
if (TIFF_WRITE_SCANLINE == config.method)
|
||||
|
@ -346,9 +343,7 @@ void save_as_tiff(T1 & file, T2 const& image, tiff_config & config)
|
|||
TIFFSetField(output, TIFFTAG_ROWSPERSTRIP, rows_per_strip);
|
||||
std::size_t strip_size = width * rows_per_strip;
|
||||
std::unique_ptr<pixel_type[]> strip_buffer(new pixel_type[strip_size]);
|
||||
int end_y=(height/rows_per_strip+1)*rows_per_strip;
|
||||
|
||||
for (int y=0; y < end_y; y+=rows_per_strip)
|
||||
for (int y=0; y < height; y+=rows_per_strip)
|
||||
{
|
||||
int ty1 = std::min(height, static_cast<int>(y + rows_per_strip)) - y;
|
||||
int row = y;
|
||||
|
|
|
@ -123,7 +123,9 @@ void agg_renderer<T0,T1>::setup(Map const &m)
|
|||
}
|
||||
else
|
||||
{
|
||||
mapnik::fill(pixmap_,*bg);
|
||||
mapnik::color bg_color = *bg;
|
||||
bg_color.set_premultiplied(true);
|
||||
mapnik::fill(pixmap_,bg_color);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,9 +45,10 @@
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
color::color(std::string const& str)
|
||||
color::color(std::string const& str, bool premultiplied)
|
||||
{
|
||||
*this = parse_color(str);
|
||||
premultiplied_ = premultiplied;
|
||||
}
|
||||
|
||||
std::string color::to_string() const
|
||||
|
@ -95,23 +96,28 @@ std::string color::to_hex_string() const
|
|||
return str;
|
||||
}
|
||||
|
||||
void color::premultiply()
|
||||
bool color::premultiply()
|
||||
{
|
||||
if (premultiplied_) return false;
|
||||
agg::rgba8 pre_c = agg::rgba8(red_,green_,blue_,alpha_);
|
||||
pre_c.premultiply();
|
||||
red_ = pre_c.r;
|
||||
green_ = pre_c.g;
|
||||
blue_ = pre_c.b;
|
||||
premultiplied_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void color::demultiply()
|
||||
bool color::demultiply()
|
||||
{
|
||||
// note: this darkens too much: https://github.com/mapnik/mapnik/issues/1519
|
||||
if (!premultiplied_) return false;
|
||||
agg::rgba8 pre_c = agg::rgba8(red_,green_,blue_,alpha_);
|
||||
pre_c.demultiply();
|
||||
red_ = pre_c.r;
|
||||
green_ = pre_c.g;
|
||||
blue_ = pre_c.b;
|
||||
premultiplied_ = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -169,7 +169,6 @@ MAPNIK_DECL void composite(image_rgba8 & dst, image_rgba8 const& src, composite_
|
|||
#ifdef MAPNIK_DEBUG
|
||||
if (!src.get_premultiplied())
|
||||
{
|
||||
abort();
|
||||
throw std::runtime_error("SOURCE MUST BE PREMULTIPLIED FOR COMPOSITING!");
|
||||
}
|
||||
if (!dst.get_premultiplied())
|
||||
|
|
|
@ -800,6 +800,14 @@ struct visitor_fill<color>
|
|||
{
|
||||
visitor_fill(color const& val)
|
||||
: val_(val) {}
|
||||
|
||||
void operator() (image_rgba8 & data)
|
||||
{
|
||||
using pixel_type = typename image_rgba8::pixel_type;
|
||||
pixel_type val = static_cast<pixel_type>(val_.rgba());
|
||||
data.set(val);
|
||||
data.set_premultiplied(val_.get_premultiplied());
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
void operator() (T2 & data)
|
||||
|
@ -1043,7 +1051,23 @@ struct visitor_set_pixel<color>
|
|||
void operator() (T2 & data)
|
||||
{
|
||||
using pixel_type = typename T2::pixel_type;
|
||||
pixel_type val = static_cast<pixel_type>(val_.rgba());
|
||||
pixel_type val;
|
||||
if (data.get_premultiplied() && !val_.get_premultiplied())
|
||||
{
|
||||
color tmp(val_);
|
||||
tmp.premultiply();
|
||||
val = static_cast<pixel_type>(tmp.rgba());
|
||||
}
|
||||
else if (!data.get_premultiplied() && val_.get_premultiplied())
|
||||
{
|
||||
color tmp(val_);
|
||||
tmp.demultiply();
|
||||
val = static_cast<pixel_type>(tmp.rgba());
|
||||
}
|
||||
else
|
||||
{
|
||||
val = static_cast<pixel_type>(val_.rgba());
|
||||
}
|
||||
if (check_bounds(data, x_, y_))
|
||||
{
|
||||
data(x_, y_) = val;
|
||||
|
@ -1137,11 +1161,7 @@ struct visitor_get_pixel<color>
|
|||
{
|
||||
if (check_bounds(data, x_, y_))
|
||||
{
|
||||
uint32_t val = static_cast<uint32_t>(data(x_, y_));
|
||||
return color(static_cast<uint8_t>(val),
|
||||
static_cast<uint8_t>((val >>= 8)),
|
||||
static_cast<uint8_t>((val >>= 8)),
|
||||
static_cast<uint8_t>((val >>= 8)));
|
||||
return color(static_cast<uint32_t>(data(x_, y_)), data.get_premultiplied());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -136,7 +136,6 @@ private:
|
|||
unsigned bands_;
|
||||
unsigned planar_config_;
|
||||
unsigned compression_;
|
||||
bool premultiplied_alpha_;
|
||||
bool has_alpha_;
|
||||
bool is_tiled_;
|
||||
|
||||
|
@ -214,7 +213,6 @@ tiff_reader<T>::tiff_reader(std::string const& file_name)
|
|||
bands_(1),
|
||||
planar_config_(PLANARCONFIG_CONTIG),
|
||||
compression_(COMPRESSION_NONE),
|
||||
premultiplied_alpha_(false),
|
||||
has_alpha_(false),
|
||||
is_tiled_(false)
|
||||
{
|
||||
|
@ -238,7 +236,6 @@ tiff_reader<T>::tiff_reader(char const* data, std::size_t size)
|
|||
bands_(1),
|
||||
planar_config_(PLANARCONFIG_CONTIG),
|
||||
compression_(COMPRESSION_NONE),
|
||||
premultiplied_alpha_(false),
|
||||
has_alpha_(false),
|
||||
is_tiled_(false)
|
||||
{
|
||||
|
@ -307,10 +304,10 @@ void tiff_reader<T>::init()
|
|||
&extrasamples, &sampleinfo))
|
||||
{
|
||||
has_alpha_ = true;
|
||||
if (extrasamples == 1 &&
|
||||
sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA)
|
||||
if (extrasamples > 0 &&
|
||||
sampleinfo[0] == EXTRASAMPLE_UNSPECIFIED)
|
||||
{
|
||||
premultiplied_alpha_ = true;
|
||||
throw std::runtime_error("Unspecified provided for extra samples to tiff reader.");
|
||||
}
|
||||
}
|
||||
// Try extracting bounding box from geoTIFF tags
|
||||
|
@ -567,7 +564,7 @@ image_any tiff_reader<T>::read(unsigned x0, unsigned y0, unsigned width, unsigne
|
|||
//PHOTOMETRIC_ITULAB = 10;
|
||||
//PHOTOMETRIC_LOGL = 32844;
|
||||
//PHOTOMETRIC_LOGLUV = 32845;
|
||||
image_rgba8 data(width,height, true, premultiplied_alpha_);
|
||||
image_rgba8 data(width,height, true, true);
|
||||
read(x0, y0, data);
|
||||
return image_any(std::move(data));
|
||||
}
|
||||
|
@ -640,30 +637,26 @@ void tiff_reader<T>::read_stripped(unsigned x0,unsigned y0,image_rgba8& image)
|
|||
int height=image.height();
|
||||
|
||||
unsigned start_y=(y0/rows_per_strip_)*rows_per_strip_;
|
||||
unsigned end_y=((y0+height)/rows_per_strip_+1)*rows_per_strip_;
|
||||
bool laststrip=(static_cast<unsigned>(end_y) > height_)?true:false;
|
||||
int row,tx0,tx1,ty0,ty1;
|
||||
unsigned end_y=std::min(y0+height, static_cast<unsigned>(height_));
|
||||
int tx0,tx1,ty0,ty1;
|
||||
|
||||
tx0=x0;
|
||||
tx1=std::min(width+x0,static_cast<unsigned>(width_));
|
||||
|
||||
int row = 0;
|
||||
for (unsigned y=start_y; y < end_y; y+=rows_per_strip_)
|
||||
{
|
||||
ty0 = std::max(y0,y)-y;
|
||||
ty1 = std::min(height+y0,y+rows_per_strip_)-y;
|
||||
ty1 = std::min(end_y,y+rows_per_strip_)-y;
|
||||
|
||||
if (!TIFFReadRGBAStrip(tif,y,strip.getData()))
|
||||
{
|
||||
std::clog << "TIFFReadRGBAStrip failed at " << y << " for " << width_ << "/" << height_ << "\n";
|
||||
break;
|
||||
}
|
||||
row=y+ty0-y0;
|
||||
|
||||
int n0=laststrip ? 0:(rows_per_strip_-ty1);
|
||||
int n1=laststrip ? (ty1-ty0-1):(rows_per_strip_-ty0-1);
|
||||
for (int n=n1;n>=n0;--n)
|
||||
// This is in reverse becauase the TIFFReadRGBAStrip reads inverted
|
||||
for (unsigned ty = ty1; ty > ty0; --ty)
|
||||
{
|
||||
image.setRow(row,tx0-x0,tx1-x0,&strip.getData()[n*width_+tx0]);
|
||||
image.setRow(row,tx0-x0,tx1-x0,&strip.getData()[(ty-1)*width_+tx0]);
|
||||
++row;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,16 @@
|
|||
REQUIRE( reader->has_alpha() == true ); \
|
||||
REQUIRE( tiff_reader2.has_alpha() == true ); \
|
||||
REQUIRE( reader2->has_alpha() == true ); \
|
||||
REQUIRE( data.get_premultiplied() == false ); \
|
||||
REQUIRE( data.get_premultiplied() == true ); \
|
||||
|
||||
#define TIFF_ASSERT_NO_ALPHA( data ) \
|
||||
#define TIFF_ASSERT_NO_ALPHA_RGB( data ) \
|
||||
REQUIRE( tiff_reader.has_alpha() == false ); \
|
||||
REQUIRE( reader->has_alpha() == false ); \
|
||||
REQUIRE( tiff_reader2.has_alpha() == false ); \
|
||||
REQUIRE( reader2->has_alpha() == false ); \
|
||||
REQUIRE( data.get_premultiplied() == true ); \
|
||||
|
||||
#define TIFF_ASSERT_NO_ALPHA_GRAY( data ) \
|
||||
REQUIRE( tiff_reader.has_alpha() == false ); \
|
||||
REQUIRE( reader->has_alpha() == false ); \
|
||||
REQUIRE( tiff_reader2.has_alpha() == false ); \
|
||||
|
@ -77,7 +84,7 @@ SECTION("scan rgb8 striped") {
|
|||
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( data );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
|
@ -107,7 +114,7 @@ SECTION("scan rgb8 tiled") {
|
|||
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( data );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
|
@ -155,7 +162,7 @@ SECTION("rgb8 striped") {
|
|||
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( data );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
|
@ -171,7 +178,7 @@ SECTION("rgb8 tiled") {
|
|||
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( data );
|
||||
TIFF_ASSERT_NO_ALPHA_RGB( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
|
@ -187,7 +194,7 @@ SECTION("gray8 striped") {
|
|||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA( data );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
|
@ -203,7 +210,7 @@ SECTION("gray8 tiled") {
|
|||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray8>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA( data );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
|
@ -219,7 +226,7 @@ SECTION("gray16 striped") {
|
|||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray16>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA( data );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
|
@ -235,7 +242,7 @@ SECTION("gray16 tiled") {
|
|||
mapnik::image_any data = reader->read(0, 0, reader->width(), reader->height());
|
||||
REQUIRE( data.is<mapnik::image_gray16>() == true );
|
||||
TIFF_ASSERT_SIZE( data,reader );
|
||||
TIFF_ASSERT_NO_ALPHA( data );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
|
@ -251,7 +258,7 @@ SECTION("gray32f striped") {
|
|||
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( data );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
|
@ -267,7 +274,7 @@ SECTION("gray32f tiled") {
|
|||
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( data );
|
||||
TIFF_ASSERT_NO_ALPHA_GRAY( data );
|
||||
TIFF_READ_ONE_PIXEL
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ def test_that_datasources_exist():
|
|||
print '***NOTICE*** - no datasource plugins have been loaded'
|
||||
|
||||
# adapted from raster_symboliser_test#test_dataraster_query_point
|
||||
@raises(RuntimeError)
|
||||
def test_vrt_referring_to_missing_files():
|
||||
srs = '+init=epsg:32630'
|
||||
if 'gdal' in mapnik.DatasourceCache.plugin_names():
|
||||
|
@ -31,13 +32,26 @@ def test_vrt_referring_to_missing_files():
|
|||
|
||||
_map.zoom_all()
|
||||
|
||||
# Should RuntimeError here
|
||||
# Fancy stuff to supress output of error
|
||||
# open 2 fds
|
||||
null_fds = [os.open(os.devnull, os.O_RDWR) for x in xrange(2)]
|
||||
# save the current file descriptors to a tuple
|
||||
save = os.dup(1), os.dup(2)
|
||||
# put /dev/null fds on 1 and 2
|
||||
os.dup2(null_fds[0], 1)
|
||||
os.dup2(null_fds[1], 2)
|
||||
|
||||
# *** run the function ***
|
||||
try:
|
||||
# Should RuntimeError here
|
||||
_map.query_point(0, x, y).features
|
||||
except RuntimeError, e:
|
||||
eq_("this_file_should_not_exist.tif' does not exist in the file system" in str(e), True)
|
||||
else:
|
||||
assert False
|
||||
finally:
|
||||
# restore file descriptors so I can print the results
|
||||
os.dup2(save[0], 1)
|
||||
os.dup2(save[1], 2)
|
||||
# close the temporary fds
|
||||
os.close(null_fds[0])
|
||||
os.close(null_fds[1])
|
||||
|
||||
|
||||
def test_field_listing():
|
||||
|
|
|
@ -28,6 +28,137 @@ def test_image_premultiply():
|
|||
eq_(im.demultiply(), False)
|
||||
eq_(im.premultiplied(),False)
|
||||
|
||||
def test_image_premultiply_values():
|
||||
im = mapnik.Image(256,256)
|
||||
im.background(mapnik.Color(16, 33, 255, 128))
|
||||
im.premultiply()
|
||||
c = im.get_pixel_color(0,0)
|
||||
eq_(c.r, 8)
|
||||
eq_(c.g, 17)
|
||||
eq_(c.b, 128)
|
||||
eq_(c.a, 128)
|
||||
im.demultiply()
|
||||
# Do to the nature of this operation the result will not be exactly the same
|
||||
c = im.get_pixel_color(0,0)
|
||||
eq_(c.r,15)
|
||||
eq_(c.g,33)
|
||||
eq_(c.b,255)
|
||||
eq_(c.a,128)
|
||||
|
||||
def test_background():
|
||||
im = mapnik.Image(256,256)
|
||||
eq_(im.premultiplied(), False)
|
||||
im.background(mapnik.Color(32,64,125,128))
|
||||
eq_(im.premultiplied(), False)
|
||||
c = im.get_pixel_color(0,0)
|
||||
eq_(c.get_premultiplied(), False)
|
||||
eq_(c.r,32)
|
||||
eq_(c.g,64)
|
||||
eq_(c.b,125)
|
||||
eq_(c.a,128)
|
||||
# Now again with a premultiplied alpha
|
||||
im.background(mapnik.Color(32,64,125,128,True))
|
||||
eq_(im.premultiplied(), True)
|
||||
c = im.get_pixel_color(0,0)
|
||||
eq_(c.get_premultiplied(), True)
|
||||
eq_(c.r,32)
|
||||
eq_(c.g,64)
|
||||
eq_(c.b,125)
|
||||
eq_(c.a,128)
|
||||
|
||||
def test_set_and_get_pixel():
|
||||
# Create an image that is not premultiplied
|
||||
im = mapnik.Image(256,256)
|
||||
c0 = mapnik.Color(16,33,255,128)
|
||||
c0_pre = mapnik.Color(16,33,255,128, True)
|
||||
im.set_pixel(0,0,c0)
|
||||
im.set_pixel(1,1,c0_pre)
|
||||
# No differences for non premultiplied pixels
|
||||
c1_int = mapnik.Color(im.get_pixel(0,0))
|
||||
eq_(c0.r, c1_int.r)
|
||||
eq_(c0.g, c1_int.g)
|
||||
eq_(c0.b, c1_int.b)
|
||||
eq_(c0.a, c1_int.a)
|
||||
c1 = im.get_pixel_color(0,0)
|
||||
eq_(c0.r, c1.r)
|
||||
eq_(c0.g, c1.g)
|
||||
eq_(c0.b, c1.b)
|
||||
eq_(c0.a, c1.a)
|
||||
# The premultiplied Color should be demultiplied before being applied.
|
||||
c0_pre.demultiply()
|
||||
c1_int = mapnik.Color(im.get_pixel(1,1))
|
||||
eq_(c0_pre.r, c1_int.r)
|
||||
eq_(c0_pre.g, c1_int.g)
|
||||
eq_(c0_pre.b, c1_int.b)
|
||||
eq_(c0_pre.a, c1_int.a)
|
||||
c1 = im.get_pixel_color(1,1)
|
||||
eq_(c0_pre.r, c1.r)
|
||||
eq_(c0_pre.g, c1.g)
|
||||
eq_(c0_pre.b, c1.b)
|
||||
eq_(c0_pre.a, c1.a)
|
||||
|
||||
# Now create a new image that is premultiplied
|
||||
im = mapnik.Image(256,256, mapnik.ImageType.rgba8, True, True)
|
||||
c0 = mapnik.Color(16,33,255,128)
|
||||
c0_pre = mapnik.Color(16,33,255,128, True)
|
||||
im.set_pixel(0,0,c0)
|
||||
im.set_pixel(1,1,c0_pre)
|
||||
# It should have put pixels that are the same as premultiplied so premultiply c0
|
||||
c0.premultiply()
|
||||
c1_int = mapnik.Color(im.get_pixel(0,0))
|
||||
eq_(c0.r, c1_int.r)
|
||||
eq_(c0.g, c1_int.g)
|
||||
eq_(c0.b, c1_int.b)
|
||||
eq_(c0.a, c1_int.a)
|
||||
c1 = im.get_pixel_color(0,0)
|
||||
eq_(c0.r, c1.r)
|
||||
eq_(c0.g, c1.g)
|
||||
eq_(c0.b, c1.b)
|
||||
eq_(c0.a, c1.a)
|
||||
# The premultiplied Color should be the same though
|
||||
c1_int = mapnik.Color(im.get_pixel(1,1))
|
||||
eq_(c0_pre.r, c1_int.r)
|
||||
eq_(c0_pre.g, c1_int.g)
|
||||
eq_(c0_pre.b, c1_int.b)
|
||||
eq_(c0_pre.a, c1_int.a)
|
||||
c1 = im.get_pixel_color(1,1)
|
||||
eq_(c0_pre.r, c1.r)
|
||||
eq_(c0_pre.g, c1.g)
|
||||
eq_(c0_pre.b, c1.b)
|
||||
eq_(c0_pre.a, c1.a)
|
||||
|
||||
@raises(IndexError)
|
||||
def test_set_pixel_out_of_range_1():
|
||||
im = mapnik.Image(4,4)
|
||||
c = mapnik.Color('blue')
|
||||
im.set_pixel(5,5,c)
|
||||
|
||||
@raises(OverflowError)
|
||||
def test_set_pixel_out_of_range_2():
|
||||
im = mapnik.Image(4,4)
|
||||
c = mapnik.Color('blue')
|
||||
im.set_pixel(-1,1,c)
|
||||
|
||||
@raises(IndexError)
|
||||
def test_get_pixel_out_of_range_1():
|
||||
im = mapnik.Image(4,4)
|
||||
c = im.get_pixel(5,5)
|
||||
|
||||
@raises(OverflowError)
|
||||
def test_get_pixel_out_of_range_2():
|
||||
im = mapnik.Image(4,4)
|
||||
c = im.get_pixel(-1,1)
|
||||
|
||||
@raises(IndexError)
|
||||
def test_get_pixel_color_out_of_range_1():
|
||||
im = mapnik.Image(4,4)
|
||||
c = im.get_pixel_color(5,5)
|
||||
|
||||
@raises(OverflowError)
|
||||
def test_get_pixel_color_out_of_range_2():
|
||||
im = mapnik.Image(4,4)
|
||||
c = im.get_pixel_color(-1,1)
|
||||
|
||||
def test_set_color_to_alpha():
|
||||
im = mapnik.Image(256,256)
|
||||
im.background(mapnik.Color('rgba(12,12,12,255)'))
|
||||
|
|
|
@ -3,10 +3,14 @@
|
|||
|
||||
import sys
|
||||
import os, mapnik
|
||||
import hashlib
|
||||
from timeit import Timer, time
|
||||
from nose.tools import *
|
||||
from utilities import execution_path, run_all
|
||||
|
||||
def hashstr(var):
|
||||
return hashlib.md5(var).hexdigest()
|
||||
|
||||
def setup():
|
||||
# All of the paths used are relative, if we run the tests
|
||||
# from another directory we need to chdir()
|
||||
|
@ -15,8 +19,8 @@ def setup():
|
|||
def test_tiff_round_trip_scanline():
|
||||
filepath = '/tmp/mapnik-tiff-io-scanline.tiff'
|
||||
im = mapnik.Image(255,267)
|
||||
im.background(mapnik.Color('rgba(1,2,3,.5)'))
|
||||
org_str = len(im.tostring())
|
||||
im.background(mapnik.Color('rgba(12,255,128,.5)'))
|
||||
org_str = hashstr(im.tostring())
|
||||
im.save(filepath,'tiff:method=scanline')
|
||||
im2 = mapnik.Image.open(filepath)
|
||||
im3 = mapnik.Image.fromstring(open(filepath,'r').read())
|
||||
|
@ -24,74 +28,121 @@ def test_tiff_round_trip_scanline():
|
|||
eq_(im.height(),im2.height())
|
||||
eq_(im.width(),im3.width())
|
||||
eq_(im.height(),im3.height())
|
||||
eq_(len(im.tostring()), org_str)
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=scanline')),len(im2.tostring('tiff:method=scanline')))
|
||||
eq_(len(im.tostring()),len(im3.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=scanline')),len(im3.tostring('tiff:method=scanline')))
|
||||
eq_(hashstr(im.tostring()), org_str)
|
||||
# This won't be the same the first time around because the im is not premultiplied and im2 is
|
||||
assert_not_equal(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
assert_not_equal(hashstr(im.tostring('tiff:method=scanline')),hashstr(im2.tostring('tiff:method=scanline')))
|
||||
# Now premultiply
|
||||
im.premultiply()
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=scanline')),hashstr(im2.tostring('tiff:method=scanline')))
|
||||
eq_(hashstr(im2.tostring()),hashstr(im3.tostring()))
|
||||
eq_(hashstr(im2.tostring('tiff:method=scanline')),hashstr(im3.tostring('tiff:method=scanline')))
|
||||
|
||||
def test_tiff_round_trip_stripped():
|
||||
filepath = '/tmp/mapnik-tiff-io-stripped.tiff'
|
||||
im = mapnik.Image(255,267)
|
||||
im.background(mapnik.Color('rgba(1,2,3,.5)'))
|
||||
org_str = len(im.tostring())
|
||||
im.background(mapnik.Color('rgba(12,255,128,.5)'))
|
||||
org_str = hashstr(im.tostring())
|
||||
im.save(filepath,'tiff:method=stripped')
|
||||
im2 = mapnik.Image.open(filepath)
|
||||
im2.save('/tmp/mapnik-tiff-io-stripped2.tiff','tiff:method=stripped')
|
||||
im3 = mapnik.Image.fromstring(open(filepath,'r').read())
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(im.width(),im3.width())
|
||||
eq_(im.height(),im3.height())
|
||||
eq_(len(im.tostring()), org_str)
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=stripped')),len(im2.tostring('tiff:method=stripped')))
|
||||
eq_(len(im.tostring()),len(im3.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=stripped')),len(im3.tostring('tiff:method=stripped')))
|
||||
# Because one will end up with UNASSOC alpha tag which internally the TIFF reader will premultiply, the first to string will not be the same due to the
|
||||
# difference in tags.
|
||||
assert_not_equal(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
assert_not_equal(hashstr(im.tostring('tiff:method=stripped')),hashstr(im2.tostring('tiff:method=stripped')))
|
||||
# Now if we premultiply they will be exactly the same
|
||||
im.premultiply()
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=stripped')),hashstr(im2.tostring('tiff:method=stripped')))
|
||||
eq_(hashstr(im2.tostring()),hashstr(im3.tostring()))
|
||||
# Both of these started out premultiplied, so this round trip should be exactly the same!
|
||||
eq_(hashstr(im2.tostring('tiff:method=stripped')),hashstr(im3.tostring('tiff:method=stripped')))
|
||||
|
||||
def test_tiff_round_trip_rows_stripped():
|
||||
filepath = '/tmp/mapnik-tiff-io-stripped.tiff'
|
||||
filepath = '/tmp/mapnik-tiff-io-rows_stripped.tiff'
|
||||
filepath2 = '/tmp/mapnik-tiff-io-rows_stripped2.tiff'
|
||||
im = mapnik.Image(255,267)
|
||||
im.background(mapnik.Color('rgba(1,2,3,.5)'))
|
||||
org_str = len(im.tostring())
|
||||
im.background(mapnik.Color('rgba(12,255,128,.5)'))
|
||||
c = im.get_pixel_color(0,0)
|
||||
eq_(c.r, 12)
|
||||
eq_(c.g, 255)
|
||||
eq_(c.b, 128)
|
||||
eq_(c.a, 128)
|
||||
eq_(c.get_premultiplied(), False)
|
||||
im.save(filepath,'tiff:method=stripped:rows_per_strip=8')
|
||||
im2 = mapnik.Image.open(filepath)
|
||||
c2 = im2.get_pixel_color(0,0)
|
||||
eq_(c2.r, 6)
|
||||
eq_(c2.g, 128)
|
||||
eq_(c2.b, 64)
|
||||
eq_(c2.a, 128)
|
||||
eq_(c2.get_premultiplied(), True)
|
||||
im2.save(filepath2,'tiff:method=stripped:rows_per_strip=8')
|
||||
im3 = mapnik.Image.fromstring(open(filepath,'r').read())
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(im.width(),im3.width())
|
||||
eq_(im.height(),im3.height())
|
||||
eq_(len(im.tostring()), org_str)
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=stripped:rows_per_strip=8')),len(im2.tostring('tiff:method=stripped:rows_per_strip=8')))
|
||||
eq_(len(im.tostring()),len(im3.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=stripped:rows_per_strip=8')),len(im3.tostring('tiff:method=stripped:rows_per_strip=8')))
|
||||
# Because one will end up with UNASSOC alpha tag which internally the TIFF reader will premultiply, the first to string will not be the same due to the
|
||||
# difference in tags.
|
||||
assert_not_equal(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
assert_not_equal(hashstr(im.tostring('tiff:method=stripped:rows_per_strip=8')),hashstr(im2.tostring('tiff:method=stripped:rows_per_strip=8')))
|
||||
# Now premultiply the first image and they will be the same!
|
||||
im.premultiply()
|
||||
eq_(hashstr(im.tostring('tiff:method=stripped:rows_per_strip=8')),hashstr(im2.tostring('tiff:method=stripped:rows_per_strip=8')))
|
||||
eq_(hashstr(im2.tostring()),hashstr(im3.tostring()))
|
||||
# Both of these started out premultiplied, so this round trip should be exactly the same!
|
||||
eq_(hashstr(im2.tostring('tiff:method=stripped:rows_per_strip=8')),hashstr(im3.tostring('tiff:method=stripped:rows_per_strip=8')))
|
||||
|
||||
def test_tiff_round_trip_buffered_tiled():
|
||||
filepath = '/tmp/mapnik-tiff-io-buffered-tiled.tiff'
|
||||
filepath2 = '/tmp/mapnik-tiff-io-buffered-tiled2.tiff'
|
||||
filepath3 = '/tmp/mapnik-tiff-io-buffered-tiled3.tiff'
|
||||
im = mapnik.Image(255,267)
|
||||
#im = mapnik.Image(256,256)
|
||||
im.background(mapnik.Color('rgba(1,2,3,.5)'))
|
||||
im.background(mapnik.Color('rgba(33,255,128,.5)'))
|
||||
c = im.get_pixel_color(0,0)
|
||||
eq_(c.r, 33)
|
||||
eq_(c.g, 255)
|
||||
eq_(c.b, 128)
|
||||
eq_(c.a, 128)
|
||||
eq_(c.get_premultiplied(), False)
|
||||
im.save(filepath,'tiff:method=tiled:tile_width=32:tile_height=32')
|
||||
im2 = mapnik.Image.open(filepath)
|
||||
c2 = im2.get_pixel_color(0,0)
|
||||
eq_(c2.r, 17)
|
||||
eq_(c2.g, 128)
|
||||
eq_(c2.b, 64)
|
||||
eq_(c2.a, 128)
|
||||
eq_(c2.get_premultiplied(), True)
|
||||
im3 = mapnik.Image.fromstring(open(filepath,'r').read())
|
||||
im2.save(filepath2, 'tiff:method=tiled:tile_width=32:tile_height=32')
|
||||
im4 = mapnik.Image.open(filepath2)
|
||||
im3.save(filepath3, 'tiff:method=tiled:tile_width=32:tile_height=32')
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(im.width(),im3.width())
|
||||
eq_(im.height(),im3.height())
|
||||
eq_(len(im2.tostring()),len(im4.tostring()))
|
||||
eq_(len(im2.tostring('tiff:method=tiled:tile_width=32:tile_height=32')),len(im4.tostring('tiff:method=tiled:tile_width=32:tile_height=32')))
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=tiled:tile_width=32:tile_height=32')),len(im2.tostring('tiff:method=tiled:tile_width=32:tile_height=32')))
|
||||
eq_(len(im.tostring()),len(im3.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=tiled:tile_width=32:tile_height=32')),len(im3.tostring('tiff:method=tiled:tile_width=32:tile_height=32')))
|
||||
# Because one will end up with UNASSOC alpha tag which internally the TIFF reader will premultiply, the first to string will not be the same due to the
|
||||
# difference in tags.
|
||||
assert_not_equal(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
assert_not_equal(hashstr(im.tostring('tiff:method=tiled:tile_width=32:tile_height=32')),hashstr(im2.tostring('tiff:method=tiled:tile_width=32:tile_height=32')))
|
||||
# Now premultiply the first image and they should be the same
|
||||
im.premultiply()
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=tiled:tile_width=32:tile_height=32')),hashstr(im2.tostring('tiff:method=tiled:tile_width=32:tile_height=32')))
|
||||
eq_(hashstr(im2.tostring()),hashstr(im3.tostring()))
|
||||
# Both of these started out premultiplied, so this round trip should be exactly the same!
|
||||
eq_(hashstr(im2.tostring('tiff:method=tiled:tile_width=32:tile_height=32')),hashstr(im3.tostring('tiff:method=tiled:tile_width=32:tile_height=32')))
|
||||
|
||||
def test_tiff_round_trip_tiled():
|
||||
filepath = '/tmp/mapnik-tiff-io-tiled.tiff'
|
||||
im = mapnik.Image(256,256)
|
||||
im.background(mapnik.Color('rgba(1,2,3,.5)'))
|
||||
im.background(mapnik.Color('rgba(1,255,128,.5)'))
|
||||
im.save(filepath,'tiff:method=tiled')
|
||||
im2 = mapnik.Image.open(filepath)
|
||||
im3 = mapnik.Image.fromstring(open(filepath,'r').read())
|
||||
|
@ -99,10 +150,17 @@ def test_tiff_round_trip_tiled():
|
|||
eq_(im.height(),im2.height())
|
||||
eq_(im.width(),im3.width())
|
||||
eq_(im.height(),im3.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=tiled')),len(im2.tostring('tiff:method=tiled')))
|
||||
eq_(len(im.tostring()),len(im3.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=tiled')),len(im3.tostring('tiff:method=tiled')))
|
||||
# Because one will end up with UNASSOC alpha tag which internally the TIFF reader will premultiply, the first to string will not be the same due to the
|
||||
# difference in tags.
|
||||
assert_not_equal(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
assert_not_equal(hashstr(im.tostring('tiff:method=tiled')),hashstr(im2.tostring('tiff:method=tiled')))
|
||||
# Now premultiply the first image and they will be exactly the same.
|
||||
im.premultiply()
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=tiled')),hashstr(im2.tostring('tiff:method=tiled')))
|
||||
eq_(hashstr(im2.tostring()),hashstr(im3.tostring()))
|
||||
# Both of these started out premultiplied, so this round trip should be exactly the same!
|
||||
eq_(hashstr(im2.tostring('tiff:method=tiled')),hashstr(im3.tostring('tiff:method=tiled')))
|
||||
|
||||
|
||||
def test_tiff_rgb8_compare():
|
||||
|
@ -113,10 +171,10 @@ def test_tiff_rgb8_compare():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff')),len(im2.tostring('tiff')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff')),hashstr(im2.tostring('tiff')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.rgba8).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_rgba8_compare_scanline():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_rgba8_striped.tif'
|
||||
|
@ -126,10 +184,10 @@ def test_tiff_rgba8_compare_scanline():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=scanline')),len(im2.tostring('tiff:method=scanline')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=scanline')),hashstr(im2.tostring('tiff:method=scanline')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.rgba8).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_rgba8_compare_stripped():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_rgba8_striped.tif'
|
||||
|
@ -139,10 +197,10 @@ def test_tiff_rgba8_compare_stripped():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=stripped')),len(im2.tostring('tiff:method=stripped')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=stripped')),hashstr(im2.tostring('tiff:method=stripped')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.rgba8).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_rgba8_compare_tiled():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_rgba8_striped.tif'
|
||||
|
@ -152,10 +210,10 @@ def test_tiff_rgba8_compare_tiled():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=tiled')),len(im2.tostring('tiff:method=tiled')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=tiled')),hashstr(im2.tostring('tiff:method=tiled')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.rgba8).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_gray8_compare_scanline():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_gray8_striped.tif'
|
||||
|
@ -165,10 +223,10 @@ def test_tiff_gray8_compare_scanline():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=scanline')),len(im2.tostring('tiff:method=scanline')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=scanline')),hashstr(im2.tostring('tiff:method=scanline')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray8).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_gray8_compare_stripped():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_gray8_striped.tif'
|
||||
|
@ -178,10 +236,10 @@ def test_tiff_gray8_compare_stripped():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=stripped')),len(im2.tostring('tiff:method=stripped')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=stripped')),hashstr(im2.tostring('tiff:method=stripped')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray8).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_gray8_compare_tiled():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_gray8_striped.tif'
|
||||
|
@ -191,10 +249,10 @@ def test_tiff_gray8_compare_tiled():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=tiled')),len(im2.tostring('tiff:method=tiled')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=tiled')),hashstr(im2.tostring('tiff:method=tiled')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray8).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_gray16_compare_scanline():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_gray16_striped.tif'
|
||||
|
@ -204,10 +262,10 @@ def test_tiff_gray16_compare_scanline():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=scanline')),len(im2.tostring('tiff:method=scanline')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=scanline')),hashstr(im2.tostring('tiff:method=scanline')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray16).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_gray16_compare_stripped():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_gray16_striped.tif'
|
||||
|
@ -217,10 +275,10 @@ def test_tiff_gray16_compare_stripped():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=stripped')),len(im2.tostring('tiff:method=stripped')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=stripped')),hashstr(im2.tostring('tiff:method=stripped')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray16).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_gray16_compare_tiled():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_gray16_striped.tif'
|
||||
|
@ -230,10 +288,10 @@ def test_tiff_gray16_compare_tiled():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=tiled')),len(im2.tostring('tiff:method=tiled')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=tiled')),hashstr(im2.tostring('tiff:method=tiled')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray16).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_gray32f_compare_scanline():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_gray32f_striped.tif'
|
||||
|
@ -243,10 +301,10 @@ def test_tiff_gray32f_compare_scanline():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=scanline')),len(im2.tostring('tiff:method=scanline')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=scanline')),hashstr(im2.tostring('tiff:method=scanline')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray32f).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_gray32f_compare_stripped():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_gray32f_striped.tif'
|
||||
|
@ -256,10 +314,10 @@ def test_tiff_gray32f_compare_stripped():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=stripped')),len(im2.tostring('tiff:method=stripped')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=stripped')),hashstr(im2.tostring('tiff:method=stripped')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray32f).tostring("tiff")),True)
|
||||
|
||||
def test_tiff_gray32f_compare_tiled():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_gray32f_striped.tif'
|
||||
|
@ -269,10 +327,10 @@ def test_tiff_gray32f_compare_tiled():
|
|||
im2 = mapnik.Image.open(filepath2)
|
||||
eq_(im.width(),im2.width())
|
||||
eq_(im.height(),im2.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
eq_(len(im.tostring('tiff:method=tiled')),len(im2.tostring('tiff:method=tiled')))
|
||||
eq_(hashstr(im.tostring()),hashstr(im2.tostring()))
|
||||
eq_(hashstr(im.tostring('tiff:method=tiled')),hashstr(im2.tostring('tiff:method=tiled')))
|
||||
# should not be a blank image
|
||||
eq_(len(im.tostring("png")) != len(mapnik.Image(im.width(),im.height()).tostring("png")),True)
|
||||
eq_(hashstr(im.tostring("tiff")) != hashstr(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray32f).tostring("tiff")),True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup()
|
||||
|
|
Before Width: | Height: | Size: 8 KiB After Width: | Height: | Size: 8 KiB |
Before Width: | Height: | Size: 8 KiB After Width: | Height: | Size: 8 KiB |
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 8.7 KiB |
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 8.7 KiB |