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

Commit 8b4ab814 authored by Alec Mouri's avatar Alec Mouri
Browse files

Only scale SDR luminance by content max luminance for tonemapping

If color conversion is SDR->SDR, then scale luminance only by the
display luminance.

The use-case is for applying a color transform, which was defined to
occcur in linear space. Since uniform generation for tonemapping is (for
now) dataspace-agnostic, this means that scaling by the content
luminance should not be used since a tone-mapping operator may override
the one that is provided by applications.

Bug: 200310159
Test: builds, boots
Test: librenderengine_test
Change-Id: I2cc5860b6df064664c5e462674df20b589eae291
parent 465b2967
Loading
Loading
Loading
Loading
+23 −8
Original line number Diff line number Diff line
@@ -114,7 +114,8 @@ static void generateXYZTransforms(SkString& shader) {
}

// Conversion from relative light to absolute light (maps from [0, 1] to [0, maxNits])
static void generateLuminanceScalesForOOTF(ui::Dataspace inputDataspace, SkString& shader) {
static void generateLuminanceScalesForOOTF(ui::Dataspace inputDataspace,
                                           ui::Dataspace outputDataspace, SkString& shader) {
    switch (inputDataspace & HAL_DATASPACE_TRANSFER_MASK) {
        case HAL_DATASPACE_TRANSFER_ST2084:
            shader.append(R"(
@@ -131,12 +132,26 @@ static void generateLuminanceScalesForOOTF(ui::Dataspace inputDataspace, SkStrin
                )");
            break;
        default:
            switch (outputDataspace & HAL_DATASPACE_TRANSFER_MASK) {
                case HAL_DATASPACE_TRANSFER_ST2084:
                case HAL_DATASPACE_TRANSFER_HLG:
                    // SDR -> HDR tonemap
                    shader.append(R"(
                            float3 ScaleLuminance(float3 xyz) {
                                return xyz * in_libtonemap_inputMaxLuminance;
                            }
                        )");
                    break;
                default:
                    // Input and output are both SDR, so no tone-mapping is expected so
                    // no-op the luminance normalization.
                    shader.append(R"(
                                float3 ScaleLuminance(float3 xyz) {
                                    return xyz * in_libtonemap_displayMaxLuminance;
                                }
                            )");
                    break;
            }
    }
}

@@ -174,7 +189,7 @@ static void generateOOTF(ui::Dataspace inputDataspace, ui::Dataspace outputDatas
                                                          toAidlDataspace(outputDataspace))
                          .c_str());

    generateLuminanceScalesForOOTF(inputDataspace, shader);
    generateLuminanceScalesForOOTF(inputDataspace, outputDataspace, shader);
    generateLuminanceNormalizationForOOTF(outputDataspace, shader);

    shader.append(R"(