| 1 | /**************************************************************************/ |
| 2 | /* image_loader_bmp.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifndef IMAGE_LOADER_BMP_H |
| 32 | #define IMAGE_LOADER_BMP_H |
| 33 | |
| 34 | #include "core/io/image_loader.h" |
| 35 | |
| 36 | class ImageLoaderBMP : public ImageFormatLoader { |
| 37 | protected: |
| 38 | static const unsigned BITMAP_SIGNATURE = 0x4d42; |
| 39 | |
| 40 | static const unsigned = 14; // bmp_file_header_s |
| 41 | static const unsigned = 40; // bmp_info_header_s |
| 42 | |
| 43 | enum bmp_compression_s { |
| 44 | BI_RGB = 0x00, |
| 45 | BI_RLE8 = 0x01, // compressed |
| 46 | BI_RLE4 = 0x02, // compressed |
| 47 | BI_BITFIELDS = 0x03, |
| 48 | BI_JPEG = 0x04, |
| 49 | BI_PNG = 0x05, |
| 50 | BI_ALPHABITFIELDS = 0x06, |
| 51 | BI_CMYK = 0x0b, |
| 52 | BI_CMYKRLE8 = 0x0c, // compressed |
| 53 | BI_CMYKRLE4 = 0x0d // compressed |
| 54 | }; |
| 55 | |
| 56 | struct { |
| 57 | struct { |
| 58 | uint16_t = 0; |
| 59 | uint32_t = 0; |
| 60 | uint32_t = 0; |
| 61 | uint32_t = 0; |
| 62 | } ; |
| 63 | |
| 64 | struct { |
| 65 | uint32_t = 0; |
| 66 | uint32_t = 0; |
| 67 | uint32_t = 0; |
| 68 | uint16_t = 0; |
| 69 | uint16_t = 0; |
| 70 | uint32_t = 0; |
| 71 | uint32_t = 0; |
| 72 | uint32_t = 0; |
| 73 | uint32_t = 0; |
| 74 | uint32_t = 0; |
| 75 | uint32_t = 0; |
| 76 | } ; |
| 77 | |
| 78 | struct { |
| 79 | uint16_t = 0x8000; |
| 80 | uint16_t = 0x7C00; |
| 81 | uint16_t = 0x03E0; |
| 82 | uint16_t = 0x001F; |
| 83 | uint16_t = 1u; |
| 84 | uint16_t = 5u; |
| 85 | uint16_t = 5u; |
| 86 | uint16_t = 5u; |
| 87 | uint8_t = 15u; // Used for bit shifting. |
| 88 | uint8_t = 10u; // Used for bit shifting. |
| 89 | uint8_t = 5u; // Used for bit shifting. |
| 90 | //uint8_t blue_offset = 0u; // Always LSB aligned no shifting needed. |
| 91 | //uint8_t alpha_max = 1u; // Always boolean or on, so no scaling needed. |
| 92 | uint8_t = 32u; // Used for color space scaling. |
| 93 | uint8_t = 32u; // Used for color space scaling. |
| 94 | uint8_t = 32u; // Used for color space scaling. |
| 95 | } ; |
| 96 | }; |
| 97 | |
| 98 | static Error (Ref<Image> p_image, |
| 99 | const uint8_t *p_buffer, |
| 100 | const uint8_t *p_color_buffer, |
| 101 | const uint32_t color_table_size, |
| 102 | const bmp_header_s &); |
| 103 | |
| 104 | public: |
| 105 | virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> f, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale); |
| 106 | virtual void get_recognized_extensions(List<String> *p_extensions) const; |
| 107 | ImageLoaderBMP(); |
| 108 | }; |
| 109 | |
| 110 | #endif // IMAGE_LOADER_BMP_H |
| 111 | |