Modules | Alphabetical List | Class List | Directories | File List | File Members | GIL Home Page # png_io.hpp Go to the documentation of this file.
    00001 /*
    00002     Copyright 2005-2007 Adobe Systems Incorporated
    00003
    00004     Use, modification and distribution are subject to the Boost Software License,
    00005     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    00006     http://www.boost.org/LICENSE_1_0.txt).
    00007
    00008     See http://opensource.adobe.com/gil for most recent version including documentation.
    00009 */
    00010
    00011 /*************************************************************************************************/
    00012
    00013 #ifndef GIL_PNG_IO_H
    00014 #define GIL_PNG_IO_H
    00015
    00019 //
    00020 // We are currently providing the following functions:
    00021 // point2<std::ptrdiff_t>    png_read_dimensions(const char*)
    00022 // template <typename View>  void png_read_view(const char*,const View&)
    00023 // template <typename View>  void png_read_image(const char*,image<View>&)
    00024 // template <typename View>  void png_write_view(const char*,const View&)
    00025 // template <typename View>  struct png_read_support;
    00026 // template <typename View>  struct png_write_support;
    00027 //
    00031
    00032 #include <stdio.h>
    00033 #include <string>
    00034 extern "C" {
    00035 #include "png.h"
    00036 }
    00037 #include <boost/static_assert.hpp>
    00038 #include "../../gil_config.hpp"
    00039 #include "../../utilities.hpp"
    00040 #include "io_error.hpp"
    00041 #include "png_io_private.hpp"
    00042
    00043 namespace boost { namespace gil {
    00044
    00048 inline point2<std::ptrdiff_t> png_read_dimensions(const char *filename) {
    00049     detail::png_reader m(filename);
    00050     return m.get_dimensions();
    00051 }
    00052
    00056 inline point2<std::ptrdiff_t> png_read_dimensions(const std::string& filename) {
    00057     return png_read_dimensions(filename.c_str());
    00058 }
    00059
    00062 template <typename View>
    00063 struct png_read_support {
    00064     BOOST_STATIC_CONSTANT(bool,is_supported=
    00065                           (detail::png_read_support_private<typename channel_type<View>::type,
    00066                                                             typename color_space_type<View>::type>::is_supported));
    00067     BOOST_STATIC_CONSTANT(int,bit_depth=
    00068                           (detail::png_read_support_private<typename channel_type<View>::type,
    00069                                                             typename color_space_type<View>::type>::bit_depth));
    00070     BOOST_STATIC_CONSTANT(int,color_type=
    00071                           (detail::png_read_support_private<typename channel_type<View>::type,
    00072                                                             typename color_space_type<View>::type>::color_type));
    00073     BOOST_STATIC_CONSTANT(bool, value=is_supported);
    00074 };
    00075
    00081 template <typename View>
    00082 inline void png_read_view(const char* filename,const View& view) {
    00083     BOOST_STATIC_ASSERT(png_read_support<View>::is_supported);
    00084     detail::png_reader m(filename);
    00085     m.apply(view);
    00086 }
    00087
    00090 template <typename View>
    00091 inline void png_read_view(const std::string& filename,const View& view) {
    00092     png_read_view(filename.c_str(),view);
    00093 }
    00094
    00100 template <typename Image>
    00101 inline void png_read_image(const char* filename,Image& im) {
    00102     BOOST_STATIC_ASSERT(png_read_support<typename Image::view_t>::is_supported);
    00103     detail::png_reader m(filename);
    00104     m.read_image(im);
    00105 }
    00106
    00109 template <typename Image>
    00110 inline void png_read_image(const std::string& filename,Image& im) {
    00111     png_read_image(filename.c_str(),im);
    00112 }
    00113
    00117 template <typename View,typename CC>
    00118 inline void png_read_and_convert_view(const char* filename,const View& view,CC cc) {
    00119     detail::png_reader_color_convert<CC> m(filename,cc);
    00120     m.apply(view);
    00121 }
    00122
    00126 template <typename View>
    00127 inline void png_read_and_convert_view(const char* filename,const View& view) {
    00128     detail::png_reader_color_convert<default_color_converter> m(filename,default_color_converter());
    00129     m.apply(view);
    00130 }
    00131
    00134 template <typename View,typename CC>
    00135 inline void png_read_and_convert_view(const std::string& filename,const View& view,CC cc) {
    00136     png_read_and_convert_view(filename.c_str(),view,cc);
    00137 }
    00138
    00141 template <typename View>
    00142 inline void png_read_and_convert_view(const std::string& filename,const View& view) {
    00143     png_read_and_convert_view(filename.c_str(),view);
    00144 }
    00145
    00149 template <typename Image,typename CC>
    00150 inline void png_read_and_convert_image(const char* filename,Image& im,CC cc) {
    00151     detail::png_reader_color_convert<CC> m(filename,cc);
    00152     m.read_image(im);
    00153 }
    00154
    00158 template <typename Image>
    00159 inline void png_read_and_convert_image(const char* filename,Image& im) {
    00160     detail::png_reader_color_convert<default_color_converter> m(filename,default_color_converter());
    00161     m.read_image(im);
    00162 }
    00163
    00166 template <typename Image,typename CC>
    00167 inline void png_read_and_convert_image(const std::string& filename,Image& im,CC cc) {
    00168     png_read_and_convert_image(filename.c_str(),im,cc);
    00169 }
    00170
    00173 template <typename Image>
    00174 inline void png_read_and_convert_image(const std::string& filename,Image& im) {
    00175     png_read_and_convert_image(filename.c_str(),im);
    00176 }
    00177
    00180 template <typename View>
    00181 struct png_write_support {
    00182     BOOST_STATIC_CONSTANT(bool,is_supported=
    00183                           (detail::png_write_support_private<typename channel_type<View>::type,
    00184                                                              typename color_space_type<View>::type>::is_supported));
    00185     BOOST_STATIC_CONSTANT(int,bit_depth=
    00186                           (detail::png_write_support_private<typename channel_type<View>::type,
    00187                                                              typename color_space_type<View>::type>::bit_depth));
    00188     BOOST_STATIC_CONSTANT(int,color_type=
    00189                           (detail::png_write_support_private<typename channel_type<View>::type,
    00190                                                              typename color_space_type<View>::type>::color_type));
    00191     BOOST_STATIC_CONSTANT(bool, value=is_supported);
    00192 };
    00193
    00198 template <typename View>
    00199 inline void png_write_view(const char* filename,const View& view) {
    00200     BOOST_STATIC_ASSERT(png_write_support<View>::is_supported);
    00201     detail::png_writer m(filename);
    00202     m.apply(view);
    00203 }
    00204
    00207 template <typename View>
    00208 inline void png_write_view(const std::string& filename,const View& view) {
    00209     png_write_view(filename.c_str(),view);
    00210 }
    00211
    00212 } }  // namespace boost::gil
    00213
    00214 #endif