conversion_policies.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. Copyright 2007-2008 Andreas Pokorny, Christian Henning
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. /*************************************************************************************************/
  8. #ifndef BOOST_GIL_IO_CONVERSION_POLICIES_HPP
  9. #define BOOST_GIL_IO_CONVERSION_POLICIES_HPP
  10. ////////////////////////////////////////////////////////////////////////////////////////
  11. /// \file
  12. /// \brief
  13. /// \author Andreas Pokorny, Christian Henning \n
  14. ///
  15. /// \date 2007-2008 \n
  16. ///
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. #include <algorithm>
  19. #include <iterator>
  20. #include <boost/gil/image_view_factory.hpp>
  21. namespace boost{namespace gil{ namespace detail {
  22. struct read_and_no_convert
  23. {
  24. public:
  25. typedef void* color_converter_type;
  26. template< typename InIterator
  27. , typename OutIterator
  28. >
  29. void read( const InIterator& /* begin */
  30. , const InIterator& /* end */
  31. , OutIterator /* out */
  32. , typename disable_if< typename pixels_are_compatible< typename std::iterator_traits<InIterator>::value_type
  33. , typename std::iterator_traits<OutIterator>::value_type
  34. >::type
  35. >::type* /* ptr */ = 0
  36. )
  37. {
  38. io_error( "Data cannot be copied because the pixels are incompatible." );
  39. }
  40. template< typename InIterator
  41. , typename OutIterator
  42. >
  43. void read( const InIterator& begin
  44. , const InIterator& end
  45. , OutIterator out
  46. , typename enable_if< typename pixels_are_compatible< typename std::iterator_traits<InIterator>::value_type
  47. , typename std::iterator_traits<OutIterator>::value_type
  48. >::type
  49. >::type* /* ptr */ = 0
  50. )
  51. {
  52. std::copy( begin
  53. , end
  54. , out
  55. );
  56. }
  57. };
  58. template<typename CC>
  59. struct read_and_convert
  60. {
  61. public:
  62. typedef CC color_converter_type;
  63. CC _cc;
  64. read_and_convert()
  65. {}
  66. read_and_convert( const color_converter_type& cc )
  67. : _cc( cc )
  68. {}
  69. template< typename InIterator
  70. , typename OutIterator
  71. >
  72. void read( const InIterator& begin
  73. , const InIterator& end
  74. , OutIterator out
  75. )
  76. {
  77. typedef color_convert_deref_fn< typename std::iterator_traits<InIterator>::reference
  78. , typename std::iterator_traits<OutIterator>::value_type //reference?
  79. , CC
  80. > deref_t;
  81. std::transform( begin
  82. , end
  83. , out
  84. , deref_t( _cc )
  85. );
  86. }
  87. };
  88. /// is_read_only metafunction
  89. /// \brief Determines if reader type is read only ( no conversion ).
  90. template< typename Conversion_Policy >
  91. struct is_read_only : mpl::false_ {};
  92. template<>
  93. struct is_read_only< detail::read_and_no_convert > : mpl::true_ {};
  94. } // namespace detail
  95. } // namespace gil
  96. } // namespace boost
  97. #endif