Added thirdparty: boost library

This commit is contained in:
Viacheslav Demydiuk
2024-01-06 19:55:56 +02:00
parent bf49f439e1
commit bccd1e7051
15683 changed files with 3239840 additions and 0 deletions
+131
View File
@@ -0,0 +1,131 @@
//
// Copyright 2012 Olivier Tournaire
// Copyright 2007 Christian Henning
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#ifndef BOOST_GIL_EXTENSION_IO_RAW_DETAIL_DEVICE_HPP
#define BOOST_GIL_EXTENSION_IO_RAW_DETAIL_DEVICE_HPP
#include <boost/gil/extension/io/raw/tags.hpp>
#include <boost/gil/io/base.hpp>
#include <boost/gil/io/device.hpp>
#include <memory>
#include <string>
#include <type_traits>
namespace boost { namespace gil { namespace detail {
class raw_device_base
{
public:
///
/// Constructor
///
raw_device_base()
: _processor_ptr( new LibRaw )
{}
// iparams getters
std::string get_camera_manufacturer() { return std::string(_processor_ptr.get()->imgdata.idata.make); }
std::string get_camera_model() { return std::string(_processor_ptr.get()->imgdata.idata.model); }
unsigned get_raw_count() { return _processor_ptr.get()->imgdata.idata.raw_count; }
unsigned get_dng_version() { return _processor_ptr.get()->imgdata.idata.dng_version; }
int get_colors() { return _processor_ptr.get()->imgdata.idata.colors; }
unsigned get_filters() { return _processor_ptr.get()->imgdata.idata.filters; }
std::string get_cdesc() { return std::string(_processor_ptr.get()->imgdata.idata.cdesc); }
// image_sizes getters
unsigned short get_raw_width() { return _processor_ptr.get()->imgdata.sizes.raw_width; }
unsigned short get_raw_height() { return _processor_ptr.get()->imgdata.sizes.raw_height; }
unsigned short get_image_width() { return _processor_ptr.get()->imgdata.sizes.width; }
unsigned short get_image_height() { return _processor_ptr.get()->imgdata.sizes.height; }
unsigned short get_top_margin() { return _processor_ptr.get()->imgdata.sizes.top_margin; }
unsigned short get_left_margin() { return _processor_ptr.get()->imgdata.sizes.left_margin; }
unsigned short get_iwidth() { return _processor_ptr.get()->imgdata.sizes.iwidth; }
unsigned short get_iheight() { return _processor_ptr.get()->imgdata.sizes.iheight; }
double get_pixel_aspect() { return _processor_ptr.get()->imgdata.sizes.pixel_aspect; }
int get_flip() { return _processor_ptr.get()->imgdata.sizes.flip; }
// colordata getters
// TODO
// imgother getters
float get_iso_speed() { return _processor_ptr.get()->imgdata.other.iso_speed; }
float get_shutter() { return _processor_ptr.get()->imgdata.other.shutter; }
float get_aperture() { return _processor_ptr.get()->imgdata.other.aperture; }
float get_focal_len() { return _processor_ptr.get()->imgdata.other.focal_len; }
time_t get_timestamp() { return _processor_ptr.get()->imgdata.other.timestamp; }
unsigned int get_shot_order() { return _processor_ptr.get()->imgdata.other.shot_order; }
unsigned* get_gpsdata() { return _processor_ptr.get()->imgdata.other.gpsdata; }
std::string get_desc() { return std::string(_processor_ptr.get()->imgdata.other.desc); }
std::string get_artist() { return std::string(_processor_ptr.get()->imgdata.other.artist); }
std::string get_version() { return std::string(_processor_ptr.get()->version()); }
std::string get_unpack_function_name() { return std::string(_processor_ptr.get()->unpack_function_name()); }
void get_mem_image_format(int *widthp, int *heightp, int *colorsp, int *bpp) { _processor_ptr.get()->get_mem_image_format(widthp, heightp, colorsp, bpp); }
int unpack() { return _processor_ptr.get()->unpack(); }
int dcraw_process() { return _processor_ptr.get()->dcraw_process(); }
libraw_processed_image_t* dcraw_make_mem_image(int* error_code=nullptr) { return _processor_ptr.get()->dcraw_make_mem_image(error_code); }
protected:
using libraw_ptr_t = std::shared_ptr<LibRaw>;
libraw_ptr_t _processor_ptr;
};
/*!
*
* file_stream_device specialization for raw images
*/
template<>
class file_stream_device< raw_tag > : public raw_device_base
{
public:
struct read_tag {};
///
/// Constructor
///
file_stream_device( std::string const& file_name
, read_tag = read_tag()
)
{
io_error_if( _processor_ptr.get()->open_file( file_name.c_str() ) != LIBRAW_SUCCESS
, "file_stream_device: failed to open file"
);
}
///
/// Constructor
///
file_stream_device( const char* file_name
, read_tag = read_tag()
)
{
io_error_if( _processor_ptr.get()->open_file( file_name ) != LIBRAW_SUCCESS
, "file_stream_device: failed to open file"
);
}
};
template< typename FormatTag >
struct is_adaptable_input_device<FormatTag, LibRaw, void> : std::true_type
{
using device_type = file_stream_device<FormatTag>;
};
} // namespace detail
} // namespace gil
} // namespace boost
#endif
+48
View File
@@ -0,0 +1,48 @@
//
// Copyright 2009 Christian Henning
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#ifndef BOOST_GIL_EXTENSION_IO_RAW_DETAIL_IS_ALLOWED_HPP
#define BOOST_GIL_EXTENSION_IO_RAW_DETAIL_IS_ALLOWED_HPP
#include <boost/gil/extension/io/raw/tags.hpp>
#include <boost/gil/io/base.hpp>
#include <type_traits>
namespace boost { namespace gil { namespace detail {
template< typename View >
bool is_allowed( const image_read_info< raw_tag >& info
, std::true_type // is read_and_no_convert
)
{
using pixel_t = typename get_pixel_type<View>::type;
using num_channel_t = typename num_channels<pixel_t>::value_type;
using channel_t = typename channel_traits<typename element_type<typename View::value_type>::type>::value_type;
constexpr num_channel_t dst_samples_per_pixel = num_channels<pixel_t>::value;
constexpr unsigned int dst_bits_per_pixel = detail::unsigned_integral_num_bits<channel_t>::value;
constexpr bool is_type_signed = std::is_signed<channel_t>::value;
return (dst_samples_per_pixel == info._samples_per_pixel &&
dst_bits_per_pixel == static_cast<unsigned int>(info._bits_per_pixel) &&
!is_type_signed);
}
template< typename View >
bool is_allowed( const image_read_info< raw_tag >& /* info */
, std::false_type // is read_and_convert
)
{
return true;
}
} // namespace detail
} // namespace gil
} // namespace boost
#endif
+241
View File
@@ -0,0 +1,241 @@
//
// Copyright 2012 Olivier Tournaire, Christian Henning
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#ifndef BOOST_GIL_EXTENSION_IO_RAW_DETAIL_READ_HPP
#define BOOST_GIL_EXTENSION_IO_RAW_DETAIL_READ_HPP
#include <boost/gil/extension/io/raw/tags.hpp>
#include <boost/gil/extension/io/raw/detail/device.hpp>
#include <boost/gil/extension/io/raw/detail/is_allowed.hpp>
#include <boost/gil/extension/io/raw/detail/reader_backend.hpp>
#include <boost/gil/io/detail/dynamic.hpp>
#include <boost/gil/io/base.hpp>
#include <boost/gil/io/bit_operations.hpp>
#include <boost/gil/io/conversion_policies.hpp>
#include <boost/gil/io/device.hpp>
#include <boost/gil/io/reader_base.hpp>
#include <boost/gil/io/row_buffer_helper.hpp>
#include <boost/gil/io/typedefs.hpp>
#include <cstdio>
#include <sstream>
#include <type_traits>
#include <vector>
namespace boost { namespace gil {
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(push)
#pragma warning(disable:4512) //assignment operator could not be generated
#endif
#define BUILD_INTERLEAVED_VIEW(color_layout, bits_per_pixel) \
{ \
color_layout##bits_per_pixel##_view_t build = boost::gil::interleaved_view(processed_image->width, \
processed_image->height, \
(color_layout##bits_per_pixel##_pixel_t*)processed_image->data, \
processed_image->colors*processed_image->width*processed_image->bits/8); \
this->_cc_policy.read( build.begin(), build.end(), dst_view.begin() ); \
} \
template< typename Device
, typename ConversionPolicy
>
class reader< Device
, raw_tag
, ConversionPolicy
>
: public reader_base< raw_tag
, ConversionPolicy
>
, public reader_backend< Device
, raw_tag
>
{
private:
using this_t = reader<Device, raw_tag, ConversionPolicy>;
using cc_t = typename ConversionPolicy::color_converter_type;
public:
using backend_t = reader_backend<Device, raw_tag>;
//
// Constructor
//
reader( const Device& io_dev
, const image_read_settings< raw_tag >& settings
)
: backend_t( io_dev
, settings
)
{}
//
// Constructor
//
reader( const Device& io_dev
, const cc_t& cc
, const image_read_settings< raw_tag >& settings
)
: reader_base< raw_tag
, ConversionPolicy
>( cc )
, backend_t( io_dev
, settings
)
{}
template< typename View >
void apply( const View& dst_view )
{
if( this->_info._valid == false )
{
io_error( "Image header was not read." );
}
using is_read_and_convert_t = typename std::is_same
<
ConversionPolicy,
detail::read_and_no_convert
>::type;
io_error_if( !detail::is_allowed< View >( this->_info
, is_read_and_convert_t()
)
, "Image types aren't compatible."
);
// TODO: better error handling based on return code
int return_code = this->_io_dev.unpack();
io_error_if( return_code != LIBRAW_SUCCESS, "Unable to unpack image" );
this->_info._unpack_function_name = this->_io_dev.get_unpack_function_name();
return_code = this->_io_dev.dcraw_process();
io_error_if( return_code != LIBRAW_SUCCESS, "Unable to emulate dcraw behavior to process image" );
libraw_processed_image_t* processed_image = this->_io_dev.dcraw_make_mem_image(&return_code);
io_error_if( return_code != LIBRAW_SUCCESS, "Unable to dcraw_make_mem_image" );
if(processed_image->colors!=1 && processed_image->colors!=3)
io_error( "Image is neither gray nor RGB" );
if(processed_image->bits!=8 && processed_image->bits!=16)
io_error( "Image is neither 8bit nor 16bit" );
// TODO Olivier Tournaire
// Here, we should use a metafunction to reduce code size and avoid a (compile time) macro
if(processed_image->bits==8)
{
if(processed_image->colors==1){ BUILD_INTERLEAVED_VIEW(gray, 8); }
else { BUILD_INTERLEAVED_VIEW(rgb, 8); }
}
else if(processed_image->bits==16)
{
if(processed_image->colors==1){ BUILD_INTERLEAVED_VIEW(gray, 16); }
else { BUILD_INTERLEAVED_VIEW(rgb, 16); }
}
}
};
namespace detail {
struct raw_read_is_supported
{
template< typename View >
struct apply : public is_read_supported< typename get_pixel_type< View >::type
, raw_tag
>
{};
};
struct raw_type_format_checker
{
raw_type_format_checker( const image_read_info< raw_tag >& info )
: _info( info )
{}
template< typename Image >
bool apply()
{
using view_t = typename Image::view_t;
return is_allowed<view_t>(_info, std::true_type{});
}
private:
///todo: do we need this here. Should be part of reader_backend
const image_read_info< raw_tag >& _info;
};
} // namespace detail
///
/// RAW Dynamic Reader
///
template< typename Device >
class dynamic_image_reader< Device
, raw_tag
>
: public reader< Device
, raw_tag
, detail::read_and_no_convert
>
{
using parent_t = reader<Device, raw_tag, detail::read_and_no_convert>;
public:
dynamic_image_reader( const Device& io_dev
, const image_read_settings< raw_tag >& settings
)
: parent_t( io_dev
, settings
)
{}
template< typename ...Images >
void apply( any_image< Images... >& images )
{
detail::raw_type_format_checker format_checker( this->_info );
if( !detail::construct_matched( images
, format_checker
))
{
std::ostringstream error_message;
error_message << "No matching image type between those of the given any_image and that of the file.\n";
error_message << "Image type must be {gray||rgb}{8||16} unsigned for RAW image files.";
io_error( error_message.str().c_str() );
}
else
{
if( !this->_info._valid )
this->read_header();
this->init_image(images, this->_settings);
detail::dynamic_io_fnobj< detail::raw_read_is_supported
, parent_t
> op( this );
variant2::visit( op
, view( images )
);
}
}
};
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(pop)
#endif
} // gil
} // boost
#endif
+140
View File
@@ -0,0 +1,140 @@
//
// Copyright 2012 Christian Henning
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#ifndef BOOST_GIL_EXTENSION_IO_RAW_DETAIL_READER_BACKEND_HPP
#define BOOST_GIL_EXTENSION_IO_RAW_DETAIL_READER_BACKEND_HPP
#include <boost/gil/extension/io/raw/tags.hpp>
namespace boost { namespace gil {
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(push)
#pragma warning(disable:4512) //assignment operator could not be generated
#endif
///
/// RAW Backend
///
template< typename Device >
struct reader_backend< Device
, raw_tag
>
{
public:
using format_tag_t = raw_tag;
public:
reader_backend( const Device& io_dev
, const image_read_settings< raw_tag >& settings
)
: _io_dev ( io_dev )
, _settings( settings )
, _info()
, _scanline_length( 0 )
{
read_header();
if( _settings._dim.x == 0 )
{
_settings._dim.x = _info._width;
}
if( _settings._dim.y == 0 )
{
_settings._dim.y = _info._height;
}
}
void read_header()
{
_io_dev.get_mem_image_format( &_info._width
, &_info._height
, &_info._samples_per_pixel
, &_info._bits_per_pixel
);
// iparams
_info._camera_manufacturer = _io_dev.get_camera_manufacturer();
_info._camera_model = _io_dev.get_camera_model();
_info._raw_images_count = _io_dev.get_raw_count();
_info._dng_version = _io_dev.get_dng_version();
_info._number_colors = _io_dev.get_colors();
//_io_dev.get_filters();
_info._colors_description = _io_dev.get_cdesc();
// image_sizes
_info._raw_width = _io_dev.get_raw_width();
_info._raw_height = _io_dev.get_raw_height();
_info._visible_width = _io_dev.get_image_width();
_info._visible_height = _io_dev.get_image_height();
_info._top_margin = _io_dev.get_top_margin();
_info._left_margin = _io_dev.get_left_margin();
_info._output_width = _io_dev.get_iwidth();
_info._output_height = _io_dev.get_iheight();
_info._pixel_aspect = _io_dev.get_pixel_aspect();
_info._flip = _io_dev.get_flip();
// imgother
_info._iso_speed = _io_dev.get_iso_speed();
_info._shutter = _io_dev.get_shutter();
_info._aperture = _io_dev.get_aperture();
_info._focal_length = _io_dev.get_focal_len();
_info._timestamp = _io_dev.get_timestamp();
_info._shot_order = static_cast< uint16_t >( _io_dev.get_shot_order() );
//_io_dev.get_gpsdata();
_info._image_description = _io_dev.get_desc();
_info._artist = _io_dev.get_artist();
_info._libraw_version = _io_dev.get_version();
_info._valid = true;
}
/// Check if image is large enough.
void check_image_size( point_t const& img_dim )
{
if( _settings._dim.x > 0 )
{
if( img_dim.x < _settings._dim.x ) { io_error( "Supplied image is too small" ); }
}
else
{
if( img_dim.x < _info._width ) { io_error( "Supplied image is too small" ); }
}
if( _settings._dim.y > 0 )
{
if( img_dim.y < _settings._dim.y ) { io_error( "Supplied image is too small" ); }
}
else
{
if( img_dim.y < _info._height ) { io_error( "Supplied image is too small" ); }
}
}
public:
Device _io_dev;
image_read_settings< raw_tag > _settings;
image_read_info< raw_tag > _info;
std::size_t _scanline_length;
};
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(pop)
#endif
} // namespace gil
} // namespace boost
#endif
@@ -0,0 +1,74 @@
//
// Copyright 2008 Christian Henning
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#ifndef BOOST_GIL_EXTENSION_IO_RAW_DETAIL_SUPPORTED_TYPES_HPP
#define BOOST_GIL_EXTENSION_IO_RAW_DETAIL_SUPPORTED_TYPES_HPP
#include <boost/gil/extension/io/raw/tags.hpp>
#include <boost/gil/channel.hpp>
#include <boost/gil/color_base.hpp>
#include <boost/gil/io/base.hpp>
#include <type_traits>
namespace boost { namespace gil { namespace detail {
// Read support
template< typename Channel
, typename ColorSpace
>
struct raw_read_support : read_support_false {};
template<>
struct raw_read_support<uint8_t
, gray_t
> : read_support_true {};
template<>
struct raw_read_support<uint16_t
, gray_t
> : read_support_true {};
template<>
struct raw_read_support<uint8_t
, rgb_t
> : read_support_true {};
template<>
struct raw_read_support<uint16_t
, rgb_t
> : read_support_true {};
// Write support
struct raw_write_support : write_support_false {};
} // namespace detail
template<typename Pixel>
struct is_read_supported<Pixel,raw_tag>
: std::integral_constant
<
bool,
detail::raw_read_support
<
typename channel_type<Pixel>::type,
typename color_space_type<Pixel>::type
>::is_supported
>
{};
template<typename Pixel>
struct is_write_supported<Pixel, raw_tag>
: std::integral_constant<bool, detail::raw_write_support::is_supported>
{};
}} // namespace boost::gil
#endif