| | | 1 | | namespace Anichron.Core.Domain; |
| | | 2 | | |
| | | 3 | | public static class ExifOrientation |
| | | 4 | | { |
| | | 5 | | public const int Upright = 1; |
| | | 6 | | public const int RotateHalfTurn = 3; |
| | | 7 | | public const int RotateClockwise = 6; |
| | | 8 | | public const int RotateAnticlockwise = 8; |
| | | 9 | | public const int Max = 8; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Whether the orientation includes a quarter turn (EXIF 5-8), so the upright image's width is the stored height. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="orientation">The EXIF orientation value, 1-8.</param> |
| | 35 | 15 | | public static bool SwapsAxes(int orientation) => orientation is >= 5 and <= Max; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// The orientation that shows stored pixels as a display rotation does (a HEIF <c>irot</c>, a QuickTime |
| | | 19 | | /// track's rotation); a rotation that is not a multiple of 90 degrees is upright. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="degrees">The display rotation, anticlockwise.</param> |
| | | 22 | | public static int OfDisplayRotation(double degrees) |
| | 35 | 23 | | => ((((int)Math.Round(degrees) % 360) + 360) % 360) switch |
| | 35 | 24 | | { |
| | 5 | 25 | | 90 => RotateAnticlockwise, |
| | 5 | 26 | | 180 => RotateHalfTurn, |
| | 8 | 27 | | 270 => RotateClockwise, |
| | 17 | 28 | | _ => Upright, |
| | 35 | 29 | | }; |
| | | 30 | | } |