diff --git a/include/lua/bitmap.hpp b/include/lua/bitmap.hpp index 4a6c05fc..1c679cad 100644 --- a/include/lua/bitmap.hpp +++ b/include/lua/bitmap.hpp @@ -61,6 +61,7 @@ struct lua_bitmap template int blit_priority(lua::state& L, lua::parameters& P); int save_png(lua::state& L, lua::parameters& P); int _save_png(lua::state& L, lua::parameters& P, bool is_method); + int sample_texture(lua::state& L, lua::parameters& P); }; struct lua_dbitmap @@ -85,6 +86,7 @@ struct lua_dbitmap int save_png(lua::state& L, lua::parameters& P); int adjust_transparency(lua::state& L, lua::parameters& P); int _save_png(lua::state& L, lua::parameters& P, bool is_method); + int sample_texture(lua::state& L, lua::parameters& P); }; struct lua_loaded_bitmap diff --git a/lua.lyx b/lua.lyx index bdebfc71..dd31c96d 100644 --- a/lua.lyx +++ b/lua.lyx @@ -1,7 +1,9 @@ -#LyX 2.1 created this file. For more info see http://www.lyx.org/ -\lyxformat 474 +#LyX 2.2 created this file. For more info see http://www.lyx.org/ +\lyxformat 508 \begin_document \begin_header +\save_transient_properties true +\origin unavailable \textclass article \use_default_options true \maintain_unincluded_children false @@ -9,16 +11,16 @@ \language_package default \inputencoding auto \fontencoding global -\font_roman default -\font_sans default -\font_typewriter default -\font_math auto +\font_roman "default" "default" +\font_sans "default" "default" +\font_typewriter "default" "default" +\font_math "auto" "auto" \font_default_family default \use_non_tex_fonts false \font_sc false \font_osf false -\font_sf_scale 100 -\font_tt_scale 100 +\font_sf_scale 100 100 +\font_tt_scale 100 100 \graphics default \default_output_format default \output_sync 0 @@ -133,6 +135,10 @@ Drawing and contexts Methods that draw something (unless stated otherwise) require a valid rendering context. This context can come in three ways: +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -175,6 +181,10 @@ Non-negative numbers less than \end_inset ) +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -195,6 +205,10 @@ Non-negative numbers less than \end_inset would be fully transparent. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -316,6 +330,10 @@ n4 steelblue steelblue1 steelblue2 steelblue3 steelblue4 tan tan1 tan2 tan3 \begin_layout Itemize The HSL base color names: hsl-. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -339,6 +357,10 @@ The color names can have a modifier after space (multiple modifiers are allowed, separated by spaces): opaque10, opaque20, opaque25, opaque30, opaque40, opaque50, opaque60, opaque70, opaque75, opaque80, opaque90, opaque, hue{+,-}{1-23}, {saturation,lightness}{+,-}{1-16}. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -451,6 +473,10 @@ addrobj: ADDRESS: The memory address. \begin_layout Itemize type: String: The type of data to map. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -1373,6 +1399,10 @@ Load a palette from file (resolved relative to ). \begin_layout Itemize The file format is a series of lines, each with following format: +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -1887,6 +1917,10 @@ h: number: The height of area to blit. \begin_layout Itemize ck: number: The color key. Pixels with this index are not copied. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -1961,6 +1995,10 @@ vscl: number: Vertical scale factor (integer). \begin_layout Itemize ck: number: The color key. Pixels with this index are not copied. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -2024,6 +2062,10 @@ h: number: The height of area to blit. \begin_layout Itemize operator: string: The operator to use. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -2104,6 +2146,10 @@ vscl: number: Vertical scale factor (integer). \begin_layout Itemize operator: string: The operator to use. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -2321,6 +2367,61 @@ Hashes bitmap and returns crypto-strong hash. Color order in bitmap is significant. \end_layout +\begin_layout Subsubsection +Method sample_texture: Sample a texture +\end_layout + +\begin_layout Itemize +Syntax: none bitmap:sample_texture(BITMAP source, number xx, number xy, + number x0, number yx, number yy, number y0, number scale, boolean wrap) +\end_layout + +\begin_layout Standard +Parameters: +\end_layout + +\begin_layout Itemize +source: BITMAP: The bitmap to sample +\end_layout + +\begin_layout Itemize +xx: number: s times the source x coefficient of target x axis. +\end_layout + +\begin_layout Itemize +xy: number: s times the source y coefficient of target x axis. +\end_layout + +\begin_layout Itemize +x0: number: s times the target x axis offset. +\end_layout + +\begin_layout Itemize +yx: number: s times the source x coefficient of target y axis. +\end_layout + +\begin_layout Itemize +yy: number: s times the source y coefficient of target y axis. +\end_layout + +\begin_layout Itemize +y0: number: s times the target y axis offset. +\end_layout + +\begin_layout Itemize +s: number: Scale of coordinates +\end_layout + +\begin_layout Itemize +wrap: boolean: If true, wrap the texture. + If false, read outside the texture as color 0. +\end_layout + +\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 Standard \begin_inset Newpage pagebreak \end_inset @@ -2652,6 +2753,10 @@ h: number: The height of area to blit. \begin_layout Itemize ck: number: The color key. Pixels with this index are not copied. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -2739,6 +2844,10 @@ vscl: number: Vertical scale factor (integer). \begin_layout Itemize ck: number: The color key. Pixels with this index are not copied. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -2814,6 +2923,10 @@ h: number: The height of area to blit. \begin_layout Itemize operator: string: The operator to use. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -2905,6 +3018,10 @@ vscl: number: Vertical scale factor (integer). \begin_layout Itemize operator: string: The operator to use. +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -3024,6 +3141,65 @@ hash: string: 64-hex digit hash \begin_layout Standard Hashes bitmap and returns crypto-strong hash. +\end_layout + +\begin_layout Subsubsection +Method sample_texture: Sample a texture +\end_layout + +\begin_layout Itemize +Syntax: none bitmap:sample_texture(BITMAP source, number xx, number xy, + number x0, number yx, number yy, number y0, number scale, boolean wrap) +\end_layout + +\begin_layout Standard +Parameters: +\end_layout + +\begin_layout Itemize +source: BITMAP: The bitmap to sample +\end_layout + +\begin_layout Itemize +xx: number: s times the source x coefficient of target x axis. +\end_layout + +\begin_layout Itemize +xy: number: s times the source y coefficient of target x axis. +\end_layout + +\begin_layout Itemize +x0: number: s times the target x axis offset. +\end_layout + +\begin_layout Itemize +yx: number: s times the source x coefficient of target y axis. +\end_layout + +\begin_layout Itemize +yy: number: s times the source y coefficient of target y axis. +\end_layout + +\begin_layout Itemize +y0: number: s times the target y axis offset. +\end_layout + +\begin_layout Itemize +s: number: Scale of coordinates +\end_layout + +\begin_layout Itemize +wrap: boolean: If true, wrap the texture. + If false, read outside the texture as color 0. +\end_layout + +\begin_layout Standard +Samples the source as texture, performing linear transform (with nearest-neighbo +r sampling) and writes the result to this bitmap. +\begin_inset Newpage pagebreak +\end_inset + + \end_layout \begin_layout Subsection @@ -3504,6 +3680,10 @@ unconvered: number: Number of bytes that were not converted (only if \begin_layout Itemize error: string: Error that caused conversion to stop (only if is false). +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -4121,11 +4301,19 @@ Calls function with function and specified arguments. \begin_layout LyX-Code on_paint = loopwrapper(function(wait) +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper \begin_layout LyX-Code while true do +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -4884,6 +5072,10 @@ Set v' to . \begin_layout Enumerate For each q: +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -5839,6 +6031,10 @@ button_count (number): Number of buttons on controller \begin_layout Itemize buttons (array): Array of following info about each button: +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -5995,6 +6191,10 @@ Returns table of tables of all available keys and axes. \begin_layout Itemize value: Last reported value for control +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper @@ -8378,7 +8578,7 @@ Various callback-related functions. \begin_layout Subsection \begin_inset CommandInset label LatexCommand label -name "sub:callback.register:-Register-a" +name "subsec:callback.register:-Register-a" \end_inset @@ -8415,7 +8615,7 @@ paint \begin_layout Subsection \begin_inset CommandInset label LatexCommand label -name "sub:callback.unregister:-Unregister-" +name "subsec:callback.unregister:-Unregister-" \end_inset @@ -8443,7 +8643,7 @@ Syntax: function callback.:register(function cbfun) Synonym for callback.register (section \begin_inset CommandInset ref LatexCommand ref -reference "sub:callback.register:-Register-a" +reference "subsec:callback.register:-Register-a" \end_inset @@ -8462,7 +8662,7 @@ Syntax: function callback.:unregister(function cbfun) Synonym for callback.unregister (section \begin_inset CommandInset ref LatexCommand ref -reference "sub:callback.unregister:-Unregister-" +reference "subsec:callback.unregister:-Unregister-" \end_inset @@ -9049,6 +9249,10 @@ index: Index of button. \begin_layout Itemize type: Type of event, one of: +\begin_inset Separator latexpar +\end_inset + + \end_layout \begin_deeper diff --git a/lua.pdf b/lua.pdf index 7e9f685f..f7b35be0 100644 Binary files a/lua.pdf and b/lua.pdf differ diff --git a/src/lua/gui-bitmap.cpp b/src/lua/gui-bitmap.cpp index 67b3b332..902da8b3 100644 --- a/src/lua/gui-bitmap.cpp +++ b/src/lua/gui-bitmap.cpp @@ -536,6 +536,48 @@ namespace } } + template + inline void _sample_texture(pixel* dest, uint32_t dwidth, uint32_t dheight, pixel* source, uint32_t swidth, + uint32_t sheight, int32_t xx, int32_t xy, int32_t x0, int32_t yx, int32_t yy, int32_t y0, uint32_t s, + bool wrap, pixel transparent) + { + int32_t th = s / 2; + size_t didx = 0; + for(int32_t i = 0; i < (int32_t)dheight; i++) { + int64_t ssx = (int64_t)xy * i + (int64_t)x0; + int64_t ssy = (int64_t)yy * i + (int64_t)y0; + for(int32_t j = 0; j < (int32_t)dwidth; j++) { + //Compute whole and fractional parts. + int64_t isx = ssx / (int32_t)s; + int32_t fsx = ssx % (int32_t)s; + int64_t isy = ssy / (int32_t)s; + int32_t fsy = ssy % (int32_t)s; + //Make the fractional parts always positive. + if(fsx < 0) { fsx += s; isx--; } + if(fsy < 0) { fsy += s; isy--; } + //Round the whole parts. + isx += fsx > th; + isy += fsy > th; + //Compute color. + pixel p = transparent; + if(wrap) { + isx = isx % swidth; + if(isx < 0) isx += swidth; + isy = isy % sheight; + if(isy < 0) isy += sheight; + p = source[isy * swidth + isx]; + } else if(isx >= 0 && isx < swidth && isy >= 0 && isy < sheight) { + p = source[isy * swidth + isx]; + } + dest[didx] = p; + //Update values for next pixel. + ssx += (int64_t)xx; + ssy += (int64_t)yx; + didx++; + } + } + } + inline int64_t mangle_color(uint32_t c) { if(c < 0x1000000) @@ -739,6 +781,7 @@ namespace {"blit_porterduff", &lua_bitmap::blit}, {"blit_scaled_porterduff", &lua_bitmap::blit}, {"save_png", &lua_bitmap::save_png}, + {"sample_texture", &lua_bitmap::sample_texture}, }, &lua_bitmap::print); lua::_class LUA_class_dbitmap(lua_class_gui, "DBITMAP", { @@ -758,6 +801,7 @@ namespace {"blit_scaled_porterduff", &lua_dbitmap::blit}, {"save_png", &lua_dbitmap::save_png}, {"adjust_transparency", &lua_dbitmap::adjust_transparency}, + {"sample_texture", &lua_dbitmap::sample_texture}, }, &lua_dbitmap::print); } @@ -1088,6 +1132,21 @@ int lua_bitmap::save_png(lua::state& L, lua::parameters& P) } } +int lua_bitmap::sample_texture(lua::state& L, lua::parameters& P) +{ + lua_bitmap* src_p; + int32_t xx, xy, yx, yy, x0, y0; + uint32_t s; + bool wrap; + uint16_t trans = 0; + + P(P.skipped(), src_p, xx, xy, x0, yx, yy, y0, s, wrap); + + _sample_texture(pixels, width, height, src_p->pixels, src_p->width, src_p->height, xx, xy, x0, yx, yy, y0, + s, wrap, trans); + return 0; +} + /** DBITMAP **/ lua_dbitmap::lua_dbitmap(lua::state& L, uint32_t w, uint32_t h) { @@ -1288,6 +1347,19 @@ int lua_dbitmap::adjust_transparency(lua::state& L, lua::parameters& P) return 0; } +int lua_dbitmap::sample_texture(lua::state& L, lua::parameters& P) +{ + lua_dbitmap* src_p; + int32_t xx, xy, yx, yy, x0, y0; + uint32_t s; + bool wrap; + + P(P.skipped(), src_p, xx, xy, x0, yx, yy, y0, s, wrap); + + _sample_texture(pixels, width, height, src_p->pixels, src_p->width, src_p->height, xx, xy, x0, yx, yy, y0, + s, wrap, framebuffer::color()); + return 0; +} template int lua_loaded_bitmap::load(lua::state& L, lua::parameters& P) {