Skip to content

Commit

Permalink
reactivate FFI blitbuffer module
Browse files Browse the repository at this point in the history
This patch should fix koreader/koreader#274
and crashes reported at koreader/koreader#288

1. The shifted x coordinates bug(koreader/koreader#274) is caused by
non-integer x, y or w, h parameters passed to paintRect. It's fixed
in checkBounds method of blitbuffer.

2. The landscape crash reported at koreader/koreader/#288 is a
historied bug in the Lua-C-API of blitbuffer. The paintRoundedCorner
sometimes write over the boundery of blitbuffer and corrupts the heap.
Now this should be fixed in the FII module since the setPixel method
checks very carefully on each pixel write.
  • Loading branch information
chrox committed Oct 15, 2013
1 parent 50b174c commit f406cec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions blitbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ inline int getPixel(BlitBuffer *bb, int x, int y) {
}

inline void setPixel(BlitBuffer *bb, int x, int y, int c) {
// do nothing if not in our range:
if (x < 0 || x >= bb->w || y < 0 || y >= bb->h) return;
uint8_t *dstptr = (uint8_t*)(bb->data) + (y * bb->pitch) + (x / 2);
ASSERT_BLITBUFFER_BOUNDARIES(bb, dstptr);

Expand Down
3 changes: 3 additions & 0 deletions ffi/blitbuffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ generic boundary check for copy operations
@return adapted source offset, guaranteed within range 0..(source_size-1)
--]]
function BB.checkBounds(length, target_offset, source_offset, target_size, source_size)
length, target_size = math.ceil(length), math.ceil(target_size)
target_offset = math.ceil(target_offset)
source_offset = math.ceil(source_offset)
if target_offset < 0 then
length = length + target_offset
source_offset = source_offset - target_offset
Expand Down
2 changes: 1 addition & 1 deletion koreader-base
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require "libs/libkoreader-luagettext"
require "libs/libkoreader-kobolight"

-- libraries converted to FFI:
--Blitbuffer = require("ffi/blitbuffer")
Blitbuffer = require("ffi/blitbuffer")
freetype = require("ffi/freetype")
Image = require("ffi/mupdfimg")
util = require("ffi/util")
Expand Down

0 comments on commit f406cec

Please sign in to comment.