]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/gil/include/boost/gil/extension/io/png_io.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / gil / include / boost / gil / extension / io / png_io.hpp
CommitLineData
7c673cae
FG
1/*
2 Copyright 2005-2007 Adobe Systems Incorporated
3
4 Use, modification and distribution are subject to the Boost Software License,
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt).
7
8 See http://opensource.adobe.com/gil for most recent version including documentation.
9*/
10
11/*************************************************************************************************/
12
13#ifndef GIL_PNG_IO_H
14#define GIL_PNG_IO_H
15
16/// \file
17/// \brief Support for reading and writing PNG files
18/// Requires libpng and zlib!
19//
20// We are currently providing the following functions:
21// point2<std::ptrdiff_t> png_read_dimensions(const char*)
22// template <typename View> void png_read_view(const char*,const View&)
23// template <typename View> void png_read_image(const char*,image<View>&)
24// template <typename View> void png_write_view(const char*,const View&)
25// template <typename View> struct png_read_support;
26// template <typename View> struct png_write_support;
27//
28/// \author Hailin Jin and Lubomir Bourdev \n
29/// Adobe Systems Incorporated
30/// \date 2005-2007 \n Last updated September 24, 2006
31
32#include <stdio.h>
33#include <string>
34extern "C" {
35#include "png.h"
36}
37#include <boost/static_assert.hpp>
38#include "../../gil_config.hpp"
39#include "../../utilities.hpp"
40#include "io_error.hpp"
41#include "png_io_private.hpp"
42
43namespace boost { namespace gil {
44
45/// \ingroup PNG_IO
46/// \brief Returns the width and height of the PNG file at the specified location.
47/// Throws std::ios_base::failure if the location does not correspond to a valid PNG file
48inline point2<std::ptrdiff_t> png_read_dimensions(const char *filename) {
49 detail::png_reader m(filename);
50 return m.get_dimensions();
51}
52
53/// \ingroup PNG_IO
54/// \brief Returns the width and height of the PNG file at the specified location.
55/// Throws std::ios_base::failure if the location does not correspond to a valid PNG file
56inline point2<std::ptrdiff_t> png_read_dimensions(const std::string& filename) {
57 return png_read_dimensions(filename.c_str());
58}
59
60/// \ingroup PNG_IO
61/// \brief Determines whether the given view type is supported for reading
62template <typename View>
63struct png_read_support {
64 BOOST_STATIC_CONSTANT(bool,is_supported=
65 (detail::png_read_support_private<typename channel_type<View>::type,
66 typename color_space_type<View>::type>::is_supported));
67 BOOST_STATIC_CONSTANT(int,bit_depth=
68 (detail::png_read_support_private<typename channel_type<View>::type,
69 typename color_space_type<View>::type>::bit_depth));
70 BOOST_STATIC_CONSTANT(int,color_type=
71 (detail::png_read_support_private<typename channel_type<View>::type,
72 typename color_space_type<View>::type>::color_type));
73 BOOST_STATIC_CONSTANT(bool, value=is_supported);
74};
75
76/// \ingroup PNG_IO
77/// \brief Loads the image specified by the given png image file name into the given view.
78/// 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.
79/// Throws std::ios_base::failure if the file is not a valid PNG file, or if its color space or channel depth are not
80/// compatible with the ones specified by View, or if its dimensions don't match the ones of the view.
81template <typename View>
82inline void png_read_view(const char* filename,const View& view) {
83 BOOST_STATIC_ASSERT(png_read_support<View>::is_supported);
84 detail::png_reader m(filename);
85 m.apply(view);
86}
87
88/// \ingroup PNG_IO
89/// \brief Loads the image specified by the given png image file name into the given view.
90template <typename View>
91inline void png_read_view(const std::string& filename,const View& view) {
92 png_read_view(filename.c_str(),view);
93}
94
95/// \ingroup PNG_IO
96/// \brief Allocates a new image whose dimensions are determined by the given png image file, and loads the pixels into it.
97/// 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.
98/// Throws std::ios_base::failure if the file is not a valid PNG file, or if its color space or channel depth are not
99/// compatible with the ones specified by Image
100template <typename Image>
101inline void png_read_image(const char* filename,Image& im) {
102 BOOST_STATIC_ASSERT(png_read_support<typename Image::view_t>::is_supported);
103 detail::png_reader m(filename);
104 m.read_image(im);
105}
106
107/// \ingroup PNG_IO
108/// \brief Allocates a new image whose dimensions are determined by the given png image file, and loads the pixels into it.
109template <typename Image>
110inline void png_read_image(const std::string& filename,Image& im) {
111 png_read_image(filename.c_str(),im);
112}
113
114/// \ingroup PNG_IO
115/// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
116/// 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.
117template <typename View,typename CC>
118inline void png_read_and_convert_view(const char* filename,const View& view,CC cc) {
119 detail::png_reader_color_convert<CC> m(filename,cc);
120 m.apply(view);
121}
122
123/// \ingroup PNG_IO
124/// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
125/// 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.
126template <typename View>
127inline void png_read_and_convert_view(const char* filename,const View& view) {
128 detail::png_reader_color_convert<default_color_converter> m(filename,default_color_converter());
129 m.apply(view);
130}
131
132/// \ingroup PNG_IO
133/// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
134template <typename View,typename CC>
135inline void png_read_and_convert_view(const std::string& filename,const View& view,CC cc) {
136 png_read_and_convert_view(filename.c_str(),view,cc);
137}
138
139/// \ingroup PNG_IO
140/// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
141template <typename View>
142inline void png_read_and_convert_view(const std::string& filename,const View& view) {
143 png_read_and_convert_view(filename.c_str(),view);
144}
145
146/// \ingroup PNG_IO
147/// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
148/// Throws std::ios_base::failure if the file is not a valid PNG file
149template <typename Image,typename CC>
150inline void png_read_and_convert_image(const char* filename,Image& im,CC cc) {
151 detail::png_reader_color_convert<CC> m(filename,cc);
152 m.read_image(im);
153}
154
155/// \ingroup PNG_IO
156/// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
157/// Throws std::ios_base::failure if the file is not a valid PNG file
158template <typename Image>
159inline void png_read_and_convert_image(const char* filename,Image& im) {
160 detail::png_reader_color_convert<default_color_converter> m(filename,default_color_converter());
161 m.read_image(im);
162}
163
164/// \ingroup PNG_IO
165/// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
166template <typename Image,typename CC>
167inline void png_read_and_convert_image(const std::string& filename,Image& im,CC cc) {
168 png_read_and_convert_image(filename.c_str(),im,cc);
169}
170
171/// \ingroup PNG_IO
172/// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
173template <typename Image>
174inline void png_read_and_convert_image(const std::string& filename,Image& im) {
175 png_read_and_convert_image(filename.c_str(),im);
176}
177
178/// \ingroup PNG_IO
179/// \brief Determines whether the given view type is supported for writing
180template <typename View>
181struct png_write_support {
182 BOOST_STATIC_CONSTANT(bool,is_supported=
183 (detail::png_write_support_private<typename channel_type<View>::type,
184 typename color_space_type<View>::type>::is_supported));
185 BOOST_STATIC_CONSTANT(int,bit_depth=
186 (detail::png_write_support_private<typename channel_type<View>::type,
187 typename color_space_type<View>::type>::bit_depth));
188 BOOST_STATIC_CONSTANT(int,color_type=
189 (detail::png_write_support_private<typename channel_type<View>::type,
190 typename color_space_type<View>::type>::color_type));
191 BOOST_STATIC_CONSTANT(bool, value=is_supported);
192};
193
194/// \ingroup PNG_IO
195/// \brief Saves the view to a png file specified by the given png image file name.
196/// 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.
197/// Throws std::ios_base::failure if it fails to create the file.
198template <typename View>
199inline void png_write_view(const char* filename,const View& view) {
200 BOOST_STATIC_ASSERT(png_write_support<View>::is_supported);
201 detail::png_writer m(filename);
202 m.apply(view);
203}
204
205/// \ingroup PNG_IO
206/// \brief Saves the view to a png file specified by the given png image file name.
207template <typename View>
208inline void png_write_view(const std::string& filename,const View& view) {
209 png_write_view(filename.c_str(),view);
210}
211
212} } // namespace boost::gil
213
214#endif