I want to write a function for converting BGRA in BGR.
void convertBGRAViewtoBGRView( const boost::gil::bgra8_view_t &src, boost::gil::bgr8_view_t dst )
If I write it like this:
size_t numPixels = src.width() * src.height();
boost::gil::bgra8_view_t::iterator it = src.begin();
boost::gil::bgr8_view_t::iterator itD = dst.begin();
for( int i = 0; i < numPixels; ++i ){
boost::gil::bgra8_pixel_t pixe(it[0]);
*it++;
boost::gil::bgr8_pixel_t pix(pixe[0],pixe[1],pixe[2]);
*itD++ = pix;
}
it works, but it is very slow. So I want to use NEON instructions and therefore I need a pointer for example (UInt8*) or (UInt32*). I tried it like this:
UInt32 *temp = (UInt32*)&src(0,0);
for( int i = 0; i < numPixels; ++i ){
boost::gil::bgr8_pixel_t pixk( (( *temp) & 0xff), ( (*temp>>8) & 0xff), ((*temp >> 16 )& 0xff));
*itD++ = pixk;
temp += 1;
}
This works more or less, but the resulting image isn't correct. I think maybe a problem with alignment. Does anyone have an idea how get it to work? This solution is about 3 times faster than the solution with the iterator.
UPDATE: I checked with the debugger: the src has width 480x360 and till i == 259 everything is correct, but afterwords the solution with iterator and pointer is different.
Thanks.