device.hpp 5.6 KB

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