Image.pkg 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. $#include "Resource/Image.h"
  2. enum CompressedFormat
  3. {
  4. CF_NONE = 0,
  5. CF_RGBA,
  6. CF_DXT1,
  7. CF_DXT3,
  8. CF_DXT5,
  9. CF_ETC1,
  10. CF_PVRTC_RGB_2BPP,
  11. CF_PVRTC_RGBA_2BPP,
  12. CF_PVRTC_RGB_4BPP,
  13. CF_PVRTC_RGBA_4BPP,
  14. };
  15. class Image : public Resource
  16. {
  17. Image();
  18. ~Image();
  19. bool SetSize(int width, int height, unsigned components);
  20. bool SetSize(int width, int height, int depth, unsigned components);
  21. void SetPixel(int x, int y, const Color& color);
  22. void SetPixel(int x, int y, int z, const Color& color);
  23. void SetPixelInt(int x, int y, unsigned uintColor);
  24. void SetPixelInt(int x, int y, int z, unsigned uintColor);
  25. bool LoadColorLUT(Deserializer& source);
  26. tolua_outside bool ImageLoadColorLUT @ LoadColorLUT(const String fileName);
  27. bool FlipHorizontal();
  28. bool FlipVertical();
  29. bool Resize(int width, int height);
  30. void Clear(const Color& color);
  31. void ClearInt(unsigned uintColor);
  32. bool SaveBMP(const String fileName) const;
  33. bool SavePNG(const String fileName) const;
  34. bool SaveTGA(const String fileName) const;
  35. bool SaveJPG(const String fileName, int quality) const;
  36. bool SaveDDS(const String fileName) const;
  37. bool SaveWEBP(const String fileName, float compression = 0.0f) const;
  38. Color GetPixel(int x, int y) const;
  39. Color GetPixel(int x, int y, int z) const;
  40. unsigned GetPixelInt(int x, int y) const;
  41. unsigned GetPixelInt(int x, int y, int z) const;
  42. Color GetPixelBilinear(float x, float y) const;
  43. Color GetPixelTrilinear(float x, float y, float z) const;
  44. int GetWidth() const;
  45. int GetHeight() const;
  46. int GetDepth() const;
  47. unsigned GetComponents() const;
  48. bool IsCompressed() const;
  49. CompressedFormat GetCompressedFormat() const;
  50. unsigned GetNumCompressedLevels() const;
  51. Image* GetSubimage(const IntRect& rect) const;
  52. bool SetSubimage(const Image* image, const IntRect rect);
  53. bool IsCubemap() const;
  54. bool IsArray() const;
  55. bool IsSRGB() const;
  56. bool HasAlphaChannel() const;
  57. tolua_readonly tolua_property__get_set int width;
  58. tolua_readonly tolua_property__get_set int height;
  59. tolua_readonly tolua_property__get_set int depth;
  60. tolua_readonly tolua_property__get_set unsigned components;
  61. tolua_readonly tolua_property__is_set bool compressed;
  62. tolua_readonly tolua_property__get_set CompressedFormat compressedFormat;
  63. tolua_readonly tolua_property__get_set unsigned numCompressedLevels;
  64. tolua_readonly tolua_property__is_set bool cubemap;
  65. tolua_readonly tolua_property__is_set bool array;
  66. tolua_readonly tolua_property__is_set bool sRGB;
  67. };
  68. ${
  69. #define TOLUA_DISABLE_tolua_ResourceLuaAPI_Image_new00
  70. static int tolua_ResourceLuaAPI_Image_new00(lua_State* tolua_S)
  71. {
  72. return ToluaNewObject<Image>(tolua_S);
  73. }
  74. #define TOLUA_DISABLE_tolua_ResourceLuaAPI_Image_new00_local
  75. static int tolua_ResourceLuaAPI_Image_new00_local(lua_State* tolua_S)
  76. {
  77. return ToluaNewObjectGC<Image>(tolua_S);
  78. }
  79. static bool ImageLoadColorLUT(Image* image, const String& fileName)
  80. {
  81. if (!image)
  82. return false;
  83. File file(image->GetContext());
  84. if (!file.Open(fileName, FILE_READ))
  85. return false;
  86. return image->LoadColorLUT(file);
  87. }
  88. $}