diff --git a/include/mapnik/image.hpp b/include/mapnik/image.hpp index 7eb71f4f0..daacba678 100644 --- a/include/mapnik/image.hpp +++ b/include/mapnik/image.hpp @@ -24,60 +24,28 @@ #define MAPNIK_IMAGE_HPP // mapnik -#include +#include #include -// stl -#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)) - {} + 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(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_; @@ -86,37 +54,20 @@ 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 +template class image { public: @@ -125,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 dimensions_; + detail::image_dimensions<65535> dimensions_; detail::buffer buffer_; pixel_type *pData_; double offset_; diff --git a/include/mapnik/image_any.hpp b/include/mapnik/image_any.hpp index 2af51976c..b5d539d39 100644 --- a/include/mapnik/image_any.hpp +++ b/include/mapnik/image_any.hpp @@ -42,7 +42,7 @@ using image_base = util::variant; -struct image_any : image_base +struct MAPNIK_DECL image_any : image_base { image_any() = default; @@ -54,7 +54,8 @@ struct image_any : image_base bool painted = false); template - image_any(T && data) noexcept; + image_any(T && data) noexcept + : image_base(std::move(data)) {} unsigned char const* getBytes() const; unsigned char* getBytes(); diff --git a/include/mapnik/image_impl.hpp b/include/mapnik/image_impl.hpp index 2d243fa92..52e2a9ebd 100644 --- a/include/mapnik/image_impl.hpp +++ b/include/mapnik/image_impl.hpp @@ -34,8 +34,43 @@ namespace mapnik { -template -image::image() +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), @@ -45,8 +80,8 @@ image::image() painted_(false) {} -template -image::image(int width, int height, bool initialize, bool premultiplied, bool painted) +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())), @@ -61,8 +96,8 @@ image::image(int width, int height, bool initialize, bool premultipl } } -template -image::image(image const& rhs) +template +image::image(image const& rhs) : dimensions_(rhs.dimensions_), buffer_(rhs.buffer_), pData_(reinterpret_cast(buffer_.data())), @@ -72,8 +107,8 @@ image::image(image const& rhs) painted_(rhs.painted_) {} -template -image::image(image && rhs) noexcept +template +image::image(image && rhs) noexcept : dimensions_(std::move(rhs.dimensions_)), buffer_(std::move(rhs.buffer_)), pData_(reinterpret_cast(buffer_.data())), @@ -86,15 +121,15 @@ image::image(image && rhs) noexcept rhs.pData_ = nullptr; } -template -image& image::operator=(image rhs) +template +image& image::operator=(image rhs) { swap(rhs); return *this; } -template -void image::swap(image & rhs) +template +void image::swap(image & rhs) { std::swap(dimensions_, rhs.dimensions_); std::swap(buffer_, rhs.buffer_); @@ -104,134 +139,134 @@ void image::swap(image & rhs) std::swap(painted_, rhs.painted_); } -template -inline typename image::pixel_type& image::operator() (std::size_t i, std::size_t j) +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 +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 +template +inline std::size_t image::width() const { return dimensions_.width(); } -template -inline std::size_t image::height() const +template +inline std::size_t image::height() const { return dimensions_.height(); } -template -inline unsigned image::getSize() const +template +inline unsigned image::getSize() const { return dimensions_.height() * dimensions_.width() * pixel_size; } -template -inline unsigned image::getRowSize() const +template +inline unsigned image::getRowSize() const { return dimensions_.width() * pixel_size; } -template -inline void image::set(pixel_type const& t) +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 +template +inline const typename image::pixel_type* image::getData() const { return pData_; } -template -inline typename image::pixel_type* image::getData() +template +inline typename image::pixel_type* image::getData() { return pData_; } -template -inline const unsigned char* image::getBytes() const +template +inline const unsigned char* image::getBytes() const { return buffer_.data(); } -template -inline unsigned char* image::getBytes() +template +inline unsigned char* image::getBytes() { return buffer_.data(); } -template -inline const typename image::pixel_type* image::getRow(std::size_t row) const +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 +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) +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) +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) +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) +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 +template +inline double image::get_offset() const { return offset_; } -template -inline void image::set_offset(double set) +template +inline void image::set_offset(double set) { offset_ = set; } -template -inline double image::get_scaling() const +template +inline double image::get_scaling() const { return scaling_; } -template -inline void image::set_scaling(double set) +template +inline void image::set_scaling(double set) { if (set != 0.0) { @@ -241,32 +276,32 @@ inline void image::set_scaling(double set) std::clog << "Can not set scaling to 0.0, offset not set." << std::endl; } -template -inline bool image::get_premultiplied() const +template +inline bool image::get_premultiplied() const { return premultiplied_alpha_; } -template -inline void image::set_premultiplied(bool set) +template +inline void image::set_premultiplied(bool set) { premultiplied_alpha_ = set; } -template -inline void image::painted(bool painted) +template +inline void image::painted(bool painted) { painted_ = painted; } -template -inline bool image::painted() const +template +inline bool image::painted() const { return painted_; } -template -inline image_dtype image::get_dtype() const +template +inline image_dtype image::get_dtype() const { return dtype; } diff --git a/include/mapnik/image_util.hpp b/include/mapnik/image_util.hpp index 13f30204e..da9067c0c 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 ceb12f4a2..b53d3c8cd 100644 --- a/include/mapnik/image_view.hpp +++ b/include/mapnik/image_view.hpp @@ -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 const& rhs); + image_view & operator=(image_view const& rhs); - 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; - } + 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_impl.hpp b/include/mapnik/image_view_impl.hpp new file mode 100644 index 000000000..2a288e58a --- /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/src/build.py b/src/build.py index 52b78a68c..064c2e683 100644 --- a/src/build.py +++ b/src/build.py @@ -175,6 +175,7 @@ source = Split( image_reader.cpp cairo_io.cpp image.cpp + image_view.cpp image_any.cpp image_null.cpp image_util.cpp diff --git a/src/image.cpp b/src/image.cpp index 7a3885b90..cb14729fe 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -29,6 +29,71 @@ 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; diff --git a/src/image_any.cpp b/src/image_any.cpp index 33932ae92..579bb071c 100644 --- a/src/image_any.cpp +++ b/src/image_any.cpp @@ -153,7 +153,7 @@ struct set_scaling_visitor } // namespace detail -image_any::image_any(int width, +MAPNIK_DECL image_any::image_any(int width, int height, image_dtype type, bool initialize, @@ -161,102 +161,73 @@ image_any::image_any(int width, bool painted) : image_base(std::move(create_image_any(width, height, type, initialize, premultiplied, painted))) {} -template -image_any::image_any(T && data) noexcept - : image_base(std::move(data)) {} - -template image_any::image_any(image_null && data) noexcept; -template image_any::image_any(image_rgba8 && data) noexcept; -template image_any::image_any(image_gray8 && data) noexcept; -template image_any::image_any(image_gray8s && data) noexcept; -template image_any::image_any(image_gray16 && data) noexcept; -template image_any::image_any(image_gray16s && data) noexcept; -template image_any::image_any(image_gray32 && data) noexcept; -template image_any::image_any(image_gray32s && data) noexcept; -template image_any::image_any(image_gray32f && data) noexcept; -template image_any::image_any(image_gray64 && data) noexcept; -template image_any::image_any(image_gray64s && data) noexcept; -template image_any::image_any(image_gray64f && data) noexcept; -template image_any::image_any(image_null const& data) noexcept; -template image_any::image_any(image_rgba8 const& data) noexcept; -template image_any::image_any(image_gray8 const& data) noexcept; -template image_any::image_any(image_gray8s const& data) noexcept; -template image_any::image_any(image_gray16 const& data) noexcept; -template image_any::image_any(image_gray16s const& data) noexcept; -template image_any::image_any(image_gray32 const& data) noexcept; -template image_any::image_any(image_gray32s const& data) noexcept; -template image_any::image_any(image_gray32f const& data) noexcept; -template image_any::image_any(image_gray64 const& data) noexcept; -template image_any::image_any(image_gray64s const& data) noexcept; -template image_any::image_any(image_gray64f const& data) noexcept; - -unsigned char const* image_any::getBytes() const +MAPNIK_DECL unsigned char const* image_any::getBytes() const { return util::apply_visitor(detail::get_bytes_visitor_const(),*this); } -unsigned char* image_any::getBytes() +MAPNIK_DECL unsigned char* image_any::getBytes() { return util::apply_visitor(detail::get_bytes_visitor(),*this); } -std::size_t image_any::width() const +MAPNIK_DECL std::size_t image_any::width() const { return util::apply_visitor(detail::get_width_visitor(),*this); } -std::size_t image_any::height() const +MAPNIK_DECL std::size_t image_any::height() const { return util::apply_visitor(detail::get_height_visitor(),*this); } -bool image_any::get_premultiplied() const +MAPNIK_DECL bool image_any::get_premultiplied() const { return util::apply_visitor(detail::get_premultiplied_visitor(),*this); } -bool image_any::painted() const +MAPNIK_DECL bool image_any::painted() const { return util::apply_visitor(detail::get_painted_visitor(),*this); } -unsigned image_any::getSize() const +MAPNIK_DECL unsigned image_any::getSize() const { return util::apply_visitor(detail::get_any_size_visitor(),*this); } -unsigned image_any::getRowSize() const +MAPNIK_DECL unsigned image_any::getRowSize() const { return util::apply_visitor(detail::get_any_row_size_visitor(),*this); } -double image_any::get_offset() const +MAPNIK_DECL double image_any::get_offset() const { return util::apply_visitor(detail::get_offset_visitor(),*this); } -double image_any::get_scaling() const +MAPNIK_DECL double image_any::get_scaling() const { return util::apply_visitor(detail::get_scaling_visitor(),*this); } -image_dtype image_any::get_dtype() const +MAPNIK_DECL image_dtype image_any::get_dtype() const { return util::apply_visitor(detail::get_dtype_visitor(),*this); } -void image_any::set_offset(double val) +MAPNIK_DECL void image_any::set_offset(double val) { util::apply_visitor(detail::set_offset_visitor(val),*this); } -void image_any::set_scaling(double val) +MAPNIK_DECL void image_any::set_scaling(double val) { util::apply_visitor(detail::set_scaling_visitor(val),*this); } -image_any create_image_any(int width, +MAPNIK_DECL image_any create_image_any(int width, int height, image_dtype type, bool initialize, diff --git a/src/image_null.cpp b/src/image_null.cpp index 89bd92af7..595cfc358 100644 --- a/src/image_null.cpp +++ b/src/image_null.cpp @@ -26,6 +26,9 @@ #include #include +//stl +#include + namespace mapnik { diff --git a/src/image_util_jpeg.cpp b/src/image_util_jpeg.cpp index 61c11245f..ff2b37ea3 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 {