summaryrefslogtreecommitdiff
path: root/source/tools
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-03-21 17:21:11 +0000
committerRobin Watts <robin.watts@artifex.com>2016-03-21 17:46:07 +0000
commitc4d3a9142761a567fce9f66946a917e087c0de67 (patch)
tree04ee2c90be31e6b2f00fe30069bdf8cb87f9961c /source/tools
parentb20bf99a01d5340e4ad0bd58b1039ac94904bdc4 (diff)
downloadmupdf-c4d3a9142761a567fce9f66946a917e087c0de67.tar.xz
Mudraw: Avoid reopening output files.
It makes a strangely large difference in timings if we close and reopen the output file for every page. Only close and reopen the output file for each page if we really need to.
Diffstat (limited to 'source/tools')
-rw-r--r--source/tools/mudraw.c57
1 files changed, 37 insertions, 20 deletions
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c
index 40d01620..0a60b699 100644
--- a/source/tools/mudraw.c
+++ b/source/tools/mudraw.c
@@ -109,6 +109,11 @@ static const format_cs_table_t format_cs_table[] =
};
static char *output = NULL;
+fz_output *out = NULL;
+static int output_pagenum = 0;
+static int output_append = 0;
+static int output_file_per_page = 0;
+
static char *format = NULL;
static int output_format = OUT_NONE;
@@ -144,13 +149,10 @@ static int invert = 0;
static int bandheight = 0;
static int errored = 0;
-static int append = 0;
static fz_stext_sheet *sheet = NULL;
static fz_colorspace *colorspace;
static char *filename;
static int files = 0;
-fz_output *out = NULL;
-static int output_pagenum = 0;
static struct {
int count, total;
@@ -305,7 +307,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
int start;
fz_cookie cookie = { 0 };
fz_rect mediabox;
- int first_page = !append;
+ int first_page = !output_append;
fz_var(list);
fz_var(dev);
@@ -323,19 +325,15 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
fz_bound_page(ctx, page, &mediabox);
- /* Open the output file (using stdout if it's given as '-'), being
- * careful to append if we're not the first page. */
- fz_drop_output(ctx, out);
- if (output && (output[0] != '-' || output[1] != 0) && *output != 0)
+ if (output_file_per_page)
{
char text_buffer[512];
+ fz_drop_output(ctx, out);
fz_snprintf(text_buffer, sizeof(text_buffer), output, pagenum);
- out = fz_new_output_with_path(ctx, text_buffer, append);
- append = !has_percent_d(output);
+ out = fz_new_output_with_path(ctx, text_buffer, output_append);
+ output_append = 1;
}
- else
- out = fz_new_output_with_file_ptr(ctx, stdout, 0);
/* Output any file level (as opposed to page level) headers. */
if (first_page)
@@ -759,7 +757,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
if (list)
fz_drop_display_list(ctx, list);
- if (!append)
+ if (!output_append)
file_level_trailers(ctx);
fz_drop_page(ctx, page);
@@ -1097,6 +1095,19 @@ int mudraw_main(int argc, char **argv)
{
pdfout = pdf_create_document(ctx);
}
+ else if (output_format == OUT_GPROOF)
+ {
+ /* GPROOF files are saved direct. Do not open "output". */
+ }
+ else if (output && (output[0] != '-' || output[1] != 0) && *output != 0)
+ {
+ if (has_percent_d(output))
+ output_file_per_page = 1;
+ else
+ out = fz_new_output_with_path(ctx, output, 0);
+ }
+ else
+ out = fz_new_output_with_file_ptr(ctx, stdout, 0);
timing.count = 0;
timing.total = 0;
@@ -1168,19 +1179,25 @@ int mudraw_main(int argc, char **argv)
errored = 1;
}
- if (pdfout)
+ if (output_append)
+ file_level_trailers(ctx);
+
+ if (output_format == OUT_PDF)
{
if (!output)
output = "out.pdf";
pdf_save_document(ctx, pdfout, output, NULL);
pdf_drop_document(ctx, pdfout);
}
-
- if (append)
- file_level_trailers(ctx);
-
- fz_drop_output(ctx, out);
- out = NULL;
+ else if (output_format == OUT_GPROOF)
+ {
+ /* No output file to close */
+ }
+ else
+ {
+ fz_drop_output(ctx, out);
+ out = NULL;
+ }
if (showtime && timing.count > 0)
{