From a4aa1332a4c6a70d6c54a3bbc6172d26fc2dce15 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Thu, 19 Oct 2017 12:54:28 -0400 Subject: Remove color space xform from alpha threshold FP This does math on the sampled color. In order to do that math in the destination color space, I split the behavior up - the threshold FP now operates on the input color, and we construct a series with a simple texture effect (possibly wrapped in a color xform), then the threshold. I also added a GM that verifies this behavior. All other GMs using this effect were operating on a layer source, which is always created in the destination color space. The new GM explicitly makes a DAG with an image source, so the alpha threshold filter needs to handle any color space mismatch. Bug: skia: Change-Id: I1ed08c99f4eed17f68176bf751677a3ae1614fe3 Reviewed-on: https://skia-review.googlesource.com/61942 Reviewed-by: Brian Salomon Commit-Queue: Brian Osman --- gm/imagealphathreshold.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'gm/imagealphathreshold.cpp') diff --git a/gm/imagealphathreshold.cpp b/gm/imagealphathreshold.cpp index 4a35018435..6d01722d0a 100644 --- a/gm/imagealphathreshold.cpp +++ b/gm/imagealphathreshold.cpp @@ -7,7 +7,9 @@ #include "gm.h" #include "SkAlphaThresholdFilter.h" +#include "SkImageSource.h" #include "SkOffsetImageFilter.h" +#include "SkRandom.h" #include "SkRegion.h" #include "SkSurface.h" @@ -153,3 +155,43 @@ private: DEF_GM(return new ImageAlphaThresholdGM(true);) DEF_GM(return new ImageAlphaThresholdGM(false);) DEF_GM(return new ImageAlphaThresholdSurfaceGM();) + +////////////////////////////////////////////////////////////////////////////// + +static sk_sp make_img() { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeS32(WIDTH, HEIGHT, kPremul_SkAlphaType)); + SkCanvas canvas(bitmap); + + SkPaint paint; + SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT); + SkRandom rnd; + + while (!rect.isEmpty()) { + paint.setColor(rnd.nextU() | (0xFF << 24)); + canvas.drawRect(rect, paint); + rect.inset(25, 25); + } + + return SkImage::MakeFromBitmap(bitmap); +} + +DEF_SIMPLE_GM_BG(imagealphathreshold_image, canvas, WIDTH * 2, HEIGHT, SK_ColorBLACK) { + sk_sp image(make_img()); + + SkIRect rects[2]; + rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300); + rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT); + SkRegion region; + region.setRects(rects, 2); + + SkPaint filterPaint; + sk_sp imageSource(SkImageSource::Make(image)); + filterPaint.setImageFilter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, + std::move(imageSource))); + + canvas->saveLayer(nullptr, &filterPaint); + canvas->restore(); + canvas->translate(WIDTH, 0); + canvas->drawImage(image, 0, 0); +} -- cgit v1.2.3