image_loader_bmp.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. struct bmp_header_s {
  37. struct bmp_file_header_s {
  38. uint16_t bmp_signature;
  39. uint32_t bmp_file_size;
  40. uint32_t bmp_file_padding;
  41. uint32_t bmp_file_offset;
  42. } bmp_file_header;
  43. struct bmp_info_header_s {
  44. uint32_t bmp_header_size;
  45. uint32_t bmp_width;
  46. uint32_t bmp_height;
  47. uint16_t bmp_planes;
  48. uint16_t bmp_bit_count;
  49. uint32_t bmp_compression;
  50. uint32_t bmp_size_image;
  51. uint32_t bmp_pixels_per_meter_x;
  52. uint32_t bmp_pixels_per_meter_y;
  53. uint32_t bmp_colors_used;
  54. uint32_t bmp_important_colors;
  55. uint32_t bmp_red_mask;
  56. uint32_t bmp_green_mask;
  57. uint32_t bmp_blue_mask;
  58. uint32_t bmp_alpha_mask;
  59. uint32_t bmp_cs_type;
  60. uint32_t bmp_endpoints[9];
  61. uint32_t bmp_gamma_red;
  62. uint32_t bmp_gamma_green;
  63. uint32_t bmp_gamma_blue;
  64. } bmp_info_header;
  65. };
  66. static Error convert_to_image(Ref<Image> p_image,
  67. const uint8_t *p_buffer,
  68. const uint8_t *p_color_buffer,
  69. const bmp_header_s &p_header);
  70. public:
  71. virtual Error load_image(Ref<Image> p_image, FileAccess *f,
  72. bool p_force_linear, float p_scale);
  73. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  74. ImageLoaderBMP();
  75. };
  76. #endif // IMAGE_LOADER_BMP_H