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