diff --git a/src/common/imagbmp.cpp b/src/common/imagbmp.cpp index f46ba6b284..c334041367 100644 --- a/src/common/imagbmp.cpp +++ b/src/common/imagbmp.cpp @@ -546,7 +546,13 @@ bool LoadBMPData(wxImage * image, const BMPDesc& desc, // destroy existing here instead of: image->Destroy(); - image->Create(width, height); + // RLE-compressed bitmaps do not necessarily specify every pixel explicitly, + // as the delta escape sequence allows offsetting the current pixel position. + // They have an implicit black background, which we get by clearing the image + // on creation. Otherwise there is no point clearing, because we are going to + // set every pixel from the source data anyway. + bool clear = desc.comp == BI_RLE4 || desc.comp == BI_RLE8; + image->Create(width, height, clear); unsigned char *ptr = image->GetData(); @@ -682,23 +688,6 @@ bool LoadBMPData(wxImage * image, const BMPDesc& desc, } } - /* - * Reading the image data - */ - unsigned char *data = ptr; - - /* set the whole image to the background color */ - if ( bpp < 16 && (desc.comp == BI_RLE4 || desc.comp == BI_RLE8) ) - { - for (int i = 0; i < width * height; i++) - { - *ptr++ = cmap[0].r; - *ptr++ = cmap[0].g; - *ptr++ = cmap[0].b; - } - ptr = data; - } - int linesize = ((width * bpp + 31) / 32) * 4; // flag indicating if we have any not fully transparent alpha values: this diff --git a/tests/image/image.cpp b/tests/image/image.cpp index bc72474000..dc02c95e2e 100644 --- a/tests/image/image.cpp +++ b/tests/image/image.cpp @@ -1381,6 +1381,8 @@ TEST_CASE_METHOD(ImageHandlersInit, "wxImage::BMPLoadMethod", "[image][bmp]") CompareBMPImageLoad("image/horse_grey.bmp"); CompareBMPImageLoad("image/horse_rle8.bmp"); CompareBMPImageLoad("image/horse_rle4.bmp"); + CompareBMPImageLoad("image/rle8-delta-320x240.bmp"); + CompareBMPImageLoad("image/rle4-delta-320x240.bmp"); } #endif // CAN_LOAD_BITMAP_DIRECTLY diff --git a/tests/image/rle8-delta-320x240-expected.bmp b/tests/image/rle8-delta-320x240-expected.bmp index a7e520ca0c..7ea2b88ea7 100644 Binary files a/tests/image/rle8-delta-320x240-expected.bmp and b/tests/image/rle8-delta-320x240-expected.bmp differ