diff options
-rw-r--r-- | src/core/SkBitmapFilter.h | 33 | ||||
-rw-r--r-- | src/core/SkBitmapScaler.cpp | 50 |
2 files changed, 3 insertions, 80 deletions
diff --git a/src/core/SkBitmapFilter.h b/src/core/SkBitmapFilter.h index dc3ea693b8..6fa8edde34 100644 --- a/src/core/SkBitmapFilter.h +++ b/src/core/SkBitmapFilter.h @@ -12,9 +12,7 @@ #include "SkMath.h" #include "SkScalar.h" -#ifndef SK_SUPPORT_LEGACY_BITMAP_FILTER #include "SkNx.h" -#endif // size of the precomputed bitmap filter tables for high quality filtering. // Used to precompute the shape of the filter kernel. @@ -52,7 +50,6 @@ public: float invWidth() const { return fInvWidth; } virtual float evaluate(float x) const = 0; -#ifndef SK_SUPPORT_LEGACY_BITMAP_FILTER virtual float evaluate_n(float val, float diff, int count, float* output) const { float sum = 0; for (int index = 0; index < count; index++) { @@ -63,7 +60,6 @@ public: } return sum; } -#endif protected: float fWidth; @@ -90,9 +86,6 @@ private: class SkMitchellFilter final : public SkBitmapFilter { public: -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - SkMitchellFilter() : INHERITED(2), B(1.f / 3), C(1.f / 3) {} -#else SkMitchellFilter() : INHERITED(2) , fB(1.f / 3.f) @@ -105,39 +98,20 @@ public: , fB2(-18 + 12*fB + 6*fC) , fD2(6 - 2*fB) {} -#endif float evaluate(float x) const override { x = fabsf(x); if (x > 2.f) { return 0; } else if (x > 1.f) { -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - return ((-B - 6*C) * x*x*x + (6*B + 30*C) * x*x + - (-12*B - 48*C) * x + (8*B + 24*C)) * (1.f/6.f); -#else return (((fA1 * x + fB1) * x + fC1) * x + fD1) * (1.f/6.f); -#endif } else { -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - return ((12 - 9*B - 6*C) * x*x*x + - (-18 + 12*B + 6*C) * x*x + - (6 - 2*B)) * (1.f/6.f); -#else return ((fA2 * x + fB2) * x*x + fD2) * (1.f/6.f); -#endif } } -#ifndef SK_SUPPORT_LEGACY_BITMAP_FILTER - // TODO : native Sk4f abs - static Sk4f abs(const Sk4f& x) { - Sk4f neg = x < Sk4f(0); - return neg.thenElse(Sk4f(0) - x, x); - } - Sk4f evalcore_n(const Sk4f& val) const { - Sk4f x = abs(val); + Sk4f x = val.abs(); Sk4f over2 = x > Sk4f(2); Sk4f over1 = x > Sk4f(1); Sk4f poly1 = (((Sk4f(fA1) * x + Sk4f(fB1)) * x + Sk4f(fC1)) * x + Sk4f(fD1)) @@ -166,16 +140,11 @@ public: result += INHERITED::evaluate_n(val, diff, count, output); return result; } -#endif protected: -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - float B, C; -#else float fB, fC; float fA1, fB1, fC1, fD1; float fA2, fB2, fD2; -#endif private: typedef SkBitmapFilter INHERITED; }; diff --git a/src/core/SkBitmapScaler.cpp b/src/core/SkBitmapScaler.cpp index dc04691c79..c69ac2a950 100644 --- a/src/core/SkBitmapScaler.cpp +++ b/src/core/SkBitmapScaler.cpp @@ -144,42 +144,20 @@ void SkResizeFilter::computeFilters(int srcSize, // downscale should "cover" the pixels around the pixel with *its center* // at coordinates (2.5, 2.5) in the source, not those around (0, 0). // Hence we need to scale coordinates (0.5, 0.5), not (0, 0). -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - int destLimit = SkScalarTruncToInt(SkScalarCeilToScalar(destSubsetHi) - - SkScalarFloorToScalar(destSubsetLo)); -#else destSubsetLo = SkScalarFloorToScalar(destSubsetLo); destSubsetHi = SkScalarCeilToScalar(destSubsetHi); float srcPixel = (destSubsetLo + 0.5f) * invScale; int destLimit = SkScalarTruncToInt(destSubsetHi - destSubsetLo); -#endif output->reserveAdditional(destLimit, SkScalarCeilToInt(destLimit * srcSupport * 2)); -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - for (int destSubsetI = SkScalarFloorToInt(destSubsetLo); destSubsetI < SkScalarCeilToInt(destSubsetHi); - destSubsetI++) -#else for (int destI = 0; destI < destLimit; srcPixel += invScale, destI++) -#endif { // Compute the (inclusive) range of source pixels the filter covers. -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - float srcPixel = (static_cast<float>(destSubsetI) + 0.5f) * invScale; - int srcBegin = SkTMax(0, SkScalarFloorToInt(srcPixel - srcSupport)); - int srcEnd = SkTMin(srcSize - 1, SkScalarCeilToInt(srcPixel + srcSupport)); -#else float srcBegin = SkTMax(0.f, SkScalarFloorToScalar(srcPixel - srcSupport)); float srcEnd = SkTMin(srcSize - 1.f, SkScalarCeilToScalar(srcPixel + srcSupport)); -#endif // Compute the unnormalized filter value at each location of the source // it covers. -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - float filterSum = 0.0f; // Sub of the filter values for normalizing. - int filterCount = srcEnd - srcBegin + 1; - filterValuesArray.reset(filterCount); - for (int curFilterPixel = srcBegin; curFilterPixel <= srcEnd; - curFilterPixel++) { -#endif + // Sum of the filter values for normalizing. // Distance from the center of the filter, this is the filter coordinate // in source space. We also need to consider the center of the pixel @@ -187,42 +165,22 @@ void SkResizeFilter::computeFilters(int srcSize, // example used above the distance from the center of the filter to // the pixel with coordinates (2, 2) should be 0, because its center // is at (2.5, 2.5). -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - float srcFilterDist = - ((static_cast<float>(curFilterPixel) + 0.5f) - srcPixel); - - // Since the filter really exists in dest space, map it there. - float destFilterDist = srcFilterDist * clampedScale; - - // Compute the filter value at that location. - float filterValue = fBitmapFilter->evaluate(destFilterDist); - filterValuesArray[curFilterPixel - srcBegin] = filterValue; - - filterSum += filterValue; - } -#else float destFilterDist = (srcBegin + 0.5f - srcPixel) * clampedScale; int filterCount = SkScalarTruncToInt(srcEnd - srcBegin) + 1; SkASSERT(filterCount > 0); filterValuesArray.reset(filterCount); float filterSum = fBitmapFilter->evaluate_n(destFilterDist, clampedScale, filterCount, filterValuesArray.begin()); -#endif + // The filter must be normalized so that we don't affect the brightness of // the image. Convert to normalized fixed point. int fixedSum = 0; fixedFilterValuesArray.reset(filterCount); const float* filterValues = filterValuesArray.begin(); SkConvolutionFilter1D::ConvolutionFixed* fixedFilterValues = fixedFilterValuesArray.begin(); -#ifndef SK_SUPPORT_LEGACY_BITMAP_FILTER float invFilterSum = 1 / filterSum; -#endif for (int fixedI = 0; fixedI < filterCount; fixedI++) { -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - int curFixed = SkConvolutionFilter1D::FloatToFixed(filterValues[fixedI] / filterSum); -#else int curFixed = SkConvolutionFilter1D::FloatToFixed(filterValues[fixedI] * invFilterSum); -#endif fixedSum += curFixed; fixedFilterValues[fixedI] = SkToS16(curFixed); } @@ -237,11 +195,7 @@ void SkResizeFilter::computeFilters(int srcSize, fixedFilterValues[filterCount / 2] += leftovers; // Now it's ready to go. -#ifdef SK_SUPPORT_LEGACY_BITMAP_FILTER - output->AddFilter(srcBegin, fixedFilterValues, filterCount); -#else output->AddFilter(SkScalarFloorToInt(srcBegin), fixedFilterValues, filterCount); -#endif } if (convolveProcs.fApplySIMDPadding) { |