27 "uniform shader base;"
28 "uniform shader gainmap;"
29 "uniform half4 logRatioMin;"
30 "uniform half4 logRatioMax;"
31 "uniform half4 gainmapGamma;"
32 "uniform half4 epsilonBase;"
33 "uniform half4 epsilonOther;"
35 "uniform int gainmapIsAlpha;"
36 "uniform int gainmapIsRed;"
37 "uniform int singleChannel;"
38 "uniform int noGamma;"
39 "uniform int isApple;"
40 "uniform half appleG;"
41 "uniform half appleH;"
43 "half4 main(float2 coord) {"
44 "half4 S = base.eval(coord);"
45 "half4 G = gainmap.eval(coord);"
46 "if (gainmapIsAlpha == 1) {"
47 "G = half4(G.a, G.a, G.a, 1.0);"
49 "if (gainmapIsRed == 1) {"
50 "G = half4(G.r, G.r, G.r, 1.0);"
52 "if (singleChannel == 1) {"
55 "L = pow(G.r, appleG);"
56 "L = log(1.0 + (appleH - 1.0) * pow(G.r, appleG));"
57 "} else if (noGamma == 1) {"
58 "L = mix(logRatioMin.r, logRatioMax.r, G.r);"
60 "L = mix(logRatioMin.r, logRatioMax.r, pow(G.r, gainmapGamma.r));"
62 "half3 H = (S.rgb + epsilonBase.rgb) * exp(L * W) - epsilonOther.rgb;"
63 "return half4(H.r, H.g, H.b, S.a);"
67 "L = pow(G.rgb, half3(appleG));"
68 "L = log(half3(1.0) + (appleH - 1.0) * L);"
69 "} else if (noGamma == 1) {"
70 "L = mix(logRatioMin.rgb, logRatioMax.rgb, G.rgb);"
72 "L = mix(logRatioMin.rgb, logRatioMax.rgb, pow(G.rgb, gainmapGamma.rgb));"
74 "half3 H = (S.rgb + epsilonBase.rgb) * exp(L * W) - epsilonOther.rgb;"
75 "return half4(H.r, H.g, H.b, S.a);"
87 return c.fR == c.fG && c.fR == c.fB;
108 if (!dstColorSpace) {
129 if (baseImageIsHdr) {
135 return baseImage->
makeShader(baseSamplingOptions, &baseRectToDstRect);
140 auto colorXformSdrToGainmap =
145 auto colorXformGainmapToDst =
149 auto baseImageShader = baseImage->
makeRawShader(baseSamplingOptions, &baseRectToDstRect)
153 auto gainmapImageShader =
154 gainmapImage->
makeRawShader(gainmapSamplingOptions, &gainmapRectToDstRect);
187 const float appleG = 1.961f;
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;
203 builder.uniform(
"isApple") = isApple;
204 builder.uniform(
"appleG") = appleG;
205 builder.uniform(
"appleH") = appleH;
207 gainmapMathShader =
builder.makeShader();
@ kRed_SkColorChannelFlag
@ kAlpha_SkColorChannelFlag
@ kGray_SkColorChannelFlag
static constexpr char gGainmapSKSL[]
static bool all_channels_equal(const SkColor4f &c)
static sk_sp< SkRuntimeEffect > gainmap_apply_effect()
static uint32_t SkColorTypeChannelFlags(SkColorType ct)
sk_sp< T > sk_ref_sp(T *obj)
static sk_sp< SkColorFilter > MakeColorSpaceXform(sk_sp< SkColorSpace > src, sk_sp< SkColorSpace > dst)
sk_sp< SkColorSpace > makeLinearGamma() const
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkShader > Make(const sk_sp< const SkImage > &baseImage, const SkRect &baseRect, const SkSamplingOptions &baseSamplingOptions, const sk_sp< const SkImage > &gainmapImage, const SkRect &gainmapRect, const SkSamplingOptions &gainmapSamplingOptions, const SkGainmapInfo &gainmapInfo, const SkRect &dstRect, float dstHdrRatio, sk_sp< SkColorSpace > dstColorSpace)
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)
static Result MakeForShader(SkString sksl, const Options &)
sk_sp< SkShader > makeWithColorFilter(sk_sp< SkColorFilter >) const
SkColor4f fGainmapRatioMax
sk_sp< SkColorSpace > fGainmapMathColorSpace
SkColor4f fGainmapRatioMin
BaseImageType fBaseImageType