diff options
author | pixel <pixel> | 2004-12-17 11:49:27 +0000 |
---|---|---|
committer | pixel <pixel> | 2004-12-17 11:49:27 +0000 |
commit | fa2e3d6b2c07ac250e1dc1c82d17193949014dc1 (patch) | |
tree | f09ab837e29941b659cbfbedd238c4fd0cd70408 /lib | |
parent | 5133823ad4cb74ed74246f0796fc393e36f64a70 (diff) |
Fixed mode video code
Added fading blit
Diffstat (limited to 'lib')
-rw-r--r-- | lib/luapsx.cpp | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/lib/luapsx.cpp b/lib/luapsx.cpp index 870b67b..986bd62 100644 --- a/lib/luapsx.cpp +++ b/lib/luapsx.cpp @@ -17,12 +17,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: luapsx.cpp,v 1.9 2004-12-13 21:42:59 pixel Exp $ */ +/* $Id: luapsx.cpp,v 1.10 2004-12-17 11:49:27 pixel Exp $ */ #include <LuaHandle.h> #include "luapsx.h" #include "generic.h" +lua_Number alpha_parameter; + void over(Byte * d, Byte R, Byte G, Byte B, Byte A) { d[0] = R; d[1] = G; @@ -37,25 +39,30 @@ void alpha(Byte d[3], Byte R, Byte G, Byte B, Byte A) { } void lighten(Byte * d, Byte R, Byte G, Byte B, Byte A) { - A = MIN(A, (Byte) 128); - R = ((int)d[0] * (128 - A) + R * A) >> 7; - G = ((int)d[1] * (128 - A) + G * A) >> 7; - B = ((int)d[2] * (128 - A) + B * A) >> 7; + A = MIN(A, (Byte) 255); + R = ((int)d[0] * (255 - A) + R * A) >> 8; + G = ((int)d[1] * (255 - A) + G * A) >> 8; + B = ((int)d[2] * (255 - A) + B * A) >> 8; d[0] = MAX(R, d[0]); d[1] = MAX(G, d[1]); d[2] = MAX(B, d[2]); } void darken(Byte * d, Byte R, Byte G, Byte B, Byte A) { - A = MIN(A, (Byte) 128); - R = ((int)d[0] * (128 - A) + R * A) >> 7; - G = ((int)d[1] * (128 - A) + G * A) >> 7; - B = ((int)d[2] * (128 - A) + B * A) >> 7; + A = MIN(A, (Byte) 255); + R = ((int)d[0] * (255 - A) + R * A) >> 8; + G = ((int)d[1] * (255 - A) + G * A) >> 8; + B = ((int)d[2] * (255 - A) + B * A) >> 8; d[0] = MIN(R, d[0]); d[1] = MIN(G, d[1]); d[2] = MIN(B, d[2]); } +void fade(Byte * d, Byte R, Byte G, Byte B, Byte A) { + A = alpha_parameter * 255; + alpha(d, R, G, B, A); +} + enum { BLIT_OVER = 0, BLIT_OVER32, @@ -64,6 +71,7 @@ enum { BLIT_LIGHTEN32, BLIT_DARKEN, BLIT_DARKEN32, + BLIT_FADE, }; typedef void psx; @@ -75,9 +83,9 @@ enum psx_functions_t { }; struct lua_functypes_t psx_functions[] = { - { PSX_BSDECODE, "bsdecode", 3, 3, { LUA_OBJECT, LUA_NUMBER, LUA_NUMBER } }, - { PSX_BSENCODE, "bsencode", 3, 5, { LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER } }, - { PSX_BLIT, "blit", 9, 9, { LUA_OBJECT, LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER } }, + { PSX_BSDECODE, "bsdecode", 3, 3, { LUA_OBJECT, LUA_NUMBER, LUA_NUMBER } }, + { PSX_BSENCODE, "bsencode", 3, 5, { LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER } }, + { PSX_BLIT, "blit", 9, 10, { LUA_OBJECT, LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER } }, { -1, 0, 0, 0, 0 } }; @@ -124,6 +132,10 @@ void Luapsx::pushstatics(Lua * L) throw (GeneralException ) { L->push("BLIT_DARKEN32"); L->push((lua_Number) BLIT_DARKEN32); L->settable(LUA_GLOBALSINDEX); + + L->push("BLIT_FADE"); + L->push((lua_Number) BLIT_FADE); + L->settable(LUA_GLOBALSINDEX); } int sLua_psx::psx_proceed_statics(Lua * L, int n, int caller) { @@ -236,24 +248,28 @@ int sLua_psx::psx_proceed_statics(Lua * L, int n, int caller) { bytes = 4; op_func = darken; break; + case BLIT_FADE: + bytes = 3; + op_func = fade; + if (n >= 10) + alpha_parameter = L->tonumber(10); + break; default: L->error("Blitting operation unknown."); return 0; } -#if 0 if ((sx + sw) < 0) - return; + return 0; if (sx >= dw) - return; + return 0; if ((sy + sh) < 0) - return; + return 0; if (sy >= dh) - return; -#endif + return 0; if (sy < 0) { sstart -= sw * bytes * sy; |