Skip to content

Commit

Permalink
Merge pull request godotengine#30655 from Xrayez/bmp-compression-fix
Browse files Browse the repository at this point in the history
Fix BMP loader to distinguish between compression types
  • Loading branch information
akien-mga authored Jul 17, 2019
2 parents fa4cb80 + 422a8ff commit 72b5a9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 10 additions & 8 deletions modules/bmp/image_loader_bmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image,
size_t height = (size_t)p_header.bmp_info_header.bmp_height;
size_t bits_per_pixel = (size_t)p_header.bmp_info_header.bmp_bit_count;

if (p_header.bmp_info_header.bmp_compression != BI_RGB) {
err = FAILED;
}
// Check whether we can load it

if (bits_per_pixel == 1) {
Expand Down Expand Up @@ -238,11 +235,16 @@ Error ImageLoaderBMP::load_image(Ref<Image> p_image, FileAccess *f,
bmp_header.bmp_info_header.bmp_colors_used = f->get_32();
bmp_header.bmp_info_header.bmp_important_colors = f->get_32();

// Compressed bitmaps not supported, stop parsing
if (bmp_header.bmp_info_header.bmp_compression != BI_RGB) {
ERR_EXPLAIN("Unsupported bmp file: " + f->get_path());
f->close();
ERR_FAIL_V(ERR_UNAVAILABLE);
switch (bmp_header.bmp_info_header.bmp_compression) {
case BI_RLE8:
case BI_RLE4:
case BI_CMYKRLE8:
case BI_CMYKRLE4: {
// Stop parsing
ERR_EXPLAIN("Compressed BMP files are not supported: " + f->get_path());
f->close();
ERR_FAIL_V(ERR_UNAVAILABLE);
} break;
}
// Don't rely on sizeof(bmp_file_header) as structure padding
// adds 2 bytes offset leading to misaligned color table reading
Expand Down
8 changes: 4 additions & 4 deletions modules/bmp/image_loader_bmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class ImageLoaderBMP : public ImageFormatLoader {

enum bmp_compression_s {
BI_RGB = 0x00,
BI_RLE8 = 0x01,
BI_RLE4 = 0x02,
BI_RLE8 = 0x01, // compressed
BI_RLE4 = 0x02, // compressed
BI_BITFIELDS = 0x03,
BI_JPEG = 0x04,
BI_PNG = 0x05,
BI_ALPHABITFIELDS = 0x06,
BI_CMYK = 0x0b,
BI_CMYKRLE8 = 0x0c,
BI_CMYKRLE4 = 0x0d
BI_CMYKRLE8 = 0x0c, // compressed
BI_CMYKRLE4 = 0x0d // compressed
};

struct bmp_header_s {
Expand Down

0 comments on commit 72b5a9e

Please sign in to comment.