/usr/include/mapnik/image_util.hpp is in libmapnik-dev 2.2.0+ds1-6build2.
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 | /*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2011 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>
#ifdef _MSC_VER
#include <mapnik/graphics.hpp>
#endif
// boost
#include <boost/algorithm/string/predicate.hpp>
#include <boost/optional.hpp>
// stl
#include <string>
#include <cmath>
namespace mapnik {
// fwd declares
class Map;
class rgba_palette;
class image_32;
class ImageWriterException : public std::exception
{
private:
std::string message_;
public:
ImageWriterException(std::string const& message)
: message_(message) {}
~ImageWriterException() throw() {}
virtual const char* what() const throw()
{
return message_.c_str();
}
};
#if defined(HAVE_CAIRO)
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
std::string const& filename,
double scale_factor=1.0);
MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
std::string const& filename,
std::string const& type,
double scale_factor=1.0);
#endif
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>
void save_as_png(T const& image,
std::string const& filename,
rgba_palette const& palette);
#if defined(HAVE_JPEG)
template <typename T>
void save_as_jpeg(std::string const& filename,
int quality,
T const& image);
#endif
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 boost::optional<std::string> type_from_filename(std::string const& filename)
{
typedef boost::optional<std::string> result_type;
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");
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>";
}
template <typename T>
double distance(T x0,T y0,T x1,T y1)
{
double dx = x1-x0;
double dy = y1-y0;
return std::sqrt(dx * dx + dy * dy);
}
// 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
}
}
/////////// save_to_file ////////////////////////////////////////////////
MAPNIK_DECL void save_to_file(image_32 const& image,
std::string const& file);
MAPNIK_DECL void save_to_file (image_32 const& image,
std::string const& file,
std::string const& type);
MAPNIK_DECL void save_to_file (image_32 const& image,
std::string const& file,
std::string const& type,
rgba_palette const& palette);
//////////////////////////////////////////////////////////////////////////
MAPNIK_DECL std::string save_to_string(image_32 const& image,
std::string const& type);
MAPNIK_DECL std::string save_to_string(image_32 const& image,
std::string const& type,
rgba_palette const& palette);
///////////////////////////////////////////////////////////////////////////
#ifdef _MSC_VER
template MAPNIK_DECL void save_to_file<image_data_32>(image_data_32 const&,
std::string const&,
std::string const&,
rgba_palette const&);
template MAPNIK_DECL void save_to_file<image_data_32>(image_data_32 const&,
std::string const&,
std::string const&);
template MAPNIK_DECL void save_to_file<image_data_32>(image_data_32 const&,
std::string const&,
rgba_palette const&);
template MAPNIK_DECL void save_to_file<image_data_32>(image_data_32 const&,
std::string const&);
template MAPNIK_DECL void save_to_file<image_view<image_data_32> > (image_view<image_data_32> const&,
std::string const&,
std::string const&,
rgba_palette const&);
template MAPNIK_DECL void save_to_file<image_view<image_data_32> > (image_view<image_data_32> const&,
std::string const&,
std::string const&);
template MAPNIK_DECL void save_to_file<image_view<image_data_32> > (image_view<image_data_32> const&,
std::string const&,
rgba_palette const&);
template MAPNIK_DECL void save_to_file<image_view<image_data_32> > (image_view<image_data_32> const&,
std::string const&);
template MAPNIK_DECL std::string save_to_string<image_data_32>(image_data_32 const&,
std::string const&,
rgba_palette const&);
template MAPNIK_DECL std::string save_to_string<image_view<image_data_32> > (image_view<image_data_32> const&,
std::string const&);
template MAPNIK_DECL std::string save_to_string<image_view<image_data_32> > (image_view<image_data_32> const&,
std::string const&,
rgba_palette const&);
#endif
}
#endif // MAPNIK_IMAGE_UTIL_HPP
|