From 5c744a9fb041ddb0bf08679f2f67a7e9b206ffe4 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 10 Oct 2023 09:31:48 -0400 Subject: [PATCH] pdf: Add a --render-repeats=N flag It calls render() N times instead of just once. Useful for benchmarking. --- Userland/Utilities/pdf.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Userland/Utilities/pdf.cpp b/Userland/Utilities/pdf.cpp index 545bdb0732..65ffe449ea 100644 --- a/Userland/Utilities/pdf.cpp +++ b/Userland/Utilities/pdf.cpp @@ -60,9 +60,11 @@ static PDF::PDFErrorOr> render_page(PDF::Document& do return bitmap; } -static PDF::PDFErrorOr save_rendered_page(PDF::Document& document, int page_index, StringView out_path) +static PDF::PDFErrorOr save_rendered_page(PDF::Document& document, int page_index, int repeats, StringView out_path) { auto bitmap = TRY(render_page(document, page_index)); + for (int i = 0; i < repeats - 1; ++i) + (void)TRY(render_page(document, page_index)); if (!out_path.ends_with(".png"sv, CaseSensitivity::CaseInsensitive)) return Error::from_string_view("can only save to .png files"sv); @@ -159,6 +161,9 @@ static PDF::PDFErrorOr pdf_main(Main::Arguments arguments) StringView render_path; args_parser.add_option(render_path, "Path to render PDF page to", "render", {}, "FILE.png"); + u32 render_repeats = 1; + args_parser.add_option(render_repeats, "Number of times to render page (for profiling)", "render-repeats", {}, "N"); + args_parser.parse(arguments); auto file = TRY(Core::MappedFile::map(in_path)); @@ -211,7 +216,7 @@ static PDF::PDFErrorOr pdf_main(Main::Arguments arguments) } if (!render_path.is_empty()) { - TRY(save_rendered_page(document, page_index, render_path)); + TRY(save_rendered_page(document, page_index, render_repeats, render_path)); return 0; }