Flutter Engine
The Flutter Engine
Classes | Namespaces | Macros | Functions
imagefiltersclipped.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkPoint3.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/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkImageFilters.h"
#include "include/effects/SkPerlinNoiseShader.h"
#include "tools/DecodeUtils.h"
#include "tools/ToolUtils.h"
#include <utility>

Go to the source code of this file.

Classes

class  skiagm::ImageFiltersClippedGM
 

Namespaces

namespace  skiagm
 

Macros

#define RESIZE_FACTOR_X   SkIntToScalar(2)
 
#define RESIZE_FACTOR_Y   SkIntToScalar(5)
 

Functions

static sk_sp< SkImagemake_gradient_circle (int width, int height)
 
static void draw_clipped_filter (SkCanvas *canvas, sk_sp< SkImageFilter > filter, size_t i, const SkRect &primBounds, const SkRect &clipBounds)
 
 DEF_SIMPLE_GM (imagefilter_convolve_subset, canvas, 160, 180)
 

Macro Definition Documentation

◆ RESIZE_FACTOR_X

#define RESIZE_FACTOR_X   SkIntToScalar(2)

Definition at line 35 of file imagefiltersclipped.cpp.

◆ RESIZE_FACTOR_Y

#define RESIZE_FACTOR_Y   SkIntToScalar(5)

Definition at line 36 of file imagefiltersclipped.cpp.

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( imagefilter_convolve_subset  ,
canvas  ,
160  ,
180   
)

Definition at line 157 of file imagefiltersclipped.cpp.

157 {
158 sk_sp<SkImage> reference = ToolUtils::GetResourceAsImage("images/filter_reference.png");
159 SkRect crop = SkRect::Make(reference->dimensions()).makeInset(10, 10);
160 auto drawFilteredImage = [&](sk_sp<SkImageFilter> filter) {
161 SkPaint p;
162 p.setImageFilter(std::move(filter));
163 canvas->drawImage(reference, 0, 0, {}, &p);
164 canvas->translate(0, reference->height());
165 };
166
167 {
168 float kernel[] = {1.f, 1.f, 1.f,
169 1.f, -7.f, 1.f,
170 1.f, 1.f, 1.f};
171 drawFilteredImage(SkImageFilters::MatrixConvolution(
172 {3, 3}, kernel, 1.f, 0.3f, {1, 1}, SkTileMode::kClamp, true, nullptr, crop));
173 }
174
175 drawFilteredImage(SkImageFilters::Blur(10.f, 10.f, SkTileMode::kMirror, nullptr, crop));
176}
static sk_sp< SkImageFilter > MatrixConvolution(const SkISize &kernelSize, const SkScalar kernel[], SkScalar gain, SkScalar bias, const SkIPoint &kernelOffset, SkTileMode tileMode, bool convolveAlpha, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
SkISize dimensions() const
Definition: SkImage.h:297
int height() const
Definition: SkImage.h:291
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
SkRect makeInset(float dx, float dy) const
Definition: SkRect.h:987

◆ draw_clipped_filter()

static void draw_clipped_filter ( SkCanvas canvas,
sk_sp< SkImageFilter filter,
size_t  i,
const SkRect primBounds,
const SkRect clipBounds 
)
static

Definition at line 55 of file imagefiltersclipped.cpp.

56 {
58 paint.setColor(SK_ColorWHITE);
59 paint.setImageFilter(std::move(filter));
60 paint.setAntiAlias(true);
61 canvas->save();
62 canvas->clipRect(clipBounds);
63 if (5 == i) {
64 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32));
65 } else if (6 == i) {
67 }
68 canvas->drawCircle(primBounds.centerX(), primBounds.centerY(),
69 primBounds.width() * 2 / 5, paint);
70 canvas->restore();
71}
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkScalarInvert(x)
Definition: SkScalar.h:73
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
const Paint & paint
Definition: color_source.cc:38
#define RESIZE_FACTOR_Y
#define RESIZE_FACTOR_X
constexpr float centerX() const
Definition: SkRect.h:776
constexpr float centerY() const
Definition: SkRect.h:785
constexpr float width() const
Definition: SkRect.h:762

◆ make_gradient_circle()

static sk_sp< SkImage > make_gradient_circle ( int  width,
int  height 
)
static

Definition at line 38 of file imagefiltersclipped.cpp.

38 {
41 SkScalar radius = std::min(x, y) * 0.8f;
43 SkCanvas* canvas = surface->getCanvas();
44 canvas->clear(0x00000000);
45 SkColor colors[2];
49 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
51 canvas->drawCircle(x, y, radius, paint);
52 return surface->makeImageSnapshot();
53}
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void clear(SkColor color)
Definition: SkCanvas.h:1199
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
VkSurfaceKHR surface
Definition: main.cc:49
float SkScalar
Definition: extension.cpp:12
static float min(float r, float g, float b)
Definition: hsl.cpp:48
double y
double x
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
int32_t height
int32_t width
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173