Flutter Engine
The Flutter Engine
Classes | Functions | Variables
lumafilter.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkLumaColorFilter.h"
#include "include/effects/SkRuntimeEffect.h"
#include "src/core/SkColorFilterPriv.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <string.h>

Go to the source code of this file.

Classes

class  LumaFilterGM
 

Functions

static void draw_label (SkCanvas *canvas, const char *label, const SkPoint &offset)
 
static void draw_scene (SkCanvas *canvas, const sk_sp< SkColorFilter > &filter, SkBlendMode mode, const sk_sp< SkShader > &s1, const sk_sp< SkShader > &s2)
 
 DEF_SIMPLE_GM (AlternateLuma, canvas, 384, 128)
 

Variables

static SkScalar kSize = 80
 
static SkScalar kInset = 10
 
static SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0xff, 0)
 
static SkColor kColor2 = SkColorSetARGB(0xff, 0x82, 0xff, 0)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( AlternateLuma  ,
canvas  ,
384  ,
128   
)

Definition at line 171 of file lumafilter.cpp.

171 {
172 sk_sp<SkImage> img = ToolUtils::GetResourceAsImage("images/mandrill_128.png");
173 if (!img) {
174 return;
175 }
176
177 // Normal luma colorfilter on the left.
179 paint.setColorFilter(SkLumaColorFilter::Make());
180 canvas->drawImage(img, 0,0, SkFilterMode::kNearest, &paint);
181 canvas->translate(128,0);
182
183 // Original image in the middle for reference.
184 canvas->drawImage(img, 0,0);
185 canvas->translate(128,0);
186
187 // Here, RGB holds CIE XYZ. Splatting the G (Y) channel should result in (near) greyscale.
189 "half4 main(half4 inColor) { return inColor.ggga; }"});
190 SkASSERT(effect && err.isEmpty());
191
192 sk_sp<SkColorFilter> filter = effect->makeColorFilter(SkData::MakeEmpty());
193 SkASSERT(filter);
194
196 paint.setColorFilter(SkColorFilterPriv::WithWorkingFormat(std::move(filter),
199 &unpremul));
200 canvas->drawImage(img, 0,0, SkFilterMode::kNearest, &paint);
201}
kUnpremul_SkAlphaType
SkAlphaType
Definition: SkAlphaType.h:26
#define SkASSERT(cond)
Definition: SkAssert.h:116
static sk_sp< SkColorFilter > WithWorkingFormat(sk_sp< SkColorFilter > child, const skcms_TransferFunction *tf, const skcms_Matrix3x3 *gamut, const SkAlphaType *at)
static sk_sp< SkData > MakeEmpty()
Definition: SkData.cpp:94
static Result MakeForColorFilter(SkString sksl, const Options &)
const Paint & paint
Definition: color_source.cc:38
static constexpr skcms_Matrix3x3 kXYZ
Definition: SkColorSpace.h:99
static constexpr skcms_TransferFunction kLinear
Definition: SkColorSpace.h:51
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
static sk_sp< SkColorFilter > Make()

◆ draw_label()

static void draw_label ( SkCanvas canvas,
const char *  label,
const SkPoint offset 
)
static

Definition at line 43 of file lumafilter.cpp.

44 {
47
48 size_t len = strlen(label);
49
50 SkScalar width = font.measureText(label, len, SkTextEncoding::kUTF8);
51 canvas->drawSimpleText(label, len, SkTextEncoding::kUTF8, offset.x() - width / 2, offset.y(),
52 font, SkPaint());
53}
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
float SkScalar
Definition: extension.cpp:12
SkFont DefaultPortableFont()
font
Font Metadata and Metrics.
int32_t width
SeparatedVector2 offset

◆ draw_scene()

static void draw_scene ( SkCanvas canvas,
const sk_sp< SkColorFilter > &  filter,
SkBlendMode  mode,
const sk_sp< SkShader > &  s1,
const sk_sp< SkShader > &  s2 
)
static

Definition at line 55 of file lumafilter.cpp.

56 {
58 paint.setAntiAlias(true);
60
61 c = bounds;
62 c.fRight = bounds.centerX();
63 paint.setARGB(0x20, 0, 0, 0xff);
64 canvas->drawRect(bounds, paint);
65
66 canvas->saveLayer(&bounds, nullptr);
67
68 r = bounds;
69 r.inset(kInset, 0);
70 paint.setShader(s1);
71 paint.setColor(s1 ? SK_ColorBLACK : SkColorSetA(kColor1, 0x80));
72 canvas->drawOval(r, paint);
73 if (!s1) {
74 canvas->save();
75 canvas->clipRect(c);
76 paint.setColor(kColor1);
77 canvas->drawOval(r, paint);
78 canvas->restore();
79 }
80
81 SkPaint xferPaint;
82 xferPaint.setBlendMode(mode);
83 canvas->saveLayer(&bounds, &xferPaint);
84
85 r = bounds;
86 r.inset(0, kInset);
87 paint.setShader(s2);
88 paint.setColor(s2 ? SK_ColorBLACK : SkColorSetA(kColor2, 0x80));
89 paint.setColorFilter(filter);
90 canvas->drawOval(r, paint);
91 if (!s2) {
92 canvas->save();
93 canvas->clipRect(c);
94 paint.setColor(kColor2);
95 canvas->drawOval(r, paint);
96 canvas->restore();
97 }
98
99 canvas->restore();
100 canvas->restore();
101}
static constexpr SkColor SkColorSetA(SkColor c, U8CPU a)
Definition: SkColor.h:82
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawOval(const SkRect &oval, const SkPaint &paint)
Definition: SkCanvas.cpp:1698
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
int save()
Definition: SkCanvas.cpp:447
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151
static SkColor kColor1
Definition: lumafilter.cpp:40
static SkScalar kInset
Definition: lumafilter.cpp:39
static SkScalar kSize
Definition: lumafilter.cpp:38
static SkColor kColor2
Definition: lumafilter.cpp:41
Optional< SkRect > bounds
Definition: SkRecords.h:189
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
void inset(float dx, float dy)
Definition: SkRect.h:1060
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

Variable Documentation

◆ kColor1

SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0xff, 0)
static

Definition at line 40 of file lumafilter.cpp.

◆ kColor2

SkColor kColor2 = SkColorSetARGB(0xff, 0x82, 0xff, 0)
static

Definition at line 41 of file lumafilter.cpp.

◆ kInset

SkScalar kInset = 10
static

Definition at line 39 of file lumafilter.cpp.

◆ kSize

SkScalar kSize = 80
static

Definition at line 38 of file lumafilter.cpp.