diff options
author | 2024-10-17 14:56:25 +0000 | |
---|---|---|
committer | 2024-11-09 05:09:56 +0000 | |
commit | e84cc9ea26177de58e2ae65a448c9b6882769d52 (patch) | |
tree | 15bc8ac7fe2273d426f9a4ba634060b7b0e4ec64 | |
parent | 06af5c8f7f73bc3c5d5907e6d6cb5136f487c9f3 (diff) |
Correctly render ISO gainmapped images
* Apply the gainmap in reverse when using an HDR base image
* Support alternative primaries
* Nudge the guards that optimize away applying the gainmap shader
Bug: 349357636
Flag: com.android.graphics.hwui.flags.iso_gainmap_apis
Test: GainmapTests
Change-Id: I230a765feddb306330e643e6ead8e62719f49ee5
-rw-r--r-- | libs/hwui/SkiaCanvas.cpp | 19 | ||||
-rw-r--r-- | libs/hwui/effects/GainmapRenderer.cpp | 15 |
2 files changed, 19 insertions, 15 deletions
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index 7c150862a422..7f5ca44f7ceb 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -622,18 +622,13 @@ bool SkiaCanvas::useGainmapShader(Bitmap& bitmap) { auto colorSpace = info.colorSpace(); // If we don't have a colorspace, we can't apply a gainmap if (!colorSpace) return false; - skcms_TransferFunction tfn; - colorSpace->transferFn(&tfn); - - auto transferType = skcms_TransferFunction_getType(&tfn); - switch (transferType) { - case skcms_TFType_HLGish: - case skcms_TFType_HLGinvish: - case skcms_TFType_PQish: - return true; - case skcms_TFType_Invalid: - case skcms_TFType_sRGBish: - return false; + + const float targetRatio = uirenderer::getTargetHdrSdrRatio(colorSpace); + + if (bitmap.gainmap()->info.fBaseImageType == SkGainmapInfo::BaseImageType::kHDR) { + return targetRatio < bitmap.gainmap()->info.fDisplayRatioHdr; + } else { + return targetRatio > bitmap.gainmap()->info.fDisplayRatioSdr; } } diff --git a/libs/hwui/effects/GainmapRenderer.cpp b/libs/hwui/effects/GainmapRenderer.cpp index eac03609d72f..18b77bc51aca 100644 --- a/libs/hwui/effects/GainmapRenderer.cpp +++ b/libs/hwui/effects/GainmapRenderer.cpp @@ -73,7 +73,9 @@ void DrawGainmapBitmap(SkCanvas* c, const sk_sp<const SkImage>& image, const SkR #ifdef __ANDROID__ auto destColorspace = c->imageInfo().refColorSpace(); float targetSdrHdrRatio = getTargetHdrSdrRatio(destColorspace.get()); - if (targetSdrHdrRatio > 1.f && gainmapImage) { + const bool baseImageHdr = gainmapInfo.fBaseImageType == SkGainmapInfo::BaseImageType::kHDR; + if (gainmapImage && ((baseImageHdr && targetSdrHdrRatio < gainmapInfo.fDisplayRatioHdr) || + (!baseImageHdr && targetSdrHdrRatio > gainmapInfo.fDisplayRatioSdr))) { SkPaint gainmapPaint = *paint; float sX = gainmapImage->width() / (float)image->width(); float sY = gainmapImage->height() / (float)image->height(); @@ -183,7 +185,10 @@ private: baseImage->colorSpace() ? baseImage->refColorSpace() : SkColorSpace::MakeSRGB(); // Determine the color space in which the gainmap math is to be applied. - sk_sp<SkColorSpace> gainmapMathColorSpace = baseColorSpace->makeLinearGamma(); + sk_sp<SkColorSpace> gainmapMathColorSpace = + mGainmapInfo.fGainmapMathColorSpace + ? mGainmapInfo.fGainmapMathColorSpace->makeLinearGamma() + : baseColorSpace->makeLinearGamma(); // Create a color filter to transform from the base image's color space to the color space // in which the gainmap is to be applied. @@ -266,6 +271,10 @@ private: W = 1.f; } } + + if (mGainmapInfo.fBaseImageType == SkGainmapInfo::BaseImageType::kHDR) { + W -= 1.f; + } mBuilder.uniform("W") = W; uniforms = mBuilder.uniforms(); } @@ -317,4 +326,4 @@ sk_sp<SkShader> MakeGainmapShader(const sk_sp<const SkImage>& image, #endif // __ANDROID__ -} // namespace android::uirenderer
\ No newline at end of file +} // namespace android::uirenderer |