Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Build libdjvu #546

Merged
merged 1 commit into from Oct 14, 2017
Merged

[Android] Build libdjvu #546

merged 1 commit into from Oct 14, 2017

Conversation

Frenzie
Copy link
Member

@Frenzie Frenzie commented Oct 14, 2017

@Frenzie
Copy link
Member Author

Frenzie commented Oct 14, 2017

This one's been bugging me a lot on Android, but I was hoping @marmistrz would tackle it.

There don't seem to be any issues. Here's a screenshot on Android with the following test file: https://en.wikisource.org/wiki/File:Test_rs20846.djvu

screenshot_1508008637

@Frenzie
Copy link
Member Author

Frenzie commented Oct 14, 2017

I was trying to grab a DjVu for testing from the Archive.org website as I'm used to and apparently they quit making new ones?!

https://archive.org/post/1053214/djvu-files-for-new-uploads

An atrocious decision.

Btw @poire-z I didn't look into it but this isn't color-enabled yet. A quick glance suggests this might be the place to look:

koreader-base/djvu.c

Lines 600 to 607 in f0cad8f

static int drawPage(lua_State *L) {
DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");
DrawContext *dc = (DrawContext*) lua_topointer(L, 2);
BlitBuffer *bb = (BlitBuffer*) lua_topointer(L, 3);
ddjvu_render_mode_t djvu_render_mode = (int) luaL_checkint(L, 6);
ddjvu_rect_t pagerect, renderrect;
int bbsize = (bb->w)*(bb->h);
uint8_t *imagebuffer = bb->data;

@Frenzie Frenzie merged commit 6002dac into koreader:master Oct 14, 2017
@Frenzie Frenzie deleted the android-djvu branch October 14, 2017 19:50
@poire-z
Copy link
Contributor

poire-z commented Oct 14, 2017

I know. I tried to enable it (and I just tried again), but I can't get something else than this kind of display:
reader_2017-oct-14_231400

There are other parts to tweak:

doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, NULL);

koreader-base/djvu.c

Lines 514 to 528 in f0cad8f

WILLUSBITMAP *dst = &kctx->src;
bmp_init(dst);
dst->width = rrect.w;
dst->height = rrect.h;
dst->bpp = 8;
bmp_alloc(dst);
if (dst->bpp == 8) {
int ii;
for (ii = 0; ii < 256; ii++)
dst->red[ii] = dst->blue[ii] = dst->green[ii] = ii;
}
ddjvu_format_set_row_order(page->doc->pixelformat, 1);
ddjvu_page_render(page->page_ref, 0, &prect, &rrect, page->doc->pixelformat,
bmp_bytewidth(dst), (char *) dst->data);

with various possibilities:

     doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, NULL);
     doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_RGB24, 0, NULL);
     static unsigned int masks[4] = {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000};
     doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_RGBMASK32, 4, masks);

but always that same kind of display.

@Frenzie
Copy link
Member Author

Frenzie commented Oct 14, 2017

The last one sounds the most interesting to me. I wonder why none of them are working though, weird. (NB Haven't tried it myself.)

@poire-z
Copy link
Contributor

poire-z commented Oct 14, 2017

Just for reference, this should make it display correctly the page in colors (with is_color_capable = false commented in djvudocument.lua)

--- a/djvu.c
+++ b/djvu.c
@@ -98,7 +98,9 @@ static int openDocument(lua_State *L) {
        while (! ddjvu_document_decoding_done(doc->doc_ref))
                handle(L, doc->context, True);

-       doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, NULL);
+//     doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, NULL);
+       static unsigned int masks[4] = {0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000};
+       doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_RGBMASK32, 4, masks);
        if (! doc->pixelformat) {
                return luaL_error(L, "cannot create DjVu pixelformat for <%s>", filename);
        }
@@ -603,7 +605,7 @@ static int drawPage(lua_State *L) {
        BlitBuffer *bb = (BlitBuffer*) lua_topointer(L, 3);
        ddjvu_render_mode_t djvu_render_mode = (int) luaL_checkint(L, 6);
        ddjvu_rect_t pagerect, renderrect;
-       int bbsize = (bb->w)*(bb->h);
+       int bbsize = (bb->w)*(bb->h)*4;
        uint8_t *imagebuffer = bb->data;

        /*printf("@page %d, @@zoom:%f, offset: (%d, %d)\n", page->num, dc->zoom, dc->offset_x, dc->offset_y);*/
@@ -638,7 +640,7 @@ static int drawPage(lua_State *L) {
         * So we don't set rotation here.
         */

-       if (!ddjvu_page_render(page->page_ref, djvu_render_mode, &pagerect, &renderrect, page->doc->pixelformat, bb->w, imagebuffer))
+       if (!ddjvu_page_render(page->page_ref, djvu_render_mode, &pagerect, &renderrect, page->doc->pixelformat, bb->w*4, imagebuffer))
                memset(imagebuffer, 0xFF, bbsize);

        /* Gamma correction of the blitbuffer, do we need to build this into BlitBuffer? */

But it then crashes when you change zoom mode to Fit content (which it seems wants some RGB24, but even when you give it RGB24, it truncates the page in its 1/3...)
edit: should be OK with RGB24 and two ->bpp = 8 to change to 24.

@Frenzie
Copy link
Member Author

Frenzie commented Mar 8, 2020

Minor update, upstream has now incorporated this: https://gitlab.com/koreader/djvulibre/-/commit/8e79901a927d7b20b629f5240e64f617d67f3dff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants