summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-07-17 18:42:33 +0100
committerRobin Watts <robin.watts@artifex.com>2013-07-19 19:54:27 +0100
commitf5f7c0e4dd83257f526b158e3998970717852a0e (patch)
treec34ee93ab7773e4fbe48506c97fb515c03707e57 /platform
parent3c559928d88fccfe17da4953ea1c93ceb42a90cb (diff)
downloadmupdf-f5f7c0e4dd83257f526b158e3998970717852a0e.tar.xz
Initial work on progressive loading
We are testing this using a new -p flag to mupdf that sets a bitrate at which data will appear to arrive progressively as time goes on. For example: mupdf -p 102400 pdf_reference17.pdf Details of the scheme used here are presented in docs/progressive.txt
Diffstat (limited to 'platform')
-rw-r--r--platform/win32/libmupdf.vcproj4
-rw-r--r--platform/x11/pdfapp.c74
-rw-r--r--platform/x11/pdfapp.h1
-rw-r--r--platform/x11/win_main.c26
4 files changed, 99 insertions, 6 deletions
diff --git a/platform/win32/libmupdf.vcproj b/platform/win32/libmupdf.vcproj
index ac9e3707..0fdfd672 100644
--- a/platform/win32/libmupdf.vcproj
+++ b/platform/win32/libmupdf.vcproj
@@ -626,6 +626,10 @@
>
</File>
<File
+ RelativePath="..\..\source\fitz\stream-prog.c"
+ >
+ </File>
+ <File
RelativePath="..\..\source\fitz\stream-read.c"
>
</File>
diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c
index 71561f14..c891558f 100644
--- a/platform/x11/pdfapp.c
+++ b/platform/x11/pdfapp.c
@@ -157,6 +157,11 @@ static void event_cb(pdf_doc_event *event, void *data)
void pdfapp_open(pdfapp_t *app, char *filename, int reload)
{
+ pdfapp_open_progressive(app, filename, reload, 0);
+}
+
+void pdfapp_open_progressive(pdfapp_t *app, char *filename, int reload, int bps)
+{
fz_context *ctx = app->ctx;
char *password = "";
@@ -164,7 +169,32 @@ void pdfapp_open(pdfapp_t *app, char *filename, int reload)
{
pdf_document *idoc;
- app->doc = fz_open_document(ctx, filename);
+ if (bps == 0)
+ {
+ app->doc = fz_open_document(ctx, filename);
+ }
+ else
+ {
+ fz_stream *stream = fz_open_file_progressive(ctx, filename, bps);
+ while (1)
+ {
+ fz_try(ctx)
+ {
+ fz_seek(stream, 0, SEEK_SET);
+ app->doc = fz_open_document_with_stream(ctx, filename, stream);
+ }
+ fz_catch(ctx)
+ {
+ if (fz_caught(ctx) == FZ_ERROR_TRYLATER)
+ {
+ pdfapp_warn(app, "not enough data to open yet");
+ continue;
+ }
+ fz_rethrow(ctx);
+ }
+ break;
+ }
+ }
idoc = pdf_specifics(app->doc);
@@ -193,8 +223,41 @@ void pdfapp_open(pdfapp_t *app, char *filename, int reload)
app->doctitle = strrchr(app->doctitle, '/') + 1;
app->doctitle = fz_strdup(ctx, app->doctitle);
- app->pagecount = fz_count_pages(app->doc);
- app->outline = fz_load_outline(app->doc);
+ while (1)
+ {
+ fz_try(ctx)
+ {
+ app->pagecount = fz_count_pages(app->doc);
+ }
+ fz_catch(ctx)
+ {
+ if (fz_caught(ctx) == FZ_ERROR_TRYLATER)
+ {
+ pdfapp_warn(app, "not enough data to count pages yet");
+ continue;
+ }
+ fz_rethrow(ctx);
+ }
+ break;
+ }
+ while (1)
+ {
+ fz_try(ctx)
+ {
+ app->outline = fz_load_outline(app->doc);
+ }
+ fz_catch(ctx)
+ {
+ if (fz_caught(ctx) == FZ_ERROR_TRYLATER)
+ {
+ pdfapp_warn(app, "not enough data to load outline yet - ignoring");
+ /* FIXME: Set 'outline_deferred' and retry at end? */
+ }
+ else
+ fz_rethrow(ctx);
+ }
+ break;
+ }
}
fz_catch(ctx)
{
@@ -441,6 +504,7 @@ static void pdfapp_loadpage(pdfapp_t *app)
/* Create display lists */
app->page_list = fz_new_display_list(app->ctx);
mdev = fz_new_list_device(app->ctx, app->page_list);
+ cookie.incomplete_ok = 1;
fz_run_page_contents(app->doc, app->page, mdev, &fz_identity, &cookie);
fz_free_device(mdev);
mdev = NULL;
@@ -453,6 +517,10 @@ static void pdfapp_loadpage(pdfapp_t *app)
pdfapp_warn(app, "Errors found on page");
errored = 1;
}
+ if (cookie.incomplete)
+ {
+ pdfapp_warn(app, "Incomplete page rendering");
+ }
}
fz_always(app->ctx)
{
diff --git a/platform/x11/pdfapp.h b/platform/x11/pdfapp.h
index 0b89923e..eabb6ca5 100644
--- a/platform/x11/pdfapp.h
+++ b/platform/x11/pdfapp.h
@@ -130,6 +130,7 @@ struct pdfapp_s
void pdfapp_init(fz_context *ctx, pdfapp_t *app);
void pdfapp_open(pdfapp_t *app, char *filename, int reload);
+void pdfapp_open_progressive(pdfapp_t *app, char *filename, int reload, int bps);
void pdfapp_close(pdfapp_t *app);
int pdfapp_preclose(pdfapp_t *app);
diff --git a/platform/x11/win_main.c b/platform/x11/win_main.c
index a22e7fc0..51dada02 100644
--- a/platform/x11/win_main.c
+++ b/platform/x11/win_main.c
@@ -1143,6 +1143,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
MSG msg;
int code;
fz_context *ctx;
+ int arg;
+ int bps = 0;
ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT);
if (!ctx)
@@ -1157,9 +1159,24 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
winopen();
- if (argc == 2)
+ arg = 1;
+ while (arg < argc)
{
- wcscpy(wbuf, argv[1]);
+ if (!wcscmp(argv[arg], L"-p"))
+ {
+ if (arg+1 < argc)
+ bps = _wtoi(argv[++arg]);
+ else
+ bps = 4096;
+ }
+ else
+ break;
+ arg++;
+ }
+
+ if (arg < argc)
+ {
+ wcscpy(wbuf, argv[arg]);
}
else
{
@@ -1171,7 +1188,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow
if (code == 0)
winerror(&gapp, "cannot convert filename to utf-8");
- pdfapp_open(&gapp, filename, 0);
+ if (bps)
+ pdfapp_open_progressive(&gapp, filename, 0, bps);
+ else
+ pdfapp_open(&gapp, filename, 0);
while (GetMessage(&msg, NULL, 0, 0))
{