diff --git a/.travis.yml b/.travis.yml index 5b7d3b20ba..cc751dbd78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,5 +44,5 @@ script: pip install cpp-coveralls; pyenv rehash; 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 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; diff --git a/benchmark/test_polygon_clipping.cpp b/benchmark/test_polygon_clipping.cpp index c26ffa03ba..9b8d9c9968 100644 --- a/benchmark/test_polygon_clipping.cpp +++ b/benchmark/test_polygon_clipping.cpp @@ -10,6 +10,7 @@ #include #include #include +#include // agg #include "agg_conv_clip_polygon.h" // clipper diff --git a/include/mapnik/agg_renderer.hpp b/include/mapnik/agg_renderer.hpp index 90ca07e06b..4f3996ba8b 100644 --- a/include/mapnik/agg_renderer.hpp +++ b/include/mapnik/agg_renderer.hpp @@ -29,15 +29,12 @@ #include // for noncopyable #include // for rule, symbolizers #include // for box2d -#include // for color #include // for view_transform #include // for composite_mode_e #include #include #include #include -#include -#include // stl #include @@ -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 class image; } namespace mapnik { @@ -171,7 +171,7 @@ class MAPNIK_DECL agg_renderer : public feature_style_processor void setup(Map const& m); }; -extern template class MAPNIK_DECL agg_renderer; +extern template class MAPNIK_DECL agg_renderer>; } // namespace mapnik diff --git a/include/mapnik/image.hpp b/include/mapnik/image.hpp index abf856e8cb..833a9989e0 100644 --- a/include/mapnik/image.hpp +++ b/include/mapnik/image.hpp @@ -20,66 +20,32 @@ * *****************************************************************************/ -#ifndef MAPNIK_IMAGE_DATA_HPP -#define MAPNIK_IMAGE_DATA_HPP +#ifndef MAPNIK_IMAGE_HPP +#define MAPNIK_IMAGE_HPP // mapnik -#include +#include #include -// stl -#include -#include -#include -#include - namespace mapnik { namespace detail { -struct buffer +struct MAPNIK_DECL buffer { - explicit buffer(std::size_t size) - : size_(size), - data_(static_cast(size_ != 0 ? ::operator new(size_) : nullptr)) - {} - - buffer(buffer && rhs) noexcept - : size_(std::move(rhs.size_)), - data_(std::move(rhs.data_)) - { - rhs.size_ = 0; - rhs.data_ = nullptr; - } - - buffer(buffer const& rhs) - : size_(rhs.size_), - data_(static_cast(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_; } + explicit buffer(std::size_t size); + buffer(buffer && rhs) noexcept; + buffer(buffer const& rhs); + ~buffer(); + + buffer& operator=(buffer rhs); + bool operator!() const; + + 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 struct image_dimensions { - image_dimensions(int width, int height) - : width_(width), - height_(height) - { - if (width < 0 || static_cast(width) > max_size) throw std::runtime_error("Invalid width for image dimensions requested"); - if (height < 0 || static_cast(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 -class image +template +class MAPNIK_DECL image { public: using pixel = T; @@ -127,7 +76,7 @@ class image static const image_dtype dtype = T::id; static constexpr std::size_t pixel_size = sizeof(pixel_type); private: - detail::image_dimensions dimensions_; + detail::image_dimensions<65535> dimensions_; detail::buffer buffer_; pixel_type *pData_; double offset_; @@ -135,192 +84,47 @@ class image 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(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 const& rhs) - : dimensions_(rhs.dimensions_), - buffer_(rhs.buffer_), - pData_(reinterpret_cast(buffer_.data())), - offset_(rhs.offset_), - scaling_(rhs.scaling_), - premultiplied_alpha_(rhs.premultiplied_alpha_), - painted_(rhs.painted_) - {} - - image(image && rhs) noexcept - : dimensions_(std::move(rhs.dimensions_)), - buffer_(std::move(rhs.buffer_)), - pData_(reinterpret_cast(buffer_.data())), - offset_(rhs.offset_), - scaling_(rhs.scaling_), - premultiplied_alpha_(rhs.premultiplied_alpha_), - painted_(rhs.painted_) - { - rhs.dimensions_ = { 0, 0 }; - rhs.pData_ = nullptr; - } - - image& operator=(image rhs) - { - swap(rhs); - return *this; - } - - void swap(image & 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; - } + image(); + image(int width, + int height, + bool initialize = true, + bool premultiplied = false, + bool painted = false); + image(image const& rhs); + image(image && rhs) noexcept; + image& operator=(image rhs); + imageconst& operator=(image const& rhs) const; + + void swap(image & 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; using image_rgba8 = image; using image_gray8 = image; using image_gray8s = image; @@ -333,6 +137,6 @@ using image_gray64 = image; using image_gray64s = image; using image_gray64f = image; -} // end ns +} // end ns mapnik -#endif // MAPNIK_IMAGE_DATA_HPP +#endif // MAPNIK_IMAGE_HPP diff --git a/include/mapnik/image_any.hpp b/include/mapnik/image_any.hpp index 8b2ce6627c..b5d539d39a 100644 --- a/include/mapnik/image_any.hpp +++ b/include/mapnik/image_any.hpp @@ -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 #include 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; -// Forward declaring -struct image_any; -image_any create_image_any(int width, - int height, - image_dtype type = image_dtype_rgba8, - bool initialize = true, - bool premultiplied = false, - bool painted = false); - -namespace detail { - -struct get_bytes_visitor -{ - template - unsigned char* operator()(T & data) - { - return data.getBytes(); - } -}; - -struct get_dtype_visitor -{ - template - image_dtype operator()(T & data) - { - return data.get_dtype(); - } -}; - -struct get_bytes_visitor_const -{ - template - unsigned char const* operator()(T const& data) const - { - return data.getBytes(); - } -}; - -struct get_width_visitor -{ - template - std::size_t operator()(T const& data) const - { - return data.width(); - } -}; - -struct get_height_visitor -{ - template - std::size_t operator()(T const& data) const - { - return data.height(); - } -}; - -struct get_premultiplied_visitor -{ - template - bool operator()(T const& data) const - { - return data.get_premultiplied(); - } -}; - -struct get_painted_visitor -{ - template - bool operator()(T const& data) const - { - return data.painted(); - } -}; - -struct get_any_size_visitor -{ - template - unsigned operator()(T const& data) const - { - return data.getSize(); - } -}; - -struct get_any_row_size_visitor -{ - template - unsigned operator()(T const& data) const - { - return data.getRowSize(); - } -}; - -struct get_offset_visitor -{ - template - double operator() (T const& data) const - { - return data.get_offset(); - } -}; - -struct get_scaling_visitor -{ - template - double operator() (T const& data) const - { - return data.get_scaling(); - } -}; - -struct set_offset_visitor -{ - set_offset_visitor(double val) - : val_(val) {} - template - void operator() (T & data) - { - data.set_offset(val_); - } - private: - double val_; -}; - -struct set_scaling_visitor -{ - set_scaling_visitor(double val) - : val_(val) {} - template - void operator() (T & data) - { - data.set_scaling(val_); - } - private: - double val_; -}; - -} // namespace detail -struct image_any : image_base +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) - : image_base(std::move(create_image_any(width, height, type, initialize, premultiplied, painted))) {} + int height, + image_dtype type = image_dtype_rgba8, + bool initialize = true, + bool premultiplied = false, + bool painted = false); template 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); - } + : 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); }; -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))); - } -} +image_any create_image_any(int width, + int height, + image_dtype type = image_dtype_rgba8, + bool initialize = true, + bool premultiplied = false, + bool painted = false); } // end mapnik ns -#endif // MAPNIK_IMAGE_DATA_ANY_HPP +#endif // MAPNIK_IMAGE_ANY_HPP diff --git a/include/mapnik/image_impl.hpp b/include/mapnik/image_impl.hpp new file mode 100644 index 0000000000..ac7d090ff9 --- /dev/null +++ b/include/mapnik/image_impl.hpp @@ -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 + +// stl +#include +#include +#include +#include + +namespace mapnik { + +namespace detail { + +// IMAGE_DIMENSIONS +template +image_dimensions::image_dimensions(int width, int height) + : width_(width), + height_(height) +{ + if (width < 0 || static_cast(width) > max_size) throw std::runtime_error("Invalid width for image dimensions requested"); + if (height < 0 || static_cast(height) > max_size) throw std::runtime_error("Invalid height for image dimensions requested"); +} + +template +image_dimensions& image_dimensions::operator= (image_dimensions rhs) +{ + std::swap(width_, rhs.width_); + std::swap(height_, rhs.height_); + return *this; +} + +template +std::size_t image_dimensions::width() const +{ + return width_; +} + +template +std::size_t image_dimensions::height() const +{ + return height_; +} + +} // end detail ns + +// IMAGE +template +image::image() + : dimensions_(0,0), + buffer_(0), + pData_(nullptr), + offset_(0.0), + scaling_(1.0), + premultiplied_alpha_(false), + painted_(false) +{} + +template +image::image(int width, int height, bool initialize, bool premultiplied, bool painted) + : dimensions_(width, height), + buffer_(dimensions_.width() * dimensions_.height() * pixel_size), + pData_(reinterpret_cast(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 +image::image(image const& rhs) + : dimensions_(rhs.dimensions_), + buffer_(rhs.buffer_), + pData_(reinterpret_cast(buffer_.data())), + offset_(rhs.offset_), + scaling_(rhs.scaling_), + premultiplied_alpha_(rhs.premultiplied_alpha_), + painted_(rhs.painted_) +{} + +template +image::image(image && rhs) noexcept + : dimensions_(std::move(rhs.dimensions_)), + buffer_(std::move(rhs.buffer_)), + pData_(reinterpret_cast(buffer_.data())), + offset_(rhs.offset_), + scaling_(rhs.scaling_), + premultiplied_alpha_(rhs.premultiplied_alpha_), + painted_(rhs.painted_) +{ + rhs.dimensions_ = { 0, 0 }; + rhs.pData_ = nullptr; +} + +template +image& image::operator=(image rhs) +{ + swap(rhs); + return *this; +} + +template +image const& image::operator=(image const& rhs) const +{ + return rhs; +} + +template +void image::swap(image & 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 +inline typename image::pixel_type& image::operator() (std::size_t i, std::size_t j) +{ + assert(i < dimensions_.width() && j < dimensions_.height()); + return pData_[j * dimensions_.width() + i]; +} + +template +inline const typename image::pixel_type& image::operator() (std::size_t i, std::size_t j) const +{ + assert(i < dimensions_.width() && j < dimensions_.height()); + return pData_[j * dimensions_.width() + i]; +} + +template +inline std::size_t image::width() const +{ + return dimensions_.width(); +} + +template +inline std::size_t image::height() const +{ + return dimensions_.height(); +} + +template +inline unsigned image::getSize() const +{ + return dimensions_.height() * dimensions_.width() * pixel_size; +} + +template +inline unsigned image::getRowSize() const +{ + return dimensions_.width() * pixel_size; +} + +template +inline void image::set(pixel_type const& t) +{ + std::fill(pData_, pData_ + dimensions_.width() * dimensions_.height(), t); +} + +template +inline const typename image::pixel_type* image::getData() const +{ + return pData_; +} + +template +inline typename image::pixel_type* image::getData() +{ + return pData_; +} + +template +inline const unsigned char* image::getBytes() const +{ + return buffer_.data(); +} + +template +inline unsigned char* image::getBytes() +{ + return buffer_.data(); +} + +template +inline const typename image::pixel_type* image::getRow(std::size_t row) const +{ + return pData_ + row * dimensions_.width(); +} + +template +inline const typename image::pixel_type* image::getRow(std::size_t row, std::size_t x0) const +{ + return pData_ + row * dimensions_.width() + x0; +} + +template +inline typename image::pixel_type* image::getRow(std::size_t row) +{ + return pData_ + row * dimensions_.width(); +} + +template +inline typename image::pixel_type* image::getRow(std::size_t row, std::size_t x0) +{ + return pData_ + row * dimensions_.width() + x0; +} + +template +inline void image::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 +inline void image::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 +inline double image::get_offset() const +{ + return offset_; +} + +template +inline void image::set_offset(double set) +{ + offset_ = set; +} + +template +inline double image::get_scaling() const +{ + return scaling_; +} + +template +inline void image::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 +inline bool image::get_premultiplied() const +{ + return premultiplied_alpha_; +} + +template +inline void image::set_premultiplied(bool set) +{ + premultiplied_alpha_ = set; +} + +template +inline void image::painted(bool painted) +{ + painted_ = painted; +} + +template +inline bool image::painted() const +{ + return painted_; +} + +template +inline image_dtype image::get_dtype() const +{ + return dtype; +} + +/* +using image_rgba8 = image; +using image_gray8 = image; +using image_gray8s = image; +using image_gray16 = image; +using image_gray16s = image; +using image_gray32 = image; +using image_gray32s = image; +using image_gray32f = image; +using image_gray64 = image; +using image_gray64s = image; +using image_gray64f = image; +*/ +} // end ns + +#endif // MAPNIK_IMAGE_IMPL_HPP diff --git a/include/mapnik/image_util.hpp b/include/mapnik/image_util.hpp index 13f30204ee..da9067c0c5 100644 --- a/include/mapnik/image_util.hpp +++ b/include/mapnik/image_util.hpp @@ -25,11 +25,12 @@ // mapnik #include -#include -#include -#include -#include -#include +#include +//#include +//#include +//#include +//#include +//#include // boost #pragma GCC diagnostic push @@ -46,6 +47,11 @@ namespace mapnik { // fwd declares class rgba_palette; +struct image_any; +template class image; +struct image_view_any; +template class image_view; +class color; class ImageWriterException : public std::exception { @@ -162,37 +168,37 @@ template MAPNIK_DECL void fill (image_any & data, T const&); template -MAPNIK_DECL void fill (image_rgba8 & data, T const&); +MAPNIK_DECL void fill (image & data, T const&); template -MAPNIK_DECL void fill (image_gray8 & data, T const&); +MAPNIK_DECL void fill (image & data, T const&); template -MAPNIK_DECL void fill (image_gray8s & data, T const&); +MAPNIK_DECL void fill (image & data, T const&); template -MAPNIK_DECL void fill (image_gray16 & data, T const&); +MAPNIK_DECL void fill (image & data, T const&); template -MAPNIK_DECL void fill (image_gray16s & data, T const&); +MAPNIK_DECL void fill (image & data, T const&); template -MAPNIK_DECL void fill (image_gray32 & data, T const&); +MAPNIK_DECL void fill (image & data, T const&); template -MAPNIK_DECL void fill (image_gray32s & data, T const&); +MAPNIK_DECL void fill (image & data, T const&); template -MAPNIK_DECL void fill (image_gray32f & data, T const&); +MAPNIK_DECL void fill (image & data, T const&); template -MAPNIK_DECL void fill (image_gray64 & data, T const&); +MAPNIK_DECL void fill (image & data, T const&); template -MAPNIK_DECL void fill (image_gray64s & data, T const&); +MAPNIK_DECL void fill (image & data, T const&); template -MAPNIK_DECL void fill (image_gray64f & data, T const&); +MAPNIK_DECL void fill (image & 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 MAPNIK_DECL void set_pixel(image_any & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); template -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 & data, std::size_t x, std::size_t y, T const& val); // GET PIXEL template @@ -258,70 +264,70 @@ template MAPNIK_DECL T get_pixel(image_view_any const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_rgba8 const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_gray8 const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_gray8s const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_gray16 const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_gray16s const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_gray32 const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_gray32s const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_gray32f const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_gray64 const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_gray64s const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -MAPNIK_DECL T get_pixel(image_gray64f const& data, std::size_t x, std::size_t y); +MAPNIK_DECL T get_pixel(image const& data, std::size_t x, std::size_t y); template -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 > const& data, std::size_t x, std::size_t y); template -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 > const& data, std::size_t x, std::size_t y); template -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 > const& data, std::size_t x, std::size_t y); template -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 > const& data, std::size_t x, std::size_t y); template -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 > const& data, std::size_t x, std::size_t y); template -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 > const& data, std::size_t x, std::size_t y); template -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 > const& data, std::size_t x, std::size_t y); template -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 > const& data, std::size_t x, std::size_t y); template -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 > const& data, std::size_t x, std::size_t y); template -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 > const& data, std::size_t x, std::size_t y); template -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 > 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); diff --git a/include/mapnik/image_view.hpp b/include/mapnik/image_view.hpp index ceb12f4a26..f9d13977f6 100644 --- a/include/mapnik/image_view.hpp +++ b/include/mapnik/image_view.hpp @@ -28,7 +28,7 @@ namespace mapnik { template -class image_view +class MAPNIK_DECL image_view { public: using pixel = typename T::pixel; @@ -36,107 +36,26 @@ class image_view 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() {} - - image_view(image_view const& rhs) - : x_(rhs.x_), - y_(rhs.y_), - width_(rhs.width_), - height_(rhs.height_), - data_(rhs.data_) {} - - image_view & operator=(image_view 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; - } + image_view(unsigned x, unsigned y, unsigned width, unsigned height, T const& data); + ~image_view(); + + image_view(image_view const& rhs); + image_view & operator=(image_view const& rhs); + + 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_; diff --git a/include/mapnik/image_view_any.hpp b/include/mapnik/image_view_any.hpp index 90bb0dbe41..7281d85508 100644 --- a/include/mapnik/image_view_any.hpp +++ b/include/mapnik/image_view_any.hpp @@ -40,82 +40,7 @@ using image_view_base = util::variant; -namespace detail { - -struct get_view_width_visitor -{ - template - std::size_t operator()(T const& data) const - { - return data.width(); - } -}; - -struct get_view_height_visitor -{ - template - std::size_t operator()(T const& data) const - { - return data.height(); - } -}; - -struct get_view_size_visitor -{ - template - unsigned operator()(T const& data) const - { - return data.getSize(); - } -}; - -struct get_view_dtype_visitor -{ - template - image_dtype operator()(T const& data) const - { - return data.get_dtype(); - } -}; - -struct get_view_row_size_visitor -{ - template - unsigned operator()(T const& data) const - { - return data.getRowSize(); - } -}; - -struct get_view_premultiplied_visitor -{ - template - bool operator()(T const& data) const - { - return data.get_premultiplied(); - } -}; - -struct get_view_offset_visitor -{ - template - double operator()(T const& data) const - { - return data.get_offset(); - } -}; - -struct get_view_scaling_visitor -{ - template - 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 diff --git a/include/mapnik/image_view_impl.hpp b/include/mapnik/image_view_impl.hpp new file mode 100644 index 0000000000..2a288e58a3 --- /dev/null +++ b/include/mapnik/image_view_impl.hpp @@ -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 + +namespace mapnik { + +template +image_view::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 +image_view::~image_view() {} + +template +image_view::image_view(image_view const& rhs) + : x_(rhs.x_), + y_(rhs.y_), + width_(rhs.width_), + height_(rhs.height_), + data_(rhs.data_) {} + +template +image_view & image_view::operator=(image_view 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 +inline unsigned image_view::x() const +{ + return x_; +} + +template +inline unsigned image_view::y() const +{ + return y_; +} + +template +inline unsigned image_view::width() const +{ + return width_; +} + +template +inline unsigned image_view::height() const +{ + return height_; +} + +template +inline const typename image_view::pixel_type& image_view::operator() (std::size_t i, std::size_t j) const +{ + return data_(i,j); +} + +template +inline unsigned image_view::getSize() const +{ + return height_ * width_ * pixel_size; +} + +template +inline unsigned image_view::getRowSize() const +{ + return width_ * pixel_size; +} + +template +inline const typename image_view::pixel_type* image_view::getRow(unsigned row) const +{ + return data_.getRow(row + y_) + x_; +} + +template +inline const typename image_view::pixel_type* image_view::getRow(unsigned row, std::size_t x0) const +{ + return data_.getRow(row + y_, x0) + x_; +} + +template +inline T const& image_view::data() const +{ + return data_; +} + +template +inline bool image_view::get_premultiplied() const +{ + return data_.get_premultiplied(); +} + +template +inline double image_view::get_offset() const +{ + return data_.get_offset(); +} + +template +inline double image_view::get_scaling() const +{ + return data_.get_scaling(); +} + +template +inline image_dtype image_view::get_dtype() const +{ + return dtype; +} + +} // end ns + +#endif // MAPNIK_IMAGE_VIEW_IMPL_HPP diff --git a/include/mapnik/pixel_types.hpp b/include/mapnik/pixel_types.hpp index 2a36cd443c..68e7ede3b6 100644 --- a/include/mapnik/pixel_types.hpp +++ b/include/mapnik/pixel_types.hpp @@ -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; }; diff --git a/src/build.py b/src/build.py index 8652937117..00bb95346e 100644 --- a/src/build.py +++ b/src/build.py @@ -174,6 +174,11 @@ def ldconfig(*args,**kwargs): 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 diff --git a/src/image.cpp b/src/image.cpp new file mode 100644 index 0000000000..cb14729fe2 --- /dev/null +++ b/src/image.cpp @@ -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 +#include +#include +#include + +namespace mapnik +{ + +namespace detail +{ + +// BUFFER +buffer::buffer(std::size_t size) + : size_(size), + data_(static_cast(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(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; +template class MAPNIK_DECL image; +template class MAPNIK_DECL image; +template class MAPNIK_DECL image; +template class MAPNIK_DECL image; +template class MAPNIK_DECL image; +template class MAPNIK_DECL image; +template class MAPNIK_DECL image; +template class MAPNIK_DECL image; +template class MAPNIK_DECL image; +template class MAPNIK_DECL image; +template class MAPNIK_DECL image; + +} // end ns diff --git a/src/image_any.cpp b/src/image_any.cpp new file mode 100644 index 0000000000..579bb071c2 --- /dev/null +++ b/src/image_any.cpp @@ -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 + +namespace mapnik { + +namespace detail { + +struct get_bytes_visitor +{ + template + unsigned char* operator()(T & data) + { + return data.getBytes(); + } +}; + +struct get_dtype_visitor +{ + template + image_dtype operator()(T & data) + { + return data.get_dtype(); + } +}; + +struct get_bytes_visitor_const +{ + template + unsigned char const* operator()(T const& data) const + { + return data.getBytes(); + } +}; + +struct get_width_visitor +{ + template + std::size_t operator()(T const& data) const + { + return data.width(); + } +}; + +struct get_height_visitor +{ + template + std::size_t operator()(T const& data) const + { + return data.height(); + } +}; + +struct get_premultiplied_visitor +{ + template + bool operator()(T const& data) const + { + return data.get_premultiplied(); + } +}; + +struct get_painted_visitor +{ + template + bool operator()(T const& data) const + { + return data.painted(); + } +}; + +struct get_any_size_visitor +{ + template + unsigned operator()(T const& data) const + { + return data.getSize(); + } +}; + +struct get_any_row_size_visitor +{ + template + unsigned operator()(T const& data) const + { + return data.getRowSize(); + } +}; + +struct get_offset_visitor +{ + template + double operator() (T const& data) const + { + return data.get_offset(); + } +}; + +struct get_scaling_visitor +{ + template + double operator() (T const& data) const + { + return data.get_scaling(); + } +}; + +struct set_offset_visitor +{ + set_offset_visitor(double val) + : val_(val) {} + template + void operator() (T & data) + { + data.set_offset(val_); + } + private: + double val_; +}; + +struct set_scaling_visitor +{ + set_scaling_visitor(double val) + : val_(val) {} + template + 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 diff --git a/src/image_null.cpp b/src/image_null.cpp new file mode 100644 index 0000000000..595cfc3587 --- /dev/null +++ b/src/image_null.cpp @@ -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 +#include +#include + +//stl +#include + +namespace mapnik +{ + +template <> +class image +{ +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 const& rhs) {} + image(image && rhs) noexcept {} + + void swap(image & 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 diff --git a/src/image_util_jpeg.cpp b/src/image_util_jpeg.cpp index 61c11245fa..ff2b37ea35 100644 --- a/src/image_util_jpeg.cpp +++ b/src/image_util_jpeg.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -37,7 +36,6 @@ // stl #include -#include namespace mapnik { diff --git a/src/image_view.cpp b/src/image_view.cpp new file mode 100644 index 0000000000..9a891ec859 --- /dev/null +++ b/src/image_view.cpp @@ -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 +#include +#include + +namespace mapnik +{ + +template class MAPNIK_DECL image_view; +template class MAPNIK_DECL image_view; +template class MAPNIK_DECL image_view; +template class MAPNIK_DECL image_view; +template class MAPNIK_DECL image_view; +template class MAPNIK_DECL image_view; +template class MAPNIK_DECL image_view; +template class MAPNIK_DECL image_view; +template class MAPNIK_DECL image_view; +template class MAPNIK_DECL image_view; +template class MAPNIK_DECL image_view; + +} // end ns mapnik diff --git a/src/image_view_any.cpp b/src/image_view_any.cpp new file mode 100644 index 0000000000..afe5a4b902 --- /dev/null +++ b/src/image_view_any.cpp @@ -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 + +namespace mapnik { + +namespace detail { + +struct get_view_width_visitor +{ + template + std::size_t operator()(T const& data) const + { + return data.width(); + } +}; + +struct get_view_height_visitor +{ + template + std::size_t operator()(T const& data) const + { + return data.height(); + } +}; + +struct get_view_size_visitor +{ + template + unsigned operator()(T const& data) const + { + return data.getSize(); + } +}; + +struct get_view_dtype_visitor +{ + template + image_dtype operator()(T const& data) const + { + return data.get_dtype(); + } +}; + +struct get_view_row_size_visitor +{ + template + unsigned operator()(T const& data) const + { + return data.getRowSize(); + } +}; + +struct get_view_premultiplied_visitor +{ + template + bool operator()(T const& data) const + { + return data.get_premultiplied(); + } +}; + +struct get_view_offset_visitor +{ + template + double operator()(T const& data) const + { + return data.get_offset(); + } +}; + +struct get_view_scaling_visitor +{ + template + 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