diff --git a/blitbuffer.c b/blitbuffer.c index 2294b8d19..5d0a7b8b3 100644 --- a/blitbuffer.c +++ b/blitbuffer.c @@ -423,6 +423,67 @@ static int invertRect(lua_State *L) { return 0; } +static int dimRect(lua_State *L) { + BlitBuffer *dst = (BlitBuffer*) luaL_checkudata(L, 1, "blitbuffer"); + int x = luaL_checkint(L, 2); + int y = luaL_checkint(L, 3); + int w = luaL_checkint(L, 4); + int h = luaL_checkint(L, 5); + uint8_t *dstptr; + + int cy, cx; + if(w <= 0 || h <= 0 || x >= dst->w || y >= dst->h) { + return 0; + } + if(x + w > dst->w) { + w = dst->w - x; + } + if(y + h > dst->h) { + h = dst->h - y; + } + + if(x & 1) { + /* This will invert 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); + for(cy = 0; cy < h; cy++) { + int px = *dstptr & 0x0F; + *dstptr &= 0xF0 | px << 1; + dstptr += dst->pitch; + } + x++; + w--; + } + dstptr = (uint8_t*)(dst->data + + y * dst->pitch + + x / 2); + for(cy = 0; cy < h; cy++) { + for(cx = 0; cx < w/2; cx++) { + *(dstptr+cx) = + *(dstptr+cx) >> 1 & 0xF0 | + *(dstptr+cx) & 0x0F >> 1; + } + dstptr += dst->pitch; + } + if(w & 1) { + /* This will invert 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) / 2); + for(cy = 0; cy < h; cy++) { + int px = *dstptr & 0xF0; + *dstptr &= 0x0F | ( px >> 1 & 0xF0 ); + dstptr += dst->pitch; + } + } + return 0; +} + static const struct luaL_Reg blitbuffer_func[] = { {"new", newBlitBuffer}, {NULL, NULL} @@ -436,6 +497,7 @@ static const struct luaL_Reg blitbuffer_meth[] = { {"blitFullFrom", blitFullToBuffer}, {"paintRect", paintRect}, {"invertRect", invertRect}, + {"dimRect", dimRect}, {"free", freeBlitBuffer}, {"__gc", freeBlitBuffer}, {NULL, NULL} diff --git a/crereader.lua b/crereader.lua index af3ca86e9..242833cc8 100644 --- a/crereader.lua +++ b/crereader.lua @@ -104,9 +104,9 @@ function CREReader:goto(pos, pos_type) print("## self.show_overlap "..self.show_overlap) if self.show_overlap < 0 then - fb.bb:invertRect(0,0, width, -self.show_overlap) + fb.bb:dimRect(0,0, width, -self.show_overlap) elseif self.show_overlap > 0 then - fb.bb:invertRect(0,height - self.show_overlap, width, self.show_overlap) + fb.bb:dimRect(0,height - self.show_overlap, width, self.show_overlap) end self.show_overlap = 0 diff --git a/unireader.lua b/unireader.lua index e845bd644..5f4c99a97 100644 --- a/unireader.lua +++ b/unireader.lua @@ -555,9 +555,9 @@ function UniReader:show(no) print("## self.show_overlap "..self.show_overlap) if self.show_overlap < 0 then - fb.bb:invertRect(0,0, width, dest_y - self.show_overlap) + fb.bb:dimRect(0,0, width, dest_y - self.show_overlap) elseif self.show_overlap > 0 then - fb.bb:invertRect(0,dest_y + height - self.show_overlap, width, self.show_overlap) + fb.bb:dimRect(0,dest_y + height - self.show_overlap, width, self.show_overlap) end self.show_overlap = 0