diff options
author | Mike Klein <mtklein@chromium.org> | 2017-08-09 18:23:25 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-10 14:34:35 +0000 |
commit | c2f876bb8d8991e428467c1d7d24152eea629770 (patch) | |
tree | 5f94199f289e68b418dfc6cafc9516e81141454d /src/core/SkColorLookUpTable.cpp | |
parent | f4874bc5c14242dc482882252f8a8d482aa11508 (diff) |
Replace interp() with clut_{3,4}D stages.
I tried to follow exactly the same strategy as a start.
(Though I did fix the off-by-one dimensions.)
It does rather look like we only need 3D and 4D now
that I've looked at the call sites.
Looks like about a 20% speedup.
Change-Id: I8b1af64750ad1750716ee1ab0767e64591c7206a
Reviewed-on: https://skia-review.googlesource.com/32842
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/core/SkColorLookUpTable.cpp')
-rw-r--r-- | src/core/SkColorLookUpTable.cpp | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/src/core/SkColorLookUpTable.cpp b/src/core/SkColorLookUpTable.cpp index c558afb0e1..f376621e7f 100644 --- a/src/core/SkColorLookUpTable.cpp +++ b/src/core/SkColorLookUpTable.cpp @@ -18,59 +18,3 @@ SkColorLookUpTable::SkColorLookUpTable(uint8_t inputChannels, const uint8_t limi SkASSERT(fLimits[i] > 1); } } - -// Our general strategy is to recursively interpolate each dimension, -// accumulating the index to sample at, and our current pixel stride to help accumulate the index. -template <int dim> -static Sk4f interp_dimension(const float* table, const uint8_t* limits, - const float* src, int index, int stride) { - // We'd logically like to sample this dimension at x. - int limit = limits[dim]; - float x = src[dim] * (limit - 1); - - // We can't index an array by a float (darn) so we have to snap to nearby integers lo and hi. - int lo = (int)(x ), - hi = (int)(x + 0.9999f); - - // Recursively sample at lo and hi. - Sk4f L = interp_dimension<dim-1>(table,limits,src, stride*lo + index, stride*limit), - H = interp_dimension<dim-1>(table,limits,src, stride*hi + index, stride*limit); - - // Linearly interpolate those colors based on their distance to x. - float t = (x - lo); - return (1 - t)*L + t*H; -} - -// Bottom out our recursion at 0 dimensions, i.e. just return the color at index. -template <> -Sk4f interp_dimension<-1>(const float* table, const uint8_t* limits, - const float* src, int index, int stride) { - return { - table[3*index+0], - table[3*index+1], - table[3*index+2], - 0.0f, - }; -} - -template <int dim> -static Sk4f interp_dimension(const float* table, const uint8_t* limits, const float* src) { - // Start our accumulated index and stride off at their identity values, 0 and 1. - return interp_dimension<dim>(table, limits, src, 0,1); -} - -void SkColorLookUpTable::interp(float* dst, const float* src) const { - Sk4f rgb; - switch (fInputChannels-1) { - case 0: rgb = interp_dimension<0>(this->table(), fLimits, src); break; - case 1: rgb = interp_dimension<1>(this->table(), fLimits, src); break; - case 2: rgb = interp_dimension<2>(this->table(), fLimits, src); break; - case 3: rgb = interp_dimension<3>(this->table(), fLimits, src); break; - default: SkDEBUGFAIL("oops"); return; - } - - rgb = Sk4f::Max(0, Sk4f::Min(rgb, 1)); - dst[0] = rgb[0]; - dst[1] = rgb[1]; - dst[2] = rgb[2]; -} |