Example #1
0
bool ImageSegmenter::_generateRaw( const ImageWrapper& image,
                                   const Handler& handler ) const
{
    const SegmentParametersList& paramList = _generateSegmentParameters( image );

    // resulting Raw segments
    for( SegmentParametersList::const_iterator it = paramList.begin();
            it != paramList.end(); ++it )
    {
        Segment segment;
        segment.parameters = *it;
        segment.imageData.reserve( segment.parameters.width *
                                   segment.parameters.height *
                                   image.getBytesPerPixel( ));

        if( paramList.size() == 1 )
        {
            // If we are not segmenting the image, just append the image data
            segment.imageData.append( (const char*)image.data,
                                      int(image.getBufferSize( )));
        }
        else // Copy the image subregion
        {
            // assume imageBuffer isn't padded
            const size_t imagePitch = image.width * image.getBytesPerPixel();
            const size_t offset = segment.parameters.y * imagePitch +
                                  segment.parameters.x * image.getBytesPerPixel();
            const char* lineData = (const char*)image.data + offset;

            for( unsigned int i = 0; i < segment.parameters.height; ++i )
            {
                segment.imageData.append( lineData, segment.parameters.width *
                                          image.getBytesPerPixel( ));
                lineData += imagePitch;
            }
        }

        if( !handler( segment ))
            return false;
    }

    return true;
}