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.
99 {
102
103
108 if (!dstColorSpace) {
110 }
111
112
115
116
123 } else {
125 }
126 }
127
129 if (baseImageIsHdr) {
131 }
132
133
135 return baseImage->
makeShader(baseSamplingOptions, &baseRectToDstRect);
136 }
137
138
139
140 auto colorXformSdrToGainmap =
142
143
144
145 auto colorXformGainmapToDst =
147
148
149 auto baseImageShader = baseImage->
makeRawShader(baseSamplingOptions, &baseRectToDstRect)
151
152
153 auto gainmapImageShader =
154 gainmapImage->
makeRawShader(gainmapSamplingOptions, &gainmapRectToDstRect);
155
156
158 {
163 1.f});
167 1.f});
168 const int noGamma =
185
187 const float appleG = 1.961f;
189
190 builder.child(
"base") = baseImageShader;
191 builder.child(
"gainmap") = gainmapImageShader;
192 builder.uniform(
"logRatioMin") = logRatioMin;
193 builder.uniform(
"logRatioMax") = logRatioMax;
195 builder.uniform(
"epsilonBase") = epsilonBase;
196 builder.uniform(
"epsilonOther") = epsilonOther;
197 builder.uniform(
"noGamma") = noGamma;
198 builder.uniform(
"singleChannel") = singleChannel;
199 builder.uniform(
"gainmapIsAlpha") = gainmapIsAlpha;
200 builder.uniform(
"gainmapIsRed") = gainmapIsRed;
202
203 builder.uniform(
"isApple") = isApple;
204 builder.uniform(
"appleG") = appleG;
205 builder.uniform(
"appleH") = appleH;
206
207 gainmapMathShader =
builder.makeShader();
209 }
210
211
213}
@ 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