23constexpr uint8_t kIsMultiChannelMask = (1u << 7);
24constexpr uint8_t kUseBaseColourSpaceMask = (1u << 6);
29 uint32_t denominator = 0x10000000;
33 int32_t numerator =
static_cast<int32_t
>(std::llround(
static_cast<double>(
x) * denominator));
40 uint32_t denominator = 0x10000000;
44 uint32_t numerator =
static_cast<uint32_t
>(std::llround(
static_cast<double>(
x) * denominator));
74 int32_t numerator = 0;
75 uint32_t denominator = 0;
82 *
value =
static_cast<float>(
static_cast<double>(numerator) /
static_cast<double>(denominator));
87 uint32_t numerator = 0;
88 uint32_t denominator = 0;
95 *
value =
static_cast<float>(
static_cast<double>(numerator) /
static_cast<double>(denominator));
101 uint16_t minimum_version = 0;
103 SkCodecPrintf(
"Failed to read ISO 21496-1 minimum version.\n");
106 if (minimum_version != 0) {
112 uint16_t writer_version = 0;
132 bool isMultiChannel = (
flags & kIsMultiChannelMask) != 0;
133 bool useBaseColourSpace = (
flags & kUseBaseColourSpaceMask) != 0;
135 float baseHdrHeadroom = 0.f;
137 SkCodecPrintf(
"Failed to read ISO 21496-1 base HDR headroom.\n");
140 float altrHdrHeadroom = 0.f;
142 SkCodecPrintf(
"Failed to read ISO 21496-1 altr HDR headroom.\n");
146 float gainMapMin[3] = {0.f};
147 float gainMapMax[3] = {0.f};
148 float gamma[3] = {0.f};
149 float baseOffset[3] = {0.f};
150 float altrOffset[3] = {0.f};
152 int channelCount = isMultiChannel ? 3 : 1;
153 for (
int i = 0;
i < channelCount; ++
i) {
155 SkCodecPrintf(
"Failed to read ISO 21496-1 gainmap minimum.\n");
159 SkCodecPrintf(
"Failed to read ISO 21496-1 gainmap maximum.\n");
177 if (!useBaseColourSpace) {
180 if (baseHdrHeadroom < altrHdrHeadroom) {
182 info.fDisplayRatioSdr = std::exp2(baseHdrHeadroom);
183 info.fDisplayRatioHdr = std::exp2(altrHdrHeadroom);
186 info.fDisplayRatioHdr = std::exp2(baseHdrHeadroom);
187 info.fDisplayRatioSdr = std::exp2(altrHdrHeadroom);
189 for (
int i = 0;
i < 3; ++
i) {
190 int j =
i >= channelCount ? 0 :
i;
191 info.fGainmapRatioMin[
i] = std::exp2(gainMapMin[j]);
192 info.fGainmapRatioMax[
i] = std::exp2(gainMapMax[j]);
193 info.fGainmapGamma[
i] = 1.f / gamma[j];
194 switch (
info.fBaseImageType) {
196 info.fEpsilonSdr[
i] = baseOffset[j];
197 info.fEpsilonHdr[
i] = altrOffset[j];
200 info.fEpsilonHdr[
i] = baseOffset[j];
201 info.fEpsilonSdr[
i] = altrOffset[j];
241 return s.detachAsData();
259 flags |= kUseBaseColourSpaceMask;
261 if (!all_single_channel) {
262 flags |= kIsMultiChannelMask;
279 for (
int i = 0;
i < (all_single_channel ? 1 : 3); ++
i) {
294 return s.detachAsData();
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
#define SkCodecPrintf(...)
#define SkEndian_SwapBE32(n)
#define SkEndian_SwapBE16(n)
static bool read_u32_be(SkStream *s, uint32_t *value)
static bool read_rational_be(SkStream *s, float *value)
static bool is_single_channel(SkColor4f c)
static void write_positive_rational_be(SkDynamicMemoryWStream &s, float x)
static bool read_u16_be(SkStream *s, uint16_t *value)
static bool read_positive_rational_be(SkStream *s, float *value)
static bool read_iso_gainmap_info(SkStream *s, SkGainmapInfo &info)
static bool read_iso_gainmap_version(SkStream *s)
static bool read_s32_be(SkStream *s, int32_t *value)
static void write_rational_be(SkDynamicMemoryWStream &s, float x)
bool SkWStreamWriteU32BE(SkWStream *s, uint32_t value)
bool SkWStreamWriteS32BE(SkWStream *s, int32_t value)
bool SkWStreamWriteU16BE(SkWStream *s, uint16_t value)
static sk_sp< SkColorSpace > MakeSRGB()
static std::unique_ptr< SkMemoryStream > MakeDirect(const void *data, size_t length)
FlutterSemanticsFlag flags
SIN Vec< N, float > abs(const Vec< N, float > &x)
SkColor4f fGainmapRatioMax
bool isUltraHDRv1Compatible() const
sk_sp< SkData > serialize() const
static bool ParseVersion(const SkData *data)
sk_sp< SkColorSpace > fGainmapMathColorSpace
SkColor4f fGainmapRatioMin
BaseImageType fBaseImageType
static bool Parse(const SkData *data, SkGainmapInfo &info)
static sk_sp< SkData > SerializeVersion()
std::shared_ptr< const fml::Mapping > data