Remove SkClampMax
Change-Id: I9709dfdfd6069d46c331d08e181e36cc9a21e71a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/269149
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 1162770..2f50058 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -7,6 +7,7 @@
Milestone 82
<Insert new notes here- top is most recent.>
+ * Removed SkClampMax.
* Removed SkScalarClampMax and SkScalarPin.
* Removed SkMax32 and SkMin32.
* Removed SkMaxScalar and SkMinScalar.
diff --git a/include/core/SkMath.h b/include/core/SkMath.h
index 33d929e..41afb5a 100644
--- a/include/core/SkMath.h
+++ b/include/core/SkMath.h
@@ -21,24 +21,6 @@
///////////////////////////////////////////////////////////////////////////////
-/** Given an integer and a positive (max) integer, return the value
- * pinned against 0 and max, inclusive.
- * @param value The value we want returned pinned between [0...max]
- * @param max The positive max value
- * @return 0 if value < 0, max if value > max, else value
- */
-static inline int SkClampMax(int value, int max) {
- // ensure that max is positive
- SkASSERT(max >= 0);
- if (value < 0) {
- value = 0;
- }
- if (value > max) {
- value = max;
- }
- return value;
-}
-
/**
* Returns true if value is a power of 2. Does not explicitly check for
* value <= 0.
diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp
index 09a75f2..683f023 100755
--- a/src/core/SkBitmapProcState.cpp
+++ b/src/core/SkBitmapProcState.cpp
@@ -36,7 +36,7 @@
{
const SkBitmapProcStateAutoMapper mapper(s, x, y);
const unsigned maxY = s.fPixmap.height() - 1;
- dstY = SkClampMax(mapper.intY(), maxY);
+ dstY = SkTPin<int>(mapper.intY(), 0, maxY);
fx = mapper.fractionalIntX();
}
@@ -68,7 +68,7 @@
}
} else {
for (int i = 0; i < count; ++i) {
- dst[i] = src[SkClampMax(SkFractionalIntToInt(fx), maxX)];
+ dst[i] = src[SkTPin<int>(SkFractionalIntToInt(fx), 0, maxX)];
fx += dx;
}
}
@@ -311,7 +311,7 @@
const int maxX = s.fPixmap.width() - 1;
const int maxY = s.fPixmap.height() - 1;
int ix = s.fFilterOneX + x;
- int iy = SkClampMax(s.fFilterOneY + y, maxY);
+ int iy = SkTPin(s.fFilterOneY + y, 0, maxY);
const SkPMColor* row = s.fPixmap.addr32(0, iy);
// clamp to the left
@@ -458,7 +458,7 @@
const int stopY = s.fPixmap.height();
switch (s.fTileModeY) {
case SkTileMode::kClamp:
- iY0 = SkClampMax(yTemp, stopY-1);
+ iY0 = SkTPin(yTemp, 0, stopY-1);
break;
case SkTileMode::kRepeat:
iY0 = sk_int_mod(yTemp, stopY);
@@ -483,7 +483,7 @@
switch (s.fTileModeY) {
case SkTileMode::kClamp:
- iY2 = SkClampMax(iY2, stopY-1);
+ iY2 = SkTPin(iY2, 0, stopY-1);
break;
case SkTileMode::kRepeat:
iY2 = sk_int_mod(iY2, stopY);
diff --git a/src/core/SkBitmapProcState_matrixProcs.cpp b/src/core/SkBitmapProcState_matrixProcs.cpp
index 0e0cd6d..2f89c87 100755
--- a/src/core/SkBitmapProcState_matrixProcs.cpp
+++ b/src/core/SkBitmapProcState_matrixProcs.cpp
@@ -243,14 +243,14 @@
}
static unsigned clamp(SkFixed fx, int max) {
- return SkClampMax(fx >> 16, max);
+ return SkTPin(fx >> 16, 0, max);
}
#if defined(SK_SUPPORT_LEGACY_TILED_BITMAPS)
// For use with extract_low_bits_general(), where clamp() above expects extract_low_bits_clamp_clamp()
static unsigned general_clamp(SkFixed fx, int max)
{
- return repeat(SkClampMax(fx, 0xFFFF), max);
+ return repeat(SkTPin(fx, 0, 0xFFFF), max);
}
#endif
diff --git a/src/core/SkBlurMask.cpp b/src/core/SkBlurMask.cpp
index 9963fff..9d51f55 100644
--- a/src/core/SkBlurMask.cpp
+++ b/src/core/SkBlurMask.cpp
@@ -612,7 +612,7 @@
finalValue /= windowSum;
uint8_t *outPixel = dstPixels + (x-pad)*dstWidth + y; // transposed output
int integerPixel = int(finalValue + 0.5f);
- *outPixel = SkClampMax( SkClampPos(integerPixel), 255 );
+ *outPixel = SkTPin(SkClampPos(integerPixel), 0, 255);
}
}
diff --git a/src/effects/SkEmbossMask.cpp b/src/effects/SkEmbossMask.cpp
index 6b8f622..6fcbce3 100644
--- a/src/effects/SkEmbossMask.cpp
+++ b/src/effects/SkEmbossMask.cpp
@@ -91,7 +91,7 @@
int hilite = (2 * dot - lz_dot8) * lz_dot8 >> 8;
if (hilite > 0) {
// pin hilite to 255, since our fast math is also a little sloppy
- hilite = SkClampMax(hilite, 255);
+ hilite = std::min(hilite, 255);
// specular is 4.4
// would really like to compute the fractional part of this
diff --git a/src/effects/imagefilters/SkLightingImageFilter.cpp b/src/effects/imagefilters/SkLightingImageFilter.cpp
index e17daf1..7d95eaa 100644
--- a/src/effects/imagefilters/SkLightingImageFilter.cpp
+++ b/src/effects/imagefilters/SkLightingImageFilter.cpp
@@ -167,9 +167,9 @@
colorScale = SkTPin(colorScale, 0.0f, SK_Scalar1);
SkPoint3 color = lightColor.makeScale(colorScale);
return SkPackARGB32(255,
- SkClampMax(SkScalarRoundToInt(color.fX), 255),
- SkClampMax(SkScalarRoundToInt(color.fY), 255),
- SkClampMax(SkScalarRoundToInt(color.fZ), 255));
+ SkTPin(SkScalarRoundToInt(color.fX), 0, 255),
+ SkTPin(SkScalarRoundToInt(color.fY), 0, 255),
+ SkTPin(SkScalarRoundToInt(color.fZ), 0, 255));
}
private:
SkScalar fKD;
@@ -191,10 +191,10 @@
SkScalar colorScale = fKS * SkScalarPow(normal.dot(halfDir), fShininess);
colorScale = SkTPin(colorScale, 0.0f, SK_Scalar1);
SkPoint3 color = lightColor.makeScale(colorScale);
- return SkPackARGB32(SkClampMax(SkScalarRoundToInt(max_component(color)), 255),
- SkClampMax(SkScalarRoundToInt(color.fX), 255),
- SkClampMax(SkScalarRoundToInt(color.fY), 255),
- SkClampMax(SkScalarRoundToInt(color.fZ), 255));
+ return SkPackARGB32(SkTPin(SkScalarRoundToInt(max_component(color)), 0, 255),
+ SkTPin(SkScalarRoundToInt(color.fX), 0, 255),
+ SkTPin(SkScalarRoundToInt(color.fY), 0, 255),
+ SkTPin(SkScalarRoundToInt(color.fZ), 0, 255));
}
private:
SkScalar fKS;
diff --git a/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp b/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp
index 268ac53..4783d25 100644
--- a/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp
@@ -291,11 +291,11 @@
}
}
int a = convolveAlpha
- ? SkClampMax(SkScalarFloorToInt(sumA * fGain + fBias), 255)
+ ? SkTPin(SkScalarFloorToInt(sumA * fGain + fBias), 0, 255)
: 255;
- int r = SkClampMax(SkScalarFloorToInt(sumR * fGain + fBias), a);
- int g = SkClampMax(SkScalarFloorToInt(sumG * fGain + fBias), a);
- int b = SkClampMax(SkScalarFloorToInt(sumB * fGain + fBias), a);
+ int r = SkTPin(SkScalarFloorToInt(sumR * fGain + fBias), 0, a);
+ int g = SkTPin(SkScalarFloorToInt(sumG * fGain + fBias), 0, a);
+ int b = SkTPin(SkScalarFloorToInt(sumB * fGain + fBias), 0, a);
if (!convolveAlpha) {
a = SkGetPackedA32(PixelFetcher::fetch(src, x, y, bounds));
*dptr++ = SkPreMultiplyARGB(a, r, g, b);
diff --git a/tests/BlurTest.cpp b/tests/BlurTest.cpp
index 1c85e31..4e80266 100644
--- a/tests/BlurTest.cpp
+++ b/tests/BlurTest.cpp
@@ -239,7 +239,7 @@
sum += gaussian(j, gaussianSigma) * step(i-j, stepMin, stepMax);
}
- result[i] = SkClampMax(SkClampPos(int(sum + 0.5f)), 255);
+ result[i] = SkTPin(SkClampPos(int(sum + 0.5f)), 0, 255);
}
}
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index 26eff95..ed358de 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -408,15 +408,6 @@
REPORTER_ASSERT(reporter, SkScalarIsNaN(x));
}
- for (i = 0; i < 1000; i++) {
- int value = rand.nextS() >> 16;
- int max = rand.nextU() >> 16;
-
- int clamp = SkClampMax(value, max);
- int clamp2 = value < 0 ? 0 : (value > max ? max : value);
- REPORTER_ASSERT(reporter, clamp == clamp2);
- }
-
for (i = 0; i < 10000; i++) {
SkPoint p;