image/src/Orientation.h

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:b45b7837ff7f
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/. */
5
6 #ifndef MOZILLA_IMAGELIB_ORIENTATION_H_
7 #define MOZILLA_IMAGELIB_ORIENTATION_H_
8
9 #include <stdint.h>
10 #include "mozilla/TypedEnum.h"
11
12 namespace mozilla {
13 namespace image {
14
15 MOZ_BEGIN_ENUM_CLASS(Angle, uint8_t)
16 D0,
17 D90,
18 D180,
19 D270
20 MOZ_END_ENUM_CLASS(Angle)
21
22 MOZ_BEGIN_ENUM_CLASS(Flip, uint8_t)
23 Unflipped,
24 Horizontal
25 MOZ_END_ENUM_CLASS(Flip)
26
27 /**
28 * A struct that describes an image's orientation as a rotation optionally
29 * followed by a reflection. This may be used to be indicate an image's inherent
30 * orientation or a desired orientation for the image.
31 */
32 struct Orientation
33 {
34 Orientation(Angle aRotation = Angle::D0, Flip mFlip = Flip::Unflipped)
35 : rotation(aRotation)
36 , flip(mFlip)
37 { }
38
39 bool IsIdentity() const {
40 return (rotation == Angle::D0) && (flip == Flip::Unflipped);
41 }
42
43 bool SwapsWidthAndHeight() const {
44 return (rotation == Angle::D90) || (rotation == Angle::D270);
45 }
46
47 bool operator==(const Orientation& aOther) const {
48 return (rotation == aOther.rotation) && (flip == aOther.flip);
49 }
50
51 bool operator!=(const Orientation& aOther) const {
52 return !(*this == aOther);
53 }
54
55 Angle rotation;
56 Flip flip;
57 };
58
59 }
60 }
61
62 #endif

mercurial