Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
alpha_bitmap_color_filter_mask_filter.cpp
Go to the documentation of this file.
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.
4REG_FIDDLE(alpha_bitmap_color_filter_mask_filter, 256, 256, false, 0) {
5static SkBitmap make_alpha_image(int w, int h) {
6 SkBitmap bm;
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;
12 }
13 }
14 bm.setImmutable();
15 return bm;
16}
17
19 SkScalar colorMatrix[20] = {
20 1, 0, 0, 0, 0,
21 0, 1, 0, 0, 0,
22 0, 0, 0.5, 0.5, 0,
23 0, 0, 0.5, 0.5, 0}; // mix G and A.
24 return SkColorFilters::Matrix(colorMatrix);
25}
26
27void draw(SkCanvas* canvas) {
28 auto image = make_alpha_image(96, 96).asImage();
29 SkSamplingOptions sampling;
31
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);
35
36 paint.setColorFilter(nullptr);
37 paint.setShader(SkShaders::Color(SK_ColorCYAN));
38 canvas->drawImage(image.get(), 144, 16, sampling, &paint);
39
40 paint.setColorFilter(make_color_filter());
41 canvas->drawImage(image.get(), 16, 144, sampling, &paint);
42
43 paint.setMaskFilter(nullptr);
44 canvas->drawImage(image.get(), 144, 144, sampling, &paint);
45}
46} // END FIDDLE
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition SkBlurTypes.h:12
constexpr SkColor SK_ColorCYAN
Definition SkColor.h:143
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
static SkBitmap make_alpha_image(int w, int h)
static sk_sp< SkColorFilter > make_color_filter()
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const
Definition SkBitmap.h:817
sk_sp< SkImage > asImage() const
Definition SkBitmap.cpp:645
void setImmutable()
Definition SkBitmap.cpp:400
uint8_t * getAddr8(int x, int y) const
Definition SkBitmap.h:1270
int width() const
Definition SkBitmap.h:149
int height() const
Definition SkBitmap.h:158
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
T * get() const
Definition SkRefCnt.h:303
const Paint & paint
sk_sp< SkImage > image
Definition examples.cpp:29
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
float SkScalar
Definition extension.cpp:12
double y
double x
SkScalar w
SkScalar h
static SkImageInfo MakeA8(int width, int height)