diff options
author | Mike Klein <mtklein@chromium.org> | 2017-05-05 13:49:00 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-05 19:20:21 +0000 |
commit | 6bfe3f5142bad09b7833ec41a3af692d4ee54919 (patch) | |
tree | 70583f78d45e24fb7fa2c8f69da62df98d893922 /gm/hsl.cpp | |
parent | 2627b0473fc1f77cce4f40157818f39c6e366452 (diff) |
add a new hsl GM
Change-Id: I2c8b9df3e6bf40de4b38966fa8ea671fc68aa45f
Reviewed-on: https://skia-review.googlesource.com/15635
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'gm/hsl.cpp')
-rw-r--r-- | gm/hsl.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/gm/hsl.cpp b/gm/hsl.cpp new file mode 100644 index 0000000000..2ffc0092f3 --- /dev/null +++ b/gm/hsl.cpp @@ -0,0 +1,64 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" +#include "sk_tool_utils.h" + +// Hue, Saturation, Color, and Luminosity blend modes are oddballs. +// They nominally convert their inputs to unpremul, then to HSL, then +// mix-and-match H,S,and L from Src and Dst, then convert back, then premul. +// +// Each mode's name describes the Src H,S,L components to keep, taking the +// others from Dst, where Color == Hue + Saturation. Color and Luminosity +// are each other's complements; Hue and Saturation have no complement. +// +// We have had many inconsistent implementations of these modes. +// This GM tries to demonstrate unambigously how they should work. +// +// TODO: double- and triple-check expected colors +// TODO: how does gamma-correction factor into this? + +DEF_SIMPLE_GM(hsl, canvas, 600, 100) { + SkPaint label; + sk_tool_utils::set_portable_typeface(&label); + label.setAntiAlias(true); + + const char* comment = "HSL blend modes are correct when you see no circles in the squares."; + canvas->drawText(comment, strlen(comment), 10,10, label); + + // Just to keep things reaaaal simple, we'll only use opaque colors. + SkPaint bg, fg; + bg.setColor(0xff00ff00); // Fully-saturated bright green, H = 120°, S = 100%, L = 50%. + fg.setColor(0xff7f3f7f); // Partly-saturated dim magenta, H = 300°, S = ~33%, L = ~37%. + + struct { + SkBlendMode mode; + SkColor expected; + } tests[] = { + { SkBlendMode::kSrc, fg.getColor() }, + { SkBlendMode::kDst, bg.getColor() }, + { SkBlendMode::kHue, 0xffff00ff }, // bright magenta, H = 300°, S = 100%, L = 50% + { SkBlendMode::kSaturation, 0xff55aa55 }, // a duller green, H = 120°, S = ~33%, L = 50% + { SkBlendMode::kColor, 0xffaa55aa }, // a lighter fg, H = 300°, S = ~33%, L = 50% + { SkBlendMode::kLuminosity, 0xff00bd00 }, // a darker bg, H = 120°, S = 100%, L = ~37% + }; + for (auto test : tests) { + canvas->drawRect({20,20,80,80}, bg); + + fg.setBlendMode(test.mode); + canvas->drawRect({20,20,80,80}, fg); + + SkPaint expected; + expected.setColor(test.expected); + canvas->drawCircle(50,50, 20, expected); + + const char* name = SkBlendMode_Name(test.mode); + canvas->drawText(name, strlen(name), 20,90, label); + + canvas->translate(100,0); + } +} |