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>
This commit is contained in:
Brian Osman 2016-12-27 11:04:12 -05:00 committed by Skia Commit-Bot
parent 210e8551a3
commit 878df6dd03

View File

@ -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");)
}