/usr/include/mapnik/image_impl.hpp is in libmapnik-dev 3.0.12+ds-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | /*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2015 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
// mapnik
#include <mapnik/image.hpp>
#include <mapnik/pixel_types.hpp>
// stl
#include <cassert>
#include <stdexcept>
#include <algorithm>
namespace mapnik {
namespace detail {
// IMAGE_DIMENSIONS
template <std::size_t max_size>
image_dimensions<max_size>::image_dimensions(int width, int height)
: width_(width),
height_(height)
{
if (width < 0 || static_cast<std::size_t>(width) > max_size) throw std::runtime_error("Invalid width for image dimensions requested");
if (height < 0 || static_cast<std::size_t>(height) > max_size) throw std::runtime_error("Invalid height for image dimensions requested");
}
template <std::size_t max_size>
std::size_t image_dimensions<max_size>::width() const
{
return width_;
}
template <std::size_t max_size>
std::size_t image_dimensions<max_size>::height() const
{
return height_;
}
} // end detail ns
// IMAGE
template <typename T>
image<T>::image()
: dimensions_(0,0),
buffer_(0),
offset_(0.0),
scaling_(1.0),
premultiplied_alpha_(false),
painted_(false)
{}
template <typename T>
image<T>::image(int width, int height, unsigned char* data, bool premultiplied, bool painted)
: dimensions_(width, height),
buffer_(data, width * height * sizeof(pixel_size)),
offset_(0.0),
scaling_(1.0),
premultiplied_alpha_(premultiplied),
painted_(painted) {}
template <typename T>
image<T>::image(int width, int height, bool initialize, bool premultiplied, bool painted)
: dimensions_(width, height),
buffer_(dimensions_.width() * dimensions_.height() * pixel_size),
offset_(0.0),
scaling_(1.0),
premultiplied_alpha_(premultiplied),
painted_(painted)
{
if (initialize)
{
std::fill(begin(), end(), 0);
}
}
template <typename T>
image<T>::image(image<T> const& rhs)
: dimensions_(rhs.dimensions_),
buffer_(rhs.buffer_),
offset_(rhs.offset_),
scaling_(rhs.scaling_),
premultiplied_alpha_(rhs.premultiplied_alpha_),
painted_(rhs.painted_) {}
template <typename T>
image<T>::image(image<T> && rhs) noexcept
: dimensions_(std::move(rhs.dimensions_)),
buffer_(std::move(rhs.buffer_)),
offset_(rhs.offset_),
scaling_(rhs.scaling_),
premultiplied_alpha_(rhs.premultiplied_alpha_),
painted_(rhs.painted_)
{
rhs.dimensions_ = { 0, 0 };
}
template <typename T>
image<T>& image<T>::operator=(image<T> rhs)
{
swap(rhs);
return *this;
}
template <typename T>
bool image<T>::operator==(image<T> const& rhs) const
{
return rhs.bytes() == bytes();
}
template <typename T>
bool image<T>::operator<(image<T> const& rhs) const
{
return size() < rhs.size();
}
template <typename T>
void image<T>::swap(image<T> & rhs)
{
std::swap(dimensions_, rhs.dimensions_);
std::swap(buffer_, rhs.buffer_);
std::swap(offset_, rhs.offset_);
std::swap(scaling_, rhs.scaling_);
std::swap(premultiplied_alpha_, rhs.premultiplied_alpha_);
std::swap(painted_, rhs.painted_);
}
template <typename T>
inline typename image<T>::pixel_type& image<T>::operator() (std::size_t i, std::size_t j)
{
assert(i < dimensions_.width() && j < dimensions_.height());
return *get_row(j, i);
}
template <typename T>
inline const typename image<T>::pixel_type& image<T>::operator() (std::size_t i, std::size_t j) const
{
assert(i < dimensions_.width() && j < dimensions_.height());
return *get_row(j, i);
}
template <typename T>
inline std::size_t image<T>::width() const
{
return dimensions_.width();
}
template <typename T>
inline std::size_t image<T>::height() const
{
return dimensions_.height();
}
template <typename T>
inline std::size_t image<T>::size() const
{
return dimensions_.height() * dimensions_.width() * pixel_size;
}
template <typename T>
inline std::size_t image<T>::row_size() const
{
return dimensions_.width() * pixel_size;
}
template <typename T>
inline void image<T>::set(pixel_type const& t)
{
std::fill(begin(), end(), t);
}
template <typename T>
inline const typename image<T>::pixel_type* image<T>::data() const
{
return reinterpret_cast<const pixel_type*>(buffer_.data());
}
template <typename T>
inline typename image<T>::pixel_type* image<T>::data()
{
return reinterpret_cast<pixel_type*>(buffer_.data());
}
template <typename T>
inline const unsigned char* image<T>::bytes() const
{
return buffer_.data();
}
template <typename T>
inline unsigned char* image<T>::bytes()
{
return buffer_.data();
}
// iterator interface
template <typename T>
inline typename image<T>::iterator image<T>::begin() { return data(); }
template <typename T>
inline typename image<T>::iterator image<T>::end() { return data() + dimensions_.width() * dimensions_.height(); }
template <typename T>
inline typename image<T>::const_iterator image<T>::begin() const { return data(); }
template <typename T>
inline typename image<T>::const_iterator image<T>::end() const{ return data() + dimensions_.width() * dimensions_.height(); }
template <typename T>
inline typename image<T>::pixel_type const* image<T>::get_row(std::size_t row) const
{
return data() + row * dimensions_.width();
}
template <typename T>
inline const typename image<T>::pixel_type* image<T>::get_row(std::size_t row, std::size_t x0) const
{
return data() + row * dimensions_.width() + x0;
}
template <typename T>
inline typename image<T>::pixel_type* image<T>::get_row(std::size_t row)
{
return data() + row * dimensions_.width();
}
template <typename T>
inline typename image<T>::pixel_type* image<T>::get_row(std::size_t row, std::size_t x0)
{
return data() + row * dimensions_.width() + x0;
}
template <typename T>
inline void image<T>::set_row(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, get_row(row));
}
template <typename T>
inline void image<T>::set_row(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), get_row(row, x0));
}
template <typename T>
inline double image<T>::get_offset() const
{
return offset_;
}
template <typename T>
inline void image<T>::set_offset(double set)
{
offset_ = set;
}
template <typename T>
inline double image<T>::get_scaling() const
{
return scaling_;
}
template <typename T>
inline void image<T>::set_scaling(double scaling)
{
if (scaling != 0.0)
{
scaling_ = scaling;
return;
}
}
template <typename T>
inline bool image<T>::get_premultiplied() const
{
return premultiplied_alpha_;
}
template <typename T>
inline void image<T>::set_premultiplied(bool set)
{
premultiplied_alpha_ = set;
}
template <typename T>
inline void image<T>::painted(bool painted)
{
painted_ = painted;
}
template <typename T>
inline bool image<T>::painted() const
{
return painted_;
}
template <typename T>
inline image_dtype image<T>::get_dtype() const
{
return dtype;
}
} // end ns
|