std::tuple<int, SkYUVAPixmapInfo::DataType> SkYUVAPixmapInfo::NumChannelsAndDataType(
SkColorType ct) { // We could allow BGR[A] color types, but then we'd have to decide whether B should be the 0th // or 2nd channel. Our docs currently say channel order is always R=0, G=1, B=2[, A=3]. switch (ct) { case kAlpha_8_SkColorType: case kGray_8_SkColorType: return {1, DataType::kUnorm8 }; case kA16_unorm_SkColorType: return {1, DataType::kUnorm16}; case kA16_float_SkColorType: return {1, DataType::kFloat16};
case kR8G8_unorm_SkColorType: return {2, DataType::kUnorm8 }; case kR16G16_unorm_SkColorType: return {2, DataType::kUnorm16 }; case kR16G16_float_SkColorType: return {2, DataType::kFloat16 };
case kRGB_888x_SkColorType: return {3, DataType::kUnorm8 }; case kRGB_101010x_SkColorType: return {3, DataType::kUnorm10_Unorm2 }; case kRGB_F16F16F16x_SkColorType: return {3, DataType::kFloat16 };
case kRGBA_8888_SkColorType: return {4, DataType::kUnorm8 }; case kR16G16B16A16_unorm_SkColorType: return {4, DataType::kUnorm16 }; case kRGBA_F16_SkColorType: return {4, DataType::kFloat16 }; case kRGBA_F16Norm_SkColorType: return {4, DataType::kFloat16 }; case kRGBA_1010102_SkColorType: return {4, DataType::kUnorm10_Unorm2 };
default: return {0, DataType::kUnorm8 };
}
}
SkYUVAPixmapInfo::SkYUVAPixmapInfo(const SkYUVAInfo& yuvaInfo, const SkColorType colorTypes[kMaxPlanes], const size_t rowBytes[kMaxPlanes])
: fYUVAInfo(yuvaInfo) { if (!yuvaInfo.isValid()) {
*this = {};
SkASSERT(!this->isValid()); return;
}
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 (size_t i = 0; i < static_cast<size_t>(n); ++i) {
fRowBytes[i] = rowBytes[i]; // Use kUnpremul so that we never multiply alpha when copying data in.
fPlaneInfos[i] = SkImageInfo::Make(planeDimensions[i],
colorTypes[i],
kUnpremul_SkAlphaType); int numRequiredChannels = yuvaInfo.numChannelsInPlane(i);
SkASSERT(numRequiredChannels > 0); auto [numColorTypeChannels, colorTypeDataType] = NumChannelsAndDataType(colorTypes[i]);
ok &= i == 0 || colorTypeDataType == fDataType;
ok &= numColorTypeChannels >= numRequiredChannels;
ok &= fPlaneInfos[i].validRowBytes(fRowBytes[i]);
fDataType = colorTypeDataType;
} if (!ok) {
*this = {};
SkASSERT(!this->isValid());
} else {
SkASSERT(this->isValid());
}
}
SkYUVAPixmapInfo::SkYUVAPixmapInfo(const SkYUVAInfo& yuvaInfo,
DataType dataType, const size_t rowBytes[kMaxPlanes]) {
SkColorType colorTypes[kMaxPlanes] = {}; int numPlanes = yuvaInfo.numPlanes(); for (int i = 0; i < numPlanes; ++i) { int numChannels = yuvaInfo.numChannelsInPlane(i);
colorTypes[i] = DefaultColorTypeForDataType(dataType, numChannels);
}
*this = SkYUVAPixmapInfo(yuvaInfo, colorTypes, rowBytes);
}
SkColorType SkYUVAPixmaps::RecommendedRGBAColorType(DataType dataType) { switch (dataType) { case DataType::kUnorm8: return kRGBA_8888_SkColorType; // F16 has better GPU support than 16 bit unorm. Often "16" bit unorm values are actually // lower precision. case DataType::kUnorm16: return kRGBA_F16_SkColorType; case DataType::kFloat16: return kRGBA_F16_SkColorType; case DataType::kUnorm10_Unorm2: return kRGBA_1010102_SkColorType;
}
SkUNREACHABLE;
}
SkYUVAPixmaps SkYUVAPixmaps::MakeCopy(const SkYUVAPixmaps& src) { if (!src.isValid()) { return {};
}
SkYUVAPixmaps result = Allocate(src.pixmapsInfo()); int n = result.numPlanes(); for (int i = 0; i < n; ++i) { // We use SkRectMemCpy rather than readPixels to ensure that we don't do any alpha type // conversion. const SkPixmap& s = src.plane(i); const SkPixmap& d = result.plane(i);
SkRectMemcpy(d.writable_addr(),
d.rowBytes(),
s.addr(),
s.rowBytes(),
s.info().minRowBytes(),
s.height());
} return result;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.