48static float min(
float r,
float g,
float b) {
return std::min(r, std::min(g,
b)); }
49static float max(
float r,
float g,
float b) {
return std::max(r, std::max(g,
b)); }
51static float sat(
float r,
float g,
float b) {
return max(r,g,
b) -
min(r,g,
b); }
52static float lum(
float r,
float g,
float b) {
return r*0.30f + g*0.59f +
b*0.11f; }
57static void set_sat(
float* r,
float* g,
float*
b,
float s) {
58 float mn =
min(*r,*g,*
b),
60 auto channel = [=](
float c) {
62 : (c - mn) *
s / (mx - mn);
69 float l =
lum(*r,*g,*
b),
72 auto clip = [=](
float c) {
73 if (mn < 0) { c = l + (c - l) * ( l) / (l - mn); }
74 if (mx > 1) { c = l + (c - l) * (1 - l) / (mx - l); }
83static void set_lum(
float* r,
float* g,
float*
b,
float l) {
84 float diff = l -
lum(*r,*g,*
b);
92static void hue(
float dr,
float dg,
float db,
93 float* sr,
float* sg,
float* sb) {
106 float* sr,
float* sg,
float* sb) {
119 float* sr,
float* sg,
float* sb) {
131 float* sr,
float* sg,
float* sb) {
143 void (*mode)(
float,
float,
float,
float*,
float*,
float*)) {
151 mode(
d.fR,
d.fG,
d.fB,
152 &
s.fR, &
s.fG, &
s.fB);
154 return s.toSkColor();
161 const char* comment =
"HSL blend modes are correct when you see no circles in the squares.";
162 canvas->drawString(comment, 10,10, font,
paint);
171 void (*reference)(float,float,float,
float*,
float*,
float*);
181 canvas->drawRect({20,20,80,80}, bg);
184 canvas->drawRect({20,20,80,80}, fg);
186 if (
test.reference) {
189 canvas->drawCircle(50,50, 20, ref);
194 canvas->translate(100,0);
204 0xFF00CCCC, 0xFF0000CC, 0xFFCC00CC, 0xFFCC0000, 0xFFCCCC00, 0xFF00CC00,
217 canvas->translate(10, 50);
218 canvas->scale(0.5f, 0.5f);
235 for (
auto [_,
name] : recs) {
238 canvas->translate(r.
width() + 10, 0);
242 for (
SkScalar src_a : {1.0f, 0.5f}) {
244 for (
auto [mode, _] : recs) {
247 canvas->drawRect(r, p);
249 p.setShader(
nullptr);
250 p.setBlendMode(mode);
254 canvas->translate(r.
width() + 10, 0);
257 str.
printf(
"alpha %g", src_a);
262 canvas->translate(0, r.
height() + 10);
SK_API const char * SkBlendMode_Name(SkBlendMode blendMode)
@ kSaturation
saturation of source with hue and luminosity of destination
@ kHue
hue of source with saturation and luminosity of destination
@ kLuminosity
luminosity of source with hue and saturation of destination
@ kColor
hue and saturation of source with luminosity of destination
#define SkColorGetA(color)
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
@ kAntiAlias
may have transparent pixels on glyph edges
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
void setColor(SkColor color)
void setBlendMode(SkBlendMode mode)
void printf(const char format[],...) SK_PRINTF_LIKE(2
const char * c_str() const
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
static void set_sat(float *r, float *g, float *b, float s)
static SkColor blend(SkColor dst, SkColor src, void(*mode)(float, float, float, float *, float *, float *))
static float sat(float r, float g, float b)
static void luminosity(float dr, float dg, float db, float *sr, float *sg, float *sb)
static void hue(float dr, float dg, float db, float *sr, float *sg, float *sb)
static void saturation(float dr, float dg, float db, float *sr, float *sg, float *sb)
static float max(float r, float g, float b)
static void clip_color(float *r, float *g, float *b)
static sk_sp< SkShader > make_grad(SkScalar width)
static float lum(float r, float g, float b)
static float min(float r, float g, float b)
static void set_lum(float *r, float *g, float *b, float l)
static SkRGBA4f FromColor(SkColor color)
static SkRect MakeIWH(int w, int h)
constexpr float height() const
constexpr float width() const