Remove deprecated matrix convolution header and old types

Bug: skia:11230
Change-Id: I9946fbcc17f96823b2b739f7d5bf065be52e9e10
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/371961
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Michael Ludwig 2021-02-18 13:47:02 -05:00 committed by Skia Commit-Bot
parent 05e1795d66
commit b06dc99130
6 changed files with 54 additions and 179 deletions

View File

@ -23,7 +23,6 @@ skia_effects_imagefilter_sources = [
"$_src/effects/imagefilters/SkLightingImageFilter.cpp",
"$_src/effects/imagefilters/SkMagnifierImageFilter.cpp",
"$_src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp",
"$_src/effects/imagefilters/SkMatrixConvolutionImageFilter.h",
"$_src/effects/imagefilters/SkMergeImageFilter.cpp",
"$_src/effects/imagefilters/SkMergeImageFilter.h",
"$_src/effects/imagefilters/SkMorphologyImageFilter.cpp",

View File

@ -494,5 +494,6 @@ void SkRegisterDropShadowImageFilterFlattenable();
void SkRegisterImageImageFilterFlattenable();
void SkRegisterLightingImageFilterFlattenables();
void SkRegisterMagnifierImageFilterFlattenable();
void SkRegisterMatrixConvolutionImageFilterFlattenable();
#endif // SkImageFilter_Base_DEFINED

View File

@ -9,7 +9,6 @@
#include "include/core/SkPaint.h"
#include "src/effects/imagefilters/SkMatrixConvolutionImageFilter.h"
#include "src/effects/imagefilters/SkMergeImageFilter.h"
#include "src/effects/imagefilters/SkMorphologyImageFilter.h"
#include "src/effects/imagefilters/SkOffsetImageFilter.h"
@ -23,7 +22,6 @@
void SkImageFilters::RegisterFlattenables() {
SkDilateImageFilter::RegisterFlattenables();
SkMatrixConvolutionImageFilter::RegisterFlattenables();
SkMergeImageFilter::RegisterFlattenables();
SkOffsetImageFilter::RegisterFlattenables();
SkPaintImageFilter::RegisterFlattenables();
@ -33,15 +31,6 @@ void SkImageFilters::RegisterFlattenables() {
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkImageFilter> SkImageFilters::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) {
return SkMatrixConvolutionImageFilter::Make(kernelSize, kernel, gain, bias, kernelOffset,
tileMode, convolveAlpha, std::move(input),
cropRect);
}
sk_sp<SkImageFilter> SkImageFilters::MatrixTransform(
const SkMatrix& transform, const SkSamplingOptions& sampling, sk_sp<SkImageFilter> input) {
return SkMatrixImageFilter::Make(transform, sampling, std::move(input));

View File

@ -5,12 +5,11 @@
* found in the LICENSE file.
*/
#include "src/effects/imagefilters/SkMatrixConvolutionImageFilter.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkRect.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkUnPreMultiply.h"
#include "include/effects/SkImageFilters.h"
#include "include/private/SkColorData.h"
#include "include/private/SkTPin.h"
#include "src/core/SkImageFilter_Base.h"
@ -27,12 +26,12 @@
namespace {
class SkMatrixConvolutionImageFilterImpl final : public SkImageFilter_Base {
class SkMatrixConvolutionImageFilter final : public SkImageFilter_Base {
public:
SkMatrixConvolutionImageFilterImpl(const SkISize& kernelSize, const SkScalar* kernel,
SkScalar gain, SkScalar bias, const SkIPoint& kernelOffset,
SkTileMode tileMode, bool convolveAlpha,
sk_sp<SkImageFilter> input, const SkRect* cropRect)
SkMatrixConvolutionImageFilter(const SkISize& kernelSize, const SkScalar* kernel,
SkScalar gain, SkScalar bias, const SkIPoint& kernelOffset,
SkTileMode tileMode, bool convolveAlpha,
sk_sp<SkImageFilter> input, const SkRect* cropRect)
: INHERITED(&input, 1, cropRect)
, fKernelSize(kernelSize)
, fGain(gain)
@ -48,7 +47,7 @@ public:
SkASSERT(kernelOffset.fY >= 0 && kernelOffset.fY < kernelSize.fHeight);
}
~SkMatrixConvolutionImageFilterImpl() override {
~SkMatrixConvolutionImageFilter() override {
delete[] fKernel;
}
@ -62,8 +61,8 @@ protected:
bool affectsTransparentBlack() const override;
private:
friend void SkMatrixConvolutionImageFilter::RegisterFlattenables();
SK_FLATTENABLE_HOOKS(SkMatrixConvolutionImageFilterImpl)
friend void ::SkRegisterMatrixConvolutionImageFilterFlattenable();
SK_FLATTENABLE_HOOKS(SkMatrixConvolutionImageFilter)
SkISize fKernelSize;
SkScalar* fKernel;
@ -143,41 +142,15 @@ public:
} // end namespace
static SkTileMode to_sktilemode(SkMatrixConvolutionImageFilter::TileMode tileMode) {
switch(tileMode) {
case SkMatrixConvolutionImageFilter::kClamp_TileMode:
return SkTileMode::kClamp;
case SkMatrixConvolutionImageFilter::kRepeat_TileMode:
return SkTileMode::kRepeat;
case SkMatrixConvolutionImageFilter::kClampToBlack_TileMode:
// Fall through
default:
return SkTileMode::kDecal;
}
}
sk_sp<SkImageFilter> SkMatrixConvolutionImageFilter::Make(const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& kernelOffset,
TileMode tileMode,
bool convolveAlpha,
sk_sp<SkImageFilter> input,
const SkRect* cropRect) {
return Make(kernelSize, kernel, gain, bias, kernelOffset, to_sktilemode(tileMode),
convolveAlpha, std::move(input), cropRect);
}
sk_sp<SkImageFilter> SkMatrixConvolutionImageFilter::Make(const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& kernelOffset,
SkTileMode tileMode,
bool convolveAlpha,
sk_sp<SkImageFilter> input,
const SkRect* cropRect) {
sk_sp<SkImageFilter> SkImageFilters::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) {
// We need to be able to read at most SK_MaxS32 bytes, so divide that
// by the size of a scalar to know how many scalars we can read.
static constexpr int32_t kMaxKernelSize = SK_MaxS32 / sizeof(SkScalar);
@ -195,21 +168,19 @@ sk_sp<SkImageFilter> SkMatrixConvolutionImageFilter::Make(const SkISize& kernelS
(kernelOffset.fY < 0) || (kernelOffset.fY >= kernelSize.fHeight)) {
return nullptr;
}
return sk_sp<SkImageFilter>(new SkMatrixConvolutionImageFilterImpl(
return sk_sp<SkImageFilter>(new SkMatrixConvolutionImageFilter(
kernelSize, kernel, gain, bias, kernelOffset, tileMode, convolveAlpha,
std::move(input), cropRect));
}
void SkMatrixConvolutionImageFilter::RegisterFlattenables() {
SK_REGISTER_FLATTENABLE(SkMatrixConvolutionImageFilterImpl);
void SkRegisterMatrixConvolutionImageFilterFlattenable() {
SK_REGISTER_FLATTENABLE(SkMatrixConvolutionImageFilter);
// TODO (michaelludwig) - Remove after grace period for SKPs to stop using old name
SkFlattenable::Register("SkMatrixConvolutionImageFilter",
SkMatrixConvolutionImageFilterImpl::CreateProc);
SkFlattenable::Register("SkMatrixConvolutionImageFilterImpl",
SkMatrixConvolutionImageFilter::CreateProc);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkFlattenable> SkMatrixConvolutionImageFilterImpl::CreateProc(SkReadBuffer& buffer) {
sk_sp<SkFlattenable> SkMatrixConvolutionImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
SkISize kernelSize;
@ -240,12 +211,12 @@ sk_sp<SkFlattenable> SkMatrixConvolutionImageFilterImpl::CreateProc(SkReadBuffer
if (!buffer.isValid()) {
return nullptr;
}
return SkMatrixConvolutionImageFilter::Make(
return SkImageFilters::MatrixConvolution(
kernelSize, kernel.get(), gain, bias, kernelOffset, tileMode,
convolveAlpha, common.getInput(0), common.cropRect());
}
void SkMatrixConvolutionImageFilterImpl::flatten(SkWriteBuffer& buffer) const {
void SkMatrixConvolutionImageFilter::flatten(SkWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
buffer.writeInt(fKernelSize.fWidth);
buffer.writeInt(fKernelSize.fHeight);
@ -258,12 +229,14 @@ void SkMatrixConvolutionImageFilterImpl::flatten(SkWriteBuffer& buffer) const {
buffer.writeBool(fConvolveAlpha);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
template<class PixelFetcher, bool convolveAlpha>
void SkMatrixConvolutionImageFilterImpl::filterPixels(const SkBitmap& src,
SkBitmap* result,
SkIVector& offset,
const SkIRect& r,
const SkIRect& bounds) const {
void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
SkBitmap* result,
SkIVector& offset,
const SkIRect& r,
const SkIRect& bounds) const {
SkIRect rect(r);
if (!rect.intersect(bounds)) {
return;
@ -304,11 +277,11 @@ void SkMatrixConvolutionImageFilterImpl::filterPixels(const SkBitmap& src,
}
template<class PixelFetcher>
void SkMatrixConvolutionImageFilterImpl::filterPixels(const SkBitmap& src,
SkBitmap* result,
SkIVector& offset,
const SkIRect& rect,
const SkIRect& bounds) const {
void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
SkBitmap* result,
SkIVector& offset,
const SkIRect& rect,
const SkIRect& bounds) const {
if (fConvolveAlpha) {
filterPixels<PixelFetcher, true>(src, result, offset, rect, bounds);
} else {
@ -316,11 +289,11 @@ void SkMatrixConvolutionImageFilterImpl::filterPixels(const SkBitmap& src,
}
}
void SkMatrixConvolutionImageFilterImpl::filterInteriorPixels(const SkBitmap& src,
SkBitmap* result,
SkIVector& offset,
const SkIRect& rect,
const SkIRect& bounds) const {
void SkMatrixConvolutionImageFilter::filterInteriorPixels(const SkBitmap& src,
SkBitmap* result,
SkIVector& offset,
const SkIRect& rect,
const SkIRect& bounds) const {
switch (fTileMode) {
case SkTileMode::kMirror:
// TODO (michaelludwig) - Implement mirror tiling, treat as repeat for now.
@ -336,11 +309,11 @@ void SkMatrixConvolutionImageFilterImpl::filterInteriorPixels(const SkBitmap& sr
}
}
void SkMatrixConvolutionImageFilterImpl::filterBorderPixels(const SkBitmap& src,
SkBitmap* result,
SkIVector& offset,
const SkIRect& rect,
const SkIRect& srcBounds) const {
void SkMatrixConvolutionImageFilter::filterBorderPixels(const SkBitmap& src,
SkBitmap* result,
SkIVector& offset,
const SkIRect& rect,
const SkIRect& srcBounds) const {
switch (fTileMode) {
case SkTileMode::kClamp:
filterPixels<ClampPixelFetcher>(src, result, offset, rect, srcBounds);
@ -356,8 +329,8 @@ void SkMatrixConvolutionImageFilterImpl::filterBorderPixels(const SkBitmap& src,
}
}
sk_sp<SkSpecialImage> SkMatrixConvolutionImageFilterImpl::onFilterImage(const Context& ctx,
SkIPoint* offset) const {
sk_sp<SkSpecialImage> SkMatrixConvolutionImageFilter::onFilterImage(const Context& ctx,
SkIPoint* offset) const {
SkIPoint inputOffset = SkIPoint::Make(0, 0);
sk_sp<SkSpecialImage> input(this->filterInput(0, ctx, &inputOffset));
if (!input) {
@ -500,7 +473,7 @@ sk_sp<SkSpecialImage> SkMatrixConvolutionImageFilterImpl::onFilterImage(const Co
dst);
}
SkIRect SkMatrixConvolutionImageFilterImpl::onFilterNodeBounds(
SkIRect SkMatrixConvolutionImageFilter::onFilterNodeBounds(
const SkIRect& src, const SkMatrix& ctm, MapDirection dir, const SkIRect* inputRect) const {
if (kReverse_MapDirection == dir && inputRect &&
(SkTileMode::kRepeat == fTileMode || SkTileMode::kMirror == fTileMode)) {
@ -520,7 +493,7 @@ SkIRect SkMatrixConvolutionImageFilterImpl::onFilterNodeBounds(
return dst;
}
bool SkMatrixConvolutionImageFilterImpl::affectsTransparentBlack() const {
bool SkMatrixConvolutionImageFilter::affectsTransparentBlack() const {
// It seems that the only rational way for repeat sample mode to work is if the caller
// explicitly restricts the input in which case the input range is explicitly known and
// specified.

View File

@ -1,88 +0,0 @@
/*
* Copyright 2012 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkMatrixConvolutionImageFilter_DEFINED
#define SkMatrixConvolutionImageFilter_DEFINED
#include "include/core/SkImageFilter.h"
#include "include/core/SkPoint.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
class SkBitmap;
enum class SkTileMode;
/*! \class SkMatrixConvolutionImageFilter
Matrix convolution image filter. This filter applies an NxM image
processing kernel to a given input image. This can be used to produce
effects such as sharpening, blurring, edge detection, etc.
DEPRECATED: Use include/effects/SkImageFilters::MatrixConvolution
*/
class SK_API SkMatrixConvolutionImageFilter {
public:
/*! \enum TileMode
* DEPRECATED: Use SkTileMode instead. */
enum TileMode {
kClamp_TileMode = 0, /*!< Clamp to the image's edge pixels. */
kRepeat_TileMode, /*!< Wrap around to the image's opposite edge. */
kClampToBlack_TileMode, /*!< Fill with transparent black. */
kLast_TileMode = kClampToBlack_TileMode,
// TODO: remove kMax - it is non-standard but used by Chromium!
kMax_TileMode = kClampToBlack_TileMode
};
static sk_sp<SkImageFilter> Make(const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& kernelOffset,
TileMode tileMode,
bool convolveAlpha,
sk_sp<SkImageFilter> input,
const SkRect* cropRect = nullptr);
/** Construct a matrix convolution image filter.
@param kernelSize The kernel size in pixels, in each dimension (N by M).
@param kernel The image processing kernel. Must contain N * M
elements, in row order.
@param gain A scale factor applied to each pixel after
convolution. This can be used to normalize the
kernel, if it does not sum to 1.
@param bias A bias factor added to each pixel after convolution.
@param kernelOffset An offset applied to each pixel coordinate before
convolution. This can be used to center the kernel
over the image (e.g., a 3x3 kernel should have an
offset of {1, 1}).
@param tileMode How accesses outside the image are treated. (@see
TileMode). EXPERIMENTAL: kMirror not supported yet.
@param convolveAlpha If true, all channels are convolved. If false,
only the RGB channels are convolved, and
alpha is copied from the source image.
@param input The input image filter. If NULL, the src bitmap
passed to filterImage() is used instead.
@param cropRect The rectangle to which the output processing will be limited.
*/
static sk_sp<SkImageFilter> Make(const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& kernelOffset,
SkTileMode tileMode,
bool convolveAlpha,
sk_sp<SkImageFilter> input,
const SkRect* cropRect = nullptr);
static void RegisterFlattenables();
private:
SkMatrixConvolutionImageFilter() = delete;
};
#endif

View File

@ -127,6 +127,7 @@
SkRegisterImageImageFilterFlattenable();
SkRegisterLightingImageFilterFlattenables();
SkRegisterMagnifierImageFilterFlattenable();
SkRegisterMatrixConvolutionImageFilterFlattenable();
SK_REGISTER_FLATTENABLE(SkLocalMatrixImageFilter);
SK_REGISTER_FLATTENABLE(SkMatrixImageFilter);
}