reader_backend.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // Copyright 2012 Christian Henning
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #ifndef BOOST_GIL_EXTENSION_IO_RAW_DETAIL_READER_BACKEND_HPP
  9. #define BOOST_GIL_EXTENSION_IO_RAW_DETAIL_READER_BACKEND_HPP
  10. #include <boost/gil/extension/io/raw/tags.hpp>
  11. namespace boost { namespace gil {
  12. #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
  13. #pragma warning(push)
  14. #pragma warning(disable:4512) //assignment operator could not be generated
  15. #endif
  16. ///
  17. /// RAW Backend
  18. ///
  19. template< typename Device >
  20. struct reader_backend< Device
  21. , raw_tag
  22. >
  23. {
  24. public:
  25. using format_tag_t = raw_tag;
  26. public:
  27. reader_backend( const Device& io_dev
  28. , const image_read_settings< raw_tag >& settings
  29. )
  30. : _io_dev ( io_dev )
  31. , _settings( settings )
  32. , _info()
  33. , _scanline_length( 0 )
  34. {
  35. read_header();
  36. if( _settings._dim.x == 0 )
  37. {
  38. _settings._dim.x = _info._width;
  39. }
  40. if( _settings._dim.y == 0 )
  41. {
  42. _settings._dim.y = _info._height;
  43. }
  44. }
  45. void read_header()
  46. {
  47. _io_dev.get_mem_image_format( &_info._width
  48. , &_info._height
  49. , &_info._samples_per_pixel
  50. , &_info._bits_per_pixel
  51. );
  52. // iparams
  53. _info._camera_manufacturer = _io_dev.get_camera_manufacturer();
  54. _info._camera_model = _io_dev.get_camera_model();
  55. _info._raw_images_count = _io_dev.get_raw_count();
  56. _info._dng_version = _io_dev.get_dng_version();
  57. _info._number_colors = _io_dev.get_colors();
  58. //_io_dev.get_filters();
  59. _info._colors_description = _io_dev.get_cdesc();
  60. // image_sizes
  61. _info._raw_width = _io_dev.get_raw_width();
  62. _info._raw_height = _io_dev.get_raw_height();
  63. _info._visible_width = _io_dev.get_image_width();
  64. _info._visible_height = _io_dev.get_image_height();
  65. _info._top_margin = _io_dev.get_top_margin();
  66. _info._left_margin = _io_dev.get_left_margin();
  67. _info._output_width = _io_dev.get_iwidth();
  68. _info._output_height = _io_dev.get_iheight();
  69. _info._pixel_aspect = _io_dev.get_pixel_aspect();
  70. _info._flip = _io_dev.get_flip();
  71. // imgother
  72. _info._iso_speed = _io_dev.get_iso_speed();
  73. _info._shutter = _io_dev.get_shutter();
  74. _info._aperture = _io_dev.get_aperture();
  75. _info._focal_length = _io_dev.get_focal_len();
  76. _info._timestamp = _io_dev.get_timestamp();
  77. _info._shot_order = static_cast< uint16_t >( _io_dev.get_shot_order() );
  78. //_io_dev.get_gpsdata();
  79. _info._image_description = _io_dev.get_desc();
  80. _info._artist = _io_dev.get_artist();
  81. _info._libraw_version = _io_dev.get_version();
  82. _info._valid = true;
  83. }
  84. /// Check if image is large enough.
  85. void check_image_size( const point_t& img_dim )
  86. {
  87. if( _settings._dim.x > 0 )
  88. {
  89. if( img_dim.x < _settings._dim.x ) { io_error( "Supplied image is too small" ); }
  90. }
  91. else
  92. {
  93. if( img_dim.x < _info._width ) { io_error( "Supplied image is too small" ); }
  94. }
  95. if( _settings._dim.y > 0 )
  96. {
  97. if( img_dim.y < _settings._dim.y ) { io_error( "Supplied image is too small" ); }
  98. }
  99. else
  100. {
  101. if( img_dim.y < _info._height ) { io_error( "Supplied image is too small" ); }
  102. }
  103. }
  104. public:
  105. Device _io_dev;
  106. image_read_settings< raw_tag > _settings;
  107. image_read_info< raw_tag > _info;
  108. std::size_t _scanline_length;
  109. };
  110. #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
  111. #pragma warning(pop)
  112. #endif
  113. } // namespace gil
  114. } // namespace boost
  115. #endif