Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6a3088cb authored by Sally Qi's avatar Sally Qi
Browse files

Add HLG transfer function to proper dataspace

- fix the issue of color washout in the textureview
- scale down hlg to [0, 1] in skia
- app side should enable wideColorGamut for it

Bug: 224841108
Test: test HLG video on Instagram
Change-Id: If9da8495139a0579667c64dcd8a61e9554b7da58
parent 2f58e1c3
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -165,6 +165,14 @@ android_dataspace ColorSpaceToADataSpace(SkColorSpace* colorSpace, SkColorType c
        if (SkColorSpace::Equals(colorSpace, rec2020PQ.get())) {
            return HAL_DATASPACE_BT2020_PQ;
        }
        // HLG
        const auto hlgFn = GetHLGScaleTransferFunction();
        if (hlgFn.has_value()) {
            auto rec2020HLG = SkColorSpace::MakeRGB(hlgFn.value(), SkNamedGamut::kRec2020);
            if (SkColorSpace::Equals(colorSpace, rec2020HLG.get())) {
                return static_cast<android_dataspace>(HAL_DATASPACE_BT2020_HLG);
            }
        }
        LOG_ALWAYS_FATAL("Only select non-numerical transfer functions are supported");
    }

@@ -247,6 +255,14 @@ sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace) {
            return nullptr;
    }

    // HLG
    if ((dataspace & HAL_DATASPACE_TRANSFER_MASK) == HAL_DATASPACE_TRANSFER_HLG) {
        const auto hlgFn = GetHLGScaleTransferFunction();
        if (hlgFn.has_value()) {
            return SkColorSpace::MakeRGB(hlgFn.value(), gamut);
        }
    }

    switch (dataspace & HAL_DATASPACE_TRANSFER_MASK) {
        case HAL_DATASPACE_TRANSFER_LINEAR:
            return SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, gamut);
@@ -264,7 +280,6 @@ sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace) {
            return SkColorSpace::MakeRGB(SkNamedTransferFn::kRec2020, gamut);
        case HAL_DATASPACE_TRANSFER_UNSPECIFIED:
            return nullptr;
        case HAL_DATASPACE_TRANSFER_HLG:
        default:
            ALOGV("Unsupported Gamma: %d", dataspace);
            return nullptr;
@@ -381,5 +396,14 @@ skcms_TransferFunction GetPQSkTransferFunction(float sdr_white_level) {
    return fn;
}

// Skia skcms' default HLG maps encoded [0, 1] to linear [1, 12] in order to follow ARIB
// but LinearEffect expects a decoded [0, 1] range instead to follow Rec 2100.
std::optional<skcms_TransferFunction> GetHLGScaleTransferFunction() {
    std::optional<skcms_TransferFunction> hlgFn = {};
    skcms_TransferFunction_makeScaledHLGish(&hlgFn.value(), 1.f / 12.f, 2.f, 2.f, 1.f / 0.17883277f,
                                            0.28466892f, 0.55991073f);
    return hlgFn;
}

}  // namespace uirenderer
}  // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@
#include <math.h>
#include <system/graphics.h>

#include <optional>

struct ANativeWindow_Buffer;
struct AHardwareBuffer_Desc;

@@ -127,6 +129,7 @@ struct Lab {
Lab sRGBToLab(SkColor color);
SkColor LabToSRGB(const Lab& lab, SkAlpha alpha);
skcms_TransferFunction GetPQSkTransferFunction(float sdr_white_level = 0.f);
std::optional<skcms_TransferFunction> GetHLGScaleTransferFunction();

} /* namespace uirenderer */
} /* namespace android */