mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-17 04:38:10 +00:00
Added thirdparty: boost library
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// Copyright 2010 Kenneth Riddile
|
||||
//
|
||||
// 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_TARGA_DETAIL_IS_ALLOWED_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_DETAIL_IS_ALLOWED_HPP
|
||||
|
||||
#include <boost/gil/extension/io/targa/tags.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost { namespace gil { namespace detail {
|
||||
|
||||
template< typename View >
|
||||
bool is_allowed( const image_read_info< targa_tag >& info
|
||||
, std::true_type // is read_and_no_convert
|
||||
)
|
||||
{
|
||||
targa_depth::type src_bits_per_pixel = 0;
|
||||
|
||||
switch( info._bits_per_pixel )
|
||||
{
|
||||
case 24:
|
||||
case 32:
|
||||
{
|
||||
src_bits_per_pixel = info._bits_per_pixel;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
io_error( "Pixel size not supported." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
using channel_t = typename channel_traits<typename element_type<typename View::value_type>::type>::value_type;
|
||||
targa_depth::type dst_bits_per_pixel = detail::unsigned_integral_num_bits< channel_t >::value * num_channels< View >::value;
|
||||
|
||||
return ( dst_bits_per_pixel == src_bits_per_pixel );
|
||||
}
|
||||
|
||||
template< typename View >
|
||||
bool is_allowed( const image_read_info< targa_tag >& /* info */
|
||||
, std::false_type // is read_and_convert
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
+400
@@ -0,0 +1,400 @@
|
||||
//
|
||||
// Copyright 2012 Kenneth Riddile, 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_TARGA_DETAIL_READ_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_DETAIL_READ_HPP
|
||||
|
||||
#include <boost/gil/extension/io/targa/tags.hpp>
|
||||
#include <boost/gil/extension/io/targa/detail/reader_backend.hpp>
|
||||
#include <boost/gil/extension/io/targa/detail/is_allowed.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 <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
|
||||
|
||||
///
|
||||
/// Targa Reader
|
||||
///
|
||||
template< typename Device
|
||||
, typename ConversionPolicy
|
||||
>
|
||||
class reader< Device
|
||||
, targa_tag
|
||||
, ConversionPolicy
|
||||
>
|
||||
: public reader_base< targa_tag
|
||||
, ConversionPolicy
|
||||
>
|
||||
, public reader_backend< Device
|
||||
, targa_tag
|
||||
>
|
||||
{
|
||||
private:
|
||||
|
||||
using this_t = reader<Device, targa_tag, ConversionPolicy>;
|
||||
using cc_t = typename ConversionPolicy::color_converter_type;
|
||||
|
||||
public:
|
||||
|
||||
using backend_t = reader_backend<Device, targa_tag>;
|
||||
|
||||
reader( const Device& io_dev
|
||||
, const image_read_settings< targa_tag >& settings
|
||||
)
|
||||
: reader_base< targa_tag
|
||||
, ConversionPolicy
|
||||
>()
|
||||
, backend_t( io_dev
|
||||
, settings
|
||||
)
|
||||
{}
|
||||
|
||||
reader( const Device& io_dev
|
||||
, const cc_t& cc
|
||||
, const image_read_settings< targa_tag >& settings
|
||||
)
|
||||
: reader_base< targa_tag
|
||||
, ConversionPolicy
|
||||
>( cc )
|
||||
, backend_t( io_dev
|
||||
, settings
|
||||
)
|
||||
{}
|
||||
|
||||
template< typename View >
|
||||
void apply( const View& dst_view )
|
||||
{
|
||||
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."
|
||||
);
|
||||
|
||||
switch( this->_info._image_type )
|
||||
{
|
||||
case targa_image_type::_rgb:
|
||||
{
|
||||
if( this->_info._color_map_type != targa_color_map_type::_rgb )
|
||||
{
|
||||
io_error( "Inconsistent color map type and image type in targa file." );
|
||||
}
|
||||
|
||||
if( this->_info._color_map_length != 0 )
|
||||
{
|
||||
io_error( "Non-indexed targa files containing a palette are not supported." );
|
||||
}
|
||||
|
||||
switch( this->_info._bits_per_pixel )
|
||||
{
|
||||
case 24:
|
||||
{
|
||||
this->_scanline_length = this->_info._width * ( this->_info._bits_per_pixel / 8 );
|
||||
|
||||
if( this->_info._screen_origin_bit )
|
||||
{
|
||||
read_data< bgr8_view_t >( flipped_up_down_view( dst_view ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
read_data< bgr8_view_t >( dst_view );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 32:
|
||||
{
|
||||
this->_scanline_length = this->_info._width * ( this->_info._bits_per_pixel / 8 );
|
||||
|
||||
if( this->_info._screen_origin_bit )
|
||||
{
|
||||
read_data< bgra8_view_t >( flipped_up_down_view( dst_view ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
read_data< bgra8_view_t >( dst_view );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
io_error( "Unsupported bit depth in targa file." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case targa_image_type::_rle_rgb:
|
||||
{
|
||||
if( this->_info._color_map_type != targa_color_map_type::_rgb )
|
||||
{
|
||||
io_error( "Inconsistent color map type and image type in targa file." );
|
||||
}
|
||||
|
||||
if( this->_info._color_map_length != 0 )
|
||||
{
|
||||
io_error( "Non-indexed targa files containing a palette are not supported." );
|
||||
}
|
||||
|
||||
switch( this->_info._bits_per_pixel )
|
||||
{
|
||||
case 24:
|
||||
{
|
||||
if( this->_info._screen_origin_bit )
|
||||
{
|
||||
read_rle_data< bgr8_view_t >( flipped_up_down_view( dst_view ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
read_rle_data< bgr8_view_t >( dst_view );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 32:
|
||||
{
|
||||
if( this->_info._screen_origin_bit )
|
||||
{
|
||||
read_rle_data< bgra8_view_t >( flipped_up_down_view( dst_view ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
read_rle_data< bgra8_view_t >( dst_view );
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
io_error( "Unsupported bit depth in targa file." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
io_error( "Unsupported image type in targa file." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// 8-8-8 BGR
|
||||
// 8-8-8-8 BGRA
|
||||
template< typename View_Src, typename View_Dst >
|
||||
void read_data( const View_Dst& view )
|
||||
{
|
||||
byte_vector_t row( this->_info._width * (this->_info._bits_per_pixel / 8) );
|
||||
|
||||
// jump to first scanline
|
||||
this->_io_dev.seek( static_cast< long >( this->_info._offset ));
|
||||
|
||||
View_Src v = interleaved_view( this->_info._width,
|
||||
1,
|
||||
reinterpret_cast<typename View_Src::value_type*>( &row.front() ),
|
||||
this->_info._width * num_channels< View_Src >::value
|
||||
);
|
||||
|
||||
typename View_Src::x_iterator beg = v.row_begin( 0 ) + this->_settings._top_left.x;
|
||||
typename View_Src::x_iterator end = beg + this->_settings._dim.x;
|
||||
|
||||
// read bottom up since targa origin is bottom left
|
||||
for( std::ptrdiff_t y = this->_settings._dim.y - 1; y > -1; --y )
|
||||
{
|
||||
// @todo: For now we're reading the whole scanline which is
|
||||
// slightly inefficient. Later versions should try to read
|
||||
// only the bytes which are necessary.
|
||||
this->_io_dev.read( &row.front(), row.size() );
|
||||
this->_cc_policy.read( beg, end, view.row_begin(y) );
|
||||
}
|
||||
}
|
||||
|
||||
// 8-8-8 BGR
|
||||
// 8-8-8-8 BGRA
|
||||
template< typename View_Src, typename View_Dst >
|
||||
void read_rle_data( const View_Dst& view )
|
||||
{
|
||||
targa_depth::type bytes_per_pixel = this->_info._bits_per_pixel / 8;
|
||||
size_t image_size = this->_info._width * this->_info._height * bytes_per_pixel;
|
||||
byte_vector_t image_data( image_size );
|
||||
|
||||
this->_io_dev.seek( static_cast< long >( this->_info._offset ));
|
||||
|
||||
for( size_t pixel = 0; pixel < image_size; )
|
||||
{
|
||||
targa_offset::type current_byte = this->_io_dev.read_uint8();
|
||||
|
||||
if( current_byte & 0x80 ) // run length chunk (high bit = 1)
|
||||
{
|
||||
uint8_t chunk_length = current_byte - 127;
|
||||
uint8_t pixel_data[4];
|
||||
for( size_t channel = 0; channel < bytes_per_pixel; ++channel )
|
||||
{
|
||||
pixel_data[channel] = this->_io_dev.read_uint8();
|
||||
}
|
||||
|
||||
// Repeat the next pixel chunk_length times
|
||||
for( uint8_t i = 0; i < chunk_length; ++i, pixel += bytes_per_pixel )
|
||||
{
|
||||
memcpy( &image_data[pixel], pixel_data, bytes_per_pixel );
|
||||
}
|
||||
}
|
||||
else // raw chunk
|
||||
{
|
||||
uint8_t chunk_length = current_byte + 1;
|
||||
|
||||
// Write the next chunk_length pixels directly
|
||||
size_t pixels_written = chunk_length * bytes_per_pixel;
|
||||
this->_io_dev.read( &image_data[pixel], pixels_written );
|
||||
pixel += pixels_written;
|
||||
}
|
||||
}
|
||||
|
||||
View_Src v = flipped_up_down_view( interleaved_view( this->_info._width,
|
||||
this->_info._height,
|
||||
reinterpret_cast<typename View_Src::value_type*>( &image_data.front() ),
|
||||
this->_info._width * num_channels< View_Src >::value ) );
|
||||
|
||||
for( std::ptrdiff_t y = 0; y != this->_settings._dim.y; ++y )
|
||||
{
|
||||
typename View_Src::x_iterator beg = v.row_begin( y ) + this->_settings._top_left.x;
|
||||
typename View_Src::x_iterator end = beg + this->_settings._dim.x;
|
||||
this->_cc_policy.read( beg, end, view.row_begin(y) );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
class targa_type_format_checker
|
||||
{
|
||||
public:
|
||||
|
||||
targa_type_format_checker( const targa_depth::type& bpp )
|
||||
: _bpp( bpp )
|
||||
{}
|
||||
|
||||
template< typename Image >
|
||||
bool apply()
|
||||
{
|
||||
if( _bpp < 32 )
|
||||
{
|
||||
return pixels_are_compatible< typename Image::value_type, rgb8_pixel_t >::value
|
||||
? true
|
||||
: false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return pixels_are_compatible< typename Image::value_type, rgba8_pixel_t >::value
|
||||
? true
|
||||
: false;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// to avoid C4512
|
||||
targa_type_format_checker& operator=( const targa_type_format_checker& ) { return *this; }
|
||||
|
||||
private:
|
||||
|
||||
const targa_depth::type _bpp;
|
||||
};
|
||||
|
||||
struct targa_read_is_supported
|
||||
{
|
||||
template< typename View >
|
||||
struct apply : public is_read_supported< typename get_pixel_type< View >::type
|
||||
, targa_tag
|
||||
>
|
||||
{};
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
///
|
||||
/// Targa Dynamic Image Reader
|
||||
///
|
||||
template< typename Device >
|
||||
class dynamic_image_reader< Device
|
||||
, targa_tag
|
||||
>
|
||||
: public reader< Device
|
||||
, targa_tag
|
||||
, detail::read_and_no_convert
|
||||
>
|
||||
{
|
||||
using parent_t = reader<Device, targa_tag, detail::read_and_no_convert>;
|
||||
|
||||
public:
|
||||
|
||||
dynamic_image_reader( const Device& io_dev
|
||||
, const image_read_settings< targa_tag >& settings
|
||||
)
|
||||
: parent_t( io_dev
|
||||
, settings
|
||||
)
|
||||
{}
|
||||
|
||||
template< typename ...Images >
|
||||
void apply( any_image< Images... >& images )
|
||||
{
|
||||
detail::targa_type_format_checker format_checker( this->_info._bits_per_pixel );
|
||||
|
||||
if( !detail::construct_matched( images
|
||||
, format_checker
|
||||
))
|
||||
{
|
||||
io_error( "No matching image type between those of the given any_image and that of the file" );
|
||||
}
|
||||
else
|
||||
{
|
||||
this->init_image( images
|
||||
, this->_settings
|
||||
);
|
||||
|
||||
detail::dynamic_io_fnobj< detail::targa_read_is_supported
|
||||
, parent_t
|
||||
> op( this );
|
||||
|
||||
variant2::visit( op
|
||||
,view( images )
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
//
|
||||
// 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_TARGA_DETAIL_READER_BACKEND_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_DETAIL_READER_BACKEND_HPP
|
||||
|
||||
#include <boost/gil/extension/io/targa/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
|
||||
|
||||
///
|
||||
/// Targa Backend
|
||||
///
|
||||
template< typename Device >
|
||||
struct reader_backend< Device
|
||||
, targa_tag
|
||||
>
|
||||
{
|
||||
public:
|
||||
|
||||
using format_tag_t = targa_tag;
|
||||
|
||||
public:
|
||||
|
||||
reader_backend( const Device& io_dev
|
||||
, const image_read_settings< targa_tag >& settings
|
||||
)
|
||||
: _io_dev ( io_dev )
|
||||
, _scanline_length(0)
|
||||
, _settings( settings )
|
||||
, _info()
|
||||
{
|
||||
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()
|
||||
{
|
||||
_info._header_size = targa_header_size::_size;
|
||||
|
||||
_info._offset = _io_dev.read_uint8() + _info._header_size;
|
||||
|
||||
_info._color_map_type = _io_dev.read_uint8();
|
||||
_info._image_type = _io_dev.read_uint8();
|
||||
|
||||
_info._color_map_start = _io_dev.read_uint16();
|
||||
_info._color_map_length = _io_dev.read_uint16();
|
||||
_info._color_map_depth = _io_dev.read_uint8();
|
||||
|
||||
_info._x_origin = _io_dev.read_uint16();
|
||||
_info._y_origin = _io_dev.read_uint16();
|
||||
|
||||
_info._width = _io_dev.read_uint16();
|
||||
_info._height = _io_dev.read_uint16();
|
||||
|
||||
if( _info._width < 1 || _info._height < 1 )
|
||||
{
|
||||
io_error( "Invalid dimension for targa file" );
|
||||
}
|
||||
|
||||
_info._bits_per_pixel = _io_dev.read_uint8();
|
||||
if( _info._bits_per_pixel != 24 && _info._bits_per_pixel != 32 )
|
||||
{
|
||||
io_error( "Unsupported bit depth for targa file" );
|
||||
}
|
||||
|
||||
_info._descriptor = _io_dev.read_uint8();
|
||||
|
||||
// According to TGA specs, http://www.gamers.org/dEngine/quake3/TGA.txt,
|
||||
// the image descriptor byte is:
|
||||
//
|
||||
// For Data Type 1, This entire byte should be set to 0.
|
||||
if (_info._image_type == 1 && _info._descriptor != 0)
|
||||
{
|
||||
io_error("Unsupported descriptor for targa file");
|
||||
}
|
||||
else if (_info._bits_per_pixel == 24)
|
||||
{
|
||||
// Bits 3-0 - For the Targa 24, it should be 0.
|
||||
if ((_info._descriptor & 0x0FU) != 0)
|
||||
{
|
||||
io_error("Unsupported descriptor for targa file");
|
||||
}
|
||||
}
|
||||
else if (_info._bits_per_pixel == 32)
|
||||
{
|
||||
// Bits 3-0 - For Targa 32, it should be 8.
|
||||
if (_info._descriptor != 8 && _info._descriptor != 40)
|
||||
{
|
||||
io_error("Unsupported descriptor for targa file");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
io_error("Unsupported descriptor for targa file");
|
||||
}
|
||||
|
||||
if (_info._descriptor & 32)
|
||||
{
|
||||
_info._screen_origin_bit = true;
|
||||
}
|
||||
|
||||
_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;
|
||||
|
||||
std::size_t _scanline_length;
|
||||
|
||||
image_read_settings< targa_tag > _settings;
|
||||
image_read_info< targa_tag > _info;
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
//
|
||||
// Copyright 2012 Kenneth Riddile, 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_TARGA_DETAIL_SCANLINE_READ_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_DETAIL_SCANLINE_READ_HPP
|
||||
|
||||
#include <boost/gil/extension/io/targa/detail/is_allowed.hpp>
|
||||
#include <boost/gil/extension/io/targa/detail/reader_backend.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/scanline_read_iterator.hpp>
|
||||
#include <boost/gil/io/typedefs.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
///
|
||||
/// Targa Scanline Reader
|
||||
///
|
||||
template< typename Device >
|
||||
class scanline_reader< Device
|
||||
, targa_tag
|
||||
>
|
||||
: public reader_backend< Device
|
||||
, targa_tag
|
||||
>
|
||||
{
|
||||
public:
|
||||
|
||||
using tag_t = targa_tag;
|
||||
using backend_t = reader_backend<Device, tag_t>;
|
||||
using this_t = scanline_reader<Device, tag_t>;
|
||||
using iterator_t = scanline_read_iterator<this_t>;
|
||||
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
scanline_reader( Device& device
|
||||
, const image_read_settings< targa_tag >& settings
|
||||
)
|
||||
: backend_t( device
|
||||
, settings
|
||||
)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
/// Read part of image defined by View and return the data.
|
||||
void read( byte_t* dst, int pos )
|
||||
{
|
||||
// jump to scanline
|
||||
long offset = this->_info._offset
|
||||
+ ( this->_info._height - 1 - pos ) * static_cast< long >( this->_scanline_length );
|
||||
|
||||
this->_io_dev.seek( offset );
|
||||
|
||||
|
||||
read_row( dst );
|
||||
}
|
||||
|
||||
/// Skip over a scanline.
|
||||
void skip( byte_t*, int )
|
||||
{
|
||||
this->_io_dev.seek( static_cast<long>( this->_scanline_length )
|
||||
, SEEK_CUR
|
||||
);
|
||||
}
|
||||
|
||||
iterator_t begin() { return iterator_t( *this ); }
|
||||
iterator_t end() { return iterator_t( *this, this->_info._height ); }
|
||||
|
||||
private:
|
||||
|
||||
void initialize()
|
||||
{
|
||||
if( this->_info._color_map_type != targa_color_map_type::_rgb )
|
||||
{
|
||||
io_error( "scanline reader cannot read indexed targa files." );
|
||||
}
|
||||
|
||||
if( this->_info._image_type != targa_image_type::_rgb )
|
||||
{
|
||||
io_error( "scanline reader cannot read this targa image type." );
|
||||
}
|
||||
|
||||
switch( this->_info._image_type )
|
||||
{
|
||||
case targa_image_type::_rgb:
|
||||
{
|
||||
if( this->_info._color_map_type != targa_color_map_type::_rgb )
|
||||
{
|
||||
io_error( "Inconsistent color map type and image type in targa file." );
|
||||
}
|
||||
|
||||
if( this->_info._color_map_length != 0 )
|
||||
{
|
||||
io_error( "Non-indexed targa files containing a palette are not supported." );
|
||||
}
|
||||
|
||||
if( this->_info._screen_origin_bit )
|
||||
{
|
||||
io_error( "scanline reader cannot read targa files which have screen origin bit set." );
|
||||
}
|
||||
|
||||
switch( this->_info._bits_per_pixel )
|
||||
{
|
||||
case 24:
|
||||
case 32:
|
||||
{
|
||||
this->_scanline_length = this->_info._width * ( this->_info._bits_per_pixel / 8 );
|
||||
|
||||
// jump to first scanline
|
||||
this->_io_dev.seek( static_cast< long >( this->_info._offset ));
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
io_error( "Unsupported bit depth in targa file." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
io_error( "Unsupported image type in targa file." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void read_row( byte_t* dst )
|
||||
{
|
||||
this->_io_dev.read( dst, this->_scanline_length );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// Copyright 2010 Kenneth Riddile
|
||||
//
|
||||
// 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_TARGA_DETAIL_SUPPORTED_TYPES_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_DETAIL_SUPPORTED_TYPES_HPP
|
||||
|
||||
#include <boost/gil/extension/io/targa/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 targa_read_support : read_support_false
|
||||
{
|
||||
static const targa_depth::type bpp = 0;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct targa_read_support<uint8_t
|
||||
, rgb_t
|
||||
> : read_support_true
|
||||
{
|
||||
static const targa_depth::type bpp = 24;
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
struct targa_read_support<uint8_t
|
||||
, rgba_t
|
||||
> : read_support_true
|
||||
{
|
||||
static const targa_depth::type bpp = 32;
|
||||
};
|
||||
|
||||
|
||||
// Write support
|
||||
|
||||
template< typename Channel
|
||||
, typename ColorSpace
|
||||
>
|
||||
struct targa_write_support : write_support_false
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct targa_write_support<uint8_t
|
||||
, rgb_t
|
||||
> : write_support_true {};
|
||||
|
||||
template<>
|
||||
struct targa_write_support<uint8_t
|
||||
, rgba_t
|
||||
> : write_support_true {};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<typename Pixel>
|
||||
struct is_read_supported<Pixel, targa_tag>
|
||||
: std::integral_constant
|
||||
<
|
||||
bool,
|
||||
detail::targa_read_support
|
||||
<
|
||||
typename channel_type<Pixel>::type,
|
||||
typename color_space_type<Pixel>::type
|
||||
>::is_supported
|
||||
>
|
||||
{
|
||||
using parent_t = detail::targa_read_support
|
||||
<
|
||||
typename channel_type<Pixel>::type,
|
||||
typename color_space_type<Pixel>::type
|
||||
>;
|
||||
|
||||
static const typename targa_depth::type bpp = parent_t::bpp;
|
||||
};
|
||||
|
||||
template<typename Pixel>
|
||||
struct is_write_supported<Pixel, targa_tag>
|
||||
: std::integral_constant
|
||||
<
|
||||
bool,
|
||||
detail::targa_write_support
|
||||
<
|
||||
typename channel_type<Pixel>::type,
|
||||
typename color_space_type<Pixel>::type
|
||||
>::is_supported
|
||||
>
|
||||
{};
|
||||
|
||||
}} // namespace boost::gil
|
||||
|
||||
#endif
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
//
|
||||
// Copyright 2010-2012 Kenneth Riddile, 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_TARGA_DETAIL_WRITE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_DETAIL_WRITE_HPP
|
||||
|
||||
#include <boost/gil/extension/io/targa/tags.hpp>
|
||||
#include <boost/gil/extension/io/targa/detail/writer_backend.hpp>
|
||||
|
||||
#include <boost/gil/io/base.hpp>
|
||||
#include <boost/gil/io/device.hpp>
|
||||
#include <boost/gil/io/detail/dynamic.hpp>
|
||||
|
||||
#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
|
||||
|
||||
namespace detail {
|
||||
|
||||
template < int N > struct get_targa_view_type {};
|
||||
template <> struct get_targa_view_type< 3 > { using type = bgr8_view_t; };
|
||||
template <> struct get_targa_view_type< 4 > { using type = bgra8_view_t; };
|
||||
|
||||
struct targa_write_is_supported
|
||||
{
|
||||
template< typename View >
|
||||
struct apply
|
||||
: public is_write_supported< typename get_pixel_type< View >::type
|
||||
, targa_tag
|
||||
>
|
||||
{};
|
||||
};
|
||||
|
||||
} // detail
|
||||
|
||||
///
|
||||
/// TARGA Writer
|
||||
///
|
||||
template< typename Device >
|
||||
class writer< Device
|
||||
, targa_tag
|
||||
>
|
||||
: public writer_backend< Device
|
||||
, targa_tag
|
||||
>
|
||||
{
|
||||
private:
|
||||
using backend_t = writer_backend<Device, targa_tag>;
|
||||
|
||||
public:
|
||||
|
||||
writer( const Device& io_dev
|
||||
, const image_write_info< targa_tag >& info
|
||||
)
|
||||
: backend_t( io_dev
|
||||
, info
|
||||
)
|
||||
{}
|
||||
|
||||
template<typename View>
|
||||
void apply( const View& view )
|
||||
{
|
||||
write( view );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template< typename View >
|
||||
void write( const View& view )
|
||||
{
|
||||
uint8_t bit_depth = static_cast<uint8_t>( num_channels<View>::value * 8 );
|
||||
|
||||
// write the TGA header
|
||||
this->_io_dev.write_uint8( 0 ); // offset
|
||||
this->_io_dev.write_uint8( targa_color_map_type::_rgb );
|
||||
this->_io_dev.write_uint8( targa_image_type::_rgb );
|
||||
this->_io_dev.write_uint16( 0 ); // color map start
|
||||
this->_io_dev.write_uint16( 0 ); // color map length
|
||||
this->_io_dev.write_uint8( 0 ); // color map depth
|
||||
this->_io_dev.write_uint16( 0 ); // x origin
|
||||
this->_io_dev.write_uint16( 0 ); // y origin
|
||||
this->_io_dev.write_uint16( static_cast<uint16_t>( view.width() ) ); // width in pixels
|
||||
this->_io_dev.write_uint16( static_cast<uint16_t>( view.height() ) ); // height in pixels
|
||||
this->_io_dev.write_uint8( bit_depth );
|
||||
|
||||
if( 32 == bit_depth )
|
||||
{
|
||||
this->_io_dev.write_uint8( 8 ); // 8-bit alpha channel descriptor
|
||||
}
|
||||
else
|
||||
{
|
||||
this->_io_dev.write_uint8( 0 );
|
||||
}
|
||||
|
||||
write_image< View
|
||||
, typename detail::get_targa_view_type< num_channels< View >::value >::type
|
||||
>( view );
|
||||
}
|
||||
|
||||
|
||||
template< typename View
|
||||
, typename TGA_View
|
||||
>
|
||||
void write_image( const View& view )
|
||||
{
|
||||
size_t row_size = view.width() * num_channels<View>::value;
|
||||
byte_vector_t buffer( row_size );
|
||||
std::fill( buffer.begin(), buffer.end(), 0 );
|
||||
|
||||
|
||||
TGA_View row = interleaved_view( view.width()
|
||||
, 1
|
||||
, reinterpret_cast<typename TGA_View::value_type*>( &buffer.front() )
|
||||
, row_size
|
||||
);
|
||||
|
||||
for( typename View::y_coord_t y = view.height() - 1; y > -1; --y )
|
||||
{
|
||||
copy_pixels( subimage_view( view
|
||||
, 0
|
||||
, static_cast<int>( y )
|
||||
, static_cast<int>( view.width() )
|
||||
, 1
|
||||
)
|
||||
, row
|
||||
);
|
||||
|
||||
this->_io_dev.write( &buffer.front(), row_size );
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
///
|
||||
/// TARGA Dynamic Image Writer
|
||||
///
|
||||
template< typename Device >
|
||||
class dynamic_image_writer< Device
|
||||
, targa_tag
|
||||
>
|
||||
: public writer< Device
|
||||
, targa_tag
|
||||
>
|
||||
{
|
||||
using parent_t = writer<Device, targa_tag>;
|
||||
|
||||
public:
|
||||
|
||||
dynamic_image_writer( const Device& io_dev
|
||||
, const image_write_info< targa_tag >& info
|
||||
)
|
||||
: parent_t( io_dev
|
||||
, info
|
||||
)
|
||||
{}
|
||||
|
||||
template< typename ...Views >
|
||||
void apply( const any_image_view< Views... >& views )
|
||||
{
|
||||
detail::dynamic_io_fnobj< detail::targa_write_is_supported
|
||||
, parent_t
|
||||
> op( this );
|
||||
|
||||
variant2::visit( op, views );
|
||||
}
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // gil
|
||||
} // boost
|
||||
|
||||
#endif
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// 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_TARGA_DETAIL_WRITER_BACKEND_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_DETAIL_WRITER_BACKEND_HPP
|
||||
|
||||
#include <boost/gil/extension/io/targa/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
|
||||
|
||||
///
|
||||
/// TARGA Writer Backend
|
||||
///
|
||||
template< typename Device >
|
||||
struct writer_backend< Device
|
||||
, targa_tag
|
||||
>
|
||||
{
|
||||
public:
|
||||
|
||||
using format_tag_t = targa_tag;
|
||||
|
||||
public:
|
||||
|
||||
writer_backend( const Device& io_dev
|
||||
, const image_write_info< targa_tag >& info
|
||||
)
|
||||
: _io_dev( io_dev )
|
||||
, _info( info )
|
||||
{}
|
||||
|
||||
public:
|
||||
|
||||
Device _io_dev;
|
||||
|
||||
image_write_info< targa_tag > _info;
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
//
|
||||
// Copyright 2010 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_TARGA_OLD_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_OLD_HPP
|
||||
|
||||
#include <boost/gil/extension/io/targa.hpp>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
/// \ingroup BMP_IO
|
||||
/// \brief Returns the width and height of the BMP file at the specified location.
|
||||
/// Throws std::ios_base::failure if the location does not correspond to a valid BMP file
|
||||
template<typename String>
|
||||
inline point_t targa_read_dimensions(String const& filename)
|
||||
{
|
||||
using backend_t = typename get_reader_backend<String, targa_tag>::type;
|
||||
backend_t backend = read_image_info(filename, targa_tag());
|
||||
return { backend._info._width, backend._info._height };
|
||||
}
|
||||
|
||||
/// \ingroup BMP_IO
|
||||
/// \brief Loads the image specified by the given targa image file name into the given view.
|
||||
/// Triggers a compile assert if the view color space and channel depth are not supported by the BMP library or by the I/O extension.
|
||||
/// Throws std::ios_base::failure if the file is not a valid BMP file, or if its color space or channel depth are not
|
||||
/// compatible with the ones specified by View, or if its dimensions don't match the ones of the view.
|
||||
template< typename String
|
||||
, typename View
|
||||
>
|
||||
inline
|
||||
void targa_read_view( const String& filename
|
||||
, const View& view
|
||||
)
|
||||
{
|
||||
read_view( filename
|
||||
, view
|
||||
, targa_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup BMP_IO
|
||||
/// \brief Allocates a new image whose dimensions are determined by the given bmp image file, and loads the pixels into it.
|
||||
/// Triggers a compile assert if the image color space or channel depth are not supported by the BMP library or by the I/O extension.
|
||||
/// Throws std::ios_base::failure if the file is not a valid BMP file, or if its color space or channel depth are not
|
||||
/// compatible with the ones specified by Image
|
||||
template< typename String
|
||||
, typename Image
|
||||
>
|
||||
inline
|
||||
void targa_read_image( const String& filename
|
||||
, Image& img
|
||||
)
|
||||
{
|
||||
read_image( filename
|
||||
, img
|
||||
, targa_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup BMP_IO
|
||||
/// \brief Loads and color-converts the image specified by the given targa image file name into the given view.
|
||||
/// Throws std::ios_base::failure if the file is not a valid BMP file, or if its dimensions don't match the ones of the view.
|
||||
template< typename String
|
||||
, typename View
|
||||
, typename CC
|
||||
>
|
||||
inline
|
||||
void targa_read_and_convert_view( const String& filename
|
||||
, const View& view
|
||||
, CC cc
|
||||
)
|
||||
{
|
||||
read_and_convert_view( filename
|
||||
, view
|
||||
, cc
|
||||
, targa_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup BMP_IO
|
||||
/// \brief Loads and color-converts the image specified by the given targa image file name into the given view.
|
||||
/// Throws std::ios_base::failure if the file is not a valid BMP file, or if its dimensions don't match the ones of the view.
|
||||
template< typename String
|
||||
, typename View
|
||||
>
|
||||
inline
|
||||
void targa_read_and_convert_view( const String& filename
|
||||
, const View& view
|
||||
)
|
||||
{
|
||||
read_and_convert_view( filename
|
||||
, view
|
||||
, targa_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup BMP_IO
|
||||
/// \brief Allocates a new image whose dimensions are determined by the given targa image file, loads and color-converts the pixels into it.
|
||||
/// Throws std::ios_base::failure if the file is not a valid BMP file
|
||||
template< typename String
|
||||
, typename Image
|
||||
, typename CC
|
||||
>
|
||||
inline
|
||||
void targa_read_and_convert_image( const String& filename
|
||||
, Image& img
|
||||
, CC cc
|
||||
)
|
||||
{
|
||||
read_and_convert_image( filename
|
||||
, img
|
||||
, cc
|
||||
, targa_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup BMP_IO
|
||||
/// \brief Allocates a new image whose dimensions are determined by the given targa image file, loads and color-converts the pixels into it.
|
||||
/// Throws std::ios_base::failure if the file is not a valid BMP file
|
||||
template< typename String
|
||||
, typename Image
|
||||
>
|
||||
inline
|
||||
void targa_read_and_convert_image( const String filename
|
||||
, Image& img
|
||||
)
|
||||
{
|
||||
read_and_convert_image( filename
|
||||
, img
|
||||
, targa_tag()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// \ingroup BMP_IO
|
||||
/// \brief Saves the view to a targa file specified by the given targa image file name.
|
||||
/// Triggers a compile assert if the view color space and channel depth are not supported by the BMP library or by the I/O extension.
|
||||
/// Throws std::ios_base::failure if it fails to create the file.
|
||||
template< typename String
|
||||
, typename View
|
||||
>
|
||||
inline
|
||||
void targa_write_view( const String& filename
|
||||
, const View& view
|
||||
)
|
||||
{
|
||||
write_view( filename
|
||||
, view
|
||||
, targa_tag()
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Copyright 2010-2012 Kenneth Riddile, 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_TARGA_READ_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_READ_HPP
|
||||
|
||||
#include <boost/gil/extension/io/targa/tags.hpp>
|
||||
#include <boost/gil/extension/io/targa/detail/read.hpp>
|
||||
#include <boost/gil/extension/io/targa/detail/scanline_read.hpp>
|
||||
#include <boost/gil/extension/io/targa/detail/supported_types.hpp>
|
||||
|
||||
#include <boost/gil/io/get_reader.hpp>
|
||||
#include <boost/gil/io/make_backend.hpp>
|
||||
#include <boost/gil/io/make_dynamic_image_reader.hpp>
|
||||
#include <boost/gil/io/make_reader.hpp>
|
||||
#include <boost/gil/io/make_scanline_reader.hpp>
|
||||
#include <boost/gil/io/read_and_convert_image.hpp>
|
||||
#include <boost/gil/io/read_and_convert_view.hpp>
|
||||
#include <boost/gil/io/read_image.hpp>
|
||||
#include <boost/gil/io/read_image_info.hpp>
|
||||
#include <boost/gil/io/read_view.hpp>
|
||||
#include <boost/gil/io/scanline_read_iterator.hpp>
|
||||
|
||||
#endif
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
//
|
||||
// Copyright 2010 Kenneth Riddile
|
||||
//
|
||||
// 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_TARGA_TAGS_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_TAGS_HPP
|
||||
|
||||
#include <boost/gil/io/base.hpp>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
/// Defines targa tag.
|
||||
struct targa_tag : format_tag {};
|
||||
|
||||
/// See http://en.wikipedia.org/wiki/Truevision_TGA#Header for reference.
|
||||
/// http://local.wasp.uwa.edu.au/~pbourke/dataformats/tga/
|
||||
|
||||
|
||||
/// Defines type for header sizes.
|
||||
struct targa_header_size : property_base< uint8_t >
|
||||
{
|
||||
static const type _size = 18; /// Constant size for targa file header size.
|
||||
};
|
||||
|
||||
/// Defines type for offset value.
|
||||
struct targa_offset : property_base< uint8_t > {};
|
||||
|
||||
/// Defines type for color map type property.
|
||||
struct targa_color_map_type : property_base< uint8_t >
|
||||
{
|
||||
static const type _rgb = 0;
|
||||
static const type _indexed = 1;
|
||||
};
|
||||
|
||||
/// Defines type for image type property.
|
||||
struct targa_image_type : property_base< uint8_t >
|
||||
{
|
||||
static const type _none = 0; /// no image data
|
||||
static const type _indexed = 1; /// indexed
|
||||
static const type _rgb = 2; /// RGB
|
||||
static const type _greyscale = 3; /// greyscale
|
||||
static const type _rle_indexed = 9; /// indexed with RLE compression
|
||||
static const type _rle_rgb = 10; /// RGB with RLE compression
|
||||
static const type _rle_greyscale = 11; /// greyscale with RLE compression
|
||||
};
|
||||
|
||||
/// Defines type for color map start property.
|
||||
struct targa_color_map_start : property_base< uint16_t > {};
|
||||
|
||||
/// Defines type for color map length property.
|
||||
struct targa_color_map_length : property_base< uint16_t > {};
|
||||
|
||||
/// Defines type for color map bit depth property.
|
||||
struct targa_color_map_depth : property_base< uint8_t > {};
|
||||
|
||||
/// Defines type for origin x and y value properties.
|
||||
struct targa_origin_element : property_base< uint16_t > {};
|
||||
|
||||
/// Defines type for image dimension properties.
|
||||
struct targa_dimension : property_base< uint16_t > {};
|
||||
|
||||
/// Defines type for image bit depth property.
|
||||
struct targa_depth : property_base< uint8_t > {};
|
||||
|
||||
/// Defines type for image descriptor property.
|
||||
struct targa_descriptor : property_base< uint8_t > {};
|
||||
|
||||
struct targa_screen_origin_bit : property_base< bool > {};
|
||||
|
||||
/// Read information for targa images.
|
||||
///
|
||||
/// The structure is returned when using read_image_info.
|
||||
template<>
|
||||
struct image_read_info< targa_tag >
|
||||
{
|
||||
/// Default contructor.
|
||||
image_read_info()
|
||||
: _screen_origin_bit(false)
|
||||
, _valid( false )
|
||||
{}
|
||||
|
||||
/// The size of this header:
|
||||
targa_header_size::type _header_size;
|
||||
|
||||
/// The offset, i.e. starting address, of the byte where the targa data can be found.
|
||||
targa_offset::type _offset;
|
||||
|
||||
/// The type of color map used by the image, i.e. RGB or indexed.
|
||||
targa_color_map_type::type _color_map_type;
|
||||
|
||||
/// The type of image data, i.e compressed, indexed, uncompressed RGB, etc.
|
||||
targa_image_type::type _image_type;
|
||||
|
||||
/// Index of first entry in the color map table.
|
||||
targa_color_map_start::type _color_map_start;
|
||||
|
||||
/// Number of entries in the color map table.
|
||||
targa_color_map_length::type _color_map_length;
|
||||
|
||||
/// Bit depth for each color map entry.
|
||||
targa_color_map_depth::type _color_map_depth;
|
||||
|
||||
/// X coordinate of the image origin.
|
||||
targa_origin_element::type _x_origin;
|
||||
|
||||
/// Y coordinate of the image origin.
|
||||
targa_origin_element::type _y_origin;
|
||||
|
||||
/// Width of the image in pixels.
|
||||
targa_dimension::type _width;
|
||||
|
||||
/// Height of the image in pixels.
|
||||
targa_dimension::type _height;
|
||||
|
||||
/// Bit depth of the image.
|
||||
targa_depth::type _bits_per_pixel;
|
||||
|
||||
/// The targa image descriptor.
|
||||
targa_descriptor::type _descriptor;
|
||||
|
||||
// false: Origin in lower left-hand corner.
|
||||
// true: Origin in upper left-hand corner.
|
||||
targa_screen_origin_bit::type _screen_origin_bit;
|
||||
|
||||
/// Used internally to identify if the header has been read.
|
||||
bool _valid;
|
||||
};
|
||||
|
||||
/// Read settings for targa images.
|
||||
///
|
||||
/// The structure can be used for all read_xxx functions, except read_image_info.
|
||||
template<>
|
||||
struct image_read_settings< targa_tag > : public image_read_settings_base
|
||||
{
|
||||
/// Default constructor
|
||||
image_read_settings()
|
||||
: image_read_settings_base()
|
||||
{}
|
||||
|
||||
/// Constructor
|
||||
/// \param top_left Top left coordinate for reading partial image.
|
||||
/// \param dim Dimensions for reading partial image.
|
||||
image_read_settings( point_t const& top_left
|
||||
, point_t const& dim
|
||||
)
|
||||
: image_read_settings_base( top_left
|
||||
, dim
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
/// Write information for targa images.
|
||||
///
|
||||
/// The structure can be used for write_view() function.
|
||||
template<>
|
||||
struct image_write_info< targa_tag >
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright 2010 Kenneth Riddile
|
||||
//
|
||||
// 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_TARGA_WRITE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_TARGA_WRITE_HPP
|
||||
|
||||
#include <boost/gil/extension/io/targa/tags.hpp>
|
||||
#include <boost/gil/extension/io/targa/detail/supported_types.hpp>
|
||||
#include <boost/gil/extension/io/targa/detail//write.hpp>
|
||||
|
||||
#include <boost/gil/io/make_dynamic_image_writer.hpp>
|
||||
#include <boost/gil/io/make_writer.hpp>
|
||||
#include <boost/gil/io/write_view.hpp>
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user