74#ifndef SKOTTIE_ACCURATE_CONTRAST_APPROXIMATION
85static constexpr char CONTRAST_EFFECT[] =
90 "half4 main(half4 color) {"
92 "color.rgb = ((a*color.rgb + b)*color.rgb + c)*color.rgb;"
104 const auto coeff_a = -contrast / (3 *
SK_ScalarPI);
109static constexpr char CONTRAST_EFFECT[] =
112 "half4 main(half4 color) {"
113 "color.rgb += a * sin(color.rgb * 6.283185);"
128static sk_sp<SkData> make_brightness_coeffs(
float brightness) {
129 const float coeff_a = std::pow(2.0f, brightness * 1.8f);
134static constexpr char BRIGHTNESS_EFFECT[] =
137 "half4 main(half4 color) {"
138 "color.rgb = 1 - pow(1 - color.rgb, half3(a));"
143class BrightnessContrastAdapter final :
public DiscardableAdapterBase<BrightnessContrastAdapter,
144 sksg::ExternalColorFilter> {
147 const AnimationBuilder& abuilder,
156 kBrightness_Index = 0,
158 kUseLegacy_Index = 2,
161 EffectBinder(jprops, abuilder,
this)
162 .bind(kBrightness_Index, fBrightness)
163 .bind( kContrast_Index, fContrast )
164 .bind( kUseLegacy_Index, fUseLegacy );
168 void onSync()
override {
170 ? this->makeLegacyCF()
195 const auto brightness =
SkTPin(fBrightness, -100.0f, 100.0f) / 255,
196 contrast =
SkTPin(fContrast , -100.0f, 100.0f) / 100;
202 const auto S = contrast > 0
214 const auto B = 0.5f * (1 -
S) + brightness *
std::max(
S, 1.0f);
227 const auto brightness =
SkTPin(fBrightness, -150.0f, 150.0f) / 150,
228 contrast =
SkTPin(fContrast , -50.0f, 100.0f) / 100;
232 : fBrightnessEffect->
makeColorFilter(make_brightness_coeffs(brightness)),
247 using INHERITED = DiscardableAdapterBase<BrightnessContrastAdapter, sksg::ExternalColorFilter>;
#define INHERITED(method,...)
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
#define SkScalarRoundToInt(x)
#define 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< SkData > MakeWithCopy(const void *data, size_t length)
sk_sp< SkColorFilter > makeColorFilter(sk_sp< const SkData > uniforms) const
void attachDiscardableAdapter(sk_sp< T > adapter) const
static float max(float r, float g, float b)
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)