Leon Scroggins III | b6ab10f | 2017-10-18 14:42:43 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkEncodedOrigin_DEFINED |
| 9 | #define SkEncodedOrigin_DEFINED |
Brian Osman | c337a63 | 2018-11-30 10:39:32 -0500 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkMatrix.h" |
Brian Osman | c337a63 | 2018-11-30 10:39:32 -0500 | [diff] [blame] | 12 | |
Leon Scroggins III | b6ab10f | 2017-10-18 14:42:43 -0400 | [diff] [blame] | 13 | // These values match the orientation www.exif.org/Exif2-2.PDF. |
| 14 | enum SkEncodedOrigin { |
| 15 | kTopLeft_SkEncodedOrigin = 1, // Default |
| 16 | kTopRight_SkEncodedOrigin = 2, // Reflected across y-axis |
| 17 | kBottomRight_SkEncodedOrigin = 3, // Rotated 180 |
| 18 | kBottomLeft_SkEncodedOrigin = 4, // Reflected across x-axis |
| 19 | kLeftTop_SkEncodedOrigin = 5, // Reflected across x-axis, Rotated 90 CCW |
| 20 | kRightTop_SkEncodedOrigin = 6, // Rotated 90 CW |
| 21 | kRightBottom_SkEncodedOrigin = 7, // Reflected across x-axis, Rotated 90 CW |
| 22 | kLeftBottom_SkEncodedOrigin = 8, // Rotated 90 CCW |
| 23 | kDefault_SkEncodedOrigin = kTopLeft_SkEncodedOrigin, |
| 24 | kLast_SkEncodedOrigin = kLeftBottom_SkEncodedOrigin, |
| 25 | }; |
Brian Osman | c337a63 | 2018-11-30 10:39:32 -0500 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Given an encoded origin and the width and height of the source data, returns a matrix |
Brian Salomon | 87d42e5 | 2020-08-24 09:18:16 -0400 | [diff] [blame] | 29 | * that transforms the source rectangle with upper left corner at [0, 0] and origin to a correctly |
| 30 | * oriented destination rectangle of [0, 0, w, h]. |
Brian Osman | c337a63 | 2018-11-30 10:39:32 -0500 | [diff] [blame] | 31 | */ |
| 32 | static inline SkMatrix SkEncodedOriginToMatrix(SkEncodedOrigin origin, int w, int h) { |
| 33 | switch (origin) { |
| 34 | case kTopLeft_SkEncodedOrigin: return SkMatrix::I(); |
| 35 | case kTopRight_SkEncodedOrigin: return SkMatrix::MakeAll(-1, 0, w, 0, 1, 0, 0, 0, 1); |
| 36 | case kBottomRight_SkEncodedOrigin: return SkMatrix::MakeAll(-1, 0, w, 0, -1, h, 0, 0, 1); |
| 37 | case kBottomLeft_SkEncodedOrigin: return SkMatrix::MakeAll( 1, 0, 0, 0, -1, h, 0, 0, 1); |
| 38 | case kLeftTop_SkEncodedOrigin: return SkMatrix::MakeAll( 0, 1, 0, 1, 0, 0, 0, 0, 1); |
Brian Salomon | 87d42e5 | 2020-08-24 09:18:16 -0400 | [diff] [blame] | 39 | case kRightTop_SkEncodedOrigin: return SkMatrix::MakeAll( 0, -1, w, 1, 0, 0, 0, 0, 1); |
| 40 | case kRightBottom_SkEncodedOrigin: return SkMatrix::MakeAll( 0, -1, w, -1, 0, h, 0, 0, 1); |
| 41 | case kLeftBottom_SkEncodedOrigin: return SkMatrix::MakeAll( 0, 1, 0, -1, 0, h, 0, 0, 1); |
Brian Osman | c337a63 | 2018-11-30 10:39:32 -0500 | [diff] [blame] | 42 | } |
| 43 | SK_ABORT("Unexpected origin"); |
Brian Osman | c337a63 | 2018-11-30 10:39:32 -0500 | [diff] [blame] | 44 | } |
| 45 | |
Leon Scroggins III | e427160 | 2020-12-15 15:52:39 -0500 | [diff] [blame] | 46 | /** |
| 47 | * Return true if the encoded origin includes a 90 degree rotation, in which case the width |
| 48 | * and height of the source data are swapped relative to a correctly oriented destination. |
| 49 | */ |
| 50 | static inline bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin) { |
| 51 | return origin >= kLeftTop_SkEncodedOrigin; |
| 52 | } |
Brian Osman | c337a63 | 2018-11-30 10:39:32 -0500 | [diff] [blame] | 53 | |
Leon Scroggins III | b6ab10f | 2017-10-18 14:42:43 -0400 | [diff] [blame] | 54 | #endif // SkEncodedOrigin_DEFINED |