diff options
author | Brian Osman <brianosman@google.com> | 2016-12-27 11:04:12 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-12-27 17:38:53 +0000 |
commit | 878df6dd03d1e5b8c018f803eff5b4736af399f8 (patch) | |
tree | d6dd929b553f7947e347c4640979a583df8588ce /gm/matrixconvolution.cpp | |
parent | 210e8551a30f6cb48894fd7c010d0a9be146ffa5 (diff) |
Modify matrix convolution GM for sRGB testing
Tag bitmap as sRGB, and adjust gain/bias in color-managed configs to
produce results that are less blown out.
Also added a colorized version of the GM, to validate that gamut
conversion is working.
BUG=skia:
Change-Id: I333988dcdaa1272121e8aa731b4188c942fe19d8
Reviewed-on: https://skia-review.googlesource.com/6466
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'gm/matrixconvolution.cpp')
-rw-r--r-- | gm/matrixconvolution.cpp | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/gm/matrixconvolution.cpp b/gm/matrixconvolution.cpp index 153f7a530a..ce5ce52bc9 100644 --- a/gm/matrixconvolution.cpp +++ b/gm/matrixconvolution.cpp @@ -7,26 +7,32 @@ #include "gm.h" #include "SkColor.h" -#include "SkMatrixConvolutionImageFilter.h" #include "SkGradientShader.h" +#include "SkMatrixConvolutionImageFilter.h" +#include "SkPixelRef.h" namespace skiagm { class MatrixConvolutionGM : public GM { public: - MatrixConvolutionGM() { + MatrixConvolutionGM(SkColor colorOne, SkColor colorTwo, const char* nameSuffix) + : fNameSuffix(nameSuffix) { this->setBGColor(0x00000000); + fColors[0] = colorOne; + fColors[1] = colorTwo; } protected: SkString onShortName() override { - return SkString("matrixconvolution"); + return SkStringPrintf("matrixconvolution%s", fNameSuffix); } void makeBitmap() { - fBitmap.allocN32Pixels(80, 80); - SkCanvas canvas(fBitmap); + // Draw our bitmap in N32, so legacy devices get "premul" values they understand + SkBitmap n32Bitmap; + n32Bitmap.allocN32Pixels(80, 80); + SkCanvas canvas(n32Bitmap); canvas.clear(0x00000000); SkPaint paint; paint.setAntiAlias(true); @@ -35,12 +41,15 @@ protected: paint.setTextSize(SkIntToScalar(180)); SkPoint pts[2] = { SkPoint::Make(0, 0), SkPoint::Make(0, SkIntToScalar(80)) }; - SkColor colors[2] = { 0xFFFFFFFF, 0x40404040 }; SkScalar pos[2] = { 0, SkIntToScalar(80) }; paint.setShader(SkGradientShader::MakeLinear( - pts, colors, pos, 2, SkShader::kClamp_TileMode)); + pts, fColors, pos, 2, SkShader::kClamp_TileMode)); const char* str = "e"; canvas.drawText(str, strlen(str), SkIntToScalar(-10), SkIntToScalar(80), paint); + + // ... tag the data as sRGB, so color-aware devices do gamut adjustment, etc... + fBitmap.setInfo(SkImageInfo::MakeS32(80, 80, kPremul_SkAlphaType)); + fBitmap.setPixelRef(sk_ref_sp(n32Bitmap.pixelRef()), 0, 0); } SkISize onISize() override { @@ -57,6 +66,19 @@ protected: }; SkISize kernelSize = SkISize::Make(3, 3); SkScalar gain = 0.3f, bias = SkIntToScalar(100); + if (canvas->imageInfo().colorSpace()) { + // TODO: Gain and bias are poorly specified (in the feConvolveMatrix SVG documentation, + // there is obviously no mention of gamma or color spaces). Eventually, we need to + // decide what to do with these (they generally have an extreme brightening effect). + // For now, I'm modifying this GM to use values tuned to preserve luminance across the + // range of input values (compared to the legacy math and values). + // + // It's impossible to match the results exactly, because legacy math produces a flat + // response (when looking at sRGB encoded results), while gamma-correct math produces + // a curve. + gain = 0.25f; + bias = 16.5f; + } SkPaint paint; paint.setImageFilter(SkMatrixConvolutionImageFilter::Make(kernelSize, kernel, @@ -104,12 +126,15 @@ protected: private: SkBitmap fBitmap; + SkColor fColors[2]; + const char* fNameSuffix; typedef GM INHERITED; }; ////////////////////////////////////////////////////////////////////////////// -DEF_GM(return new MatrixConvolutionGM;) +DEF_GM(return new MatrixConvolutionGM(0xFFFFFFFF, 0x40404040, "");) +DEF_GM(return new MatrixConvolutionGM(0xFFFF0000, 0xFF00FF00, "_color");) } |