| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkScalar_DEFINED | 8 #ifndef SkScalar_DEFINED |
| 9 #define SkScalar_DEFINED | 9 #define SkScalar_DEFINED |
| 10 | 10 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 If t is 0, return A | 209 If t is 0, return A |
| 210 If t is 1, return B | 210 If t is 1, return B |
| 211 else interpolate. | 211 else interpolate. |
| 212 t must be [0..SK_Scalar1] | 212 t must be [0..SK_Scalar1] |
| 213 */ | 213 */ |
| 214 static inline SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t) { | 214 static inline SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t) { |
| 215 SkASSERT(t >= 0 && t <= SK_Scalar1); | 215 SkASSERT(t >= 0 && t <= SK_Scalar1); |
| 216 return A + SkScalarMul(B - A, t); | 216 return A + SkScalarMul(B - A, t); |
| 217 } | 217 } |
| 218 | 218 |
| 219 static inline SkScalar SkScalarLog2(SkScalar x) { | |
| 220 static const SkScalar log2_conversion_factor = SkScalarDiv(1, SkScalarLog(2)
); | |
| 221 | |
| 222 return SkScalarMul(SkScalarLog(x), log2_conversion_factor); | |
| 223 } | |
| 224 | |
| 225 /** Interpolate along the function described by (keys[length], values[length]) | 219 /** Interpolate along the function described by (keys[length], values[length]) |
| 226 for the passed searchKey. SearchKeys outside the range keys[0]-keys[Length] | 220 for the passed searchKey. SearchKeys outside the range keys[0]-keys[Length] |
| 227 clamp to the min or max value. This function was inspired by a desire | 221 clamp to the min or max value. This function was inspired by a desire |
| 228 to change the multiplier for thickness in fakeBold; therefore it assumes | 222 to change the multiplier for thickness in fakeBold; therefore it assumes |
| 229 the number of pairs (length) will be small, and a linear search is used. | 223 the number of pairs (length) will be small, and a linear search is used. |
| 230 Repeated keys are allowed for discontinuous functions (so long as keys is | 224 Repeated keys are allowed for discontinuous functions (so long as keys is |
| 231 monotonically increasing), and if key is the value of a repeated scalar in | 225 monotonically increasing), and if key is the value of a repeated scalar in |
| 232 keys, the first one will be used. However, that may change if a binary | 226 keys, the first one will be used. However, that may change if a binary |
| 233 search is used. | 227 search is used. |
| 234 */ | 228 */ |
| 235 SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[], | 229 SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[], |
| 236 const SkScalar values[], int length); | 230 const SkScalar values[], int length); |
| 237 | 231 |
| 238 /* | 232 /* |
| 239 * Helper to compare an array of scalars. | 233 * Helper to compare an array of scalars. |
| 240 */ | 234 */ |
| 241 static inline bool SkScalarsEqual(const SkScalar a[], const SkScalar b[], int n)
{ | 235 static inline bool SkScalarsEqual(const SkScalar a[], const SkScalar b[], int n)
{ |
| 242 SkASSERT(n >= 0); | 236 SkASSERT(n >= 0); |
| 243 for (int i = 0; i < n; ++i) { | 237 for (int i = 0; i < n; ++i) { |
| 244 if (a[i] != b[i]) { | 238 if (a[i] != b[i]) { |
| 245 return false; | 239 return false; |
| 246 } | 240 } |
| 247 } | 241 } |
| 248 return true; | 242 return true; |
| 249 } | 243 } |
| 250 | 244 |
| 251 #endif | 245 #endif |
| OLD | NEW |