Make a gainmap shader.
When sampling the base image baseImage, the rectangle baseRect will be sampled to map to the rectangle dstRect. Sampling will be done according to baseSamplingOptions.
When sampling the gainmap image gainmapImage, the rectangle gainmapRect will be sampled to map to the rectangle dstRect. Sampling will be done according to gainmapSamplingOptions.
The gainmap will be applied according to the HDR to SDR ratio specified in dstHdrRatio.
This shader must know the color space of the canvas that it will be rendered to. This color space must be specified in dstColorSpace. TODO(ccameron): Remove the need for dstColorSpace.
90 {
93
94
98 : baseColorSpace->makeLinearGamma();
99 if (!dstColorSpace) {
101 }
102
103
106
107
114 } else {
116 }
117 }
118
120 if (baseImageIsHdr) {
122 }
123
124
126 return baseImage->
makeShader(baseSamplingOptions, &baseRectToDstRect);
127 }
128
129
130
131 auto colorXformSdrToGainmap =
133
134
135
136 auto colorXformGainmapToDst =
138
139
140 auto baseImageShader = baseImage->
makeRawShader(baseSamplingOptions, &baseRectToDstRect)
142
143
144 auto gainmapImageShader =
145 gainmapImage->
makeRawShader(gainmapSamplingOptions, &gainmapRectToDstRect);
146
147
149 {
154 1.f});
158 1.f});
159 const int noGamma =
176 builder.child(
"base") = baseImageShader;
177 builder.child(
"gainmap") = gainmapImageShader;
178 builder.uniform(
"logRatioMin") = logRatioMin;
179 builder.uniform(
"logRatioMax") = logRatioMax;
181 builder.uniform(
"epsilonBase") = epsilonBase;
182 builder.uniform(
"epsilonOther") = epsilonOther;
183 builder.uniform(
"noGamma") = noGamma;
184 builder.uniform(
"singleChannel") = singleChannel;
185 builder.uniform(
"gainmapIsAlpha") = gainmapIsAlpha;
186 builder.uniform(
"gainmapIsRed") = gainmapIsRed;
188 gainmapMathShader =
builder.makeShader();
190 }
191
192
193 return gainmapMathShader->makeWithColorFilter(colorXformGainmapToDst);
194}
@ kRed_SkColorChannelFlag
@ kAlpha_SkColorChannelFlag
@ kGray_SkColorChannelFlag
static bool all_channels_equal(const SkColor4f &c)
static sk_sp< SkRuntimeEffect > gainmap_apply_effect()
static uint32_t SkColorTypeChannelFlags(SkColorType ct)
static sk_sp< SkColorFilter > MakeColorSpaceXform(sk_sp< SkColorSpace > src, sk_sp< SkColorSpace > dst)
sk_sp< SkColorSpace > makeLinearGamma() const
static sk_sp< SkColorSpace > MakeSRGB()
SkColorSpace * colorSpace() const
sk_sp< SkShader > makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
SkColorType colorType() const
sk_sp< SkColorSpace > refColorSpace() const
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
sk_sp< SkShader > makeWithColorFilter(sk_sp< SkColorFilter >) const
SkColor4f fGainmapRatioMax
sk_sp< SkColorSpace > fGainmapMathColorSpace
SkColor4f fGainmapRatioMin
BaseImageType fBaseImageType