HEIF decode: add support for 10-bit color format

Reworked https://skia-review.googlesource.com/c/skia/+/501159

Bug: b/201083499
Test: android.graphics.cts.AImageDecoderTest
      android.graphics.cts.BitmapFactoryTest
Change-Id: I44fe6b9c36a177e36dac6fe8d58e5feb48381422
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/502208
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Dichen Zhang <dichenzhang@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
This commit is contained in:
Dichen Zhang 2021-11-17 11:32:55 -08:00 committed by SkCQ
parent 7646dffe58
commit 1844e99f53
6 changed files with 30 additions and 4 deletions

View File

@ -758,6 +758,8 @@ protected:
std::unique_ptr<SkStream>,
SkEncodedOrigin = kTopLeft_SkEncodedOrigin);
void setSrcXformFormat(XformFormat pixelFormat);
virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const {
// By default, scaling is not supported.
return this->dimensions();
@ -876,7 +878,7 @@ protected:
private:
const SkEncodedInfo fEncodedInfo;
const XformFormat fSrcXformFormat;
XformFormat fSrcXformFormat;
std::unique_ptr<SkStream> fStream;
bool fNeedsRewind;
const SkEncodedOrigin fOrigin;

View File

@ -133,6 +133,8 @@ SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorTyp
return kRGB_565_SkColorType;
}
break;
case kRGBA_1010102_SkColorType:
return kRGBA_1010102_SkColorType;
case kRGBA_F16_SkColorType:
return kRGBA_F16_SkColorType;
default:
@ -140,6 +142,9 @@ SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorTyp
}
// F16 is the Android default for high precision images.
// TODO: b/217378990, b/217378477
// Check the bit-depth of the input source. For 10-bit color input sources, change
// default to kRGBA_1010102_SkColorType instead of kN32_SkColorType.
return highPrecision ? kRGBA_F16_SkColorType : kN32_SkColorType;
}
@ -156,7 +161,8 @@ sk_sp<SkColorSpace> SkAndroidCodec::computeOutputColorSpace(SkColorType outputCo
case kRGBA_F16_SkColorType:
case kRGB_565_SkColorType:
case kRGBA_8888_SkColorType:
case kBGRA_8888_SkColorType: {
case kBGRA_8888_SkColorType:
case kRGBA_1010102_SkColorType: {
// If |prefColorSpace| is supplied, choose it.
if (prefColorSpace) {
return prefColorSpace;

View File

@ -190,6 +190,10 @@ SkCodec::SkCodec(SkEncodedInfo&& info, XformFormat srcFormat, std::unique_ptr<Sk
SkCodec::~SkCodec() {}
void SkCodec::setSrcXformFormat(XformFormat pixelFormat) {
fSrcXformFormat = pixelFormat;
}
bool SkCodec::queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
SkYUVAPixmapInfo* yuvaPixmapInfo) const {
if (!yuvaPixmapInfo) {

View File

@ -214,20 +214,28 @@ bool SkHeifCodec::conversionSupported(const SkImageInfo& dstInfo, bool srcIsOpaq
switch (dstInfo.colorType()) {
case kRGBA_8888_SkColorType:
this->setSrcXformFormat(skcms_PixelFormat_RGBA_8888);
return fHeifDecoder->setOutputColor(kHeifColorFormat_RGBA_8888);
case kBGRA_8888_SkColorType:
this->setSrcXformFormat(skcms_PixelFormat_RGBA_8888);
return fHeifDecoder->setOutputColor(kHeifColorFormat_BGRA_8888);
case kRGB_565_SkColorType:
this->setSrcXformFormat(skcms_PixelFormat_RGBA_8888);
if (needsColorXform) {
return fHeifDecoder->setOutputColor(kHeifColorFormat_RGBA_8888);
} else {
return fHeifDecoder->setOutputColor(kHeifColorFormat_RGB565);
}
case kRGBA_1010102_SkColorType:
this->setSrcXformFormat(skcms_PixelFormat_RGBA_1010102);
return fHeifDecoder->setOutputColor(kHeifColorFormat_RGBA_1010102);
case kRGBA_F16_SkColorType:
SkASSERT(needsColorXform);
this->setSrcXformFormat(skcms_PixelFormat_RGBA_8888);
return fHeifDecoder->setOutputColor(kHeifColorFormat_RGBA_8888);
default:
@ -426,8 +434,12 @@ void SkHeifCodec::initializeSwizzler(
const SkImageInfo& dstInfo, const Options& options) {
SkImageInfo swizzlerDstInfo = dstInfo;
if (this->colorXform()) {
// The color xform will be expecting RGBA 8888 input.
swizzlerDstInfo = swizzlerDstInfo.makeColorType(kRGBA_8888_SkColorType);
// Aligned with conversionSupported()
if (dstInfo.colorType() == kRGBA_1010102_SkColorType) {
swizzlerDstInfo = swizzlerDstInfo.makeColorType(kRGBA_1010102_SkColorType);
} else {
swizzlerDstInfo = swizzlerDstInfo.makeColorType(kRGBA_8888_SkColorType);
}
}
int srcBPP = 4;

View File

@ -19,6 +19,7 @@ enum HeifColorFormat {
kHeifColorFormat_RGB565,
kHeifColorFormat_RGBA_8888,
kHeifColorFormat_BGRA_8888,
kHeifColorFormat_RGBA_1010102,
};
struct HeifStream {

View File

@ -789,6 +789,7 @@ std::unique_ptr<SkSwizzler> SkSwizzler::MakeSimple(int srcBPP, const SkImageInfo
break;
case 4: // kRGBA_8888_SkColorType
// kBGRA_8888_SkColorType
// kRGBA_1010102_SkColorType
proc = &sample4;
break;
case 6: // 16 bit PNG no alpha