Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkGainmapInfo.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkGainmapInfo_DEFINED
9#define SkGainmapInfo_DEFINED
10
13
14/**
15 * Gainmap rendering parameters. Suppose our display has HDR to SDR ratio of H and we wish to
16 * display an image with gainmap on this display. Let B be the pixel value from the base image
17 * in a color space that has the primaries of the base image and a linear transfer function. Let
18 * G be the pixel value from the gainmap. Let D be the output pixel in the same color space as B.
19 * The value of D is computed as follows:
20 *
21 * First, let W be a weight parameter determing how much the gainmap will be applied.
22 * W = clamp((log(H) - log(fDisplayRatioSdr)) /
23 * (log(fDisplayRatioHdr) - log(fDisplayRatioSdr), 0, 1)
24 *
25 * Next, let L be the gainmap value in log space. We compute this from the value G that was
26 * sampled from the texture as follows:
27 * L = mix(log(fGainmapRatioMin), log(fGainmapRatioMax), pow(G, fGainmapGamma))
28 *
29 * Finally, apply the gainmap to compute D, the displayed pixel. If the base image is SDR then
30 * compute:
31 * D = (B + fEpsilonSdr) * exp(L * W) - fEpsilonHdr
32 * If the base image is HDR then compute:
33 * D = (B + fEpsilonHdr) * exp(L * (W - 1)) - fEpsilonSdr
34 *
35 * In the above math, log() is a natural logarithm and exp() is natural exponentiation. Note,
36 * however, that the base used for the log() and exp() functions does not affect the results of
37 * the computation (it cancels out, as long as the same base is used throughout).
38 *
39 * This product includes Gain Map technology under license by Adobe.
40 */
42 /**
43 * Parameters for converting the gainmap from its image encoding to log space. These are
44 * specified per color channel. The alpha value is unused.
45 */
46 SkColor4f fGainmapRatioMin = {1.f, 1.f, 1.f, 1.0};
47 SkColor4f fGainmapRatioMax = {2.f, 2.f, 2.f, 1.0};
48 SkColor4f fGainmapGamma = {1.f, 1.f, 1.f, 1.f};
49
50 /**
51 * Parameters sometimes used in gainmap computation to avoid numerical instability.
52 */
53 SkColor4f fEpsilonSdr = {0.f, 0.f, 0.f, 1.0};
54 SkColor4f fEpsilonHdr = {0.f, 0.f, 0.f, 1.0};
55
56 /**
57 * If the output display's HDR to SDR ratio is less or equal than fDisplayRatioSdr then the SDR
58 * rendition is displayed. If the output display's HDR to SDR ratio is greater or equal than
59 * fDisplayRatioHdr then the HDR rendition is displayed. If the output display's HDR to SDR
60 * ratio is between these values then an interpolation between the two is displayed using the
61 * math above.
62 */
63 float fDisplayRatioSdr = 1.f;
64 float fDisplayRatioHdr = 2.f;
65
66 /**
67 * Whether the base image is the SDR image or the HDR image.
68 */
69 enum class BaseImageType {
70 kSDR,
71 kHDR,
72 };
74
75 /**
76 * If specified, color space to apply the gainmap in, otherwise the base image's color space
77 * is used. Only the color primaries are used, the transfer function is irrelevant.
78 */
80
91 inline bool operator!=(const SkGainmapInfo& other) const { return !(*this == other); }
92
93 // TODO(ccameron): Remove these parameters once we are certain they are not used in Android.
94 enum class Type {
96 };
98};
99
100#endif
static bool Equals(const SkColorSpace *, const SkColorSpace *)
T * get() const
Definition SkRefCnt.h:303
bool operator!=(const SkGainmapInfo &other) const
SkColor4f fGainmapRatioMax
SkColor4f fEpsilonSdr
SkColor4f fGainmapGamma
sk_sp< SkColorSpace > fGainmapMathColorSpace
SkColor4f fGainmapRatioMin
BaseImageType fBaseImageType
float fDisplayRatioSdr
bool operator==(const SkGainmapInfo &other) const
SkColor4f fEpsilonHdr
float fDisplayRatioHdr