aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-07-19 17:25:38 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-19 21:58:09 +0000
commitf828c1df2f7f9583b854f68713932a5e677b5f4c (patch)
treeafae3f471fa86c3fc7cc1d1bff9e114a6bef72be /gm
parentf3316224b95e4d3325972552df0d1c046ae73225 (diff)
Add Alpha Image GM
Change-Id: I835a59d9f8593e30db817dc8bd1d276af8c80cd7 Reviewed-on: https://skia-review.googlesource.com/24685 Reviewed-by: Hal Canary <halcanary@google.com> Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'gm')
-rw-r--r--gm/alpha_image.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/gm/alpha_image.cpp b/gm/alpha_image.cpp
new file mode 100644
index 0000000000..0a0da03a3b
--- /dev/null
+++ b/gm/alpha_image.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2017 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 "SkBlurMaskFilter.h"
+#include "SkColorFilter.h"
+#include "SkImage.h"
+#include "SkShader.h"
+
+static SkBitmap make_alpha_image(int w, int h) {
+ SkBitmap bm;
+ bm.allocPixels(SkImageInfo::MakeA8(w, h));
+ bm.eraseARGB(10, 0, 0 , 0);
+ for (int y = 0; y < bm.height(); ++y) {
+ for (int x = y; x < bm.width(); ++x) {
+ *bm.getAddr8(x, y) = 0xFF;
+ }
+ }
+ bm.setImmutable();
+ return bm;
+}
+
+static sk_sp<SkColorFilter> make_color_filter() {
+ SkScalar colorMatrix[20] = {
+ 1, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0,
+ 0, 0, 0.5, 0.5, 0,
+ 0, 0, 0.5, 0.5, 0}; // mix G and A.
+ return SkColorFilter::MakeMatrixFilterRowMajor255(colorMatrix);
+}
+
+DEF_SIMPLE_GM(alpha_image, canvas, 256, 256) {
+ auto image = SkImage::MakeFromBitmap(make_alpha_image(96, 96));
+ SkPaint paint;
+
+ paint.setColorFilter(make_color_filter());
+ paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 10.0f, 0));
+ canvas->drawImage(image.get(), 16, 16, &paint);
+
+ paint.setColorFilter(nullptr);
+ paint.setShader(SkShader::MakeColorShader(SK_ColorCYAN));
+ canvas->drawImage(image.get(), 144, 16, &paint);
+
+ paint.setColorFilter(make_color_filter());
+ canvas->drawImage(image.get(), 16, 144, &paint);
+
+ paint.setMaskFilter(nullptr);
+ canvas->drawImage(image.get(), 144, 144, &paint);
+}