Modules | Alphabetical List | Class List | Directories | File List | GIL Home Page

# jpeg_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_JPEG_IO_H
    00014 #define GIL_JPEG_IO_H
    00015
    00022
    00023 #include <cstdio>
    00024 #include <algorithm>
    00025 #include <string>
    00026 #include <boost/static_assert.hpp>
    00027 #include <boost/shared_ptr.hpp>
    00028 extern "C" {
    00029 #include <jpeglib.h>
    00030 }
    00031 #include "io_error.hpp"
    00032 #include "jpeg_io_private.hpp"
    00033
    00034 namespace boost { namespace gil {
    00035
    00038 template <typename View>
    00039 struct jpeg_read_support {
    00040     BOOST_STATIC_CONSTANT(bool,is_supported=
    00041                           (detail::jpeg_read_support_private<typename channel_type<View>::type,
    00042                                                              typename color_space_type<View>::type>::is_supported));
    00043     BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=
    00044                           (detail::jpeg_read_support_private<typename channel_type<View>::type,
    00045                                                              typename color_space_type<View>::type>::color_type));
    00046     BOOST_STATIC_CONSTANT(bool, value=is_supported);
    00047 };
    00048
    00052 inline point2<std::ptrdiff_t> jpeg_read_dimensions(const char* filename) {
    00053     detail::jpeg_reader m(filename);
    00054     return m.get_dimensions();
    00055 }
    00056
    00060 inline point2<std::ptrdiff_t> jpeg_read_dimensions(const std::string& filename) {
    00061     return jpeg_read_dimensions(filename.c_str());
    00062 }
    00063
    00069 template <typename View>
    00070 inline void jpeg_read_view(const char* filename,const View& view) {
    00071     BOOST_STATIC_ASSERT(jpeg_read_support<View>::is_supported);
    00072
    00073     detail::jpeg_reader m(filename);
    00074     m.apply(view);
    00075 }
    00076
    00079 template <typename View>
    00080 inline void jpeg_read_view(const std::string& filename,const View& view) {
    00081     jpeg_read_view(filename.c_str(),view);
    00082 }
    00083
    00089 template <typename Image>
    00090 inline void jpeg_read_image(const char* filename,Image& im) {
    00091     BOOST_STATIC_ASSERT(jpeg_read_support<typename Image::view_t>::is_supported);
    00092
    00093     detail::jpeg_reader m(filename);
    00094     m.read_image(im);
    00095 }
    00096
    00099 template <typename Image>
    00100 inline void jpeg_read_image(const std::string& filename,Image& im) {
    00101     jpeg_read_image(filename.c_str(),im);
    00102 }
    00103
    00107 template <typename View,typename CC>
    00108 inline void jpeg_read_and_convert_view(const char* filename,const View& view,CC cc) {
    00109     detail::jpeg_reader_color_convert<CC> m(filename,cc);
    00110     m.apply(view);
    00111 }
    00112
    00116 template <typename View>
    00117 inline void jpeg_read_and_convert_view(const char* filename,const View& view) {
    00118     detail::jpeg_reader_color_convert<default_color_converter> m(filename,default_color_converter());
    00119     m.apply(view);
    00120 }
    00121
    00124 template <typename View,typename CC>
    00125 inline void jpeg_read_and_convert_view(const std::string& filename,const View& view,CC cc) {
    00126     jpeg_read_and_convert_view(filename.c_str(),view);
    00127 }
    00128
    00131 template <typename View>
    00132 inline void jpeg_read_and_convert_view(const std::string& filename,const View& view) {
    00133     jpeg_read_and_convert_view(filename.c_str(),view);
    00134 }
    00135
    00139 template <typename Image,typename CC>
    00140 inline void jpeg_read_and_convert_image(const char* filename,Image& im,CC cc) {
    00141     detail::jpeg_reader_color_convert<CC> m(filename,cc);
    00142     m.read_image(im);
    00143 }
    00144
    00148 template <typename Image>
    00149 inline void jpeg_read_and_convert_image(const char* filename,Image& im) {
    00150     detail::jpeg_reader_color_convert<default_color_converter> m(filename,default_color_converter());
    00151     m.read_image(im);
    00152 }
    00153
    00156 template <typename Image,typename CC>
    00157 inline void jpeg_read_and_convert_image(const std::string& filename,Image& im,CC cc) {
    00158     jpeg_read_and_convert_image(filename.c_str(),im);
    00159 }
    00160
    00163 template <typename Image>
    00164 inline void jpeg_read_and_convert_image(const std::string& filename,Image& im) {
    00165     jpeg_read_and_convert_image(filename.c_str(),im);
    00166 }
    00167
    00170 template <typename View>
    00171 struct jpeg_write_support {
    00172     BOOST_STATIC_CONSTANT(bool,is_supported=
    00173                           (detail::jpeg_write_support_private<typename channel_type<View>::type,
    00174                                                               typename color_space_type<View>::type>::is_supported));
    00175     BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=
    00176                           (detail::jpeg_write_support_private<typename channel_type<View>::type,
    00177                                                              typename color_space_type<View>::type>::color_type));
    00178     BOOST_STATIC_CONSTANT(bool, value=is_supported);
    00179 };
    00180
    00185 template <typename View>
    00186 inline void jpeg_write_view(const char* filename,const View& view,int quality=100) {
    00187     BOOST_STATIC_ASSERT(jpeg_write_support<View>::is_supported);
    00188
    00189     detail::jpeg_writer m(filename);
    00190     m.apply(view,quality);
    00191 }
    00192
    00195 template <typename View>
    00196 inline void jpeg_write_view(const std::string& filename,const View& view,int quality=100) {
    00197     jpeg_write_view(filename.c_str(),view,quality);
    00198 }
    00199
    00200 } }  // namespace boost::gil
    00201
    00202 #endif