diff --git a/blitbuffer.c b/blitbuffer.c index b149923d8..6345025d7 100644 --- a/blitbuffer.c +++ b/blitbuffer.c @@ -332,9 +332,25 @@ static int paintRect(lua_State *L) { uint8_t *dstptr; int cy; - if(w <= 0 || h <= 0 || x >= dst->w || y >= dst->h) { - return 0; + + if(x < 0) { + if (x+w > 0) { + w += x; + x = 0; + } else { + return 0; + } } + + if(y < 0) { + if (y+h > 0) { + h += y; + y = 0; + } else { + return 0; + } + } + if(x + w > dst->w) { w = dst->w - x; } @@ -342,6 +358,10 @@ static int paintRect(lua_State *L) { h = dst->h - y; } + if(w <= 0 || h <= 0 || x >= dst->w || y >= dst->h) { + return 0; + } + if(x & 1) { /* This will render the leftmost column * in the case when x is odd. After this,