| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/io/image_loader.h" |
| 34 |
|
| 35 |
class ImageLoaderBMP : public ImageFormatLoader { |
| 36 |
protected: |
| 37 |
static const unsigned BITMAP_SIGNATURE = 0x4d42; |
| 38 |
|
| 39 |
static const unsigned BITMAP_FILE_HEADER_SIZE = 14; |
| 40 |
static const unsigned BITMAP_INFO_HEADER_MIN_SIZE = 40; |
| 41 |
|
| 42 |
enum bmp_compression_s { |
| 43 |
BI_RGB = 0x00, |
| 44 |
BI_RLE8 = 0x01, |
| 45 |
BI_RLE4 = 0x02, |
| 46 |
BI_BITFIELDS = 0x03, |
| 47 |
BI_JPEG = 0x04, |
| 48 |
BI_PNG = 0x05, |
| 49 |
BI_ALPHABITFIELDS = 0x06, |
| 50 |
BI_CMYK = 0x0b, |
| 51 |
BI_CMYKRLE8 = 0x0c, |
| 52 |
BI_CMYKRLE4 = 0x0d |
| 53 |
}; |
| 54 |
|
| 55 |
struct bmp_header_s { |
| 56 |
struct bmp_file_header_s { |
| 57 |
uint16_t bmp_signature = 0; |
| 58 |
uint32_t bmp_file_size = 0; |
| 59 |
uint32_t bmp_file_padding = 0; |
| 60 |
uint32_t bmp_file_offset = 0; |
| 61 |
} bmp_file_header; |
| 62 |
|
| 63 |
struct bmp_info_header_s { |
| 64 |
uint32_t bmp_header_size = 0; |
| 65 |
uint32_t bmp_width = 0; |
| 66 |
uint32_t bmp_height = 0; |
| 67 |
uint16_t bmp_planes = 0; |
| 68 |
uint16_t bmp_bit_count = 0; |
| 69 |
uint32_t bmp_compression = 0; |
| 70 |
uint32_t bmp_size_image = 0; |
| 71 |
uint32_t bmp_pixels_per_meter_x = 0; |
| 72 |
uint32_t bmp_pixels_per_meter_y = 0; |
| 73 |
uint32_t bmp_colors_used = 0; |
| 74 |
uint32_t bmp_important_colors = 0; |
| 75 |
} bmp_info_header; |
| 76 |
|
| 77 |
struct bmp_bitfield_s { |
| 78 |
uint16_t alpha_mask = 0x8000; |
| 79 |
uint16_t red_mask = 0x7C00; |
| 80 |
uint16_t green_mask = 0x03E0; |
| 81 |
uint16_t blue_mask = 0x001F; |
| 82 |
uint16_t alpha_mask_width = 1u; |
| 83 |
uint16_t red_mask_width = 5u; |
| 84 |
uint16_t green_mask_width = 5u; |
| 85 |
uint16_t blue_mask_width = 5u; |
| 86 |
uint8_t alpha_offset = 15u; |
| 87 |
uint8_t red_offset = 10u; |
| 88 |
uint8_t green_offset = 5u; |
| 89 |
|
| 90 |
|
| 91 |
uint8_t red_max = 32u; |
| 92 |
uint8_t green_max = 32u; |
| 93 |
uint8_t blue_max = 32u; |
| 94 |
} bmp_bitfield; |
| 95 |
}; |
| 96 |
|
| 97 |
static Error convert_to_image(Ref<Image> p_image, |
| 98 |
const uint8_t *p_buffer, |
| 99 |
const uint8_t *p_color_buffer, |
| 100 |
const uint32_t color_table_size, |
| 101 |
const bmp_header_s &p_header); |
| 102 |
|
| 103 |
public: |
| 104 |
virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> f, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale); |
| 105 |
virtual void get_recognized_extensions(List<String> *p_extensions) const; |
| 106 |
ImageLoaderBMP(); |
| 107 |
}; |