Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Unified Diff: ui/file_manager/file_manager/foreground/js/thumbnail_loader.js

Issue 2640743002: Revert of Apply image transformation for thumbnails loaded by loadDetachedImage. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/file_manager/foreground/js/thumbnail_loader.js
diff --git a/ui/file_manager/file_manager/foreground/js/thumbnail_loader.js b/ui/file_manager/file_manager/foreground/js/thumbnail_loader.js
index 65d012ff2b42fc2a541101782b7be95f58bd8dfc..a5a090a71b89daff9b4a816d3aae8733334cc898 100644
--- a/ui/file_manager/file_manager/foreground/js/thumbnail_loader.js
+++ b/ui/file_manager/file_manager/foreground/js/thumbnail_loader.js
@@ -324,46 +324,6 @@
};
/**
- * Renders an Image to canvas applying an image transformation.
- * @param {Image} image Original image. Can be an unattached one to an elment.
- * @param {number} width width of the original image
- * @param {number} height height of the original image
- * @param {{scaleX:number, scaleY:number, rotate90: number}} transform
- * Transform.
- * @param {!Object} canvas
- */
-ThumbnailLoader.prototype.renderImageToCanvasWithTransform_ = function(
- image, width, height, transform, canvas) {
- var scaleX = transform.scaleX;
- var scaleY = transform.scaleY;
- var rotate90 = transform.rotate90;
-
- assert(scaleX === 1 || scaleX === -1);
- assert(scaleY === 1 || scaleY === -1);
- assert(rotate90 === 0 || rotate90 === 1);
-
- var context = canvas.getContext('2d');
-
- canvas.width = rotate90 === 1 ? height : width;
- canvas.height = rotate90 === 1 ? width : height;
-
- // Scale transformation should be applied before rotate transformation.
- // i.e. When matrices for scale and rotate are A and B, transformation matrix
- // should be BA.
-
- // Rotate 90 degree at center.
- if (rotate90 === 1) {
- context.translate(height, 0);
- context.rotate(Math.PI / 2);
- }
-
- // Flip X and Y.
- context.translate(scaleX === -1 ? width : 0, scaleY === -1 ? height : 0);
- context.scale(scaleX, scaleY);
- context.drawImage(image, 0, 0);
-};
-
-/**
* Applies transform to data url.
*
* @param {{scaleX:number, scaleY:number, rotate90: number}} transform
@@ -378,6 +338,13 @@
ThumbnailLoader.prototype.applyTransformToDataUrl_ = function(
transform, dataUrl, width, height) {
var image = new Image();
+ var scaleX = this.transform_.scaleX;
+ var scaleY = this.transform_.scaleY;
+ var rotate90 = this.transform_.rotate90;
+
+ assert(scaleX === 1 || scaleX === -1);
+ assert(scaleY === 1 || scaleY === -1);
+ assert(rotate90 === 0 || rotate90 === 1);
return new Promise(function(resolve, reject) {
// Decode image for transformation.
@@ -385,9 +352,27 @@
image.onerror = reject;
image.src = dataUrl;
}).then(function() {
+ // Apply transform. Scale transformation should be applied before rotate
+ // transformation. i.e. When matrices for scale and rotate are A and B,
+ // transformation matrix should be BA.
var canvas = document.createElement('canvas');
- this.renderImageToCanvasWithTransform_(
- image, width, height, this.transform_, canvas);
+ var context = canvas.getContext('2d');
+
+ canvas.width = rotate90 === 1 ? height : width;
+ canvas.height = rotate90 === 1 ? width : height;
+
+ // Rotate 90 degree at center.
+ if (rotate90 === 1) {
+ context.translate(height, 0);
+ context.rotate(Math.PI / 2);
+ }
+
+ // Flip X and Y.
+ context.translate(scaleX === -1 ? width : 0, scaleY === -1 ? height : 0);
+ context.scale(scaleX, scaleY);
+
+ context.drawImage(image, 0, 0);
+
return {
data: canvas.toDataURL('image/png'),
width: canvas.width,
@@ -488,8 +473,6 @@
this.canvas_ = document.createElement('canvas');
// Copy the image to a canvas if the canvas is outdated.
- // At this point, image transformation is not applied because we attach style
- // attribute to an img element in attachImage() instead.
if (!this.canvasUpToDate_) {
this.canvas_.width = this.image_.width;
this.canvas_.height = this.image_.height;
@@ -538,22 +521,14 @@
/**
* Gets the loaded image.
+ * TODO(mtomasz): Apply transformations.
*
* @return {Image|HTMLCanvasElement} Either image or a canvas object.
*/
ThumbnailLoader.prototype.getImage = function() {
this.renderMedia_();
- if (this.loaderType_ === ThumbnailLoader.LoaderType.IMAGE)
- // TODO(yamaguchi): Fix image orientation in case of detached image loaded
- // in IMAGE mode. Either apply transformation here or return
- // this.transform_ as well.
- return this.image_;
- if (this.transform_) {
- this.renderImageToCanvasWithTransform_(
- this.image_, this.image_.width, this.image_.height,
- this.transform_, this.canvas_);
- }
- return this.canvas_;
+ return this.loaderType_ === ThumbnailLoader.LoaderType.CANVAS ? this.canvas_ :
+ this.image_;
};
/**

Powered by Google App Engine
This is Rietveld 408576698