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

Unified Diff: ui/file_manager/file_manager/foreground/js/metadata/image_orientation.js

Issue 2691933007: Rotate an image bitmap in ImageLoader extension when loading detached. (Closed)
Patch Set: Reuse 'orientation' field to make different transformation formats exclusive. Created 3 years, 10 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/metadata/image_orientation.js
diff --git a/ui/file_manager/file_manager/foreground/js/metadata/image_orientation.js b/ui/file_manager/file_manager/foreground/js/metadata/image_orientation.js
index cc3508a1d597f327c8fa78d6370b5de46671de7e..bab051877dab2d525df93f5befbf0a5a2f811715 100644
--- a/ui/file_manager/file_manager/foreground/js/metadata/image_orientation.js
+++ b/ui/file_manager/file_manager/foreground/js/metadata/image_orientation.js
@@ -73,14 +73,25 @@ ImageOrientation.fromExifOrientation = function(orientation) {
* @return {!ImageOrientation}
*/
ImageOrientation.fromDriveOrientation = function(rotation90) {
+ return ImageOrientation.fromClockwiseRotation(rotation90);
+};
+
+/**
+ * @param {number} rotation90 Clockwise degrees / 90.
+ * @return {!ImageOrientation}
+ */
+ImageOrientation.fromClockwiseRotation = function(rotation90) {
switch (~~(rotation90 % 4)) {
case 0:
return new ImageOrientation(1, 0, 0, 1);
case 1:
+ case -3:
return new ImageOrientation(0, -1, 1, 0);
case 2:
+ case -2:
return new ImageOrientation(-1, 0, 0, -1);
case 3:
+ case -1:
return new ImageOrientation(0, 1, -1, 0);
default:
console.error('Invalid orientation number.');
@@ -89,6 +100,27 @@ ImageOrientation.fromDriveOrientation = function(rotation90) {
};
/**
+ * Builds a transformation matrix from the image transform parameters.
+ * @param {{scaleX: number, scaleY: number, rotate90: number}} transform
+ * rotate90: counterclockwise degrees / 90.
yamaguchi 2017/02/16 14:01:18 rotate() in CSS transform property is clockwise. h
+ * @return {!ImageOrientation}
+ */
+ImageOrientation.fromRotationAndScale = function(transform) {
+ var scaleX = transform.scaleX;
+ var scaleY = transform.scaleY;
+ var rotate90 = transform.rotate90;
+
+ var orientation = ImageOrientation.fromClockwiseRotation(-rotate90);
+
+ // Flip X and Y.
+ return new ImageOrientation(
+ orientation.a * scaleX,
+ orientation.b * scaleY,
yamaguchi 2017/02/16 14:01:18 This was wrong. https://www.w3.org/TR/2dcontext/#t
yamaguchi 2017/02/16 14:03:21 See my source code comment in the latest Patchset.
+ orientation.c * scaleX,
+ orientation.d * scaleY);
+}
+
+/**
* Obtains the image size after cancelling its orientation.
* @param {number} imageWidth
* @param {number} imageHeight

Powered by Google App Engine
This is Rietveld 408576698