Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83970 - in trunk: boost/gil/extension/io boost/gil/extension/io/formats/png libs/gil/io/doc
From: chhenning_at_[hidden]
Date: 2013-04-19 18:40:07


Author: chhenning
Date: 2013-04-19 18:40:05 EDT (Fri, 19 Apr 2013)
New Revision: 83970
URL: http://svn.boost.org/trac/boost/changeset/83970

Log:
Added some more parameter to configure libpng on how to write images.
Text files modified:
   trunk/boost/gil/extension/io/formats/png/write.hpp | 11 --
   trunk/boost/gil/extension/io/formats/png/writer_backend.hpp | 85 ++++++++++++++++
   trunk/boost/gil/extension/io/png_tags.hpp | 201 ++++++++++++++++++++++++++++++++++++++-
   trunk/libs/gil/io/doc/io.qbk | 2
   4 files changed, 280 insertions(+), 19 deletions(-)

Modified: trunk/boost/gil/extension/io/formats/png/write.hpp
==============================================================================
--- trunk/boost/gil/extension/io/formats/png/write.hpp (original)
+++ trunk/boost/gil/extension/io/formats/png/write.hpp 2013-04-19 18:40:05 EDT (Fri, 19 Apr 2013)
@@ -19,17 +19,6 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////////////
 
-// taken from jpegxx - https://bitbucket.org/edd/jpegxx/src/ea2492a1a4a6/src/ijg_headers.hpp
-#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
-
 #include <boost/mpl/and.hpp>
 #include <boost/mpl/equal_to.hpp>
 #include <boost/mpl/less.hpp>

Modified: trunk/boost/gil/extension/io/formats/png/writer_backend.hpp
==============================================================================
--- trunk/boost/gil/extension/io/formats/png/writer_backend.hpp (original)
+++ trunk/boost/gil/extension/io/formats/png/writer_backend.hpp 2013-04-19 18:40:05 EDT (Fri, 19 Apr 2013)
@@ -380,6 +380,91 @@
             }
         }
 
+ // 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()
                       );

Modified: trunk/boost/gil/extension/io/png_tags.hpp
==============================================================================
--- trunk/boost/gil/extension/io/png_tags.hpp (original)
+++ trunk/boost/gil/extension/io/png_tags.hpp 2013-04-19 18:40:05 EDT (Fri, 19 Apr 2013)
@@ -25,17 +25,23 @@
 #endif BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
 #endif BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
 
-// taken from jpegxx - https://bitbucket.org/edd/jpegxx/src/ea2492a1a4a6/src/ijg_headers.hpp
 #ifndef BOOST_GIL_EXTENSION_IO_PNG_C_LIB_COMPILED_AS_CPLUSPLUS
     extern "C" {
 #endif
-
-#include <png.h>
-
+ #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
+
+
 #include <string>
 #include <vector>
 
@@ -57,9 +63,6 @@
 /// Defines type for interlace method property.
 struct png_interlace_method : property_base< int > {};
 
-/// Defines type for compression method property.
-struct png_compression_method : property_base< int > {};
-
 /// Defines type for filter method property.
 struct png_filter_method : property_base< int > {};
 
@@ -185,6 +188,104 @@
 /// Defines type for png function return type.
 struct png_return_value : property_base< png_uint_32 > {};
 
+////////////////////////
+// Write properties
+////////////////////////
+
+// 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 = Z_BEST_COMPRESSION;
+};
+
+struct png_compression_mem_level : property_base< int >
+{
+ static const type default_value = 8;
+};
+
+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 = 15;
+};
+
+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 > >
+{
+ static const type default_value;
+};
+
+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 > >
+{
+ static const type default_value;
+};
+
+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 > >
+{
+ static const type default_value;
+};
+
+// 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.
@@ -640,9 +741,93 @@
 template<>
 struct image_write_info< png_tag > : public png_info_base
 {
- image_write_info()
+ image_write_info( 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_palette::type palette = png_dithering_palette::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_dithering_histogram::type histogram = png_dithering_histogram::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_true_bits::type true_bits = png_true_bits::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_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( palette )
+ , _dithering_num_palette( num_palette )
+ , _dithering_maximum_colors( maximum_colors )
+ , _dithering_histogram(histogram)
+ , _full_dither( full_dither )
+
+ , _set_filter( false )
+ , _filter( filter )
+
+ , _invert_mono( invert_mono )
+
+ , _set_true_bits( false )
+ , _true_bits( true_bits )
+
+ , _set_srgb_intent( false )
+ , _srgb_intent( srgb_intent )
+
+ , _strip_alpha( strip_alpha )
+
+ , _swap_alpha( swap_alpha )
     {}
+
+
+ // compression stuff
+ 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

Modified: trunk/libs/gil/io/doc/io.qbk
==============================================================================
--- trunk/libs/gil/io/doc/io.qbk (original)
+++ trunk/libs/gil/io/doc/io.qbk 2013-04-19 18:40:05 EDT (Fri, 19 Apr 2013)
@@ -335,10 +335,12 @@
     [[BOOST_GIL_IO_ADD_FS_PATH_SUPPORT] [Enable boost::filesystem 3.0 library.]]
     [[BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED] [Use libpng in floating point mode. This symbol is incompatible with BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED.]]
     [[BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED] [Use libpng in integer mode. This symbol is incompatible with BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED.]]
+ [[BOOST_GIL_IO_PNG_DITHERING_SUPPORTED] [Look up "dithering" in libpng manual for explanation.]]
     [[BOOST_GIL_EXTENSION_IO_JPEG_C_LIB_COMPILED_AS_CPLUSPLUS] [libjpeg is compiled as c++ lib.]]
     [[BOOST_GIL_EXTENSION_IO_PNG_C_LIB_COMPILED_AS_CPLUSPLUS] [libpng is compiled as c++ lib.]]
     [[BOOST_GIL_EXTENSION_IO_RAW_C_LIB_COMPILED_AS_CPLUSPLUS] [libraw is compiled as c++ lib.]]
     [[BOOST_GIL_EXTENSION_IO_TIFF_C_LIB_COMPILED_AS_CPLUSPLUS] [libtiff is compiled as c++ lib.]]
+ [[BOOST_GIL_EXTENSION_IO_ZLIB_C_LIB_COMPILED_AS_CPLUSPLUS] [zlib is compiled as c++ lib.]]
     [[BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES] [Allow basic test images to be read from local hard drive. The paths can be set in paths.hpp]]
     [[BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES] [Allow images to be written to the local hard drive. The paths can be set in paths.hpp]]
     [[BOOST_GIL_IO_USE_BMP_TEST_SUITE_IMAGES] [Run tests using the bmp test images suite. See _BMP_TEST_FILES]]


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk