2
0
mirror of https://github.com/koreader/koreader synced 2024-11-13 19:11:25 +00:00

fix: two bugs in zomming

This commit is contained in:
Qingping Hou 2012-03-04 01:11:34 +08:00
parent 84d6bfe3f8
commit f1fdd9a18c
2 changed files with 13 additions and 9 deletions

14
djvu.c
View File

@ -224,12 +224,13 @@ static int openPage(lua_State *L) {
return 1; return 1;
} }
/* get page size after zoomed */
static int getPageSize(lua_State *L) { static int getPageSize(lua_State *L) {
DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage"); DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");
DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext"); DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext");
lua_pushnumber(L, page->info.width); lua_pushnumber(L, dc->zoom * page->info.width);
lua_pushnumber(L, page->info.height); lua_pushnumber(L, dc->zoom * page->info.height);
return 2; return 2;
} }
@ -291,7 +292,7 @@ static int drawPage(lua_State *L) {
ddjvu_format_set_gamma(pixelformat, dc->gamma); ddjvu_format_set_gamma(pixelformat, dc->gamma);
/*ddjvu_format_set_ditherbits(dc->pixelformat, 2);*/ /*ddjvu_format_set_ditherbits(dc->pixelformat, 2);*/
/*printf("@page %d, @@zoom:%f\n", page->num, dc->zoom);*/ printf("@page %d, @@zoom:%f, offset: (%d, %d)\n", page->num, dc->zoom, dc->offset_x, dc->offset_y);
/* render full page into rectangle specified by pagerect */ /* render full page into rectangle specified by pagerect */
/*pagerect.x = luaL_checkint(L, 4);*/ /*pagerect.x = luaL_checkint(L, 4);*/
@ -301,7 +302,7 @@ static int drawPage(lua_State *L) {
pagerect.w = page->info.width * dc->zoom; pagerect.w = page->info.width * dc->zoom;
pagerect.h = page->info.height * dc->zoom; pagerect.h = page->info.height * dc->zoom;
/*printf("--pagerect--- (x: %d, y: %d), w: %d, h: %d.\n", 0, 0, pagerect.w, pagerect.h);*/ printf("--pagerect--- (x: %d, y: %d), w: %d, h: %d.\n", 0, 0, pagerect.w, pagerect.h);
/* copy pixels area from pagerect specified by renderrect */ /* copy pixels area from pagerect specified by renderrect */
/* ddjvulibre does not support negative offset, /* ddjvulibre does not support negative offset,
@ -312,7 +313,7 @@ static int drawPage(lua_State *L) {
renderrect.w = MIN(pagerect.w - renderrect.x, bb->w); renderrect.w = MIN(pagerect.w - renderrect.x, bb->w);
renderrect.h = MIN(pagerect.h - renderrect.y, bb->h); renderrect.h = MIN(pagerect.h - renderrect.y, bb->h);
/*printf("--renderrect--- (%d, %d), w:%d, h:%d\n", renderrect.x, renderrect.y, renderrect.w, renderrect.h);*/ printf("--renderrect--- (%d, %d), w:%d, h:%d\n", renderrect.x, renderrect.y, renderrect.w, renderrect.h);
/*@TODO handle rotate 04.03 2012*/ /*@TODO handle rotate 04.03 2012*/
@ -333,7 +334,8 @@ static int drawPage(lua_State *L) {
bbptr += bb->pitch * y_offset; bbptr += bb->pitch * y_offset;
for(y = y_offset; y < bb->h; y++) { for(y = y_offset; y < bb->h; y++) {
for(x = x_offset; x < (bb->w / 2); x++) { /* bbptr's width is half of pmptr's */
for(x = x_offset/2; x < (bb->w / 2); x++) {
/*printf(" --- y: %d, x: %d\n", y, x);*/ /*printf(" --- y: %d, x: %d\n", y, x);*/
bbptr[x] = 255 - (((pmptr[x*2 + 1 - x_offset] & 0xF0) >> 4) | bbptr[x] = 255 - (((pmptr[x*2 + 1 - x_offset] & 0xF0) >> 4) |
(pmptr[x*2 - x_offset] & 0xF0)); (pmptr[x*2 - x_offset] & 0xF0));

View File

@ -147,6 +147,8 @@ function DJVUReader:setzoom(page)
self.offset_y = (height - (self.globalzoom * pheight)) / 2 self.offset_y = (height - (self.globalzoom * pheight)) / 2
if height / pheight < self.globalzoom then if height / pheight < self.globalzoom then
self.globalzoom = height / pheight self.globalzoom = height / pheight
print "adf"
print(width, (self.globalzoom * pwidth))
self.offset_x = (width - (self.globalzoom * pwidth)) / 2 self.offset_x = (width - (self.globalzoom * pwidth)) / 2
self.offset_y = 0 self.offset_y = 0
end end
@ -166,9 +168,9 @@ function DJVUReader:setzoom(page)
self.globalzoom_orig = self.globalzoom self.globalzoom_orig = self.globalzoom
dc:setRotate(self.globalrotate); dc:setRotate(self.globalrotate);
dc:setOffset(self.offset_x, self.offset_y) dc:setOffset(self.offset_x, self.offset_y)
--self.fullwidth, self.fullheight = page:getSize(dc) self.fullwidth, self.fullheight = page:getSize(dc)
self.min_offset_x = fb.bb:getWidth() * (1 - self.globalzoom) self.min_offset_x = fb.bb:getWidth() - self.fullwidth
self.min_offset_y = fb.bb:getHeight() * (1 - self.globalzoom) self.min_offset_y = fb.bb:getHeight() - self.fullheight
if(self.min_offset_x > 0) then if(self.min_offset_x > 0) then
self.min_offset_x = 0 self.min_offset_x = 0
end end