annotate DEPENDENCIES/generic/include/boost/gil/extension/io/png_io.hpp @ 133:4acb5d8d80b6 tip

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