diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2017-04-24 13:52:22 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2017-04-27 15:11:37 +0200 |
commit | b3d004e42d14d99ae4c4b53f1b43b7fae0b50649 (patch) | |
tree | c494c4dd6e66d66d31391a9388bb78a623a52ec6 /source/tools | |
parent | 4fe64a86f24b4aa5cb92f35fe025200cf42144ea (diff) | |
download | mupdf-b3d004e42d14d99ae4c4b53f1b43b7fae0b50649.tar.xz |
Use feature defines in tools.
If DISABLE_MUTHREADS is set, don't include the thread helper library.
If FZ_ENABLE_PDF is 0, don't include mupdf/pdf.h.
Diffstat (limited to 'source/tools')
-rw-r--r-- | source/tools/mudraw.c | 21 | ||||
-rw-r--r-- | source/tools/murun.c | 10 |
2 files changed, 28 insertions, 3 deletions
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 0e9ec27d..f1d085ec 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -3,9 +3,14 @@ */ #include "mupdf/fitz.h" + +#if FZ_ENABLE_PDF #include "mupdf/pdf.h" /* for pdf output */ +#endif +#ifndef DISABLE_MUTHREADS #include "mupdf/helpers/mu-threads.h" +#endif /* Enable for helpful threading debug */ /* #define DEBUG_THREADS(A) do { printf A; fflush(stdout); } while (0) */ @@ -176,9 +181,11 @@ typedef struct worker_t { fz_pixmap *pix; fz_bitmap *bit; fz_cookie cookie; +#ifndef DISABLE_MUTHREADS mu_semaphore start; mu_semaphore stop; mu_thread thread; +#endif } worker_t; static char *output = NULL; @@ -242,9 +249,11 @@ static struct { int active; int started; fz_context *ctx; +#ifndef DISABLE_MUTHREADS mu_thread thread; mu_semaphore start; mu_semaphore stop; +#endif int pagenum; char *filename; fz_display_list *list; @@ -731,8 +740,10 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in workers[band].list = list; workers[band].pix = fz_new_pixmap_with_bbox(ctx, colorspace, &band_ibounds, alpha); fz_set_pixmap_resolution(ctx, workers[band].pix, resolution, resolution); +#ifndef DISABLE_MUTHREADS DEBUG_THREADS(("Worker %d, Pre-triggering band %d\n", band, band)); mu_trigger_semaphore(&workers[band].start); +#endif ctm.f -= drawheight; } pix = workers[0].pix; @@ -783,8 +794,10 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in if (num_workers > 0) { worker_t *w = &workers[band % num_workers]; +#ifndef DISABLE_MUTHREADS DEBUG_THREADS(("Waiting for worker %d to complete band %d\n", w->num, band)); mu_wait_semaphore(&w->stop); +#endif pix = w->pix; bit = w->bit; w->bit = NULL; @@ -808,8 +821,10 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in w->ctm = ctm; w->tbounds = tbounds; memset(&w->cookie, 0, sizeof(fz_cookie)); +#ifndef DISABLE_MUTHREADS DEBUG_THREADS(("Triggering worker %d for band %d\n", w->num, w->band)); mu_trigger_semaphore(&w->start); +#endif } ctm.f -= drawheight; } @@ -924,7 +939,9 @@ static void bgprint_flush(void) if (!bgprint.active || !bgprint.started) return; +#ifndef DISABLE_MUTHREADS mu_wait_semaphore(&bgprint.stop); +#endif bgprint.started = 0; } @@ -1030,7 +1047,9 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) bgprint.filename = filename; bgprint.pagenum = pagenum; bgprint.interptime = start; +#ifndef DISABLE_MUTHREADS mu_trigger_semaphore(&bgprint.start); +#endif } else { @@ -1205,6 +1224,7 @@ static inline int iswhite(int ch) static void apply_layer_config(fz_context *ctx, fz_document *doc, const char *lc) { +#if FZ_ENABLE_PDF pdf_document *pdoc = pdf_specifics(ctx, doc); int config = -1; int n, j; @@ -1299,6 +1319,7 @@ static void apply_layer_config(fz_context *ctx, fz_document *doc, const char *lc fprintf(stderr, " <locked>"); fprintf(stderr, "\n"); } +#endif } #ifdef MUDRAW_STANDALONE diff --git a/source/tools/murun.c b/source/tools/murun.c index 85cb521d..76cb54e4 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -1,5 +1,8 @@ #include "mupdf/fitz.h" + +#if FZ_ENABLE_PDF #include "mupdf/pdf.h" +#endif #if FZ_ENABLE_JS @@ -98,6 +101,7 @@ static void jsB_write(js_State *J) static void jsB_read(js_State *J) { + fz_context *ctx = js_getcontext(J); const char *filename = js_tostring(J, 1); FILE *f; char *s; @@ -125,7 +129,7 @@ static void jsB_read(js_State *J) js_error(J, "cannot seek in file: '%s'", filename); } - s = malloc(n + 1); + s = fz_malloc(ctx, n + 1); if (!s) { fclose(f); js_error(J, "cannot allocate storage for file contents: '%s'", filename); @@ -133,14 +137,14 @@ static void jsB_read(js_State *J) t = fread(s, 1, n, f); if (t != n) { - free(s); + fz_free(ctx, s); fclose(f); js_error(J, "cannot read data from file: '%s'", filename); } s[n] = 0; js_pushstring(J, s); - free(s); + fz_free(ctx, s); fclose(f); } |