wxON_BLOCK_EXIT1(&BMPPalette::Free, cmap);
+ bool isUpsideDown = true;
+
+ if (height < 0)
+ {
+ isUpsideDown = false;
+ height = -height;
+ }
+
// destroy existing here instead of:
image->Destroy();
image->Create(width, height);
// this case (see #10915)
bool hasValidAlpha = false;
- /* BMPs are stored upside down */
- for ( int line = (height - 1); line >= 0; line-- )
+ for ( int row = 0; row < height; row++ )
{
+ int line = isUpsideDown ? height - 1 - row : row;
+
int linepos = 0;
for ( int column = 0; column < width ; )
{
{
if ( aByte == 0 )
{
- if ( column > 0 )
- column = width;
+ // end of scanline marker
+ column = width;
+ row--;
}
else if ( aByte == 1 )
{
+ // end of RLE data marker, stop decoding
column = width;
- line = -1;
+ row = height;
}
else if ( aByte == 2 )
{
+ // delta marker, move in image
aByte = stream.GetC();
column += aByte;
linepos = column * bpp / 4;
aByte = stream.GetC();
- line -= aByte; // upside down
+ row += aByte; // upside down
}
else
{
{
if ( aByte == 0 )
{
- /* column = width; */
+ // end of scanline marker
+ column = width;
+ row--;
}
else if ( aByte == 1 )
{
+ // end of RLE data marker, stop decoding
column = width;
- line = -1;
+ row = height;
}
else if ( aByte == 2 )
{
+ // delta marker, move in image
aByte = stream.GetC();
column += aByte;
linepos = column * bpp / 8;
aByte = stream.GetC();
- line += aByte;
+ row -= aByte;
}
else
{
CPPUNIT_TEST( ReadCorruptedTGA );
CPPUNIT_TEST( GIFComment );
CPPUNIT_TEST( DibPadding );
+ CPPUNIT_TEST( BMPFlippingAndRLECompression );
CPPUNIT_TEST_SUITE_END();
void LoadFromSocketStream();
void ReadCorruptedTGA();
void GIFComment();
void DibPadding();
+ void BMPFlippingAndRLECompression();
DECLARE_NO_COPY_CLASS(ImageTestCase)
};
CPPUNIT_ASSERT( image.SaveFile(memOut, wxBITMAP_TYPE_ICO) );
}
+static void CompareBMPImage(const wxString& file1, const wxString& file2)
+{
+ wxImage image1(file1);
+ CPPUNIT_ASSERT( image1.IsOk() );
+
+ wxImage image2(file2);
+ CPPUNIT_ASSERT( image2.IsOk() );
+
+ CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_BMP), image1, 0, &image2);
+}
+
+void ImageTestCase::BMPFlippingAndRLECompression()
+{
+ CompareBMPImage("image/horse_grey.bmp", "image/horse_grey_flipped.bmp");
+
+ CompareBMPImage("image/horse_rle8.bmp", "image/horse_grey.bmp");
+ CompareBMPImage("image/horse_rle8.bmp", "image/horse_rle8_flipped.bmp");
+
+ CompareBMPImage("image/horse_rle4.bmp", "image/horse_rle4_flipped.bmp");
+}
#endif //wxUSE_IMAGE