OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
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 #include "SkMipMap.h" | 8 #include "SkMipMap.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 srcBM = dstBM; | 218 srcBM = dstBM; |
219 addr += height * rowBytes; | 219 addr += height * rowBytes; |
220 } | 220 } |
221 SkASSERT(addr == baseAddr + size); | 221 SkASSERT(addr == baseAddr + size); |
222 | 222 |
223 return mipmap; | 223 return mipmap; |
224 } | 224 } |
225 | 225 |
226 /////////////////////////////////////////////////////////////////////////////// | 226 /////////////////////////////////////////////////////////////////////////////// |
227 | 227 |
228 //static int gCounter; | 228 #ifdef SK_SUPPORT_LEGACY_MIPLEVELCHOICE |
229 | |
230 static SkFixed compute_level(SkScalar scale) { | 229 static SkFixed compute_level(SkScalar scale) { |
231 SkScalar inv = SkScalarAbs(SkScalarInvert(scale)); | 230 SkScalar inv = SkScalarAbs(SkScalarInvert(scale)); |
232 if (inv > 32767) { // Watch out for SkFixed overflow. | 231 if (inv > 32767) { // Watch out for SkFixed overflow. |
233 inv = 32767; | 232 inv = 32767; |
234 } | 233 } |
235 SkFixed s = SkScalarToFixed(inv); | 234 SkFixed s = SkScalarToFixed(inv); |
236 | 235 |
237 if (s < SK_Fixed1) { | 236 if (s < SK_Fixed1) { |
238 return 0; | 237 return 0; |
239 } | 238 } |
240 int clz = SkCLZ(s); | 239 int clz = SkCLZ(s); |
241 SkASSERT(clz >= 1 && clz <= 15); | 240 SkASSERT(clz >= 1 && clz <= 15); |
242 return SkIntToFixed(15 - clz) + ((unsigned)(s << (clz + 1)) >> 16); | 241 return SkIntToFixed(15 - clz) + ((unsigned)(s << (clz + 1)) >> 16); |
243 } | 242 } |
| 243 #endif |
244 | 244 |
245 bool SkMipMap::extractLevel(SkScalar scale, Level* levelPtr) const { | 245 bool SkMipMap::extractLevel(SkScalar scale, Level* levelPtr) const { |
246 if (NULL == fLevels) { | 246 if (NULL == fLevels) { |
247 return false; | 247 return false; |
248 } | 248 } |
249 | 249 |
250 if (scale >= SK_Scalar1) { | 250 if (scale >= SK_Scalar1 || scale <= 0 || !SkScalarIsFinite(scale)) { |
251 return false; | 251 return false; |
252 } | 252 } |
253 | 253 |
| 254 #ifdef SK_SUPPORT_LEGACY_MIPLEVELCHOICE |
254 int level = compute_level(scale) >> 16; | 255 int level = compute_level(scale) >> 16; |
| 256 #else |
| 257 SkScalar L = -SkScalarLog2(scale); |
| 258 if (!SkScalarIsFinite(L)) { |
| 259 return false; |
| 260 } |
| 261 SkASSERT(L >= 0); |
| 262 int level = SkScalarRoundToInt(L); |
| 263 // SkDebugf("mipmap scale=%g L=%g level=%d\n", scale, L, level); |
| 264 #endif |
| 265 |
255 SkASSERT(level >= 0); | 266 SkASSERT(level >= 0); |
256 if (level <= 0) { | 267 if (level <= 0) { |
257 return false; | 268 return false; |
258 } | 269 } |
259 | 270 |
260 if (level > fCount) { | 271 if (level > fCount) { |
261 level = fCount; | 272 level = fCount; |
262 } | 273 } |
263 if (levelPtr) { | 274 if (levelPtr) { |
264 *levelPtr = fLevels[level - 1]; | 275 *levelPtr = fLevels[level - 1]; |
265 } | 276 } |
266 return true; | 277 return true; |
267 } | 278 } |
OLD | NEW |