1 //
2 // Copyright 2007-2008 Christian Henning
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #ifndef BOOST_GIL_EXTENSION_IO_PNG_OLD_HPP
9 #define BOOST_GIL_EXTENSION_IO_PNG_OLD_HPP
10
11 #include <boost/gil/extension/io/png.hpp>
12
13 namespace boost { namespace gil {
14
15 /// \ingroup PNG_IO
16 /// \brief Returns the width and height of the PNG file at the specified location.
17 /// Throws std::ios_base::failure if the location does not correspond to a valid PNG file
18 template<typename String>
png_read_dimensions(String const & filename)19 inline point_t png_read_dimensions(String const& filename)
20 {
21 using backend_t = typename get_reader_backend<String, png_tag>::type;
22 backend_t backend = read_image_info(filename, png_tag());
23 return { static_cast<std::ptrdiff_t>(backend._info._width), static_cast<std::ptrdiff_t>(backend._info._height) };
24 }
25
26 /// \ingroup PNG_IO
27 /// \brief Loads the image specified by the given png image file name into the given view.
28 /// 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.
29 /// Throws std::ios_base::failure if the file is not a valid PNG file, or if its color space or channel depth are not
30 /// compatible with the ones specified by View, or if its dimensions don't match the ones of the view.
31 template< typename String
32 , typename View
33 >
34 inline
png_read_view(const String & filename,const View & view)35 void png_read_view( const String& filename
36 , const View& view
37 )
38 {
39 read_view( filename
40 , view
41 , png_tag()
42 );
43 }
44
45 /// \ingroup PNG_IO
46 /// \brief Allocates a new image whose dimensions are determined by the given png image file, and loads the pixels into it.
47 /// 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.
48 /// Throws std::ios_base::failure if the file is not a valid PNG file, or if its color space or channel depth are not
49 /// compatible with the ones specified by Image
50 template< typename String
51 , typename Image
52 >
53 inline
png_read_image(const String & filename,Image & img)54 void png_read_image( const String& filename
55 , Image& img
56 )
57 {
58 read_image( filename
59 , img
60 , png_tag()
61 );
62 }
63
64 /// \ingroup PNG_IO
65 /// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
66 /// 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.
67 template< typename String
68 , typename View
69 , typename CC
70 >
71 inline
png_read_and_convert_view(const String & filename,const View & view,CC cc)72 void png_read_and_convert_view( const String& filename
73 , const View& view
74 , CC cc
75 )
76 {
77 read_and_convert_view( filename
78 , view
79 , cc
80 , png_tag()
81 );
82 }
83
84 /// \ingroup PNG_IO
85 /// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
86 /// 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.
87 template< typename String
88 , typename View
89 >
90 inline
png_read_and_convert_view(const String & filename,const View & view)91 void png_read_and_convert_view( const String& filename
92 , const View& view
93 )
94 {
95 read_and_convert_view( filename
96 , view
97 , png_tag()
98 );
99 }
100
101 /// \ingroup PNG_IO
102 /// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
103 /// Throws std::ios_base::failure if the file is not a valid PNG file
104 template< typename String
105 , typename Image
106 , typename CC
107 >
108 inline
png_read_and_convert_image(const String & filename,Image & img,CC cc)109 void png_read_and_convert_image( const String& filename
110 , Image& img
111 , CC cc
112 )
113 {
114 read_and_convert_image( filename
115 , img
116 , cc
117 , png_tag()
118 );
119 }
120
121 /// \ingroup PNG_IO
122 /// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
123 /// Throws std::ios_base::failure if the file is not a valid PNG file
124 template< typename String
125 , typename Image
126 >
127 inline
png_read_and_convert_image(const String filename,Image & img)128 void png_read_and_convert_image( const String filename
129 , Image& img
130 )
131 {
132 read_and_convert_image( filename
133 , img
134 , png_tag()
135 );
136 }
137
138 /// \ingroup PNG_IO
139 /// \brief Saves the view to a png file specified by the given png image file name.
140 /// 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.
141 /// Throws std::ios_base::failure if it fails to create the file.
142 template< typename String
143 , typename View
144 >
145 inline
png_write_view(const String & filename,const View & view)146 void png_write_view( const String& filename
147 , const View& view
148 )
149 {
150 write_view( filename
151 , view
152 , png_tag()
153 );
154 }
155
156 } // namespace gil
157 } // namespace boost
158
159 #endif
160