| 1 | /* |
|---|---|
| 2 | * Copyright 2018 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 | |
| 8 | #include "include/core/SkYUVASizeInfo.h" |
| 9 | #include "include/private/SkTemplates.h" |
| 10 | #include "src/core/SkSafeMath.h" |
| 11 | |
| 12 | size_t SkYUVASizeInfo::computeTotalBytes() const { |
| 13 | SkSafeMath safe; |
| 14 | size_t totalBytes = 0; |
| 15 | |
| 16 | for (int i = 0; i < kMaxCount; ++i) { |
| 17 | SkASSERT((!fSizes[i].isEmpty() && fWidthBytes[i]) || |
| 18 | (fSizes[i].isEmpty() && !fWidthBytes[i])); |
| 19 | totalBytes = safe.add(totalBytes, safe.mul(fWidthBytes[i], fSizes[i].height())); |
| 20 | } |
| 21 | |
| 22 | return safe.ok() ? totalBytes : SIZE_MAX; |
| 23 | } |
| 24 | |
| 25 | void SkYUVASizeInfo::computePlanes(void* base, void* planes[SkYUVASizeInfo::kMaxCount]) const { |
| 26 | planes[0] = base; |
| 27 | int i = 1; |
| 28 | for (; i < SkYUVASizeInfo::kMaxCount; ++i) { |
| 29 | if (fSizes[i].isEmpty()) { |
| 30 | break; |
| 31 | } |
| 32 | planes[i] = SkTAddOffset<void>(planes[i - 1], fWidthBytes[i - 1] * fSizes[i - 1].height()); |
| 33 | } |
| 34 | for (; i < SkYUVASizeInfo::kMaxCount; ++i) { |
| 35 | planes[i] = nullptr; |
| 36 | } |
| 37 | } |
| 38 |