Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blurry CVImageElement drawing on high dpi (>1.0) displays #2896

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17,372 changes: 17,372 additions & 0 deletions build/player/cjs/lottie.min.js

Large diffs are not rendered by default.

15,622 changes: 15,622 additions & 0 deletions build/player/cjs/lottie_canvas.min.js

Large diffs are not rendered by default.

15,941 changes: 15,941 additions & 0 deletions build/player/cjs/lottie_html.min.js

Large diffs are not rendered by default.

11,328 changes: 11,328 additions & 0 deletions build/player/cjs/lottie_light.min.js

Large diffs are not rendered by default.

12,760 changes: 12,760 additions & 0 deletions build/player/cjs/lottie_light_canvas.min.js

Large diffs are not rendered by default.

12,533 changes: 12,533 additions & 0 deletions build/player/cjs/lottie_light_html.min.js

Large diffs are not rendered by default.

14,736 changes: 14,736 additions & 0 deletions build/player/cjs/lottie_svg.min.js

Large diffs are not rendered by default.

17,368 changes: 17,368 additions & 0 deletions build/player/esm/lottie.min.js

Large diffs are not rendered by default.

15,618 changes: 15,618 additions & 0 deletions build/player/esm/lottie_canvas.min.js

Large diffs are not rendered by default.

15,937 changes: 15,937 additions & 0 deletions build/player/esm/lottie_html.min.js

Large diffs are not rendered by default.

11,324 changes: 11,324 additions & 0 deletions build/player/esm/lottie_light.min.js

Large diffs are not rendered by default.

12,756 changes: 12,756 additions & 0 deletions build/player/esm/lottie_light_canvas.min.js

Large diffs are not rendered by default.

12,529 changes: 12,529 additions & 0 deletions build/player/esm/lottie_light_html.min.js

Large diffs are not rendered by default.

14,732 changes: 14,732 additions & 0 deletions build/player/esm/lottie_svg.min.js

Large diffs are not rendered by default.

3,857 changes: 437 additions & 3,420 deletions build/player/lottie.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/player/lottie.min.js

Large diffs are not rendered by default.

3,478 changes: 380 additions & 3,098 deletions build/player/lottie_canvas.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/player/lottie_canvas.min.js

Large diffs are not rendered by default.

3,859 changes: 438 additions & 3,421 deletions build/player/lottie_canvas_worker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/player/lottie_canvas_worker.min.js

Large diffs are not rendered by default.

3,544 changes: 401 additions & 3,143 deletions build/player/lottie_html.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/player/lottie_html.min.js

Large diffs are not rendered by default.

2,394 changes: 232 additions & 2,162 deletions build/player/lottie_light.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/player/lottie_light.min.js

Large diffs are not rendered by default.

2,703 changes: 265 additions & 2,438 deletions build/player/lottie_light_canvas.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/player/lottie_light_canvas.min.js

Large diffs are not rendered by default.

2,661 changes: 268 additions & 2,393 deletions build/player/lottie_light_html.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/player/lottie_light_html.min.js

Large diffs are not rendered by default.

3,277 changes: 365 additions & 2,912 deletions build/player/lottie_svg.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/player/lottie_svg.min.js

Large diffs are not rendered by default.

3,859 changes: 438 additions & 3,421 deletions build/player/lottie_worker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/player/lottie_worker.min.js

Large diffs are not rendered by default.

44 changes: 17 additions & 27 deletions player/js/elements/canvasElements/CVImageElement.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
extendPrototype,
} from '../../utils/functionExtensions';
import createTag from '../../utils/helpers/html_elements';
import RenderableElement from '../helpers/RenderableElement';
import BaseElement from '../BaseElement';
import TransformElement from '../helpers/TransformElement';
Expand All @@ -21,34 +20,25 @@ extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement,
CVImageElement.prototype.initElement = SVGShapeElement.prototype.initElement;
CVImageElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame;

CVImageElement.prototype.createContent = function () {
if (this.img.width && (this.assetData.w !== this.img.width || this.assetData.h !== this.img.height)) {
var canvas = createTag('canvas');
canvas.width = this.assetData.w;
canvas.height = this.assetData.h;
var ctx = canvas.getContext('2d');

var imgW = this.img.width;
var imgH = this.img.height;
var imgRel = imgW / imgH;
var canvasRel = this.assetData.w / this.assetData.h;
var widthCrop;
var heightCrop;
var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio;
if ((imgRel > canvasRel && par === 'xMidYMid slice') || (imgRel < canvasRel && par !== 'xMidYMid slice')) {
heightCrop = imgH;
widthCrop = heightCrop * canvasRel;
} else {
widthCrop = imgW;
heightCrop = widthCrop / canvasRel;
}
ctx.drawImage(this.img, (imgW - widthCrop) / 2, (imgH - heightCrop) / 2, widthCrop, heightCrop, 0, 0, this.assetData.w, this.assetData.h);
this.img = canvas;
CVImageElement.prototype.renderInnerContent = function () {
var imgW = this.img.width;
var imgH = this.img.height;

var imgRel = imgW / imgH;
var canvasRel = this.assetData.w / this.assetData.h;
var widthCrop;
var heightCrop;
var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio;

if ((imgRel > canvasRel && par === 'xMidYMid slice') || (imgRel < canvasRel && par !== 'xMidYMid slice')) {
heightCrop = imgH;
widthCrop = heightCrop * canvasRel;
} else {
widthCrop = imgW;
heightCrop = widthCrop / canvasRel;
}
};

CVImageElement.prototype.renderInnerContent = function () {
this.canvasContext.drawImage(this.img, 0, 0);
this.canvasContext.drawImage(this.img, (imgW - widthCrop) / 2, (imgH - heightCrop) / 2, widthCrop, heightCrop, 0, 0, this.assetData.w, this.assetData.h);
};

CVImageElement.prototype.destroy = function () {
Expand Down