Merge "Add HLG transfer function to proper dataspace" into tm-dev
This commit is contained in:
@@ -165,6 +165,14 @@ android_dataspace ColorSpaceToADataSpace(SkColorSpace* colorSpace, SkColorType c
|
|||||||
if (SkColorSpace::Equals(colorSpace, rec2020PQ.get())) {
|
if (SkColorSpace::Equals(colorSpace, rec2020PQ.get())) {
|
||||||
return HAL_DATASPACE_BT2020_PQ;
|
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");
|
LOG_ALWAYS_FATAL("Only select non-numerical transfer functions are supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,6 +255,14 @@ sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace) {
|
|||||||
return nullptr;
|
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) {
|
switch (dataspace & HAL_DATASPACE_TRANSFER_MASK) {
|
||||||
case HAL_DATASPACE_TRANSFER_LINEAR:
|
case HAL_DATASPACE_TRANSFER_LINEAR:
|
||||||
return SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, gamut);
|
return SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, gamut);
|
||||||
@@ -264,7 +280,6 @@ sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace) {
|
|||||||
return SkColorSpace::MakeRGB(SkNamedTransferFn::kRec2020, gamut);
|
return SkColorSpace::MakeRGB(SkNamedTransferFn::kRec2020, gamut);
|
||||||
case HAL_DATASPACE_TRANSFER_UNSPECIFIED:
|
case HAL_DATASPACE_TRANSFER_UNSPECIFIED:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
case HAL_DATASPACE_TRANSFER_HLG:
|
|
||||||
default:
|
default:
|
||||||
ALOGV("Unsupported Gamma: %d", dataspace);
|
ALOGV("Unsupported Gamma: %d", dataspace);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -381,5 +396,14 @@ skcms_TransferFunction GetPQSkTransferFunction(float sdr_white_level) {
|
|||||||
return fn;
|
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 uirenderer
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <system/graphics.h>
|
#include <system/graphics.h>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
struct ANativeWindow_Buffer;
|
struct ANativeWindow_Buffer;
|
||||||
struct AHardwareBuffer_Desc;
|
struct AHardwareBuffer_Desc;
|
||||||
|
|
||||||
@@ -127,6 +129,7 @@ struct Lab {
|
|||||||
Lab sRGBToLab(SkColor color);
|
Lab sRGBToLab(SkColor color);
|
||||||
SkColor LabToSRGB(const Lab& lab, SkAlpha alpha);
|
SkColor LabToSRGB(const Lab& lab, SkAlpha alpha);
|
||||||
skcms_TransferFunction GetPQSkTransferFunction(float sdr_white_level = 0.f);
|
skcms_TransferFunction GetPQSkTransferFunction(float sdr_white_level = 0.f);
|
||||||
|
std::optional<skcms_TransferFunction> GetHLGScaleTransferFunction();
|
||||||
|
|
||||||
} /* namespace uirenderer */
|
} /* namespace uirenderer */
|
||||||
} /* namespace android */
|
} /* namespace android */
|
||||||
|
|||||||
Reference in New Issue
Block a user