Hello, I just found a bug in ip::flipHorizontal.
Surface.hasAlpha() is used to decide the pixel byte increment.
In the case of BGRX hasAlpha returns false, but the increment should be 4 and not 3.
I am not sure where else hasAlpha is used to decide the byte increment and I am not sure if making hasAlpha return true for BGRX would break something else…
I guess the following should fix the problem in the case of flipHorizontal but not anywhere else:
template<typename T>
void flipHorizontal( SurfaceT<T> *surface )
{
const int32_t height = surface->getHeight();
const int32_t width = surface->getWidth();
const int32_t halfWidth = width / 2;
const int32_t numBytes = surface->getPixelBytes();
for( int32_t y = 0; y < height; ++y ) {
T *rowPtr = surface->getData( ivec2( 0, y ) );
for( int32_t x = 0; x < halfWidth; ++x ) {
for( int c = 0; c < numBytes; ++c ) {
T temp = rowPtr[x*numBytes+c];
rowPtr[x*numBytes+c] = rowPtr[(width-x-1)*numBytes+c];
rowPtr[(width-x-1)*numBytes+c] = temp;
}
}
}
}