Boost logo

Boost :

Subject: Re: [boost] [gil::io] Feedback for scanline_read_iterator
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2013-02-18 11:52:16


Hi Christian,

Christian Henning wrote:
>> 3) scanline_read_iterator is an input iterator, do you also plan output one too?
>
> Not before the release. But logically I don't think there is much
> interest. What do you think?

The example that I originally presented for needing line-by-line access
was to read in a very large image and cut it into tiles, without
needing RAM proportional to the image size. There is an exact converse
case where you might want to combine many smaller images into one
larger one, without needing enough RAM for the whole image. Consider,
for example, the final step in a panorama-stitching program like hugin:
it's entirely reasonable to want to do this on a memory-constrained
platform like a camera or phone.

>> 4) The meat of your example:
>>
>> reader_t reader = make_scanline_reader( file_name, bmp_tag() );
>> byte_t* buffer = new byte_t[ reader._scanline_length ];
>> scanline_read_iterator<reader_t> it =
>> scanline_read_iterator<reader_t>(reader, buffer);
>> scanline_read_iterator<reader_t> end = scanline_read_iterator<reader_t>();
>> int row = 0;
>> while( it != end )
>> {
>> *it; // ?
>>
>> copy_pixels(
>> interleaved_view(reader._info._width, 1,
>> (image_t::view_t::x_iterator) buffer, reader._scanline_length)
>> , subimage_view(view(dst), 0, row, reader._info._width, 1));
>>
>> ++row;
>> }

>> c) Any particular reason you don't use result of the iterator
>> deference directly?

I agree that the way the iterator is dereferenced in that code ("*it;")
is non-obvious. I can't think of any other case where dereferencing an
iterator has such significant side-effects i.e. it writes into an
implied buffer and advances itself. More conventional code might look like:

buffer_t buffer = ......;
iterator begin(.....);
iterator end();
for( iterator it = begin; it != end; ++it )
{
   const buffer_t& b = *it;
   copy_pixels( .... );
}

Here I am explicitly (a) incrementing the iterator, and (b) using the
result of the dereference. I think you can do that and still get the
same performance.

Regards, Phil.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk