SkEncodedOrigin.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2017 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkEncodedOrigin_DEFINED
  8. #define SkEncodedOrigin_DEFINED
  9. #include "include/core/SkMatrix.h"
  10. // These values match the orientation www.exif.org/Exif2-2.PDF.
  11. enum SkEncodedOrigin {
  12. kTopLeft_SkEncodedOrigin = 1, // Default
  13. kTopRight_SkEncodedOrigin = 2, // Reflected across y-axis
  14. kBottomRight_SkEncodedOrigin = 3, // Rotated 180
  15. kBottomLeft_SkEncodedOrigin = 4, // Reflected across x-axis
  16. kLeftTop_SkEncodedOrigin = 5, // Reflected across x-axis, Rotated 90 CCW
  17. kRightTop_SkEncodedOrigin = 6, // Rotated 90 CW
  18. kRightBottom_SkEncodedOrigin = 7, // Reflected across x-axis, Rotated 90 CW
  19. kLeftBottom_SkEncodedOrigin = 8, // Rotated 90 CCW
  20. kDefault_SkEncodedOrigin = kTopLeft_SkEncodedOrigin,
  21. kLast_SkEncodedOrigin = kLeftBottom_SkEncodedOrigin,
  22. };
  23. /**
  24. * Given an encoded origin and the width and height of the source data, returns a matrix
  25. * that transforms the source rectangle [0, 0, w, h] to a correctly oriented destination
  26. * rectangle, with the upper left corner still at [0, 0].
  27. */
  28. static inline SkMatrix SkEncodedOriginToMatrix(SkEncodedOrigin origin, int w, int h) {
  29. switch (origin) {
  30. case kTopLeft_SkEncodedOrigin: return SkMatrix::I();
  31. case kTopRight_SkEncodedOrigin: return SkMatrix::MakeAll(-1, 0, w, 0, 1, 0, 0, 0, 1);
  32. case kBottomRight_SkEncodedOrigin: return SkMatrix::MakeAll(-1, 0, w, 0, -1, h, 0, 0, 1);
  33. case kBottomLeft_SkEncodedOrigin: return SkMatrix::MakeAll( 1, 0, 0, 0, -1, h, 0, 0, 1);
  34. case kLeftTop_SkEncodedOrigin: return SkMatrix::MakeAll( 0, 1, 0, 1, 0, 0, 0, 0, 1);
  35. case kRightTop_SkEncodedOrigin: return SkMatrix::MakeAll( 0, -1, h, 1, 0, 0, 0, 0, 1);
  36. case kRightBottom_SkEncodedOrigin: return SkMatrix::MakeAll( 0, -1, h, -1, 0, w, 0, 0, 1);
  37. case kLeftBottom_SkEncodedOrigin: return SkMatrix::MakeAll( 0, 1, 0, -1, 0, w, 0, 0, 1);
  38. }
  39. SK_ABORT("Unexpected origin");
  40. return SkMatrix::I();
  41. }
  42. #endif // SkEncodedOrigin_DEFINED