From b511878ba75e5a1a3779c8bda7cee2644dd6f4d6 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Tue, 2 Apr 2024 14:57:29 +0200 Subject: [PATCH] Always enable smoothing when rendering downscaled image and rely on the Interpolate flag only when the image is upscaled. Fixes #16273. --- src/display/canvas.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index 384b9fd51e913..f5ae6642d5654 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -913,6 +913,14 @@ function composeSMask(ctx, smask, layerCtx, layerBox) { } function getImageSmoothingEnabled(transform, interpolate) { + // In section 8.9.5.3 of the PDF spec, it's mentioned that the interpolate + // flag should be used when the image is upscaled. + // In Firefox, smoothing is always used when downscaling images (bug 1360415). + + if (interpolate) { + return true; + } + const scale = Util.singularValueDecompose2dScale(transform); // Round to a 32bit float so that `<=` check below will pass for numbers that // are very close, but not exactly the same 64bit floats. @@ -921,15 +929,7 @@ function getImageSmoothingEnabled(transform, interpolate) { const actualScale = Math.fround( (globalThis.devicePixelRatio || 1) * PixelsPerInch.PDF_TO_CSS_UNITS ); - if (interpolate !== undefined) { - // If the value is explicitly set use it. - return interpolate; - } else if (scale[0] <= actualScale || scale[1] <= actualScale) { - // Smooth when downscaling. - return true; - } - // Don't smooth when upscaling. - return false; + return scale[0] <= actualScale && scale[1] <= actualScale; } const LINE_CAP_STYLES = ["butt", "round", "square"];