Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Unified Diff: src/core/SkBitmapFilter.h

Issue 18978014: Working plumb of image scaling: (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: nits from robert Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/gmslides.gypi ('k') | src/core/SkBitmapFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmapFilter.h
diff --git a/src/core/SkBitmapFilter.h b/src/core/SkBitmapFilter.h
index 82734200e1cdebcdb54f1e8b52a3b25989cf117a..1a002b09ee8ee438a6fcef1598dfc7b9ec877a49 100644
--- a/src/core/SkBitmapFilter.h
+++ b/src/core/SkBitmapFilter.h
@@ -22,23 +22,26 @@ class SkBitmapFilter {
public:
SkBitmapFilter(float width)
: fWidth(width), fInvWidth(1.f/width) {
- precomputed = false;
+ fPrecomputed = false;
+ fLookupMultiplier = this->invWidth() * (SKBITMAP_FILTER_TABLE_SIZE-1);
}
SkFixed lookup( float x ) const {
- if (!precomputed) {
+ if (!fPrecomputed) {
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 {
- if (!precomputed) {
+ SkScalar lookupScalar( float x ) const {
+ if (!fPrecomputed) {
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;
+
+ float fLookupMultiplier;
- mutable bool precomputed;
+ mutable bool fPrecomputed;
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;
+ fPrecomputed = true;
SkFixed *ftp = fFilterTable;
- float *ftp_float = fFilterTableFloat;
+ SkScalar *ftpScalar = 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;
+ *ftpScalar++ = SkFloatToScalar(filter_value);
*ftp++ = SkFloatToFixed(filter_value);
}
}
« no previous file with comments | « gyp/gmslides.gypi ('k') | src/core/SkBitmapFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698