SkYUVASizeInfo.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2016 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 SkYUVASizeInfo_DEFINED
  8. #define SkYUVASizeInfo_DEFINED
  9. #include "include/codec/SkEncodedOrigin.h"
  10. #include "include/core/SkImageInfo.h"
  11. #include "include/core/SkSize.h"
  12. struct SK_API SkYUVASizeInfo {
  13. static constexpr auto kMaxCount = 4;
  14. SkISize fSizes[kMaxCount];
  15. /**
  16. * While the widths of the Y, U, V and A planes are not restricted, the
  17. * implementation often requires that the width of the memory allocated
  18. * for each plane be a multiple of 8.
  19. *
  20. * This struct allows us to inform the client how many "widthBytes"
  21. * that we need. Note that we use the new idea of "widthBytes"
  22. * because this idea is distinct from "rowBytes" (used elsewhere in
  23. * Skia). "rowBytes" allow the last row of the allocation to not
  24. * include any extra padding, while, in this case, every single row of
  25. * the allocation must be at least "widthBytes".
  26. */
  27. size_t fWidthBytes[kMaxCount];
  28. /**
  29. * YUVA data often comes from formats like JPEG that support EXIF orientation.
  30. * Code that operates on the raw YUV data often needs to know that orientation.
  31. */
  32. SkEncodedOrigin fOrigin = kDefault_SkEncodedOrigin;
  33. bool operator==(const SkYUVASizeInfo& that) const {
  34. for (int i = 0; i < kMaxCount; ++i) {
  35. SkASSERT((!fSizes[i].isEmpty() && fWidthBytes[i]) ||
  36. (fSizes[i].isEmpty() && !fWidthBytes[i]));
  37. if (fSizes[i] != that.fSizes[i] || fWidthBytes[i] != that.fWidthBytes[i]) {
  38. return false;
  39. }
  40. }
  41. return true;
  42. }
  43. size_t computeTotalBytes() const {
  44. size_t totalBytes = 0;
  45. for (int i = 0; i < kMaxCount; ++i) {
  46. SkASSERT((!fSizes[i].isEmpty() && fWidthBytes[i]) ||
  47. (fSizes[i].isEmpty() && !fWidthBytes[i]));
  48. totalBytes += fWidthBytes[i] * fSizes[i].height();
  49. }
  50. return totalBytes;
  51. }
  52. void computePlanes(void* base, void* planes[kMaxCount]) const;
  53. };
  54. #endif // SkYUVASizeInfo_DEFINED