Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66049 - sandbox/gil/boost/gil/extension/io2
From: dsaritz_at_[hidden]
Date: 2010-10-17 16:30:36


Author: psiha
Date: 2010-10-17 16:30:34 EDT (Sun, 17 Oct 2010)
New Revision: 66049
URL: http://svn.boost.org/trac/boost/changeset/66049

Log:
Added support manual setup of output scaling (using the low level lib_object() interface).
Minor stylistic changes.
Text files modified:
   sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp | 39 +++++++++++++++++++++++++++++++--------
   1 files changed, 31 insertions(+), 8 deletions(-)

Modified: sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/libjpeg_image.hpp 2010-10-17 16:30:34 EDT (Sun, 17 Oct 2010)
@@ -453,8 +453,8 @@
 
 class libjpeg_image
     :
- public detail::libjpeg_base,
- public detail::formatted_image<libjpeg_image>
+ public detail::libjpeg_base,
+ public detail::formatted_image<libjpeg_image>
 {
 public:
     struct guard {};
@@ -568,11 +568,20 @@
 public:
     point2<std::ptrdiff_t> dimensions() const
     {
- return point2<std::ptrdiff_t>( decompressor().image_width, decompressor().image_height );
+ // Implementation note:
+ // A user might have setup output image scaling through the low-level
+ // lib_object accessor.
+ // (17.10.2010.) (Domagoj Saric)
+ if ( dirty_output_dimensions_ )
+ {
+ jpeg_calc_output_dimensions( &const_cast<libjpeg_image &>( *this ).lib_object() );
+ dirty_output_dimensions_ = false;
+ }
+ return point2<std::ptrdiff_t>( decompressor().output_width, decompressor().output_height );
     }
 
- jpeg_decompress_struct & lib_object() { return decompressor(); }
- jpeg_decompress_struct const & lib_object() const { return const_cast<libjpeg_image &>( *this ).lib_object(); }
+ jpeg_decompress_struct & lib_object() { dirty_output_dimensions_ = true; return decompressor(); }
+ jpeg_decompress_struct const & lib_object() const { return decompressor(); }
 
 private: // Private interface for the base formatted_image<> class.
     friend base_t;
@@ -794,7 +803,20 @@
     {
         BOOST_VERIFY( jpeg_read_header( &decompressor(), true ) == JPEG_HEADER_OK );
 
- detail::io_error_if( decompressor().data_precision != 8, "Unsupported image file data precision." );
+ // Implementation note:
+ // To enable users to setup output scaling we use the output
+ // dimensions to report the image dimensions in the dimensions() getter
+ // so we have to manually initialize them here.
+ // (17.10.2010.) (Domagoj Saric)
+ BOOST_ASSERT( decompressor().output_width == 0 );
+ BOOST_ASSERT( decompressor().output_height == 0 );
+
+ decompressor().output_width = decompressor().image_width ;
+ decompressor().output_height = decompressor().image_height;
+
+ dirty_output_dimensions_ = false;
+
+ detail::io_error_if( decompressor().data_precision != BITS_IN_JSAMPLE, "Unsupported image file data precision." );
     }
 
     // Unextracted "libjpeg_reader" interface.
@@ -937,8 +959,9 @@
     }
 
 private:
- jpeg_source_mgr source_manager_;
- array<JOCTET, 4096> read_buffer_ ;//...zzz...extract to a wrapper...not needed for in memory sources...
+ jpeg_source_mgr source_manager_ ;
+ array<JOCTET, 4096> read_buffer_ ;//...zzz...extract to a wrapper...not needed for in memory sources...
+ mutable bool dirty_output_dimensions_;
 };
 
 #if defined(BOOST_MSVC)


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