Flutter Engine
The Flutter Engine
Functions
unpremul.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include <string.h>

Go to the source code of this file.

Functions

 DEF_SIMPLE_GM (unpremul, canvas, 200, 200)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( unpremul  ,
canvas  ,
200  ,
200   
)

Definition at line 20 of file unpremul.cpp.

20 {
21 const SkColor color = 0xbf400000;
22
23 auto grade = [&](int x, int y){
24 SkBitmap bm;
29 if (!canvas->readPixels(bm, x,y)) {
30 // Picture-backed canvases, that sort of thing. Just assume they're good.
31 MarkGMGood(canvas, 140,40);
32 return;
33 }
34
35 SkColor pixel;
36 memcpy(&pixel, bm.getAddr(0,0), sizeof(pixel));
37
38 auto close = [](int x, int y) {
39 return x-y < 2
40 && y-x < 2;
41 };
42
43 if (close(SkColorGetR(pixel), SkColorGetR(color)) &&
44 close(SkColorGetG(pixel), SkColorGetG(color)) &&
45 close(SkColorGetB(pixel), SkColorGetB(color)) &&
46 close(SkColorGetA(pixel), SkColorGetA(color))) {
47
48 MarkGMGood(canvas, 140,40);
49 } else {
50 MarkGMBad(canvas, 140,40);
51 }
52 };
53
54 {
56 paint.setBlendMode(SkBlendMode::kSrc);
57 paint.setColor(color);
58
59 canvas->drawRect({0,0,100,100}, paint);
60 grade(50,50);
61 }
62
63 canvas->translate(0,100);
64
65 {
67 paint.setBlendMode(SkBlendMode::kSrc);
68
69 SkBitmap bm;
71 bm.eraseColor(color);
72
73 canvas->drawImage(bm.asImage(), 0,0, SkSamplingOptions(), &paint);
74 grade(50,150);
75 }
76
77}
kUnpremul_SkAlphaType
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
uint32_t SkColor
Definition: SkColor.h:37
#define SkColorGetA(color)
Definition: SkColor.h:61
#define SkColorGetB(color)
Definition: SkColor.h:73
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void * getAddr(int x, int y) const
Definition: SkBitmap.cpp:406
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
static sk_sp< SkColorSpace > MakeSRGB()
const Paint & paint
Definition: color_source.cc:38
DlColor color
void MarkGMGood(SkCanvas *canvas, SkScalar x, SkScalar y)
Definition: gm.cpp:221
void MarkGMBad(SkCanvas *canvas, SkScalar x, SkScalar y)
Definition: gm.cpp:238
double y
double x
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)