Lua (d)bitmap: add hflip and vflip functions
This commit is contained in:
parent
298610752b
commit
9318e4de94
4 changed files with 106 additions and 0 deletions
|
@ -56,6 +56,8 @@ struct lua_bitmap
|
|||
int pset(lua::state& L, lua::parameters& P);
|
||||
int pget(lua::state& L, lua::parameters& P);
|
||||
int size(lua::state& L, lua::parameters& P);
|
||||
int hflip(lua::state& L, lua::parameters& P);
|
||||
int vflip(lua::state& L, lua::parameters& P);
|
||||
int hash(lua::state& L, lua::parameters& P);
|
||||
template<bool scaled, bool porterduff> int blit(lua::state& L, lua::parameters& P);
|
||||
template<bool scaled> int blit_priority(lua::state& L, lua::parameters& P);
|
||||
|
@ -81,6 +83,8 @@ struct lua_dbitmap
|
|||
int pset(lua::state& L, lua::parameters& P);
|
||||
int pget(lua::state& L, lua::parameters& P);
|
||||
int size(lua::state& L, lua::parameters& P);
|
||||
int hflip(lua::state& L, lua::parameters& P);
|
||||
int vflip(lua::state& L, lua::parameters& P);
|
||||
int hash(lua::state& L, lua::parameters& P);
|
||||
template<bool scaled, bool porterduff> int blit(lua::state& L, lua::parameters& P);
|
||||
int save_png(lua::state& L, lua::parameters& P);
|
||||
|
|
51
lua.lyx
51
lua.lyx
|
@ -2422,6 +2422,30 @@ Samples the source as texture, performing linear transform (with nearest-neighbo
|
|||
r sampling) and writes the result to this bitmap.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
Method hflip: Horizontally flip a bitmap
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
Syntax: none bitmap:hflip()
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Horizontally flips a bitmap.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
Method vflip: Vertically flip a bitmap
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
Syntax: none bitmap:vflip()
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Vertically flips a bitmap.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
\begin_inset Newpage pagebreak
|
||||
\end_inset
|
||||
|
@ -3196,6 +3220,33 @@ wrap: boolean: If true, wrap the texture.
|
|||
\begin_layout Standard
|
||||
Samples the source as texture, performing linear transform (with nearest-neighbo
|
||||
r sampling) and writes the result to this bitmap.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
Method hflip: Horizontally flip a bitmap
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
Syntax: none dbitmap:hflip()
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Horizontally flips a bitmap.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
Method vflip: Vertically flip a bitmap
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
Syntax: none dbitmap:vflip()
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Vertically flips a bitmap.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
\begin_inset Newpage pagebreak
|
||||
\end_inset
|
||||
|
||||
|
|
BIN
lua.pdf
BIN
lua.pdf
Binary file not shown.
|
@ -634,6 +634,33 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
template<typename pixel>
|
||||
inline int _hflip(pixel* pixels, uint32_t width, uint32_t height)
|
||||
{
|
||||
uint32_t w = width, h = height;
|
||||
|
||||
for (uint32_t x = 0; x < w/2; x++) {
|
||||
for (uint32_t y = 0; y < h; y++) {
|
||||
std::swap(pixels[y * w + x], pixels[(y + 1) * w - x - 1]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename pixel>
|
||||
inline int _vflip(pixel* pixels, uint32_t width, uint32_t height)
|
||||
{
|
||||
uint32_t w = width, h = height;
|
||||
|
||||
for (uint32_t x = 0; x < w; x++) {
|
||||
for (uint32_t y = 0; y < h/2; y++) {
|
||||
std::swap(pixels[y * w + x], pixels[(h - y - 1) * w + x]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int64_t mangle_color(uint32_t c)
|
||||
{
|
||||
if(c < 0x1000000)
|
||||
|
@ -829,6 +856,8 @@ namespace
|
|||
{"pset", &lua_bitmap::pset},
|
||||
{"pget", &lua_bitmap::pget},
|
||||
{"size", &lua_bitmap::size},
|
||||
{"hflip", &lua_bitmap::hflip},
|
||||
{"vflip", &lua_bitmap::vflip},
|
||||
{"hash", &lua_bitmap::hash},
|
||||
{"blit", &lua_bitmap::blit<false, false>},
|
||||
{"blit_priority", &lua_bitmap::blit_priority<false>},
|
||||
|
@ -850,6 +879,8 @@ namespace
|
|||
{"pset", &lua_dbitmap::pset},
|
||||
{"pget", &lua_dbitmap::pget},
|
||||
{"size", &lua_dbitmap::size},
|
||||
{"hflip", &lua_dbitmap::hflip},
|
||||
{"vflip", &lua_dbitmap::vflip},
|
||||
{"hash", &lua_dbitmap::hash},
|
||||
{"blit", &lua_dbitmap::blit<false, false>},
|
||||
{"blit_scaled", &lua_dbitmap::blit<true, false>},
|
||||
|
@ -1102,6 +1133,16 @@ int lua_bitmap::size(lua::state& L, lua::parameters& P)
|
|||
return 2;
|
||||
}
|
||||
|
||||
int lua_bitmap::hflip(lua::state& L, lua::parameters& P)
|
||||
{
|
||||
return _hflip(pixels, width, height);
|
||||
}
|
||||
|
||||
int lua_bitmap::vflip(lua::state& L, lua::parameters& P)
|
||||
{
|
||||
return _vflip(pixels, width, height);
|
||||
}
|
||||
|
||||
int lua_bitmap::hash(lua::state& L, lua::parameters& P)
|
||||
{
|
||||
sha256 h;
|
||||
|
@ -1289,6 +1330,16 @@ int lua_dbitmap::size(lua::state& L, lua::parameters& P)
|
|||
return 2;
|
||||
}
|
||||
|
||||
int lua_dbitmap::hflip(lua::state& L, lua::parameters& P)
|
||||
{
|
||||
return _hflip(pixels, width, height);
|
||||
}
|
||||
|
||||
int lua_dbitmap::vflip(lua::state& L, lua::parameters& P)
|
||||
{
|
||||
return _vflip(pixels, width, height);
|
||||
}
|
||||
|
||||
int lua_dbitmap::hash(lua::state& L, lua::parameters& P)
|
||||
{
|
||||
sha256 h;
|
||||
|
|
Loading…
Add table
Reference in a new issue