SkYUVASizeInfo.h 1.8 KB

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