1 #ifndef _lua__bitmap__hpp__included__
2 #define _lua__bitmap__hpp__included__
7 #include "core/window.hpp"
8 #include "library/lua-base.hpp"
9 #include "library/lua-class.hpp"
10 #include "library/lua-params.hpp"
11 #include "library/framebuffer.hpp"
12 #include "library/threads.hpp"
13 #include "library/string.hpp"
17 std::vector
<framebuffer::color
> lcolors
;
18 framebuffer::color
* colors
;
19 framebuffer::color
* scolors
;
20 lua_palette(lua::state
& L
);
22 const static size_t reserved_colors
= 32;
23 static size_t overcommit() {
24 return lua::overcommit_std_align
+ reserved_colors
* sizeof(framebuffer::color
);
27 threads::lock palette_mutex
;
29 static int create(lua::state
& L
, lua::parameters
& P
);
30 static int load(lua::state
& L
, lua::parameters
& P
);
31 static int load_str(lua::state
& L
, lua::parameters
& P
);
32 int set(lua::state
& L
, lua::parameters
& P
);
33 int get(lua::state
& L
, lua::parameters
& P
);
34 int hash(lua::state
& L
, lua::parameters
& P
);
35 int debug(lua::state
& L
, lua::parameters
& P
);
36 int adjust_transparency(lua::state
& L
, lua::parameters
& P
);
37 void adjust_palette_size(size_t newsize
);
38 void push_back(const framebuffer::color
& c
);
43 lua_bitmap(lua::state
& L
, uint32_t w
, uint32_t h
);
44 static size_t overcommit(uint32_t w
, uint32_t h
) {
45 return lua::overcommit_std_align
+ sizeof(uint16_t) * (size_t)w
* h
;
51 std::vector
<char> save_png(const lua_palette
& pal
) const;
53 static int create(lua::state
& L
, lua::parameters
& P
);
54 template<bool outside
, bool clip
> int draw(lua::state
& L
, lua::parameters
& P
);
55 int pset(lua::state
& L
, lua::parameters
& P
);
56 int pget(lua::state
& L
, lua::parameters
& P
);
57 int size(lua::state
& L
, lua::parameters
& P
);
58 int hash(lua::state
& L
, lua::parameters
& P
);
59 template<bool scaled
, bool porterduff
> int blit(lua::state
& L
, lua::parameters
& P
);
60 template<bool scaled
> int blit_priority(lua::state
& L
, lua::parameters
& P
);
61 int save_png(lua::state
& L
, lua::parameters
& P
);
62 int _save_png(lua::state
& L
, lua::parameters
& P
, bool is_method
);
67 lua_dbitmap(lua::state
& L
, uint32_t w
, uint32_t h
);
68 static size_t overcommit(uint32_t w
, uint32_t h
) {
69 return lua::overcommit_std_align
+ sizeof(framebuffer::color
) * (size_t)w
* h
;
74 framebuffer::color
* pixels
;
75 std::vector
<char> save_png() const;
77 static int create(lua::state
& L
, lua::parameters
& P
);
78 template<bool outside
, bool clip
> int draw(lua::state
& L
, lua::parameters
& P
);
79 int pset(lua::state
& L
, lua::parameters
& P
);
80 int pget(lua::state
& L
, lua::parameters
& P
);
81 int size(lua::state
& L
, lua::parameters
& P
);
82 int hash(lua::state
& L
, lua::parameters
& P
);
83 template<bool scaled
, bool porterduff
> int blit(lua::state
& L
, lua::parameters
& P
);
84 int save_png(lua::state
& L
, lua::parameters
& P
);
85 int adjust_transparency(lua::state
& L
, lua::parameters
& P
);
86 int _save_png(lua::state
& L
, lua::parameters
& P
, bool is_method
);
89 struct lua_loaded_bitmap
94 std::vector
<int64_t> bitmap
;
95 std::vector
<int64_t> palette
;
96 static struct lua_loaded_bitmap
load(std::istream
& stream
);
97 static struct lua_loaded_bitmap
load(const std::string
& name
);
98 template<bool png
> static int load(lua::state
& L
, lua::parameters
& P
);
99 template<bool png
> static int load_str(lua::state
& L
, lua::parameters
& P
);