From c2dd2d9897741d3597f15cc9840c7170e2155b46 Mon Sep 17 00:00:00 2001 From: HW Date: Sun, 20 Nov 2011 21:29:59 +0100 Subject: [PATCH] switched blitbuffer to 4bpp (from 8bpp alpha + 8bpp gray) this should allow to cache more, bigger pixmaps. We'll need this for zoomed-in pages. --- blitbuffer.c | 2 +- blitbuffer.h | 1 - einkfb.c | 20 +++++--------------- pdf.c | 22 ++++++++++++++++++++-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/blitbuffer.c b/blitbuffer.c index 35faa1c3a..03f0f675e 100644 --- a/blitbuffer.c +++ b/blitbuffer.c @@ -21,7 +21,7 @@ static int newBlitBuffer(lua_State *L) { int w = luaL_checkint(L, 1); int h = luaL_checkint(L, 2); - BlitBuffer *bb = (BlitBuffer*) lua_newuserdata(L, sizeof(BlitBuffer) + (w * h * BLITBUFFER_BYTESPP) - 1); + BlitBuffer *bb = (BlitBuffer*) lua_newuserdata(L, sizeof(BlitBuffer) + (w * h / 2) - 1); luaL_getmetatable(L, "blitbuffer"); lua_setmetatable(L, -2); diff --git a/blitbuffer.h b/blitbuffer.h index ea3a0105c..36e8f159a 100644 --- a/blitbuffer.h +++ b/blitbuffer.h @@ -28,7 +28,6 @@ typedef struct BlitBuffer { int h; uint8_t data[1]; } BlitBuffer; -#define BLITBUFFER_BYTESPP 2 int luaopen_blitbuffer(lua_State *L); diff --git a/einkfb.c b/einkfb.c index 039d7524a..cb047caaf 100644 --- a/einkfb.c +++ b/einkfb.c @@ -126,16 +126,8 @@ static int blitFullToFrameBuffer(lua_State *L) { return luaL_error(L, "blitbuffer size must be framebuffer size!"); } - uint8_t *fbptr = (uint8_t*)fb->data; - uint32_t *bbptr = (uint32_t*)bb->data; - - int c = fb->vinfo.xres * fb->vinfo.yres / 2; + memcpy(fb->data, bb->data, bb->w * bb->h / 2); - while(c--) { - *fbptr = (((*bbptr & 0x00F00000) >> 20) | (*bbptr & 0x000000F0)) ^ 0xFF; - fbptr++; - bbptr++; - } return 0; } @@ -177,14 +169,12 @@ static int blitToFrameBuffer(lua_State *L) { uint8_t *fbptr = (uint8_t*)(fb->data + ydest * fb->finfo.line_length + xdest / 2); - uint32_t *bbptr = (uint32_t*)(bb->data + - yoffs * bb->w * BLITBUFFER_BYTESPP + - xoffs * BLITBUFFER_BYTESPP); + uint8_t *bbptr = (uint32_t*)(bb->data + + yoffs * bb->w / 2 + + xoffs / 2 ); for(y = 0; y < h; y++) { - for(x = 0; x < w; x++) { - fbptr[x] = (((bbptr[x] & 0x00F00000) >> 20) | (bbptr[x] & 0x000000F0)) ^ 0xFF; - } + memcpy(fbptr, bbptr, w); fbptr += fb->finfo.line_length; bbptr += (bb->w / 2); } diff --git a/pdf.c b/pdf.c index 1e5b82e38..67d80cbfd 100644 --- a/pdf.c +++ b/pdf.c @@ -227,7 +227,7 @@ static int drawPage(lua_State *L) { rect.y0 = luaL_checkint(L, 5); rect.x1 = rect.x0 + bb->w; rect.y1 = rect.y0 + bb->h; - pix = fz_new_pixmap_with_rect_and_data(fz_device_gray, rect, bb->data); + pix = fz_new_pixmap_with_rect(fz_device_gray, rect); fz_clear_pixmap_with_color(pix, 0xff); ctm = fz_translate(-page->page->mediabox.x0, -page->page->mediabox.y1); @@ -235,10 +235,10 @@ static int drawPage(lua_State *L) { ctm = fz_concat(ctm, fz_rotate(page->page->rotate)); ctm = fz_concat(ctm, fz_rotate(dc->rotate)); ctm = fz_concat(ctm, fz_translate(dc->offset_x, dc->offset_y)); - bbox = fz_round_rect(fz_transform_rect(ctm, page->page->mediabox)); dev = fz_new_draw_device(page->doc->glyphcache, pix); #ifdef USE_DISPLAY_LIST #ifdef MUPDF_TRACE + bbox = fz_round_rect(fz_transform_rect(ctm, page->page->mediabox)); fz_device *tdev; tdev = fz_new_trace_device(); fz_execute_display_list(page->list, tdev, ctm, bbox); @@ -246,6 +246,12 @@ static int drawPage(lua_State *L) { #endif fz_execute_display_list(page->list, dev, ctm, bbox); #else +#ifdef MUPDF_TRACE + fz_device *tdev; + tdev = fz_new_trace_device(); + pdf_run_page(page->doc->xref, page->page, tdev, ctm); + fz_free_device(tdev); +#endif pdf_run_page(page->doc->xref, page->page, dev, ctm); #endif if(dc->gamma >= 0.0) { @@ -253,6 +259,18 @@ static int drawPage(lua_State *L) { } fz_free_device(dev); + + uint8_t *bbptr = (uint8_t*)bb->data; + uint32_t *pmptr = (uint32_t*)pix->samples; + + int c = bb->w * bb->h / 2; + + while(c--) { + *bbptr = (((*pmptr & 0x00F00000) >> 20) | (*pmptr & 0x000000F0)) ^ 0xFF; + bbptr++; + pmptr++; + } + fz_drop_pixmap(pix); return 0;