From 57688a1e57f0eececd45b6b35ca33b8e308cbcb6 Mon Sep 17 00:00:00 2001 From: rxi Date: Fri, 20 Jun 2014 21:30:23 +0100 Subject: [PATCH] Added love.graphics.setPalette() function --- src/graphics.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/graphics.c b/src/graphics.c index 9fa72c9..35b6ec9 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -7,6 +7,7 @@ #include #include +#include #include "luaobj.h" #include "image.h" #include "font.h" @@ -185,6 +186,25 @@ int l_graphics_setFlip(lua_State *L) { } +int l_graphics_setPalette(lua_State *L) { + int idx = luaL_checkint(L, 1); + int r = luaL_checkint(L, 2); + int g = luaL_checkint(L, 3); + int b = luaL_checkint(L, 4); + #define CLAMP(x, a, b) ((x) < (a) ? (a) : (x) > (b) ? (b) : (x)) + idx = CLAMP(idx, 0, 0xff); + r = CLAMP(r, 0, 0xff) >> 2; + g = CLAMP(g, 0, 0xff) >> 2; + b = CLAMP(b, 0, 0xff) >> 2; + #undef CLAMP + outp(0x03c8, idx); + outp(0x03c9, r); + outp(0x03c9, g); + outp(0x03c9, b); + return 0; +} + + int l_graphics_reset(lua_State *L) { int (*funcs[])(lua_State*) = { l_graphics_setBackgroundColor, @@ -452,6 +472,7 @@ int luaopen_graphics(lua_State *L) { { "setCanvas", l_graphics_setCanvas }, { "getFlip", l_graphics_getFlip }, { "setFlip", l_graphics_setFlip }, + { "setPalette", l_graphics_setPalette }, { "reset", l_graphics_reset }, { "clear", l_graphics_clear }, { "present", l_graphics_present },