Adobe Systems, Inc.

jpeg_dynamic_io.hpp

Go to the documentation of this file.
00001 /*
00002   Copyright 2005-2006 Adobe Systems Incorporated
00003   Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004   or a copy at http://opensource.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef GIL_JPEG_DYNAMIC_IO_H
00010 #define GIL_JPEG_DYNAMIC_IO_H
00011 
00015 //
00019 
00020 #include <stdio.h>
00021 #include <string>
00022 #include <boost/mpl/bool.hpp>
00023 #include <boost/shared_ptr.hpp>
00024 #include "../../core/gil_config.hpp"
00025 #include "../dynamic_image/any_image.hpp"
00026 #include "io_error.hpp"
00027 
00028 #include "jpeg_io.hpp"
00029 #include "jpeg_io_private.hpp"
00030 #include "dynamic_io.hpp"
00031 
00032 ADOBE_GIL_NAMESPACE_BEGIN
00033 
00034 namespace detail {
00035 
00036 struct jpeg_write_is_supported {
00037     template<typename VIEW> struct apply
00038         : public boost::mpl::bool_<jpeg_write_support<VIEW>::is_supported> {};
00039 };
00040 
00041 class jpeg_writer_dynamic : public jpeg_writer {
00042     int _quality;
00043 public:    
00044     jpeg_writer_dynamic(FILE* file,           int quality=100) : jpeg_writer(file)    , _quality(quality) {}
00045     jpeg_writer_dynamic(const char* filename, int quality=100) : jpeg_writer(filename), _quality(quality) {}
00046 
00047     template <typename VIEWS>
00048     void write_view(const any_image_view<VIEWS>& runtime_view) {
00049         dynamic_io_fnobj<jpeg_write_is_supported, jpeg_writer> op(this);
00050         apply_operation(runtime_view,op);
00051     }
00052 };
00053 
00054 class jpeg_type_format_checker {
00055     J_COLOR_SPACE _color_type;
00056 public:
00057     jpeg_type_format_checker(J_COLOR_SPACE color_type_in) :
00058         _color_type(color_type_in) {}
00059     template <typename IMAGE>
00060     bool apply() {
00061         return jpeg_read_support<typename IMAGE::view_t>::color_type==_color_type;
00062     }
00063 };
00064 
00065 struct jpeg_read_is_supported {
00066     template<typename VIEW> struct apply
00067         : public boost::mpl::bool_<jpeg_read_support<VIEW>::is_supported> {};
00068 };
00069 
00070 class jpeg_reader_dynamic : public jpeg_reader {
00071 public:
00072     jpeg_reader_dynamic(FILE* file)           : jpeg_reader(file)    {}
00073     jpeg_reader_dynamic(const char* filename) : jpeg_reader(filename){}
00074         
00075     template <typename IMAGES>
00076     void read_image(any_image<IMAGES>& im) {
00077         if (!construct_matched(im,detail::jpeg_type_format_checker(_cinfo.out_color_space))) {
00078             io_error("jpeg_reader_dynamic::read_image(): no matching image type between those of the given any_image and that of the file");
00079         } else {
00080             resize_clobber_image(im,get_dimensions());
00081             dynamic_io_fnobj<jpeg_read_is_supported, jpeg_reader> op(this);
00082             apply_operation(view(im),op);
00083         }
00084     }
00085 };
00086 
00087 } // namespace detail
00088 
00089 
00094 template <typename IMAGES>
00095 inline void jpeg_read_image(const char* filename,any_image<IMAGES>& im) {
00096     detail::jpeg_reader_dynamic m(filename);
00097     m.read_image(im);
00098 }
00099 
00102 template <typename IMAGES>
00103 inline void jpeg_read_image(const std::string& filename,any_image<IMAGES>& im) {
00104     jpeg_read_image(filename.c_str(),im);
00105 }
00106 
00111 template <typename VIEWS>
00112 inline void jpeg_write_view(const char* filename,const any_image_view<VIEWS>& runtime_view) {
00113     detail::jpeg_writer_dynamic m(filename);
00114     m.write_view(runtime_view);
00115 }
00116 
00119 template <typename VIEWS>
00120 inline void jpeg_write_view(const std::string& filename,const any_image_view<VIEWS>& runtime_view) {
00121     jpeg_write_view(filename.c_str(),runtime_view);
00122 }
00123 
00124 ADOBE_GIL_NAMESPACE_END
00125 
00126 #endif

Copyright © 2006 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google