Flutter Engine
The Flutter Engine
Classes | Typedefs | Functions
imagemakewithfilter.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/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkImageInfo.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/SkRegion.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkImageFilters.h"
#include "tools/DecodeUtils.h"
#include "tools/GpuToolUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <utility>

Go to the source code of this file.

Classes

class  ImageMakeWithFilterGM
 

Typedefs

typedef sk_sp< SkImageFilter >(* FilterFactory) (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 

Functions

static void show_bounds (SkCanvas *canvas, const SkIRect *clip, const SkIRect *inSubset, const SkIRect *outSubset)
 
static sk_sp< SkImageFiltercolor_filter_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFilterblur_filter_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFilterdrop_shadow_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFilteroffset_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFilterdilate_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFiltererode_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFilterdisplacement_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFilterarithmetic_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFilterblend_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFilterconvolution_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFiltermatrix_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFilterlighting_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 
static sk_sp< SkImageFiltertile_factory (sk_sp< SkImage > auxImage, const SkIRect *cropRect)
 

Typedef Documentation

◆ FilterFactory

typedef sk_sp< SkImageFilter >(* FilterFactory) (sk_sp< SkImage > auxImage, const SkIRect *cropRect)

Definition at line 69 of file imagemakewithfilter.cpp.

Function Documentation

◆ arithmetic_factory()

static sk_sp< SkImageFilter > arithmetic_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 105 of file imagemakewithfilter.cpp.

105 {
106 sk_sp<SkImageFilter> background = SkImageFilters::Image(std::move(auxImage),
108 return SkImageFilters::Arithmetic(0.0f, .6f, 1.f, 0.f, false, std::move(background),
109 nullptr, cropRect);
110}
static sk_sp< SkImageFilter > Arithmetic(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4, bool enforcePMColor, sk_sp< SkImageFilter > background, sk_sp< SkImageFilter > foreground, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)

◆ blend_factory()

static sk_sp< SkImageFilter > blend_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 112 of file imagemakewithfilter.cpp.

112 {
113 sk_sp<SkImageFilter> background = SkImageFilters::Image(std::move(auxImage),
116 SkBlendMode::kModulate, std::move(background), nullptr, cropRect);
117}
@ kModulate
r = s*d
static sk_sp< SkImageFilter > Blend(SkBlendMode mode, sk_sp< SkImageFilter > background, sk_sp< SkImageFilter > foreground=nullptr, const CropRect &cropRect={})

◆ blur_filter_factory()

static sk_sp< SkImageFilter > blur_filter_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 78 of file imagemakewithfilter.cpp.

78 {
79 return SkImageFilters::Blur(2.0f, 2.0f, nullptr, cropRect);
80}
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})

◆ color_filter_factory()

static sk_sp< SkImageFilter > color_filter_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 71 of file imagemakewithfilter.cpp.

71 {
72 // The color filter uses kSrcIn so that it respects the transparency introduced by clamping;
73 // using kSrc would just turn the entire out rect to green regardless.
75 return SkImageFilters::ColorFilter(std::move(cf), nullptr, cropRect);
76}
@ kSrcIn
r = s * da
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
static sk_sp< SkImageFilter > ColorFilter(sk_sp< SkColorFilter > cf, sk_sp< SkImageFilter > input, const CropRect &cropRect={})

◆ convolution_factory()

static sk_sp< SkImageFilter > convolution_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 119 of file imagemakewithfilter.cpp.

119 {
120 SkISize kernelSize = SkISize::Make(3, 3);
121 SkIPoint kernelOffset = SkIPoint::Make(1, 1);
122 // A Laplacian edge detector, ee https://en.wikipedia.org/wiki/Kernel_(image_processing)
123 SkScalar kernel[9] = {-1.f, -1.f, -1.f,
124 -1.f, 8.f, -1.f,
125 -1.f, -1.f, -1.f};
126 return SkImageFilters::MatrixConvolution(kernelSize, kernel, 1.f, 0.f, kernelOffset,
127 SkTileMode::kClamp, false, nullptr, cropRect);
128}
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={})
float SkScalar
Definition: extension.cpp:12
static constexpr SkIPoint Make(int32_t x, int32_t y)
Definition: SkPoint_impl.h:38
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ dilate_factory()

static sk_sp< SkImageFilter > dilate_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 90 of file imagemakewithfilter.cpp.

90 {
91 return SkImageFilters::Dilate(10.f, 5.f, nullptr, cropRect);
92}
static sk_sp< SkImageFilter > Dilate(SkScalar radiusX, SkScalar radiusY, sk_sp< SkImageFilter > input, const CropRect &cropRect={})

◆ displacement_factory()

static sk_sp< SkImageFilter > displacement_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 98 of file imagemakewithfilter.cpp.

98 {
99 sk_sp<SkImageFilter> displacement = SkImageFilters::Image(std::move(auxImage),
102 std::move(displacement), nullptr, cropRect);
103}
static sk_sp< SkImageFilter > DisplacementMap(SkColorChannel xChannelSelector, SkColorChannel yChannelSelector, SkScalar scale, sk_sp< SkImageFilter > displacement, sk_sp< SkImageFilter > color, const CropRect &cropRect={})

◆ drop_shadow_factory()

static sk_sp< SkImageFilter > drop_shadow_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 82 of file imagemakewithfilter.cpp.

82 {
83 return SkImageFilters::DropShadow(10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE, nullptr, cropRect);
84}
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
static sk_sp< SkImageFilter > DropShadow(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, SkColor color, sk_sp< SkImageFilter > input, const CropRect &cropRect={})

◆ erode_factory()

static sk_sp< SkImageFilter > erode_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 94 of file imagemakewithfilter.cpp.

94 {
95 return SkImageFilters::Erode(10.f, 5.f, nullptr, cropRect);
96}
static sk_sp< SkImageFilter > Erode(SkScalar radiusX, SkScalar radiusY, sk_sp< SkImageFilter > input, const CropRect &cropRect={})

◆ lighting_factory()

static sk_sp< SkImageFilter > lighting_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 138 of file imagemakewithfilter.cpp.

138 {
139 // Must convert the RGB values of the source to alpha, since that is what the lighting filters
140 // use to estimate their normals. This color matrix changes the color to white and the alpha
141 // to be equal to the approx. luminance of the original color.
142 static const float kMatrix[20] = {
143 0.f, 0.f, 0.f, 0.f, 1.f,
144 0.f, 0.f, 0.f, 0.f, 1.f,
145 0.f, 0.f, 0.f, 0.f, 1.f,
146 0.2126f, 0.7152f, 0.0722f, 0.f, 0.f
147 };
149 SkColorFilters::Matrix(kMatrix), nullptr);
150
151 // Combine both specular and diffuse into a single DAG since they use separate internal filter
152 // implementations.
153 SkScalar sinAzimuth = SkScalarSin(SkDegreesToRadians(225.f)),
154 cosAzimuth = SkScalarCos(SkDegreesToRadians(225.f));
155
156 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40), 0);
157 SkPoint3 diffLocation = SkPoint3::Make(spotTarget.fX + 50 * cosAzimuth,
158 spotTarget.fY + 50 * sinAzimuth,
159 SkIntToScalar(10));
160 SkPoint3 specLocation = SkPoint3::Make(spotTarget.fX - 50 * sinAzimuth,
161 spotTarget.fY + 50 * cosAzimuth,
162 SkIntToScalar(10));
164 diffLocation, SK_ColorWHITE, /* scale */ 1.f, /* kd */ 2.f, srcToAlpha, cropRect);
166 specLocation, SK_ColorRED, /* scale */ 1.f, /* ks */ 1.f, /* shine */ 8.f,
167 srcToAlpha, cropRect);
168 return SkImageFilters::Merge(std::move(diffuse), std::move(specular), cropRect);
169}
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkDegreesToRadians(degrees)
Definition: SkScalar.h:77
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define SkScalarCos(radians)
Definition: SkScalar.h:46
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
static sk_sp< SkImageFilter > PointLitDiffuse(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Merge(sk_sp< SkImageFilter > *const filters, int count, const CropRect &cropRect={})
static sk_sp< SkImageFilter > PointLitSpecular(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
SkScalar fX
Definition: SkPoint3.h:16
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
SkScalar fY
Definition: SkPoint3.h:16

◆ matrix_factory()

static sk_sp< SkImageFilter > matrix_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 130 of file imagemakewithfilter.cpp.

130 {
132 matrix.setRotate(45.f, 50.f, 50.f);
133
134 // This doesn't support a cropRect
136}
static sk_sp< SkImageFilter > MatrixTransform(const SkMatrix &matrix, const SkSamplingOptions &sampling, sk_sp< SkImageFilter > input)
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
SkSamplingOptions(SkFilterMode::kLinear))

◆ offset_factory()

static sk_sp< SkImageFilter > offset_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 86 of file imagemakewithfilter.cpp.

86 {
87 return SkImageFilters::Offset(10.f, 5.f, nullptr, cropRect);
88}
static sk_sp< SkImageFilter > Offset(SkScalar dx, SkScalar dy, sk_sp< SkImageFilter > input, const CropRect &cropRect={})

◆ show_bounds()

static void show_bounds ( SkCanvas canvas,
const SkIRect clip,
const SkIRect inSubset,
const SkIRect outSubset 
)
static

Definition at line 49 of file imagemakewithfilter.cpp.

50 {
51 const SkIRect* rects[] { clip, inSubset, outSubset };
53
56
57 for (size_t i = 0; i < std::size(rects); ++i) {
58 // Skip null bounds rects, since not all methods have subsets
59 if (rects[i]) {
60 paint.setColor(colors[i]);
61 canvas->drawRect(SkRect::Make(*(rects[i])), paint);
62 }
63 }
64}
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
uint32_t SkColor
Definition: SkColor.h:37
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
const Paint & paint
Definition: color_source.cc:38
PODArray< SkColor > colors
Definition: SkRecords.h:276
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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: SkRect.h:32
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ tile_factory()

static sk_sp< SkImageFilter > tile_factory ( sk_sp< SkImage auxImage,
const SkIRect cropRect 
)
static

Definition at line 171 of file imagemakewithfilter.cpp.

171 {
172 // Tile the subset over a large region
173 return SkImageFilters::Tile(SkRect::MakeLTRB(25, 25, 75, 75), SkRect::MakeWH(100, 100),
174 nullptr);
175}
static sk_sp< SkImageFilter > Tile(const SkRect &src, const SkRect &dst, sk_sp< SkImageFilter > input)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646