/usr/include/mapnik/image_util.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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | /*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2015 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_IMAGE_UTIL_HPP
#define MAPNIK_IMAGE_UTIL_HPP
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/pixel_types.hpp>
#include <mapnik/image_compositing.hpp>
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/optional.hpp>
#pragma GCC diagnostic pop
// stl
#include <string>
#include <exception>
namespace mapnik {
// fwd declares
class rgba_palette;
struct image_any;
template <typename T> class image;
struct image_view_any;
template <typename T> class image_view;
class color;
class image_writer_exception : public std::exception
{
private:
std::string message_;
public:
image_writer_exception(std::string const& message)
: message_(message) {}
~image_writer_exception() throw() {}
virtual const char* what() const throw()
{
return message_.c_str();
}
};
template <typename T>
MAPNIK_DECL void save_to_file(T const& image,
std::string const& filename,
std::string const& type);
template <typename T>
MAPNIK_DECL void save_to_file(T const& image,
std::string const& filename,
std::string const& type,
rgba_palette const& palette);
// guess type from file extension
template <typename T>
MAPNIK_DECL void save_to_file(T const& image,
std::string const& filename);
template <typename T>
MAPNIK_DECL void save_to_file(T const& image,
std::string const& filename,
rgba_palette const& palette);
template <typename T>
MAPNIK_DECL std::string save_to_string(T const& image,
std::string const& type);
template <typename T>
MAPNIK_DECL std::string save_to_string(T const& image,
std::string const& type,
rgba_palette const& palette);
template <typename T>
MAPNIK_DECL void save_to_stream
(
T const& image,
std::ostream & stream,
std::string const& type,
rgba_palette const& palette
);
template <typename T>
MAPNIK_DECL void save_to_stream
(
T const& image,
std::ostream & stream,
std::string const& type
);
// PREMULTIPLY ALPHA
MAPNIK_DECL bool premultiply_alpha(image_any & image);
template <typename T>
MAPNIK_DECL bool premultiply_alpha(T & image);
// DEMULTIPLY ALPHA
MAPNIK_DECL bool demultiply_alpha(image_any & image);
template <typename T>
MAPNIK_DECL bool demultiply_alpha(T & image);
// SET PREMULTIPLIED ALPHA
MAPNIK_DECL void set_premultiplied_alpha(image_any & image, bool status);
template <typename T>
MAPNIK_DECL void set_premultiplied_alpha(T & image, bool status);
// IS SOLID
MAPNIK_DECL bool is_solid (image_any const& image);
MAPNIK_DECL bool is_solid (image_view_any const& image);
template <typename T>
MAPNIK_DECL bool is_solid (T const& image);
// APPLY OPACITY
MAPNIK_DECL void apply_opacity (image_any & image, float opacity);
template <typename T>
MAPNIK_DECL void apply_opacity (T & image, float opacity);
// SET GRAYSCALE TO ALPHA
MAPNIK_DECL void set_grayscale_to_alpha (image_any & image);
MAPNIK_DECL void set_grayscale_to_alpha (image_any & image, color const& c);
template <typename T>
MAPNIK_DECL void set_grayscale_to_alpha (T & image);
template <typename T>
MAPNIK_DECL void set_grayscale_to_alpha (T & image, color const& c);
// SET COLOR TO ALPHA
MAPNIK_DECL void set_color_to_alpha (image_any & image, color const& c);
template <typename T>
MAPNIK_DECL void set_color_to_alpha (T & image, color const& c);
// FILL
template <typename T>
MAPNIK_DECL void fill (image_any & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<rgba8_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<gray8_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<gray8s_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<gray16_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<gray16s_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<gray32_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<gray32s_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<gray32f_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<gray64_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<gray64s_t> & data, T const&);
template <typename T>
MAPNIK_DECL void fill (image<gray64f_t> & data, T const&);
// CHECK BOUNDS
template <typename T>
inline bool check_bounds (T const& data, std::size_t x, std::size_t y)
{
return (x < data.width() && y < data.height());
}
// COMPOSITE_PIXEL
MAPNIK_DECL void composite_pixel(image_any & data, composite_mode_e comp_op, std::size_t x, std::size_t y, unsigned c, unsigned cover, double opacity );
template <typename T>
MAPNIK_DECL void composite_pixel(T & data, composite_mode_e comp_op, std::size_t x, std::size_t y, unsigned c, unsigned cover, double opacity );
// SET PIXEL
template <typename T>
MAPNIK_DECL void set_pixel(image_any & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<rgba8_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<gray8_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<gray8s_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<gray16_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<gray16s_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<gray32_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<gray32s_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<gray32f_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<gray64_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<gray64s_t> & data, std::size_t x, std::size_t y, T const& val);
template <typename T>
MAPNIK_DECL void set_pixel(image<gray64f_t> & data, std::size_t x, std::size_t y, T const& val);
// GET PIXEL
template <typename T>
MAPNIK_DECL T get_pixel(image_any const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view_any const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<rgba8_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<gray8_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<gray8s_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<gray16_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<gray16s_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<gray32_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<gray32s_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<gray32f_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<gray64_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<gray64s_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image<gray64f_t> const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<rgba8_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray8_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray8s_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray16_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray16s_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray32_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray32s_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray32f_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray64_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray64s_t> > const& data, std::size_t x, std::size_t y);
template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray64f_t> > const& data, std::size_t x, std::size_t y);
// VIEW TO OUTPUT STREAM
template <typename Out>
MAPNIK_DECL void view_to_stream (image_view_any const& view, Out & os);
// CREATE VIEW
MAPNIK_DECL image_view_any create_view (image_any const& data, std::size_t x, std::size_t y, std::size_t w, std::size_t h);
// COMPARE
template <typename T>
MAPNIK_DECL std::size_t compare(T const& im1, T const& im2, double threshold = 0.0, bool alpha = true);
inline bool is_png(std::string const& filename)
{
return boost::algorithm::iends_with(filename,std::string(".png"));
}
inline bool is_jpeg(std::string const& filename)
{
return boost::algorithm::iends_with(filename,std::string(".jpg")) ||
boost::algorithm::iends_with(filename,std::string(".jpeg"));
}
inline bool is_tiff(std::string const& filename)
{
return boost::algorithm::iends_with(filename,std::string(".tif")) ||
boost::algorithm::iends_with(filename,std::string(".tiff"));
}
inline bool is_pdf(std::string const& filename)
{
return boost::algorithm::iends_with(filename,std::string(".pdf"));
}
inline bool is_svg(std::string const& filename)
{
return boost::algorithm::iends_with(filename,std::string(".svg"));
}
inline bool is_ps(std::string const& filename)
{
return boost::algorithm::iends_with(filename,std::string(".ps"));
}
inline bool is_webp(std::string const& filename)
{
return boost::algorithm::iends_with(filename,std::string(".webp"));
}
inline boost::optional<std::string> type_from_filename(std::string const& filename)
{
using result_type = boost::optional<std::string>;
if (is_png(filename)) return result_type("png");
if (is_jpeg(filename)) return result_type("jpeg");
if (is_tiff(filename)) return result_type("tiff");
if (is_pdf(filename)) return result_type("pdf");
if (is_svg(filename)) return result_type("svg");
if (is_ps(filename)) return result_type("ps");
if (is_webp(filename)) return result_type("webp");
return result_type();
}
inline std::string guess_type( std::string const& filename )
{
std::string::size_type idx = filename.find_last_of(".");
if ( idx != std::string::npos ) {
return filename.substr( idx + 1 );
}
return "<unknown>";
}
// add 1-px border around image - useful for debugging alignment issues
template <typename T>
void add_border(T & image)
{
for (unsigned x = 0; x < image.width();++x)
{
image(x,0) = 0xff0000ff; // red
image(x,image.height()-1) = 0xff00ff00; //green
}
for (unsigned y = 0; y < image.height();++y)
{
image(0,y) = 0xff00ffff; //yellow
image(image.width()-1,y) = 0xffff0000; // blue
}
}
}
#endif // MAPNIK_IMAGE_UTIL_HPP
|