Merge pull request #16117 from calixteman/workaround_bug1820511

Avoid to have a factor too close to 2 when downscaling image
This commit is contained in:
calixteman 2023-03-08 11:12:56 +01:00 committed by GitHub
commit cc555a389b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -193,8 +193,13 @@ class ImageResizer {
for (const step of steps) {
const prevWidth = newWidth;
const prevHeight = newHeight;
newWidth = Math.floor(newWidth / step);
newHeight = Math.floor(newHeight / step);
// See bug 1820511 (Windows specific bug).
// TODO: once the above bug is fixed we could revert to:
// newWidth = Math.floor(newWidth / 2);
newWidth = Math.floor(newWidth / step) - 1;
newHeight = Math.floor(newHeight / step) - 1;
const canvas = new OffscreenCanvas(newWidth, newHeight);
const ctx = canvas.getContext("2d");
ctx.drawImage(

View File

@ -1313,11 +1313,21 @@ class CanvasGraphics {
let newWidth = paintWidth,
newHeight = paintHeight;
if (widthScale > 2 && paintWidth > 1) {
newWidth = Math.ceil(paintWidth / 2);
// See bug 1820511 (Windows specific bug).
// TODO: once the above bug is fixed we could revert to:
// newWidth = Math.ceil(paintWidth / 2);
newWidth =
paintWidth >= 16384
? Math.floor(paintWidth / 2) - 1 || 1
: Math.ceil(paintWidth / 2);
widthScale /= paintWidth / newWidth;
}
if (heightScale > 2 && paintHeight > 1) {
newHeight = Math.ceil(paintHeight / 2);
// TODO: see the comment above.
newHeight =
paintHeight >= 16384
? Math.floor(paintHeight / 2) - 1 || 1
: Math.ceil(paintHeight) / 2;
heightScale /= paintHeight / newHeight;
}
tmpCanvas = this.cachedCanvases.getCanvas(