device.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Copyright 2012 Olivier Tournaire
  3. // Copyright 2007 Christian Henning
  4. //
  5. // Distributed under the Boost Software License, Version 1.0
  6. // See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt
  8. //
  9. #ifndef BOOST_GIL_EXTENSION_IO_RAW_DETAIL_DEVICE_HPP
  10. #define BOOST_GIL_EXTENSION_IO_RAW_DETAIL_DEVICE_HPP
  11. #include <boost/gil/extension/io/raw/tags.hpp>
  12. #include <boost/gil/io/base.hpp>
  13. #include <boost/gil/io/device.hpp>
  14. #include <memory>
  15. #include <string>
  16. #include <type_traits>
  17. namespace boost { namespace gil { namespace detail {
  18. class raw_device_base
  19. {
  20. public:
  21. ///
  22. /// Constructor
  23. ///
  24. raw_device_base()
  25. : _processor_ptr( new LibRaw )
  26. {}
  27. // iparams getters
  28. std::string get_camera_manufacturer() { return std::string(_processor_ptr.get()->imgdata.idata.make); }
  29. std::string get_camera_model() { return std::string(_processor_ptr.get()->imgdata.idata.model); }
  30. unsigned get_raw_count() { return _processor_ptr.get()->imgdata.idata.raw_count; }
  31. unsigned get_dng_version() { return _processor_ptr.get()->imgdata.idata.dng_version; }
  32. int get_colors() { return _processor_ptr.get()->imgdata.idata.colors; }
  33. unsigned get_filters() { return _processor_ptr.get()->imgdata.idata.filters; }
  34. std::string get_cdesc() { return std::string(_processor_ptr.get()->imgdata.idata.cdesc); }
  35. // image_sizes getters
  36. unsigned short get_raw_width() { return _processor_ptr.get()->imgdata.sizes.raw_width; }
  37. unsigned short get_raw_height() { return _processor_ptr.get()->imgdata.sizes.raw_height; }
  38. unsigned short get_image_width() { return _processor_ptr.get()->imgdata.sizes.width; }
  39. unsigned short get_image_height() { return _processor_ptr.get()->imgdata.sizes.height; }
  40. unsigned short get_top_margin() { return _processor_ptr.get()->imgdata.sizes.top_margin; }
  41. unsigned short get_left_margin() { return _processor_ptr.get()->imgdata.sizes.left_margin; }
  42. unsigned short get_iwidth() { return _processor_ptr.get()->imgdata.sizes.iwidth; }
  43. unsigned short get_iheight() { return _processor_ptr.get()->imgdata.sizes.iheight; }
  44. double get_pixel_aspect() { return _processor_ptr.get()->imgdata.sizes.pixel_aspect; }
  45. int get_flip() { return _processor_ptr.get()->imgdata.sizes.flip; }
  46. // colordata getters
  47. // TODO
  48. // imgother getters
  49. float get_iso_speed() { return _processor_ptr.get()->imgdata.other.iso_speed; }
  50. float get_shutter() { return _processor_ptr.get()->imgdata.other.shutter; }
  51. float get_aperture() { return _processor_ptr.get()->imgdata.other.aperture; }
  52. float get_focal_len() { return _processor_ptr.get()->imgdata.other.focal_len; }
  53. time_t get_timestamp() { return _processor_ptr.get()->imgdata.other.timestamp; }
  54. unsigned int get_shot_order() { return _processor_ptr.get()->imgdata.other.shot_order; }
  55. unsigned* get_gpsdata() { return _processor_ptr.get()->imgdata.other.gpsdata; }
  56. std::string get_desc() { return std::string(_processor_ptr.get()->imgdata.other.desc); }
  57. std::string get_artist() { return std::string(_processor_ptr.get()->imgdata.other.artist); }
  58. std::string get_version() { return std::string(_processor_ptr.get()->version()); }
  59. std::string get_unpack_function_name() { return std::string(_processor_ptr.get()->unpack_function_name()); }
  60. void get_mem_image_format(int *widthp, int *heightp, int *colorsp, int *bpp) { _processor_ptr.get()->get_mem_image_format(widthp, heightp, colorsp, bpp); }
  61. int unpack() { return _processor_ptr.get()->unpack(); }
  62. int dcraw_process() { return _processor_ptr.get()->dcraw_process(); }
  63. libraw_processed_image_t* dcraw_make_mem_image(int* error_code=nullptr) { return _processor_ptr.get()->dcraw_make_mem_image(error_code); }
  64. protected:
  65. using libraw_ptr_t = std::shared_ptr<LibRaw>;
  66. libraw_ptr_t _processor_ptr;
  67. };
  68. /*!
  69. *
  70. * file_stream_device specialization for raw images
  71. */
  72. template<>
  73. class file_stream_device< raw_tag > : public raw_device_base
  74. {
  75. public:
  76. struct read_tag {};
  77. ///
  78. /// Constructor
  79. ///
  80. file_stream_device( std::string const& file_name
  81. , read_tag = read_tag()
  82. )
  83. {
  84. io_error_if( _processor_ptr.get()->open_file( file_name.c_str() ) != LIBRAW_SUCCESS
  85. , "file_stream_device: failed to open file"
  86. );
  87. }
  88. ///
  89. /// Constructor
  90. ///
  91. file_stream_device( const char* file_name
  92. , read_tag = read_tag()
  93. )
  94. {
  95. io_error_if( _processor_ptr.get()->open_file( file_name ) != LIBRAW_SUCCESS
  96. , "file_stream_device: failed to open file"
  97. );
  98. }
  99. };
  100. template< typename FormatTag >
  101. struct is_adaptable_input_device<FormatTag, LibRaw, void> : std::true_type
  102. {
  103. using device_type = file_stream_device<FormatTag>;
  104. };
  105. } // namespace detail
  106. } // namespace gil
  107. } // namespace boost
  108. #endif