Merge branch 'master' into bugfix/image_util_impl
Conflicts: include/mapnik/image_view.hpp src/image_util.cpp
This commit is contained in:
commit
08c675e1a4
17 changed files with 164 additions and 209 deletions
|
@ -54,7 +54,7 @@ void render(mapnik::geometry_type & geom,
|
|||
ras.add_path(path);
|
||||
agg::scanline_u8 sl;
|
||||
agg::render_scanlines(ras, sl, ren);
|
||||
mapnik::save_to_file(im,name);
|
||||
mapnik::save_to_file(im.data(),name);
|
||||
geom.rewind(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
mapnik::image_32 im(m.width(),m.height());
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(m,im);
|
||||
ren.apply();
|
||||
//mapnik::save_to_file(im,"test.png");
|
||||
//mapnik::save_to_file(im.data(),"test.png");
|
||||
return true;
|
||||
}
|
||||
bool operator()() const
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
ren.apply();
|
||||
if (!preview_.empty()) {
|
||||
std::clog << "preview available at " << preview_ << "\n";
|
||||
mapnik::save_to_file(im,preview_);
|
||||
mapnik::save_to_file(im.data(),preview_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public:
|
|||
ren.end_map_processing(*m_);
|
||||
if (!preview_.empty()) {
|
||||
std::clog << "preview available at " << preview_ << "\n";
|
||||
mapnik::save_to_file(im_,preview_);
|
||||
mapnik::save_to_file(im_.data(),preview_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
// cairo
|
||||
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
|
||||
#include <mapnik/cairo/cairo_context.hpp>
|
||||
#include <mapnik/cairo/cairo_image_util.hpp>
|
||||
#include <pycairo.h>
|
||||
#include <cairo.h>
|
||||
#endif
|
||||
|
@ -98,17 +99,17 @@ PyObject* tostring3(image_32 const & im, std::string const& format, mapnik::rgba
|
|||
|
||||
void save_to_file1(mapnik::image_32 const& im, std::string const& filename)
|
||||
{
|
||||
save_to_file(im,filename);
|
||||
save_to_file(im.data(),filename);
|
||||
}
|
||||
|
||||
void save_to_file2(mapnik::image_32 const& im, std::string const& filename, std::string const& type)
|
||||
{
|
||||
save_to_file(im,filename,type);
|
||||
save_to_file(im.data(),filename,type);
|
||||
}
|
||||
|
||||
void save_to_file3(mapnik::image_32 const& im, std::string const& filename, std::string const& type, mapnik::rgba_palette const& pal)
|
||||
{
|
||||
save_to_file(im,filename,type,pal);
|
||||
save_to_file(im.data(),filename,type,pal);
|
||||
}
|
||||
|
||||
bool painted(mapnik::image_32 const& im)
|
||||
|
@ -217,7 +218,8 @@ void composite(image_32 & dst, image_32 & src, mapnik::composite_mode_e mode, fl
|
|||
std::shared_ptr<image_32> from_cairo(PycairoSurface* py_surface)
|
||||
{
|
||||
mapnik::cairo_surface_ptr surface(cairo_surface_reference(py_surface->surface), mapnik::cairo_surface_closer());
|
||||
std::shared_ptr<image_32> image_ptr = std::make_shared<image_32>(surface);
|
||||
std::shared_ptr<image_32> image_ptr = std::make_shared<image_32>(cairo_image_surface_get_width(&*surface), cairo_image_surface_get_height(&*surface));
|
||||
cairo_image_to_rgba8(image_ptr->data(), image_surface);
|
||||
return image_ptr;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -387,7 +387,7 @@ void render_to_file1(mapnik::Map const& map,
|
|||
{
|
||||
mapnik::image_32 image(map.width(),map.height());
|
||||
render(map,image,1.0,0,0);
|
||||
mapnik::save_to_file(image,filename,format);
|
||||
mapnik::save_to_file(image.data(),filename,format);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -406,7 +406,7 @@ void render_to_file2(mapnik::Map const& map,std::string const& filename)
|
|||
{
|
||||
mapnik::image_32 image(map.width(),map.height());
|
||||
render(map,image,1.0,0,0);
|
||||
mapnik::save_to_file(image,filename);
|
||||
mapnik::save_to_file(image.data(),filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -444,7 +444,7 @@ void render_to_file3(mapnik::Map const& map,
|
|||
{
|
||||
mapnik::image_32 image(map.width(),map.height());
|
||||
render(map,image,scale_factor,0,0);
|
||||
mapnik::save_to_file(image,filename,format);
|
||||
mapnik::save_to_file(image.data(),filename,format);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
|
||||
#if defined(HAVE_CAIRO)
|
||||
#include <mapnik/cairo/cairo_renderer.hpp>
|
||||
#include <mapnik/cairo/cairo_image_util.hpp>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
@ -309,21 +310,21 @@ int main ( int, char** )
|
|||
ren.apply();
|
||||
std::string msg("These maps have been rendered using AGG in the current directory:\n");
|
||||
#ifdef HAVE_JPEG
|
||||
save_to_file(buf,"demo.jpg","jpeg");
|
||||
save_to_file(buf.data(),"demo.jpg","jpeg");
|
||||
msg += "- demo.jpg\n";
|
||||
#endif
|
||||
#ifdef HAVE_PNG
|
||||
save_to_file(buf,"demo.png","png");
|
||||
save_to_file(buf,"demo256.png","png8");
|
||||
save_to_file(buf.data(),"demo.png","png");
|
||||
save_to_file(buf.data(),"demo256.png","png8");
|
||||
msg += "- demo.png\n";
|
||||
msg += "- demo256.png\n";
|
||||
#endif
|
||||
#ifdef HAVE_TIFF
|
||||
save_to_file(buf,"demo.tif","tiff");
|
||||
save_to_file(buf.data(),"demo.tif","tiff");
|
||||
msg += "- demo.tif\n";
|
||||
#endif
|
||||
#ifdef HAVE_WEBP
|
||||
save_to_file(buf,"demo.webp","webp");
|
||||
save_to_file(buf.data(),"demo.webp","webp");
|
||||
msg += "- demo.webp\n";
|
||||
#endif
|
||||
msg += "Have a look!\n";
|
||||
|
@ -352,8 +353,9 @@ int main ( int, char** )
|
|||
cairo_surface_write_to_png(&*image_surface, "cairo-demo.png");
|
||||
// but we can also benefit from quantization by converting
|
||||
// to a mapnik image object and then saving that
|
||||
image_32 im(image_surface);
|
||||
save_to_file(im, "cairo-demo256.png","png8");
|
||||
mapnik::image_data_rgba8 im_data(cairo_image_surface_get_width(&*image_surface), cairo_image_surface_get_height(&*image_surface));
|
||||
cairo_image_to_rgba8(im_data, image_surface);
|
||||
save_to_file(im_data, "cairo-demo256.png","png8");
|
||||
cairo_surface_finish(&*image_surface);
|
||||
|
||||
std::cout << "Three maps have been rendered using Cairo in the current directory:\n"
|
||||
|
|
|
@ -23,13 +23,7 @@
|
|||
import sys
|
||||
from os import path
|
||||
|
||||
try:
|
||||
import mapnik
|
||||
except:
|
||||
print '\n\nThe mapnik library and python bindings must have been compiled and \
|
||||
installed successfully before running this script.\n\n'
|
||||
sys.exit(1)
|
||||
|
||||
import mapnik
|
||||
|
||||
# Instanciate a map, giving it a width and height. Remember: the word "map" is
|
||||
# reserved in Python! :)
|
||||
|
|
84
include/mapnik/cairo/cairo_image_util.hpp
Normal file
84
include/mapnik/cairo/cairo_image_util.hpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||
#define MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/image_data.hpp>
|
||||
#include <mapnik/cairo/cairo_context.hpp> // for cairo_surface_ptr
|
||||
|
||||
// stl
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
static inline void cairo_image_to_rgba8(mapnik::image_data_rgba8 & data,
|
||||
cairo_surface_ptr const& surface)
|
||||
{
|
||||
if (cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32)
|
||||
{
|
||||
throw std::runtime_error("Unable to convert this Cairo format to rgba8 image");
|
||||
}
|
||||
|
||||
if (cairo_image_surface_get_width(&*surface) != data.width() ||
|
||||
cairo_image_surface_get_height(&*surface) != data.height())
|
||||
{
|
||||
throw std::runtime_error("Mismatch in dimensions: size of image must match side of cairo surface");
|
||||
}
|
||||
|
||||
int stride = cairo_image_surface_get_stride(&*surface) / 4;
|
||||
|
||||
const std::unique_ptr<unsigned int[]> out_row(new unsigned int[data.width()]);
|
||||
const unsigned int *in_row = (const unsigned int *)cairo_image_surface_get_data(&*surface);
|
||||
|
||||
for (unsigned int row = 0; row < data.height(); row++, in_row += stride)
|
||||
{
|
||||
for (unsigned int column = 0; column < data.width(); column++)
|
||||
{
|
||||
unsigned int in = in_row[column];
|
||||
unsigned int a = (in >> 24) & 0xff;
|
||||
unsigned int r = (in >> 16) & 0xff;
|
||||
unsigned int g = (in >> 8) & 0xff;
|
||||
unsigned int b = (in >> 0) & 0xff;
|
||||
|
||||
#define DE_ALPHA(x) do { \
|
||||
if (a == 0) x = 0; \
|
||||
else x = x * 255 / a; \
|
||||
if (x > 255) x = 255; \
|
||||
} while(0)
|
||||
|
||||
DE_ALPHA(r);
|
||||
DE_ALPHA(g);
|
||||
DE_ALPHA(b);
|
||||
|
||||
out_row[column] = color(r, g, b, a).rgba();
|
||||
}
|
||||
data.setRow(row, out_row.get(), data.width());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // MAPNIK_CAIRO_IMAGE_UTIL_HPP
|
|
@ -39,30 +39,20 @@
|
|||
// boost
|
||||
#include <boost/optional/optional.hpp>
|
||||
|
||||
struct _cairo_surface;
|
||||
typedef struct _cairo_surface cairo_surface_t;
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
using cairo_surface_ptr = std::shared_ptr<cairo_surface_t>;
|
||||
|
||||
class MAPNIK_DECL image_32
|
||||
{
|
||||
private:
|
||||
unsigned width_;
|
||||
unsigned height_;
|
||||
boost::optional<color> background_;
|
||||
image_data_rgba8 data_;
|
||||
boost::optional<color> background_;
|
||||
bool painted_;
|
||||
bool premultiplied_;
|
||||
public:
|
||||
using pixel_type = typename image_data_rgba8::pixel_type;
|
||||
image_32(int width,int height);
|
||||
image_32(image_32 const& rhs);
|
||||
#ifdef HAVE_CAIRO
|
||||
explicit image_32(cairo_surface_ptr const& surface);
|
||||
#endif
|
||||
~image_32();
|
||||
|
||||
void painted(bool painted)
|
||||
|
@ -138,7 +128,7 @@ private:
|
|||
|
||||
inline bool checkBounds(int x, int y) const
|
||||
{
|
||||
return (x >= 0 && x < static_cast<int>(width_) && y >= 0 && y < static_cast<int>(height_));
|
||||
return (x >= 0 && x < static_cast<int>(data_.width()) && y >= 0 && y < static_cast<int>(data_.height()));
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -154,17 +144,17 @@ public:
|
|||
|
||||
inline unsigned width() const
|
||||
{
|
||||
return width_;
|
||||
return data_.width();
|
||||
}
|
||||
|
||||
inline unsigned height() const
|
||||
{
|
||||
return height_;
|
||||
return data_.height();
|
||||
}
|
||||
|
||||
inline void set_rectangle(int x0,int y0,image_data_rgba8 const& data)
|
||||
{
|
||||
box2d<int> ext0(0,0,width_,height_);
|
||||
box2d<int> ext0(0,0,data_.width(),data_.height());
|
||||
box2d<int> ext1(x0,y0,x0+data.width(),y0+data.height());
|
||||
|
||||
if (ext0.intersects(ext1))
|
||||
|
@ -188,7 +178,7 @@ public:
|
|||
|
||||
inline void set_rectangle_alpha(int x0,int y0,const image_data_rgba8& data)
|
||||
{
|
||||
box2d<int> ext0(0,0,width_,height_);
|
||||
box2d<int> ext0(0,0,data_.width(),data_.height());
|
||||
box2d<int> ext1(x0,y0,x0 + data.width(),y0 + data.height());
|
||||
|
||||
if (ext0.intersects(ext1))
|
||||
|
@ -232,7 +222,7 @@ public:
|
|||
|
||||
inline void set_rectangle_alpha2(image_data_rgba8 const& data, unsigned x0, unsigned y0, float opacity)
|
||||
{
|
||||
box2d<int> ext0(0,0,width_,height_);
|
||||
box2d<int> ext0(0,0,data_.width(),data_.height());
|
||||
box2d<int> ext1(x0,y0,x0 + data.width(),y0 + data.height());
|
||||
|
||||
if (ext0.intersects(ext1))
|
||||
|
@ -280,7 +270,7 @@ public:
|
|||
template <typename MergeMethod>
|
||||
inline void merge_rectangle(image_data_rgba8 const& data, unsigned x0, unsigned y0, float opacity)
|
||||
{
|
||||
box2d<int> ext0(0,0,width_,height_);
|
||||
box2d<int> ext0(0,0,data_.width(),data_.height());
|
||||
box2d<int> ext1(x0,y0,x0 + data.width(),y0 + data.height());
|
||||
|
||||
if (ext0.intersects(ext1))
|
||||
|
|
|
@ -45,7 +45,6 @@ namespace mapnik {
|
|||
// fwd declares
|
||||
class Map;
|
||||
class rgba_palette;
|
||||
class image_32;
|
||||
|
||||
class ImageWriterException : public std::exception
|
||||
{
|
||||
|
@ -211,44 +210,6 @@ void add_border(T & image)
|
|||
}
|
||||
|
||||
|
||||
|
||||
/////////// save_to_file //////////////////////////////////////////////////
|
||||
|
||||
MAPNIK_DECL void save_to_file(image_32 const& image,
|
||||
std::string const& file);
|
||||
|
||||
MAPNIK_DECL void save_to_file (image_32 const& image,
|
||||
std::string const& file,
|
||||
std::string const& type);
|
||||
|
||||
MAPNIK_DECL void save_to_file (image_32 const& image,
|
||||
std::string const& file,
|
||||
std::string const& type,
|
||||
rgba_palette const& palette);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
MAPNIK_DECL std::string save_to_string(image_32 const& image,
|
||||
std::string const& type);
|
||||
|
||||
MAPNIK_DECL std::string save_to_string(image_32 const& image,
|
||||
std::string const& type,
|
||||
rgba_palette const& palette);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MAPNIK_DECL void save_to_stream(image_32 const& image,
|
||||
std::ostream & stream,
|
||||
std::string const& type,
|
||||
rgba_palette const& palette);
|
||||
|
||||
MAPNIK_DECL void save_to_stream(image_32 const& image,
|
||||
std::ostream & stream,
|
||||
std::string const& type);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern template MAPNIK_DECL void save_to_file<image_data_rgba8>(image_data_rgba8 const&,
|
||||
std::string const&,
|
||||
std::string const&,
|
||||
|
|
|
@ -105,27 +105,11 @@ public:
|
|||
return data_.getRow(row + y_, x0) + x_;
|
||||
}
|
||||
|
||||
inline const unsigned char* getBytes() const
|
||||
{
|
||||
return data_.getBytes();
|
||||
}
|
||||
|
||||
inline unsigned char* getBytes()
|
||||
{
|
||||
return const_cast<unsigned char*>(data_.getBytes());
|
||||
}
|
||||
|
||||
inline T const& data() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
inline const pixel_type* getData() const
|
||||
{
|
||||
return data_.getData();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
unsigned x_;
|
||||
unsigned y_;
|
||||
|
|
|
@ -39,74 +39,24 @@
|
|||
namespace mapnik
|
||||
{
|
||||
image_32::image_32(int width,int height)
|
||||
:width_(width),
|
||||
height_(height),
|
||||
data_(width,height),
|
||||
: data_(width,height),
|
||||
painted_(false),
|
||||
premultiplied_(false) {}
|
||||
|
||||
|
||||
image_32::image_32(image_32 const& rhs)
|
||||
:width_(rhs.width_),
|
||||
height_(rhs.height_),
|
||||
data_(rhs.data_),
|
||||
: data_(rhs.data_),
|
||||
painted_(rhs.painted_),
|
||||
premultiplied_(rhs.premultiplied_) {}
|
||||
|
||||
#ifdef HAVE_CAIRO
|
||||
image_32::image_32(cairo_surface_ptr const& surface)
|
||||
:width_(cairo_image_surface_get_width(&*surface)),
|
||||
height_(cairo_image_surface_get_height(&*surface)),
|
||||
data_(width_, height_),
|
||||
premultiplied_(false)
|
||||
{
|
||||
painted_ = true;
|
||||
if ( cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32)
|
||||
{
|
||||
MAPNIK_LOG_WARN(graphics) << "Unable to convert this Cairo format";
|
||||
throw;
|
||||
}
|
||||
|
||||
int stride = cairo_image_surface_get_stride(&*surface) / 4;
|
||||
|
||||
const std::unique_ptr<unsigned int[]> out_row(new unsigned int[width_]);
|
||||
const unsigned int *in_row = (const unsigned int *)cairo_image_surface_get_data(&*surface);
|
||||
|
||||
for (unsigned int row = 0; row < height_; row++, in_row += stride)
|
||||
{
|
||||
for (unsigned int column = 0; column < width_; column++)
|
||||
{
|
||||
unsigned int in = in_row[column];
|
||||
unsigned int a = (in >> 24) & 0xff;
|
||||
unsigned int r = (in >> 16) & 0xff;
|
||||
unsigned int g = (in >> 8) & 0xff;
|
||||
unsigned int b = (in >> 0) & 0xff;
|
||||
|
||||
#define DE_ALPHA(x) do { \
|
||||
if (a == 0) x = 0; \
|
||||
else x = x * 255 / a; \
|
||||
if (x > 255) x = 255; \
|
||||
} while(0)
|
||||
|
||||
DE_ALPHA(r);
|
||||
DE_ALPHA(g);
|
||||
DE_ALPHA(b);
|
||||
|
||||
out_row[column] = color(r, g, b, a).rgba();
|
||||
}
|
||||
data_.setRow(row, out_row.get(), width_);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
image_32::~image_32() {}
|
||||
|
||||
void image_32::set_grayscale_to_alpha()
|
||||
{
|
||||
for (unsigned int y = 0; y < height_; ++y)
|
||||
for (unsigned int y = 0; y < data_.height(); ++y)
|
||||
{
|
||||
unsigned int* row_from = data_.getRow(y);
|
||||
for (unsigned int x = 0; x < width_; ++x)
|
||||
for (unsigned int x = 0; x < data_.width(); ++x)
|
||||
{
|
||||
unsigned rgba = row_from[x];
|
||||
unsigned r = rgba & 0xff;
|
||||
|
@ -123,10 +73,10 @@ void image_32::set_grayscale_to_alpha()
|
|||
|
||||
void image_32::set_color_to_alpha(const color& c)
|
||||
{
|
||||
for (unsigned y = 0; y < height_; ++y)
|
||||
for (unsigned y = 0; y < data_.height(); ++y)
|
||||
{
|
||||
unsigned int* row_from = data_.getRow(y);
|
||||
for (unsigned x = 0; x < width_; ++x)
|
||||
for (unsigned x = 0; x < data_.width(); ++x)
|
||||
{
|
||||
unsigned rgba = row_from[x];
|
||||
unsigned r = rgba & 0xff;
|
||||
|
@ -142,10 +92,10 @@ void image_32::set_color_to_alpha(const color& c)
|
|||
|
||||
void image_32::set_alpha(float opacity)
|
||||
{
|
||||
for (unsigned int y = 0; y < height_; ++y)
|
||||
for (unsigned int y = 0; y < data_.height(); ++y)
|
||||
{
|
||||
unsigned int* row_to = data_.getRow(y);
|
||||
for (unsigned int x = 0; x < width_; ++x)
|
||||
for (unsigned int x = 0; x < data_.width(); ++x)
|
||||
{
|
||||
unsigned rgba = row_to[x];
|
||||
unsigned a0 = (rgba >> 24) & 0xff;
|
||||
|
@ -175,7 +125,7 @@ boost::optional<color> const& image_32::get_background() const
|
|||
|
||||
void image_32::premultiply()
|
||||
{
|
||||
agg::rendering_buffer buffer(data_.getBytes(),width_,height_,width_ * 4);
|
||||
agg::rendering_buffer buffer(data_.getBytes(),data_.width(),data_.height(),data_.width() * 4);
|
||||
agg::pixfmt_rgba32 pixf(buffer);
|
||||
pixf.premultiply();
|
||||
premultiplied_ = true;
|
||||
|
@ -183,7 +133,7 @@ void image_32::premultiply()
|
|||
|
||||
void image_32::demultiply()
|
||||
{
|
||||
agg::rendering_buffer buffer(data_.getBytes(),width_,height_,width_ * 4);
|
||||
agg::rendering_buffer buffer(data_.getBytes(),data_.width(),data_.height(),data_.width() * 4);
|
||||
agg::pixfmt_rgba32_pre pixf(buffer);
|
||||
pixf.demultiply();
|
||||
premultiplied_ = false;
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
#include <mapnik/image_util_tiff.hpp>
|
||||
#include <mapnik/image_util_webp.hpp>
|
||||
#include <mapnik/image_data.hpp>
|
||||
#include <mapnik/image_data_any.hpp>
|
||||
#include <mapnik/graphics.hpp>
|
||||
#include <mapnik/memory.hpp>
|
||||
#include <mapnik/image_view.hpp>
|
||||
#include <mapnik/palette.hpp>
|
||||
|
@ -327,37 +325,4 @@ template std::string save_to_string<image_view<image_data_rgba8> > (image_view<i
|
|||
std::string const&,
|
||||
rgba_palette const& palette);
|
||||
|
||||
void save_to_file(image_32 const& image,std::string const& file)
|
||||
{
|
||||
save_to_file<image_data_rgba8>(image.data(), file);
|
||||
}
|
||||
|
||||
void save_to_file (image_32 const& image,
|
||||
std::string const& file,
|
||||
std::string const& type)
|
||||
{
|
||||
save_to_file<image_data_rgba8>(image.data(), file, type);
|
||||
}
|
||||
|
||||
void save_to_file (image_32 const& image,
|
||||
std::string const& file,
|
||||
std::string const& type,
|
||||
rgba_palette const& palette)
|
||||
{
|
||||
save_to_file<image_data_rgba8>(image.data(), file, type, palette);
|
||||
}
|
||||
|
||||
std::string save_to_string(image_32 const& image,
|
||||
std::string const& type)
|
||||
{
|
||||
return save_to_string<image_data_rgba8>(image.data(), type);
|
||||
}
|
||||
|
||||
std::string save_to_string(image_32 const& image,
|
||||
std::string const& type,
|
||||
rgba_palette const& palette)
|
||||
{
|
||||
return save_to_string<image_data_rgba8>(image.data(), type, palette);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#include <mapnik/util/fs.hpp>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#if defined(HAVE_CAIRO)
|
||||
#include <mapnik/cairo/cairo_context.hpp>
|
||||
#include <mapnik/cairo/cairo_image_util.hpp>
|
||||
#endif
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
|
@ -60,6 +64,18 @@ int main(int argc, char** argv)
|
|||
BOOST_TEST( true ); // should hit bad alloc here
|
||||
}
|
||||
|
||||
#if defined(HAVE_CAIRO)
|
||||
mapnik::cairo_surface_ptr image_surface(
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,256,257),
|
||||
mapnik::cairo_surface_closer());
|
||||
mapnik::image_data_rgba8 im_data(cairo_image_surface_get_width(&*image_surface), cairo_image_surface_get_height(&*image_surface));
|
||||
im_data.set(1);
|
||||
BOOST_TEST( (unsigned)im_data(0,0) == unsigned(1) );
|
||||
// Should set back to fully transparent
|
||||
mapnik::cairo_image_to_rgba8(im_data, image_surface);
|
||||
BOOST_TEST( (unsigned)im_data(0,0) == unsigned(0) );
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_PNG)
|
||||
should_throw = "./tests/cpp_tests/data/blank.png";
|
||||
BOOST_TEST( mapnik::util::exists( should_throw ) );
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include <mapnik/image_reader.hpp>
|
||||
#include <mapnik/scale_denominator.hpp>
|
||||
#include <mapnik/feature_style_processor.hpp>
|
||||
#include <mapnik/projection.hpp>
|
||||
#include <mapnik/layer.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
@ -65,9 +67,6 @@ int main(int argc, char** argv)
|
|||
args.push_back(argv[i]);
|
||||
}
|
||||
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
|
||||
// TODO - re-enable if we can control the freetype/cairo versions used
|
||||
// https://github.com/mapnik/mapnik/issues/1868
|
||||
/*
|
||||
std::string expected("./tests/cpp_tests/support/map-request-marker-text-line-expected.png");
|
||||
std::string expected_cairo("./tests/cpp_tests/support/map-request-marker-text-line-expected-cairo.png");
|
||||
try {
|
||||
|
@ -86,9 +85,11 @@ int main(int argc, char** argv)
|
|||
mapnik::agg_renderer<mapnik::image_32> renderer1(m,im,scale_factor);
|
||||
renderer1.apply();
|
||||
std::string actual1("/tmp/map-request-marker-text-line-actual1.png");
|
||||
//mapnik::save_to_file(im,expected);
|
||||
mapnik::save_to_file(im,actual1);
|
||||
BOOST_TEST(compare_images(actual1,expected));
|
||||
//mapnik::save_to_file(im.data(),expected);
|
||||
mapnik::save_to_file(im.data(),actual1);
|
||||
// TODO - re-enable if we can control the freetype/cairo versions used
|
||||
// https://github.com/mapnik/mapnik/issues/1868
|
||||
//BOOST_TEST(compare_images(actual1,expected));
|
||||
|
||||
// reset image
|
||||
im.clear();
|
||||
|
@ -98,17 +99,20 @@ int main(int argc, char** argv)
|
|||
req.set_buffer_size(m.buffer_size());
|
||||
|
||||
// render using apply() and mapnik::request
|
||||
mapnik::agg_renderer<mapnik::image_32> renderer2(m,req,im,scale_factor);
|
||||
mapnik::attributes vars;
|
||||
mapnik::agg_renderer<mapnik::image_32> renderer2(m,req,vars,im,scale_factor);
|
||||
renderer2.apply();
|
||||
std::string actual2("/tmp/map-request-marker-text-line-actual2.png");
|
||||
mapnik::save_to_file(im,actual2);
|
||||
BOOST_TEST(compare_images(actual2,expected));
|
||||
mapnik::save_to_file(im.data(),actual2);
|
||||
// TODO - re-enable if we can control the freetype/cairo versions used
|
||||
// https://github.com/mapnik/mapnik/issues/1868
|
||||
//BOOST_TEST(compare_images(actual2,expected));
|
||||
|
||||
// reset image
|
||||
im.clear();
|
||||
|
||||
// render with apply_to_layer api and mapnik::request params passed to apply_to_layer
|
||||
mapnik::agg_renderer<mapnik::image_32> renderer3(m,req,im,scale_factor);
|
||||
mapnik::agg_renderer<mapnik::image_32> renderer3(m,req,vars,im,scale_factor);
|
||||
renderer3.start_map_processing(m);
|
||||
mapnik::projection map_proj(m.srs(),true);
|
||||
double scale_denom = mapnik::scale_denominator(req.scale(),map_proj.is_geographic());
|
||||
|
@ -133,8 +137,10 @@ int main(int argc, char** argv)
|
|||
}
|
||||
renderer3.end_map_processing(m);
|
||||
std::string actual3("/tmp/map-request-marker-text-line-actual3.png");
|
||||
mapnik::save_to_file(im,actual3);
|
||||
BOOST_TEST(compare_images(actual3,expected));
|
||||
mapnik::save_to_file(im.data(),actual3);
|
||||
// TODO - re-enable if we can control the freetype/cairo versions used
|
||||
// https://github.com/mapnik/mapnik/issues/1868
|
||||
//BOOST_TEST(compare_images(actual3,expected));
|
||||
|
||||
// also test cairo
|
||||
#if defined(HAVE_CAIRO)
|
||||
|
@ -142,19 +148,20 @@ int main(int argc, char** argv)
|
|||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,req.width(),req.height()),
|
||||
mapnik::cairo_surface_closer());
|
||||
mapnik::cairo_ptr image_context = (mapnik::create_context(image_surface));
|
||||
mapnik::cairo_renderer<mapnik::cairo_ptr> png_render(m,req,image_context,scale_factor);
|
||||
mapnik::cairo_renderer<mapnik::cairo_ptr> png_render(m,req,vars,image_context,scale_factor);
|
||||
png_render.apply();
|
||||
//cairo_surface_write_to_png(&*image_surface, expected_cairo.c_str());
|
||||
std::string actual_cairo("/tmp/map-request-marker-text-line-actual4.png");
|
||||
cairo_surface_write_to_png(&*image_surface, actual_cairo.c_str());
|
||||
BOOST_TEST(compare_images(actual_cairo,expected_cairo));
|
||||
// TODO - re-enable if we can control the freetype/cairo versions used
|
||||
// https://github.com/mapnik/mapnik/issues/1868
|
||||
//BOOST_TEST(compare_images(actual_cairo,expected_cairo));
|
||||
#endif
|
||||
// TODO - test grid_renderer
|
||||
|
||||
} catch (std::exception const& ex) {
|
||||
std::clog << ex.what() << "\n";
|
||||
}
|
||||
*/
|
||||
if (!::boost::detail::test_errors()) {
|
||||
if (quiet) std::clog << "\x1b[1;32m.\x1b[0m";
|
||||
else std::clog << "C++ Map Request rendering hook: \x1b[1;32m✓ \x1b[0m\n";
|
||||
|
|
|
@ -140,7 +140,7 @@ int main (int argc,char** argv)
|
|||
}
|
||||
mapnik::agg_renderer<mapnik::image_32> ren(map,req,vars,im,scale_factor,0,0);
|
||||
ren.apply();
|
||||
mapnik::save_to_file(im,img_file);
|
||||
mapnik::save_to_file(im.data(),img_file);
|
||||
if (auto_open)
|
||||
{
|
||||
std::ostringstream s;
|
||||
|
|
Loading…
Reference in a new issue