|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83075 - in trunk/boost/gil/extension/io: detail formats/bmp formats/jpeg formats/png formats/pnm formats/targa formats/tiff
From: chhenning_at_[hidden]
Date: 2013-02-21 21:28:25
Author: chhenning
Date: 2013-02-21 21:28:20 EST (Thu, 21 Feb 2013)
New Revision: 83075
URL: http://svn.boost.org/trac/boost/changeset/83075
Log:
changes to scanline_read_iterator.
Text files modified:
trunk/boost/gil/extension/io/detail/scanline_read_iterator.hpp | 168 ++++++---------------------------------
trunk/boost/gil/extension/io/formats/bmp/scanline_read.hpp | 11 +
trunk/boost/gil/extension/io/formats/jpeg/scanline_read.hpp | 10 +
trunk/boost/gil/extension/io/formats/png/scanline_read.hpp | 9 +
trunk/boost/gil/extension/io/formats/pnm/scanline_read.hpp | 13 +-
trunk/boost/gil/extension/io/formats/targa/scanline_read.hpp | 14 ++-
trunk/boost/gil/extension/io/formats/tiff/scanline_read.hpp | 15 +-
7 files changed, 77 insertions(+), 163 deletions(-)
Modified: trunk/boost/gil/extension/io/detail/scanline_read_iterator.hpp
==============================================================================
--- trunk/boost/gil/extension/io/detail/scanline_read_iterator.hpp (original)
+++ trunk/boost/gil/extension/io/detail/scanline_read_iterator.hpp 2013-02-21 21:28:20 EST (Thu, 21 Feb 2013)
@@ -19,10 +19,17 @@
///
////////////////////////////////////////////////////////////////////////////////////////
+#include <vector>
+
#include <boost/gil/extension/io/detail/io_error.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
+
/// Input iterator to read images.
template< typename Reader >
class scanline_read_iterator
@@ -37,122 +44,34 @@
typedef value_type const& reference;
typedef int difference_type;
- /// todo
- //typedef ptrdiff_t difference_type;
-
public:
- /// Default Constructor, usually used to create an end iterator.
- scanline_read_iterator()
- : _pos( -1 )
- , _read_scanline( true )
- , _skip_scanline( true )
- , _reader( NULL )
- , _buffer( NULL )
- {}
-
/// Constructor with preallocated image. Reading starts at first scanline of source image.
scanline_read_iterator( Reader& reader
- , byte_t* buffer
- )
- : _pos( 0 )
- , _read_scanline( true )
- , _skip_scanline( true )
- , _reader( &reader )
- , _buffer( buffer )
- {
- init();
- }
-
- /// Constructor with preallocated image. Reading starts at first scanline of source image.
- scanline_read_iterator( Reader& reader )
- : _pos( 0 )
- , _read_scanline( true )
- , _skip_scanline( true )
- , _reader( &reader )
- , _buffer( NULL )
- {
- init();
- }
-
- /// Constructor with preallocated image. Reading starts at pos scanline of source image.
- scanline_read_iterator( std::size_t pos
- , Reader& reader
- , byte_t* buffer
+ , int pos = 0
)
: _pos( pos )
, _read_scanline( true )
, _skip_scanline( true )
- , _reader( &reader )
- , _buffer( buffer )
- {
- init();
-
- if( this->_pos >= this->_reader->_info._height )
- {
- throw std::runtime_error( "Trying to read past image." );
- }
-
- if( pos > 0 && _buffer == NULL )
- {
- throw std::runtime_error( "Cannot proceed without initializing read buffer." );
- }
-
- for( std::size_t i = 0; i < pos; ++i )
- {
- _skip();
- }
- }
-
- //
- // Destructor
- //
- ~scanline_read_iterator()
- {
- if( _reader )
- {
- _reader->clean_up();
- }
- }
-
- /// Set reader. Do clean up before if necessary.
- void set_reader( Reader& reader )
+ , _reader( reader )
{
- if( _reader )
- {
- _reader->clean_up();
-
- _pos = 0;
- }
-
- _reader = &reader;
-
init();
}
- /// Set reader. Do clean up before if necessary.
- void set_buffer( byte_t* buffer )
- {
- _buffer = buffer;
- }
-
/// Dereference Operator
reference operator*()
{
- if( _reader == NULL ) { io_error( "Reader cannot be null for this operation." ); }
- if( _buffer == NULL ) { io_error( "Buffer cannot be null for this operation." ); }
-
if( _read_scanline == true )
{
- _reader->read( _buffer, _pos );
-
- increase_pos();
+ _reader.read( _buffer_start
+ , _pos
+ );
}
_skip_scanline = false;
_read_scanline = false;
- return _buffer;
+ return _buffer_start;
}
/// Pointer-To-Memper Operator.
@@ -167,22 +86,16 @@
if( _skip_scanline == true )
{
_skip();
-
- increase_pos();
}
+ ++_pos;
+
_skip_scanline = true;
_read_scanline = true;
return (*this);
}
- /// Compare passed iterator to this.
- bool equal( const scanline_read_iterator< Reader >& rhs ) const
- {
- return (_reader == rhs._reader) && ( _buffer == rhs._buffer );
- }
-
bool operator ==( const scanline_read_iterator< Reader >& rhs ) const
{
return _pos == rhs._pos;
@@ -190,51 +103,22 @@
bool operator !=( const scanline_read_iterator< Reader >& rhs ) const
{
- return _pos != rhs._pos;
- }
-
- /// Return backend.
- const backend_t& backend()
- {
- if( _reader )
- {
- return *_reader;
- }
-
- io_error( "Reader cannot be null for this operation." );
+ return _pos < rhs._pos;
}
private:
void init()
{
- // this needs to be done by the scanline_reader. Otherwise the user wont know the scanline length.
- //if( _reader )
- //{
- // _reader->initialize();
- //}
+ _buffer = std::vector< byte_t >( _reader._scanline_length );
+ _buffer_start = &_buffer.front();
}
void _skip()
{
- if( _reader )
- {
- _reader->skip( _buffer, _pos );
- }
- }
-
- void increase_pos()
- {
- if( this->_reader == NULL ) { io_error("Reader cannot be null for this operation."); }
-
- if( _pos < static_cast< int >( this->_reader->_info._height ) - 1 )
- {
- ++_pos;
- }
- else
- {
- _pos = -1;
- }
+ _reader.skip( _buffer_start
+ , _pos
+ );
}
private:
@@ -244,10 +128,16 @@
mutable bool _read_scanline;
mutable bool _skip_scanline;
- Reader* _reader;
- byte_t* _buffer;
+ Reader& _reader;
+
+ std::vector< byte_t > _buffer;
+ byte_t* _buffer_start;
};
+#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
+#pragma warning(pop)
+#endif
+
} // namespace gil
} // namespace boost
Modified: trunk/boost/gil/extension/io/formats/bmp/scanline_read.hpp
==============================================================================
--- trunk/boost/gil/extension/io/formats/bmp/scanline_read.hpp (original)
+++ trunk/boost/gil/extension/io/formats/bmp/scanline_read.hpp 2013-02-21 21:28:20 EST (Thu, 21 Feb 2013)
@@ -29,6 +29,7 @@
#include <boost/gil/extension/io/detail/row_buffer_helper.hpp>
#include <boost/gil/extension/io/detail/reader_base.hpp>
#include <boost/gil/extension/io/detail/io_device.hpp>
+#include <boost/gil/extension/io/detail/scanline_read_iterator.hpp>
#include <boost/gil/extension/io/detail/typedefs.hpp>
#include "reader_backend.hpp"
@@ -55,7 +56,10 @@
public:
- typedef reader_backend< Device, bmp_tag > backend_t;
+ typedef bmp_tag tag_t;
+ typedef reader_backend < Device, tag_t > backend_t;
+ typedef scanline_reader< Device, tag_t > this_t;
+ typedef scanline_read_iterator< this_t > iterator_t;
public:
@@ -74,8 +78,6 @@
initialize();
}
- void clean_up(){}
-
/// Read part of image defined by View and return the data.
void read( byte_t* dst, int pos )
{
@@ -107,6 +109,9 @@
// nothing to do.
}
+ iterator_t begin() { return iterator_t( *this ); }
+ iterator_t end() { return iterator_t( *this, this->_info._height ); }
+
private:
void initialize()
Modified: trunk/boost/gil/extension/io/formats/jpeg/scanline_read.hpp
==============================================================================
--- trunk/boost/gil/extension/io/formats/jpeg/scanline_read.hpp (original)
+++ trunk/boost/gil/extension/io/formats/jpeg/scanline_read.hpp 2013-02-21 21:28:20 EST (Thu, 21 Feb 2013)
@@ -26,8 +26,10 @@
#include <boost/gil/extension/io/detail/conversion_policies.hpp>
#include <boost/gil/extension/io/detail/reader_base.hpp>
#include <boost/gil/extension/io/detail/io_device.hpp>
+#include <boost/gil/extension/io/detail/scanline_read_iterator.hpp>
#include <boost/gil/extension/io/detail/typedefs.hpp>
+
#include "reader_backend.hpp"
#include "base.hpp"
#include "is_allowed.hpp"
@@ -52,7 +54,10 @@
{
public:
- typedef reader_backend< Device, jpeg_tag > backend_t;
+ typedef jpeg_tag tag_t;
+ typedef reader_backend < Device, tag_t > backend_t;
+ typedef scanline_reader< Device, tag_t > this_t;
+ typedef scanline_read_iterator< this_t > iterator_t;
public:
scanline_reader( Device& device
@@ -88,7 +93,8 @@
read_scanline( dst );
}
- void clean_up() {}
+ iterator_t begin() { return iterator_t( *this ); }
+ iterator_t end() { return iterator_t( *this, this->_info._height ); }
private:
Modified: trunk/boost/gil/extension/io/formats/png/scanline_read.hpp
==============================================================================
--- trunk/boost/gil/extension/io/formats/png/scanline_read.hpp (original)
+++ trunk/boost/gil/extension/io/formats/png/scanline_read.hpp 2013-02-21 21:28:20 EST (Thu, 21 Feb 2013)
@@ -27,6 +27,7 @@
#include <boost/gil/extension/io/detail/io_device.hpp>
#include <boost/gil/extension/io/detail/typedefs.hpp>
#include <boost/gil/extension/io/detail/row_buffer_helper.hpp>
+#include <boost/gil/extension/io/detail/scanline_read_iterator.hpp>
#include "reader_backend.hpp"
#include "is_allowed.hpp"
@@ -52,7 +53,10 @@
public:
- typedef reader_backend< Device, png_tag > backend_t;
+ typedef png_tag tag_t;
+ typedef reader_backend < Device, tag_t > backend_t;
+ typedef scanline_reader< Device, tag_t > this_t;
+ typedef scanline_read_iterator< this_t > iterator_t;
public:
@@ -84,7 +88,8 @@
read_scanline( dst );
}
- void clean_up() {}
+ iterator_t begin() { return iterator_t( *this ); }
+ iterator_t end() { return iterator_t( *this, this->_info._height ); }
private:
Modified: trunk/boost/gil/extension/io/formats/pnm/scanline_read.hpp
==============================================================================
--- trunk/boost/gil/extension/io/formats/pnm/scanline_read.hpp (original)
+++ trunk/boost/gil/extension/io/formats/pnm/scanline_read.hpp 2013-02-21 21:28:20 EST (Thu, 21 Feb 2013)
@@ -31,6 +31,7 @@
#include <boost/gil/extension/io/detail/bit_operations.hpp>
#include <boost/gil/extension/io/detail/reader_base.hpp>
#include <boost/gil/extension/io/detail/io_device.hpp>
+#include <boost/gil/extension/io/detail/scanline_read_iterator.hpp>
#include <boost/gil/extension/io/detail/typedefs.hpp>
#include "reader_backend.hpp"
@@ -57,9 +58,10 @@
public:
- typedef reader_backend< Device
- , pnm_tag
- > backend_t;
+ typedef pnm_tag tag_t;
+ typedef reader_backend < Device, tag_t > backend_t;
+ typedef scanline_reader< Device, tag_t > this_t;
+ typedef scanline_read_iterator< this_t > iterator_t;
public:
@@ -73,8 +75,6 @@
initialize();
}
- void clean_up() {}
-
/// Read part of image defined by View and return the data.
void read( byte_t* dst
, int
@@ -89,6 +89,9 @@
_skip_function( this );
}
+ iterator_t begin() { return iterator_t( *this ); }
+ iterator_t end() { return iterator_t( *this, this->_info._height ); }
+
private:
void initialize()
Modified: trunk/boost/gil/extension/io/formats/targa/scanline_read.hpp
==============================================================================
--- trunk/boost/gil/extension/io/formats/targa/scanline_read.hpp (original)
+++ trunk/boost/gil/extension/io/formats/targa/scanline_read.hpp 2013-02-21 21:28:20 EST (Thu, 21 Feb 2013)
@@ -27,6 +27,7 @@
#include <boost/gil/extension/io/detail/row_buffer_helper.hpp>
#include <boost/gil/extension/io/detail/reader_base.hpp>
#include <boost/gil/extension/io/detail/io_device.hpp>
+#include <boost/gil/extension/io/detail/scanline_read_iterator.hpp>
#include <boost/gil/extension/io/detail/typedefs.hpp>
#include "reader_backend.hpp"
@@ -53,9 +54,11 @@
public:
- typedef reader_backend< Device
- , targa_tag
- > backend_t;
+
+ typedef targa_tag tag_t;
+ typedef reader_backend < Device, tag_t > backend_t;
+ typedef scanline_reader< Device, tag_t > this_t;
+ typedef scanline_read_iterator< this_t > iterator_t;
public:
@@ -72,8 +75,6 @@
initialize();
}
- void clean_up() {}
-
/// Read part of image defined by View and return the data.
void read( byte_t* dst, int pos )
{
@@ -93,6 +94,9 @@
this->_io_dev.seek( static_cast<long>( this->_scanline_length ), SEEK_CUR );
}
+ iterator_t begin() { return iterator_t( *this ); }
+ iterator_t end() { return iterator_t( *this, this->_info._height ); }
+
private:
void initialize()
Modified: trunk/boost/gil/extension/io/formats/tiff/scanline_read.hpp
==============================================================================
--- trunk/boost/gil/extension/io/formats/tiff/scanline_read.hpp (original)
+++ trunk/boost/gil/extension/io/formats/tiff/scanline_read.hpp 2013-02-21 21:28:20 EST (Thu, 21 Feb 2013)
@@ -44,6 +44,7 @@
#include <boost/gil/extension/io/detail/row_buffer_helper.hpp>
#include <boost/gil/extension/io/detail/io_device.hpp>
#include <boost/gil/extension/io/detail/reader_base.hpp>
+#include <boost/gil/extension/io/detail/scanline_read_iterator.hpp>
#include "reader_backend.hpp"
#include "device.hpp"
@@ -70,9 +71,11 @@
> this_t;
public:
- typedef reader_backend< Device
- , tiff_tag
- > backend_t;
+
+ typedef tiff_tag tag_t;
+ typedef reader_backend < Device, tag_t > backend_t;
+ typedef scanline_reader< Device, tag_t > this_t;
+ typedef scanline_read_iterator< this_t > iterator_t;
public:
@@ -98,10 +101,8 @@
this->_read_function( this, dst, pos );
}
- void clean_up()
- {
- ///@todo
- }
+ iterator_t begin() { return iterator_t( *this ); }
+ iterator_t end() { return iterator_t( *this, this->_info._height ); }
private:
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