52static constexpr char gSaturateSkSL[] =
53"uniform half u_scale;"
55"half4 main(half4 c) {"
57 "half2 rg_srt = (c.r < c.g) ? c.rg : c.gr;"
58 "half c_min = min(rg_srt.x, c.b),"
59 "c_max = max(rg_srt.y, c.b),"
62 "ch = max(c_max - c_min, 0.0001),"
63 "ch_mid = (c_min + c_max)*0.5,"
66 "scale_max = min(ch_mid, c.a - ch_mid)/ch*2,"
67 "scale = min(u_scale, scale_max);"
70 "c.rgb = ch_mid + (c.rgb - ch_mid)*scale;"
76 static const auto* effect =
83class HueSaturationEffectAdapter final :
public AnimatablePropertyContainer {
87 const AnimationBuilder* abuilder) {
90 new HueSaturationEffectAdapter(jprops, std::move(layer), abuilder));
98 const AnimationBuilder* abuilder)
99 : fColorFilter(
sksg::ExternalColorFilter::
Make(
std::move(layer))) {
101 kChannelControl_Index = 0,
102 kChannelRange_Index = 1,
103 kMasterHue_Index = 2,
104 kMasterSat_Index = 3,
105 kMasterLightness_Index = 4,
107 kColorizeHue_Index = 6,
108 kColorizeSat_Index = 7,
109 kColorizeLightness_Index = 8,
112 EffectBinder(jprops, *abuilder,
this)
113 .bind( kChannelControl_Index, fChanCtrl )
114 .bind( kMasterHue_Index, fMasterHue )
115 .bind( kMasterSat_Index, fMasterSat )
116 .bind(kMasterLightness_Index, fMasterLight);
121 void onSync()
override {
122 fColorFilter->setColorFilter(this->makeColorFilter());
129 kYellows_Chan = 0x03,
133 kMagentas_Chan = 0x07,
137 if (
static_cast<int>(fChanCtrl) != kMaster_Chan) {
145 const auto h = fMasterHue/360;
147 const float cm[20] = {
159 static constexpr auto kMaxScale = 126.0f;
164 const auto s =
SkTPin(fMasterSat/100, -1.0f, 1.0f),
165 chroma_scale =
s < 0 ?
s + 1 :
std::min(1/(1 -
s), kMaxScale);
177 const auto l =
SkTPin(fMasterLight/100, -1.0f, 1.0f),
179 lo = l < 0 ? 0 : 1 - ls;
181 const float cm[20] = {
196 float fChanCtrl = 0.0f,
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
static sk_sp< SkColorFilter > Compose(const sk_sp< SkColorFilter > &outer, sk_sp< SkColorFilter > inner)
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
static sk_sp< SkColorFilter > HSLAMatrix(const SkColorMatrix &)
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
static Result MakeForColorFilter(SkString sksl, const Options &)
void attachDiscardableAdapter(sk_sp< T > adapter) const
static float min(float r, float g, float b)
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
SIN Vec< N, float > abs(const Vec< N, float > &x)