Simpler SkYUVAPixmapInfo construction

Bug: skia:10632
Change-Id: I40636d004f8458b3eb578caeeb9e77594ce8bc54
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313908
Auto-Submit: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Brian Salomon 2020-08-28 16:10:01 -04:00 committed by Skia Commit-Bot
parent c23eeb8c78
commit ffd61ca012
2 changed files with 22 additions and 0 deletions

View File

@ -35,10 +35,17 @@ public:
* This will be invalid if the colorTypes aren't compatible with the SkYUVAInfo or if a
* rowBytes entry is not valid for the plane dimensions and color type. Color type and
* row byte values beyond the number of planes in SkYUVAInfo are ignored.
*
* If rowBytes is nullptr then bpp*width is assumed for each plane.
*/
SkYUVAPixmapInfo(const SkYUVAInfo&,
const SkColorType[kMaxPlanes],
const size_t rowBytes[kMaxPlanes]);
/**
* Like above but uses the same color type for all planes.
*/
SkYUVAPixmapInfo(const SkYUVAInfo&, SkColorType, const size_t rowBytes[kMaxPlanes]);
SkYUVAPixmapInfo(const SkYUVAPixmapInfo&) = default;
SkYUVAPixmapInfo& operator=(const SkYUVAPixmapInfo&) = default;

View File

@ -46,6 +46,13 @@ SkYUVAPixmapInfo::SkYUVAPixmapInfo(const SkYUVAInfo& yuvaInfo,
}
SkISize planeDimensions[4];
int n = yuvaInfo.planeDimensions(planeDimensions);
size_t tempRowBytes[kMaxPlanes];
if (!rowBytes) {
for (int i = 0; i < n; ++i) {
tempRowBytes[i] = SkColorTypeBytesPerPixel(colorTypes[i]) * planeDimensions[i].width();
}
rowBytes = tempRowBytes;
}
bool ok = true;
for (int i = 0; i < n; ++i) {
fRowBytes[i] = rowBytes[i];
@ -80,6 +87,14 @@ SkYUVAPixmapInfo::SkYUVAPixmapInfo(const SkYUVAInfo& yuvaInfo,
}
}
SkYUVAPixmapInfo::SkYUVAPixmapInfo(const SkYUVAInfo& yuvaInfo,
const SkColorType colorType,
const size_t rowBytes[kMaxPlanes]) {
SkColorType colorTypes[kMaxPlanes];
std::fill_n(colorTypes, kMaxPlanes, colorType);
*this = SkYUVAPixmapInfo(yuvaInfo, colorTypes, rowBytes);
}
size_t SkYUVAPixmapInfo::computeTotalBytes(size_t planeSizes[kMaxPlanes]) const {
if (!this->isValid()) {
if (planeSizes) {