Merge branch 'master' into mapnik-geometry

This commit is contained in:
artemp 2015-03-16 16:20:46 +01:00
commit 71c9c04e92
19 changed files with 1342 additions and 843 deletions

View file

@ -30,6 +30,10 @@ script:
- source bootstrap.sh
- wget https://gist.githubusercontent.com/springmeyer/0833fa43794838889139/raw/build_pycairo.sh && chmod +x build_pycairo.sh && ./build_pycairo.sh
- export PYTHONPATH=$(pwd)/mason_packages/.link/lib/python2.7/site-packages:${PYTHONPATH}
- if [[ ${COVERAGE} == true ]]; then ./configure CUSTOM_LDFLAGS='--coverage' CUSTOM_CXXFLAGS='--coverage' CUSTOM_CFLAGS='--coverage' DEBUG=True; else ./configure; fi;
- make
- git clone --depth=1 https://github.com/mapbox/mapnik-test-data tests/data/mapnik-test-data
- make test
- if [[ ${COVERAGE} == true ]]; then
brew update;
brew install pyenv;
@ -40,9 +44,5 @@ script:
pip install cpp-coveralls;
pyenv rehash;
fi;
- if [[ ${COVERAGE} == true ]]; then ./configure CUSTOM_LDFLAGS='--coverage' CUSTOM_CXXFLAGS='--coverage' CUSTOM_CFLAGS='--coverage' DEBUG=True; else ./configure; fi;
- make
- git clone --depth=1 https://github.com/mapbox/mapnik-test-data tests/data/mapnik-test-data
- make test
- if [[ ${COVERAGE} == true ]]; then cpp-coveralls --build-root . --gcov-options '\-lp' --exclude mason_packages --exclude .sconf_temp --exclude benchmark --exclude deps --exclude scons --exclude tests --exclude demo --exclude docs --exclude fonts --exclude utils > /dev/null; fi;
- if [[ ${COVERAGE} == true ]]; then cpp-coveralls --build-root . --gcov-options '\-lp' --exclude mason_packages --exclude .sconf_temp --exclude benchmark --exclude deps --exclude scons --exclude tests --exclude py2cairo-1.10.0 --exclude demo --exclude docs --exclude fonts --exclude utils > /dev/null; fi;
- if [[ ${COVERAGE} != true ]]; then make bench; fi;

View file

@ -10,6 +10,7 @@
#include <mapnik/util/fs.hpp>
#include <mapnik/polygon_clipper.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/color.hpp>
// agg
#include "agg_conv_clip_polygon.h"
// clipper

View file

@ -29,15 +29,12 @@
#include <mapnik/util/noncopyable.hpp> // for noncopyable
#include <mapnik/rule.hpp> // for rule, symbolizers
#include <mapnik/box2d.hpp> // for box2d
#include <mapnik/color.hpp> // for color
#include <mapnik/view_transform.hpp> // for view_transform
#include <mapnik/image_compositing.hpp> // for composite_mode_e
#include <mapnik/pixel_position.hpp>
#include <mapnik/request.hpp>
#include <mapnik/symbolizer_enumerations.hpp>
#include <mapnik/renderer_common.hpp>
#include <mapnik/image.hpp>
#include <mapnik/image_any.hpp>
// stl
#include <memory>
@ -51,9 +48,12 @@ namespace mapnik {
class feature_type_style;
class label_collision_detector4;
class layer;
class color;
struct marker;
class proj_transform;
struct rasterizer;
struct rgba8_t;
template<typename T> class image;
}
namespace mapnik {
@ -171,7 +171,7 @@ private:
void setup(Map const& m);
};
extern template class MAPNIK_DECL agg_renderer<image_rgba8>;
extern template class MAPNIK_DECL agg_renderer<image<rgba8_t>>;
} // namespace mapnik

View file

@ -20,66 +20,32 @@
*
*****************************************************************************/
#ifndef MAPNIK_IMAGE_DATA_HPP
#define MAPNIK_IMAGE_DATA_HPP
#ifndef MAPNIK_IMAGE_HPP
#define MAPNIK_IMAGE_HPP
// mapnik
#include <mapnik/global.hpp>
#include <mapnik/config.hpp>
#include <mapnik/pixel_types.hpp>
// stl
#include <algorithm>
#include <cassert>
#include <stdexcept>
#include <iostream>
namespace mapnik {
namespace detail {
struct buffer
struct MAPNIK_DECL buffer
{
explicit buffer(std::size_t size)
: size_(size),
data_(static_cast<unsigned char*>(size_ != 0 ? ::operator new(size_) : nullptr))
{}
explicit buffer(std::size_t size);
buffer(buffer && rhs) noexcept;
buffer(buffer const& rhs);
~buffer();
buffer(buffer && rhs) noexcept
: size_(std::move(rhs.size_)),
data_(std::move(rhs.data_))
{
rhs.size_ = 0;
rhs.data_ = nullptr;
}
buffer& operator=(buffer rhs);
bool operator!() const;
buffer(buffer const& rhs)
: size_(rhs.size_),
data_(static_cast<unsigned char*>(size_ != 0 ? ::operator new(size_) : nullptr))
{
if (data_) std::copy(rhs.data_, rhs.data_ + rhs.size_, data_);
}
buffer& operator=(buffer rhs)
{
swap(rhs);
return *this;
}
void swap(buffer & rhs)
{
std::swap(size_, rhs.size_);
std::swap(data_, rhs.data_);
}
inline bool operator!() const { return (data_ == nullptr)? false : true; }
~buffer()
{
::operator delete(data_);
}
inline unsigned char* data() { return data_; }
inline unsigned char const* data() const { return data_; }
inline std::size_t size() const { return size_; }
void swap(buffer & rhs);
unsigned char* data();
unsigned char const* data() const;
std::size_t size() const;
private:
std::size_t size_;
unsigned char* data_;
@ -88,38 +54,21 @@ struct buffer
template <std::size_t max_size>
struct image_dimensions
{
image_dimensions(int width, int height)
: width_(width),
height_(height)
{
if (width < 0 || static_cast<std::size_t>(width) > max_size) throw std::runtime_error("Invalid width for image dimensions requested");
if (height < 0 || static_cast<std::size_t>(height) > max_size) throw std::runtime_error("Invalid height for image dimensions requested");
}
image_dimensions(int width, int height);
image_dimensions(image_dimensions const& other) = default;
image_dimensions(image_dimensions && other) = default;
image_dimensions& operator= (image_dimensions rhs)
{
std::swap(width_, rhs.width_);
std::swap(height_, rhs.height_);
return *this;
}
std::size_t width() const
{
return width_;
}
std::size_t height() const
{
return height_;
}
image_dimensions& operator= (image_dimensions rhs);
std::size_t width() const;
std::size_t height() const;
private:
std::size_t width_;
std::size_t height_;
};
}
} // end ns detail
template <typename T, std::size_t max_size = 65535>
class image
template <typename T>
class MAPNIK_DECL image
{
public:
using pixel = T;
@ -127,7 +76,7 @@ public:
static const image_dtype dtype = T::id;
static constexpr std::size_t pixel_size = sizeof(pixel_type);
private:
detail::image_dimensions<max_size> dimensions_;
detail::image_dimensions<65535> dimensions_;
detail::buffer buffer_;
pixel_type *pData_;
double offset_;
@ -135,192 +84,47 @@ private:
bool premultiplied_alpha_;
bool painted_;
public:
image(int width, int height, bool initialize = true, bool premultiplied = false, bool painted = false)
: dimensions_(width, height),
buffer_(dimensions_.width() * dimensions_.height() * pixel_size),
pData_(reinterpret_cast<pixel_type*>(buffer_.data())),
offset_(0.0),
scaling_(1.0),
premultiplied_alpha_(premultiplied),
painted_(painted)
{
if (pData_ && initialize) std::fill(pData_, pData_ + dimensions_.width() * dimensions_.height(), 0);
}
image();
image(int width,
int height,
bool initialize = true,
bool premultiplied = false,
bool painted = false);
image(image<T> const& rhs);
image(image<T> && rhs) noexcept;
image<T>& operator=(image<T> rhs);
image<T>const& operator=(image<T> const& rhs) const;
image(image<T> const& rhs)
: dimensions_(rhs.dimensions_),
buffer_(rhs.buffer_),
pData_(reinterpret_cast<pixel_type*>(buffer_.data())),
offset_(rhs.offset_),
scaling_(rhs.scaling_),
premultiplied_alpha_(rhs.premultiplied_alpha_),
painted_(rhs.painted_)
{}
image(image<T> && rhs) noexcept
: dimensions_(std::move(rhs.dimensions_)),
buffer_(std::move(rhs.buffer_)),
pData_(reinterpret_cast<pixel_type*>(buffer_.data())),
offset_(rhs.offset_),
scaling_(rhs.scaling_),
premultiplied_alpha_(rhs.premultiplied_alpha_),
painted_(rhs.painted_)
{
rhs.dimensions_ = { 0, 0 };
rhs.pData_ = nullptr;
}
image<T>& operator=(image<T> rhs)
{
swap(rhs);
return *this;
}
void swap(image<T> & rhs)
{
std::swap(dimensions_, rhs.dimensions_);
std::swap(buffer_, rhs.buffer_);
std::swap(offset_, rhs.offset_);
std::swap(scaling_, rhs.scaling_);
std::swap(premultiplied_alpha_, rhs.premultiplied_alpha_);
std::swap(painted_, rhs.painted_);
}
inline pixel_type& operator() (std::size_t i, std::size_t j)
{
assert(i < dimensions_.width() && j < dimensions_.height());
return pData_[j * dimensions_.width() + i];
}
inline const pixel_type& operator() (std::size_t i, std::size_t j) const
{
assert(i < dimensions_.width() && j < dimensions_.height());
return pData_[j * dimensions_.width() + i];
}
inline std::size_t width() const
{
return dimensions_.width();
}
inline std::size_t height() const
{
return dimensions_.height();
}
inline unsigned getSize() const
{
return dimensions_.height() * dimensions_.width() * pixel_size;
}
inline unsigned getRowSize() const
{
return dimensions_.width() * pixel_size;
}
inline void set(pixel_type const& t)
{
std::fill(pData_, pData_ + dimensions_.width() * dimensions_.height(), t);
}
inline const pixel_type* getData() const
{
return pData_;
}
inline pixel_type* getData()
{
return pData_;
}
inline const unsigned char* getBytes() const
{
return buffer_.data();
}
inline unsigned char* getBytes()
{
return buffer_.data();
}
inline const pixel_type* getRow(std::size_t row) const
{
return pData_ + row * dimensions_.width();
}
inline const pixel_type* getRow(std::size_t row, std::size_t x0) const
{
return pData_ + row * dimensions_.width() + x0;
}
inline pixel_type* getRow(std::size_t row)
{
return pData_ + row * dimensions_.width();
}
inline pixel_type* getRow(std::size_t row, std::size_t x0)
{
return pData_ + row * dimensions_.width() + x0;
}
inline void setRow(std::size_t row, pixel_type const* buf, std::size_t size)
{
assert(row < dimensions_.height());
assert(size <= dimensions_.width());
std::copy(buf, buf + size, pData_ + row * dimensions_.width());
}
inline void setRow(std::size_t row, std::size_t x0, std::size_t x1, pixel_type const* buf)
{
assert(row < dimensions_.height());
assert ((x1 - x0) <= dimensions_.width() );
std::copy(buf, buf + (x1 - x0), pData_ + row * dimensions_.width() + x0);
}
inline double get_offset() const
{
return offset_;
}
inline void set_offset(double set)
{
offset_ = set;
}
inline double get_scaling() const
{
return scaling_;
}
inline void set_scaling(double set)
{
if (set != 0.0)
{
scaling_ = set;
return;
}
std::clog << "Can not set scaling to 0.0, offset not set." << std::endl;
}
inline bool get_premultiplied() const
{
return premultiplied_alpha_;
}
inline void set_premultiplied(bool set)
{
premultiplied_alpha_ = set;
}
inline void painted(bool painted)
{
painted_ = painted;
}
inline bool painted() const
{
return painted_;
}
inline image_dtype get_dtype() const
{
return dtype;
}
void swap(image<T> & rhs);
pixel_type& operator() (std::size_t i, std::size_t j);
const pixel_type& operator() (std::size_t i, std::size_t j) const;
std::size_t width() const;
std::size_t height() const;
unsigned getSize() const;
unsigned getRowSize() const;
void set(pixel_type const& t);
const pixel_type* getData() const;
pixel_type* getData();
const unsigned char* getBytes() const;
unsigned char* getBytes();
const pixel_type* getRow(std::size_t row) const;
const pixel_type* getRow(std::size_t row, std::size_t x0) const;
pixel_type* getRow(std::size_t row);
pixel_type* getRow(std::size_t row, std::size_t x0);
void setRow(std::size_t row, pixel_type const* buf, std::size_t size);
void setRow(std::size_t row, std::size_t x0, std::size_t x1, pixel_type const* buf);
double get_offset() const;
void set_offset(double set);
double get_scaling() const;
void set_scaling(double set);
bool get_premultiplied() const;
void set_premultiplied(bool set);
void painted(bool painted);
bool painted() const;
image_dtype get_dtype() const;
};
using image_null = image<null_t>;
using image_rgba8 = image<rgba8_t>;
using image_gray8 = image<gray8_t>;
using image_gray8s = image<gray8s_t>;
@ -333,6 +137,6 @@ using image_gray64 = image<gray64_t>;
using image_gray64s = image<gray64s_t>;
using image_gray64f = image<gray64f_t>;
} // end ns
} // end ns mapnik
#endif // MAPNIK_IMAGE_DATA_HPP
#endif // MAPNIK_IMAGE_HPP

View file

@ -20,43 +20,14 @@
*
*****************************************************************************/
#ifndef MAPNIK_IMAGE_DATA_ANY_HPP
#define MAPNIK_IMAGE_DATA_ANY_HPP
#ifndef MAPNIK_IMAGE_ANY_HPP
#define MAPNIK_IMAGE_ANY_HPP
#include <mapnik/image.hpp>
#include <mapnik/util/variant.hpp>
namespace mapnik {
struct image_null
{
using pixel_type = uint8_t;
static const image_dtype dtype = image_dtype_null;
unsigned char const* getBytes() const { return nullptr; }
unsigned char* getBytes() { return nullptr;}
unsigned getSize() const { return 0; }
unsigned getRowSize() const { return 0; }
std::size_t width() const { return 0; }
std::size_t height() const { return 0; }
bool painted() const { return false; }
double get_offset() const { return 0.0; }
void set_offset(double) {}
image_dtype get_dtype() const { return dtype; }
double get_scaling() const { return 1.0; }
void set_scaling(double) {}
bool get_premultiplied() const { return false; }
void set_premultiplied(bool) {}
void set(pixel_type const&) { throw std::runtime_error("Can not set values for null image"); }
pixel_type& operator() (std::size_t, std::size_t)
{
throw std::runtime_error("Can not set or get values for null image");
}
pixel_type const& operator() (std::size_t, std::size_t) const
{
throw std::runtime_error("Can not set or get values for null image");
}
};
using image_base = util::variant<image_null,
image_rgba8,
image_gray8,
@ -70,8 +41,37 @@ using image_base = util::variant<image_null,
image_gray64s,
image_gray64f>;
// Forward declaring
struct image_any;
struct MAPNIK_DECL image_any : image_base
{
image_any() = default;
image_any(int width,
int height,
image_dtype type = image_dtype_rgba8,
bool initialize = true,
bool premultiplied = false,
bool painted = false);
template <typename T>
image_any(T && data) noexcept
: image_base(std::move(data)) {}
unsigned char const* getBytes() const;
unsigned char* getBytes();
std::size_t width() const;
std::size_t height() const;
bool get_premultiplied() const;
bool painted() const;
unsigned getSize() const;
unsigned getRowSize() const;
double get_offset() const;
double get_scaling() const;
image_dtype get_dtype() const;
void set_offset(double val);
void set_scaling(double val);
};
image_any create_image_any(int width,
int height,
image_dtype type = image_dtype_rgba8,
@ -79,255 +79,6 @@ image_any create_image_any(int width,
bool premultiplied = false,
bool painted = false);
namespace detail {
struct get_bytes_visitor
{
template <typename T>
unsigned char* operator()(T & data)
{
return data.getBytes();
}
};
struct get_dtype_visitor
{
template <typename T>
image_dtype operator()(T & data)
{
return data.get_dtype();
}
};
struct get_bytes_visitor_const
{
template <typename T>
unsigned char const* operator()(T const& data) const
{
return data.getBytes();
}
};
struct get_width_visitor
{
template <typename T>
std::size_t operator()(T const& data) const
{
return data.width();
}
};
struct get_height_visitor
{
template <typename T>
std::size_t operator()(T const& data) const
{
return data.height();
}
};
struct get_premultiplied_visitor
{
template <typename T>
bool operator()(T const& data) const
{
return data.get_premultiplied();
}
};
struct get_painted_visitor
{
template <typename T>
bool operator()(T const& data) const
{
return data.painted();
}
};
struct get_any_size_visitor
{
template <typename T>
unsigned operator()(T const& data) const
{
return data.getSize();
}
};
struct get_any_row_size_visitor
{
template <typename T>
unsigned operator()(T const& data) const
{
return data.getRowSize();
}
};
struct get_offset_visitor
{
template <typename T>
double operator() (T const& data) const
{
return data.get_offset();
}
};
struct get_scaling_visitor
{
template <typename T>
double operator() (T const& data) const
{
return data.get_scaling();
}
};
struct set_offset_visitor
{
set_offset_visitor(double val)
: val_(val) {}
template <typename T>
void operator() (T & data)
{
data.set_offset(val_);
}
private:
double val_;
};
struct set_scaling_visitor
{
set_scaling_visitor(double val)
: val_(val) {}
template <typename T>
void operator() (T & data)
{
data.set_scaling(val_);
}
private:
double val_;
};
} // namespace detail
struct image_any : image_base
{
image_any() = default;
image_any(int width,
int height,
image_dtype type = image_dtype_rgba8,
bool initialize = true,
bool premultiplied = false,
bool painted = false)
: image_base(std::move(create_image_any(width, height, type, initialize, premultiplied, painted))) {}
template <typename T>
image_any(T && data) noexcept
: image_base(std::move(data)) {}
unsigned char const* getBytes() const
{
return util::apply_visitor(detail::get_bytes_visitor_const(),*this);
}
unsigned char* getBytes()
{
return util::apply_visitor(detail::get_bytes_visitor(),*this);
}
std::size_t width() const
{
return util::apply_visitor(detail::get_width_visitor(),*this);
}
std::size_t height() const
{
return util::apply_visitor(detail::get_height_visitor(),*this);
}
bool get_premultiplied() const
{
return util::apply_visitor(detail::get_premultiplied_visitor(),*this);
}
bool painted() const
{
return util::apply_visitor(detail::get_painted_visitor(),*this);
}
unsigned getSize() const
{
return util::apply_visitor(detail::get_any_size_visitor(),*this);
}
unsigned getRowSize() const
{
return util::apply_visitor(detail::get_any_row_size_visitor(),*this);
}
double get_offset() const
{
return util::apply_visitor(detail::get_offset_visitor(),*this);
}
double get_scaling() const
{
return util::apply_visitor(detail::get_scaling_visitor(),*this);
}
image_dtype get_dtype() const
{
return util::apply_visitor(detail::get_dtype_visitor(),*this);
}
void set_offset(double val)
{
util::apply_visitor(detail::set_offset_visitor(val),*this);
}
void set_scaling(double val)
{
util::apply_visitor(detail::set_scaling_visitor(val),*this);
}
};
inline image_any create_image_any(int width,
int height,
image_dtype type,
bool initialize,
bool premultiplied,
bool painted)
{
switch (type)
{
case image_dtype_gray8:
return image_any(std::move(image_gray8(width, height, initialize, premultiplied, painted)));
case image_dtype_gray8s:
return image_any(std::move(image_gray8s(width, height, initialize, premultiplied, painted)));
case image_dtype_gray16:
return image_any(std::move(image_gray16(width, height, initialize, premultiplied, painted)));
case image_dtype_gray16s:
return image_any(std::move(image_gray16s(width, height, initialize, premultiplied, painted)));
case image_dtype_gray32:
return image_any(std::move(image_gray32(width, height, initialize, premultiplied, painted)));
case image_dtype_gray32s:
return image_any(std::move(image_gray32s(width, height, initialize, premultiplied, painted)));
case image_dtype_gray32f:
return image_any(std::move(image_gray32f(width, height, initialize, premultiplied, painted)));
case image_dtype_gray64:
return image_any(std::move(image_gray64(width, height, initialize, premultiplied, painted)));
case image_dtype_gray64s:
return image_any(std::move(image_gray64s(width, height, initialize, premultiplied, painted)));
case image_dtype_gray64f:
return image_any(std::move(image_gray64f(width, height, initialize, premultiplied, painted)));
case image_dtype_null:
return image_any(std::move(image_null()));
case image_dtype_rgba8:
case IMAGE_DTYPE_MAX:
default:
return image_any(std::move(image_rgba8(width, height, initialize, premultiplied, painted)));
}
}
} // end mapnik ns
#endif // MAPNIK_IMAGE_DATA_ANY_HPP
#endif // MAPNIK_IMAGE_ANY_HPP

View file

@ -0,0 +1,330 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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_IMAGE_IMPL_HPP
#define MAPNIK_IMAGE_IMPL_HPP
// mapnik
#include <mapnik/image.hpp>
// stl
#include <algorithm>
#include <cassert>
#include <stdexcept>
#include <iostream>
namespace mapnik {
namespace detail {
// IMAGE_DIMENSIONS
template <std::size_t max_size>
image_dimensions<max_size>::image_dimensions(int width, int height)
: width_(width),
height_(height)
{
if (width < 0 || static_cast<std::size_t>(width) > max_size) throw std::runtime_error("Invalid width for image dimensions requested");
if (height < 0 || static_cast<std::size_t>(height) > max_size) throw std::runtime_error("Invalid height for image dimensions requested");
}
template <std::size_t max_size>
image_dimensions<max_size>& image_dimensions<max_size>::operator= (image_dimensions rhs)
{
std::swap(width_, rhs.width_);
std::swap(height_, rhs.height_);
return *this;
}
template <std::size_t max_size>
std::size_t image_dimensions<max_size>::width() const
{
return width_;
}
template <std::size_t max_size>
std::size_t image_dimensions<max_size>::height() const
{
return height_;
}
} // end detail ns
// IMAGE
template <typename T>
image<T>::image()
: dimensions_(0,0),
buffer_(0),
pData_(nullptr),
offset_(0.0),
scaling_(1.0),
premultiplied_alpha_(false),
painted_(false)
{}
template <typename T>
image<T>::image(int width, int height, bool initialize, bool premultiplied, bool painted)
: dimensions_(width, height),
buffer_(dimensions_.width() * dimensions_.height() * pixel_size),
pData_(reinterpret_cast<pixel_type*>(buffer_.data())),
offset_(0.0),
scaling_(1.0),
premultiplied_alpha_(premultiplied),
painted_(painted)
{
if (pData_ && initialize)
{
std::fill(pData_, pData_ + dimensions_.width() * dimensions_.height(), 0);
}
}
template <typename T>
image<T>::image(image<T> const& rhs)
: dimensions_(rhs.dimensions_),
buffer_(rhs.buffer_),
pData_(reinterpret_cast<pixel_type*>(buffer_.data())),
offset_(rhs.offset_),
scaling_(rhs.scaling_),
premultiplied_alpha_(rhs.premultiplied_alpha_),
painted_(rhs.painted_)
{}
template <typename T>
image<T>::image(image<T> && rhs) noexcept
: dimensions_(std::move(rhs.dimensions_)),
buffer_(std::move(rhs.buffer_)),
pData_(reinterpret_cast<pixel_type*>(buffer_.data())),
offset_(rhs.offset_),
scaling_(rhs.scaling_),
premultiplied_alpha_(rhs.premultiplied_alpha_),
painted_(rhs.painted_)
{
rhs.dimensions_ = { 0, 0 };
rhs.pData_ = nullptr;
}
template <typename T>
image<T>& image<T>::operator=(image<T> rhs)
{
swap(rhs);
return *this;
}
template <typename T>
image<T> const& image<T>::operator=(image<T> const& rhs) const
{
return rhs;
}
template <typename T>
void image<T>::swap(image<T> & rhs)
{
std::swap(dimensions_, rhs.dimensions_);
std::swap(buffer_, rhs.buffer_);
std::swap(offset_, rhs.offset_);
std::swap(scaling_, rhs.scaling_);
std::swap(premultiplied_alpha_, rhs.premultiplied_alpha_);
std::swap(painted_, rhs.painted_);
}
template <typename T>
inline typename image<T>::pixel_type& image<T>::operator() (std::size_t i, std::size_t j)
{
assert(i < dimensions_.width() && j < dimensions_.height());
return pData_[j * dimensions_.width() + i];
}
template <typename T>
inline const typename image<T>::pixel_type& image<T>::operator() (std::size_t i, std::size_t j) const
{
assert(i < dimensions_.width() && j < dimensions_.height());
return pData_[j * dimensions_.width() + i];
}
template <typename T>
inline std::size_t image<T>::width() const
{
return dimensions_.width();
}
template <typename T>
inline std::size_t image<T>::height() const
{
return dimensions_.height();
}
template <typename T>
inline unsigned image<T>::getSize() const
{
return dimensions_.height() * dimensions_.width() * pixel_size;
}
template <typename T>
inline unsigned image<T>::getRowSize() const
{
return dimensions_.width() * pixel_size;
}
template <typename T>
inline void image<T>::set(pixel_type const& t)
{
std::fill(pData_, pData_ + dimensions_.width() * dimensions_.height(), t);
}
template <typename T>
inline const typename image<T>::pixel_type* image<T>::getData() const
{
return pData_;
}
template <typename T>
inline typename image<T>::pixel_type* image<T>::getData()
{
return pData_;
}
template <typename T>
inline const unsigned char* image<T>::getBytes() const
{
return buffer_.data();
}
template <typename T>
inline unsigned char* image<T>::getBytes()
{
return buffer_.data();
}
template <typename T>
inline const typename image<T>::pixel_type* image<T>::getRow(std::size_t row) const
{
return pData_ + row * dimensions_.width();
}
template <typename T>
inline const typename image<T>::pixel_type* image<T>::getRow(std::size_t row, std::size_t x0) const
{
return pData_ + row * dimensions_.width() + x0;
}
template <typename T>
inline typename image<T>::pixel_type* image<T>::getRow(std::size_t row)
{
return pData_ + row * dimensions_.width();
}
template <typename T>
inline typename image<T>::pixel_type* image<T>::getRow(std::size_t row, std::size_t x0)
{
return pData_ + row * dimensions_.width() + x0;
}
template <typename T>
inline void image<T>::setRow(std::size_t row, pixel_type const* buf, std::size_t size)
{
assert(row < dimensions_.height());
assert(size <= dimensions_.width());
std::copy(buf, buf + size, pData_ + row * dimensions_.width());
}
template <typename T>
inline void image<T>::setRow(std::size_t row, std::size_t x0, std::size_t x1, pixel_type const* buf)
{
assert(row < dimensions_.height());
assert ((x1 - x0) <= dimensions_.width() );
std::copy(buf, buf + (x1 - x0), pData_ + row * dimensions_.width() + x0);
}
template <typename T>
inline double image<T>::get_offset() const
{
return offset_;
}
template <typename T>
inline void image<T>::set_offset(double set)
{
offset_ = set;
}
template <typename T>
inline double image<T>::get_scaling() const
{
return scaling_;
}
template <typename T>
inline void image<T>::set_scaling(double set)
{
if (set != 0.0)
{
scaling_ = set;
return;
}
std::clog << "Can not set scaling to 0.0, offset not set." << std::endl;
}
template <typename T>
inline bool image<T>::get_premultiplied() const
{
return premultiplied_alpha_;
}
template <typename T>
inline void image<T>::set_premultiplied(bool set)
{
premultiplied_alpha_ = set;
}
template <typename T>
inline void image<T>::painted(bool painted)
{
painted_ = painted;
}
template <typename T>
inline bool image<T>::painted() const
{
return painted_;
}
template <typename T>
inline image_dtype image<T>::get_dtype() const
{
return dtype;
}
/*
using image_rgba8 = image<rgba8_t>;
using image_gray8 = image<gray8_t>;
using image_gray8s = image<gray8s_t>;
using image_gray16 = image<gray16_t>;
using image_gray16s = image<gray16s_t>;
using image_gray32 = image<gray32_t>;
using image_gray32s = image<gray32s_t>;
using image_gray32f = image<gray32f_t>;
using image_gray64 = image<gray64_t>;
using image_gray64s = image<gray64s_t>;
using image_gray64f = image<gray64f_t>;
*/
} // end ns
#endif // MAPNIK_IMAGE_IMPL_HPP

View file

@ -25,11 +25,12 @@
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/image.hpp>
#include <mapnik/image_any.hpp>
#include <mapnik/image_view.hpp>
#include <mapnik/image_view_any.hpp>
#include <mapnik/color.hpp>
#include <mapnik/pixel_types.hpp>
//#include <mapnik/image.hpp>
//#include <mapnik/image_any.hpp>
//#include <mapnik/image_view.hpp>
//#include <mapnik/image_view_any.hpp>
//#include <mapnik/color.hpp>
// boost
#pragma GCC diagnostic push
@ -46,6 +47,11 @@ namespace mapnik {
// fwd declares
class rgba_palette;
struct image_any;
template <typename T> class image;
struct image_view_any;
template <typename T> class image_view;
class color;
class ImageWriterException : public std::exception
{
@ -162,37 +168,37 @@ template <typename T>
MAPNIK_DECL void fill (image_any & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_rgba8 & data, T const&);
MAPNIK_DECL void fill (image<rgba8_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_gray8 & data, T const&);
MAPNIK_DECL void fill (image<gray8_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_gray8s & data, T const&);
MAPNIK_DECL void fill (image<gray8s_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_gray16 & data, T const&);
MAPNIK_DECL void fill (image<gray16_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_gray16s & data, T const&);
MAPNIK_DECL void fill (image<gray16s_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_gray32 & data, T const&);
MAPNIK_DECL void fill (image<gray32_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_gray32s & data, T const&);
MAPNIK_DECL void fill (image<gray32s_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_gray32f & data, T const&);
MAPNIK_DECL void fill (image<gray32f_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_gray64 & data, T const&);
MAPNIK_DECL void fill (image<gray64_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_gray64s & data, T const&);
MAPNIK_DECL void fill (image<gray64s_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image_gray64f & data, T const&);
MAPNIK_DECL void fill (image<gray64f_t> & data, T const&);
// SET RECTANGLE
MAPNIK_DECL void set_rectangle (image_any & dst, image_any const& src, int x = 0, int y = 0);
@ -218,37 +224,37 @@ template <typename T>
MAPNIK_DECL void set_pixel(image_any & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_rgba8 & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<rgba8_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_gray8 & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<gray8_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_gray8s & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<gray8s_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_gray16 & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<gray16_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_gray16s & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<gray16s_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_gray32 & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<gray32_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_gray32s & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<gray32s_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_gray32f & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<gray32f_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_gray64 & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<gray64_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_gray64s & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<gray64s_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image_gray64f & data, std::size_t x, std::size_t y, T const& val);
MAPNIK_DECL void set_pixel(image<gray64f_t> & data, std::size_t x, std::size_t y, T const& val);
// GET PIXEL
template <typename T>
@ -258,70 +264,70 @@ template <typename T>
MAPNIK_DECL T get_pixel(image_view_any const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_rgba8 const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<rgba8_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_gray8 const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<gray8_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_gray8s const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<gray8s_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_gray16 const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<gray16_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_gray16s const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<gray16s_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_gray32 const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<gray32_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_gray32s const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<gray32s_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_gray32f const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<gray32f_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_gray64 const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<gray64_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_gray64s const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<gray64s_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_gray64f const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image<gray64f_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_rgba8 const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<rgba8_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_gray8 const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<gray8_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_gray8s const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<gray8s_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_gray16 const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<gray16_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_gray16s const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<gray16s_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_gray32 const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<gray32_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_gray32s const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<gray32s_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_gray32f const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<gray32f_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_gray64 const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<gray64_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_gray64s const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<gray64s_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_gray64f const& data, std::size_t x, std::size_t y);
MAPNIK_DECL T get_pixel(image_view<image<gray64f_t> > const& data, std::size_t x, std::size_t y);
// VIEW TO STRING
MAPNIK_DECL void view_to_string (image_view_any const& view, std::ostringstream & ss);

View file

@ -28,7 +28,7 @@
namespace mapnik {
template <typename T>
class image_view
class MAPNIK_DECL image_view
{
public:
using pixel = typename T::pixel;
@ -36,107 +36,26 @@ public:
static const image_dtype dtype = T::dtype;
static constexpr std::size_t pixel_size = sizeof(pixel_type);
image_view(unsigned x, unsigned y, unsigned width, unsigned height, T const& data)
: x_(x),
y_(y),
width_(width),
height_(height),
data_(data)
{
if (x_ >= data_.width() && data_.width() > 0) x_ = data_.width() - 1;
if (y_ >= data_.height() && data.height() > 0) y_ = data_.height() - 1;
if (x_ + width_ > data_.width()) width_ = data_.width() - x_;
if (y_ + height_ > data_.height()) height_ = data_.height() - y_;
}
image_view(unsigned x, unsigned y, unsigned width, unsigned height, T const& data);
~image_view();
~image_view() {}
image_view(image_view<T> const& rhs);
image_view<T> & operator=(image_view<T> const& rhs);
image_view(image_view<T> const& rhs)
: x_(rhs.x_),
y_(rhs.y_),
width_(rhs.width_),
height_(rhs.height_),
data_(rhs.data_) {}
image_view<T> & operator=(image_view<T> const& rhs)
{
if (&rhs==this) return *this;
x_ = rhs.x_;
y_ = rhs.y_;
width_ = rhs.width_;
height_ = rhs.height_;
data_ = rhs.data_;
return *this;
}
inline unsigned x() const
{
return x_;
}
inline unsigned y() const
{
return y_;
}
inline unsigned width() const
{
return width_;
}
inline unsigned height() const
{
return height_;
}
inline const pixel_type& operator() (std::size_t i, std::size_t j) const
{
return data_(i,j);
}
inline unsigned getSize() const
{
return height_ * width_ * pixel_size;
}
inline unsigned getRowSize() const
{
return width_ * pixel_size;
}
inline const pixel_type* getRow(unsigned row) const
{
return data_.getRow(row + y_) + x_;
}
inline const pixel_type* getRow(unsigned row, std::size_t x0) const
{
return data_.getRow(row + y_, x0) + x_;
}
inline T const& data() const
{
return data_;
}
inline bool get_premultiplied() const
{
return data_.get_premultiplied();
}
inline double get_offset() const
{
return data_.get_offset();
}
inline double get_scaling() const
{
return data_.get_scaling();
}
inline image_dtype get_dtype() const
{
return dtype;
}
unsigned x() const;
unsigned y() const;
unsigned width() const;
unsigned height() const;
const pixel_type& operator() (std::size_t i, std::size_t j) const;
unsigned getSize() const;
unsigned getRowSize() const;
const pixel_type* getRow(unsigned row) const;
const pixel_type* getRow(unsigned row, std::size_t x0) const;
T const& data() const;
bool get_premultiplied() const;
double get_offset() const;
double get_scaling() const;
image_dtype get_dtype() const;
private:
unsigned x_;

View file

@ -40,82 +40,7 @@ using image_view_base = util::variant<image_view_rgba8,
image_view_gray64s,
image_view_gray64f>;
namespace detail {
struct get_view_width_visitor
{
template <typename T>
std::size_t operator()(T const& data) const
{
return data.width();
}
};
struct get_view_height_visitor
{
template <typename T>
std::size_t operator()(T const& data) const
{
return data.height();
}
};
struct get_view_size_visitor
{
template <typename T>
unsigned operator()(T const& data) const
{
return data.getSize();
}
};
struct get_view_dtype_visitor
{
template <typename T>
image_dtype operator()(T const& data) const
{
return data.get_dtype();
}
};
struct get_view_row_size_visitor
{
template <typename T>
unsigned operator()(T const& data) const
{
return data.getRowSize();
}
};
struct get_view_premultiplied_visitor
{
template <typename T>
bool operator()(T const& data) const
{
return data.get_premultiplied();
}
};
struct get_view_offset_visitor
{
template <typename T>
double operator()(T const& data) const
{
return data.get_offset();
}
};
struct get_view_scaling_visitor
{
template <typename T>
double operator()(T const& data) const
{
return data.get_scaling();
}
};
} // namespace detail
struct image_view_any : image_view_base
struct MAPNIK_DECL image_view_any : image_view_base
{
image_view_any() = default;
@ -123,47 +48,16 @@ struct image_view_any : image_view_base
image_view_any(T && data) noexcept
: image_view_base(std::move(data)) {}
std::size_t width() const
{
return util::apply_visitor(detail::get_view_width_visitor(),*this);
}
std::size_t height() const
{
return util::apply_visitor(detail::get_view_height_visitor(),*this);
}
unsigned getSize() const
{
return util::apply_visitor(detail::get_view_size_visitor(),*this);
}
unsigned getRowSize() const
{
return util::apply_visitor(detail::get_view_row_size_visitor(),*this);
}
bool get_premultiplied() const
{
return util::apply_visitor(detail::get_view_premultiplied_visitor(),*this);
}
double get_offset() const
{
return util::apply_visitor(detail::get_view_offset_visitor(),*this);
}
double get_scaling() const
{
return util::apply_visitor(detail::get_view_scaling_visitor(),*this);
}
image_dtype get_dtype() const
{
return util::apply_visitor(detail::get_view_dtype_visitor(),*this);
}
std::size_t width() const;
std::size_t height() const;
unsigned getSize() const;
unsigned getRowSize() const;
bool get_premultiplied() const;
double get_offset() const;
double get_scaling() const;
image_dtype get_dtype() const;
};
}
} // end mapnik ns
#endif // MAPNIK_IMAGE_VIEW_ANY_HPP

View file

@ -0,0 +1,153 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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_IMAGE_VIEW_IMPL_HPP
#define MAPNIK_IMAGE_VIEW_IMPL_HPP
#include <mapnik/image.hpp>
namespace mapnik {
template <typename T>
image_view<T>::image_view(unsigned x, unsigned y, unsigned width, unsigned height, T const& data)
: x_(x),
y_(y),
width_(width),
height_(height),
data_(data)
{
if (x_ >= data_.width() && data_.width() > 0) x_ = data_.width() - 1;
if (y_ >= data_.height() && data.height() > 0) y_ = data_.height() - 1;
if (x_ + width_ > data_.width()) width_ = data_.width() - x_;
if (y_ + height_ > data_.height()) height_ = data_.height() - y_;
}
template <typename T>
image_view<T>::~image_view() {}
template <typename T>
image_view<T>::image_view(image_view<T> const& rhs)
: x_(rhs.x_),
y_(rhs.y_),
width_(rhs.width_),
height_(rhs.height_),
data_(rhs.data_) {}
template <typename T>
image_view<T> & image_view<T>::operator=(image_view<T> const& rhs)
{
if (&rhs==this) return *this;
x_ = rhs.x_;
y_ = rhs.y_;
width_ = rhs.width_;
height_ = rhs.height_;
data_ = rhs.data_;
return *this;
}
template <typename T>
inline unsigned image_view<T>::x() const
{
return x_;
}
template <typename T>
inline unsigned image_view<T>::y() const
{
return y_;
}
template <typename T>
inline unsigned image_view<T>::width() const
{
return width_;
}
template <typename T>
inline unsigned image_view<T>::height() const
{
return height_;
}
template <typename T>
inline const typename image_view<T>::pixel_type& image_view<T>::operator() (std::size_t i, std::size_t j) const
{
return data_(i,j);
}
template <typename T>
inline unsigned image_view<T>::getSize() const
{
return height_ * width_ * pixel_size;
}
template <typename T>
inline unsigned image_view<T>::getRowSize() const
{
return width_ * pixel_size;
}
template <typename T>
inline const typename image_view<T>::pixel_type* image_view<T>::getRow(unsigned row) const
{
return data_.getRow(row + y_) + x_;
}
template <typename T>
inline const typename image_view<T>::pixel_type* image_view<T>::getRow(unsigned row, std::size_t x0) const
{
return data_.getRow(row + y_, x0) + x_;
}
template <typename T>
inline T const& image_view<T>::data() const
{
return data_;
}
template <typename T>
inline bool image_view<T>::get_premultiplied() const
{
return data_.get_premultiplied();
}
template <typename T>
inline double image_view<T>::get_offset() const
{
return data_.get_offset();
}
template <typename T>
inline double image_view<T>::get_scaling() const
{
return data_.get_scaling();
}
template <typename T>
inline image_dtype image_view<T>::get_dtype() const
{
return dtype;
}
} // end ns
#endif // MAPNIK_IMAGE_VIEW_IMPL_HPP

View file

@ -44,6 +44,7 @@ enum image_dtype : std::uint8_t
IMAGE_DTYPE_MAX
};
struct null_t { using type = std::uint8_t; static const image_dtype id = image_dtype_null; };
struct rgba8_t { using type = std::uint32_t; static const image_dtype id = image_dtype_rgba8; };
struct gray8_t { using type = std::uint8_t; static const image_dtype id = image_dtype_gray8; };
struct gray8s_t { using type = std::int8_t; static const image_dtype id = image_dtype_gray8s; };

View file

@ -174,6 +174,11 @@ source = Split(
parse_path.cpp
image_reader.cpp
cairo_io.cpp
image.cpp
image_view.cpp
image_view_any.cpp
image_any.cpp
image_null.cpp
image_util.cpp
image_util_jpeg.cpp
image_util_png.cpp

110
src/image.cpp Normal file
View file

@ -0,0 +1,110 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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
*
*****************************************************************************/
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/image.hpp>
#include <mapnik/image_impl.hpp>
#include <mapnik/pixel_types.hpp>
namespace mapnik
{
namespace detail
{
// BUFFER
buffer::buffer(std::size_t size)
: size_(size),
data_(static_cast<unsigned char*>(size_ != 0 ? ::operator new(size_) : nullptr))
{}
buffer::buffer(buffer && rhs) noexcept
: size_(std::move(rhs.size_)),
data_(std::move(rhs.data_))
{
rhs.size_ = 0;
rhs.data_ = nullptr;
}
buffer::buffer(buffer const& rhs)
: size_(rhs.size_),
data_(static_cast<unsigned char*>(size_ != 0 ? ::operator new(size_) : nullptr))
{
if (data_) std::copy(rhs.data_, rhs.data_ + rhs.size_, data_);
}
buffer::~buffer()
{
::operator delete(data_);
}
buffer& buffer::operator=(buffer rhs)
{
swap(rhs);
return *this;
}
void buffer::swap(buffer & rhs)
{
std::swap(size_, rhs.size_);
std::swap(data_, rhs.data_);
}
inline bool buffer::operator!() const
{
return (data_ == nullptr)? false : true;
}
unsigned char* buffer::data()
{
return data_;
}
unsigned char const* buffer::data() const
{
return data_;
}
std::size_t buffer::size() const
{
return size_;
}
template struct MAPNIK_DECL image_dimensions<65535>;
} // end ns detail
template class MAPNIK_DECL image<null_t>;
template class MAPNIK_DECL image<rgba8_t>;
template class MAPNIK_DECL image<gray8_t>;
template class MAPNIK_DECL image<gray8s_t>;
template class MAPNIK_DECL image<gray16_t>;
template class MAPNIK_DECL image<gray16s_t>;
template class MAPNIK_DECL image<gray32_t>;
template class MAPNIK_DECL image<gray32s_t>;
template class MAPNIK_DECL image<gray32f_t>;
template class MAPNIK_DECL image<gray64_t>;
template class MAPNIK_DECL image<gray64s_t>;
template class MAPNIK_DECL image<gray64f_t>;
} // end ns

268
src/image_any.cpp Normal file
View file

@ -0,0 +1,268 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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
*
*****************************************************************************/
#include <mapnik/image_any.hpp>
namespace mapnik {
namespace detail {
struct get_bytes_visitor
{
template <typename T>
unsigned char* operator()(T & data)
{
return data.getBytes();
}
};
struct get_dtype_visitor
{
template <typename T>
image_dtype operator()(T & data)
{
return data.get_dtype();
}
};
struct get_bytes_visitor_const
{
template <typename T>
unsigned char const* operator()(T const& data) const
{
return data.getBytes();
}
};
struct get_width_visitor
{
template <typename T>
std::size_t operator()(T const& data) const
{
return data.width();
}
};
struct get_height_visitor
{
template <typename T>
std::size_t operator()(T const& data) const
{
return data.height();
}
};
struct get_premultiplied_visitor
{
template <typename T>
bool operator()(T const& data) const
{
return data.get_premultiplied();
}
};
struct get_painted_visitor
{
template <typename T>
bool operator()(T const& data) const
{
return data.painted();
}
};
struct get_any_size_visitor
{
template <typename T>
unsigned operator()(T const& data) const
{
return data.getSize();
}
};
struct get_any_row_size_visitor
{
template <typename T>
unsigned operator()(T const& data) const
{
return data.getRowSize();
}
};
struct get_offset_visitor
{
template <typename T>
double operator() (T const& data) const
{
return data.get_offset();
}
};
struct get_scaling_visitor
{
template <typename T>
double operator() (T const& data) const
{
return data.get_scaling();
}
};
struct set_offset_visitor
{
set_offset_visitor(double val)
: val_(val) {}
template <typename T>
void operator() (T & data)
{
data.set_offset(val_);
}
private:
double val_;
};
struct set_scaling_visitor
{
set_scaling_visitor(double val)
: val_(val) {}
template <typename T>
void operator() (T & data)
{
data.set_scaling(val_);
}
private:
double val_;
};
} // namespace detail
MAPNIK_DECL image_any::image_any(int width,
int height,
image_dtype type,
bool initialize,
bool premultiplied,
bool painted)
: image_base(std::move(create_image_any(width, height, type, initialize, premultiplied, painted))) {}
MAPNIK_DECL unsigned char const* image_any::getBytes() const
{
return util::apply_visitor(detail::get_bytes_visitor_const(),*this);
}
MAPNIK_DECL unsigned char* image_any::getBytes()
{
return util::apply_visitor(detail::get_bytes_visitor(),*this);
}
MAPNIK_DECL std::size_t image_any::width() const
{
return util::apply_visitor(detail::get_width_visitor(),*this);
}
MAPNIK_DECL std::size_t image_any::height() const
{
return util::apply_visitor(detail::get_height_visitor(),*this);
}
MAPNIK_DECL bool image_any::get_premultiplied() const
{
return util::apply_visitor(detail::get_premultiplied_visitor(),*this);
}
MAPNIK_DECL bool image_any::painted() const
{
return util::apply_visitor(detail::get_painted_visitor(),*this);
}
MAPNIK_DECL unsigned image_any::getSize() const
{
return util::apply_visitor(detail::get_any_size_visitor(),*this);
}
MAPNIK_DECL unsigned image_any::getRowSize() const
{
return util::apply_visitor(detail::get_any_row_size_visitor(),*this);
}
MAPNIK_DECL double image_any::get_offset() const
{
return util::apply_visitor(detail::get_offset_visitor(),*this);
}
MAPNIK_DECL double image_any::get_scaling() const
{
return util::apply_visitor(detail::get_scaling_visitor(),*this);
}
MAPNIK_DECL image_dtype image_any::get_dtype() const
{
return util::apply_visitor(detail::get_dtype_visitor(),*this);
}
MAPNIK_DECL void image_any::set_offset(double val)
{
util::apply_visitor(detail::set_offset_visitor(val),*this);
}
MAPNIK_DECL void image_any::set_scaling(double val)
{
util::apply_visitor(detail::set_scaling_visitor(val),*this);
}
MAPNIK_DECL image_any create_image_any(int width,
int height,
image_dtype type,
bool initialize,
bool premultiplied,
bool painted)
{
switch (type)
{
case image_dtype_gray8:
return image_any(std::move(image_gray8(width, height, initialize, premultiplied, painted)));
case image_dtype_gray8s:
return image_any(std::move(image_gray8s(width, height, initialize, premultiplied, painted)));
case image_dtype_gray16:
return image_any(std::move(image_gray16(width, height, initialize, premultiplied, painted)));
case image_dtype_gray16s:
return image_any(std::move(image_gray16s(width, height, initialize, premultiplied, painted)));
case image_dtype_gray32:
return image_any(std::move(image_gray32(width, height, initialize, premultiplied, painted)));
case image_dtype_gray32s:
return image_any(std::move(image_gray32s(width, height, initialize, premultiplied, painted)));
case image_dtype_gray32f:
return image_any(std::move(image_gray32f(width, height, initialize, premultiplied, painted)));
case image_dtype_gray64:
return image_any(std::move(image_gray64(width, height, initialize, premultiplied, painted)));
case image_dtype_gray64s:
return image_any(std::move(image_gray64s(width, height, initialize, premultiplied, painted)));
case image_dtype_gray64f:
return image_any(std::move(image_gray64f(width, height, initialize, premultiplied, painted)));
case image_dtype_null:
return image_any(std::move(image_null()));
case image_dtype_rgba8:
case IMAGE_DTYPE_MAX:
default:
return image_any(std::move(image_rgba8(width, height, initialize, premultiplied, painted)));
}
}
} // end mapnik ns

71
src/image_null.cpp Normal file
View file

@ -0,0 +1,71 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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
*
*****************************************************************************/
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/image.hpp>
#include <mapnik/pixel_types.hpp>
//stl
#include <stdexcept>
namespace mapnik
{
template <>
class image<null_t>
{
public:
using pixel_type = typename null_t::type;
static const image_dtype dtype = null_t::id;
private:
public:
image() {}
image(int width,
int height,
bool initialize = true,
bool premultiplied = false,
bool painted = false) {}
image(image<null_t> const& rhs) {}
image(image<null_t> && rhs) noexcept {}
void swap(image<null_t> & rhs) {}
std::size_t width() const { return 0; }
std::size_t height() const { return 0; }
unsigned getSize() const { return 0; }
unsigned getRowSize() const { return 0; }
void set(pixel_type const& t) { throw std::runtime_error("Can not set values for null image"); }
const unsigned char* getBytes() const { return nullptr; }
unsigned char* getBytes() {return nullptr; }
double get_offset() const { return 0.0; }
void set_offset(double set) {}
double get_scaling() const { return 1.0; }
void set_scaling(double set) {}
bool get_premultiplied() const { return false; }
void set_premultiplied(bool set) {}
void painted(bool painted) {}
bool painted() const { return false; }
image_dtype get_dtype() const { return dtype; }
};
} // end ns mapnik

View file

@ -28,7 +28,6 @@
#include <mapnik/image_util.hpp>
#include <mapnik/image_util_jpeg.hpp>
#include <mapnik/image.hpp>
#include <mapnik/image_any.hpp>
#include <mapnik/image_view.hpp>
#include <mapnik/util/conversions.hpp>
@ -37,7 +36,6 @@
// stl
#include <string>
#include <iostream>
namespace mapnik
{

44
src/image_view.cpp Normal file
View file

@ -0,0 +1,44 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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
*
*****************************************************************************/
// mapnik
#include <mapnik/image_view.hpp>
#include <mapnik/image_view_impl.hpp>
#include <mapnik/pixel_types.hpp>
namespace mapnik
{
template class MAPNIK_DECL image_view<image_rgba8>;
template class MAPNIK_DECL image_view<image_gray8>;
template class MAPNIK_DECL image_view<image_gray8s>;
template class MAPNIK_DECL image_view<image_gray16>;
template class MAPNIK_DECL image_view<image_gray16s>;
template class MAPNIK_DECL image_view<image_gray32>;
template class MAPNIK_DECL image_view<image_gray32s>;
template class MAPNIK_DECL image_view<image_gray32f>;
template class MAPNIK_DECL image_view<image_gray64>;
template class MAPNIK_DECL image_view<image_gray64s>;
template class MAPNIK_DECL image_view<image_gray64f>;
} // end ns mapnik

143
src/image_view_any.cpp Normal file
View file

@ -0,0 +1,143 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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
*
*****************************************************************************/
#include <mapnik/image_view_any.hpp>
namespace mapnik {
namespace detail {
struct get_view_width_visitor
{
template <typename T>
std::size_t operator()(T const& data) const
{
return data.width();
}
};
struct get_view_height_visitor
{
template <typename T>
std::size_t operator()(T const& data) const
{
return data.height();
}
};
struct get_view_size_visitor
{
template <typename T>
unsigned operator()(T const& data) const
{
return data.getSize();
}
};
struct get_view_dtype_visitor
{
template <typename T>
image_dtype operator()(T const& data) const
{
return data.get_dtype();
}
};
struct get_view_row_size_visitor
{
template <typename T>
unsigned operator()(T const& data) const
{
return data.getRowSize();
}
};
struct get_view_premultiplied_visitor
{
template <typename T>
bool operator()(T const& data) const
{
return data.get_premultiplied();
}
};
struct get_view_offset_visitor
{
template <typename T>
double operator()(T const& data) const
{
return data.get_offset();
}
};
struct get_view_scaling_visitor
{
template <typename T>
double operator()(T const& data) const
{
return data.get_scaling();
}
};
} // end namespace detail
std::size_t image_view_any::width() const
{
return util::apply_visitor(detail::get_view_width_visitor(),*this);
}
std::size_t image_view_any::height() const
{
return util::apply_visitor(detail::get_view_height_visitor(),*this);
}
unsigned image_view_any::getSize() const
{
return util::apply_visitor(detail::get_view_size_visitor(),*this);
}
unsigned image_view_any::getRowSize() const
{
return util::apply_visitor(detail::get_view_row_size_visitor(),*this);
}
bool image_view_any::get_premultiplied() const
{
return util::apply_visitor(detail::get_view_premultiplied_visitor(),*this);
}
double image_view_any::get_offset() const
{
return util::apply_visitor(detail::get_view_offset_visitor(),*this);
}
double image_view_any::get_scaling() const
{
return util::apply_visitor(detail::get_view_scaling_visitor(),*this);
}
image_dtype image_view_any::get_dtype() const
{
return util::apply_visitor(detail::get_view_dtype_visitor(),*this);
}
} // end mapnik ns

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import mapnik
from unittest import TestCase
try:
import json
@ -35,14 +36,8 @@ def compare(actual, expected, alpha=True):
im2 = mapnik.Image.open(expected)
pixels = im1.width() * im1.height()
delta_pixels = (im2.width() * im2.height()) - pixels
#diff = 0
if delta_pixels != 0:
return delta_pixels
#for x in range(0,im1.width(),2):
# for y in range(0,im1.height(),2):
# if compare_pixels(im1.get_pixel(x,y),im2.get_pixel(x,y),alpha=alpha):
# diff += 1
#return diff
return im1.compare(im2, 0, alpha)
def compare_grids(actual, expected, threshold=0, alpha=True):
@ -57,21 +52,27 @@ def compare_grids(actual, expected, threshold=0, alpha=True):
return 99999999
grid1 = im1['grid']
grid2 = im2['grid']
# dimensions must be exact
width1 = len(grid1[0])
width2 = len(grid2[0])
if not width1 == width2:
return 99999999
height1 = len(grid1)
height2 = len(grid2)
if not height1 == height2:
return 99999999
diff = 0;
for y in range(0,height1-1):
row1 = grid1[y]
row2 = grid2[y]
width = min(len(row1),len(row2))
for w in range(0,width):
if row1[w] != row2[w]:
diff += 1
return diff
try:
assertSequenceEqual(grid1, grid2)
return 0
except:
# dimensions must be exact
width1 = len(grid1[0])
width2 = len(grid2[0])
if not width1 == width2:
return 99999999
height1 = len(grid1)
height2 = len(grid2)
if not height1 == height2:
return 99999999
diff = 0;
for y in range(0,height1-1):
row1 = grid1[y]
row2 = grid2[y]
if row1 == row2:
continue;
#width = min(len(row1),len(row2))
for w in range(0,width1):
if row1[w] != row2[w]:
diff += 1
return diff