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
14 enum class Angle
: uint8_t { D0
, D90
, D180
, D270
};
16 enum class Flip
: uint8_t { Unflipped
, Horizontal
};
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.)
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
) {
70 } // namespace mozilla
72 #endif // mozilla_image_Orientation_h