Adobe Systems, Inc.

tiff_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_TIFF_DYNAMIC_IO_H
00010 #define GIL_TIFF_DYNAMIC_IO_H
00011 
00015 //
00016 // We are currently providing the following functions:
00017 // template <typename IMAGES> void tiff_read_image(const char*,any_image<IMAGES>)
00018 // template <typename VIEWS> void tiff_write_view(const char*,any_image_view<VIEWS>)
00019 //
00023 
00024 #include <string>
00025 #include <boost/mpl/bool.hpp>
00026 #include "../../core/gil_config.hpp"
00027 #include "../dynamic_image/any_image.hpp"
00028 #include "io_error.hpp"
00029 #include "tiff_io.hpp"
00030 #include "dynamic_io.hpp"
00031 
00032 ADOBE_GIL_NAMESPACE_BEGIN
00033 
00034 namespace detail {
00035 
00036 struct tiff_write_is_supported {
00037     template<typename VIEW> struct apply
00038         : public boost::mpl::bool_<tiff_write_support<VIEW>::is_supported> {};
00039 };
00040 
00041 class tiff_writer_dynamic : public tiff_writer {
00042 public:
00043     typedef void result_type;
00044     tiff_writer_dynamic(const char* filename) : tiff_writer(filename) {}
00045 
00046     template <typename VIEWS>
00047     void write_view(const any_image_view<VIEWS>& runtime_view) {
00048         dynamic_io_fnobj<tiff_write_is_supported, tiff_writer> op(this);
00049         apply_operation(runtime_view,op);
00050     }
00051 };
00052 
00053 class tiff_type_format_checker {
00054     int _bit_depth;
00055     int _color_type;
00056 public:
00057     tiff_type_format_checker(int bit_depth_in,int color_type_in) :
00058         _bit_depth(bit_depth_in),_color_type(color_type_in) {}
00059     template <typename IMAGE>
00060     bool apply() {
00061         return tiff_read_support<typename IMAGE::view_t>::bit_depth==_bit_depth &&
00062                tiff_read_support<typename IMAGE::view_t>::color_type==_color_type;
00063     }
00064 };
00065 
00066 struct tiff_read_is_supported {
00067     template<typename VIEW> struct apply
00068         : public boost::mpl::bool_<tiff_read_support<VIEW>::is_supported> {};
00069 };
00070 
00071 class tiff_reader_dynamic : public tiff_reader {
00072 public:
00073     tiff_reader_dynamic(const char* filename) : tiff_reader(filename) {}
00074 
00075     template <typename IMAGES>
00076     void read_image(any_image<IMAGES>& im) {
00077         int width,height;
00078         unsigned short bps,photometric;
00079         TIFFGetField(_tp,TIFFTAG_IMAGEWIDTH,&width);
00080         TIFFGetField(_tp,TIFFTAG_IMAGELENGTH,&height);
00081         TIFFGetField(_tp,TIFFTAG_BITSPERSAMPLE,&bps);
00082         TIFFGetField(_tp,TIFFTAG_PHOTOMETRIC,&photometric);
00083         if (!construct_matched(im,tiff_type_format_checker(bps,photometric))) {
00084             io_error("tiff_reader_dynamic::read_image(): no matching image type between those of the given any_image and that of the file");
00085         } else {
00086             resize_clobber_image(im,point2<int>(width,height));
00087             dynamic_io_fnobj<tiff_read_is_supported, tiff_reader> op(this);
00088             apply_operation(view(im),op);
00089         }
00090     }
00091 };
00092 
00093 } // namespace detail
00094 
00099 template <typename IMAGES>
00100 inline void tiff_read_image(const char* filename,any_image<IMAGES>& im) {
00101     detail::tiff_reader_dynamic m(filename);
00102     m.read_image(im);
00103 }
00104 
00107 template <typename IMAGES>
00108 inline void tiff_read_image(const std::string& filename,any_image<IMAGES>& im) {
00109     tiff_read_image(filename.c_str(),im);
00110 }
00111 
00116 template <typename VIEWS>
00117 inline void tiff_write_view(const char* filename,const any_image_view<VIEWS>& runtime_view) {
00118     detail::tiff_writer_dynamic m(filename);
00119     m.write_view(runtime_view);
00120 }
00121 
00124 template <typename VIEWS>
00125 inline void tiff_write_view(const std::string& filename,const any_image_view<VIEWS>& runtime_view) {
00126     tiff_write_view(filename.c_str(),runtime_view);
00127 }
00128 
00129 ADOBE_GIL_NAMESPACE_END
00130 
00131 #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