From 9a4750fee5888962ec745af34e06bc87d9b7dc5d Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Fri, 21 Jul 2023 12:52:16 +0200 Subject: [PATCH] Don't uselessly change the filter when drawing When profiling the pdf in https://bugzilla.mozilla.org/show_bug.cgi?id=1508765, I noticed that half a second was spent to set the filter to "none". --- src/display/canvas.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index 1fbd6f28a..821212a5f 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -790,7 +790,10 @@ function resetCtxToDefault(ctx) { (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) || !isNodeJS ) { - ctx.filter = "none"; + const { filter } = ctx; + if (filter !== "none" && filter !== "") { + ctx.filter = "none"; + } } } @@ -2961,7 +2964,10 @@ class CanvasGraphics { // It must be applied to the image before rescaling else some artifacts // could appear. // The final restore will reset it to its value. - ctx.filter = "none"; + const { filter } = ctx; + if (filter !== "none" && filter !== "") { + ctx.filter = "none"; + } } // scale the image to the unit square