Change rgba color implementation to use integer number encoding - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2011年11月06日 18:04:21 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2011年11月06日 18:04:21 +0100
commit65ceb0cae23f9ade2f5d7b51e94286e10b525852 (patch)
tree104af7f29cefac8c460e2d3df34c13f20eb2a85d /agg-plot
parent394be1a7f6b20470ff89ef1c2988146fcac6957c (diff)
downloadgsl-shell-65ceb0cae23f9ade2f5d7b51e94286e10b525852.tar.gz
Change rgba color implementation to use integer number encoding
Diffstat (limited to 'agg-plot')
-rw-r--r--agg-plot/colors.cpp 26
-rw-r--r--agg-plot/colors.h 1
-rw-r--r--agg-plot/lua-draw.cpp 104
-rw-r--r--agg-plot/lua-draw.h 3
4 files changed, 17 insertions, 117 deletions
diff --git a/agg-plot/colors.cpp b/agg-plot/colors.cpp
index 39d93828..f6b414a1 100644
--- a/agg-plot/colors.cpp
+++ b/agg-plot/colors.cpp
@@ -4,7 +4,7 @@
#include "lua-cpp-utils.h"
#include "colors.h"
-agg::rgba8
+static agg::rgba8
rgba8_lookup (lua_State *L, const char *color_str)
{
const char *p = color_str;
@@ -49,17 +49,25 @@ agg::rgba8
color_arg_lookup (lua_State *L, int index)
{
if (lua_isnoneornil (L, index))
+ return colors::cdefault;
+
+ if (lua_isnumber(L, index))
{
- return colors::cdefault;
- }
- else if (lua_isstring (L, index))
- {
- const char *cstr = lua_tostring (L, index);
- return rgba8_lookup (L, cstr);
+ unsigned int col = (unsigned int) lua_tointeger (L, index);
+ agg::int8u r = (col & 0xff000000) >> 24;
+ agg::int8u g = (col & 0x00ff0000) >> 16;
+ agg::int8u b = (col & 0x0000ff00) >> 8;
+ agg::int8u a = (col & 0x000000ff);
+
+ return agg::rgba8(r, g, b, a);
}
- agg::rgba8 *pc = object_check<agg::rgba8> (L, index, GS_RGBA_COLOR);
- return *pc;
+ const char *cstr = lua_tostring (L, index);
+
+ if (!cstr)
+ luaL_error (L, "invalid color specification");
+
+ return rgba8_lookup (L, cstr);
}
agg::rgba colors::white(1, 1, 1);
diff --git a/agg-plot/colors.h b/agg-plot/colors.h
index 16016c71..ceba512e 100644
--- a/agg-plot/colors.h
+++ b/agg-plot/colors.h
@@ -8,7 +8,6 @@ extern "C" {
#include "defs.h"
#include "agg_color_rgba.h"
-extern agg::rgba8 rga8_lookup (lua_State *L, const char *color_str);
extern agg::rgba8 color_arg_lookup (lua_State *L, int index);
namespace colors {
diff --git a/agg-plot/lua-draw.cpp b/agg-plot/lua-draw.cpp
index 4b9d83ff..d533e745 100644
--- a/agg-plot/lua-draw.cpp
+++ b/agg-plot/lua-draw.cpp
@@ -62,11 +62,6 @@ static int agg_ellipse_new (lua_State *L);
static int agg_circle_new (lua_State *L);
static int agg_ellipse_free (lua_State *L);
-
-static int agg_rgba_add (lua_State *L);
-static int agg_rgba_mul (lua_State *L);
-static int agg_rgba_set_alpha (lua_State *L);
-
static void path_cmd (draw::path *p, int cmd, struct cmd_call_stack *stack);
static struct path_cmd_reg cmd_table[] = {
@@ -83,8 +78,6 @@ static const struct luaL_Reg draw_functions[] = {
{"path", agg_path_new},
{"ellipse", agg_ellipse_new},
{"circle", agg_circle_new},
- {"rgba", agg_rgba_new},
- {"rgb", agg_rgb_new},
{NULL, NULL}
};
@@ -100,14 +93,6 @@ static const struct luaL_Reg agg_ellipse_methods[] = {
{NULL, NULL}
};
-// no finalizer is needed because rgba does not allocate memory
-static const struct luaL_Reg rgba_methods[] = {
- {"__add", agg_rgba_add },
- {"__mul", agg_rgba_mul },
- {"alpha", agg_rgba_set_alpha },
- {NULL, NULL}
-};
-
int
agg_path_new (lua_State *L)
{
@@ -267,89 +252,6 @@ agg_ellipse_free (lua_State *L)
return object_free<draw::ellipse>(L, 1, GS_DRAW_ELLIPSE);
}
-static unsigned int double2uint8 (double x)
-{
- int u = x * 255.0;
- if (u > 255)
- u = 255;
- else if (u < 0)
- u = 0;
- return (unsigned int) u;
-}
-
-agg::rgba8 *
-check_agg_rgba8 (lua_State *L, int index)
-{
- return (agg::rgba8 *) gs_check_userdata (L, index, GS_RGBA_COLOR);
-}
-
-int
-agg_rgba_new (lua_State *L)
-{
- unsigned int r = double2uint8 (luaL_checknumber (L, 1));
- unsigned int g = double2uint8 (luaL_checknumber (L, 2));
- unsigned int b = double2uint8 (luaL_checknumber (L, 3));
- unsigned int a = double2uint8 (luaL_checknumber (L, 4));
-
- new(L, GS_RGBA_COLOR) agg::rgba8(r, g, b, a);
- return 1;
-}
-
-int
-agg_rgb_new (lua_State *L)
-{
- unsigned int r = double2uint8 (luaL_checknumber (L, 1));
- unsigned int g = double2uint8 (luaL_checknumber (L, 2));
- unsigned int b = double2uint8 (luaL_checknumber (L, 3));
-
- new(L, GS_RGBA_COLOR) agg::rgba8(r, g, b, 255);
- return 1;
-}
-
-int
-agg_rgba_set_alpha (lua_State *L)
-{
- agg::rgba8 *c = object_check<agg::rgba8> (L, 1, GS_RGBA_COLOR);
- double a = luaL_checknumber (L, 2);
- c->a = agg::rgba8::base_mask * a;
- return 0;
-}
-
-int
-agg_rgba_add (lua_State *L)
-{
- agg::rgba8 *c1 = object_check<agg::rgba8> (L, 1, GS_RGBA_COLOR);
- agg::rgba8 *c2 = object_check<agg::rgba8> (L, 2, GS_RGBA_COLOR);
-
- unsigned int r = c1->r + c2->r;
- unsigned int g = c1->g + c2->g;
- unsigned int b = c1->b + c2->b;
-
- new(L, GS_RGBA_COLOR) agg::rgba8(r, g, b);
-
- return 1;
-}
-
-int
-agg_rgba_mul (lua_State *L)
-{
- int is = 1, ic = 2;
-
- if (gs_is_userdata (L, 1, GS_RGBA_COLOR))
- {
- ic = 1;
- is = 2;
- }
-
- double f = luaL_checknumber (L, is);
- agg::rgba8 *c = object_check<agg::rgba8> (L, ic, GS_RGBA_COLOR);
-
- unsigned int r = f * c->r, g = f * c->g, b = f * c->b;
-
- new(L, GS_RGBA_COLOR) agg::rgba8(r, g, b);
- return 1;
-}
-
void
draw_register (lua_State *L)
{
@@ -363,12 +265,6 @@ draw_register (lua_State *L)
luaL_register (L, NULL, agg_ellipse_methods);
lua_pop (L, 1);
- luaL_newmetatable (L, GS_METATABLE(GS_RGBA_COLOR));
- lua_pushvalue (L, -1);
- lua_setfield (L, -2, "__index");
- luaL_register (L, NULL, rgba_methods);
- lua_pop (L, 1);
-
/* gsl module registration */
luaL_register (L, NULL, draw_functions);
}
diff --git a/agg-plot/lua-draw.h b/agg-plot/lua-draw.h
index 55509946..ba2cb500 100644
--- a/agg-plot/lua-draw.h
+++ b/agg-plot/lua-draw.h
@@ -19,11 +19,8 @@ __END_DECLS
extern int agg_text_new (lua_State *L);
extern int agg_path_new (lua_State *L);
-extern int agg_rgb_new (lua_State *L);
-extern int agg_rgba_new (lua_State *L);
extern draw::path* check_agg_path (lua_State *L, int index);
-extern agg::rgba8* check_agg_rgba8 (lua_State *L, int index);
#endif
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月15日 23:22:12 +0000

AltStyle によって変換されたページ (->オリジナル) /