Add gm to test HSL modes, esp. with src-alpha
Note: the results (esp. Saturation) don't exactly match the reference images in the W3 spec. However, if I tell viewer to be in P3 colorspace, then the gm looks (nearly) identical to florin's codepen (when viewed on a P3 iMac). Change-Id: Iecf21b3078f079eb30af59d697b97b64091c585c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/278416 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
7e9d6f43c1
commit
bd1db41bd8
69
gm/hsl.cpp
69
gm/hsl.cpp
@ -13,6 +13,7 @@
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/core/SkTypeface.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "tools/Resources.h"
|
||||
#include "tools/ToolUtils.h"
|
||||
|
||||
// Hue, Saturation, Color, and Luminosity blend modes are oddballs.
|
||||
@ -191,3 +192,71 @@ DEF_SIMPLE_GM(hsl, canvas, 600, 100) {
|
||||
canvas->translate(100,0);
|
||||
}
|
||||
}
|
||||
|
||||
#include "include/effects/SkGradientShader.h"
|
||||
|
||||
// Trying to match sample images on https://www.w3.org/TR/compositing-1/#blendingnonseparable
|
||||
//
|
||||
static sk_sp<SkShader> make_grad(SkScalar width) {
|
||||
SkColor colors[] = {
|
||||
0xFF00CCCC, 0xFF0000CC, 0xFFCC00CC, 0xFFCC0000, 0xFFCCCC00, 0xFF00CC00,
|
||||
};
|
||||
SkPoint pts[] = {{0, 0}, {width, 0}};
|
||||
|
||||
return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
|
||||
SkTileMode::kClamp);
|
||||
}
|
||||
|
||||
DEF_SIMPLE_GM(HSL_duck, canvas, 1110, 620) {
|
||||
auto src = GetResourceAsImage("ducky.png");
|
||||
auto dst = make_grad(src->width());
|
||||
SkRect r = SkRect::MakeIWH(src->width(), src->height());
|
||||
|
||||
canvas->translate(10, 50);
|
||||
canvas->scale(0.5f, 0.5f);
|
||||
|
||||
const struct {
|
||||
SkBlendMode fMode;
|
||||
const char* fName;
|
||||
} recs[] = {
|
||||
{ SkBlendMode::kHue, "Hue" },
|
||||
{ SkBlendMode::kSaturation, "Saturation" },
|
||||
{ SkBlendMode::kColor, "Color" },
|
||||
{ SkBlendMode::kLuminosity, "Luminosity" },
|
||||
};
|
||||
|
||||
SkFont font;
|
||||
font.setSize(40);
|
||||
font.setEdging(SkFont::Edging::kAntiAlias);
|
||||
|
||||
canvas->save();
|
||||
for (auto [_, name] : recs) {
|
||||
canvas->drawSimpleText(name, strlen(name), SkTextEncoding::kUTF8, 150, -20,
|
||||
font, SkPaint());
|
||||
canvas->translate(r.width() + 10, 0);
|
||||
}
|
||||
canvas->restore();
|
||||
|
||||
for (SkScalar src_a : {1.0f, 0.5f}) {
|
||||
canvas->save();
|
||||
for (auto [mode, _] : recs) {
|
||||
SkPaint p;
|
||||
p.setShader(dst);
|
||||
canvas->drawRect(r, p); // bg
|
||||
|
||||
p.setShader(nullptr);
|
||||
p.setBlendMode(mode);
|
||||
p.setAlphaf(src_a);
|
||||
canvas->drawImageRect(src, r, &p);
|
||||
|
||||
canvas->translate(r.width() + 10, 0);
|
||||
}
|
||||
SkString str;
|
||||
str.printf("alpha %g", src_a);
|
||||
canvas->drawSimpleText(str.c_str(), str.size(), SkTextEncoding::kUTF8, 10, r.height()/2,
|
||||
font, SkPaint());
|
||||
|
||||
canvas->restore();
|
||||
canvas->translate(0, r.height() + 10);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user