/**************************************************************************/1/* image_loader_bmp.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/io/image_loader.h"3334class ImageLoaderBMP : public ImageFormatLoader {35protected:36static const unsigned BITMAP_SIGNATURE = 0x4d42;3738static const unsigned BITMAP_FILE_HEADER_SIZE = 14; // bmp_file_header_s39static const unsigned BITMAP_INFO_HEADER_MIN_SIZE = 40; // bmp_info_header_s4041enum bmp_compression_s {42BI_RGB = 0x00,43BI_RLE8 = 0x01, // compressed44BI_RLE4 = 0x02, // compressed45BI_BITFIELDS = 0x03,46BI_JPEG = 0x04,47BI_PNG = 0x05,48BI_ALPHABITFIELDS = 0x06,49BI_CMYK = 0x0b,50BI_CMYKRLE8 = 0x0c, // compressed51BI_CMYKRLE4 = 0x0d // compressed52};5354struct bmp_header_s {55struct bmp_file_header_s {56uint16_t bmp_signature = 0;57uint32_t bmp_file_size = 0;58uint32_t bmp_file_padding = 0;59uint32_t bmp_file_offset = 0;60} bmp_file_header;6162struct bmp_info_header_s {63uint32_t bmp_header_size = 0;64uint32_t bmp_width = 0;65uint32_t bmp_height = 0;66uint16_t bmp_planes = 0;67uint16_t bmp_bit_count = 0;68uint32_t bmp_compression = 0;69uint32_t bmp_size_image = 0;70uint32_t bmp_pixels_per_meter_x = 0;71uint32_t bmp_pixels_per_meter_y = 0;72uint32_t bmp_colors_used = 0;73uint32_t bmp_important_colors = 0;74} bmp_info_header;7576struct bmp_bitfield_s {77uint16_t alpha_mask = 0x8000;78uint16_t red_mask = 0x7C00;79uint16_t green_mask = 0x03E0;80uint16_t blue_mask = 0x001F;81uint16_t alpha_mask_width = 1u;82uint16_t red_mask_width = 5u;83uint16_t green_mask_width = 5u;84uint16_t blue_mask_width = 5u;85uint8_t alpha_offset = 15u; // Used for bit shifting.86uint8_t red_offset = 10u; // Used for bit shifting.87uint8_t green_offset = 5u; // Used for bit shifting.88//uint8_t blue_offset = 0u; // Always LSB aligned no shifting needed.89//uint8_t alpha_max = 1u; // Always boolean or on, so no scaling needed.90uint8_t red_max = 32u; // Used for color space scaling.91uint8_t green_max = 32u; // Used for color space scaling.92uint8_t blue_max = 32u; // Used for color space scaling.93} bmp_bitfield;94};9596static Error convert_to_image(Ref<Image> p_image,97const uint8_t *p_buffer,98const uint8_t *p_color_buffer,99const uint32_t color_table_size,100const bmp_header_s &p_header);101102public:103virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> f, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale);104virtual void get_recognized_extensions(List<String> *p_extensions) const;105ImageLoaderBMP();106};107108109