image_loader_bmp.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*************************************************************************/
  2. /* image_loader_bmp.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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. #ifndef IMAGE_LOADER_BMP_H
  31. #define IMAGE_LOADER_BMP_H
  32. #include "core/io/image_loader.h"
  33. class ImageLoaderBMP : public ImageFormatLoader {
  34. protected:
  35. static const unsigned BITMAP_SIGNATURE = 0x4d42;
  36. static const unsigned BITMAP_FILE_HEADER_SIZE = 14; // bmp_file_header_s
  37. static const unsigned BITMAP_INFO_HEADER_MIN_SIZE = 40; // bmp_info_header_s
  38. enum bmp_compression_s {
  39. BI_RGB = 0x00,
  40. BI_RLE8 = 0x01, // compressed
  41. BI_RLE4 = 0x02, // compressed
  42. BI_BITFIELDS = 0x03,
  43. BI_JPEG = 0x04,
  44. BI_PNG = 0x05,
  45. BI_ALPHABITFIELDS = 0x06,
  46. BI_CMYK = 0x0b,
  47. BI_CMYKRLE8 = 0x0c, // compressed
  48. BI_CMYKRLE4 = 0x0d // compressed
  49. };
  50. struct bmp_header_s {
  51. struct bmp_file_header_s {
  52. uint16_t bmp_signature;
  53. uint32_t bmp_file_size;
  54. uint32_t bmp_file_padding;
  55. uint32_t bmp_file_offset;
  56. } bmp_file_header;
  57. struct bmp_info_header_s {
  58. uint32_t bmp_header_size;
  59. uint32_t bmp_width;
  60. uint32_t bmp_height;
  61. uint16_t bmp_planes;
  62. uint16_t bmp_bit_count;
  63. uint32_t bmp_compression;
  64. uint32_t bmp_size_image;
  65. uint32_t bmp_pixels_per_meter_x;
  66. uint32_t bmp_pixels_per_meter_y;
  67. uint32_t bmp_colors_used;
  68. uint32_t bmp_important_colors;
  69. } bmp_info_header;
  70. };
  71. static Error convert_to_image(Ref<Image> p_image,
  72. const uint8_t *p_buffer,
  73. const uint8_t *p_color_buffer,
  74. const uint32_t color_table_size,
  75. const bmp_header_s &p_header);
  76. public:
  77. virtual Error load_image(Ref<Image> p_image, FileAccess *f,
  78. bool p_force_linear, float p_scale);
  79. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  80. ImageLoaderBMP();
  81. };
  82. #endif // IMAGE_LOADER_BMP_H