From 97cd1e79a57722873c511d05a999781dfc66534c Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 10 Jan 2013 11:34:00 +0800 Subject: [PATCH] add pitch argument to newBlitBufferNative --- blitbuffer.c | 12 ++++++++---- blitbuffer.h | 2 +- ft.c | 2 +- mupdfimg.c | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/blitbuffer.c b/blitbuffer.c index df0a4f65d..427b28c2d 100644 --- a/blitbuffer.c +++ b/blitbuffer.c @@ -44,13 +44,16 @@ inline int setPixel(BlitBuffer *bb, int x, int y, int c) { 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)); luaL_getmetatable(L, "blitbuffer"); lua_setmetatable(L, -2); bb->w = w; - bb->pitch = (w + 1) / 2; + bb->pitch = ((pitch == 0) ? ((w + 1) / 2) : pitch); bb->h = h; bb->data = malloc(bb->pitch * h); 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) { int w = luaL_checkint(L, 1); 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) { @@ -98,7 +102,7 @@ static int blitFullToBuffer(lua_State *L) { BlitBuffer *src = (BlitBuffer*) luaL_checkudata(L, 2, "blitbuffer"); 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); diff --git a/blitbuffer.h b/blitbuffer.h index d5f8a8b34..51407186f 100644 --- a/blitbuffer.h +++ b/blitbuffer.h @@ -31,7 +31,7 @@ typedef struct BlitBuffer { uint8_t allocated; } 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); #endif diff --git a/ft.c b/ft.c index 38f6b13a4..385ebbecf 100644 --- a/ft.c +++ b/ft.c @@ -78,7 +78,7 @@ static int renderGlyph(lua_State *L) { lua_newtable(L); BlitBuffer *bb; - int result = newBlitBufferNative(L, w, h, &bb); + int result = newBlitBufferNative(L, w, h, 0, &bb); if(result != 1) { return result; } diff --git a/mupdfimg.c b/mupdfimg.c index fe14e5ad6..efd30e1dd 100644 --- a/mupdfimg.c +++ b/mupdfimg.c @@ -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) { // TODO (?): fail more gracefully, clean up mem? return ret;