Image.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef IMAGE_H
  2. #define IMAGE_H
  3. #if defined(_WIN32)
  4. # ifdef _GD_CPP_CORE_API_IMPL
  5. # define GD_CPP_CORE_API __declspec(dllexport)
  6. # else
  7. # define GD_CPP_CORE_API __declspec(dllimport)
  8. # endif
  9. #else
  10. # define GD_CPP_CORE_API
  11. #endif
  12. #include "Defs.hpp"
  13. #include "Vector2.hpp"
  14. #include "Rect2.hpp"
  15. #include "Color.hpp"
  16. #include "String.hpp"
  17. #include <godot/godot_image.h>
  18. namespace godot {
  19. class PoolByteArray;
  20. class GD_CPP_CORE_API Image {
  21. godot_image _godot_image;
  22. public:
  23. enum Format {
  24. FORMAT_L8, //luminance
  25. FORMAT_LA8, //luminance-alpha
  26. FORMAT_R8,
  27. FORMAT_RG8,
  28. FORMAT_RGB8,
  29. FORMAT_RGBA8,
  30. FORMAT_RGB565, //16 bit
  31. FORMAT_RGBA4444,
  32. FORMAT_RGBA5551,
  33. FORMAT_RF, //float
  34. FORMAT_RGF,
  35. FORMAT_RGBF,
  36. FORMAT_RGBAF,
  37. FORMAT_RH, //half float
  38. FORMAT_RGH,
  39. FORMAT_RGBH,
  40. FORMAT_RGBAH,
  41. FORMAT_DXT1, //s3tc bc1
  42. FORMAT_DXT3, //bc2
  43. FORMAT_DXT5, //bc3
  44. FORMAT_ATI1, //bc4
  45. FORMAT_ATI2, //bc5
  46. FORMAT_BPTC_RGBA, //btpc bc6h
  47. FORMAT_BPTC_RGBF, //float /
  48. FORMAT_BPTC_RGBFU, //unsigned float
  49. FORMAT_PVRTC2, //pvrtc
  50. FORMAT_PVRTC2A,
  51. FORMAT_PVRTC4,
  52. FORMAT_PVRTC4A,
  53. FORMAT_ETC, //etc1
  54. FORMAT_ETC2_R11, //etc2
  55. FORMAT_ETC2_R11S, //signed, NOT srgb.
  56. FORMAT_ETC2_RG11,
  57. FORMAT_ETC2_RG11S,
  58. FORMAT_ETC2_RGB8,
  59. FORMAT_ETC2_RGBA8,
  60. FORMAT_ETC2_RGB8A1,
  61. FORMAT_MAX
  62. };
  63. enum Interpolation {
  64. INTERPOLATE_NEAREST,
  65. INTERPOLATE_BILINEAR,
  66. INTERPOLATE_CUBIC,
  67. /* INTERPOLATE GAUSS */
  68. };
  69. enum CompressMode {
  70. COMPRESS_16BIT,
  71. COMPRESS_S3TC,
  72. COMPRESS_PVRTC2,
  73. COMPRESS_PVRTC4,
  74. COMPRESS_ETC,
  75. COMPRESS_ETC2
  76. };
  77. Image();
  78. Image(const int width, const int height, const bool mipmaps, const Format format);
  79. void blit_rect(const Image& src, const Rect2& src_rect, const Vector2& dest = Vector2(0, 0));
  80. void brush_transfer(const Image& src, const Image& brush, const Vector2& pos = Vector2(0, 0));
  81. Image brushed(const Image& src, const Image& brush, const Vector2& pos = Vector2(0, 0));
  82. Image compressed(const Format format);
  83. Image converted(const Format format);
  84. Image decompressed();
  85. bool empty() const;
  86. void fix_alpha_edges();
  87. PoolByteArray get_data();
  88. Format get_format() const;
  89. int get_height() const;
  90. Color get_pixel(const int x, const int y, const int mipmap_level = 0);
  91. Image get_rect(const Rect2& area = Rect2());
  92. Rect2 get_used_rect() const;
  93. int get_width() const;
  94. Error load(const String& path);
  95. void put_pixel(const int x, const int y, const Color& color, int mipmap_level = 0);
  96. Image resized(const int x, const int y, const Interpolation interpolation = INTERPOLATE_NEAREST);
  97. Error save_png(const String& path);
  98. ~Image();
  99. };
  100. }
  101. #endif // IMAGE_H