Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:58

0001 //
0002 // Copyright 2012 Olivier Tournaire
0003 // Copyright 2007 Christian Henning
0004 //
0005 // Distributed under the Boost Software License, Version 1.0
0006 // See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt
0008 //
0009 #ifndef BOOST_GIL_EXTENSION_IO_RAW_DETAIL_DEVICE_HPP
0010 #define BOOST_GIL_EXTENSION_IO_RAW_DETAIL_DEVICE_HPP
0011 
0012 #include <boost/gil/extension/io/raw/tags.hpp>
0013 
0014 #include <boost/gil/io/base.hpp>
0015 #include <boost/gil/io/device.hpp>
0016 
0017 #include <memory>
0018 #include <string>
0019 #include <type_traits>
0020 
0021 namespace boost { namespace gil { namespace detail {
0022 
0023 class raw_device_base
0024 {
0025 public:
0026 
0027     ///
0028     /// Constructor
0029     ///
0030     raw_device_base()
0031     : _processor_ptr( new LibRaw )
0032     {}
0033 
0034     // iparams getters
0035     std::string get_camera_manufacturer() { return std::string(_processor_ptr.get()->imgdata.idata.make);  }
0036     std::string get_camera_model()        { return std::string(_processor_ptr.get()->imgdata.idata.model); }
0037     unsigned get_raw_count()              { return _processor_ptr.get()->imgdata.idata.raw_count; }
0038     unsigned get_dng_version()            { return _processor_ptr.get()->imgdata.idata.dng_version; }
0039     int get_colors()                      { return _processor_ptr.get()->imgdata.idata.colors; }
0040     unsigned get_filters()                { return _processor_ptr.get()->imgdata.idata.filters; }
0041     std::string get_cdesc()               { return std::string(_processor_ptr.get()->imgdata.idata.cdesc); }
0042 
0043     // image_sizes getters
0044     unsigned short get_raw_width()    { return _processor_ptr.get()->imgdata.sizes.raw_width;  }
0045     unsigned short get_raw_height()   { return _processor_ptr.get()->imgdata.sizes.raw_height; }
0046     unsigned short get_image_width()  { return _processor_ptr.get()->imgdata.sizes.width;  }
0047     unsigned short get_image_height() { return _processor_ptr.get()->imgdata.sizes.height; }
0048     unsigned short get_top_margin()   { return _processor_ptr.get()->imgdata.sizes.top_margin;  }
0049     unsigned short get_left_margin()  { return _processor_ptr.get()->imgdata.sizes.left_margin; }
0050     unsigned short get_iwidth()       { return _processor_ptr.get()->imgdata.sizes.iwidth;  }
0051     unsigned short get_iheight()      { return _processor_ptr.get()->imgdata.sizes.iheight; }
0052     double get_pixel_aspect()         { return _processor_ptr.get()->imgdata.sizes.pixel_aspect;  }
0053     int get_flip()                    { return _processor_ptr.get()->imgdata.sizes.flip; }
0054 
0055     // colordata getters
0056     // TODO
0057 
0058     // imgother getters
0059     float get_iso_speed()     { return _processor_ptr.get()->imgdata.other.iso_speed; }
0060     float get_shutter()       { return _processor_ptr.get()->imgdata.other.shutter; }
0061     float get_aperture()      { return _processor_ptr.get()->imgdata.other.aperture; }
0062     float get_focal_len()     { return _processor_ptr.get()->imgdata.other.focal_len; }
0063     time_t get_timestamp()    { return _processor_ptr.get()->imgdata.other.timestamp; }
0064     unsigned int get_shot_order() { return _processor_ptr.get()->imgdata.other.shot_order; }
0065     unsigned* get_gpsdata()   { return _processor_ptr.get()->imgdata.other.gpsdata; }
0066     std::string get_desc()    { return std::string(_processor_ptr.get()->imgdata.other.desc); }
0067     std::string get_artist()  { return std::string(_processor_ptr.get()->imgdata.other.artist); }
0068 
0069     std::string get_version()               { return std::string(_processor_ptr.get()->version()); }
0070     std::string get_unpack_function_name()  { return std::string(_processor_ptr.get()->unpack_function_name()); }
0071 
0072     void get_mem_image_format(int *widthp, int *heightp, int *colorsp, int *bpp) { _processor_ptr.get()->get_mem_image_format(widthp, heightp, colorsp, bpp); }
0073 
0074     int unpack()                                                         { return _processor_ptr.get()->unpack(); }
0075     int dcraw_process()                                                  { return _processor_ptr.get()->dcraw_process(); }
0076     libraw_processed_image_t* dcraw_make_mem_image(int* error_code=nullptr) { return _processor_ptr.get()->dcraw_make_mem_image(error_code); }
0077 
0078 protected:
0079 
0080     using libraw_ptr_t = std::shared_ptr<LibRaw>;
0081     libraw_ptr_t _processor_ptr;
0082 };
0083 
0084 /*!
0085  *
0086  * file_stream_device specialization for raw images
0087  */
0088 template<>
0089 class file_stream_device< raw_tag > : public raw_device_base
0090 {
0091 public:
0092 
0093     struct read_tag {};
0094 
0095     ///
0096     /// Constructor
0097     ///
0098     file_stream_device( std::string const& file_name
0099                       , read_tag   = read_tag()
0100                       )
0101     {
0102         io_error_if( _processor_ptr.get()->open_file( file_name.c_str() ) != LIBRAW_SUCCESS
0103                    , "file_stream_device: failed to open file"
0104                    );
0105     }
0106 
0107     ///
0108     /// Constructor
0109     ///
0110     file_stream_device( const char* file_name
0111                       , read_tag   = read_tag()
0112                       )
0113     {
0114         io_error_if( _processor_ptr.get()->open_file( file_name ) != LIBRAW_SUCCESS
0115                    , "file_stream_device: failed to open file"
0116                    );
0117     }
0118 };
0119 
0120 template< typename FormatTag >
0121 struct is_adaptable_input_device<FormatTag, LibRaw, void> : std::true_type
0122 {
0123     using device_type = file_stream_device<FormatTag>;
0124 };
0125 
0126 
0127 } // namespace detail
0128 } // namespace gil
0129 } // namespace boost
0130 
0131 #endif