From 936ce2d661a31a0ab7305817bcae759ac9b1c510 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 6 Mar 2012 11:10:20 +0800 Subject: [PATCH] fix: bug in paintRect When calculating index of byte for rightmost column, it should be (x + w)/2 not (x + w + 1)/2. --- blitbuffer.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/blitbuffer.c b/blitbuffer.c index 5a7027a8b..1a8253967 100644 --- a/blitbuffer.c +++ b/blitbuffer.c @@ -302,7 +302,9 @@ static int paintRect(lua_State *L) { } if(x & 1) { - /* this will render the leftmost column */ + /* This will render the leftmost column + * in the case when x is odd. After this, + * x will become even. */ dstptr = (uint8_t*)(dst->data + y * dst->pitch + x / 2); @@ -322,9 +324,12 @@ static int paintRect(lua_State *L) { dstptr += dst->pitch; } if(w & 1) { + /* This will render the rightmost column + * in the case when (w & 1) && !(x & 1) or + * !(w & 1) && (x & 1). */ dstptr = (uint8_t*)(dst->data + y * dst->pitch + - (x + w + 1) / 2); + (x + w) / 2); for(cy = 0; cy < h; cy++) { *dstptr &= 0x0F; *dstptr |= (c << 4);