1 // Copyright 2020 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(alpha_bitmap_color_filter_mask_filter, 256, 256, false, 0) {
5 static SkBitmap make_alpha_image(int w, int h) {
7 bm.allocPixels(SkImageInfo::MakeA8(w, h));
8 bm.eraseARGB(10, 0, 0, 0);
9 for (int y = 0; y < bm.height(); ++y) {
10 for (int x = y; x < bm.width(); ++x) {
11 *bm.getAddr8(x, y) = 0xFF;
18 static sk_sp<SkColorFilter> make_color_filter() {
19 SkScalar colorMatrix[20] = {
23 0, 0, 0.5, 0.5, 0}; // mix G and A.
24 return SkColorFilters::Matrix(colorMatrix);
27 void draw(SkCanvas* canvas) {
28 auto image = make_alpha_image(96, 96).asImage();
29 SkSamplingOptions sampling;
32 paint.setColorFilter(make_color_filter());
33 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 10.0f, false));
34 canvas->drawImage(image.get(), 16, 16, sampling, &paint);
36 paint.setColorFilter(nullptr);
37 paint.setShader(SkShaders::Color(SK_ColorCYAN));
38 canvas->drawImage(image.get(), 144, 16, sampling, &paint);
40 paint.setColorFilter(make_color_filter());
41 canvas->drawImage(image.get(), 16, 144, sampling, &paint);
43 paint.setMaskFilter(nullptr);
44 canvas->drawImage(image.get(), 144, 144, sampling, &paint);