aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/imagealphathreshold.cpp
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-10-19 12:54:28 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-19 20:07:44 +0000
commita4aa1332a4c6a70d6c54a3bbc6172d26fc2dce15 (patch)
treee6ab58d4ba8a3f636acb357ed75fe12cb31f6f53 /gm/imagealphathreshold.cpp
parent5f379a8b117f68b2087ab4b400b7d2f110f5600c (diff)
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 <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'gm/imagealphathreshold.cpp')
-rw-r--r--gm/imagealphathreshold.cpp42
1 files changed, 42 insertions, 0 deletions
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<SkImage> 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<SkImage> 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<SkImageFilter> 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);
+}