-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathmapnik_image_view.cpp
More file actions
103 lines (91 loc) · 3.09 KB
/
Copy pathmapnik_image_view.cpp
File metadata and controls
103 lines (91 loc) · 3.09 KB
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
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2024 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/config.hpp>
#include <mapnik/image.hpp>
#include <mapnik/image_view.hpp>
#include <mapnik/image_view_any.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/palette.hpp>
#include <mapnik/util/variant.hpp>
//stl
#include <sstream>
//pybind11
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
using mapnik::image_view_any;
using mapnik::save_to_file;
namespace py = pybind11;
// output 'raw' pixels
py::object view_tostring1(image_view_any const& view)
{
std::ostringstream ss(std::ios::out|std::ios::binary);
mapnik::view_to_stream(view, ss);
return py::bytes(ss.str().c_str(), ss.str().size());
}
// encode (png,jpeg)
py::object view_tostring2(image_view_any const & view, std::string const& format)
{
std::string s = save_to_string(view, format);
return py::bytes(s.data(), s.length());
}
py::object view_tostring3(image_view_any const & view, std::string const& format, mapnik::rgba_palette const& pal)
{
std::string s = save_to_string(view, format, pal);
return py::bytes(s.data(), s.length());
}
bool is_solid(image_view_any const& view)
{
return mapnik::is_solid(view);
}
void save_view1(image_view_any const& view,
std::string const& filename)
{
save_to_file(view,filename);
}
void save_view2(image_view_any const& view,
std::string const& filename,
std::string const& type)
{
save_to_file(view,filename,type);
}
void save_view3(image_view_any const& view,
std::string const& filename,
std::string const& type,
mapnik::rgba_palette const& pal)
{
save_to_file(view,filename,type,pal);
}
void export_image_view(py::module const& m)
{
py::class_<image_view_any>(m, "ImageView", "A view into an image.")
.def("width",&image_view_any::width)
.def("height",&image_view_any::height)
.def("is_solid",&is_solid)
.def("to_string",&view_tostring1)
.def("to_string",&view_tostring2)
.def("to_string",&view_tostring3)
.def("save",&save_view1)
.def("save",&save_view2)
.def("save",&save_view3)
;
}