in fuzz/FuzzCanvas.cpp [536:792]
static sk_sp<SkImageFilter> make_fuzz_imageFilter(Fuzz* fuzz, int depth) {
if (depth <= 0) {
return nullptr;
}
uint8_t imageFilterType;
fuzz->nextRange(&imageFilterType, 0, 22);
switch (imageFilterType) {
case 0:
return nullptr;
case 1: {
SkScalar sigmaX, sigmaY;
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
bool useCropRect;
fuzz->next(&sigmaX, &sigmaY, &useCropRect);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
return SkImageFilters::Blur(sigmaX, sigmaY, std::move(input),
useCropRect ? &cropRect : nullptr);
}
case 2: {
SkMatrix matrix;
FuzzNiceMatrix(fuzz, &matrix);
const auto sampling = next_sampling(fuzz);
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
return SkImageFilters::MatrixTransform(matrix, sampling, std::move(input));
}
case 3: {
float k1, k2, k3, k4;
bool enforcePMColor;
bool useCropRect;
fuzz->next(&k1, &k2, &k3, &k4, &enforcePMColor, &useCropRect);
sk_sp<SkImageFilter> background = make_fuzz_imageFilter(fuzz, depth - 1);
sk_sp<SkImageFilter> foreground = make_fuzz_imageFilter(fuzz, depth - 1);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
return SkImageFilters::Arithmetic(k1, k2, k3, k4, enforcePMColor,
std::move(background), std::move(foreground),
useCropRect ? &cropRect : nullptr);
}
case 4: {
sk_sp<SkColorFilter> cf = make_fuzz_colorfilter(fuzz, depth - 1);
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
bool useCropRect;
SkIRect cropRect;
fuzz->next(&useCropRect);
if (useCropRect) {
fuzz->next(&cropRect);
}
return SkImageFilters::ColorFilter(std::move(cf), std::move(input),
useCropRect ? &cropRect : nullptr);
}
case 5: {
sk_sp<SkImageFilter> ifo = make_fuzz_imageFilter(fuzz, depth - 1);
sk_sp<SkImageFilter> ifi = make_fuzz_imageFilter(fuzz, depth - 1);
return SkImageFilters::Compose(std::move(ifo), std::move(ifi));
}
case 6: {
SkColorChannel xChannelSelector, yChannelSelector;
fuzz->nextEnum(&xChannelSelector, SkColorChannel::kLastEnum);
fuzz->nextEnum(&yChannelSelector, SkColorChannel::kLastEnum);
SkScalar scale;
bool useCropRect;
fuzz->next(&scale, &useCropRect);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
sk_sp<SkImageFilter> displacement = make_fuzz_imageFilter(fuzz, depth - 1);
sk_sp<SkImageFilter> color = make_fuzz_imageFilter(fuzz, depth - 1);
return SkImageFilters::DisplacementMap(xChannelSelector, yChannelSelector, scale,
std::move(displacement), std::move(color),
useCropRect ? &cropRect : nullptr);
}
case 7: {
SkScalar dx, dy, sigmaX, sigmaY;
SkColor color;
bool shadowOnly, useCropRect;
fuzz->next(&dx, &dy, &sigmaX, &sigmaY, &color, &shadowOnly, &useCropRect);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
if (shadowOnly) {
return SkImageFilters::DropShadowOnly(dx, dy, sigmaX, sigmaY, color,
std::move(input),
useCropRect ? &cropRect : nullptr);
} else {
return SkImageFilters::DropShadow(dx, dy, sigmaX, sigmaY, color, std::move(input),
useCropRect ? &cropRect : nullptr);
}
}
case 8:
return SkImageFilters::Image(make_fuzz_image(fuzz), SkCubicResampler::Mitchell());
case 9: {
sk_sp<SkImage> image = make_fuzz_image(fuzz);
SkRect srcRect, dstRect;
fuzz->next(&srcRect, &dstRect);
return SkImageFilters::Image(std::move(image), srcRect, dstRect, next_sampling(fuzz));
}
case 10:
return make_fuzz_lighting_imagefilter(fuzz, depth - 1);
case 11: {
SkRect lensBounds;
SkScalar zoomAmount;
SkScalar inset;
bool useCropRect;
SkIRect cropRect;
fuzz->next(&lensBounds, &zoomAmount, &inset, &useCropRect);
if (useCropRect) {
fuzz->next(&cropRect);
}
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
const auto sampling = next_sampling(fuzz);
return SkImageFilters::Magnifier(lensBounds, zoomAmount, inset, sampling,
std::move(input), useCropRect ? &cropRect : nullptr);
}
case 12: {
constexpr int kMaxKernelSize = 5;
int32_t n, m;
fuzz->nextRange(&n, 1, kMaxKernelSize);
fuzz->nextRange(&m, 1, kMaxKernelSize);
SkScalar kernel[kMaxKernelSize * kMaxKernelSize];
fuzz->nextN(kernel, n * m);
int32_t offsetX, offsetY;
fuzz->nextRange(&offsetX, 0, n - 1);
fuzz->nextRange(&offsetY, 0, m - 1);
SkScalar gain, bias;
bool convolveAlpha, useCropRect;
fuzz->next(&gain, &bias, &convolveAlpha, &useCropRect);
SkTileMode tileMode;
fuzz->nextEnum(&tileMode, SkTileMode::kLastTileMode);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
return SkImageFilters::MatrixConvolution(
SkISize{n, m}, kernel, gain, bias, SkIPoint{offsetX, offsetY}, tileMode,
convolveAlpha, std::move(input), useCropRect ? &cropRect : nullptr);
}
case 13: {
sk_sp<SkImageFilter> first = make_fuzz_imageFilter(fuzz, depth - 1);
sk_sp<SkImageFilter> second = make_fuzz_imageFilter(fuzz, depth - 1);
bool useCropRect;
fuzz->next(&useCropRect);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
return SkImageFilters::Merge(std::move(first), std::move(second),
useCropRect ? &cropRect : nullptr);
}
case 14: {
constexpr int kMaxCount = 4;
sk_sp<SkImageFilter> ifs[kMaxCount];
int count;
fuzz->nextRange(&count, 1, kMaxCount);
for (int i = 0; i < count; ++i) {
ifs[i] = make_fuzz_imageFilter(fuzz, depth - 1);
}
bool useCropRect;
fuzz->next(&useCropRect);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
return SkImageFilters::Merge(ifs, count, useCropRect ? &cropRect : nullptr);
}
case 15: {
int rx, ry;
fuzz->next(&rx, &ry);
bool useCropRect;
fuzz->next(&useCropRect);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
return SkImageFilters::Dilate(rx, ry, std::move(input),
useCropRect ? &cropRect : nullptr);
}
case 16: {
int rx, ry;
fuzz->next(&rx, &ry);
bool useCropRect;
fuzz->next(&useCropRect);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
return SkImageFilters::Erode(rx, ry, std::move(input),
useCropRect ? &cropRect : nullptr);
}
case 17: {
SkScalar dx, dy;
fuzz->next(&dx, &dy);
bool useCropRect;
fuzz->next(&useCropRect);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
return SkImageFilters::Offset(dx, dy, std::move(input),
useCropRect ? &cropRect : nullptr);
}
case 18: {
sk_sp<SkPicture> picture = make_fuzz_picture(fuzz, depth - 1);
return SkImageFilters::Picture(std::move(picture));
}
case 19: {
SkRect cropRect;
fuzz->next(&cropRect);
sk_sp<SkPicture> picture = make_fuzz_picture(fuzz, depth - 1);
return SkImageFilters::Picture(std::move(picture), cropRect);
}
case 20: {
SkRect src, dst;
fuzz->next(&src, &dst);
sk_sp<SkImageFilter> input = make_fuzz_imageFilter(fuzz, depth - 1);
return SkImageFilters::Tile(src, dst, std::move(input));
}
case 21: {
SkBlendMode blendMode;
bool useCropRect;
fuzz->next(&useCropRect);
fuzz->nextEnum(&blendMode, SkBlendMode::kLastMode);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
sk_sp<SkImageFilter> bg = make_fuzz_imageFilter(fuzz, depth - 1);
sk_sp<SkImageFilter> fg = make_fuzz_imageFilter(fuzz, depth - 1);
return SkImageFilters::Blend(blendMode, std::move(bg), std::move(fg),
useCropRect ? &cropRect : nullptr);
}
case 22: {
sk_sp<SkShader> shader = make_fuzz_shader(fuzz, depth - 1);
bool useCropRect;
fuzz->next(&useCropRect);
SkIRect cropRect;
if (useCropRect) {
fuzz->next(&cropRect);
}
return SkImageFilters::Shader(std::move(shader), useCropRect ? &cropRect : nullptr);
}
default:
SkASSERT(false);
return nullptr;
}
}