Skip to content

Commit

Permalink
Always enable smoothing when rendering downscaled image
Browse files Browse the repository at this point in the history
and rely on the Interpolate flag only when the image is upscaled.
Fixes #16273.
  • Loading branch information
calixteman committed Apr 24, 2024
1 parent d1f494d commit b511878
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"];
Expand Down

0 comments on commit b511878

Please sign in to comment.