Bug 1728955: part 8) Refactor `DisplayErrCode` in Windows' `nsClipboard`. r=masayuki
[gecko.git] / image / Orientation.h
blobc1c739b853c28fd61d5e53f1fc07754096314ff8
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_image_Orientation_h
7 #define mozilla_image_Orientation_h
9 #include <stdint.h>
11 namespace mozilla {
12 namespace image {
14 enum class Angle : uint8_t { D0, D90, D180, D270 };
16 enum class Flip : uint8_t { Unflipped, Horizontal };
18 /**
19 * A struct that describes an image's orientation as a rotation optionally
20 * followed by a reflection. This may be used to be indicate an image's inherent
21 * orientation or a desired orientation for the image.
23 * When flipFirst = true, this indicates that the reflection is applied before
24 * the rotation. (This is used by OrientedImage to represent the inverse of an
25 * underlying image's Orientation.)
27 struct Orientation {
28 explicit Orientation(Angle aRotation = Angle::D0,
29 Flip aFlip = Flip::Unflipped, bool aFlipFirst = false)
30 : rotation(aRotation), flip(aFlip), flipFirst(aFlipFirst) {}
32 Orientation Reversed() const {
33 return Orientation(InvertAngle(rotation), flip, !flipFirst);
36 bool IsIdentity() const {
37 return (rotation == Angle::D0) && (flip == Flip::Unflipped);
40 bool SwapsWidthAndHeight() const {
41 return (rotation == Angle::D90) || (rotation == Angle::D270);
44 bool operator==(const Orientation& aOther) const {
45 return rotation == aOther.rotation && flip == aOther.flip &&
46 flipFirst == aOther.flipFirst;
49 bool operator!=(const Orientation& aOther) const {
50 return !(*this == aOther);
53 static Angle InvertAngle(Angle aAngle) {
54 switch (aAngle) {
55 case Angle::D90:
56 return Angle::D270;
57 case Angle::D270:
58 return Angle::D90;
59 default:
60 return aAngle;
64 Angle rotation;
65 Flip flip;
66 bool flipFirst;
69 } // namespace image
70 } // namespace mozilla
72 #endif // mozilla_image_Orientation_h