Chromium Code Reviews| Index: src/core/SkBitmapFilter.h |
| diff --git a/src/core/SkBitmapFilter.h b/src/core/SkBitmapFilter.h |
| index 82734200e1cdebcdb54f1e8b52a3b25989cf117a..86884a313d7249854c1631c755795aac57d669e1 100644 |
| --- a/src/core/SkBitmapFilter.h |
| +++ b/src/core/SkBitmapFilter.h |
| @@ -23,22 +23,25 @@ class SkBitmapFilter { |
| SkBitmapFilter(float width) |
| : fWidth(width), fInvWidth(1.f/width) { |
| precomputed = false; |
|
robertphillips
2013/07/12 19:42:31
this->invWidth()
humper
2013/07/12 21:12:03
Done.
|
| + fLookupMultiplier = invWidth() * (SKBITMAP_FILTER_TABLE_SIZE-1); |
| } |
| SkFixed lookup( float x ) const { |
| if (!precomputed) { |
| precomputeTable(); |
| } |
| - int filter_idx = int(fabsf(x * invWidth() * SKBITMAP_FILTER_TABLE_SIZE)); |
| - return fFilterTable[ SkTMin(filter_idx, SKBITMAP_FILTER_TABLE_SIZE-1) ]; |
| + int filter_idx = int(sk_float_abs(x * fLookupMultiplier)); |
| + SkASSERT(filter_idx < SKBITMAP_FILTER_TABLE_SIZE); |
| + return fFilterTable[ filter_idx ]; |
| } |
| - float lookupFloat( float x ) const { |
| + SkScalar lookupScalar( float x ) const { |
| if (!precomputed) { |
| precomputeTable(); |
| } |
| - int filter_idx = int(fabsf(x * invWidth() * SKBITMAP_FILTER_TABLE_SIZE)); |
| - return fFilterTableFloat[ SkTMin(filter_idx, SKBITMAP_FILTER_TABLE_SIZE-1) ]; |
| + int filter_idx = int(sk_float_abs(x * fLookupMultiplier)); |
| + SkASSERT(filter_idx < SKBITMAP_FILTER_TABLE_SIZE); |
| + return fFilterTableScalar[ filter_idx ]; |
| } |
| float width() const { return fWidth; } |
| @@ -48,19 +51,21 @@ class SkBitmapFilter { |
| protected: |
| float fWidth; |
| float fInvWidth; |
| + |
| + int fLookupMultiplier; |
| mutable bool precomputed; |
|
robertphillips
2013/07/12 19:42:31
fPrecomputed
humper
2013/07/12 21:12:03
Done.
|
| mutable SkFixed fFilterTable[SKBITMAP_FILTER_TABLE_SIZE]; |
| - mutable float fFilterTableFloat[SKBITMAP_FILTER_TABLE_SIZE]; |
| + mutable SkScalar fFilterTableScalar[SKBITMAP_FILTER_TABLE_SIZE]; |
| private: |
| void precomputeTable() const { |
| precomputed = true; |
| SkFixed *ftp = fFilterTable; |
|
robertphillips
2013/07/12 19:42:31
ftpScalar
humper
2013/07/12 21:12:03
Done.
|
| - float *ftp_float = fFilterTableFloat; |
| + SkScalar *ftp_scalar = fFilterTableScalar; |
| for (int x = 0; x < SKBITMAP_FILTER_TABLE_SIZE; ++x) { |
| float fx = ((float)x + .5f) * this->width() / SKBITMAP_FILTER_TABLE_SIZE; |
| float filter_value = evaluate(fx); |
| - *ftp_float++ = filter_value; |
| + *ftp_scalar++ = SkFloatToScalar(filter_value); |
| *ftp++ = SkFloatToFixed(filter_value); |
| } |
| } |