1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkScalar.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,36 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2010 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#include "SkMath.h" 1.14 +#include "SkScalar.h" 1.15 + 1.16 +SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[], 1.17 + const SkScalar values[], int length) { 1.18 + SkASSERT(length > 0); 1.19 + SkASSERT(keys != NULL); 1.20 + SkASSERT(values != NULL); 1.21 +#ifdef SK_DEBUG 1.22 + for (int i = 1; i < length; i++) 1.23 + SkASSERT(keys[i] >= keys[i-1]); 1.24 +#endif 1.25 + int right = 0; 1.26 + while (right < length && searchKey > keys[right]) 1.27 + right++; 1.28 + // Could use sentinel values to eliminate conditionals, but since the 1.29 + // tables are taken as input, a simpler format is better. 1.30 + if (length == right) 1.31 + return values[length-1]; 1.32 + if (0 == right) 1.33 + return values[0]; 1.34 + // Otherwise, interpolate between right - 1 and right. 1.35 + SkScalar rightKey = keys[right]; 1.36 + SkScalar leftKey = keys[right-1]; 1.37 + SkScalar fract = SkScalarDiv(searchKey-leftKey,rightKey-leftKey); 1.38 + return SkScalarInterp(values[right-1], values[right], fract); 1.39 +}