Make SkColor4f <-> SkColor skip sRGB conversion
This lets us remove the old S32 functions, and fix a couple bugs.
I think this is a good first step to using SkColor4f for paint colors.
Bug: skia:
Change-Id: I0337c2b6db29b73c2f682f85b9cf68c985de7cce
Reviewed-on: https://skia-review.googlesource.com/147205
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/gm/colorspacexform.cpp b/gm/colorspacexform.cpp
deleted file mode 100644
index 72ea4ce..0000000
--- a/gm/colorspacexform.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2016 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 "SkColor.h"
-#include "SkColorSpaceXform.h"
-#include "SkRect.h"
-#include "SkShader.h"
-
-class ColorSpaceXformGM : public skiagm::GM {
-public:
- ColorSpaceXformGM() {}
-
-protected:
- void onOnceBeforeDraw() override {
- SkColor colors[] = {
- SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW,
- SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorMAGENTA,
- };
- static_assert(kNumColors == SK_ARRAY_COUNT(colors), "Fix number of colors.");
-
- for (int i = 0; i < kNumColors; i++) {
- fSRGBColors[i] = SkColor4f::FromColor(colors[i]);
- }
-
- static constexpr float kWideGamutRGB_toXYZD50[]{
- 0.7161046f, 0.1009296f, 0.1471858f,
- 0.2581874f, 0.7249378f, 0.0168748f,
- 0.0000000f, 0.0517813f, 0.7734287f,
- };
-
- SkMatrix44 wideGamut(SkMatrix44::kUninitialized_Constructor);
- wideGamut.set3x3RowMajorf(kWideGamutRGB_toXYZD50);
-
- // Test BGRA input.
- sk_sp<SkColorSpace> srcSpace = SkColorSpace::MakeSRGB();
- sk_sp<SkColorSpace> dstSpace =
- SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, wideGamut);
- std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace.get(),
- dstSpace.get());
- xform->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, fWideGamutColors0,
- SkColorSpaceXform::kBGRA_8888_ColorFormat, colors, kNumColors,
- kOpaque_SkAlphaType);
-
- // Test F32 input.
- srcSpace = srcSpace->makeLinearGamma();
- xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get());
- xform->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, fWideGamutColors1,
- SkColorSpaceXform::kRGBA_F32_ColorFormat, fSRGBColors, kNumColors,
- kOpaque_SkAlphaType);
- }
-
- SkString onShortName() override {
- return SkString("colorspacexform");
- }
-
- SkISize onISize() override {
- return SkISize::Make(500, 300);
- }
-
- void onDraw(SkCanvas* canvas) override {
- auto drawColors = [canvas](SkColor4f* colors) {
- SkRect r = SkRect::MakeXYWH(0.0f, 0.0f, 50.0f, 100.0f);
-
- canvas->save();
- for (int i = 0; i < kNumColors; i++) {
- auto space = SkColorSpace::MakeSRGBLinear();
- sk_sp<SkShader> s = SkShader::MakeColorShader(colors[i], space);
- SkPaint paint;
- paint.setShader(s);
- canvas->drawRect(r, paint);
- canvas->translate(50.0f, 0.0f);
- }
- canvas->restore();
- };
-
- // Wide gamut colors should appear darker - we are simulating a more intense display.
- drawColors(fSRGBColors);
- canvas->translate(0.0f, 100.0f);
- drawColors(fWideGamutColors0);
- canvas->translate(0.0f, 100.0f);
- drawColors(fWideGamutColors1);
- }
-
-private:
- static constexpr int kNumColors = 10;
-
- SkColor4f fSRGBColors[kNumColors];
- SkColor4f fWideGamutColors0[kNumColors];
- SkColor4f fWideGamutColors1[kNumColors];
-
- typedef skiagm::GM INHERITED;
-};
-
-DEF_GM(return new ColorSpaceXformGM;)
diff --git a/gm/encode-srgb.cpp b/gm/encode-srgb.cpp
index 6993642..2538e6e 100644
--- a/gm/encode-srgb.cpp
+++ b/gm/encode-srgb.cpp
@@ -16,7 +16,6 @@
#include "SkJpegEncoder.h"
#include "SkPngEncoder.h"
#include "SkPM4f.h"
-#include "SkSRGB.h"
#include "SkWebpEncoder.h"
namespace skiagm {
diff --git a/gm/hsl.cpp b/gm/hsl.cpp
index 39074e2..a4c9657 100644
--- a/gm/hsl.cpp
+++ b/gm/hsl.cpp
@@ -130,35 +130,17 @@
}
static SkColor blend(SkColor dst, SkColor src,
- void (*mode)(float,float,float, float*,float*,float*),
- bool legacy) {
+ void (*mode)(float,float,float, float*,float*,float*)) {
SkASSERT(SkColorGetA(dst) == 0xff
&& SkColorGetA(src) == 0xff); // Not fundamental, just simplifying for this GM.
- auto to_float = [&](SkColor c) {
- if (legacy) {
- return SkColor4f{
- SkColorGetR(c) * (1/255.0f),
- SkColorGetG(c) * (1/255.0f),
- SkColorGetB(c) * (1/255.0f),
- 1.0f,
- };
- }
- return SkColor4f::FromColor(c);
- };
-
- SkColor4f d = to_float(dst),
- s = to_float(src);
+ SkColor4f d = SkColor4f::FromColor(dst),
+ s = SkColor4f::FromColor(src);
mode( d.fR, d.fG, d.fB,
&s.fR, &s.fG, &s.fB);
- if (legacy) {
- return SkColorSetRGB(s.fR * 255.0f + 0.5f,
- s.fG * 255.0f + 0.5f,
- s.fB * 255.0f + 0.5f);
- }
return s.toSkColor();
}
@@ -186,7 +168,6 @@
{ SkBlendMode::kColor, color },
{ SkBlendMode::kLuminosity, luminosity },
};
- bool legacy = !canvas->imageInfo().colorSpace();
for (auto test : tests) {
canvas->drawRect({20,20,80,80}, bg);
@@ -195,7 +176,7 @@
if (test.reference) {
SkPaint ref;
- ref.setColor(blend(bg.getColor(), fg.getColor(), test.reference, legacy));
+ ref.setColor(blend(bg.getColor(), fg.getColor(), test.reference));
canvas->drawCircle(50,50, 20, ref);
}