Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lodepng_io.hpp « coding - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 23b7787e703e039b297ebbe5590d617e3528bb59 (plain)
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
/*
    Copyright 2005-2007 Adobe Systems Incorporated

    Use, modification and distribution are subject to the Boost Software License,
    Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt).

    See http://opensource.adobe.com/gil for most recent version including documentation.
*/

/*************************************************************************************************/

#ifndef GIL_LODEPNG_IO_H
#define GIL_LODEPNG_IO_H

/// \file
/// \brief  Support for reading and writing PNG files
///         using LodePNG
//
// We are currently providing the following functions:
// point2<std::ptrdiff_t>    lodepng_read_dimensions(const char*)
// template <typename View>  void lodepng_read_view(const char*,const View&)
// template <typename View>  void lodepng_read_image(const char*,image<View>&)
// template <typename View>  void lodepng_write_view(const char*,const View&)
// template <typename View>  struct lodepng_read_support;
// template <typename View>  struct lodepng_write_support;
//
/// \author Rachytski Siarhei
/// \date   2010 \n Last updated June 20, 2010

#include <stdio.h>
#include <string>
#include <boost/static_assert.hpp>
#include <boost/gil/gil_config.hpp>
#include <boost/gil/utilities.hpp>
#include <boost/gil/extension/io/io_error.hpp>
#include "lodepng_io_private.hpp"

namespace boost { namespace gil {

/// \ingroup LODEPNG_IO
/// \brief Returns the width and height of the PNG file at the specified location.
/// Throws std::ios_base::failure if the location does not correspond to a valid PNG file
inline point2<std::ptrdiff_t> lodepng_read_dimensions(ReaderPtr<Reader> & reader) {
    detail::lodepng_reader m(reader);
    return m.get_dimensions();
}

/// \ingroup LODEPNG_IO
/// \brief Returns the width and height of the PNG file at the specified location.
/// Throws std::ios_base::failure if the location does not correspond to a valid PNG file
//inline point2<std::ptrdiff_t> lodepng_read_dimensions(ReaderPtr<Reader> & reader) {
//    return lodepng_read_dimensions(reader);
//}

/// \ingroup LODEPNG_IO
/// \brief Determines whether the given view type is supported for reading
template <typename View>
struct lodepng_read_support {
    BOOST_STATIC_CONSTANT(bool,is_supported=
                          (detail::lodepng_read_support_private<typename channel_type<View>::type,
                                                            typename color_space_type<View>::type>::is_supported));
    BOOST_STATIC_CONSTANT(int,bit_depth=
                          (detail::lodepng_read_support_private<typename channel_type<View>::type,
                                                            typename color_space_type<View>::type>::bit_depth));
    BOOST_STATIC_CONSTANT(int,color_type=
                          (detail::lodepng_read_support_private<typename channel_type<View>::type,
                                                            typename color_space_type<View>::type>::color_type));
    BOOST_STATIC_CONSTANT(bool, value=is_supported);
};

/// \ingroup LODEPNG_IO
/// \brief Loads the image specified by the given png image file name into the given view.
/// Triggers a compile assert if the view color space and channel depth are not supported by the PNG library or by the I/O extension.
/// Throws std::ios_base::failure if the file is not a valid PNG file, or if its color space or channel depth are not
/// compatible with the ones specified by View, or if its dimensions don't match the ones of the view.
template <typename View>
inline void lodepng_read_view(ReaderPtr<Reader> & reader, const View& view) {
    BOOST_STATIC_ASSERT(lodepng_read_support<View>::is_supported);
    detail::lodepng_reader m(reader);
    m.apply(view);
}

/// \ingroup LODEPNG_IO
/// \brief Loads the image specified by the given png image file name into the given view.
template <typename View>
inline void lodepng_read_view(const std::string& filename,const View& view) {
    lodepng_read_view(filename.c_str(),view);
}

/// \ingroup LODEPNG_IO
/// \brief Allocates a new image whose dimensions are determined by the given png image file, and loads the pixels into it.
/// Triggers a compile assert if the image color space or channel depth are not supported by the PNG library or by the I/O extension.
/// Throws std::ios_base::failure if the file is not a valid PNG file, or if its color space or channel depth are not
/// compatible with the ones specified by Image
template <typename Image>
inline void lodepng_read_image(ReaderPtr<Reader> & reader, Image& im) {
    BOOST_STATIC_ASSERT(lodepng_read_support<typename Image::view_t>::is_supported);
    detail::lodepng_reader m(reader);
    m.read_image(im);
}

/// \ingroup LODEPNG_IO
/// \brief Allocates a new image whose dimensions are determined by the given png image file, and loads the pixels into it.
template <typename Image>
inline void lodepng_read_image(const std::string& filename,Image& im) {
    lodepng_read_image(filename.c_str(),im);
}

/// \ingroup LODEPNG_IO
/// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
/// Throws std::ios_base::failure if the file is not a valid PNG file, or if its dimensions don't match the ones of the view.
template <typename View,typename CC>
inline void lodepng_read_and_convert_view(const char* filename,const View& view,CC cc) {
    detail::lodepng_reader_color_convert<CC> m(filename,cc);
    m.apply(view);
}

/// \ingroup LODEPNG_IO
/// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
/// Throws std::ios_base::failure if the file is not a valid PNG file, or if its dimensions don't match the ones of the view.
template <typename View>
inline void lodepng_read_and_convert_view(ReaderPtr<Reader> & reader,const View& view) {
    detail::lodepng_reader_color_convert<default_color_converter> m(reader,default_color_converter());
    m.apply(view);
}

/// \ingroup LODEPNG_IO
/// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
template <typename View,typename CC>
inline void lodepng_read_and_convert_view(ReaderPtr<Reader> & reader,const View& view,CC cc) {
    detail::lodepng_reader_color_convert<CC> m(reader, cc);
    m.apply(view);
}

/// \ingroup LODEPNG_IO
/// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
//template <typename View>
//inline void lodepng_read_and_convert_view(ReaderPtr<Reader> & reader,const View& view) {
//    lodepng_read_and_convert_view(reader,view);
//}

/// \ingroup LODEPNG_IO
/// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
/// Throws std::ios_base::failure if the file is not a valid PNG file
template <typename Image,typename CC>
inline void lodepng_read_and_convert_image(ReaderPtr<Reader> & reader,Image& im,CC cc) {
    detail::lodepng_reader_color_convert<CC> m(reader,cc);
    m.read_image(im);
}

/// \ingroup LODEPNG_IO
/// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
/// Throws std::ios_base::failure if the file is not a valid PNG file
template <typename Image>
inline void lodepng_read_and_convert_image(ReaderPtr<Reader> & reader, Image& im) {
    detail::lodepng_reader_color_convert<default_color_converter> m(reader, default_color_converter());
    m.read_image(im);
}

/// \ingroup LODEPNG_IO
/// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
template <typename Image,typename CC>
inline void lodepng_read_and_convert_image(const std::string& filename,Image& im,CC cc) {
    lodepng_read_and_convert_image(filename.c_str(),im,cc);
}

/// \ingroup LODEPNG_IO
/// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
template <typename Image>
inline void lodepng_read_and_convert_image(const std::string& filename,Image& im) {
    lodepng_read_and_convert_image(filename.c_str(),im);
}

/// \ingroup LODEPNG_IO
/// \brief Determines whether the given view type is supported for writing
template <typename View>
struct lodepng_write_support {
    BOOST_STATIC_CONSTANT(bool,is_supported=
                          (detail::lodepng_write_support_private<typename channel_type<View>::type,
                                                             typename color_space_type<View>::type>::is_supported));
    BOOST_STATIC_CONSTANT(int,bit_depth=
                          (detail::lodepng_write_support_private<typename channel_type<View>::type,
                                                             typename color_space_type<View>::type>::bit_depth));
    BOOST_STATIC_CONSTANT(int,color_type=
                          (detail::lodepng_write_support_private<typename channel_type<View>::type,
                                                             typename color_space_type<View>::type>::color_type));
    BOOST_STATIC_CONSTANT(bool, value=is_supported);
};

/// \ingroup LODEPNG_IO
/// \brief Saves the view to a png file specified by the given png image file name.
/// Triggers a compile assert if the view color space and channel depth are not supported by the PNG library or by the I/O extension.
/// Throws std::ios_base::failure if it fails to create the file.
template <typename View>
inline void lodepng_write_view(WriterPtr<Writer> & writer,const View& view) {
    BOOST_STATIC_ASSERT(lodepng_write_support<View>::is_supported);
    detail::lodepng_writer m(writer);
    m.apply(view);
}

/// \ingroup LODEPNG_IO
/// \brief Saves the view to a png file specified by the given png image file name.
/*template <typename View>
inline void lodepng_write_view(const std::string& filename,const View& view) {
    lodepng_write_view(filename.c_str(),view);
}*/

} }  // namespace boost::gil

#endif