Change color notation to allow Lua scripts use full truecolor

This commit is contained in:
Ilari Liusvaara 2011-10-21 13:54:47 +03:00
parent 7e924d9c83
commit b8c426662b
7 changed files with 60 additions and 81 deletions

View file

@ -7,6 +7,7 @@
#include <list>
#include <vector>
#include <stdexcept>
#include <iostream>
/**
* Low color (32768 colors) screen from buffer.
@ -255,15 +256,23 @@ struct premultiplied_color
uint32_t hi;
uint32_t lo;
uint16_t inv;
premultiplied_color(uint16_t color, uint8_t alpha) throw()
premultiplied_color(int64_t color) throw()
{
uint32_t c = color;
uint16_t a = alpha;
hi = ((c & 0x7C00) << 9) | ((c & 0x1F) << 3);
lo = ((c & 0x3E0) << 6);
hi *= (a << 3);
lo *= (a << 3);
inv = 256 - (a << 3);
if(color < 0) {
//Transparent.
hi = 0;
lo = 0;
inv = 256;
} else {
uint32_t c = (color & 0xFFFFFF);
uint16_t a = 256 - ((color >> 24) & 0xFF);
hi = c & 0xFF00FF;
lo = c & 0x00FF00;
hi *= a;
lo *= a;
inv = 256 - a;
}
//std::cerr << "Color " << color << " -> hi=" << hi << " lo=" << lo << " inv=" << inv << std::endl;
}
uint32_t blend(uint32_t color) throw()
{

View file

@ -49,10 +49,15 @@ namespace
});
function_ptr_luafun gui_color("gui.color", [](lua_State* LS, const std::string& fname) -> int {
uint32_t r = get_numeric_argument<uint32_t>(LS, 1, fname.c_str());
uint32_t g = get_numeric_argument<uint32_t>(LS, 2, fname.c_str());
uint32_t b = get_numeric_argument<uint32_t>(LS, 3, fname.c_str());
lua_pushnumber(LS, ((r << 7) & 0x7C00) | ((g << 2) & 0x3E0) | ((b >> 3) & 0x1F));
int64_t a = 256;
int64_t r = get_numeric_argument<uint32_t>(LS, 1, fname.c_str());
int64_t g = get_numeric_argument<uint32_t>(LS, 2, fname.c_str());
int64_t b = get_numeric_argument<uint32_t>(LS, 3, fname.c_str());
get_numeric_argument<int64_t>(LS, 4, a, fname.c_str());
if(a > 0)
lua_pushnumber(LS, ((256 - a) << 24) | (r << 16) | (g << 8) | b);
else
lua_pushnumber(LS, -1);
return 1;
});
}

View file

@ -33,15 +33,13 @@ namespace
function_ptr_luafun gui_crosshair("gui.crosshair", [](lua_State* LS, const std::string& fname) -> int {
if(!lua_render_ctx)
return 0;
uint16_t color = 0x7FFFU;
uint8_t alpha = 32;
int64_t color = 0xFFFFFFU;
uint32_t length = 10;
int32_t x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
get_numeric_argument<uint32_t>(LS, 3, length, fname.c_str());
get_numeric_argument<uint16_t>(LS, 4, color, fname.c_str());
get_numeric_argument<uint8_t>(LS, 5, alpha, fname.c_str());
premultiplied_color pcolor(color, alpha);
get_numeric_argument<int64_t>(LS, 4, color, fname.c_str());
premultiplied_color pcolor(color);
lua_render_ctx->queue->add(*new render_object_crosshair(x, y, pcolor, length));
return 0;
});

View file

@ -27,13 +27,11 @@ namespace
function_ptr_luafun gui_pixel("gui.pixel", [](lua_State* LS, const std::string& fname) -> int {
if(!lua_render_ctx)
return 0;
uint16_t color = 0x7FFFU;
uint8_t alpha = 32;
int64_t color = 0xFFFFFFU;
int32_t x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
get_numeric_argument<uint16_t>(LS, 3, color, fname.c_str());
get_numeric_argument<uint8_t>(LS, 4, alpha, fname.c_str());
premultiplied_color pcolor(color, alpha);
get_numeric_argument<int64_t>(LS, 3, color, fname.c_str());
premultiplied_color pcolor(color);
lua_render_ctx->queue->add(*new render_object_pixel(x, y, pcolor));
return 0;
});

View file

@ -42,22 +42,18 @@ namespace
function_ptr_luafun gui_rectangle("gui.rectangle", [](lua_State* LS, const std::string& fname) -> int {
if(!lua_render_ctx)
return 0;
uint16_t outline = 0x7FFFU;
uint8_t outlinealpha = 32;
uint16_t fill = 0;
uint8_t fillalpha = 0;
int64_t outline = 0xFFFFFFU;
int64_t fill = -1;
uint32_t thickness = 1;
int32_t x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
uint32_t width = get_numeric_argument<uint32_t>(LS, 3, fname.c_str());
uint32_t height = get_numeric_argument<uint32_t>(LS, 4, fname.c_str());
get_numeric_argument<uint32_t>(LS, 5, thickness, fname.c_str());
get_numeric_argument<uint16_t>(LS, 6, outline, fname.c_str());
get_numeric_argument<uint8_t>(LS, 7, outlinealpha, fname.c_str());
get_numeric_argument<uint16_t>(LS, 8, fill, fname.c_str());
get_numeric_argument<uint8_t>(LS, 9, fillalpha, fname.c_str());
premultiplied_color poutline(outline, outlinealpha);
premultiplied_color pfill(fill, fillalpha);
get_numeric_argument<int64_t>(LS, 6, outline, fname.c_str());
get_numeric_argument<int64_t>(LS, 7, fill, fname.c_str());
premultiplied_color poutline(outline);
premultiplied_color pfill(fill);
lua_render_ctx->queue->add(*new render_object_rectangle(x, y, width, height, poutline, pfill,
thickness));
return 0;

View file

@ -24,19 +24,15 @@ namespace
function_ptr_luafun gui_text("gui.text", [](lua_State* LS, const std::string& fname) -> int {
if(!lua_render_ctx)
return 0;
uint32_t fgc = 0x7FFFU;
uint32_t bgc = 0;
uint16_t fga = 32;
uint16_t bga = 0;
int64_t fgc = 0xFFFFFFU;
int64_t bgc = -1;
int32_t _x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
int32_t _y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
get_numeric_argument<uint32_t>(LS, 4, fgc, fname.c_str());
get_numeric_argument<uint16_t>(LS, 5, fga, fname.c_str());
get_numeric_argument<uint32_t>(LS, 6, bgc, fname.c_str());
get_numeric_argument<uint16_t>(LS, 7, bga, fname.c_str());
get_numeric_argument<int64_t>(LS, 4, fgc, fname.c_str());
get_numeric_argument<int64_t>(LS, 5, bgc, fname.c_str());
std::string text = get_string_argument(LS, 3, fname.c_str());
premultiplied_color fg(fgc, fga);
premultiplied_color bg(bgc, bga);
premultiplied_color fg(fgc);
premultiplied_color bg(bgc);
lua_render_ctx->queue->add(*new render_object_text(_x, _y, text, fg, bg));
return 0;
});

View file

@ -1837,8 +1837,7 @@ Set the <class> (left, right, top, bottom) gap to specified value (max gap
\end_layout
\begin_layout Subsubsection
gui.text(number x, number y, string text[, number fgc[, number fga[, number
bgc[, number bga]]]])
gui.text(number x, number y, string text[, number fgc[, number bgc]])
\end_layout
\begin_layout Standard
@ -1861,24 +1860,16 @@ text: The text to draw.
\end_layout
\begin_layout Itemize
fgc: Text color (default is 0x7FFF (white))
fgc: Text color (default is 0xFFFFFF (white))
\end_layout
\begin_layout Itemize
fga: Text alpha (default is 32 (opaque))
\end_layout
\begin_layout Itemize
bgc: Background color (default is 0 (black))
\end_layout
\begin_layout Itemize
bga: Background alpha (default is 0 (transparent))
bgc: Background color (default is -1 (transparent))
\end_layout
\begin_layout Subsubsection
gui.rectangle(number x, number y, number width, number height[, number thickness[
, number outline[, number outlinealpha[, number fill[, number fillalpha]]]]])
, number outline[, number fill]]])
\end_layout
\begin_layout Standard
@ -1907,23 +1898,15 @@ thickness: Thickness of outline (default is 1).
\end_layout
\begin_layout Itemize
outline: Color of outline (default is 0x7FFF (white))
outline: Color of outline (default is 0xFFFFFF (white))
\end_layout
\begin_layout Itemize
outlinealpha: Outline alpha (default is 32 (opaque))
\end_layout
\begin_layout Itemize
fill: Color of fil (default is 0 (black))
\end_layout
\begin_layout Itemize
fillalpha: Fill alpha (default is 0 (transparent))
fill: Color of fil (default is -1 (transparent))
\end_layout
\begin_layout Subsubsection
gui.pixel(number x, number y[, number color[, number alpha]])
gui.pixel(number x, number y[, number color])
\end_layout
\begin_layout Standard
@ -1940,16 +1923,11 @@ y: Y-coordinate of the pixel
\end_layout
\begin_layout Itemize
color: Color of the pixel (default is 0x7FFF (white))
\end_layout
\begin_layout Itemize
alpha: Alpha for the pixel (default is 32 (opaque))
color: Color of the pixel (default is 0xFFFFFF (white))
\end_layout
\begin_layout Subsubsection
gui.crosshair(number x, number y[, number length[, number color[, number
alpha]]]
gui.crosshair(number x, number y[, number length[, number color]]
\end_layout
\begin_layout Standard
@ -1970,11 +1948,7 @@ length: Length of the crosshair lines (default 10).
\end_layout
\begin_layout Itemize
color: Color of the crosshair (default is 0x7FFF (white))
\end_layout
\begin_layout Itemize
alpha: Alpha for the crosshair (default is 32 (opaque))
color: Color of the crosshair (default is 0xFFFFFF (white))
\end_layout
\begin_layout Subsubsection
@ -2006,12 +1980,15 @@ Write PNG screenshot of the current frame (no drawings) to specified file.
\end_layout
\begin_layout Subsubsection
gui.color(number r, number g, number b)
gui.color(number r, number g, number b[, number a])
\end_layout
\begin_layout Standard
Returns color (in 16-bit notation Lua scripts use) corresponding to color
(r,g,b), each component in scale 0-255.
Returns color (in notation Lua scripts use) corresponding to color (r,g,b),
each component in scale 0-255.
If a is specified, that is alpha (0 is fully transparent, 256(sic) is fully
opaque).
The default alpha is 256.
\end_layout
\begin_layout Subsection