lsnes rr2-β23
[lsnes.git] / include / lua / bitmap.hpp
blob0197c4302127c15168ea56ebd9fa1f54038781d2
1 #ifndef _lua__bitmap__hpp__included__
2 #define _lua__bitmap__hpp__included__
4 #include <vector>
5 #include <string>
6 #include <cstdint>
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"
15 struct lua_palette
17 std::vector<framebuffer::color> lcolors;
18 framebuffer::color* colors;
19 framebuffer::color* scolors;
20 lua_palette(lua::state& L);
21 size_t color_count;
22 const static size_t reserved_colors = 32;
23 static size_t overcommit() {
24 return lua::overcommit_std_align + reserved_colors * sizeof(framebuffer::color);
26 ~lua_palette();
27 threads::lock palette_mutex;
28 std::string print();
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);
41 struct lua_bitmap
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;
47 ~lua_bitmap();
48 size_t width;
49 size_t height;
50 uint16_t* pixels;
51 std::vector<char> save_png(const lua_palette& pal) const;
52 std::string print();
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);
65 struct lua_dbitmap
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;
71 ~lua_dbitmap();
72 size_t width;
73 size_t height;
74 framebuffer::color* pixels;
75 std::vector<char> save_png() const;
76 std::string print();
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
91 size_t w;
92 size_t h;
93 bool d;
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);
103 #endif