Orientation.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifndef mozilla_image_Orientation_h
  6. #define mozilla_image_Orientation_h
  7. #include <stdint.h>
  8. namespace mozilla {
  9. namespace image {
  10. enum class Angle : uint8_t {
  11. D0,
  12. D90,
  13. D180,
  14. D270
  15. };
  16. enum class Flip : uint8_t {
  17. Unflipped,
  18. Horizontal
  19. };
  20. /**
  21. * A struct that describes an image's orientation as a rotation optionally
  22. * followed by a reflection. This may be used to be indicate an image's inherent
  23. * orientation or a desired orientation for the image.
  24. */
  25. struct Orientation
  26. {
  27. explicit Orientation(Angle aRotation = Angle::D0,
  28. Flip mFlip = Flip::Unflipped)
  29. : rotation(aRotation)
  30. , flip(mFlip)
  31. { }
  32. bool IsIdentity() const {
  33. return (rotation == Angle::D0) && (flip == Flip::Unflipped);
  34. }
  35. bool SwapsWidthAndHeight() const {
  36. return (rotation == Angle::D90) || (rotation == Angle::D270);
  37. }
  38. bool operator==(const Orientation& aOther) const {
  39. return (rotation == aOther.rotation) && (flip == aOther.flip);
  40. }
  41. bool operator!=(const Orientation& aOther) const {
  42. return !(*this == aOther);
  43. }
  44. Angle rotation;
  45. Flip flip;
  46. };
  47. } // namespace image
  48. } // namespace mozilla
  49. #endif // mozilla_image_Orientation_h