Add skhdr::Agtm interface Add a semi-public skhdr::Agtm interface for AGTM metdata. Rename the internal skhdr::Agtm structure to skhdr::AgtmImpl, and have it implement the abstract public interface. Add the function AgtmImpl::populateGainCurvesXYM which populates the SkImage used for the gain curves. This is now done at creation time, instead of being done lazily. Add the functions skhdr::Metadata::get/setAgtm. These functions take serialized AGTM metadata. The actual AGTM metadata will most often flow through the full display pipeline in its serialized form (perhaps going all the way to the OS without ever being deserialized). Add the function skhdr::AgtmImpl::toString, because it is needed for the function skhdr::Metadata::toString. Bug: skia:456675139 Change-Id: Ic41ec122698a9fa57336f8dc7324fa6d2909dc7f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1110357 Owners-Override: Kaylee Lubick <kjlubick@google.com> Commit-Queue: Christopher Cameron <ccameron@google.com> Reviewed-by: Kaylee Lubick <kjlubick@google.com> Reviewed-by: Michael Ludwig <michaelludwig@google.com> Reviewed-by: Christopher Cameron <ccameron@google.com>
diff --git a/include/core/SkData.h b/include/core/SkData.h index d680fab..0225208 100644 --- a/include/core/SkData.h +++ b/include/core/SkData.h
@@ -40,6 +40,14 @@ } /** + * Return true if both arguments are the same size and contain the same bytes, or if both + * arguments are null. + */ + static bool Equals(const SkData* a, const SkData* b) { + return (a == nullptr) ? (b == nullptr) : a->equals(b); + } + + /** * Returns the number of bytes stored. */ size_t size() const { return fSpan.size(); }
diff --git a/include/private/SkHdrMetadata.h b/include/private/SkHdrMetadata.h index 400718a..173552b 100644 --- a/include/private/SkHdrMetadata.h +++ b/include/private/SkHdrMetadata.h
@@ -9,12 +9,13 @@ #define SkHdrMetadata_DEFINED #include "include/core/SkColorSpace.h" -#include "include/core/SkRefCnt.h" +#include "include/core/SkData.h" #include "include/private/base/SkAPI.h" +#include <memory> #include <optional> - +class SkColorFilter; class SkData; class SkString; @@ -122,6 +123,75 @@ }; /** + * Adaptive Global Tone Mapping HDR metadata + * The semantics of this metadata is defined in: + * SMPTE ST 2094-50: Dynamic metadata for color volume transform — Application #5 + * Under development at: + * https://github.com/SMPTE/st2094-50 + */ +class SK_API Agtm { + public: + /** + * Parse the specified SkData. Returns nullptr if the data fails to parse. + */ + static std::unique_ptr<Agtm> Make(const SkData* data); + + /** + * Generate reference white tone mapping metadata for the specified baseline HDR headroom and + * HDR reference white values. + */ + static std::unique_ptr<Agtm> MakeReferenceWhite(float hdrReferenceWhite, + float baselineHdrHeadroom); + + /** + * Generate metadata with a HDR reference white set to `hdrReferenceWhite`, that specifies that + * no tone mapping is to be done (that is, just clamping is to be performed), and that the + * content has HDR headroom specified by `baselineHdrHeadroom`. + */ + static std::unique_ptr<Agtm> MakeClamp(float hdrReferenceWhite, float baselineHdrHeadroom); + + virtual ~Agtm() = default; + + /** + * Serialize the data to the format parsed by Make. + */ + virtual sk_sp<SkData> serialize() const = 0; + + /** + * The default value for the HdrReferenceWhite metadata item. + */ + static constexpr float kDefaultHdrReferenceWhite = 203.f; + + /** + * Return the HdrReferenceWhite metadata item value. + */ + virtual float getHdrReferenceWhite() const = 0; + + /** + * Functions to query if the BaselineHdrHeadroom metadata item was specified and retrieve it + * (which will assert if was not specified). + */ + virtual bool hasBaselineHdrHeadroom() const = 0; + virtual float getBaselineHdrHeadroom() const = 0; + + /** + * Return true if this metadata specifies not to do any tone mapping (it is the type that + * was created using MakeClamp). + */ + virtual bool isClamp() const = 0; + + /** + * Return the SkColorFilter to tone map to the specified targeted HDR headroom. + */ + virtual sk_sp<SkColorFilter> makeColorFilter(float targetedHdrHeadroom) const = 0; + + /** + * Return a human-readable description. + */ + virtual SkString toString() const = 0; +}; + +/** * Structure containing all HDR metadata that can be attached to an image or video frame. */ class SK_API Metadata { @@ -154,6 +224,16 @@ void setMasteringDisplayColorVolume(const MasteringDisplayColorVolume& mdcv); /** + * Return the serialized Adaptive Global Tone Mapping metadata, or nullptr if none has been set. + */ + sk_sp<const SkData> getSerializedAgtm() const; + + /** + * Set the serialized Adaptive Global Tone Mapping metadata. + */ + void setSerializedAgtm(sk_sp<const SkData>); + + /** * Return a human-readable description. */ SkString toString() const; @@ -166,6 +246,7 @@ private: std::optional<ContentLightLevelInformation> fContentLightLevelInformation; std::optional<MasteringDisplayColorVolume> fMasteringDisplayColorVolume; + sk_sp<const SkData> fAgtm; }; } // namespace skhdr
diff --git a/relnotes/agtm.md b/relnotes/agtm.md new file mode 100644 index 0000000..14bc097 --- /dev/null +++ b/relnotes/agtm.md
@@ -0,0 +1,8 @@ +Add `skhdr::Agtm` interface. + +Provide an interface to to create SMPTE ST 2094-50 (also known as Adaptive +Global Tone Mapping) metadata. This interface includes parsing, serialization, +and tone mapping (via an SkColorFilter). + +Add interface to set and get serialized AGTM metadata to `skhdr::Metadata`. +
diff --git a/relnotes/skdata-equals.md b/relnotes/skdata-equals.md new file mode 100644 index 0000000..9661d8a --- /dev/null +++ b/relnotes/skdata-equals.md
@@ -0,0 +1,4 @@ +Add the function `SkData::Equals`. + +This function can compare two `SkData`s, even when both are nullptr. +
diff --git a/src/codec/SkHdrAgtm.cpp b/src/codec/SkHdrAgtm.cpp index 520ed27..49430f8 100644 --- a/src/codec/SkHdrAgtm.cpp +++ b/src/codec/SkHdrAgtm.cpp
@@ -6,6 +6,7 @@ */ #include "include/core/SkBitmap.h" +#include "include/core/SkColorFilter.h" #include "include/effects/SkRuntimeEffect.h" #include "include/private/SkHdrMetadata.h" #include "src/codec/SkHdrAgtmPriv.h" @@ -26,7 +27,7 @@ "uniform half curve_texcoord_y_j;" "uniform half curve_N_cp_j;" - // Shader equivalent of Agtm::ComponentMixingFunction::evaluate. + // Shader equivalent of AgtmImpl::ComponentMixingFunction::evaluate. "half3 EvalComponentMixing(half3 color, half4 rgbx, half4 Mmcx) {" "half common = dot(rgbx.rgb, color) +" "Mmcx[0] * max(max(color.r, color.g), color.b) +" @@ -34,7 +35,7 @@ "return Mmcx[2] * color + half3(common);" "}" - // Shader equivalent of Agtm::PiecewiseCubicFunction::evaluate. + // Shader equivalent of AgtmImpl::PiecewiseCubicFunction::evaluate. "half EvalGainCurve(half x, half curve_texcoord_y, half curve_N_cp) {" // Handle points to the left of the first control point. "half c_min = 0.0;" @@ -48,8 +49,8 @@ "if (x >= xym_max.x) {" "return xym_max.y + log2(xym_max.x / x);" "}" - // Binary search for the interval containing x. This will require sampling at most - // log2(32)=5 more control points. + // Binary search for the interval containing x. This will require sampling at most + // log2(32)=5 more control points. "for (int step = 0; step < 5; ++step) {" // Early-out if we've already found the interval. "if (c_max - c_min <= 1.0) {" @@ -81,7 +82,7 @@ "return ((c3*t + c2)*t + c1)*t + c0;" "}" - // Shader equivalent of Agtm::GainFunction::evaluate. + // Shader equivalent of AgtmImpl::GainFunction::evaluate. "half3 EvalColorGainFunction(half3 color," "half4 mix_rgbx, half4 mix_Mmcx," "float curve_texcoord_y, float curve_N_cp) {" @@ -95,7 +96,7 @@ "EvalGainCurve(M.b, curve_texcoord_y, curve_N_cp));" "}" - // Shader equivalent of Agtm::applyGain. + // Shader equivalent of AgtmImpl::applyGain. "half4 main(half4 color) {" "if (weight_i > 0.0) {" // Unpremultiply alpha is needed. @@ -128,7 +129,7 @@ namespace skhdr { -SkColor4f Agtm::ComponentMixingFunction::evaluate(const SkColor4f& c) const { +SkColor4f AgtmImpl::ComponentMixingFunction::evaluate(const SkColor4f& c) const { // Assert that the parameters satisfy the constraints in clause 5.2.2. SkASSERT(0.f <= fRed && fRed <= 1.f); SkASSERT(0.f <= fGreen && fGreen <= 1.f); @@ -153,7 +154,7 @@ return {fComponent * c.fR + common, fComponent * c.fG + common, fComponent * c.fB + common, c.fA}; } -float Agtm::PiecewiseCubicFunction::evaluate(float x) const { +float AgtmImpl::PiecewiseCubicFunction::evaluate(float x) const { // This implements that math in Formula 1 of SMPTE ST 2094-50. SkASSERT(fNumControlPoints > 0 && fNumControlPoints <= 32); @@ -203,7 +204,7 @@ return ((c3*t + c2)*t + c1)*t + c0; } -SkColor4f Agtm::GainFunction::evaluate(const SkColor4f& c) const { +SkColor4f AgtmImpl::GainFunction::evaluate(const SkColor4f& c) const { SkColor4f m = fComponentMixing.evaluate(c); SkColor4f result = {0.f, 0.f, 0.f, c.fA}; result.fR = fPiecewiseCubic.evaluate(m.fR); @@ -217,12 +218,12 @@ return result; } -void Agtm::PiecewiseCubicFunction::populateSlopeFromPCHIP() { +void AgtmImpl::PiecewiseCubicFunction::populateSlopeFromPCHIP() { size_t N = fNumControlPoints; // Compute the interval width (h) and piecewise linear slope (s). - float s[Agtm::PiecewiseCubicFunction::kMaxNumControlPoints]; - float h[Agtm::PiecewiseCubicFunction::kMaxNumControlPoints]; + float s[AgtmImpl::PiecewiseCubicFunction::kMaxNumControlPoints]; + float h[AgtmImpl::PiecewiseCubicFunction::kMaxNumControlPoints]; for (size_t i = 0; i < N - 1; ++i) { h[i] = fX[i+1] - fX[i]; } @@ -256,7 +257,26 @@ } } -void Agtm::populateUsingRwtmo() { +void AgtmImpl::populateGainCurvesXYM() { + SkBitmap curve_xym_bm; + curve_xym_bm.allocPixels(SkImageInfo::Make( + PiecewiseCubicFunction::kMaxNumControlPoints, kMaxNumAlternateImages, + kRGBA_F32_SkColorType, kUnpremul_SkAlphaType)); + for (uint8_t a = 0; a < fNumAlternateImages; ++a) { + auto& cubic = fGainFunction[a].fPiecewiseCubic; + for (uint8_t c = 0; c < cubic.fNumControlPoints; ++c) { + float* xymX = reinterpret_cast<float*>(curve_xym_bm.getAddr(c, a)); + xymX[0] = cubic.fX[c]; + xymX[1] = cubic.fY[c]; + xymX[2] = cubic.fM[c]; + xymX[3] = 1.f; + } + } + curve_xym_bm.setImmutable(); + fGainCurvesXYM = SkImages::RasterFromBitmap(curve_xym_bm); +} + +void AgtmImpl::populateUsingRwtmo() { fType = Type::kReferenceWhite; fGainApplicationSpacePrimaries = SkNamedPrimaries::kRec2020; @@ -319,7 +339,7 @@ } } -Agtm::Weighting Agtm::computeWeighting(float targetedHdrHeadroom) const { +AgtmImpl::Weighting AgtmImpl::computeWeighting(float targetedHdrHeadroom) const { Weighting result; // Create the list of HDR headrooms including the baseline image and all alternate images, as @@ -390,7 +410,7 @@ return result; } -void Agtm::applyGain(SkSpan<SkColor4f> colors, float targetedHdrHeadroom) const { +void AgtmImpl::applyGain(SkSpan<SkColor4f> colors, float targetedHdrHeadroom) const { const auto weighting = computeWeighting(targetedHdrHeadroom); if (weighting.fWeight[0] == 0.f) { // If no weight is non-zero, then no gain will be applied. Leave the points unchanged. @@ -427,33 +447,41 @@ } } -sk_sp<SkColorFilter> Agtm::makeColorFilter(float targetedHdrHeadroom) const { +sk_sp<SkColorSpace> AgtmImpl::getGainApplicationSpace() const { + skcms_Matrix3x3 toXYZD50; + if (!fGainApplicationSpacePrimaries.toXYZD50(&toXYZD50)) { + return nullptr; + } + return SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, toXYZD50); +} + +float AgtmImpl::getHdrReferenceWhite() const { + return fHdrReferenceWhite; +} + +bool AgtmImpl::hasBaselineHdrHeadroom() const { + return fType != Type::kNone; +} + +float AgtmImpl::getBaselineHdrHeadroom() const { + SkASSERT(fType != Type::kNone); + return fBaselineHdrHeadroom; +} + +bool AgtmImpl::isClamp() const { + if (fType == Type::kNone) { + return false; + } + return fNumAlternateImages == 0; +} + +sk_sp<SkColorFilter> AgtmImpl::makeColorFilter(float targetedHdrHeadroom) const { auto effect = agtm_runtime_effect(); if (!effect) { return nullptr; } const auto weighting = computeWeighting(targetedHdrHeadroom); - // Populate all control points into a cached SkImage. - if (!fGainCurvesXYM) { - SkBitmap curve_xym_bm; - curve_xym_bm.allocPixels(SkImageInfo::Make( - PiecewiseCubicFunction::kMaxNumControlPoints, kMaxNumAlternateImages, - kRGBA_F32_SkColorType, kUnpremul_SkAlphaType)); - for (uint8_t a = 0; a < fNumAlternateImages; ++a) { - auto& cubic = fGainFunction[a].fPiecewiseCubic; - for (uint8_t c = 0; c < cubic.fNumControlPoints; ++c) { - float* xymX = reinterpret_cast<float*>(curve_xym_bm.getAddr(c, a)); - xymX[0] = cubic.fX[c]; - xymX[1] = cubic.fY[c]; - xymX[2] = cubic.fM[c]; - xymX[3] = 1.f; - } - } - curve_xym_bm.setImmutable(); - fGainCurvesXYM = SkImages::RasterFromBitmap(curve_xym_bm); - } - SkRuntimeShaderBuilder builder(effect); for (uint8_t a = 0; a < 2; ++a) { const char* weight_str[2] = {"weight_i", "weight_j"}; @@ -495,12 +523,58 @@ return filter->makeWithWorkingColorSpace(getGainApplicationSpace()); } -sk_sp<SkColorSpace> Agtm::getGainApplicationSpace() const { - skcms_Matrix3x3 toXYZD50; - if (!fGainApplicationSpacePrimaries.toXYZD50(&toXYZD50)) { +SkString AgtmImpl::toString() const { + SkString result = SkStringPrintf("{hdrReferenceWhite:%f", fHdrReferenceWhite); + if (fType == Type::kNone) { + result += "}"; + return result; + } + result += SkStringPrintf(", baselineHdrHeadroom:%f", fBaselineHdrHeadroom); + if (fType == Type::kReferenceWhite) { + result += ", RWTMO}"; + return result; + } + result += ", alternateHdrHeadrooms:["; + for (uint8_t a = 0; a < fNumAlternateImages; ++a) { + result += SkStringPrintf("%f", fAlternateHdrHeadroom[a]); + if (a != fNumAlternateImages - 1) { + result += ", "; + } + } + result += "]}"; + return result; +} + +// static +std::unique_ptr<Agtm> Agtm::Make(const SkData* data) { + auto result = std::make_unique<AgtmImpl>(); + if (!result->parse(data)) { return nullptr; } - return SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, toXYZD50); + result->populateGainCurvesXYM(); + return result; +} + +// static +std::unique_ptr<Agtm> Agtm::MakeReferenceWhite(float hdrReferenceWhite, float baselineHdrHeadroom) { + SkASSERT(baselineHdrHeadroom >= 0.f); + auto result = std::make_unique<AgtmImpl>(); + result->fHdrReferenceWhite = hdrReferenceWhite; + result->fBaselineHdrHeadroom = baselineHdrHeadroom; + result->populateUsingRwtmo(); + result->populateGainCurvesXYM(); + return result; +} + +// static +std::unique_ptr<Agtm> Agtm::MakeClamp(float hdrReferenceWhite, float baselineHdrHeadroom) { + SkASSERT(baselineHdrHeadroom >= 0.f); + auto result = std::make_unique<AgtmImpl>(); + result->fHdrReferenceWhite = hdrReferenceWhite; + result->fBaselineHdrHeadroom = baselineHdrHeadroom; + result->fGainApplicationSpacePrimaries = SkNamedPrimaries::kRec2020; + result->populateGainCurvesXYM(); + return result; } } // namespace skhdr
diff --git a/src/codec/SkHdrAgtmParse.cpp b/src/codec/SkHdrAgtmParse.cpp index 31e6024..fb1a41d 100644 --- a/src/codec/SkHdrAgtmParse.cpp +++ b/src/codec/SkHdrAgtmParse.cpp
@@ -203,7 +203,7 @@ } } for (uint8_t a = 0; a < std::min(num_alternate_images, - skhdr::Agtm::kMaxNumAlternateImages); ++a) { + skhdr::AgtmImpl::kMaxNumAlternateImages); ++a) { RETURN_ON_FALSE(SkStreamPriv::ReadU16BE(&s, &alternate_hdr_headrooms[a])); RETURN_ON_FALSE(parse_component_mixing(a, s)); RETURN_ON_FALSE(parse_gain_curve(a, s)); @@ -345,7 +345,7 @@ namespace skhdr { -bool Agtm::parse(const SkData* data) { +bool AgtmImpl::parse(const SkData* data) { if (data == nullptr) { return false; } @@ -483,7 +483,7 @@ return true; } -sk_sp<SkData> Agtm::serialize() const { +sk_sp<SkData> AgtmImpl::serialize() const { AgtmSyntax syntax; memset(&syntax, 0, sizeof(syntax));
diff --git a/src/codec/SkHdrAgtmPriv.h b/src/codec/SkHdrAgtmPriv.h index e828eb2..5bbe143 100644 --- a/src/codec/SkHdrAgtmPriv.h +++ b/src/codec/SkHdrAgtmPriv.h
@@ -9,12 +9,11 @@ #define SkHdrAgtmPriv_DEFINED #include "include/core/SkColor.h" -#include "include/core/SkColorFilter.h" #include "include/core/SkColorSpace.h" #include "include/core/SkImage.h" #include "include/core/SkRefCnt.h" #include "include/core/SkSpan.h" -#include "include/private/base/SkAPI.h" +#include "include/private/SkHdrMetadata.h" #include <optional> #include <vector> @@ -30,7 +29,8 @@ * SMPTE ST 2094-50: Dynamic metadata for color volume transform — Application #5 * https://github.com/SMPTE/st2094-50 */ -struct SK_API Agtm { +class AgtmImpl final : public Agtm { + public: // A PiecewiseCubic metadata group, described in Clause 5.1, Piecewise cubic function. struct PiecewiseCubicFunction { // The GainCurveNumControlPoints metadata item. @@ -94,7 +94,6 @@ Type fType = Type::kNone; // The HdrReferenceWhite metadata item. - static constexpr float kDefaultHdrReferenceWhite = 203.f; float fHdrReferenceWhite = kDefaultHdrReferenceWhite; // The BaselineHdrHeadroom metadata item. @@ -113,9 +112,14 @@ // The GainFunction metadata item list. GainFunction fGainFunction[kMaxNumAlternateImages]; - // SkImage containing the control point values for use by the color filter. This is - // lazily allocated by makeColorFilter(). - mutable sk_sp<SkImage> fGainCurvesXYM; + // SkImage containing the control point values for use by the color filter, populated by + // populateGainCurvesXYM. + sk_sp<SkImage> fGainCurvesXYM; + + /** + * Populate the fGainCurvesXYM which will cache the gain curves' values in an SkImage. + */ + void populateGainCurvesXYM(); /** * This will populate the metadata with the Reference White Tone Mapping Operator (RWTMO) @@ -130,11 +134,6 @@ bool parse(const SkData* data); /** - * Serialize to a smpte_st_2094_50_application_info_v0() bitstream. - */ - sk_sp<SkData> serialize() const; - - /** * Compute the weighting for the specified targeted HDR headroom according to the computations * in Clause 5.4.5, Computation of the adaptive tone map. */ @@ -156,14 +155,21 @@ void applyGain(SkSpan<SkColor4f> colors, float targetedHdrHeadroom) const; /** - * Return a color filter to apply tone mapping targeting the specified `targetedHdrHeadroom`. - */ - sk_sp<SkColorFilter> makeColorFilter(float targetedHdrHeadroom) const; - - /** * Return the gain application color space. */ sk_sp<SkColorSpace> getGainApplicationSpace() const; + + /** + * Implementation of the Agtm interface. + */ + ~AgtmImpl() override = default; + sk_sp<SkData> serialize() const override; + float getHdrReferenceWhite() const override; + bool hasBaselineHdrHeadroom() const override; + float getBaselineHdrHeadroom() const override; + bool isClamp() const override; + sk_sp<SkColorFilter> makeColorFilter(float targetedHdrHeadroom) const override; + SkString toString() const override; }; } // namespace skhdr
diff --git a/src/codec/SkHdrMetadata.cpp b/src/codec/SkHdrMetadata.cpp index cc50270..8f63cae 100644 --- a/src/codec/SkHdrMetadata.cpp +++ b/src/codec/SkHdrMetadata.cpp
@@ -185,6 +185,10 @@ return true; } +sk_sp<const SkData> Metadata::getSerializedAgtm() const { + return fAgtm; +} + void Metadata::setMasteringDisplayColorVolume(const MasteringDisplayColorVolume& mdcv) { fMasteringDisplayColorVolume = mdcv; } @@ -193,17 +197,24 @@ fContentLightLevelInformation = clli; } +void Metadata::setSerializedAgtm(sk_sp<const SkData> agtm) { + fAgtm = agtm; +} + SkString Metadata::toString() const { - return SkStringPrintf("{clli:%s, mdcv:%s}", + auto agtm = Agtm::Make(fAgtm.get()); + return SkStringPrintf("{clli:%s, mdcv:%s, agtm:%s}", fContentLightLevelInformation.has_value() ? fContentLightLevelInformation->toString().c_str() : "None", fMasteringDisplayColorVolume.has_value() ? - fMasteringDisplayColorVolume->toString().c_str() : "None"); + fMasteringDisplayColorVolume->toString().c_str() : "None", + agtm ? agtm->toString().c_str() : "None"); } bool Metadata::operator==(const Metadata& other) const { return fContentLightLevelInformation == other.fContentLightLevelInformation && - fMasteringDisplayColorVolume == other.fMasteringDisplayColorVolume; + fMasteringDisplayColorVolume == other.fMasteringDisplayColorVolume && + SkData::Equals(fAgtm.get(), other.fAgtm.get()); } } // namespace skhdr
diff --git a/tests/HdrMetadataTest.cpp b/tests/HdrMetadataTest.cpp index 99f6ee7..8d50717 100644 --- a/tests/HdrMetadataTest.cpp +++ b/tests/HdrMetadataTest.cpp
@@ -7,6 +7,7 @@ #include "include/core/SkBitmap.h" #include "include/core/SkCanvas.h" +#include "include/core/SkColorFilter.h" #include "include/core/SkData.h" #include "include/core/SkImage.h" #include "include/core/SkScalar.h" @@ -70,7 +71,7 @@ } DEF_TEST(HdrMetadata_Agtm_Cubic, r) { - skhdr::Agtm::PiecewiseCubicFunction cubic = { + skhdr::AgtmImpl::PiecewiseCubicFunction cubic = { 10, {0.10720647f, 0.76246667f, 1.39535723f, 2.17572099f, 2.47834070f, 3.14288223f, 3.35428070f, 4.24864607f, 4.59087493f, 4.80373641f}, @@ -98,7 +99,7 @@ } DEF_TEST(HdrMetadata_Agtm_Mix, r) { - auto test = [&r](const std::string& name, skhdr::Agtm::ComponentMixingFunction mix, + auto test = [&r](const std::string& name, skhdr::AgtmImpl::ComponentMixingFunction mix, SkColor4f input, SkColor4f expected) { skiatest::ReporterContext ctx(r, name); SkColor4f actual = mix.evaluate(input); @@ -110,49 +111,49 @@ }; test("Red only", - skhdr::Agtm::ComponentMixingFunction({.fRed=1.f}), + skhdr::AgtmImpl::ComponentMixingFunction({.fRed=1.f}), SkColor4f({0.5f, 0.75f, 0.25f, 1.f}), SkColor4f({0.5f, 0.5f, 0.5f, 1.f})); test("Green only", - skhdr::Agtm::ComponentMixingFunction({.fGreen=1.f}), + skhdr::AgtmImpl::ComponentMixingFunction({.fGreen=1.f}), SkColor4f({0.75f, 0.5f, 0.25f, 1.f}), SkColor4f({0.5f, 0.5f, 0.5f, 1.f})); test("Blue only", - skhdr::Agtm::ComponentMixingFunction({.fBlue=1.f}), + skhdr::AgtmImpl::ComponentMixingFunction({.fBlue=1.f}), SkColor4f({0.75f, 0.25f, 0.5f, 1.f}), SkColor4f({0.5f, 0.5f, 0.5f, 1.f})); test("Max only", - skhdr::Agtm::ComponentMixingFunction({.fMax=1.f}), + skhdr::AgtmImpl::ComponentMixingFunction({.fMax=1.f}), SkColor4f({0.75f, 0.5f, 0.25f, 1.f}), SkColor4f({0.75f, 0.75f, 0.75f, 1.f})); test("Min only", - skhdr::Agtm::ComponentMixingFunction({.fMin=1.f}), + skhdr::AgtmImpl::ComponentMixingFunction({.fMin=1.f}), SkColor4f({0.75f, 0.5f, 0.25f, 1.f}), SkColor4f({0.25f, 0.25f, 0.25f, 1.f})); test("Component only", - skhdr::Agtm::ComponentMixingFunction({.fComponent=1.f}), + skhdr::AgtmImpl::ComponentMixingFunction({.fComponent=1.f}), SkColor4f({0.75f, 0.5f, 0.25f, 1.f}), SkColor4f({0.75f, 0.5f, 0.25f, 1.f})); test("CIE Y (luminance)", - skhdr::Agtm::ComponentMixingFunction({.fRed=0.2627f, .fGreen=0.6780f, .fBlue=0.0593f}), + skhdr::AgtmImpl::ComponentMixingFunction({.fRed=0.2627f, .fGreen=0.6780f, .fBlue=0.0593f}), SkColor4f({0.75f, 0.5f, 0.25f, 0.125f}), SkColor4f({0.55085f, 0.55085f, 0.55085f, 0.125f})); test("max-component", - skhdr::Agtm::ComponentMixingFunction({.fMax=0.75f, .fComponent=0.25f}), + skhdr::AgtmImpl::ComponentMixingFunction({.fMax=0.75f, .fComponent=0.25f}), SkColor4f({0.75f, 0.5f, 0.25f, 0.125f}), SkColor4f({0.75f, 0.6875f, 0.6250f, 0.125f})); } DEF_TEST(HdrMetadata_Agtm_RWTMO, r) { - skhdr::Agtm agtm; + skhdr::AgtmImpl agtm; agtm.fBaselineHdrHeadroom = 1.f; agtm.populateUsingRwtmo(); @@ -187,13 +188,13 @@ } DEF_TEST(HdrMetadata_Agtm_Weighting, r) { - skhdr::Agtm agtm; + skhdr::AgtmImpl agtm; auto test = [&r, &agtm](const std::string& name, float targetedHdrHeadroom, - const skhdr::Agtm::Weighting& wExpected) { + const skhdr::AgtmImpl::Weighting& wExpected) { skiatest::ReporterContext ctx(r, name); - skhdr::Agtm::Weighting w = agtm.computeWeighting(targetedHdrHeadroom); + skhdr::AgtmImpl::Weighting w = agtm.computeWeighting(targetedHdrHeadroom); REPORTER_ASSERT(r, w.fWeight[0] == wExpected.fWeight[0]); REPORTER_ASSERT(r, w.fWeight[1] == wExpected.fWeight[1]); REPORTER_ASSERT(r, w.fAlternateImageIndex[0] == wExpected.fAlternateImageIndex[0]); @@ -203,15 +204,15 @@ // Tests with a single baseline representation. agtm.fBaselineHdrHeadroom = 1.f; test("base-1, target-0", 0.f, - {{skhdr::Agtm::Weighting::kInvalidIndex, skhdr::Agtm::Weighting::kInvalidIndex}, + {{skhdr::AgtmImpl::Weighting::kInvalidIndex, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {0.f, 0.f}}); test("base-1, target-1", 1.f, - {{skhdr::Agtm::Weighting::kInvalidIndex, skhdr::Agtm::Weighting::kInvalidIndex}, + {{skhdr::AgtmImpl::Weighting::kInvalidIndex, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {0.f, 0.f}}); test("base-2, target-2", 2.f, - {{skhdr::Agtm::Weighting::kInvalidIndex, skhdr::Agtm::Weighting::kInvalidIndex}, + {{skhdr::AgtmImpl::Weighting::kInvalidIndex, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {0.f, 0.f}}); // Tests with a baseline and an alternate representation. @@ -220,19 +221,19 @@ agtm.fAlternateHdrHeadroom[0] = 0.f; test("base-1-alt0, target-0", 0.f, - {{0, skhdr::Agtm::Weighting::kInvalidIndex}, + {{0, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {1.f, 0.f}}); test("base-1-alt0, target-0.25", 0.25f, - {{0, skhdr::Agtm::Weighting::kInvalidIndex}, + {{0, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {0.75f, 0.f}}); test("base-1-alt0, target-1", 1.f, - {{skhdr::Agtm::Weighting::kInvalidIndex, skhdr::Agtm::Weighting::kInvalidIndex}, + {{skhdr::AgtmImpl::Weighting::kInvalidIndex, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {0.f, 0.f}}); test("base-1-alt0, target-1.25", 1.25f, - {{skhdr::Agtm::Weighting::kInvalidIndex, skhdr::Agtm::Weighting::kInvalidIndex}, + {{skhdr::AgtmImpl::Weighting::kInvalidIndex, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {0.f, 0.f}}); // Two alternate representations. @@ -242,27 +243,27 @@ agtm.fAlternateHdrHeadroom[1] = 2.f; test("base-1-alt0-alt2, target-0", 0.f, - {{0, skhdr::Agtm::Weighting::kInvalidIndex}, + {{0, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {1.f, 0.f}}); test("base-1-alt0-alt2, target-0.25", 0.25f, - {{0, skhdr::Agtm::Weighting::kInvalidIndex}, + {{0, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {0.75f, 0.f}}); test("base-1-alt0-alt2, target-1", 1.f, - {{skhdr::Agtm::Weighting::kInvalidIndex, skhdr::Agtm::Weighting::kInvalidIndex}, + {{skhdr::AgtmImpl::Weighting::kInvalidIndex, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {0.f, 0.f}}); test("base-1-alt0-alt2, target-1.25", 1.25f, - {{1, skhdr::Agtm::Weighting::kInvalidIndex}, + {{1, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {0.25f, 0.f}}); test("base-1-alt0-alt2, target-2", 2.f, - {{1, skhdr::Agtm::Weighting::kInvalidIndex}, + {{1, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {1.f, 0.f}}); test("base-1-alt0-alt2, target-3", 3.f, - {{1, skhdr::Agtm::Weighting::kInvalidIndex}, + {{1, skhdr::AgtmImpl::Weighting::kInvalidIndex}, {1.f, 0.f}}); // Two alternate representations again, now mix-able. @@ -281,8 +282,8 @@ } static void assert_agtms_equal(skiatest::Reporter* r, - const skhdr::Agtm& agtmIn, - const skhdr::Agtm& agtmOut) { + const skhdr::AgtmImpl& agtmIn, + const skhdr::AgtmImpl& agtmOut) { // Allow error for headrooms, x, and y to twice the their encoding step. constexpr float kHeadroomError = 2.f * 1.f / 10000.f; constexpr float kXError = 2.f * 1.f / 1000.f; @@ -290,12 +291,12 @@ // Allow a wider error for slope because its encoding is non-uniform. constexpr float kMError = 0.005f; - REPORTER_ASSERT(r, agtmIn.fType == agtmOut.fType); - REPORTER_ASSERT(r, agtmIn.fHdrReferenceWhite == agtmOut.fHdrReferenceWhite); + REPORTER_ASSERT(r, agtmIn.fType == agtmOut.fType); + REPORTER_ASSERT(r, agtmIn.fHdrReferenceWhite == agtmOut.fHdrReferenceWhite); REPORTER_ASSERT(r, SkScalarNearlyEqual( agtmIn.fBaselineHdrHeadroom, agtmOut.fBaselineHdrHeadroom, kHeadroomError)); REPORTER_ASSERT(r, agtmIn.fGainApplicationSpacePrimaries == - agtmOut.fGainApplicationSpacePrimaries); + agtmOut.fGainApplicationSpacePrimaries); REPORTER_ASSERT(r, agtmIn.fNumAlternateImages == agtmOut.fNumAlternateImages); if (agtmIn.fNumAlternateImages != agtmOut.fNumAlternateImages) { return; @@ -336,11 +337,11 @@ { skiatest::ReporterContext ctx(r, "NoAdaptiveToneMap"); - skhdr::Agtm agtmIn; + skhdr::AgtmImpl agtmIn; agtmIn.fHdrReferenceWhite = 123.f; - agtmIn.fType = skhdr::Agtm::Type::kNone; + agtmIn.fType = skhdr::AgtmImpl::Type::kNone; - skhdr::Agtm agtmOut; + skhdr::AgtmImpl agtmOut; REPORTER_ASSERT(r, agtmOut.parse(agtmIn.serialize().get())); assert_agtms_equal(r, agtmIn, agtmOut); @@ -349,11 +350,11 @@ { skiatest::ReporterContext ctx(r, "RWTMO"); - skhdr::Agtm agtmIn; + skhdr::AgtmImpl agtmIn; agtmIn.fBaselineHdrHeadroom = 1.f; agtmIn.populateUsingRwtmo(); - skhdr::Agtm agtmOut; + skhdr::AgtmImpl agtmOut; REPORTER_ASSERT(r, agtmOut.parse(agtmIn.serialize().get())); assert_agtms_equal(r, agtmIn, agtmOut); @@ -362,14 +363,14 @@ { skiatest::ReporterContext ctx(r, "ClampInRec601"); - skhdr::Agtm agtmIn; - agtmIn.fType = skhdr::Agtm::Type::kCustom; + skhdr::AgtmImpl agtmIn; + agtmIn.fType = skhdr::AgtmImpl::Type::kCustom; agtmIn.fHdrReferenceWhite = 100.f; agtmIn.fBaselineHdrHeadroom = 2.f; agtmIn.fGainApplicationSpacePrimaries = SkNamedPrimaries::kRec601; agtmIn.fNumAlternateImages = 0; - skhdr::Agtm agtmOut; + skhdr::AgtmImpl agtmOut; REPORTER_ASSERT(r, agtmOut.parse(agtmIn.serialize().get())); assert_agtms_equal(r, agtmIn, agtmOut); @@ -378,8 +379,8 @@ { skiatest::ReporterContext ctx(r, "OneAlternates"); - skhdr::Agtm agtmIn; - agtmIn.fType = skhdr::Agtm::Type::kCustom; + skhdr::AgtmImpl agtmIn; + agtmIn.fType = skhdr::AgtmImpl::Type::kCustom; agtmIn.fHdrReferenceWhite = 400.f; agtmIn.fBaselineHdrHeadroom = 4.f; agtmIn.fGainApplicationSpacePrimaries = SkNamedPrimaries::kSMPTE_EG_432_1; @@ -397,7 +398,7 @@ }, }; - skhdr::Agtm agtmOut; + skhdr::AgtmImpl agtmOut; REPORTER_ASSERT(r, agtmOut.parse(agtmIn.serialize().get())); assert_agtms_equal(r, agtmIn, agtmOut); @@ -406,8 +407,8 @@ { skiatest::ReporterContext ctx(r, "FourAlternates"); - skhdr::Agtm agtmIn; - agtmIn.fType = skhdr::Agtm::Type::kCustom; + skhdr::AgtmImpl agtmIn; + agtmIn.fType = skhdr::AgtmImpl::Type::kCustom; agtmIn.fHdrReferenceWhite = 400.f; agtmIn.fBaselineHdrHeadroom = 2.f; agtmIn.fGainApplicationSpacePrimaries = SkNamedPrimaries::kSMPTE_EG_432_1; @@ -464,7 +465,7 @@ }, }; - skhdr::Agtm agtmOut; + skhdr::AgtmImpl agtmOut; REPORTER_ASSERT(r, agtmOut.parse(agtmIn.serialize().get())); assert_agtms_equal(r, agtmIn, agtmOut); @@ -475,9 +476,10 @@ DEF_TEST(HdrMetadata_Agtm_Apply_and_Shader, r) { // This will tone map several input colors to different targeted HDR headrooms using this // RWTMO metadata. - skhdr::Agtm agtm; + skhdr::AgtmImpl agtm; agtm.fBaselineHdrHeadroom = 2; agtm.populateUsingRwtmo(); + agtm.populateGainCurvesXYM(); // We will use the following input pixel values in gain application color space. These include // monochrome and non-monochrome values, as well as values that are less than white (less than @@ -553,7 +555,7 @@ // Test the Agtm::applyGain function. for (size_t t = 0; t < kNumTests; ++t) { const auto targetedHdrHeadroom = testTargetedHdrHeadrooms[t]; - skiatest::ReporterContext ctx(r, SkStringPrintf("Agtm::applyGain, targetedHdrHeadroom:%f", targetedHdrHeadroom)); + skiatest::ReporterContext ctx(r, SkStringPrintf("AgtmImpl::applyGain, targetedHdrHeadroom:%f", targetedHdrHeadroom)); // Copy the inputTextColors to outputTestColors (because applyGain works in-place). SkColor4f outputTestColors[kNumTestColors];