annotate DEPENDENCIES/generic/include/boost/gil/extension/io/tiff_dynamic_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_TIFF_DYNAMIC_IO_H
Chris@16 14 #define GIL_TIFF_DYNAMIC_IO_H
Chris@16 15
Chris@16 16 /// \file
Chris@16 17 /// \brief Support for reading and writing TIFF files
Chris@16 18 /// Requires libtiff!
Chris@16 19 /// \author Hailin Jin and Lubomir Bourdev \n
Chris@16 20 /// Adobe Systems Incorporated
Chris@16 21 /// \date 2005-2007 \n Last updated June 10, 2006
Chris@16 22 //
Chris@16 23 // We are currently providing the following functions:
Chris@16 24 // template <typename Images> void tiff_read_image(const char*,any_image<Images>)
Chris@16 25 // template <typename Views> void tiff_write_view(const char*,any_image_view<Views>)
Chris@16 26 //
Chris@16 27
Chris@16 28 #include <string>
Chris@16 29 #include <boost/mpl/bool.hpp>
Chris@16 30 #include "../dynamic_image/dynamic_image_all.hpp"
Chris@16 31 #include "io_error.hpp"
Chris@16 32 #include "tiff_io.hpp"
Chris@16 33 #include "dynamic_io.hpp"
Chris@16 34
Chris@16 35 namespace boost { namespace gil {
Chris@16 36
Chris@16 37 namespace detail {
Chris@16 38
Chris@16 39 struct tiff_write_is_supported {
Chris@16 40 template<typename View> struct apply
Chris@16 41 : public mpl::bool_<tiff_write_support<View>::is_supported> {};
Chris@16 42 };
Chris@16 43
Chris@16 44 class tiff_writer_dynamic : public tiff_writer {
Chris@16 45 public:
Chris@16 46 typedef void result_type;
Chris@16 47 tiff_writer_dynamic(const char* filename) : tiff_writer(filename) {}
Chris@16 48
Chris@16 49 template <typename Views>
Chris@16 50 void write_view(const any_image_view<Views>& runtime_view) {
Chris@16 51 dynamic_io_fnobj<tiff_write_is_supported, tiff_writer> op(this);
Chris@16 52 apply_operation(runtime_view,op);
Chris@16 53 }
Chris@16 54 };
Chris@16 55
Chris@16 56 class tiff_type_format_checker {
Chris@16 57 int _bit_depth;
Chris@16 58 int _color_type;
Chris@16 59 public:
Chris@16 60 tiff_type_format_checker(int bit_depth_in,int color_type_in) :
Chris@16 61 _bit_depth(bit_depth_in),_color_type(color_type_in) {}
Chris@16 62 template <typename Image>
Chris@16 63 bool apply() {
Chris@16 64 return tiff_read_support<typename Image::view_t>::bit_depth==_bit_depth &&
Chris@16 65 tiff_read_support<typename Image::view_t>::color_type==_color_type;
Chris@16 66 }
Chris@16 67 };
Chris@16 68
Chris@16 69 struct tiff_read_is_supported {
Chris@16 70 template<typename View> struct apply
Chris@16 71 : public mpl::bool_<tiff_read_support<View>::is_supported> {};
Chris@16 72 };
Chris@16 73
Chris@16 74 class tiff_reader_dynamic : public tiff_reader {
Chris@16 75 public:
Chris@16 76 tiff_reader_dynamic(const char* filename) : tiff_reader(filename) {}
Chris@16 77
Chris@16 78 template <typename Images>
Chris@16 79 void read_image(any_image<Images>& im) {
Chris@16 80 int width,height;
Chris@16 81 unsigned short bps,photometric;
Chris@16 82 TIFFGetField(_tp,TIFFTAG_IMAGEWIDTH,&width);
Chris@16 83 TIFFGetField(_tp,TIFFTAG_IMAGELENGTH,&height);
Chris@16 84 TIFFGetField(_tp,TIFFTAG_BITSPERSAMPLE,&bps);
Chris@16 85 TIFFGetField(_tp,TIFFTAG_PHOTOMETRIC,&photometric);
Chris@16 86 if (!construct_matched(im,tiff_type_format_checker(bps,photometric))) {
Chris@16 87 io_error("tiff_reader_dynamic::read_image(): no matching image type between those of the given any_image and that of the file");
Chris@16 88 } else {
Chris@16 89 im.recreate(width,height);
Chris@16 90 dynamic_io_fnobj<tiff_read_is_supported, tiff_reader> op(this);
Chris@16 91 apply_operation(view(im),op);
Chris@16 92 }
Chris@16 93 }
Chris@16 94 };
Chris@16 95
Chris@16 96 } // namespace detail
Chris@16 97
Chris@16 98 /// \ingroup TIFF_IO
Chris@16 99 /// \brief reads a TIFF image into a run-time instantiated image
Chris@16 100 /// Opens the given tiff file name, selects the first type in Images whose color space and channel are compatible to those of the image file
Chris@16 101 /// and creates a new image of that type with the dimensions specified by the image file.
Chris@16 102 /// Throws std::ios_base::failure if none of the types in Images are compatible with the type on disk.
Chris@16 103 template <typename Images>
Chris@16 104 inline void tiff_read_image(const char* filename,any_image<Images>& im) {
Chris@16 105 detail::tiff_reader_dynamic m(filename);
Chris@16 106 m.read_image(im);
Chris@16 107 }
Chris@16 108
Chris@16 109 /// \ingroup TIFF_IO
Chris@16 110 /// \brief reads a TIFF image into a run-time instantiated image
Chris@16 111 template <typename Images>
Chris@16 112 inline void tiff_read_image(const std::string& filename,any_image<Images>& im) {
Chris@16 113 tiff_read_image(filename.c_str(),im);
Chris@16 114 }
Chris@16 115
Chris@16 116 /// \ingroup TIFF_IO
Chris@16 117 /// \brief Saves the currently instantiated view to a tiff file specified by the given tiff image file name.
Chris@16 118 /// Throws std::ios_base::failure if the currently instantiated view type is not supported for writing by the I/O extension
Chris@16 119 /// or if it fails to create the file.
Chris@16 120 template <typename Views>
Chris@16 121 inline void tiff_write_view(const char* filename,const any_image_view<Views>& runtime_view) {
Chris@16 122 detail::tiff_writer_dynamic m(filename);
Chris@16 123 m.write_view(runtime_view);
Chris@16 124 }
Chris@16 125
Chris@16 126 /// \ingroup TIFF_IO
Chris@16 127 /// \brief Saves the currently instantiated view to a tiff file specified by the given tiff image file name.
Chris@16 128 template <typename Views>
Chris@16 129 inline void tiff_write_view(const std::string& filename,const any_image_view<Views>& runtime_view) {
Chris@16 130 tiff_write_view(filename.c_str(),runtime_view);
Chris@16 131 }
Chris@16 132
Chris@16 133 } } // namespace boost::gil
Chris@16 134
Chris@16 135 #endif