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" |
| 11 #include "SkMath.h" |
11 #include "SkNx.h" | 12 #include "SkNx.h" |
| 13 #include "SkTypes.h" |
12 | 14 |
13 // | 15 // |
14 // ColorTypeFilter is the "Type" we pass to some downsample template functions. | 16 // ColorTypeFilter is the "Type" we pass to some downsample template functions. |
15 // It controls how we expand a pixel into a large type, with space between each
component, | 17 // It controls how we expand a pixel into a large type, with space between each
component, |
16 // so we can then perform our simple filter (either box or triangle) and store t
he intermediates | 18 // so we can then perform our simple filter (either box or triangle) and store t
he intermediates |
17 // in the expanded type. | 19 // in the expanded type. |
18 // | 20 // |
19 | 21 |
20 struct ColorTypeFilter_8888 { | 22 struct ColorTypeFilter_8888 { |
21 typedef uint32_t Type; | 23 typedef uint32_t Type; |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 return nullptr; | 367 return nullptr; |
366 } | 368 } |
367 const SkPixmap& srcPixmap = srcUnlocker.pixmap(); | 369 const SkPixmap& srcPixmap = srcUnlocker.pixmap(); |
368 // Try to catch where we might have returned nullptr for src crbug.com/49281
8 | 370 // Try to catch where we might have returned nullptr for src crbug.com/49281
8 |
369 if (nullptr == srcPixmap.addr()) { | 371 if (nullptr == srcPixmap.addr()) { |
370 sk_throw(); | 372 sk_throw(); |
371 } | 373 } |
372 return Build(srcPixmap, fact); | 374 return Build(srcPixmap, fact); |
373 } | 375 } |
374 | 376 |
| 377 int SkMipMap::countLevels() const { |
| 378 return fCount; |
| 379 } |
| 380 |
| 381 void SkMipMap::getLevel(int index, Level* levelPtr) const { |
| 382 if (NULL == fLevels) { |
| 383 return; |
| 384 } |
| 385 if (index < 0) { |
| 386 return; |
| 387 } |
| 388 if (index > fCount - 1) { |
| 389 return; |
| 390 } |
| 391 if (levelPtr) { |
| 392 *levelPtr = fLevels[index]; |
| 393 } |
| 394 } |
| 395 |
| 396 int SkGetMipMapLevelCount(int baseWidth, int baseHeight) { |
| 397 // OpenGL's spec requires that each mipmap level have height/width equal to |
| 398 // max(1, floor(original_height / 2^i) |
| 399 // (or original_width) where i is the mipmap level. |
| 400 // Continue scaling down until both axes are size 1. |
| 401 |
| 402 const int largestAxis = SkTMax(baseWidth, baseHeight); |
| 403 if (largestAxis < 0) { |
| 404 return 0; |
| 405 } |
| 406 const int leadingZeros = SkCLZ(static_cast<uint32_t>(largestAxis)); |
| 407 // If the value 00011010 has 3 leading 0s then it has 5 significant bits |
| 408 // (the bits which are not leading zeros) |
| 409 const int significantBits = (sizeof(uint32_t) * 8) - leadingZeros; |
| 410 // This is making the assumption that the size of a byte is 8 bits |
| 411 // and that sizeof(uint32_t)'s implementation-defined behavior is 4. |
| 412 const int mipLevelCount = significantBits; |
| 413 |
| 414 return mipLevelCount; |
| 415 } |
OLD | NEW |