Skip to content

Commit

Permalink
Merge pull request #42 from thotypous/bboxoptim
Browse files Browse the repository at this point in the history
Optimize getAutoBBox for djvu files: render on a buffer with the same size as the screen
  • Loading branch information
houqp committed Aug 11, 2013
2 parents b5625d4 + 96894f2 commit 2dfda0d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions djvu.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,14 @@ static int getAutoBBox(lua_State *L) {
KOPTContext *kctx = (KOPTContext*) luaL_checkudata(L, 2, "koptcontext");
ddjvu_rect_t prect;
ddjvu_rect_t rrect;
int px, py, pw, ph, rx, ry, rw, rh, status;

double wfactor = (double)ddjvu_page_get_width(page->page_ref) / kctx->dev_width;
double hfactor = (double)ddjvu_page_get_height(page->page_ref) / kctx->dev_height;

prect.x = 0;
prect.y = 0;
prect.w = ddjvu_page_get_width(page->page_ref);
prect.h = ddjvu_page_get_height(page->page_ref);
prect.w = kctx->dev_width;
prect.h = kctx->dev_height;
rrect = prect;

WILLUSBITMAP *src = &kctx->src;
Expand All @@ -508,10 +510,10 @@ static int getAutoBBox(lua_State *L) {

k2pdfopt_crop_bmp(kctx);

lua_pushnumber(L, ((double)kctx->bbox.x0));
lua_pushnumber(L, ((double)kctx->bbox.y0));
lua_pushnumber(L, ((double)kctx->bbox.x1));
lua_pushnumber(L, ((double)kctx->bbox.y1));
lua_pushnumber(L, floor(wfactor*kctx->bbox.x0));
lua_pushnumber(L, floor(hfactor*kctx->bbox.y0));
lua_pushnumber(L, ceil (wfactor*kctx->bbox.x1));
lua_pushnumber(L, ceil (hfactor*kctx->bbox.y1));

return 4;
}
Expand Down

0 comments on commit 2dfda0d

Please sign in to comment.