blob: 06fb3f65498bcc03974dd9339df22f59e16e9204 [file] [log] [blame]
Hal Canaryf828c1d2017-07-19 17:25:38 -04001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9
Hal Canaryf828c1d2017-07-19 17:25:38 -040010#include "SkColorFilter.h"
11#include "SkImage.h"
Mike Reed1be1f8d2018-03-14 13:01:17 -040012#include "SkMaskFilter.h"
Hal Canaryf828c1d2017-07-19 17:25:38 -040013#include "SkShader.h"
14
15static SkBitmap make_alpha_image(int w, int h) {
16 SkBitmap bm;
17 bm.allocPixels(SkImageInfo::MakeA8(w, h));
18 bm.eraseARGB(10, 0, 0 , 0);
19 for (int y = 0; y < bm.height(); ++y) {
20 for (int x = y; x < bm.width(); ++x) {
21 *bm.getAddr8(x, y) = 0xFF;
22 }
23 }
24 bm.setImmutable();
25 return bm;
26}
27
28static sk_sp<SkColorFilter> make_color_filter() {
29 SkScalar colorMatrix[20] = {
30 1, 0, 0, 0, 0,
31 0, 1, 0, 0, 0,
32 0, 0, 0.5, 0.5, 0,
33 0, 0, 0.5, 0.5, 0}; // mix G and A.
34 return SkColorFilter::MakeMatrixFilterRowMajor255(colorMatrix);
35}
36
37DEF_SIMPLE_GM(alpha_image, canvas, 256, 256) {
38 auto image = SkImage::MakeFromBitmap(make_alpha_image(96, 96));
39 SkPaint paint;
40
41 paint.setColorFilter(make_color_filter());
Mike Reed1be1f8d2018-03-14 13:01:17 -040042 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 10.0f));
Hal Canaryf828c1d2017-07-19 17:25:38 -040043 canvas->drawImage(image.get(), 16, 16, &paint);
44
45 paint.setColorFilter(nullptr);
46 paint.setShader(SkShader::MakeColorShader(SK_ColorCYAN));
47 canvas->drawImage(image.get(), 144, 16, &paint);
48
49 paint.setColorFilter(make_color_filter());
50 canvas->drawImage(image.get(), 16, 144, &paint);
51
52 paint.setMaskFilter(nullptr);
53 canvas->drawImage(image.get(), 144, 144, &paint);
54}