Flutter Engine
The Flutter Engine
Classes | Namespaces | Functions
imagefilterstransformed.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/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.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/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkImageFilters.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/timer/TimeUtils.h"
#include <utility>

Go to the source code of this file.

Classes

class  skiagm::ImageFiltersTransformedGM
 
class  ImageFilterMatrixWLocalMatrix
 
class  ImageFilterComposedTransform
 

Namespaces

namespace  skiagm
 

Functions

static sk_sp< SkImageskiagm::make_gradient_circle (int width, int height)
 
 DEF_SIMPLE_GM (rotate_imagefilter, canvas, 500, 500)
 
 DEF_SIMPLE_GM (imagefilter_transformed_image, canvas, 256, 256)
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/2]

DEF_SIMPLE_GM ( imagefilter_transformed_image  ,
canvas  ,
256  ,
256   
)

Definition at line 316 of file imagefilterstransformed.cpp.

316 {
317 sk_sp<SkImage> image = ToolUtils::GetResourceAsImage("images/color_wheel.png");
319
320 const SkRect imageRect = SkRect::MakeIWH(image->width(), image->height());
321
322 SkM44 m1 = SkM44::Translate(0.9f * image->width(), 0.1f * image->height()) *
323 SkM44::Scale(-.8f, .8f);
324
325 SkM44 m2 = SkM44::RectToRect({-1.f, -1.f, 1.f, 1.f}, imageRect) *
326 SkM44::Perspective(0.01f, 100.f, SK_ScalarPI / 3.f) *
327 SkM44::Translate(0.f, 0.f, -2.f) *
328 SkM44::Rotate({0.f, 1.f, 0.f}, SK_ScalarPI / 6.f) *
329 SkM44::RectToRect(imageRect, {-1.f, -1.f, 1.f, 1.f});
330
332 canvas->drawString("Columns should match", 5.f, 15.f, font, SkPaint());
333 canvas->translate(0.f, 10.f);
334
336 for (auto m : {m1, m2}) {
337 canvas->save();
338 for (bool canvasTransform : {false, true}) {
339 canvas->save();
340 canvas->clipRect(imageRect);
341
342 sk_sp<SkImageFilter> finalFilter;
343 if (canvasTransform) {
344 canvas->concat(m);
345 finalFilter = imageFilter;
346 } else {
347 finalFilter = SkImageFilters::MatrixTransform(m.asM33(), sampling, imageFilter);
348 }
349
351 paint.setImageFilter(std::move(finalFilter));
352 canvas->drawPaint(paint);
353
354 canvas->restore();
355 canvas->translate(image->width(), 0.f);
356 }
357 canvas->restore();
358
359 canvas->translate(0.f, image->height());
360 }
361}
#define SK_ScalarPI
Definition: SkScalar.h:21
Definition: SkFont.h:35
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
static sk_sp< SkImageFilter > MatrixTransform(const SkMatrix &matrix, const SkSamplingOptions &sampling, sk_sp< SkImageFilter > input)
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
Definition: SkM44.h:150
static SkM44 Rotate(SkV3 axis, SkScalar radians)
Definition: SkM44.h:239
static SkM44 RectToRect(const SkRect &src, const SkRect &dst)
Definition: SkM44.cpp:304
static SkM44 Translate(SkScalar x, SkScalar y, SkScalar z=0)
Definition: SkM44.h:225
static SkM44 Perspective(float near, float far, float angle)
Definition: SkM44.cpp:343
static SkM44 Scale(SkScalar x, SkScalar y, SkScalar z=1)
Definition: SkM44.h:232
const Paint & paint
Definition: color_source.cc:38
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions sampling
Definition: SkRecords.h:337
SkFont DefaultPortableFont()
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
font
Font Metadata and Metrics.
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623

◆ DEF_SIMPLE_GM() [2/2]

DEF_SIMPLE_GM ( rotate_imagefilter  ,
canvas  ,
500  ,
500   
)

Definition at line 134 of file imagefilterstransformed.cpp.

134 {
136
137 const SkRect r = SkRect::MakeXYWH(50, 50, 100, 100);
138
139 sk_sp<SkImageFilter> filters[] = {
140 nullptr,
141 SkImageFilters::Blur(6, 0, nullptr),
143 };
144
145 for (auto& filter : filters) {
146 paint.setAntiAlias(false);
147 paint.setImageFilter(filter);
148
149 canvas->save();
150
151 canvas->drawRect(r, paint);
152
153 canvas->translate(150, 0);
154 canvas->save();
155 canvas->rotate(30, 100, 100);
156 canvas->drawRect(r, paint);
157 canvas->restore();
158
159 paint.setAntiAlias(true);
160 canvas->translate(150, 0);
161 canvas->save();
162 canvas->rotate(30, 100, 100);
163 canvas->drawRect(r, paint);
164 canvas->restore();
165
166 canvas->restore();
167 canvas->translate(0, 150);
168 }
169}
@ kSrcOver
r = s + (1-sa)*d
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Blend(SkBlendMode mode, sk_sp< SkImageFilter > background, sk_sp< SkImageFilter > foreground=nullptr, const CropRect &cropRect={})
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659