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

fixed image drawing for the both UI #1302

Merged
Merged
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
4 changes: 4 additions & 0 deletions cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,10 @@ export class CanvasViewImpl implements CanvasView, Listener {
ctx.scale(image.renderWidth / image.imageData.width,
image.renderHeight / image.imageData.height);
ctx.putImageData(image.imageData, 0, 0);
// Transformation matrix must not affect the putImageData() method.
// By this reason need to redraw the image to apply scale.
// https://www.w3.org/TR/2dcontext/#dom-context-2d-putimagedata
ctx.drawImage(this.background, 0, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is problem here?
Why putImageData is not enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current path, transformation matrix, shadow attributes, global alpha, the clipping region, and global composition operator must not affect the getImageData() and putImageData() methods.

from: https://www.w3.org/TR/2dcontext/#dom-context-2d-putimagedata

By this reason I have to redraw canvas to apply scale.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fast operation? As far as I remember it was quite slow before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case putImageData takes ~1ms, drawImage < 1ms for fullHD and ~10 ms and <1ms for 4k.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if you left a comment in the code about why we need this line (just to do not forget)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

} else {
ctx.drawImage(image.imageData, 0, 0);
}
Expand Down
8 changes: 6 additions & 2 deletions cvat/apps/engine/static/engine/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ class PlayerModel extends Listener {
if (absolute) {
this._frame.requested.clear();
}
this._frame.requested.add(requestedFrame);

if (!isLoadFrame) {
this._image = null;
this._continueAfterLoad = this.playing;
Expand All @@ -287,6 +285,8 @@ class PlayerModel extends Listener {
return false;
}

this._frame.requested.add(requestedFrame);

try {
const frame = await this._frameProvider.require(requestedFrame,
this._playing, this._step);
Expand Down Expand Up @@ -965,6 +965,10 @@ class PlayerView {
ctx.scale(image.renderWidth / image.imageData.width,
image.renderHeight / image.imageData.height);
ctx.putImageData(image.imageData, 0, 0);
// Transformation matrix must not affect the putImageData() method.
// By this reason need to redraw the image to apply scale.
// https://www.w3.org/TR/2dcontext/#dom-context-2d-putimagedata
ctx.drawImage(this._playerCanvasBackground[0], 0, 0);
} else {
ctx.drawImage(image.imageData, 0, 0);
}
Expand Down