Fixed some issues in color and bindings where you could create a color and premultiplied was not set and it was resulting in it being assigned randomly, causing some issues at runtime.
Updated some images in visual tests that were orginally set prior to all tiffs being premultiplied, this was causing a slight difference in a few pixels. Updated the tiff tests a lot. Fixed tiff reader so that it always considers everything read from RGB or RGBA as premultiplied. This is due to the fact that RGBA reader always premultiplies the alpha no matter its original form. Put in a fix so that the file does not exist no longer shows up in the test running. Fixed some failing tests in the c++ test due to tiffs now always being premultiplied for RGB(A)
|
@ -84,6 +84,12 @@ void export_color ()
|
|||
"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,
|
||||
|
@ -108,8 +114,6 @@ void export_color ()
|
|||
.def(self != self)
|
||||
.def_pickle(color_pickle_suite())
|
||||
.def("__str__",&color::to_string)
|
||||
.def("packed",&color::rgba)
|
||||
.def("premultiply",&color::premultiply)
|
||||
.def("set_premultiplied",&color::set_premultiplied)
|
||||
.def("get_premultiplied",&color::get_premultiplied)
|
||||
.def("premultiply",&color::premultiply)
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
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;
|
||||
|
|
|
@ -179,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) {}
|
||||
|
||||
|
@ -263,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
|
||||
|
@ -287,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;
|
||||
|
||||
|
@ -317,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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,7 +304,6 @@ void tiff_reader<T>::init()
|
|||
&extrasamples, &sampleinfo))
|
||||
{
|
||||
has_alpha_ = true;
|
||||
premultiplied_alpha_ = true;
|
||||
if (extrasamples > 0 &&
|
||||
sampleinfo[0] == EXTRASAMPLE_UNSPECIFIED)
|
||||
{
|
||||
|
@ -568,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));
|
||||
}
|
||||
|
|
|
@ -33,7 +33,14 @@
|
|||
REQUIRE( reader2->has_alpha() == true ); \
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -231,7 +231,7 @@ def test_background_image_with_alpha_and_background_color():
|
|||
m.background_image = '../data/images/yellow_half_trans.png'
|
||||
im = mapnik.Image(m.width,m.height)
|
||||
mapnik.render(m,im)
|
||||
eq_(get_unique_colors(im),['rgba(255,255,170,191)'])
|
||||
eq_(get_unique_colors(im),['rgba(255,255,85,191)'])
|
||||
|
||||
def test_background_image_with_alpha_and_background_color_against_composited_control():
|
||||
m = mapnik.Map(10,10)
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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
|
||||
#mapnik.logger.set_severity(mapnik.severity_type.Debug)
|
||||
|
||||
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()
|
||||
|
@ -16,7 +20,7 @@ def test_tiff_round_trip_scanline():
|
|||
filepath = '/tmp/mapnik-tiff-io-scanline.tiff'
|
||||
im = mapnik.Image(255,267)
|
||||
im.background(mapnik.Color('rgba(12,255,128,.5)'))
|
||||
org_str = len(im.tostring())
|
||||
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,17 +28,22 @@ 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(12,255,128,.5)'))
|
||||
org_str = len(im.tostring())
|
||||
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')
|
||||
|
@ -43,38 +52,53 @@ def test_tiff_round_trip_stripped():
|
|||
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()))
|
||||
# Because one will end up with UNASSOC alpha tag which internally the TIFF will multiply, the first to string will not be the same due to the
|
||||
# difference in tags. But size should still be the same
|
||||
eq_(len(im.tostring('tiff:method=stripped')),len(im2.tostring('tiff:method=stripped')))
|
||||
eq_(len(im2.tostring()),len(im3.tostring()))
|
||||
# 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_(len(im2.tostring('tiff:method=stripped')),len(im3.tostring('tiff:method=stripped')))
|
||||
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-rows_stripped.tiff'
|
||||
filepath2 = '/tmp/mapnik-tiff-io-rows_stripped2.tiff'
|
||||
im = mapnik.Image(255,267)
|
||||
im.background(mapnik.Color('rgba(12,255,128,.5)'))
|
||||
#im.premultiply()
|
||||
org_str = len(im.tostring())
|
||||
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()))
|
||||
# Because one will end up with UNASSOC alpha tag which internally the TIFF will multiply, the first to string will not be the same due to the
|
||||
# difference in tags. But size should still be the same
|
||||
eq_(len(im.tostring('tiff:method=stripped:rows_per_strip=8')),len(im2.tostring('tiff:method=stripped:rows_per_strip=8')))
|
||||
eq_(len(im2.tostring()),len(im3.tostring()))
|
||||
# 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_(len(im2.tostring('tiff:method=stripped:rows_per_strip=8')),len(im3.tostring('tiff:method=stripped:rows_per_strip=8')))
|
||||
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'
|
||||
|
@ -82,8 +106,20 @@ def test_tiff_round_trip_buffered_tiled():
|
|||
filepath3 = '/tmp/mapnik-tiff-io-buffered-tiled3.tiff'
|
||||
im = mapnik.Image(255,267)
|
||||
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')
|
||||
im3.save(filepath3, 'tiff:method=tiled:tile_width=32:tile_height=32')
|
||||
|
@ -91,13 +127,17 @@ def test_tiff_round_trip_buffered_tiled():
|
|||
eq_(im.height(),im2.height())
|
||||
eq_(im.width(),im3.width())
|
||||
eq_(im.height(),im3.height())
|
||||
eq_(len(im.tostring()),len(im2.tostring()))
|
||||
# Because one will end up with UNASSOC alpha tag which internally the TIFF will multiply, the first to string will not be the same due to the
|
||||
# difference in tags. But size should still be the same
|
||||
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(im2.tostring()),len(im3.tostring()))
|
||||
# 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_(len(im2.tostring('tiff:method=tiled:tile_width=32:tile_height=32')),len(im3.tostring('tiff:method=tiled:tile_width=32:tile_height=32')))
|
||||
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'
|
||||
|
@ -110,27 +150,31 @@ 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()))
|
||||
# Because one will end up with UNASSOC alpha tag which internally the TIFF will multiply, the first to string will not be the same due to the
|
||||
# difference in tags. HOWEVER for this type they have the same size? Perhaps is a bad test?
|
||||
eq_(len(im.tostring('tiff:method=tiled')),len(im2.tostring('tiff:method=tiled')))
|
||||
eq_(len(im2.tostring()),len(im3.tostring()))
|
||||
# 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_(len(im2.tostring('tiff:method=tiled')),len(im3.tostring('tiff:method=tiled')))
|
||||
eq_(hashstr(im2.tostring('tiff:method=tiled')),hashstr(im3.tostring('tiff:method=tiled')))
|
||||
|
||||
|
||||
def test_tiff_rgb8_compare():
|
||||
filepath1 = '../data/tiff/ndvi_256x256_rgb8_striped.tif'
|
||||
filepath2 = '/tmp/mapnik-tiff-rgb8.tiff'
|
||||
im = mapnik.Image.open(filepath1)
|
||||
im.save(filepath2,'tiff:method=stripped:rows_per_strip=10')
|
||||
im.save(filepath2,'tiff')
|
||||
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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.rgba8).tostring("tiff")),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'
|
||||
|
@ -140,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.rgba8).tostring("tiff")),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'
|
||||
|
@ -153,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.rgba8).tostring("tiff")),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'
|
||||
|
@ -166,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.rgba8).tostring("tiff")),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'
|
||||
|
@ -179,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray8).tostring("tiff")),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'
|
||||
|
@ -192,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray8).tostring("tiff")),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'
|
||||
|
@ -205,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray8).tostring("tiff")),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'
|
||||
|
@ -218,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray16).tostring("tiff")),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'
|
||||
|
@ -231,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray16).tostring("tiff")),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'
|
||||
|
@ -244,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray16).tostring("tiff")),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'
|
||||
|
@ -257,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray32f).tostring("tiff")),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'
|
||||
|
@ -270,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray32f).tostring("tiff")),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'
|
||||
|
@ -283,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("tiff")) != len(mapnik.Image(im.width(),im.height(),mapnik.ImageType.gray32f).tostring("tiff")),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 |