Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
SkGainmapInfo Struct Reference

#include <SkGainmapInfo.h>

Public Types

enum class  BaseImageType { kSDR , kHDR }
 
enum class  Type { kDefault , kApple }
 

Public Member Functions

bool isUltraHDRv1Compatible () const
 
sk_sp< SkDataserialize () const
 
bool operator== (const SkGainmapInfo &other) const
 
bool operator!= (const SkGainmapInfo &other) const
 

Static Public Member Functions

static bool ParseVersion (const SkData *data)
 
static bool Parse (const SkData *data, SkGainmapInfo &info)
 
static sk_sp< SkDataSerializeVersion ()
 

Public Attributes

SkColor4f fGainmapRatioMin = {1.f, 1.f, 1.f, 1.0}
 
SkColor4f fGainmapRatioMax = {2.f, 2.f, 2.f, 1.0}
 
SkColor4f fGainmapGamma = {1.f, 1.f, 1.f, 1.f}
 
SkColor4f fEpsilonSdr = {0.f, 0.f, 0.f, 1.0}
 
SkColor4f fEpsilonHdr = {0.f, 0.f, 0.f, 1.0}
 
float fDisplayRatioSdr = 1.f
 
float fDisplayRatioHdr = 2.f
 
BaseImageType fBaseImageType = BaseImageType::kSDR
 
Type fType = Type::kDefault
 
sk_sp< SkColorSpacefGainmapMathColorSpace = nullptr
 

Detailed Description

Gainmap rendering parameters. Suppose our display has HDR to SDR ratio of H and we wish to display an image with gainmap on this display. Let B be the pixel value from the base image in a color space that has the primaries of the base image and a linear transfer function. Let G be the pixel value from the gainmap. Let D be the output pixel in the same color space as B. The value of D is computed as follows:

First, let W be a weight parameter determing how much the gainmap will be applied. W = clamp((log(H) - log(fDisplayRatioSdr)) / (log(fDisplayRatioHdr) - log(fDisplayRatioSdr), 0, 1)

Next, let L be the gainmap value in log space. We compute this from the value G that was sampled from the texture as follows: L = mix(log(fGainmapRatioMin), log(fGainmapRatioMax), pow(G, fGainmapGamma))

Finally, apply the gainmap to compute D, the displayed pixel. If the base image is SDR then compute: D = (B + fEpsilonSdr) * exp(L * W) - fEpsilonHdr If the base image is HDR then compute: D = (B + fEpsilonHdr) * exp(L * (W - 1)) - fEpsilonSdr

In the above math, log() is a natural logarithm and exp() is natural exponentiation. Note, however, that the base used for the log() and exp() functions does not affect the results of the computation (it cancels out, as long as the same base is used throughout).

This product includes Gain Map technology under license by Adobe.

Definition at line 43 of file SkGainmapInfo.h.

Member Enumeration Documentation

◆ BaseImageType

enum class SkGainmapInfo::BaseImageType
strong

Whether the base image is the SDR image or the HDR image.

Enumerator
kSDR 
kHDR 

Definition at line 71 of file SkGainmapInfo.h.

71 {
72 kSDR,
73 kHDR,
74 };

◆ Type

enum class SkGainmapInfo::Type
strong

The type of the gainmap image. If the type is kApple, then the gainmap image was originally encoded according to the specification at [0], and can be converted to the kDefault type by applying the transformation described at [1]. [0] https://developer.apple.com/documentation/appkit/images_and_pdf/ applying_apple_hdr_effect_to_your_photos [1] https://docs.google.com/document/d/1iUpYAThVV_FuDdeiO3t0vnlfoA1ryq0WfGS9FuydwKc

Enumerator
kDefault 
kApple 

Definition at line 85 of file SkGainmapInfo.h.

85 {
87 kApple,
88 };
@ kDefault

Member Function Documentation

◆ isUltraHDRv1Compatible()

bool SkGainmapInfo::isUltraHDRv1Compatible ( ) const

Return true if this can be encoded as an UltraHDR v1 image.

Definition at line 208 of file SkGainmapInfo.cpp.

208 {
209 // UltraHDR v1 supports having the base image be HDR in theory, but it is largely
210 // untested.
212 return false;
213 }
214 // UltraHDR v1 doesn't support a non-base gainmap math color space.
216 return false;
217 }
218 return true;
219}
sk_sp< SkColorSpace > fGainmapMathColorSpace
Definition: SkGainmapInfo.h:95
BaseImageType fBaseImageType
Definition: SkGainmapInfo.h:75

◆ operator!=()

bool SkGainmapInfo::operator!= ( const SkGainmapInfo other) const
inline

Definition at line 137 of file SkGainmapInfo.h.

137{ return !(*this == other); }

◆ operator==()

bool SkGainmapInfo::operator== ( const SkGainmapInfo other) const
inline

Definition at line 127 of file SkGainmapInfo.h.

127 {
128 return fGainmapRatioMin == other.fGainmapRatioMin &&
130 fEpsilonSdr == other.fEpsilonSdr && fEpsilonHdr == other.fEpsilonHdr &&
133 fBaseImageType == other.fBaseImageType && fType == other.fType &&
136 }
static bool Equals(const SkColorSpace *, const SkColorSpace *)
T * get() const
Definition: SkRefCnt.h:303
SkColor4f fGainmapRatioMax
Definition: SkGainmapInfo.h:49
SkColor4f fEpsilonSdr
Definition: SkGainmapInfo.h:55
SkColor4f fGainmapGamma
Definition: SkGainmapInfo.h:50
SkColor4f fGainmapRatioMin
Definition: SkGainmapInfo.h:48
float fDisplayRatioSdr
Definition: SkGainmapInfo.h:65
SkColor4f fEpsilonHdr
Definition: SkGainmapInfo.h:56
float fDisplayRatioHdr
Definition: SkGainmapInfo.h:66

◆ Parse()

bool SkGainmapInfo::Parse ( const SkData data,
SkGainmapInfo info 
)
static

If |data| constains ISO 21496-1 metadata then parse that metadata then use it to populate |info| and return true, otherwise return false. If |data| indicates that that the base image color space primaries should be used for gainmap application then set |fGainmapMathColorSpace| to nullptr, otherwise set |fGainmapMathColorSpace| to sRGB (the default, to be overwritten by the image decoder).

Definition at line 229 of file SkGainmapInfo.cpp.

229 {
230 if (!data) {
231 return false;
232 }
233 auto s = SkMemoryStream::MakeDirect(data->data(), data->size());
234 return read_iso_gainmap_info(s.get(), info);
235}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static bool read_iso_gainmap_info(SkStream *s, SkGainmapInfo &info)
static std::unique_ptr< SkMemoryStream > MakeDirect(const void *data, size_t length)
Definition: SkStream.cpp:310
struct MyStruct s
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ ParseVersion()

bool SkGainmapInfo::ParseVersion ( const SkData data)
static

If |data| contains an ISO 21496-1 version that is supported, return true. Otherwise return false.

Definition at line 221 of file SkGainmapInfo.cpp.

221 {
222 if (!data) {
223 return false;
224 }
225 auto s = SkMemoryStream::MakeDirect(data->data(), data->size());
226 return read_iso_gainmap_version(s.get());
227}
static bool read_iso_gainmap_version(SkStream *s)

◆ serialize()

sk_sp< SkData > SkGainmapInfo::serialize ( ) const

Serialize an ISO 21496-1 version 0 blob containing this' gainmap parameters.

Definition at line 246 of file SkGainmapInfo.cpp.

246 {
248 // Version.
249 SkWStreamWriteU16BE(&s, 0); // Minimum reader version
250 SkWStreamWriteU16BE(&s, 0); // Writer version
251
252 // Flags.
253 bool all_single_channel = is_single_channel(fGainmapRatioMin) &&
257 uint8_t flags = 0;
259 flags |= kUseBaseColourSpaceMask;
260 }
261 if (!all_single_channel) {
262 flags |= kIsMultiChannelMask;
263 }
264 s.write8(flags);
265
266 // Base and altr headroom.
267 switch (fBaseImageType) {
271 break;
275 break;
276 }
277
278 // Per-channel information.
279 for (int i = 0; i < (all_single_channel ? 1 : 3); ++i) {
283 switch (fBaseImageType) {
287 break;
291 break;
292 }
293 }
294 return s.detachAsData();
295}
static bool is_single_channel(SkColor4f c)
static void write_positive_rational_be(SkDynamicMemoryWStream &s, float x)
static void write_rational_be(SkDynamicMemoryWStream &s, float x)
bool SkWStreamWriteU16BE(SkWStream *s, uint16_t value)
Definition: SkStreamPriv.h:49
FlutterSemanticsFlag flags

◆ SerializeVersion()

sk_sp< SkData > SkGainmapInfo::SerializeVersion ( )
static

Serialize an ISO 21496-1 version 0 blob containing only the version structure.

Definition at line 237 of file SkGainmapInfo.cpp.

237 {
239 SkWStreamWriteU16BE(&s, 0); // Minimum reader version
240 SkWStreamWriteU16BE(&s, 0); // Writer version
241 return s.detachAsData();
242}

Member Data Documentation

◆ fBaseImageType

BaseImageType SkGainmapInfo::fBaseImageType = BaseImageType::kSDR

Definition at line 75 of file SkGainmapInfo.h.

◆ fDisplayRatioHdr

float SkGainmapInfo::fDisplayRatioHdr = 2.f

Definition at line 66 of file SkGainmapInfo.h.

◆ fDisplayRatioSdr

float SkGainmapInfo::fDisplayRatioSdr = 1.f

If the output display's HDR to SDR ratio is less or equal than fDisplayRatioSdr then the SDR rendition is displayed. If the output display's HDR to SDR ratio is greater or equal than fDisplayRatioHdr then the HDR rendition is displayed. If the output display's HDR to SDR ratio is between these values then an interpolation between the two is displayed using the math above.

Definition at line 65 of file SkGainmapInfo.h.

◆ fEpsilonHdr

SkColor4f SkGainmapInfo::fEpsilonHdr = {0.f, 0.f, 0.f, 1.0}

Definition at line 56 of file SkGainmapInfo.h.

◆ fEpsilonSdr

SkColor4f SkGainmapInfo::fEpsilonSdr = {0.f, 0.f, 0.f, 1.0}

Parameters sometimes used in gainmap computation to avoid numerical instability.

Definition at line 55 of file SkGainmapInfo.h.

◆ fGainmapGamma

SkColor4f SkGainmapInfo::fGainmapGamma = {1.f, 1.f, 1.f, 1.f}

Definition at line 50 of file SkGainmapInfo.h.

◆ fGainmapMathColorSpace

sk_sp<SkColorSpace> SkGainmapInfo::fGainmapMathColorSpace = nullptr

If specified, color space to apply the gainmap in, otherwise the base image's color space is used. Only the color primaries are used, the transfer function is irrelevant.

Definition at line 95 of file SkGainmapInfo.h.

◆ fGainmapRatioMax

SkColor4f SkGainmapInfo::fGainmapRatioMax = {2.f, 2.f, 2.f, 1.0}

Definition at line 49 of file SkGainmapInfo.h.

◆ fGainmapRatioMin

SkColor4f SkGainmapInfo::fGainmapRatioMin = {1.f, 1.f, 1.f, 1.0}

Parameters for converting the gainmap from its image encoding to log space. These are specified per color channel. The alpha value is unused.

Definition at line 48 of file SkGainmapInfo.h.

◆ fType

Type SkGainmapInfo::fType = Type::kDefault

Definition at line 89 of file SkGainmapInfo.h.


The documentation for this struct was generated from the following files: