Remove legacy code for box blur.
Change-Id: I2a4ca5d623adcf923981dd27be40dcbf81152954 Reviewed-on: https://skia-review.googlesource.com/48583 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
parent
6b6674d321
commit
07cb2a2f87
@ -58,144 +58,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// Old slower version of Box which uses 64 bit multiply instead of 32 bit multiple.
|
||||
// Controlled by SK_SUPPORT_LEGACY_SLOW_SMALL_BLUR
|
||||
class PlanBox32 final : public PlanningInterface {
|
||||
public:
|
||||
explicit PlanBox32(double sigma) {
|
||||
// Calculate the radius from sigma. Taken from the old code until something better is
|
||||
// figured out.
|
||||
auto possibleRadius = 1.5 * sigma - 0.5;
|
||||
auto radius = std::max(std::numeric_limits<double>::epsilon(), possibleRadius);
|
||||
auto outerRadius = std::ceil(radius);
|
||||
auto outerWindow = 2 * outerRadius + 1;
|
||||
auto outerFactor = (1 - (outerRadius - radius)) / outerWindow;
|
||||
fOuterWeight = static_cast<uint64_t>(round(outerFactor * (1ull << 32)));
|
||||
|
||||
auto innerRadius = outerRadius - 1;
|
||||
auto innerWindow = 2 * innerRadius + 1;
|
||||
auto innerFactor = (1 - (radius - innerRadius)) / innerWindow;
|
||||
fInnerWeight = static_cast<uint64_t>(round(innerFactor * (1ull << 32)));
|
||||
|
||||
// Sliding window is defined by the relationship between the outer and inner widows.
|
||||
// In the single window case, you add the element on the right, and subtract the element on
|
||||
// the left. But, because two windows are used, this relationship is more complicated; an
|
||||
// element is added from the right of the outer window, and subtracted from the left of the
|
||||
// inner window. Because innerWindow = outerWindow - 2, the distance between
|
||||
// the left and right in the two window case is outerWindow - 1.
|
||||
fSlidingWindow = static_cast<size_t>(outerWindow - 1);
|
||||
}
|
||||
|
||||
size_t bufferSize() const override { return 0; }
|
||||
|
||||
// Remember that sliding window = window - 1. Therefore, radius = sliding window / 2.
|
||||
size_t border() const override { return fSlidingWindow / 2; }
|
||||
|
||||
bool needsBlur() const override { return true; }
|
||||
|
||||
BlurScanInterface* makeBlurScan(
|
||||
SkArenaAlloc* alloc, size_t width, uint32_t* buffer) const override
|
||||
{
|
||||
size_t noChangeCount;
|
||||
size_t trailingEdgeZeroCount;
|
||||
|
||||
// The relation between the slidingWindow and the width dictates two operating modes.
|
||||
// * width >= slidingWindow - both sides of the window are contained in the image while
|
||||
// scanning. Therefore, we assume that slidingWindow zeros are consumed on the trailing
|
||||
// edge of the window. After this count, then both edges are traversing the image.
|
||||
// * slidingWindow > width - both sides of the window are off the image while scanning
|
||||
// the middle. The front edge of the window can only travel width until it falls off the
|
||||
// image. At this point, both edges of the window are off the image consuming zeros
|
||||
// and therefore, the destination value does not change. The scan produces unchanged
|
||||
// values until the trailing edge of the window enters the image. This count is
|
||||
// slidingWindow - width.
|
||||
if (width >= fSlidingWindow) {
|
||||
noChangeCount = 0;
|
||||
trailingEdgeZeroCount = fSlidingWindow;
|
||||
} else {
|
||||
noChangeCount = fSlidingWindow - width;
|
||||
trailingEdgeZeroCount = width;
|
||||
}
|
||||
return alloc->make<Box>(fOuterWeight, fInnerWeight, noChangeCount, trailingEdgeZeroCount);
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
class Box final : public BlurScanInterface {
|
||||
public:
|
||||
Box(uint64_t outerWeight, uint64_t innerWeight,
|
||||
size_t noChangeCount, size_t trailingEdgeZeroCount)
|
||||
: fOuterWeight{outerWeight}
|
||||
, fInnerWeight{innerWeight}
|
||||
, fNoChangeCount{noChangeCount}
|
||||
, fTrailingEdgeZeroCount{trailingEdgeZeroCount} { }
|
||||
|
||||
void blur(const uint8_t* src, size_t srcStride, const uint8_t* srcEnd,
|
||||
uint8_t* dst, size_t dstStride, uint8_t* dstEnd) const override {
|
||||
auto rightOuter = src;
|
||||
auto dstCursor = dst;
|
||||
|
||||
uint32_t outerSum = 0;
|
||||
uint32_t innerSum = 0;
|
||||
for (size_t i = 0; i < fTrailingEdgeZeroCount; i++) {
|
||||
innerSum = outerSum;
|
||||
outerSum += *rightOuter;
|
||||
*dstCursor = this->interpolateSums(outerSum, innerSum);
|
||||
|
||||
rightOuter += srcStride;
|
||||
dstCursor += dstStride;
|
||||
}
|
||||
|
||||
// slidingWindow > width
|
||||
for (size_t i = 0; i < fNoChangeCount; i++) {
|
||||
*dstCursor = this->interpolateSums(outerSum, innerSum);;
|
||||
dstCursor += dstStride;
|
||||
}
|
||||
|
||||
// width > slidingWindow
|
||||
auto leftInner = src;
|
||||
while (rightOuter < srcEnd) {
|
||||
innerSum = outerSum - *leftInner;
|
||||
outerSum += *rightOuter;
|
||||
*dstCursor = this->interpolateSums(outerSum, innerSum);
|
||||
outerSum -= *leftInner;
|
||||
|
||||
rightOuter += srcStride;
|
||||
leftInner += srcStride;
|
||||
dstCursor += dstStride;
|
||||
}
|
||||
|
||||
auto leftOuter = srcEnd;
|
||||
dstCursor = dstEnd;
|
||||
outerSum = 0;
|
||||
for (size_t i = 0; i < fTrailingEdgeZeroCount; i++) {
|
||||
leftOuter -= srcStride;
|
||||
dstCursor -= dstStride;
|
||||
|
||||
innerSum = outerSum;
|
||||
outerSum += *leftOuter;
|
||||
*dstCursor = this->interpolateSums(outerSum, innerSum);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr uint64_t kHalf = static_cast<uint64_t>(1) << 31;
|
||||
|
||||
uint8_t interpolateSums(uint32_t outerSum, uint32_t innerSum) const {
|
||||
return SkTo<uint8_t>((fOuterWeight * outerSum + fInnerWeight * innerSum + kHalf) >> 32);
|
||||
}
|
||||
uint64_t fOuterWeight;
|
||||
uint64_t fInnerWeight;
|
||||
size_t fNoChangeCount;
|
||||
size_t fTrailingEdgeZeroCount;
|
||||
};
|
||||
private:
|
||||
uint64_t fOuterWeight;
|
||||
uint64_t fInnerWeight;
|
||||
size_t fSlidingWindow;
|
||||
};
|
||||
|
||||
|
||||
class PlanBox final : public PlanningInterface {
|
||||
public:
|
||||
explicit PlanBox(double sigma) {
|
||||
@ -656,11 +518,7 @@ static PlanningInterface* make_plan(SkArenaAlloc* alloc, double sigma) {
|
||||
if (3 * sigma <= 1) {
|
||||
plan = alloc->make<None>();
|
||||
} else if (sigma < kSmallSigma) {
|
||||
#if defined(SK_SUPPORT_LEGACY_SLOW_SMALL_BLUR)
|
||||
plan = alloc->make<PlanBox32>(sigma);
|
||||
#else
|
||||
plan = alloc->make<PlanBox>(sigma);
|
||||
#endif
|
||||
plan = alloc->make<PlanBox>(sigma);
|
||||
} else {
|
||||
plan = alloc->make<PlanGauss>(sigma);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user