diff options
Diffstat (limited to 'lib/luapsx.cpp')
-rw-r--r-- | lib/luapsx.cpp | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/lib/luapsx.cpp b/lib/luapsx.cpp index da66ac6..6a784d3 100644 --- a/lib/luapsx.cpp +++ b/lib/luapsx.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: luapsx.cpp,v 1.7 2004-11-27 21:47:56 pixel Exp $ */ +/* $Id: luapsx.cpp,v 1.8 2004-12-12 02:14:37 pixel Exp $ */ #include <LuaHandle.h> #include "luapsx.h" @@ -29,11 +29,11 @@ void over(Byte * d, Byte R, Byte G, Byte B, Byte A) { d[2] = B; } -void alpha(Byte * d, Byte R, Byte G, Byte B, Byte A) { - A = MIN(A, (Byte) 128); - d[0] = ((int)d[0] * (128 - A) + R * A) >> 7; - d[1] = ((int)d[1] * (128 - A) + G * A) >> 7; - d[2] = ((int)d[2] * (128 - A) + B * A) >> 7; +void alpha(Byte d[3], Byte R, Byte G, Byte B, Byte A) { + A = MIN(A, (Byte) 255); + d[0] = MIN(((int)d[0] * (255 - A) + R * A) >> 8, 255); + d[1] = MIN(((int)d[1] * (255 - A) + G * A) >> 8, 255); + d[2] = MIN(((int)d[2] * (255 - A) + B * A) >> 8, 255); } void lighten(Byte * d, Byte R, Byte G, Byte B, Byte A) { @@ -133,65 +133,67 @@ int sLua_psx::psx_proceed_statics(Lua * L, int n, int caller) { case PSX_BSDECODE: r = 1; { + bs_init(); Buffer * b = new Buffer(true); Handle * f = (Handle *) LuaObject::getme(L, 1); int width = L->tonumber(2); int height = L->tonumber(3); - Byte * in = (Byte *) malloc(f->GetSize() + 10); + Byte * in = (Byte *) malloc(f->GetSize() + 16); Byte * out = (Byte *) malloc(width * height * 3); LuaBuffer lb(b); lb.pushdestruct(L); f->read(in, f->GetSize()); bs_decode_rgb24(out, (bs_header_t *) in, width, height, 0); - for (int i = 0; i < width * height * 3; i++) { - b[i] = out[i]; - } + b->write(out, width * height * 3); free(out); free(in); } + break; case PSX_BSENCODE: r = 3; { - unsigned short out[0x80000]; + static unsigned short out[0x80000]; + int width, height; Buffer * b = new Buffer(true); LuaBuffer lb(b); lb.pushdestruct(L); Handle * f = (Handle *) LuaObject::getme(L, 1); bs_input_image_t img; - img.width = L->tonumber(2); - img.height = L->tonumber(3); + width = L->tonumber(2); + height = L->tonumber(3); int max_size = 14112, cur_size; int q_scale = 1; if (n >= 4) max_size = L->tonumber(4); if (n >= 5) q_scale = L->tonumber(5); - img.lpbits = (Byte *) malloc(f->GetSize()); - img.top = img.lpbits; - img.nextline = img.width * 3; - img.bit = 24; + Byte * in = (Byte *) malloc(f->GetSize()); - f->read(img.lpbits, f->GetSize()); - - bs_init(); + f->read(in, f->GetSize()); - cur_size = max_size + 1; + bs_init(); for (cur_size = max_size + 1; max_size < cur_size; q_scale++) { + img.width = width; + img.height = height; + img.lpbits = in; + img.top = img.lpbits; + img.nextline = img.width * 3; + img.bit = 24; cur_size = bs_encode((bs_header_t *) out, &img, 2, q_scale, 0); } - - for (int i = 0; i < cur_size; i++) { - b[i] = out[i]; - } + q_scale--; + + b->write(out, cur_size); L->push((lua_Number) cur_size); L->push((lua_Number) q_scale); } + break; case PSX_BLIT: r = 0; { - Handle * d = (Handle *) LuaObject::getme(L, 1); + Buffer * d = (Buffer *) LuaObject::getme(L, 1); Handle * s = (Handle *) LuaObject::getme(L, 2); int dw = L->tonumber(3), dh = L->tonumber(4), @@ -201,7 +203,7 @@ int sLua_psx::psx_proceed_statics(Lua * L, int n, int caller) { sy = L->tonumber(8), bl = L->tonumber(9); int bytes, dstart = 0, dskip = 0, sstart = 0, sskip = 0, i, j; - Byte RGB[3], R, G, B, A = 128; + Byte RGB[3], R, G, B, A = 255; void (*op_func)(Byte *, Byte, Byte, Byte, Byte); switch(bl) { @@ -281,26 +283,25 @@ int sLua_psx::psx_proceed_statics(Lua * L, int n, int caller) { dskip = (dw - sw) * 3; d->seek(dstart); + d->wseek(dstart); s->seek(sstart); - for (i = 0; i < sh; i++, s->seek(sskip, SEEK_CUR), d->seek(dskip, SEEK_CUR)) { + for (i = 0; i < sh; i++, s->seek(sskip, SEEK_CUR), d->seek(dskip, SEEK_CUR), d->wseek(dskip, SEEK_CUR)) { for (j = 0; j < sw; j++) { RGB[0] = d->readU8(); RGB[1] = d->readU8(); RGB[2] = d->readU8(); - d->seek(-3, SEEK_CUR); R = s->readU8(); G = s->readU8(); B = s->readU8(); if (bytes == 4) A = s->readU8(); op_func(RGB, R, G, B, A); - d->writeU8(R); - d->writeU8(G); - d->writeU8(B); + d->writeU8(RGB[0]); + d->writeU8(RGB[1]); + d->writeU8(RGB[2]); } } - } } return r; |