Flutter Engine
The Flutter Engine
Functions
alpha_image.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlurTypes.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMaskFilter.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkShader.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"

Go to the source code of this file.

Functions

static SkBitmap make_alpha_image (int w, int h)
 
static sk_sp< SkColorFiltermake_color_filter ()
 
 DEF_SIMPLE_GM (alpha_image, canvas, 256, 256)
 
 DEF_SIMPLE_GM (alpha_image_alpha_tint, canvas, 152, 80)
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/2]

DEF_SIMPLE_GM ( alpha_image  ,
canvas  ,
256  ,
256   
)

Definition at line 45 of file alpha_image.cpp.

45 {
46 auto image = make_alpha_image(96, 96).asImage();
48
49 paint.setColorFilter(make_color_filter());
51 canvas->drawImage(image.get(), 16, 16, SkSamplingOptions(), &paint);
52
53 paint.setColorFilter(nullptr);
55 canvas->drawImage(image.get(), 144, 16, SkSamplingOptions(), &paint);
56
57 paint.setColorFilter(make_color_filter());
58 canvas->drawImage(image.get(), 16, 144, SkSamplingOptions(), &paint);
59
60 paint.setMaskFilter(nullptr);
61 canvas->drawImage(image.get(), 144, 144, SkSamplingOptions(), &paint);
62}
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
static SkBitmap make_alpha_image(int w, int h)
Definition: alpha_image.cpp:23
static sk_sp< SkColorFilter > make_color_filter()
Definition: alpha_image.cpp:36
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SK_API sk_sp< SkShader > Color(SkColor)

◆ DEF_SIMPLE_GM() [2/2]

DEF_SIMPLE_GM ( alpha_image_alpha_tint  ,
canvas  ,
152  ,
80   
)

Definition at line 66 of file alpha_image.cpp.

66 {
67 canvas->clear(SK_ColorGRAY);
68
69 SkBitmap bm;
71 for (int y = 0; y < bm.height(); ++y) {
72 for (int x = 0; x < bm.width(); ++x) {
73 *bm.getAddr8(x, y) = y * 4;
74 }
75 }
76 bm.setImmutable();
77 auto image = bm.asImage();
78
80 paint.setColor4f({ 0, 1, 0, 0.5f });
81
82 canvas->translate(8, 8);
83 canvas->drawImage(image.get(), 0, 0, SkSamplingOptions(), &paint);
84
85 canvas->translate(72, 0);
87 canvas->drawRect({ 0, 0, 64, 64 }, paint);
88}
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
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
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
double y
double x
static SkImageInfo MakeA8(int width, int height)

◆ make_alpha_image()

static SkBitmap make_alpha_image ( int  w,
int  h 
)
static

Definition at line 23 of file alpha_image.cpp.

23 {
24 SkBitmap bm;
26 bm.eraseARGB(10, 0, 0 , 0);
27 for (int y = 0; y < bm.height(); ++y) {
28 for (int x = y; x < bm.width(); ++x) {
29 *bm.getAddr8(x, y) = 0xFF;
30 }
31 }
32 bm.setImmutable();
33 return bm;
34}
void eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const
Definition: SkBitmap.h:817
SkScalar w
SkScalar h

◆ make_color_filter()

static sk_sp< SkColorFilter > make_color_filter ( )
static

Definition at line 36 of file alpha_image.cpp.

36 {
37 float colorMatrix[20] = {
38 1, 0, 0, 0, 0,
39 0, 1, 0, 0, 0,
40 0, 0, 0.5, 0.5, 0,
41 0, 0, 0.5, 0.5, 0}; // mix G and A.
42 return SkColorFilters::Matrix(colorMatrix);
43}
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)