Skip to content

Commit

Permalink
Merge pull request #17868 from calixteman/interpolate_flag
Browse files Browse the repository at this point in the history
Always enable smoothing when rendering downscaled image
  • Loading branch information
calixteman authored Apr 24, 2024
2 parents d1f494d + b511878 commit 90d4b9c
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 90d4b9c

Please sign in to comment.