add pitch argument to newBlitBufferNative

pull/2/merge
Qingping Hou 12 years ago
parent e02c88a929
commit 97cd1e79a5

@ -44,13 +44,16 @@ inline int setPixel(BlitBuffer *bb, int x, int y, int c) {
return 0; return 0;
} }
int newBlitBufferNative(lua_State *L, int w, int h, BlitBuffer **newBuffer) { /*
* if ptich equals zero, we calculate it as (w + 1) / 2
*/
int newBlitBufferNative(lua_State *L, int w, int h, int pitch, BlitBuffer **newBuffer) {
BlitBuffer *bb = (BlitBuffer*) lua_newuserdata(L, sizeof(BlitBuffer)); BlitBuffer *bb = (BlitBuffer*) lua_newuserdata(L, sizeof(BlitBuffer));
luaL_getmetatable(L, "blitbuffer"); luaL_getmetatable(L, "blitbuffer");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
bb->w = w; bb->w = w;
bb->pitch = (w + 1) / 2; bb->pitch = ((pitch == 0) ? ((w + 1) / 2) : pitch);
bb->h = h; bb->h = h;
bb->data = malloc(bb->pitch * h); bb->data = malloc(bb->pitch * h);
if(bb->data == NULL) { if(bb->data == NULL) {
@ -67,7 +70,8 @@ int newBlitBufferNative(lua_State *L, int w, int h, BlitBuffer **newBuffer) {
static int newBlitBuffer(lua_State *L) { static int newBlitBuffer(lua_State *L) {
int w = luaL_checkint(L, 1); int w = luaL_checkint(L, 1);
int h = luaL_checkint(L, 2); int h = luaL_checkint(L, 2);
return newBlitBufferNative(L, w, h, NULL); int pitch = luaL_optint(L, 3, 0);
return newBlitBufferNative(L, w, h, pitch, NULL);
} }
static int getWidth(lua_State *L) { static int getWidth(lua_State *L) {
@ -98,7 +102,7 @@ static int blitFullToBuffer(lua_State *L) {
BlitBuffer *src = (BlitBuffer*) luaL_checkudata(L, 2, "blitbuffer"); BlitBuffer *src = (BlitBuffer*) luaL_checkudata(L, 2, "blitbuffer");
if(src->w != dst->w || src->h != dst->h || src->pitch != dst->pitch) { if(src->w != dst->w || src->h != dst->h || src->pitch != dst->pitch) {
return luaL_error(L, "blitbuffer size must be framebuffer size!"); return luaL_error(L, "dst and src blitbuffer size not match!");
} }
memcpy(dst->data, src->data, src->pitch * src->h); memcpy(dst->data, src->data, src->pitch * src->h);

@ -31,7 +31,7 @@ typedef struct BlitBuffer {
uint8_t allocated; uint8_t allocated;
} BlitBuffer; } BlitBuffer;
int newBlitBufferNative(lua_State *L, int w, int h, BlitBuffer **newBuffer); int newBlitBufferNative(lua_State *L, int w, int h, int pitch, BlitBuffer **newBuffer);
int luaopen_blitbuffer(lua_State *L); int luaopen_blitbuffer(lua_State *L);
#endif #endif

@ -78,7 +78,7 @@ static int renderGlyph(lua_State *L) {
lua_newtable(L); lua_newtable(L);
BlitBuffer *bb; BlitBuffer *bb;
int result = newBlitBufferNative(L, w, h, &bb); int result = newBlitBufferNative(L, w, h, 0, &bb);
if(result != 1) { if(result != 1) {
return result; return result;
} }

@ -93,7 +93,7 @@ static int toBlitBuffer(lua_State *L) {
} }
} }
ret = newBlitBufferNative(L, img->pixmap->w, img->pixmap->h, &bb); ret = newBlitBufferNative(L, img->pixmap->w, img->pixmap->h, 0, &bb);
if(ret != 1) { if(ret != 1) {
// TODO (?): fail more gracefully, clean up mem? // TODO (?): fail more gracefully, clean up mem?
return ret; return ret;

Loading…
Cancel
Save