device.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. namespace boost { namespace gil { namespace detail {
  17. class raw_device_base
  18. {
  19. public:
  20. ///
  21. /// Constructor
  22. ///
  23. raw_device_base()
  24. : _processor_ptr( new LibRaw )
  25. {}
  26. // iparams getters
  27. std::string get_camera_manufacturer() { return std::string(_processor_ptr.get()->imgdata.idata.make); }
  28. std::string get_camera_model() { return std::string(_processor_ptr.get()->imgdata.idata.model); }
  29. unsigned get_raw_count() { return _processor_ptr.get()->imgdata.idata.raw_count; }
  30. unsigned get_dng_version() { return _processor_ptr.get()->imgdata.idata.dng_version; }
  31. int get_colors() { return _processor_ptr.get()->imgdata.idata.colors; }
  32. unsigned get_filters() { return _processor_ptr.get()->imgdata.idata.filters; }
  33. std::string get_cdesc() { return std::string(_processor_ptr.get()->imgdata.idata.cdesc); }
  34. // image_sizes getters
  35. unsigned short get_raw_width() { return _processor_ptr.get()->imgdata.sizes.raw_width; }
  36. unsigned short get_raw_height() { return _processor_ptr.get()->imgdata.sizes.raw_height; }
  37. unsigned short get_image_width() { return _processor_ptr.get()->imgdata.sizes.width; }
  38. unsigned short get_image_height() { return _processor_ptr.get()->imgdata.sizes.height; }
  39. unsigned short get_top_margin() { return _processor_ptr.get()->imgdata.sizes.top_margin; }
  40. unsigned short get_left_margin() { return _processor_ptr.get()->imgdata.sizes.left_margin; }
  41. unsigned short get_iwidth() { return _processor_ptr.get()->imgdata.sizes.iwidth; }
  42. unsigned short get_iheight() { return _processor_ptr.get()->imgdata.sizes.iheight; }
  43. double get_pixel_aspect() { return _processor_ptr.get()->imgdata.sizes.pixel_aspect; }
  44. int get_flip() { return _processor_ptr.get()->imgdata.sizes.flip; }
  45. // colordata getters
  46. // TODO
  47. // imgother getters
  48. float get_iso_speed() { return _processor_ptr.get()->imgdata.other.iso_speed; }
  49. float get_shutter() { return _processor_ptr.get()->imgdata.other.shutter; }
  50. float get_aperture() { return _processor_ptr.get()->imgdata.other.aperture; }
  51. float get_focal_len() { return _processor_ptr.get()->imgdata.other.focal_len; }
  52. time_t get_timestamp() { return _processor_ptr.get()->imgdata.other.timestamp; }
  53. unsigned int get_shot_order() { return _processor_ptr.get()->imgdata.other.shot_order; }
  54. unsigned* get_gpsdata() { return _processor_ptr.get()->imgdata.other.gpsdata; }
  55. std::string get_desc() { return std::string(_processor_ptr.get()->imgdata.other.desc); }
  56. std::string get_artist() { return std::string(_processor_ptr.get()->imgdata.other.artist); }
  57. std::string get_version() { return std::string(_processor_ptr.get()->version()); }
  58. std::string get_unpack_function_name() { return std::string(_processor_ptr.get()->unpack_function_name()); }
  59. void get_mem_image_format(int *widthp, int *heightp, int *colorsp, int *bpp) { _processor_ptr.get()->get_mem_image_format(widthp, heightp, colorsp, bpp); }
  60. int unpack() { return _processor_ptr.get()->unpack(); }
  61. int dcraw_process() { return _processor_ptr.get()->dcraw_process(); }
  62. libraw_processed_image_t* dcraw_make_mem_image(int* error_code=nullptr) { return _processor_ptr.get()->dcraw_make_mem_image(error_code); }
  63. protected:
  64. using libraw_ptr_t = std::shared_ptr<LibRaw>;
  65. libraw_ptr_t _processor_ptr;
  66. };
  67. /*!
  68. *
  69. * file_stream_device specialization for raw images
  70. */
  71. template<>
  72. class file_stream_device< raw_tag > : public raw_device_base
  73. {
  74. public:
  75. struct read_tag {};
  76. ///
  77. /// Constructor
  78. ///
  79. file_stream_device( std::string const& file_name
  80. , read_tag = read_tag()
  81. )
  82. {
  83. io_error_if( _processor_ptr.get()->open_file( file_name.c_str() ) != LIBRAW_SUCCESS
  84. , "file_stream_device: failed to open file"
  85. );
  86. }
  87. ///
  88. /// Constructor
  89. ///
  90. file_stream_device( const char* file_name
  91. , read_tag = read_tag()
  92. )
  93. {
  94. io_error_if( _processor_ptr.get()->open_file( file_name ) != LIBRAW_SUCCESS
  95. , "file_stream_device: failed to open file"
  96. );
  97. }
  98. };
  99. template< typename FormatTag >
  100. struct is_adaptable_input_device< FormatTag
  101. , LibRaw
  102. , void
  103. >
  104. : mpl::true_
  105. {
  106. using device_type = file_stream_device<FormatTag>;
  107. };
  108. } // namespace detail
  109. } // namespace gil
  110. } // namespace boost
  111. #endif