add boost on mac
This commit is contained in:
102
macx64/include/boost/gil/extension/io/png/detail/base.hpp
Normal file
102
macx64/include/boost/gil/extension/io/png/detail/base.hpp
Normal file
@@ -0,0 +1,102 @@
|
||||
//
|
||||
// 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_PNG_DETAIL_BASE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_BASE_HPP
|
||||
|
||||
#include <boost/gil/extension/io/png/tags.hpp>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace boost { namespace gil { namespace detail {
|
||||
|
||||
struct png_ptr_wrapper
|
||||
{
|
||||
png_ptr_wrapper()
|
||||
: _struct( nullptr )
|
||||
, _info ( nullptr )
|
||||
{}
|
||||
|
||||
png_structp _struct;
|
||||
png_infop _info;
|
||||
};
|
||||
|
||||
///
|
||||
/// Wrapper for libpng's png_struct and png_info object. Implements value semantics.
|
||||
///
|
||||
struct png_struct_info_wrapper
|
||||
{
|
||||
protected:
|
||||
|
||||
using png_ptr_t = std::shared_ptr<png_ptr_wrapper>;
|
||||
|
||||
protected:
|
||||
|
||||
///
|
||||
/// Default Constructor
|
||||
///
|
||||
png_struct_info_wrapper( bool read = true )
|
||||
: _png_ptr( new png_ptr_wrapper()
|
||||
, ( ( read ) ? png_ptr_read_deleter : png_ptr_write_deleter )
|
||||
)
|
||||
{}
|
||||
|
||||
png_ptr_wrapper* get() { return _png_ptr.get(); }
|
||||
png_ptr_wrapper const* get() const { return _png_ptr.get(); }
|
||||
|
||||
png_struct* get_struct() { return get()->_struct; }
|
||||
png_struct const* get_struct() const { return get()->_struct; }
|
||||
|
||||
png_info* get_info() { return get()->_info; }
|
||||
png_info const* get_info() const { return get()->_info; }
|
||||
|
||||
private:
|
||||
|
||||
static void png_ptr_read_deleter( png_ptr_wrapper* png_ptr )
|
||||
{
|
||||
if( png_ptr )
|
||||
{
|
||||
BOOST_ASSERT(png_ptr->_struct && png_ptr->_info);
|
||||
|
||||
png_destroy_read_struct( &png_ptr->_struct
|
||||
, &png_ptr->_info
|
||||
, nullptr
|
||||
);
|
||||
|
||||
delete png_ptr;
|
||||
png_ptr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void png_ptr_write_deleter( png_ptr_wrapper* png_ptr )
|
||||
{
|
||||
if( png_ptr )
|
||||
{
|
||||
BOOST_ASSERT(png_ptr->_struct && png_ptr->_info);
|
||||
|
||||
png_destroy_write_struct( &png_ptr->_struct
|
||||
, &png_ptr->_info
|
||||
);
|
||||
|
||||
delete png_ptr;
|
||||
png_ptr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
png_ptr_t _png_ptr;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright 2008 Christian Henning, Lubomir Bourdev
|
||||
//
|
||||
// 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_PNG_DETAIL_IS_ALLOWED_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_IS_ALLOWED_HPP
|
||||
|
||||
#include <boost/gil/extension/io/png/tags.hpp>
|
||||
|
||||
#include <boost/mpl/bool_fwd.hpp>
|
||||
#include <boost/mpl/for_each.hpp>
|
||||
|
||||
namespace boost { namespace gil { namespace detail {
|
||||
|
||||
template< typename View >
|
||||
bool is_allowed( const image_read_info< png_tag >& info
|
||||
, mpl::true_ // is read_and_no_convert
|
||||
)
|
||||
{
|
||||
using pixel_t = typename get_pixel_type<View>::type;
|
||||
|
||||
using channel_t = typename channel_traits<typename element_type<pixel_t>::type>::value_type;
|
||||
|
||||
const png_num_channels::type dst_num_channels = num_channels< pixel_t >::value;
|
||||
const png_bitdepth::type dst_bit_depth = detail::unsigned_integral_num_bits< channel_t >::value;
|
||||
|
||||
return dst_num_channels == info._num_channels
|
||||
&& dst_bit_depth == info._bit_depth;
|
||||
}
|
||||
|
||||
template< typename View >
|
||||
bool is_allowed( const image_read_info< png_tag >& /* info */
|
||||
, mpl::false_ // is read_and_convert
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
434
macx64/include/boost/gil/extension/io/png/detail/read.hpp
Normal file
434
macx64/include/boost/gil/extension/io/png/detail/read.hpp
Normal file
@@ -0,0 +1,434 @@
|
||||
//
|
||||
// Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
//
|
||||
// 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_PNG_DETAIL_READ_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_READ_HPP
|
||||
|
||||
#include <boost/gil/extension/io/png/tags.hpp>
|
||||
#include <boost/gil/extension/io/png/detail/reader_backend.hpp>
|
||||
#include <boost/gil/extension/io/png/detail/is_allowed.hpp>
|
||||
|
||||
#include <boost/gil.hpp> // FIXME: Include what you use!
|
||||
#include <boost/gil/io/base.hpp>
|
||||
#include <boost/gil/io/conversion_policies.hpp>
|
||||
#include <boost/gil/io/device.hpp>
|
||||
#include <boost/gil/io/dynamic_io_new.hpp>
|
||||
#include <boost/gil/io/reader_base.hpp>
|
||||
#include <boost/gil/io/row_buffer_helper.hpp>
|
||||
#include <boost/gil/io/typedefs.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
|
||||
|
||||
///
|
||||
/// PNG Reader
|
||||
///
|
||||
template< typename Device
|
||||
, typename ConversionPolicy
|
||||
>
|
||||
class reader< Device
|
||||
, png_tag
|
||||
, ConversionPolicy
|
||||
>
|
||||
: public reader_base< png_tag
|
||||
, ConversionPolicy >
|
||||
, public reader_backend< Device
|
||||
, png_tag
|
||||
>
|
||||
{
|
||||
private:
|
||||
|
||||
using this_t = reader<Device, png_tag, ConversionPolicy>;
|
||||
using cc_t = typename ConversionPolicy::color_converter_type;
|
||||
|
||||
public:
|
||||
|
||||
using backend_t = reader_backend<Device, png_tag>;
|
||||
|
||||
public:
|
||||
|
||||
reader( const Device& io_dev
|
||||
, const image_read_settings< png_tag >& settings
|
||||
)
|
||||
: reader_base< png_tag
|
||||
, ConversionPolicy
|
||||
>()
|
||||
, backend_t( io_dev
|
||||
, settings
|
||||
)
|
||||
{}
|
||||
|
||||
reader( const Device& io_dev
|
||||
, const typename ConversionPolicy::color_converter_type& cc
|
||||
, const image_read_settings< png_tag >& settings
|
||||
)
|
||||
: reader_base< png_tag
|
||||
, ConversionPolicy
|
||||
>( cc )
|
||||
, backend_t( io_dev
|
||||
, settings
|
||||
)
|
||||
{}
|
||||
|
||||
template< typename View >
|
||||
void apply( const View& view )
|
||||
{
|
||||
// The info structures are filled at this point.
|
||||
|
||||
// Now it's time for some transformations.
|
||||
|
||||
if( little_endian() )
|
||||
{
|
||||
if( this->_info._bit_depth == 16 )
|
||||
{
|
||||
// Swap bytes of 16 bit files to least significant byte first.
|
||||
png_set_swap( this->get_struct() );
|
||||
}
|
||||
|
||||
if( this->_info._bit_depth < 8 )
|
||||
{
|
||||
// swap bits of 1, 2, 4 bit packed pixel formats
|
||||
png_set_packswap( this->get_struct() );
|
||||
}
|
||||
}
|
||||
|
||||
if( this->_info._color_type == PNG_COLOR_TYPE_PALETTE )
|
||||
{
|
||||
png_set_palette_to_rgb( this->get_struct() );
|
||||
}
|
||||
|
||||
if( png_get_valid( this->get_struct(), this->get_info(), PNG_INFO_tRNS ) )
|
||||
{
|
||||
png_set_tRNS_to_alpha( this->get_struct() );
|
||||
}
|
||||
|
||||
// Tell libpng to handle the gamma conversion for you. The final call
|
||||
// is a good guess for PC generated images, but it should be configurable
|
||||
// by the user at run time by the user. It is strongly suggested that
|
||||
// your application support gamma correction.
|
||||
if( this->_settings._apply_screen_gamma )
|
||||
{
|
||||
// png_set_gamma will change the image data!
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
png_set_gamma( this->get_struct()
|
||||
, this->_settings._screen_gamma
|
||||
, this->_info._file_gamma
|
||||
);
|
||||
#else
|
||||
png_set_gamma( this->get_struct()
|
||||
, this->_settings._screen_gamma
|
||||
, this->_info._file_gamma
|
||||
);
|
||||
#endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
}
|
||||
|
||||
// Turn on interlace handling. REQUIRED if you are not using
|
||||
// png_read_image(). To see how to handle interlacing passes,
|
||||
// see the png_read_row() method below:
|
||||
this->_number_passes = png_set_interlace_handling( this->get_struct() );
|
||||
|
||||
|
||||
// The above transformation might have changed the bit_depth and color type.
|
||||
png_read_update_info( this->get_struct()
|
||||
, this->get_info()
|
||||
);
|
||||
|
||||
this->_info._bit_depth = png_get_bit_depth( this->get_struct()
|
||||
, this->get_info()
|
||||
);
|
||||
|
||||
this->_info._num_channels = png_get_channels( this->get_struct()
|
||||
, this->get_info()
|
||||
);
|
||||
|
||||
this->_info._color_type = png_get_color_type( this->get_struct()
|
||||
, this->get_info()
|
||||
);
|
||||
|
||||
this->_scanline_length = png_get_rowbytes( this->get_struct()
|
||||
, this->get_info()
|
||||
);
|
||||
|
||||
switch( this->_info._color_type )
|
||||
{
|
||||
case PNG_COLOR_TYPE_GRAY:
|
||||
{
|
||||
switch( this->_info._bit_depth )
|
||||
{
|
||||
case 1: read_rows< gray1_image_t::view_t::reference >( view ); break;
|
||||
case 2: read_rows< gray2_image_t::view_t::reference >( view ); break;
|
||||
case 4: read_rows< gray4_image_t::view_t::reference >( view ); break;
|
||||
case 8: read_rows< gray8_pixel_t >( view ); break;
|
||||
case 16: read_rows< gray16_pixel_t >( view ); break;
|
||||
default: io_error( "png_reader::read_data(): unknown combination of color type and bit depth" );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case PNG_COLOR_TYPE_GA:
|
||||
{
|
||||
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
switch( this->_info._bit_depth )
|
||||
{
|
||||
case 8: read_rows< gray_alpha8_pixel_t > ( view ); break;
|
||||
case 16: read_rows< gray_alpha16_pixel_t >( view ); break;
|
||||
default: io_error( "png_reader::read_data(): unknown combination of color type and bit depth" );
|
||||
}
|
||||
#else
|
||||
io_error( "gray_alpha isn't enabled. Use ENABLE_GRAY_ALPHA when building application." );
|
||||
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
case PNG_COLOR_TYPE_RGB:
|
||||
{
|
||||
switch( this->_info._bit_depth )
|
||||
{
|
||||
case 8: read_rows< rgb8_pixel_t > ( view ); break;
|
||||
case 16: read_rows< rgb16_pixel_t >( view ); break;
|
||||
default: io_error( "png_reader::read_data(): unknown combination of color type and bit depth" );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case PNG_COLOR_TYPE_RGBA:
|
||||
{
|
||||
switch( this->_info._bit_depth )
|
||||
{
|
||||
case 8: read_rows< rgba8_pixel_t > ( view ); break;
|
||||
case 16: read_rows< rgba16_pixel_t >( view ); break;
|
||||
default: io_error( "png_reader_color_convert::read_data(): unknown combination of color type and bit depth" );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default: io_error( "png_reader_color_convert::read_data(): unknown color type" );
|
||||
}
|
||||
|
||||
// read rest of file, and get additional chunks in info_ptr
|
||||
png_read_end( this->get_struct()
|
||||
, nullptr
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template< typename ImagePixel
|
||||
, typename View
|
||||
>
|
||||
void read_rows( const View& view )
|
||||
{
|
||||
using row_buffer_helper_t = detail::row_buffer_helper_view<ImagePixel>;
|
||||
|
||||
using it_t = typename row_buffer_helper_t::iterator_t;
|
||||
|
||||
using is_read_and_convert_t = typename 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."
|
||||
);
|
||||
|
||||
std::size_t rowbytes = png_get_rowbytes( this->get_struct()
|
||||
, this->get_info()
|
||||
);
|
||||
|
||||
row_buffer_helper_t buffer( rowbytes
|
||||
, true
|
||||
);
|
||||
|
||||
png_bytep row_ptr = (png_bytep)( &( buffer.data()[0]));
|
||||
|
||||
for( std::size_t pass = 0; pass < this->_number_passes; pass++ )
|
||||
{
|
||||
if( pass == this->_number_passes - 1 )
|
||||
{
|
||||
// skip lines if necessary
|
||||
for( std::ptrdiff_t y = 0; y < this->_settings._top_left.y; ++y )
|
||||
{
|
||||
// Read the image using the "sparkle" effect.
|
||||
png_read_rows( this->get_struct()
|
||||
, &row_ptr
|
||||
, nullptr
|
||||
, 1
|
||||
);
|
||||
}
|
||||
|
||||
for( std::ptrdiff_t y = 0
|
||||
; y < this->_settings._dim.y
|
||||
; ++y
|
||||
)
|
||||
{
|
||||
// Read the image using the "sparkle" effect.
|
||||
png_read_rows( this->get_struct()
|
||||
, &row_ptr
|
||||
, nullptr
|
||||
, 1
|
||||
);
|
||||
|
||||
it_t first = buffer.begin() + this->_settings._top_left.x;
|
||||
it_t last = first + this->_settings._dim.x; // one after last element
|
||||
|
||||
this->_cc_policy.read( first
|
||||
, last
|
||||
, view.row_begin( y ));
|
||||
}
|
||||
|
||||
// Read the rest of the image. libpng needs that.
|
||||
std::ptrdiff_t remaining_rows = static_cast< std::ptrdiff_t >( this->_info._height )
|
||||
- this->_settings._top_left.y
|
||||
- this->_settings._dim.y;
|
||||
for( std::ptrdiff_t y = 0
|
||||
; y < remaining_rows
|
||||
; ++y
|
||||
)
|
||||
{
|
||||
// Read the image using the "sparkle" effect.
|
||||
png_read_rows( this->get_struct()
|
||||
, &row_ptr
|
||||
, nullptr
|
||||
, 1
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int y = 0; y < view.height(); ++y )
|
||||
{
|
||||
// Read the image using the "sparkle" effect.
|
||||
png_read_rows( this->get_struct()
|
||||
, &row_ptr
|
||||
, nullptr
|
||||
, 1
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct png_type_format_checker
|
||||
{
|
||||
png_type_format_checker( png_bitdepth::type bit_depth
|
||||
, png_color_type::type color_type
|
||||
)
|
||||
: _bit_depth ( bit_depth )
|
||||
, _color_type( color_type )
|
||||
{}
|
||||
|
||||
template< typename Image >
|
||||
bool apply()
|
||||
{
|
||||
using is_supported_t = is_read_supported
|
||||
<
|
||||
typename get_pixel_type<typename Image::view_t>::type,
|
||||
png_tag
|
||||
>;
|
||||
|
||||
return is_supported_t::_bit_depth == _bit_depth
|
||||
&& is_supported_t::_color_type == _color_type;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
png_bitdepth::type _bit_depth;
|
||||
png_color_type::type _color_type;
|
||||
};
|
||||
|
||||
struct png_read_is_supported
|
||||
{
|
||||
template< typename View >
|
||||
struct apply : public is_read_supported< typename get_pixel_type< View >::type
|
||||
, png_tag
|
||||
>
|
||||
{};
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
///
|
||||
/// PNG Dynamic Image Reader
|
||||
///
|
||||
template< typename Device
|
||||
>
|
||||
class dynamic_image_reader< Device
|
||||
, png_tag
|
||||
>
|
||||
: public reader< Device
|
||||
, png_tag
|
||||
, detail::read_and_no_convert
|
||||
>
|
||||
{
|
||||
using parent_t = reader
|
||||
<
|
||||
Device,
|
||||
png_tag,
|
||||
detail::read_and_no_convert
|
||||
>;
|
||||
|
||||
public:
|
||||
|
||||
dynamic_image_reader( const Device& io_dev
|
||||
, const image_read_settings< png_tag >& settings
|
||||
)
|
||||
: parent_t( io_dev
|
||||
, settings
|
||||
)
|
||||
{}
|
||||
|
||||
template< typename Images >
|
||||
void apply( any_image< Images >& images )
|
||||
{
|
||||
detail::png_type_format_checker format_checker( this->_info._bit_depth
|
||||
, this->_info._color_type
|
||||
);
|
||||
|
||||
if( !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::png_read_is_supported
|
||||
, parent_t
|
||||
> op( this );
|
||||
|
||||
apply_operation( view( images )
|
||||
, op
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,678 @@
|
||||
//
|
||||
// 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_DETAIL_READER_BACKEND_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_DETAIL_READER_BACKEND_HPP
|
||||
|
||||
#include <boost/gil/extension/io/png/tags.hpp>
|
||||
#include <boost/gil/extension/io/png/detail/base.hpp>
|
||||
#include <boost/gil/extension/io/png/detail/supported_types.hpp>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4512) //assignment operator could not be generated
|
||||
#pragma warning(disable:4611) //interaction between '_setjmp' and C++ object destruction is non-portable
|
||||
#endif
|
||||
|
||||
///
|
||||
/// PNG Backend
|
||||
///
|
||||
template<typename Device >
|
||||
struct reader_backend< Device
|
||||
, png_tag
|
||||
>
|
||||
: public detail::png_struct_info_wrapper
|
||||
{
|
||||
public:
|
||||
|
||||
using format_tag_t = png_tag;
|
||||
using this_t = reader_backend<Device, png_tag>;
|
||||
|
||||
public:
|
||||
|
||||
reader_backend( const Device& io_dev
|
||||
, const image_read_settings< png_tag >& settings
|
||||
)
|
||||
: _io_dev( io_dev )
|
||||
|
||||
, _settings( settings )
|
||||
, _info()
|
||||
, _scanline_length( 0 )
|
||||
|
||||
, _number_passes( 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()
|
||||
{
|
||||
using boost::gil::detail::PNG_BYTES_TO_CHECK;
|
||||
|
||||
// check the file's first few bytes
|
||||
byte_t buf[PNG_BYTES_TO_CHECK];
|
||||
|
||||
io_error_if( _io_dev.read( buf
|
||||
, PNG_BYTES_TO_CHECK
|
||||
) != PNG_BYTES_TO_CHECK
|
||||
, "png_check_validity: failed to read image"
|
||||
);
|
||||
|
||||
io_error_if( png_sig_cmp( png_bytep(buf)
|
||||
, png_size_t(0)
|
||||
, PNG_BYTES_TO_CHECK
|
||||
) != 0
|
||||
, "png_check_validity: invalid png image"
|
||||
);
|
||||
|
||||
// Create and initialize the png_struct with the desired error handler
|
||||
// functions. If you want to use the default stderr and longjump method,
|
||||
// you can supply NULL for the last three parameters. We also supply the
|
||||
// the compiler header file version, so that we know if the application
|
||||
// was compiled with a compatible version of the library. REQUIRED
|
||||
get()->_struct = png_create_read_struct( PNG_LIBPNG_VER_STRING
|
||||
, nullptr // user_error_ptr
|
||||
, nullptr // user_error_fn
|
||||
, nullptr // user_warning_fn
|
||||
);
|
||||
|
||||
io_error_if( get()->_struct == nullptr
|
||||
, "png_reader: fail to call png_create_write_struct()"
|
||||
);
|
||||
|
||||
png_uint_32 user_chunk_data[4];
|
||||
user_chunk_data[0] = 0;
|
||||
user_chunk_data[1] = 0;
|
||||
user_chunk_data[2] = 0;
|
||||
user_chunk_data[3] = 0;
|
||||
png_set_read_user_chunk_fn( get_struct()
|
||||
, user_chunk_data
|
||||
, this_t::read_user_chunk_callback
|
||||
);
|
||||
|
||||
// Allocate/initialize the memory for image information. REQUIRED.
|
||||
get()->_info = png_create_info_struct( get_struct() );
|
||||
|
||||
if( get_info() == nullptr )
|
||||
{
|
||||
png_destroy_read_struct( &get()->_struct
|
||||
, nullptr
|
||||
, nullptr
|
||||
);
|
||||
|
||||
io_error( "png_reader: fail to call png_create_info_struct()" );
|
||||
}
|
||||
|
||||
// Set error handling if you are using the setjmp/longjmp method (this is
|
||||
// the normal method of doing things with libpng). REQUIRED unless you
|
||||
// set up your own error handlers in the png_create_read_struct() earlier.
|
||||
if( setjmp( png_jmpbuf( get_struct() )))
|
||||
{
|
||||
//free all of the memory associated with the png_ptr and info_ptr
|
||||
png_destroy_read_struct( &get()->_struct
|
||||
, &get()->_info
|
||||
, nullptr
|
||||
);
|
||||
|
||||
io_error( "png is invalid" );
|
||||
}
|
||||
|
||||
png_set_read_fn( get_struct()
|
||||
, static_cast< png_voidp >( &this->_io_dev )
|
||||
, this_t::read_data
|
||||
);
|
||||
|
||||
// Set up a callback function that will be
|
||||
// called after each row has been read, which you can use to control
|
||||
// a progress meter or the like.
|
||||
png_set_read_status_fn( get_struct()
|
||||
, this_t::read_row_callback
|
||||
);
|
||||
|
||||
// Set up a callback which implements user defined transformation.
|
||||
// @todo
|
||||
png_set_read_user_transform_fn( get_struct()
|
||||
, png_user_transform_ptr( nullptr )
|
||||
);
|
||||
|
||||
png_set_keep_unknown_chunks( get_struct()
|
||||
, PNG_HANDLE_CHUNK_ALWAYS
|
||||
, nullptr
|
||||
, 0
|
||||
);
|
||||
|
||||
|
||||
// Make sure we read the signature.
|
||||
// @todo make it an option
|
||||
png_set_sig_bytes( get_struct()
|
||||
, PNG_BYTES_TO_CHECK
|
||||
);
|
||||
|
||||
// The call to png_read_info() gives us all of the information from the
|
||||
// PNG file before the first IDAT (image data chunk). REQUIRED
|
||||
png_read_info( get_struct()
|
||||
, get_info()
|
||||
);
|
||||
|
||||
///
|
||||
/// Start reading the image information
|
||||
///
|
||||
|
||||
// get PNG_IHDR chunk information from png_info structure
|
||||
png_get_IHDR( get_struct()
|
||||
, get_info()
|
||||
, &this->_info._width
|
||||
, &this->_info._height
|
||||
, &this->_info._bit_depth
|
||||
, &this->_info._color_type
|
||||
, &this->_info._interlace_method
|
||||
, &this->_info._compression_method
|
||||
, &this->_info._filter_method
|
||||
);
|
||||
|
||||
// get number of color channels in image
|
||||
this->_info._num_channels = png_get_channels( get_struct()
|
||||
, get_info()
|
||||
);
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
// Get CIE chromacities and referenced white point
|
||||
if( this->_settings._read_cie_chromacities )
|
||||
{
|
||||
this->_info._valid_cie_colors = png_get_cHRM( get_struct()
|
||||
, get_info()
|
||||
, &this->_info._white_x, &this->_info._white_y
|
||||
, &this->_info._red_x, &this->_info._red_y
|
||||
, &this->_info._green_x, &this->_info._green_y
|
||||
, &this->_info._blue_x, &this->_info._blue_y
|
||||
);
|
||||
}
|
||||
|
||||
// get the gamma value
|
||||
if( this->_settings._read_file_gamma )
|
||||
{
|
||||
this->_info._valid_file_gamma = png_get_gAMA( get_struct()
|
||||
, get_info()
|
||||
, &this->_info._file_gamma
|
||||
);
|
||||
|
||||
if( this->_info._valid_file_gamma == false )
|
||||
{
|
||||
this->_info._file_gamma = 1.0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
// Get CIE chromacities and referenced white point
|
||||
if( this->_settings._read_cie_chromacities )
|
||||
{
|
||||
this->_info._valid_cie_colors = png_get_cHRM_fixed( get_struct()
|
||||
, get_info()
|
||||
, &this->_info._white_x, &this->_info._white_y
|
||||
, &this->_info._red_x, &this->_info._red_y
|
||||
, &this->_info._green_x, &this->_info._green_y
|
||||
, &this->_info._blue_x, &this->_info._blue_y
|
||||
);
|
||||
}
|
||||
|
||||
// get the gamma value
|
||||
if( this->_settings._read_file_gamma )
|
||||
{
|
||||
this->_info._valid_file_gamma = png_get_gAMA_fixed( get_struct()
|
||||
, get_info()
|
||||
, &this->_info._file_gamma
|
||||
);
|
||||
|
||||
if( this->_info._valid_file_gamma == false )
|
||||
{
|
||||
this->_info._file_gamma = 1;
|
||||
}
|
||||
}
|
||||
#endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
// get the embedded ICC profile data
|
||||
if( this->_settings._read_icc_profile )
|
||||
{
|
||||
#if PNG_LIBPNG_VER_MINOR >= 5
|
||||
png_charp icc_name = png_charp( nullptr );
|
||||
png_bytep profile = png_bytep( nullptr );
|
||||
|
||||
this->_info._valid_icc_profile = png_get_iCCP( get_struct()
|
||||
, get_info()
|
||||
, &icc_name
|
||||
, &this->_info._iccp_compression_type
|
||||
, &profile
|
||||
, &this->_info._profile_length
|
||||
);
|
||||
#else
|
||||
png_charp icc_name = png_charp( NULL );
|
||||
png_charp profile = png_charp( NULL );
|
||||
|
||||
this->_info._valid_icc_profile = png_get_iCCP( get_struct()
|
||||
, get_info()
|
||||
, &icc_name
|
||||
, &this->_info._iccp_compression_type
|
||||
, &profile
|
||||
, &this->_info._profile_length
|
||||
);
|
||||
#endif
|
||||
if( icc_name )
|
||||
{
|
||||
this->_info._icc_name.append( icc_name
|
||||
, std::strlen( icc_name )
|
||||
);
|
||||
}
|
||||
|
||||
if( this->_info._profile_length != 0 )
|
||||
{
|
||||
std:: copy_n (profile, this->_info._profile_length, std:: back_inserter (this->_info._profile));
|
||||
}
|
||||
}
|
||||
|
||||
// get the rendering intent
|
||||
if( this->_settings._read_intent )
|
||||
{
|
||||
this->_info._valid_intent = png_get_sRGB( get_struct()
|
||||
, get_info()
|
||||
, &this->_info._intent
|
||||
);
|
||||
}
|
||||
|
||||
// get image palette information from png_info structure
|
||||
if( this->_settings._read_palette )
|
||||
{
|
||||
png_colorp palette = png_colorp( nullptr );
|
||||
|
||||
this->_info._valid_palette = png_get_PLTE( get_struct()
|
||||
, get_info()
|
||||
, &palette
|
||||
, &this->_info._num_palette
|
||||
);
|
||||
|
||||
if( this->_info._num_palette > 0 )
|
||||
{
|
||||
this->_info._palette.resize( this->_info._num_palette );
|
||||
std::copy( palette
|
||||
, palette + this->_info._num_palette
|
||||
, &this->_info._palette.front()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// get background color
|
||||
if( this->_settings._read_background )
|
||||
{
|
||||
png_color_16p background = png_color_16p( nullptr );
|
||||
|
||||
this->_info._valid_background = png_get_bKGD( get_struct()
|
||||
, get_info()
|
||||
, &background
|
||||
);
|
||||
if( background )
|
||||
{
|
||||
this->_info._background = *background;
|
||||
}
|
||||
}
|
||||
|
||||
// get the histogram
|
||||
if( this->_settings._read_histogram )
|
||||
{
|
||||
png_uint_16p histogram = png_uint_16p( nullptr );
|
||||
|
||||
this->_info._valid_histogram = png_get_hIST( get_struct()
|
||||
, get_info()
|
||||
, &histogram
|
||||
);
|
||||
|
||||
if( histogram )
|
||||
{
|
||||
// the number of values is set by the number of colors inside
|
||||
// the palette.
|
||||
if( this->_settings._read_palette == false )
|
||||
{
|
||||
png_colorp palette = png_colorp( nullptr );
|
||||
png_get_PLTE( get_struct()
|
||||
, get_info()
|
||||
, &palette
|
||||
, &this->_info._num_palette
|
||||
);
|
||||
}
|
||||
|
||||
std::copy( histogram
|
||||
, histogram + this->_info._num_palette
|
||||
, &this->_info._histogram.front()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// get screen offsets for the given image
|
||||
if( this->_settings._read_screen_offsets )
|
||||
{
|
||||
this->_info._valid_offset = png_get_oFFs( get_struct()
|
||||
, get_info()
|
||||
, &this->_info._offset_x
|
||||
, &this->_info._offset_y
|
||||
, &this->_info._off_unit_type
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// get pixel calibration settings
|
||||
if( this->_settings._read_pixel_calibration )
|
||||
{
|
||||
png_charp purpose = png_charp ( nullptr );
|
||||
png_charp units = png_charp ( nullptr );
|
||||
png_charpp params = png_charpp( nullptr );
|
||||
|
||||
this->_info._valid_pixel_calibration = png_get_pCAL( get_struct()
|
||||
, get_info()
|
||||
, &purpose
|
||||
, &this->_info._X0
|
||||
, &this->_info._X1
|
||||
, &this->_info._cal_type
|
||||
, &this->_info._num_params
|
||||
, &units
|
||||
, ¶ms
|
||||
);
|
||||
if( purpose )
|
||||
{
|
||||
this->_info._purpose.append( purpose
|
||||
, std::strlen( purpose )
|
||||
);
|
||||
}
|
||||
|
||||
if( units )
|
||||
{
|
||||
this->_info._units.append( units
|
||||
, std::strlen( units )
|
||||
);
|
||||
}
|
||||
|
||||
if( this->_info._num_params > 0 )
|
||||
{
|
||||
this->_info._params.resize( this->_info._num_params );
|
||||
|
||||
for( png_CAL_nparam::type i = 0
|
||||
; i < this->_info._num_params
|
||||
; ++i
|
||||
)
|
||||
{
|
||||
this->_info._params[i].append( params[i]
|
||||
, std::strlen( params[i] )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get the physical resolution
|
||||
if( this->_settings._read_physical_resolution )
|
||||
{
|
||||
this->_info._valid_resolution = png_get_pHYs( get_struct()
|
||||
, get_info()
|
||||
, &this->_info._res_x
|
||||
, &this->_info._res_y
|
||||
, &this->_info._phy_unit_type
|
||||
);
|
||||
}
|
||||
|
||||
// get the image resolution in pixels per meter.
|
||||
if( this->_settings._read_pixels_per_meter )
|
||||
{
|
||||
this->_info._pixels_per_meter = png_get_pixels_per_meter( get_struct()
|
||||
, get_info()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// get number of significant bits for each color channel
|
||||
if( this->_settings._read_number_of_significant_bits )
|
||||
{
|
||||
png_color_8p sig_bits = png_color_8p( nullptr );
|
||||
|
||||
this->_info._valid_significant_bits = png_get_sBIT( get_struct()
|
||||
, get_info()
|
||||
, &sig_bits
|
||||
);
|
||||
|
||||
// @todo Is there one or more colors?
|
||||
if( sig_bits )
|
||||
{
|
||||
this->_info._sig_bits = *sig_bits;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef BOOST_GIL_IO_PNG_1_4_OR_LOWER
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
// get physical scale settings
|
||||
if( this->_settings._read_scale_factors )
|
||||
{
|
||||
this->_info._valid_scale_factors = png_get_sCAL( get_struct()
|
||||
, get_info()
|
||||
, &this->_info._scale_unit
|
||||
, &this->_info._scale_width
|
||||
, &this->_info._scale_height
|
||||
);
|
||||
}
|
||||
#else
|
||||
#ifdef BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
|
||||
if( this->_settings._read_scale_factors )
|
||||
{
|
||||
this->_info._valid_scale_factors = png_get_sCAL_fixed( get_struct()
|
||||
, get_info()
|
||||
, &this->_info._scale_unit
|
||||
, &this->_info._scale_width
|
||||
, &this->_info._scale_height
|
||||
);
|
||||
}
|
||||
#else
|
||||
if( this->_settings._read_scale_factors )
|
||||
{
|
||||
png_charp scale_width = nullptr;
|
||||
png_charp scale_height = nullptr;
|
||||
|
||||
this->_info._valid_scale_factors = png_get_sCAL_s(
|
||||
get_struct(), get_info(), &this->_info._scale_unit, &scale_width, &scale_height);
|
||||
|
||||
if (this->_info._valid_scale_factors)
|
||||
{
|
||||
if( scale_width )
|
||||
{
|
||||
this->_info._scale_width.append( scale_width
|
||||
, std::strlen( scale_width )
|
||||
);
|
||||
}
|
||||
|
||||
if( scale_height )
|
||||
{
|
||||
this->_info._scale_height.append( scale_height
|
||||
, std::strlen( scale_height )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
|
||||
#endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
#endif // BOOST_GIL_IO_PNG_1_4_OR_LOWER
|
||||
|
||||
// get comments information from png_info structure
|
||||
if( this->_settings._read_comments )
|
||||
{
|
||||
png_textp text = png_textp( nullptr );
|
||||
|
||||
this->_info._valid_text = png_get_text( get_struct()
|
||||
, get_info()
|
||||
, &text
|
||||
, &this->_info._num_text
|
||||
);
|
||||
|
||||
if( this->_info._num_text > 0 )
|
||||
{
|
||||
this->_info._text.resize( this->_info._num_text );
|
||||
|
||||
for( png_num_text::type i = 0
|
||||
; i < this->_info._num_text
|
||||
; ++i
|
||||
)
|
||||
{
|
||||
this->_info._text[i]._compression = text[i].compression;
|
||||
this->_info._text[i]._key.append( text[i].key
|
||||
, std::strlen( text[i].key )
|
||||
);
|
||||
|
||||
this->_info._text[i]._text.append( text[i].text
|
||||
, std::strlen( text[i].text )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get last modification time
|
||||
if( this->_settings._read_last_modification_time )
|
||||
{
|
||||
png_timep mod_time = png_timep( nullptr );
|
||||
this->_info._valid_modification_time = png_get_tIME( get_struct()
|
||||
, get_info()
|
||||
, &mod_time
|
||||
);
|
||||
if( mod_time )
|
||||
{
|
||||
this->_info._mod_time = *mod_time;
|
||||
}
|
||||
}
|
||||
|
||||
// get transparency data
|
||||
if( this->_settings._read_transparency_data )
|
||||
{
|
||||
png_bytep trans = png_bytep ( nullptr );
|
||||
png_color_16p trans_values = png_color_16p( nullptr );
|
||||
|
||||
this->_info._valid_transparency_factors = png_get_tRNS( get_struct()
|
||||
, get_info()
|
||||
, &trans
|
||||
, &this->_info._num_trans
|
||||
, &trans_values
|
||||
);
|
||||
|
||||
if( trans )
|
||||
{
|
||||
//@todo What to do, here? How do I know the length of the "trans" array?
|
||||
}
|
||||
|
||||
if( this->_info._num_trans )
|
||||
{
|
||||
this->_info._trans_values.resize( this->_info._num_trans );
|
||||
std::copy( trans_values
|
||||
, trans_values + this->_info._num_trans
|
||||
, &this->_info._trans_values.front()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// @todo One day!
|
||||
/*
|
||||
if( false )
|
||||
{
|
||||
png_unknown_chunkp unknowns = png_unknown_chunkp( NULL );
|
||||
int num_unknowns = static_cast< int >( png_get_unknown_chunks( get_struct()
|
||||
, get_info()
|
||||
, &unknowns
|
||||
)
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/// Check if image is large enough.
|
||||
void check_image_size( const point_t& 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" ); }
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
static void read_data( png_structp png_ptr
|
||||
, png_bytep data
|
||||
, png_size_t length
|
||||
)
|
||||
{
|
||||
static_cast<Device*>(png_get_io_ptr(png_ptr) )->read( data
|
||||
, length );
|
||||
}
|
||||
|
||||
static void flush( png_structp png_ptr )
|
||||
{
|
||||
static_cast<Device*>(png_get_io_ptr(png_ptr) )->flush();
|
||||
}
|
||||
|
||||
|
||||
static int read_user_chunk_callback( png_struct* /* png_ptr */
|
||||
, png_unknown_chunkp /* chunk */
|
||||
)
|
||||
{
|
||||
// @todo
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void read_row_callback( png_structp /* png_ptr */
|
||||
, png_uint_32 /* row_number */
|
||||
, int /* pass */
|
||||
)
|
||||
{
|
||||
// @todo
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Device _io_dev;
|
||||
|
||||
image_read_settings< png_tag > _settings;
|
||||
image_read_info < png_tag > _info;
|
||||
|
||||
std::size_t _scanline_length;
|
||||
|
||||
std::size_t _number_passes;
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,167 @@
|
||||
//
|
||||
// Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
//
|
||||
// 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_PNG_DETAIL_SCANLINE_READ_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_SCANLINE_READ_HPP
|
||||
|
||||
#include <boost/gil/extension/io/png/detail/is_allowed.hpp>
|
||||
#include <boost/gil/extension/io/png/detail/reader_backend.hpp>
|
||||
|
||||
#include <boost/gil.hpp> // FIXME: Include what you use!
|
||||
#include <boost/gil/io/base.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>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
///
|
||||
/// PNG Reader
|
||||
///
|
||||
template< typename Device >
|
||||
class scanline_reader< Device
|
||||
, png_tag
|
||||
>
|
||||
: public reader_backend< Device
|
||||
, png_tag
|
||||
>
|
||||
{
|
||||
public:
|
||||
|
||||
using tag_t = png_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( const Device& io_dev
|
||||
, const image_read_settings< png_tag >& settings
|
||||
)
|
||||
: reader_backend< Device
|
||||
, png_tag
|
||||
>( io_dev
|
||||
, settings
|
||||
)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
void read( byte_t* dst
|
||||
, int
|
||||
)
|
||||
{
|
||||
read_scanline( dst );
|
||||
}
|
||||
|
||||
/// Skip over a scanline.
|
||||
void skip( byte_t* dst, int )
|
||||
{
|
||||
read_scanline( dst );
|
||||
}
|
||||
|
||||
iterator_t begin() { return iterator_t( *this ); }
|
||||
iterator_t end() { return iterator_t( *this, this->_info._height ); }
|
||||
|
||||
private:
|
||||
|
||||
void initialize()
|
||||
{
|
||||
// Now it's time for some transformations.
|
||||
|
||||
if( little_endian() )
|
||||
{
|
||||
if( this->_info._bit_depth == 16 )
|
||||
{
|
||||
// Swap bytes of 16 bit files to least significant byte first.
|
||||
png_set_swap( this->get()->_struct );
|
||||
}
|
||||
|
||||
if( this->_info._bit_depth < 8 )
|
||||
{
|
||||
// swap bits of 1, 2, 4 bit packed pixel formats
|
||||
png_set_packswap( this->get()->_struct );
|
||||
}
|
||||
}
|
||||
|
||||
if( this->_info._color_type == PNG_COLOR_TYPE_PALETTE )
|
||||
{
|
||||
png_set_palette_to_rgb( this->get()->_struct );
|
||||
}
|
||||
|
||||
if( this->_info._num_trans > 0 )
|
||||
{
|
||||
png_set_tRNS_to_alpha( this->get()->_struct );
|
||||
}
|
||||
|
||||
// Tell libpng to handle the gamma conversion for you. The final call
|
||||
// is a good guess for PC generated images, but it should be configurable
|
||||
// by the user at run time by the user. It is strongly suggested that
|
||||
// your application support gamma correction.
|
||||
if( this->_settings._apply_screen_gamma )
|
||||
{
|
||||
// png_set_gamma will change the image data!
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
png_set_gamma( this->get()->_struct
|
||||
, this->_settings._screen_gamma
|
||||
, this->_info._file_gamma
|
||||
);
|
||||
#else
|
||||
png_set_gamma( this->get()->_struct
|
||||
, this->_settings._screen_gamma
|
||||
, this->_info._file_gamma
|
||||
);
|
||||
#endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
}
|
||||
|
||||
// Interlaced images are not supported.
|
||||
this->_number_passes = png_set_interlace_handling( this->get()->_struct );
|
||||
io_error_if( this->_number_passes != 1
|
||||
, "scanline_read_iterator cannot read interlaced png images."
|
||||
);
|
||||
|
||||
|
||||
// The above transformation might have changed the bit_depth and color type.
|
||||
png_read_update_info( this->get()->_struct
|
||||
, this->get()->_info
|
||||
);
|
||||
|
||||
this->_info._bit_depth = png_get_bit_depth( this->get()->_struct
|
||||
, this->get()->_info
|
||||
);
|
||||
|
||||
this->_info._num_channels = png_get_channels( this->get()->_struct
|
||||
, this->get()->_info
|
||||
);
|
||||
|
||||
this->_info._color_type = png_get_color_type( this->get()->_struct
|
||||
, this->get()->_info
|
||||
);
|
||||
|
||||
this->_scanline_length = png_get_rowbytes( this->get()->_struct
|
||||
, this->get()->_info
|
||||
);
|
||||
}
|
||||
|
||||
void read_scanline( byte_t* dst )
|
||||
{
|
||||
png_read_row( this->get()->_struct
|
||||
, dst
|
||||
, NULL
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,362 @@
|
||||
//
|
||||
// Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
//
|
||||
// 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_PNG_DETAIL_SUPPORTED_TYPES_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_SUPPORTED_TYPES_HPP
|
||||
|
||||
#include <boost/gil/extension/io/png/tags.hpp>
|
||||
|
||||
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
#include <boost/gil/extension/toolbox/color_spaces/gray_alpha.hpp>
|
||||
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost { namespace gil { namespace detail {
|
||||
|
||||
static const size_t PNG_BYTES_TO_CHECK = 4;
|
||||
|
||||
// Read support
|
||||
template< png_bitdepth::type BitDepth
|
||||
, png_color_type::type ColorType
|
||||
>
|
||||
struct png_rw_support_base
|
||||
{
|
||||
static const png_bitdepth::type _bit_depth = BitDepth;
|
||||
static const png_color_type::type _color_type = ColorType;
|
||||
};
|
||||
|
||||
template< typename Channel
|
||||
, typename ColorSpace
|
||||
>
|
||||
struct png_read_support : read_support_false
|
||||
, png_rw_support_base< 1
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
> {};
|
||||
|
||||
template< typename BitField
|
||||
, bool Mutable
|
||||
>
|
||||
struct png_read_support< packed_dynamic_channel_reference< BitField
|
||||
, 1
|
||||
, Mutable
|
||||
>
|
||||
, gray_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 1
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
> {};
|
||||
|
||||
template< typename BitField
|
||||
, bool Mutable
|
||||
>
|
||||
struct png_read_support< packed_dynamic_channel_reference< BitField
|
||||
, 2
|
||||
, Mutable
|
||||
>
|
||||
, gray_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 2
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
> {};
|
||||
|
||||
template< typename BitField
|
||||
, bool Mutable
|
||||
>
|
||||
struct png_read_support< packed_dynamic_channel_reference< BitField
|
||||
, 4
|
||||
, Mutable
|
||||
>
|
||||
, gray_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 4
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
> {};
|
||||
|
||||
template<>
|
||||
struct png_read_support<uint8_t
|
||||
, gray_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 8
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
> {};
|
||||
|
||||
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
template<>
|
||||
struct png_read_support<uint8_t
|
||||
, gray_alpha_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 8
|
||||
, PNG_COLOR_TYPE_GA
|
||||
> {};
|
||||
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
|
||||
template<>
|
||||
struct png_read_support<uint8_t
|
||||
, rgb_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 8
|
||||
, PNG_COLOR_TYPE_RGB
|
||||
> {};
|
||||
|
||||
template<>
|
||||
struct png_read_support<uint8_t
|
||||
, rgba_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 8
|
||||
, PNG_COLOR_TYPE_RGBA
|
||||
> {};
|
||||
|
||||
template<>
|
||||
struct png_read_support<uint16_t
|
||||
, gray_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 16
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
> {};
|
||||
|
||||
template<>
|
||||
struct png_read_support<uint16_t
|
||||
, rgb_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 16
|
||||
, PNG_COLOR_TYPE_RGB
|
||||
> {};
|
||||
|
||||
template<>
|
||||
struct png_read_support<uint16_t
|
||||
, rgba_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 16
|
||||
, PNG_COLOR_TYPE_RGBA
|
||||
> {};
|
||||
|
||||
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
template<>
|
||||
struct png_read_support<uint16_t
|
||||
, gray_alpha_t
|
||||
> : read_support_true
|
||||
, png_rw_support_base< 16
|
||||
, PNG_COLOR_TYPE_GA
|
||||
> {};
|
||||
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
|
||||
// Write support
|
||||
|
||||
template< typename Channel
|
||||
, typename ColorSpace
|
||||
>
|
||||
struct png_write_support : write_support_false
|
||||
, png_rw_support_base< 1
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
> {};
|
||||
|
||||
template< typename BitField
|
||||
, bool Mutable
|
||||
>
|
||||
struct png_write_support< packed_dynamic_channel_reference< BitField
|
||||
, 1
|
||||
, Mutable
|
||||
>
|
||||
, gray_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 1
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
>
|
||||
{};
|
||||
|
||||
template< typename BitField
|
||||
, bool Mutable
|
||||
>
|
||||
struct png_write_support< packed_dynamic_channel_reference< BitField
|
||||
, 1
|
||||
, Mutable
|
||||
> const
|
||||
, gray_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 1
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
>
|
||||
{};
|
||||
|
||||
template< typename BitField
|
||||
, bool Mutable
|
||||
>
|
||||
struct png_write_support< packed_dynamic_channel_reference< BitField
|
||||
, 2
|
||||
, Mutable
|
||||
>
|
||||
, gray_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 2
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
>
|
||||
{};
|
||||
|
||||
template< typename BitField
|
||||
, bool Mutable
|
||||
>
|
||||
struct png_write_support< packed_dynamic_channel_reference< BitField
|
||||
, 2
|
||||
, Mutable
|
||||
> const
|
||||
, gray_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 2
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
>
|
||||
{};
|
||||
|
||||
template< typename BitField
|
||||
, bool Mutable
|
||||
>
|
||||
struct png_write_support< packed_dynamic_channel_reference< BitField
|
||||
, 4
|
||||
, Mutable
|
||||
>
|
||||
, gray_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 4
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
>
|
||||
{};
|
||||
|
||||
template< typename BitField
|
||||
, bool Mutable
|
||||
>
|
||||
struct png_write_support< packed_dynamic_channel_reference< BitField
|
||||
, 4
|
||||
, Mutable
|
||||
> const
|
||||
, gray_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 4
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
>
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct png_write_support<uint8_t
|
||||
, gray_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 8
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
>
|
||||
{};
|
||||
|
||||
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
template<>
|
||||
struct png_write_support<uint8_t
|
||||
, gray_alpha_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 8
|
||||
, PNG_COLOR_TYPE_GA
|
||||
>
|
||||
{};
|
||||
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
|
||||
template<>
|
||||
struct png_write_support<uint8_t
|
||||
, rgb_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 8
|
||||
, PNG_COLOR_TYPE_RGB
|
||||
>
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct png_write_support<uint8_t
|
||||
, rgba_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 8
|
||||
, PNG_COLOR_TYPE_RGBA
|
||||
>
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct png_write_support<uint16_t
|
||||
, gray_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 16
|
||||
, PNG_COLOR_TYPE_GRAY
|
||||
>
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct png_write_support<uint16_t
|
||||
, rgb_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 16
|
||||
, PNG_COLOR_TYPE_RGB
|
||||
>
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct png_write_support<uint16_t
|
||||
, rgba_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 16
|
||||
, PNG_COLOR_TYPE_RGBA
|
||||
>
|
||||
{};
|
||||
|
||||
#ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
template<>
|
||||
struct png_write_support<uint16_t
|
||||
, gray_alpha_t
|
||||
> : write_support_true
|
||||
, png_rw_support_base< 16
|
||||
, PNG_COLOR_TYPE_GA
|
||||
>
|
||||
{};
|
||||
#endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
|
||||
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template< typename Pixel >
|
||||
struct is_read_supported< Pixel
|
||||
, png_tag
|
||||
>
|
||||
: mpl::bool_< detail::png_read_support< typename channel_type< Pixel >::type
|
||||
, typename color_space_type< Pixel >::type
|
||||
>::is_supported
|
||||
>
|
||||
{
|
||||
using parent_t = detail::png_read_support
|
||||
<
|
||||
typename channel_type<Pixel>::type,
|
||||
typename color_space_type<Pixel>::type
|
||||
>;
|
||||
|
||||
static const png_bitdepth::type _bit_depth = parent_t::_bit_depth;
|
||||
static const png_color_type::type _color_type = parent_t::_color_type;
|
||||
};
|
||||
|
||||
template< typename Pixel >
|
||||
struct is_write_supported< Pixel
|
||||
, png_tag
|
||||
>
|
||||
: mpl::bool_< detail::png_write_support< typename channel_type< Pixel >::type
|
||||
, typename color_space_type< Pixel >::type
|
||||
>::is_supported
|
||||
>
|
||||
{
|
||||
using parent_t = detail::png_write_support
|
||||
<
|
||||
typename channel_type<Pixel>::type,
|
||||
typename color_space_type<Pixel>::type
|
||||
>;
|
||||
|
||||
static const png_bitdepth::type _bit_depth = parent_t::_bit_depth;
|
||||
static const png_color_type::type _color_type = parent_t::_color_type;
|
||||
};
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
239
macx64/include/boost/gil/extension/io/png/detail/write.hpp
Normal file
239
macx64/include/boost/gil/extension/io/png/detail/write.hpp
Normal file
@@ -0,0 +1,239 @@
|
||||
//
|
||||
// Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
//
|
||||
// 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_PNG_DETAIL_WRITE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_WRITE_HPP
|
||||
|
||||
#include <boost/gil/extension/io/png/detail/writer_backend.hpp>
|
||||
|
||||
#include <boost/gil/io/device.hpp>
|
||||
#include <boost/gil/io/dynamic_io_new.hpp>
|
||||
#include <boost/gil/io/row_buffer_helper.hpp>
|
||||
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/equal_to.hpp>
|
||||
#include <boost/mpl/less.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
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 {
|
||||
|
||||
struct png_write_is_supported
|
||||
{
|
||||
template< typename View >
|
||||
struct apply
|
||||
: public is_write_supported< typename get_pixel_type< View >::type
|
||||
, png_tag
|
||||
>
|
||||
{};
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
///
|
||||
/// PNG Writer
|
||||
///
|
||||
template< typename Device >
|
||||
class writer< Device
|
||||
, png_tag
|
||||
>
|
||||
: public writer_backend< Device
|
||||
, png_tag
|
||||
>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
using backend_t = writer_backend<Device, png_tag>;
|
||||
|
||||
writer( const Device& io_dev
|
||||
, const image_write_info< png_tag >& info
|
||||
)
|
||||
: backend_t( io_dev
|
||||
, info
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
template< typename View >
|
||||
void apply( const View& view )
|
||||
{
|
||||
io_error_if( view.width() == 0 && view.height() == 0
|
||||
, "png format cannot handle empty views."
|
||||
);
|
||||
|
||||
this->write_header( view );
|
||||
|
||||
write_view( view
|
||||
, typename is_bit_aligned< typename View::value_type >::type()
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template<typename View>
|
||||
void write_view( const View& view
|
||||
, mpl::false_ // is bit aligned
|
||||
)
|
||||
{
|
||||
using pixel_t = typename get_pixel_type<View>::type;
|
||||
|
||||
using png_rw_info = detail::png_write_support
|
||||
<
|
||||
typename channel_type<pixel_t>::type,
|
||||
typename color_space_type<pixel_t>::type
|
||||
>;
|
||||
|
||||
if( little_endian() )
|
||||
{
|
||||
set_swap< png_rw_info >();
|
||||
}
|
||||
|
||||
std::vector< pixel< typename channel_type< View >::type
|
||||
, layout<typename color_space_type< View >::type >
|
||||
>
|
||||
> row_buffer( view.width() );
|
||||
|
||||
for( int y = 0; y != view.height(); ++ y)
|
||||
{
|
||||
std::copy( view.row_begin( y )
|
||||
, view.row_end ( y )
|
||||
, row_buffer.begin()
|
||||
);
|
||||
|
||||
png_write_row( this->get_struct()
|
||||
, reinterpret_cast< png_bytep >( row_buffer.data() )
|
||||
);
|
||||
}
|
||||
|
||||
png_write_end( this->get_struct()
|
||||
, this->get_info()
|
||||
);
|
||||
}
|
||||
|
||||
template<typename View>
|
||||
void write_view( const View& view
|
||||
, mpl::true_ // is bit aligned
|
||||
)
|
||||
{
|
||||
using png_rw_info = detail::png_write_support
|
||||
<
|
||||
typename kth_semantic_element_type<typename View::value_type, 0>::type,
|
||||
typename color_space_type<View>::type
|
||||
>;
|
||||
|
||||
if (little_endian() )
|
||||
{
|
||||
set_swap< png_rw_info >();
|
||||
}
|
||||
|
||||
detail::row_buffer_helper_view< View > row_buffer( view.width()
|
||||
, false
|
||||
);
|
||||
|
||||
for( int y = 0; y != view.height(); ++y )
|
||||
{
|
||||
std::copy( view.row_begin( y )
|
||||
, view.row_end ( y )
|
||||
, row_buffer.begin()
|
||||
);
|
||||
|
||||
png_write_row( this->get_struct()
|
||||
, reinterpret_cast< png_bytep >( row_buffer.data() )
|
||||
);
|
||||
}
|
||||
|
||||
png_free_data( this->get_struct()
|
||||
, this->get_info()
|
||||
, PNG_FREE_UNKN
|
||||
, -1
|
||||
);
|
||||
|
||||
png_write_end( this->get_struct()
|
||||
, this->get_info()
|
||||
);
|
||||
}
|
||||
|
||||
template< typename Info > struct is_less_than_eight : mpl::less< mpl::int_< Info::_bit_depth >, mpl::int_< 8 > > {};
|
||||
template< typename Info > struct is_equal_to_sixteen : mpl::equal_to< mpl::int_< Info::_bit_depth >, mpl::int_< 16 > > {};
|
||||
|
||||
template <typename Info>
|
||||
void set_swap(typename std::enable_if<is_less_than_eight<Info>::value>::type* /*ptr*/ = 0)
|
||||
{
|
||||
png_set_packswap(this->get_struct());
|
||||
}
|
||||
|
||||
template <typename Info>
|
||||
void set_swap(typename std::enable_if<is_equal_to_sixteen<Info>::value>::type* /*ptr*/ = 0)
|
||||
{
|
||||
png_set_swap(this->get_struct());
|
||||
}
|
||||
|
||||
template <typename Info>
|
||||
void set_swap(
|
||||
typename std::enable_if
|
||||
<
|
||||
mpl::and_
|
||||
<
|
||||
mpl::not_<is_less_than_eight<Info>>,
|
||||
mpl::not_<is_equal_to_sixteen<Info>>
|
||||
>::value
|
||||
>::type* /*ptr*/ = nullptr)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
///
|
||||
/// PNG Dynamic Image Writer
|
||||
///
|
||||
template< typename Device >
|
||||
class dynamic_image_writer< Device
|
||||
, png_tag
|
||||
>
|
||||
: public writer< Device
|
||||
, png_tag
|
||||
>
|
||||
{
|
||||
using parent_t = writer<Device, png_tag>;
|
||||
|
||||
public:
|
||||
|
||||
dynamic_image_writer( const Device& io_dev
|
||||
, const image_write_info< png_tag >& info
|
||||
)
|
||||
: parent_t( io_dev
|
||||
, info
|
||||
)
|
||||
{}
|
||||
|
||||
template< typename Views >
|
||||
void apply( const any_image_view< Views >& views )
|
||||
{
|
||||
detail::dynamic_io_fnobj< detail::png_write_is_supported
|
||||
, parent_t
|
||||
> op( this );
|
||||
|
||||
apply_operation( views, op );
|
||||
}
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,502 @@
|
||||
//
|
||||
// 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_PNG_DETAIL_WRITER_BACKEND_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_WRITER_BACKEND_HPP
|
||||
|
||||
#include <boost/gil/extension/io/png/tags.hpp>
|
||||
#include <boost/gil/extension/io/png/detail/base.hpp>
|
||||
#include <boost/gil/extension/io/png/detail/supported_types.hpp>
|
||||
|
||||
#include <boost/gil/io/base.hpp>
|
||||
#include <boost/gil/io/typedefs.hpp>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4512) //assignment operator could not be generated
|
||||
#pragma warning(disable:4611) //interaction between '_setjmp' and C++ object destruction is non-portable
|
||||
#endif
|
||||
|
||||
///
|
||||
/// PNG Writer Backend
|
||||
///
|
||||
template< typename Device >
|
||||
struct writer_backend< Device
|
||||
, png_tag
|
||||
>
|
||||
: public detail::png_struct_info_wrapper
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
using this_t = writer_backend<Device, png_tag>;
|
||||
|
||||
public:
|
||||
|
||||
using format_tag_t = png_tag;
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
writer_backend( const Device& io_dev
|
||||
, const image_write_info< png_tag >& info
|
||||
)
|
||||
: png_struct_info_wrapper( false )
|
||||
, _io_dev( io_dev )
|
||||
, _info( info )
|
||||
{
|
||||
// Create and initialize the png_struct with the desired error handler
|
||||
// functions. If you want to use the default stderr and longjump method,
|
||||
// you can supply NULL for the last three parameters. We also check that
|
||||
// the library version is compatible with the one used at compile time,
|
||||
// in case we are using dynamically linked libraries. REQUIRED.
|
||||
get()->_struct = png_create_write_struct( PNG_LIBPNG_VER_STRING
|
||||
, nullptr // user_error_ptr
|
||||
, nullptr // user_error_fn
|
||||
, nullptr // user_warning_fn
|
||||
);
|
||||
|
||||
io_error_if( get_struct() == nullptr
|
||||
, "png_writer: fail to call png_create_write_struct()"
|
||||
);
|
||||
|
||||
// Allocate/initialize the image information data. REQUIRED
|
||||
get()->_info = png_create_info_struct( get_struct() );
|
||||
|
||||
if( get_info() == nullptr )
|
||||
{
|
||||
png_destroy_write_struct( &get()->_struct
|
||||
, nullptr
|
||||
);
|
||||
|
||||
io_error( "png_writer: fail to call png_create_info_struct()" );
|
||||
}
|
||||
|
||||
// Set error handling. REQUIRED if you aren't supplying your own
|
||||
// error handling functions in the png_create_write_struct() call.
|
||||
if( setjmp( png_jmpbuf( get_struct() )))
|
||||
{
|
||||
//free all of the memory associated with the png_ptr and info_ptr
|
||||
png_destroy_write_struct( &get()->_struct
|
||||
, &get()->_info
|
||||
);
|
||||
|
||||
io_error( "png_writer: fail to call setjmp()" );
|
||||
}
|
||||
|
||||
init_io( get_struct() );
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
template< typename View >
|
||||
void write_header( const View& view )
|
||||
{
|
||||
using png_rw_info_t = detail::png_write_support
|
||||
<
|
||||
typename channel_type<typename get_pixel_type<View>::type>::type,
|
||||
typename color_space_type<View>::type
|
||||
>;
|
||||
|
||||
// Set the image information here. Width and height are up to 2^31,
|
||||
// bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
|
||||
// the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
|
||||
// PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
|
||||
// or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
|
||||
// PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
|
||||
// currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
|
||||
png_set_IHDR( get_struct()
|
||||
, get_info()
|
||||
, static_cast< png_image_width::type >( view.width() )
|
||||
, static_cast< png_image_height::type >( view.height() )
|
||||
, static_cast< png_bitdepth::type >( png_rw_info_t::_bit_depth )
|
||||
, static_cast< png_color_type::type >( png_rw_info_t::_color_type )
|
||||
, _info._interlace_method
|
||||
, _info._compression_type
|
||||
, _info._filter_method
|
||||
);
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
if( _info._valid_cie_colors )
|
||||
{
|
||||
png_set_cHRM( get_struct()
|
||||
, get_info()
|
||||
, _info._white_x
|
||||
, _info._white_y
|
||||
, _info._red_x
|
||||
, _info._red_y
|
||||
, _info._green_x
|
||||
, _info._green_y
|
||||
, _info._blue_x
|
||||
, _info._blue_y
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_file_gamma )
|
||||
{
|
||||
png_set_gAMA( get_struct()
|
||||
, get_info()
|
||||
, _info._file_gamma
|
||||
);
|
||||
}
|
||||
#else
|
||||
if( _info._valid_cie_colors )
|
||||
{
|
||||
png_set_cHRM_fixed( get_struct()
|
||||
, get_info()
|
||||
, _info._white_x
|
||||
, _info._white_y
|
||||
, _info._red_x
|
||||
, _info._red_y
|
||||
, _info._green_x
|
||||
, _info._green_y
|
||||
, _info._blue_x
|
||||
, _info._blue_y
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_file_gamma )
|
||||
{
|
||||
png_set_gAMA_fixed( get_struct()
|
||||
, get_info()
|
||||
, _info._file_gamma
|
||||
);
|
||||
}
|
||||
#endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
if( _info._valid_icc_profile )
|
||||
{
|
||||
#if PNG_LIBPNG_VER_MINOR >= 5
|
||||
png_set_iCCP( get_struct()
|
||||
, get_info()
|
||||
, const_cast< png_charp >( _info._icc_name.c_str() )
|
||||
, _info._iccp_compression_type
|
||||
, reinterpret_cast< png_const_bytep >( & (_info._profile.front ()) )
|
||||
, _info._profile_length
|
||||
);
|
||||
#else
|
||||
png_set_iCCP( get_struct()
|
||||
, get_info()
|
||||
, const_cast< png_charp >( _info._icc_name.c_str() )
|
||||
, _info._iccp_compression_type
|
||||
, const_cast< png_charp >( & (_info._profile.front()) )
|
||||
, _info._profile_length
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
if( _info._valid_intent )
|
||||
{
|
||||
png_set_sRGB( get_struct()
|
||||
, get_info()
|
||||
, _info._intent
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_palette )
|
||||
{
|
||||
png_set_PLTE( get_struct()
|
||||
, get_info()
|
||||
, const_cast< png_colorp >( &_info._palette.front() )
|
||||
, _info._num_palette
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_background )
|
||||
{
|
||||
png_set_bKGD( get_struct()
|
||||
, get_info()
|
||||
, const_cast< png_color_16p >( &_info._background )
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_histogram )
|
||||
{
|
||||
png_set_hIST( get_struct()
|
||||
, get_info()
|
||||
, const_cast< png_uint_16p >( &_info._histogram.front() )
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_offset )
|
||||
{
|
||||
png_set_oFFs( get_struct()
|
||||
, get_info()
|
||||
, _info._offset_x
|
||||
, _info._offset_y
|
||||
, _info._off_unit_type
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_pixel_calibration )
|
||||
{
|
||||
std::vector< const char* > params( _info._num_params );
|
||||
for( std::size_t i = 0; i < params.size(); ++i )
|
||||
{
|
||||
params[i] = _info._params[ i ].c_str();
|
||||
}
|
||||
|
||||
png_set_pCAL( get_struct()
|
||||
, get_info()
|
||||
, const_cast< png_charp >( _info._purpose.c_str() )
|
||||
, _info._X0
|
||||
, _info._X1
|
||||
, _info._cal_type
|
||||
, _info._num_params
|
||||
, const_cast< png_charp >( _info._units.c_str() )
|
||||
, const_cast< png_charpp >( ¶ms.front() )
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_resolution )
|
||||
{
|
||||
png_set_pHYs( get_struct()
|
||||
, get_info()
|
||||
, _info._res_x
|
||||
, _info._res_y
|
||||
, _info._phy_unit_type
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_significant_bits )
|
||||
{
|
||||
png_set_sBIT( get_struct()
|
||||
, get_info()
|
||||
, const_cast< png_color_8p >( &_info._sig_bits )
|
||||
);
|
||||
}
|
||||
|
||||
#ifndef BOOST_GIL_IO_PNG_1_4_OR_LOWER
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
if( _info._valid_scale_factors )
|
||||
{
|
||||
png_set_sCAL( get_struct()
|
||||
, get_info()
|
||||
, this->_info._scale_unit
|
||||
, this->_info._scale_width
|
||||
, this->_info._scale_height
|
||||
);
|
||||
}
|
||||
#else
|
||||
#ifdef BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
|
||||
if( _info._valid_scale_factors )
|
||||
{
|
||||
png_set_sCAL_fixed( get_struct()
|
||||
, get_info()
|
||||
, this->_info._scale_unit
|
||||
, this->_info._scale_width
|
||||
, this->_info._scale_height
|
||||
);
|
||||
}
|
||||
#else
|
||||
if( _info._valid_scale_factors )
|
||||
{
|
||||
png_set_sCAL_s( get_struct()
|
||||
, get_info()
|
||||
, this->_info._scale_unit
|
||||
, const_cast< png_charp >( this->_info._scale_width.c_str() )
|
||||
, const_cast< png_charp >( this->_info._scale_height.c_str() )
|
||||
);
|
||||
}
|
||||
|
||||
#endif // BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
|
||||
#endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
#endif // BOOST_GIL_IO_PNG_1_4_OR_LOWER
|
||||
|
||||
if( _info._valid_text )
|
||||
{
|
||||
std::vector< png_text > texts( _info._num_text );
|
||||
for( std::size_t i = 0; i < texts.size(); ++i )
|
||||
{
|
||||
png_text pt;
|
||||
pt.compression = _info._text[i]._compression;
|
||||
pt.key = const_cast< png_charp >( this->_info._text[i]._key.c_str() );
|
||||
pt.text = const_cast< png_charp >( this->_info._text[i]._text.c_str() );
|
||||
pt.text_length = _info._text[i]._text.length();
|
||||
|
||||
texts[i] = pt;
|
||||
}
|
||||
|
||||
png_set_text( get_struct()
|
||||
, get_info()
|
||||
, &texts.front()
|
||||
, _info._num_text
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_modification_time )
|
||||
{
|
||||
png_set_tIME( get_struct()
|
||||
, get_info()
|
||||
, const_cast< png_timep >( &_info._mod_time )
|
||||
);
|
||||
}
|
||||
|
||||
if( _info._valid_transparency_factors )
|
||||
{
|
||||
int sample_max = ( 1u << _info._bit_depth );
|
||||
|
||||
/* libpng doesn't reject a tRNS chunk with out-of-range samples */
|
||||
if( !( ( _info._color_type == PNG_COLOR_TYPE_GRAY
|
||||
&& (int) _info._trans_values[0].gray > sample_max
|
||||
)
|
||||
|| ( _info._color_type == PNG_COLOR_TYPE_RGB
|
||||
&&( (int) _info._trans_values[0].red > sample_max
|
||||
|| (int) _info._trans_values[0].green > sample_max
|
||||
|| (int) _info._trans_values[0].blue > sample_max
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
//@todo Fix that once reading transparency values works
|
||||
/*
|
||||
png_set_tRNS( get_struct()
|
||||
, get_info()
|
||||
, trans
|
||||
, num_trans
|
||||
, trans_values
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// Compression Levels - valid values are [0,9]
|
||||
png_set_compression_level( get_struct()
|
||||
, _info._compression_level
|
||||
);
|
||||
|
||||
png_set_compression_mem_level( get_struct()
|
||||
, _info._compression_mem_level
|
||||
);
|
||||
|
||||
png_set_compression_strategy( get_struct()
|
||||
, _info._compression_strategy
|
||||
);
|
||||
|
||||
png_set_compression_window_bits( get_struct()
|
||||
, _info._compression_window_bits
|
||||
);
|
||||
|
||||
png_set_compression_method( get_struct()
|
||||
, _info._compression_method
|
||||
);
|
||||
|
||||
png_set_compression_buffer_size( get_struct()
|
||||
, _info._compression_buffer_size
|
||||
);
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_DITHERING_SUPPORTED
|
||||
// Dithering
|
||||
if( _info._set_dithering )
|
||||
{
|
||||
png_set_dither( get_struct()
|
||||
, &_info._dithering_palette.front()
|
||||
, _info._dithering_num_palette
|
||||
, _info._dithering_maximum_colors
|
||||
, &_info._dithering_histogram.front()
|
||||
, _info._full_dither
|
||||
);
|
||||
}
|
||||
#endif // BOOST_GIL_IO_PNG_DITHERING_SUPPORTED
|
||||
|
||||
// Filter
|
||||
if( _info._set_filter )
|
||||
{
|
||||
png_set_filter( get_struct()
|
||||
, 0
|
||||
, _info._filter
|
||||
);
|
||||
}
|
||||
|
||||
// Invert Mono
|
||||
if( _info._invert_mono )
|
||||
{
|
||||
png_set_invert_mono( get_struct() );
|
||||
}
|
||||
|
||||
// True Bits
|
||||
if( _info._set_true_bits )
|
||||
{
|
||||
png_set_sBIT( get_struct()
|
||||
, get_info()
|
||||
, &_info._true_bits.front()
|
||||
);
|
||||
}
|
||||
|
||||
// sRGB Intent
|
||||
if( _info._set_srgb_intent )
|
||||
{
|
||||
png_set_sRGB( get_struct()
|
||||
, get_info()
|
||||
, _info._srgb_intent
|
||||
);
|
||||
}
|
||||
|
||||
// Strip Alpha
|
||||
if( _info._strip_alpha )
|
||||
{
|
||||
png_set_strip_alpha( get_struct() );
|
||||
}
|
||||
|
||||
// Swap Alpha
|
||||
if( _info._swap_alpha )
|
||||
{
|
||||
png_set_swap_alpha( get_struct() );
|
||||
}
|
||||
|
||||
|
||||
png_write_info( get_struct()
|
||||
, get_info()
|
||||
);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
static void write_data( png_structp png_ptr
|
||||
, png_bytep data
|
||||
, png_size_t length
|
||||
)
|
||||
{
|
||||
static_cast< Device* >( png_get_io_ptr( png_ptr ))->write( data
|
||||
, length );
|
||||
}
|
||||
|
||||
static void flush( png_structp png_ptr )
|
||||
{
|
||||
static_cast< Device* >(png_get_io_ptr(png_ptr) )->flush();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void init_io( png_structp png_ptr )
|
||||
{
|
||||
png_set_write_fn( png_ptr
|
||||
, static_cast< void* > ( &this->_io_dev )
|
||||
, static_cast< png_rw_ptr > ( &this_t::write_data )
|
||||
, static_cast< png_flush_ptr >( &this_t::flush )
|
||||
);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Device _io_dev;
|
||||
|
||||
image_write_info< png_tag > _info;
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
159
macx64/include/boost/gil/extension/io/png/old.hpp
Normal file
159
macx64/include/boost/gil/extension/io/png/old.hpp
Normal file
@@ -0,0 +1,159 @@
|
||||
//
|
||||
// Copyright 2007-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_PNG_OLD_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_OLD_HPP
|
||||
|
||||
#include <boost/gil/extension/io/png.hpp>
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
/// \ingroup PNG_IO
|
||||
/// \brief Returns the width and height of the PNG file at the specified location.
|
||||
/// Throws std::ios_base::failure if the location does not correspond to a valid PNG file
|
||||
template<typename String>
|
||||
inline point_t png_read_dimensions(String const& filename)
|
||||
{
|
||||
using backend_t = typename get_reader_backend<String, png_tag>::type;
|
||||
backend_t backend = read_image_info(filename, png_tag());
|
||||
return { backend._info._width, backend._info._height };
|
||||
}
|
||||
|
||||
/// \ingroup PNG_IO
|
||||
/// \brief Loads the image specified by the given png image file name into the given view.
|
||||
/// Triggers a compile assert if the view color space and channel depth are not supported by the PNG library or by the I/O extension.
|
||||
/// Throws std::ios_base::failure if the file is not a valid PNG 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 png_read_view( const String& filename
|
||||
, const View& view
|
||||
)
|
||||
{
|
||||
read_view( filename
|
||||
, view
|
||||
, png_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup PNG_IO
|
||||
/// \brief Allocates a new image whose dimensions are determined by the given png 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 PNG library or by the I/O extension.
|
||||
/// Throws std::ios_base::failure if the file is not a valid PNG 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 png_read_image( const String& filename
|
||||
, Image& img
|
||||
)
|
||||
{
|
||||
read_image( filename
|
||||
, img
|
||||
, png_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup PNG_IO
|
||||
/// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
|
||||
/// Throws std::ios_base::failure if the file is not a valid PNG file, or if its dimensions don't match the ones of the view.
|
||||
template< typename String
|
||||
, typename View
|
||||
, typename CC
|
||||
>
|
||||
inline
|
||||
void png_read_and_convert_view( const String& filename
|
||||
, const View& view
|
||||
, CC cc
|
||||
)
|
||||
{
|
||||
read_and_convert_view( filename
|
||||
, view
|
||||
, cc
|
||||
, png_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup PNG_IO
|
||||
/// \brief Loads the image specified by the given png image file name and color-converts it into the given view.
|
||||
/// Throws std::ios_base::failure if the file is not a valid PNG file, or if its dimensions don't match the ones of the view.
|
||||
template< typename String
|
||||
, typename View
|
||||
>
|
||||
inline
|
||||
void png_read_and_convert_view( const String& filename
|
||||
, const View& view
|
||||
)
|
||||
{
|
||||
read_and_convert_view( filename
|
||||
, view
|
||||
, png_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup PNG_IO
|
||||
/// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
|
||||
/// Throws std::ios_base::failure if the file is not a valid PNG file
|
||||
template< typename String
|
||||
, typename Image
|
||||
, typename CC
|
||||
>
|
||||
inline
|
||||
void png_read_and_convert_image( const String& filename
|
||||
, Image& img
|
||||
, CC cc
|
||||
)
|
||||
{
|
||||
read_and_convert_image( filename
|
||||
, img
|
||||
, cc
|
||||
, png_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup PNG_IO
|
||||
/// \brief Allocates a new image whose dimensions are determined by the given png image file, loads and color-converts the pixels into it.
|
||||
/// Throws std::ios_base::failure if the file is not a valid PNG file
|
||||
template< typename String
|
||||
, typename Image
|
||||
>
|
||||
inline
|
||||
void png_read_and_convert_image( const String filename
|
||||
, Image& img
|
||||
)
|
||||
{
|
||||
read_and_convert_image( filename
|
||||
, img
|
||||
, png_tag()
|
||||
);
|
||||
}
|
||||
|
||||
/// \ingroup PNG_IO
|
||||
/// \brief Saves the view to a png file specified by the given png image file name.
|
||||
/// Triggers a compile assert if the view color space and channel depth are not supported by the PNG 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 png_write_view( const String& filename
|
||||
, const View& view
|
||||
)
|
||||
{
|
||||
write_view( filename
|
||||
, view
|
||||
, png_tag()
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
30
macx64/include/boost/gil/extension/io/png/read.hpp
Normal file
30
macx64/include/boost/gil/extension/io/png/read.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Copyright 2007-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_PNG_READ_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_READ_HPP
|
||||
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_READ_ENABLED // TODO: Document, explain, review
|
||||
|
||||
#include <boost/gil/extension/io/png/tags.hpp>
|
||||
#include <boost/gil/extension/io/png/detail/read.hpp>
|
||||
#include <boost/gil/extension/io/png/detail/scanline_read.hpp>
|
||||
#include <boost/gil/extension/io/png/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
|
||||
833
macx64/include/boost/gil/extension/io/png/tags.hpp
Normal file
833
macx64/include/boost/gil/extension/io/png/tags.hpp
Normal file
@@ -0,0 +1,833 @@
|
||||
//
|
||||
// Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
|
||||
//
|
||||
// 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_PNG_TAGS_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_TAGS_HPP
|
||||
|
||||
#include <boost/gil/io/base.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
#ifdef BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
|
||||
# error "Cannot set both symbols"
|
||||
#endif // BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
|
||||
#endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_PNG_C_LIB_COMPILED_AS_CPLUSPLUS
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <png.h>
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_PNG_C_LIB_COMPILED_AS_CPLUSPLUS
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_ZLIB_C_LIB_COMPILED_AS_CPLUSPLUS
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <zlib.h>
|
||||
#ifndef BOOST_GIL_EXTENSION_IO_ZLIB_C_LIB_COMPILED_AS_CPLUSPLUS
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PNG_LIBPNG_VER_MAJOR == 1
|
||||
#if PNG_LIBPNG_VER_MINOR <= 4
|
||||
#define BOOST_GIL_IO_PNG_1_4_OR_LOWER
|
||||
#endif // PNG_LIBPNG_VER_MAJOR == 1
|
||||
#endif // PNG_LIBPNG_VER_MINOR <= 4
|
||||
|
||||
namespace boost { namespace gil {
|
||||
|
||||
/// Defines png tag.
|
||||
struct png_tag : format_tag {};
|
||||
|
||||
/// see http://en.wikipedia.org/wiki/Portable_Network_Graphics for reference
|
||||
|
||||
/// Defines type for image width property.
|
||||
struct png_image_width : property_base< png_uint_32 > {};
|
||||
|
||||
/// Defines type for image height property.
|
||||
struct png_image_height : property_base< png_uint_32 > {};
|
||||
|
||||
/// Defines type for interlace method property.
|
||||
struct png_interlace_method : property_base< int > {};
|
||||
|
||||
/// Defines type for filter method property.
|
||||
struct png_filter_method : property_base< int > {};
|
||||
|
||||
/// Defines type for bit depth method property.
|
||||
struct png_bitdepth : property_base< int > {};
|
||||
|
||||
/// Defines type for bit depth method property.
|
||||
struct png_color_type : property_base< int > {};
|
||||
|
||||
/// Defines type for number of channels property.
|
||||
struct png_num_channels : property_base< png_byte > {};
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
/// Defines type for CIE chromacities property.
|
||||
struct png_chromacities_type : property_base< double > {};
|
||||
|
||||
/// Defines type for gamma correction property.
|
||||
struct png_gamma : property_base< double > {};
|
||||
|
||||
/// Defines type for physical scale unit property.
|
||||
struct png_unit : property_base< int > {};
|
||||
|
||||
/// Defines type for physical scale property.
|
||||
struct png_scale : property_base< double > {};
|
||||
|
||||
#else
|
||||
/// Defines type for CIE chromacities property.
|
||||
struct png_chromacities_type : property_base< png_fixed_point > {};
|
||||
|
||||
/// Defines type for gamma correction property.
|
||||
struct png_gamma : property_base< png_fixed_point > {};
|
||||
|
||||
/// Defines type for physical scale unit property.
|
||||
struct png_unit : property_base< int > {};
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
|
||||
/// Defines type for physical scale property.
|
||||
struct png_scale : property_base< png_fixed_point > {};
|
||||
#else
|
||||
/// Defines type for physical scale property.
|
||||
struct png_scale : property_base< std::string > {};
|
||||
#endif // BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
|
||||
|
||||
#endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
/// Returns image resolution in pixels per meter, from pHYs chunk data.
|
||||
struct png_pixels_per_meter : property_base< png_uint_32 > {};
|
||||
|
||||
/// Defines type for ICC profile name property.
|
||||
struct png_ICC_name : property_base< std::string > {};
|
||||
/// Defines type for ICC profile property.
|
||||
#if PNG_LIBPNG_VER_MINOR >= 5
|
||||
struct png_ICC_profile : property_base< std:: vector <uint8_t> > {};
|
||||
#else
|
||||
struct png_ICC_profile : property_base< std:: vector <char> > {};
|
||||
#endif
|
||||
/// Defines type for ICC profile length property.
|
||||
struct png_ICC_profile_length : property_base< png_uint_32 > {};
|
||||
/// Defines type for ICC compression property.
|
||||
struct png_ICC_compression_type : property_base< int > {};
|
||||
|
||||
/// Defines type for rendering intent property.
|
||||
struct png_intent : property_base< int > {};
|
||||
|
||||
/// Defines type for color palette property.
|
||||
struct png_color_palette : property_base< std::vector< png_color > > {};
|
||||
/// Defines type for number of colors property.
|
||||
struct png_num_palette : property_base< int > {};
|
||||
|
||||
/// Defines type for background property.
|
||||
struct png_background : property_base< png_color_16 > {};
|
||||
|
||||
/// Defines type for histogram property.
|
||||
struct png_histrogram : property_base< std::vector< png_uint_16 > > {};
|
||||
|
||||
/// Defines type for screen offset property.
|
||||
struct png_offset : property_base< png_int_32 > {};
|
||||
/// Defines type for screen offset type property.
|
||||
struct png_offset_type : property_base< int > {};
|
||||
|
||||
/// Defines type pixel calibration for property.
|
||||
struct png_CAL : property_base< std::string > {};
|
||||
/// Defines type for pixel calibration parameters property.
|
||||
struct png_CAL_params : property_base< std::vector< std::string > > {};
|
||||
/// Defines type for pixel calibration x property.
|
||||
struct png_CAL_X : property_base< png_int_32 > {};
|
||||
/// Defines type for pixel calibration type property.
|
||||
struct png_CAL_type : property_base< int > {};
|
||||
/// Defines type for number of pixel calibration properties.
|
||||
struct png_CAL_nparam : property_base< int > {};
|
||||
|
||||
/// Defines type for physical resolution property.
|
||||
struct png_resolution : property_base< png_uint_32 > {};
|
||||
/// Defines type for physical resolution unit property.
|
||||
struct png_unit_type : property_base< int > {};
|
||||
|
||||
/// Defines type for significant bits property.
|
||||
struct png_significant_bits : property_base< png_color_8 > {};
|
||||
|
||||
/// Helper structure for reading text property.
|
||||
struct gil_io_png_text
|
||||
{
|
||||
/// Compression type
|
||||
int _compression;
|
||||
// Key
|
||||
std::string _key;
|
||||
/// Text
|
||||
std::string _text;
|
||||
};
|
||||
|
||||
/// Defines type for text property.
|
||||
struct png_text_ : property_base< std::vector< gil_io_png_text > > {};
|
||||
/// Defines type for number of text property.
|
||||
struct png_num_text : property_base< int > {};
|
||||
|
||||
/// Defines type for modification time property.
|
||||
struct png_mod_time : property_base< png_time > {};
|
||||
|
||||
/// Defines type for transparency data property.
|
||||
struct png_trans : property_base< std::vector< png_byte > > {};
|
||||
/// Defines type for number of transparency data property.
|
||||
struct png_num_trans : property_base< int > {};
|
||||
/// Defines type for transparency data values property.
|
||||
struct png_trans_values : property_base< std::vector< png_color_16 > > {};
|
||||
|
||||
/// Defines type for png function return type.
|
||||
struct png_return_value : property_base< png_uint_32 > {};
|
||||
|
||||
////////////////////////
|
||||
// Write properties
|
||||
////////////////////////
|
||||
|
||||
// relates to info_ptr->compression_type
|
||||
struct png_compression_type : property_base< png_byte >
|
||||
{
|
||||
static const type default_value = PNG_COMPRESSION_TYPE_BASE;
|
||||
};
|
||||
|
||||
// compression level - default values taken from libpng manual.
|
||||
// Look for png_set_compression_level
|
||||
struct png_compression_level : property_base< int >
|
||||
{
|
||||
static const type default_value = 3;
|
||||
};
|
||||
|
||||
struct png_compression_mem_level : property_base< int >
|
||||
{
|
||||
static const type default_value = MAX_MEM_LEVEL;
|
||||
};
|
||||
|
||||
struct png_compression_strategy : property_base< int >
|
||||
{
|
||||
static const type default_value = Z_DEFAULT_STRATEGY;
|
||||
};
|
||||
|
||||
struct png_compression_window_bits : property_base< int >
|
||||
{
|
||||
static const type default_value = 9;
|
||||
};
|
||||
|
||||
struct png_compression_method : property_base< int >
|
||||
{
|
||||
static const type default_value = 8;
|
||||
};
|
||||
|
||||
struct png_compression_buffer_size : property_base< int >
|
||||
{
|
||||
static const type default_value = 8192;
|
||||
};
|
||||
|
||||
// dithering
|
||||
struct png_dithering_palette : property_base< std::vector< png_color > >
|
||||
{};
|
||||
|
||||
struct png_dithering_num_palette : property_base< int >
|
||||
{
|
||||
static const type default_value = 0;
|
||||
};
|
||||
|
||||
struct png_dithering_maximum_colors : property_base< int >
|
||||
{
|
||||
static const type default_value = 0;
|
||||
};
|
||||
|
||||
struct png_dithering_histogram : property_base< std::vector< png_uint_16 > >
|
||||
{};
|
||||
|
||||
struct png_full_dither : property_base< int >
|
||||
{
|
||||
static const type default_value = 0;
|
||||
};
|
||||
|
||||
// filter
|
||||
struct png_filter : property_base< int >
|
||||
{
|
||||
static const type default_value = 0;
|
||||
};
|
||||
|
||||
// invert mono
|
||||
struct png_invert_mono : property_base< bool >
|
||||
{
|
||||
static const type default_value = false;
|
||||
};
|
||||
|
||||
// true bits
|
||||
struct png_true_bits : property_base< std::vector< png_color_8 > >
|
||||
{};
|
||||
|
||||
// sRGB Intent
|
||||
struct png_srgb_intent : property_base< int >
|
||||
{
|
||||
static const type default_value = 0;
|
||||
};
|
||||
|
||||
// strip alpha
|
||||
struct png_strip_alpha : property_base< bool >
|
||||
{
|
||||
static const type default_value = false;
|
||||
};
|
||||
|
||||
struct png_swap_alpha : property_base< bool >
|
||||
{
|
||||
static const type default_value = false;
|
||||
};
|
||||
|
||||
|
||||
/// PNG info base class. Containing all header information both for reading and writing.
|
||||
///
|
||||
/// This base structure was created to avoid code doubling.
|
||||
struct png_info_base
|
||||
{
|
||||
/// Default constructor
|
||||
png_info_base()
|
||||
: _width ( 0 )
|
||||
, _height( 0 )
|
||||
|
||||
, _bit_depth ( 0 )
|
||||
, _color_type ( 0 )
|
||||
, _interlace_method ( PNG_INTERLACE_NONE )
|
||||
, _compression_method( PNG_COMPRESSION_TYPE_DEFAULT )
|
||||
, _filter_method ( PNG_FILTER_TYPE_DEFAULT )
|
||||
|
||||
, _num_channels( 0 )
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
, _valid_cie_colors( 0 )
|
||||
, _white_x ( 0.0 )
|
||||
, _white_y ( 0.0 )
|
||||
, _red_x ( 0.0 )
|
||||
, _red_y ( 0.0 )
|
||||
, _green_x ( 0.0 )
|
||||
, _green_y ( 0.0 )
|
||||
, _blue_x ( 0.0 )
|
||||
, _blue_y ( 0.0 )
|
||||
|
||||
, _valid_file_gamma( 0 )
|
||||
, _file_gamma ( 1.0 )
|
||||
#else
|
||||
, _valid_cie_colors( 0 )
|
||||
, _white_x ( 0 )
|
||||
, _white_y ( 0 )
|
||||
, _red_x ( 0 )
|
||||
, _red_y ( 0 )
|
||||
, _green_x ( 0 )
|
||||
, _green_y ( 0 )
|
||||
, _blue_x ( 0 )
|
||||
, _blue_y ( 0 )
|
||||
|
||||
, _valid_file_gamma( 0 )
|
||||
, _file_gamma ( 1 )
|
||||
#endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
, _valid_icc_profile ( 0 )
|
||||
, _icc_name ( )
|
||||
, _iccp_compression_type( PNG_COMPRESSION_TYPE_BASE )
|
||||
, _profile ( )
|
||||
, _profile_length ( 0 )
|
||||
|
||||
, _valid_intent( 0 )
|
||||
, _intent ( 0 )
|
||||
|
||||
, _valid_palette( 0 )
|
||||
, _palette ( )
|
||||
, _num_palette ( 0 )
|
||||
|
||||
, _valid_background( 0 )
|
||||
, _background ( )
|
||||
|
||||
, _valid_histogram( 0 )
|
||||
, _histogram ( )
|
||||
|
||||
, _valid_offset ( 0 )
|
||||
, _offset_x ( 0 )
|
||||
, _offset_y ( 0 )
|
||||
, _off_unit_type( PNG_OFFSET_PIXEL )
|
||||
|
||||
, _valid_pixel_calibration( 0 )
|
||||
, _purpose ( )
|
||||
, _X0 ( 0 )
|
||||
, _X1 ( 0 )
|
||||
, _cal_type ( 0 )
|
||||
, _num_params ( 0 )
|
||||
, _units ( )
|
||||
, _params ( )
|
||||
|
||||
, _valid_resolution( 0 )
|
||||
, _res_x ( 0 )
|
||||
, _res_y ( 0 )
|
||||
, _phy_unit_type ( PNG_RESOLUTION_UNKNOWN )
|
||||
|
||||
, _pixels_per_meter( 0 )
|
||||
|
||||
, _valid_significant_bits( 0 )
|
||||
, _sig_bits ( )
|
||||
|
||||
, _valid_scale_factors( 0 )
|
||||
, _scale_unit ( PNG_SCALE_UNKNOWN )
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
, _scale_width ( 0.0 )
|
||||
, _scale_height( 0.0 )
|
||||
#else
|
||||
#ifdef BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
|
||||
, _scale_width ( 0 )
|
||||
, _scale_height( 0 )
|
||||
#else
|
||||
, _scale_width ()
|
||||
, _scale_height()
|
||||
#endif // BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
|
||||
#endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
, _valid_text( 0 )
|
||||
, _text ( )
|
||||
, _num_text ( 0 )
|
||||
|
||||
, _valid_modification_time( 0 )
|
||||
, _mod_time ( )
|
||||
|
||||
, _valid_transparency_factors( 0 )
|
||||
, _trans ( )
|
||||
, _num_trans ( 0 )
|
||||
, _trans_values ( )
|
||||
{}
|
||||
|
||||
/// The image width.
|
||||
png_image_width::type _width;
|
||||
/// The image height.
|
||||
png_image_height::type _height;
|
||||
|
||||
/// The bit depth per channel.
|
||||
png_bitdepth::type _bit_depth;
|
||||
/// The color space type.
|
||||
png_color_type::type _color_type;
|
||||
/// The interlace methos.
|
||||
png_interlace_method::type _interlace_method;
|
||||
/// The compression method.
|
||||
png_compression_method::type _compression_method;
|
||||
/// The filer method.
|
||||
png_filter_method::type _filter_method;
|
||||
|
||||
/// The number of channels.
|
||||
png_num_channels::type _num_channels;
|
||||
|
||||
// CIE chromacities
|
||||
/// The return value when reading CIE chromacities.
|
||||
png_return_value::type _valid_cie_colors;
|
||||
/// The white x value.
|
||||
png_chromacities_type::type _white_x;
|
||||
/// The white y value.
|
||||
png_chromacities_type::type _white_y;
|
||||
/// The red x value.
|
||||
png_chromacities_type::type _red_x;
|
||||
/// The red y value.
|
||||
png_chromacities_type::type _red_y;
|
||||
/// The green x value.
|
||||
png_chromacities_type::type _green_x;
|
||||
/// The green y value.
|
||||
png_chromacities_type::type _green_y;
|
||||
/// The blue x value.
|
||||
png_chromacities_type::type _blue_x;
|
||||
/// The blue y value.
|
||||
png_chromacities_type::type _blue_y;
|
||||
|
||||
// Gamma Value
|
||||
/// The return value when reading gamma value.
|
||||
png_return_value::type _valid_file_gamma;
|
||||
/// The file gamma value.
|
||||
png_gamma::type _file_gamma;
|
||||
|
||||
// Embedded ICC profile
|
||||
/// The return value when reading ICC profile.
|
||||
png_return_value::type _valid_icc_profile;
|
||||
/// The ICC name.
|
||||
png_ICC_name::type _icc_name;
|
||||
/// The icc compression type.
|
||||
png_ICC_compression_type::type _iccp_compression_type;
|
||||
/// The ICC profile.
|
||||
png_ICC_profile::type _profile;
|
||||
/// The ICC profile length.
|
||||
png_ICC_profile_length::type _profile_length;
|
||||
|
||||
// Rendering intent
|
||||
/// The return value when reading rendering intent.
|
||||
png_return_value::type _valid_intent;
|
||||
/// The rendering intent value.
|
||||
png_intent::type _intent;
|
||||
|
||||
// Image palette
|
||||
/// The return value when reading image palette.
|
||||
png_return_value::type _valid_palette;
|
||||
/// The color palette.
|
||||
png_color_palette::type _palette;
|
||||
/// The number of colors in the palettes.
|
||||
png_num_palette::type _num_palette;
|
||||
|
||||
// Background
|
||||
/// The return value when reading background.
|
||||
png_return_value::type _valid_background;
|
||||
/// The background color.
|
||||
png_background::type _background;
|
||||
|
||||
// Histogram
|
||||
/// The return value when reading histogram.
|
||||
png_return_value::type _valid_histogram;
|
||||
/// The histogram.
|
||||
png_histrogram::type _histogram;
|
||||
|
||||
// Screen offsets
|
||||
/// The return value when reading screen offsets.
|
||||
png_return_value::type _valid_offset;
|
||||
/// The x offset.
|
||||
png_offset::type _offset_x;
|
||||
/// The y offset.
|
||||
png_offset::type _offset_y;
|
||||
/// The offset unit.
|
||||
png_offset_type::type _off_unit_type;
|
||||
|
||||
// Pixel Calibration
|
||||
/// The return value when reading pixel calibration.
|
||||
png_return_value::type _valid_pixel_calibration;
|
||||
/// The purpose.
|
||||
png_CAL::type _purpose;
|
||||
/// The x_0 value.
|
||||
png_CAL_X::type _X0;
|
||||
/// The x_1 value.
|
||||
png_CAL_X::type _X1;
|
||||
/// The calibration type.
|
||||
png_CAL_type::type _cal_type;
|
||||
/// The number of calibration parameters.
|
||||
png_CAL_nparam::type _num_params;
|
||||
/// The calibration unit type.
|
||||
png_CAL::type _units;
|
||||
/// The calibration parameters.
|
||||
png_CAL_params::type _params;
|
||||
|
||||
// Physical resolution
|
||||
/// The return value when reading physical resolution properties.
|
||||
png_return_value::type _valid_resolution;
|
||||
/// The x physical resolution.
|
||||
png_resolution::type _res_x;
|
||||
/// The y physical resolution.
|
||||
png_resolution::type _res_y;
|
||||
/// The physical resolution unit.
|
||||
png_unit_type::type _phy_unit_type;
|
||||
|
||||
/// The Image resolution in pixels per meter.
|
||||
png_pixels_per_meter::type _pixels_per_meter;
|
||||
|
||||
// Number of significant bits
|
||||
/// The return value when reading significant bits.
|
||||
png_return_value::type _valid_significant_bits;
|
||||
/// The significant bits.
|
||||
png_significant_bits::type _sig_bits;
|
||||
|
||||
// Scale Factors
|
||||
/// The return value when reading scale factors.
|
||||
png_return_value::type _valid_scale_factors;
|
||||
/// The scaling unit.
|
||||
png_unit::type _scale_unit;
|
||||
/// The scaling width.
|
||||
png_scale::type _scale_width;
|
||||
/// The scaling height.
|
||||
png_scale::type _scale_height;
|
||||
|
||||
// Comments information
|
||||
/// The return value when reading image comments.
|
||||
png_return_value::type _valid_text;
|
||||
/// The comments.
|
||||
png_text_::type _text;
|
||||
/// The number of comments.
|
||||
png_num_text::type _num_text;
|
||||
|
||||
// Last modification time
|
||||
/// The return value when reading modification time.
|
||||
png_return_value::type _valid_modification_time;
|
||||
/// The modification time.
|
||||
png_mod_time::type _mod_time;
|
||||
|
||||
// Transparency data
|
||||
/// The return value when reading transparency data.
|
||||
png_return_value::type _valid_transparency_factors;
|
||||
/// The transparency data.
|
||||
png_trans::type _trans;
|
||||
/// The number of transparency data.
|
||||
png_num_trans::type _num_trans;
|
||||
/// The transparency data values.
|
||||
png_trans_values::type _trans_values;
|
||||
};
|
||||
|
||||
/// Read information for png images.
|
||||
///
|
||||
/// The structure is returned when using read_image_info.
|
||||
template<>
|
||||
struct image_read_info< png_tag > : public png_info_base
|
||||
{
|
||||
/// Default constructor.
|
||||
image_read_info< png_tag >()
|
||||
: png_info_base()
|
||||
{}
|
||||
};
|
||||
|
||||
/// PNG settings base class.
|
||||
///
|
||||
/// This base structure was created to avoid code doubling.
|
||||
struct png_read_settings_base
|
||||
{
|
||||
/// Default Constructor.
|
||||
png_read_settings_base()
|
||||
{
|
||||
_read_cie_chromacities = false;
|
||||
_read_file_gamma = false;
|
||||
_read_icc_profile = false;
|
||||
_read_intent = false;
|
||||
_read_palette = false;
|
||||
_read_background = false;
|
||||
_read_histogram = false;
|
||||
_read_screen_offsets = false;
|
||||
_read_pixel_calibration = false;
|
||||
_read_physical_resolution = false;
|
||||
_read_pixels_per_meter = false;
|
||||
_read_number_of_significant_bits = false;
|
||||
_read_scale_factors = false;
|
||||
_read_comments = false;
|
||||
_read_last_modification_time = false;
|
||||
_read_transparency_data = false;
|
||||
}
|
||||
|
||||
/// Helper function to enabling reading all png properties.
|
||||
void set_read_members_true()
|
||||
{
|
||||
_read_cie_chromacities = true;
|
||||
_read_file_gamma = true;
|
||||
_read_icc_profile = true;
|
||||
_read_intent = true;
|
||||
_read_palette = true;
|
||||
_read_background = true;
|
||||
_read_histogram = true;
|
||||
_read_screen_offsets = true;
|
||||
_read_pixel_calibration = true;
|
||||
_read_physical_resolution = true;
|
||||
_read_pixels_per_meter = true;
|
||||
_read_number_of_significant_bits = true;
|
||||
_read_scale_factors = true;
|
||||
_read_comments = true;
|
||||
_read_last_modification_time = true;
|
||||
_read_transparency_data = true;
|
||||
}
|
||||
|
||||
/// Enable reading CIE chromacities.
|
||||
bool _read_cie_chromacities;
|
||||
/// Enable reading file gamma.
|
||||
bool _read_file_gamma;
|
||||
/// Enable reading ICC profile.
|
||||
bool _read_icc_profile;
|
||||
/// Enable reading rendering intent.
|
||||
bool _read_intent;
|
||||
/// Enable reading color palette.
|
||||
bool _read_palette;
|
||||
/// Enable reading background color.
|
||||
bool _read_background;
|
||||
/// Enable reading histogram.
|
||||
bool _read_histogram;
|
||||
/// Enable reading screen offsets.
|
||||
bool _read_screen_offsets;
|
||||
/// Enable reading pixel calibration.
|
||||
bool _read_pixel_calibration;
|
||||
/// Enable reading physical resolution.
|
||||
bool _read_physical_resolution;
|
||||
/// Enable reading pixels per meter information.
|
||||
bool _read_pixels_per_meter;
|
||||
/// Enable reading significant bits.
|
||||
bool _read_number_of_significant_bits;
|
||||
/// Enable reading scaling factors.
|
||||
bool _read_scale_factors;
|
||||
/// Enable reading comments.
|
||||
bool _read_comments;
|
||||
/// Enable reading modification time.
|
||||
bool _read_last_modification_time;
|
||||
/// Enable reading transparency data.
|
||||
bool _read_transparency_data;
|
||||
};
|
||||
|
||||
#ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
/// Read settings for png images.
|
||||
///
|
||||
/// The structure can be used for all read_xxx functions, except read_image_info.
|
||||
template<>
|
||||
struct image_read_settings< png_tag > : public image_read_settings_base
|
||||
, public png_read_settings_base
|
||||
{
|
||||
/// Default Constructor
|
||||
image_read_settings< png_tag >()
|
||||
: image_read_settings_base()
|
||||
, png_read_settings_base()
|
||||
, _screen_gamma( 1.0 )
|
||||
{}
|
||||
|
||||
/// Constructor
|
||||
/// \param top_left Top left coordinate for reading partial image.
|
||||
/// \param dim Dimensions for reading partial image.
|
||||
/// \param gamma Screen gamma value.
|
||||
image_read_settings( const point_t& top_left
|
||||
, const point_t& dim
|
||||
, const bool apply_screen_gamma = false
|
||||
, const png_gamma::type& screen_gamma = 1.0
|
||||
)
|
||||
: image_read_settings_base( top_left
|
||||
, dim
|
||||
)
|
||||
, png_read_settings_base()
|
||||
, _apply_screen_gamma( apply_screen_gamma )
|
||||
, _screen_gamma( screen_gamma )
|
||||
{}
|
||||
|
||||
/// Apply screen gamma value.
|
||||
bool _apply_screen_gamma;
|
||||
/// The screen gamma value.
|
||||
png_gamma::type _screen_gamma;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
/// Read settings for png images.
|
||||
///
|
||||
/// The structure can be used for all read_xxx functions, except read_image_info.
|
||||
template<>
|
||||
struct image_read_settings< png_tag > : public image_read_settings_base
|
||||
, public png_read_settings_base
|
||||
{
|
||||
/// Default Constructor.
|
||||
image_read_settings< png_tag >()
|
||||
: image_read_settings_base()
|
||||
, png_read_settings_base()
|
||||
, _apply_screen_gamma( false )
|
||||
, _screen_gamma ( 2 )
|
||||
{}
|
||||
|
||||
image_read_settings( const point_t& top_left
|
||||
, const point_t& dim
|
||||
)
|
||||
: image_read_settings_base( top_left
|
||||
, dim
|
||||
)
|
||||
, png_read_settings_base()
|
||||
, _apply_screen_gamma( false )
|
||||
, _screen_gamma ( 2 )
|
||||
{}
|
||||
|
||||
/// Apply screen gamma value.
|
||||
bool _apply_screen_gamma;
|
||||
/// The screen gamma value.
|
||||
png_gamma::type _screen_gamma;
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Write information for png images.
|
||||
///
|
||||
/// The structure can be used for write_view() function.
|
||||
template<>
|
||||
struct image_write_info< png_tag > : public png_info_base
|
||||
{
|
||||
image_write_info( const png_compression_type::type compression_type = png_compression_type::default_value
|
||||
, const png_compression_level::type compression_level = png_compression_level::default_value
|
||||
, const png_compression_mem_level::type compression_mem_level = png_compression_mem_level::default_value
|
||||
, const png_compression_strategy::type compression_strategy = png_compression_strategy::default_value
|
||||
, const png_compression_window_bits::type compression_window_bits = png_compression_window_bits::default_value
|
||||
, const png_compression_method::type compression_method = png_compression_method::default_value
|
||||
, const png_compression_buffer_size::type compression_buffer_size = png_compression_buffer_size::default_value
|
||||
, const png_dithering_num_palette::type num_palette = png_dithering_num_palette::default_value
|
||||
, const png_dithering_maximum_colors::type maximum_colors = png_dithering_maximum_colors::default_value
|
||||
, const png_full_dither::type full_dither = png_full_dither::default_value
|
||||
, const png_filter::type filter = png_filter::default_value
|
||||
, const png_invert_mono::type invert_mono = png_invert_mono::default_value
|
||||
, const png_srgb_intent::type srgb_intent = png_srgb_intent::default_value
|
||||
, const png_strip_alpha::type strip_alpha = png_strip_alpha::default_value
|
||||
, const png_swap_alpha::type swap_alpha = png_swap_alpha::default_value
|
||||
)
|
||||
: png_info_base()
|
||||
, _compression_type( compression_type )
|
||||
, _compression_level( compression_level )
|
||||
, _compression_mem_level( compression_mem_level )
|
||||
, _compression_strategy( compression_strategy )
|
||||
, _compression_window_bits( compression_window_bits )
|
||||
, _compression_method( compression_method )
|
||||
, _compression_buffer_size( compression_buffer_size )
|
||||
|
||||
, _set_dithering( false )
|
||||
, _dithering_palette()
|
||||
, _dithering_num_palette( num_palette )
|
||||
, _dithering_maximum_colors( maximum_colors )
|
||||
, _dithering_histogram()
|
||||
, _full_dither( full_dither )
|
||||
|
||||
, _set_filter( false )
|
||||
, _filter( filter )
|
||||
|
||||
, _invert_mono( invert_mono )
|
||||
|
||||
, _set_true_bits( false )
|
||||
, _true_bits()
|
||||
|
||||
, _set_srgb_intent( false )
|
||||
, _srgb_intent( srgb_intent )
|
||||
|
||||
, _strip_alpha( strip_alpha )
|
||||
|
||||
, _swap_alpha( swap_alpha )
|
||||
{}
|
||||
|
||||
// compression stuff
|
||||
png_compression_type::type _compression_type;
|
||||
png_compression_level::type _compression_level;
|
||||
png_compression_mem_level::type _compression_mem_level;
|
||||
png_compression_strategy::type _compression_strategy;
|
||||
png_compression_window_bits::type _compression_window_bits;
|
||||
png_compression_method::type _compression_method;
|
||||
png_compression_buffer_size::type _compression_buffer_size;
|
||||
|
||||
// png_set_dither
|
||||
bool _set_dithering;
|
||||
png_dithering_palette::type _dithering_palette;
|
||||
png_dithering_num_palette::type _dithering_num_palette;
|
||||
png_dithering_maximum_colors::type _dithering_maximum_colors;
|
||||
png_dithering_histogram::type _dithering_histogram;
|
||||
png_full_dither::type _full_dither;
|
||||
|
||||
//png_set_filter
|
||||
bool _set_filter;
|
||||
png_filter::type _filter;
|
||||
|
||||
// png_set_invert_mono
|
||||
png_invert_mono::type _invert_mono;
|
||||
|
||||
// png_set_sBIT
|
||||
bool _set_true_bits;
|
||||
png_true_bits::type _true_bits;
|
||||
|
||||
// png_set_sRGB
|
||||
bool _set_srgb_intent;
|
||||
png_srgb_intent::type _srgb_intent;
|
||||
|
||||
// png_set_strip_alpha
|
||||
png_strip_alpha::type _strip_alpha;
|
||||
|
||||
// png_set_swap_alpha
|
||||
png_swap_alpha::type _swap_alpha;
|
||||
|
||||
};
|
||||
|
||||
} // namespace gil
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
19
macx64/include/boost/gil/extension/io/png/write.hpp
Normal file
19
macx64/include/boost/gil/extension/io/png/write.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright 2007-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_PNG_WRITE_HPP
|
||||
#define BOOST_GIL_EXTENSION_IO_PNG_WRITE_HPP
|
||||
|
||||
#include <boost/gil/extension/io/png/tags.hpp>
|
||||
#include <boost/gil/extension/io/png/detail/supported_types.hpp>
|
||||
#include <boost/gil/extension/io/png/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