| 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 return nullptr; | 366 return nullptr; |
| 367 } | 367 } |
| 368 | 368 |
| 369 if (src.width() <= 1 && src.height() <= 1) { | 369 if (src.width() <= 1 && src.height() <= 1) { |
| 370 return nullptr; | 370 return nullptr; |
| 371 } | 371 } |
| 372 // whip through our loop to compute the exact size needed | 372 // whip through our loop to compute the exact size needed |
| 373 size_t size = 0; | 373 size_t size = 0; |
| 374 int countLevels = ComputeLevelCount(src.width(), src.height()); | 374 int countLevels = ComputeLevelCount(src.width(), src.height()); |
| 375 for (int currentMipLevel = countLevels; currentMipLevel > 0; currentMipLevel
--) { | 375 for (int currentMipLevel = countLevels; currentMipLevel > 0; currentMipLevel
--) { |
| 376 SkSize mipSize = ComputeLevelSize(src.width(), src.height(), currentMipL
evel); | 376 SkISize mipSize = ComputeLevelSize(src.width(), src.height(), currentMip
Level); |
| 377 size += SkColorTypeMinRowBytes(ct, mipSize.fWidth) * mipSize.fHeight; | 377 size += SkColorTypeMinRowBytes(ct, mipSize.fWidth) * mipSize.fHeight; |
| 378 } | 378 } |
| 379 | 379 |
| 380 size_t storageSize = SkMipMap::AllocLevelsSize(countLevels, size); | 380 size_t storageSize = SkMipMap::AllocLevelsSize(countLevels, size); |
| 381 if (0 == storageSize) { | 381 if (0 == storageSize) { |
| 382 return nullptr; | 382 return nullptr; |
| 383 } | 383 } |
| 384 | 384 |
| 385 SkMipMap* mipmap; | 385 SkMipMap* mipmap; |
| 386 if (fact) { | 386 if (fact) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 // For example, it contains levels 1-x instead of 0-x. | 489 // For example, it contains levels 1-x instead of 0-x. |
| 490 // This is because the image used to create SkMipMap is the base level. | 490 // This is because the image used to create SkMipMap is the base level. |
| 491 // So subtract 1 from the mip level count. | 491 // So subtract 1 from the mip level count. |
| 492 if (mipLevelCount > 0) { | 492 if (mipLevelCount > 0) { |
| 493 --mipLevelCount; | 493 --mipLevelCount; |
| 494 } | 494 } |
| 495 | 495 |
| 496 return mipLevelCount; | 496 return mipLevelCount; |
| 497 } | 497 } |
| 498 | 498 |
| 499 SkSize SkMipMap::ComputeLevelSize(int baseWidth, int baseHeight, int level) { | 499 SkISize SkMipMap::ComputeLevelSize(int baseWidth, int baseHeight, int level) { |
| 500 if (baseWidth < 1 || baseHeight < 1) { | 500 if (baseWidth < 1 || baseHeight < 1) { |
| 501 return SkSize::Make(0, 0); | 501 return SkISize::Make(0, 0); |
| 502 } | 502 } |
| 503 | 503 |
| 504 int maxLevelCount = ComputeLevelCount(baseWidth, baseHeight); | 504 int maxLevelCount = ComputeLevelCount(baseWidth, baseHeight); |
| 505 if (level > maxLevelCount || level < 0) { | 505 if (level > maxLevelCount || level < 0) { |
| 506 return SkSize::Make(0, 0); | 506 return SkISize::Make(0, 0); |
| 507 } | 507 } |
| 508 if (level == 0) { | 508 if (level == 0) { |
| 509 return SkSize::Make(baseWidth, baseHeight); | 509 return SkISize::Make(baseWidth, baseHeight); |
| 510 } | 510 } |
| 511 | 511 |
| 512 // OpenGL's spec requires that each mipmap level have height/width equal to | 512 // OpenGL's spec requires that each mipmap level have height/width equal to |
| 513 // max(1, floor(original_height / 2^i) | 513 // max(1, floor(original_height / 2^i) |
| 514 // (or original_width) where i is the mipmap level. | 514 // (or original_width) where i is the mipmap level. |
| 515 | 515 |
| 516 int width = SkTMax(1, baseWidth >> level); | 516 int width = SkTMax(1, baseWidth >> level); |
| 517 int height = SkTMax(1, baseHeight >> level); | 517 int height = SkTMax(1, baseHeight >> level); |
| 518 | 518 |
| 519 return SkSize::Make(width, height); | 519 return SkISize::Make(width, height); |
| 520 } | 520 } |
| 521 | 521 |
| 522 /////////////////////////////////////////////////////////////////////////////// | 522 /////////////////////////////////////////////////////////////////////////////// |
| 523 | 523 |
| 524 bool SkMipMap::extractLevel(const SkSize& scaleSize, Level* levelPtr) const { | 524 bool SkMipMap::extractLevel(const SkSize& scaleSize, Level* levelPtr) const { |
| 525 if (nullptr == fLevels) { | 525 if (nullptr == fLevels) { |
| 526 return false; | 526 return false; |
| 527 } | 527 } |
| 528 | 528 |
| 529 SkASSERT(scaleSize.width() >= 0 && scaleSize.height() >= 0); | 529 SkASSERT(scaleSize.width() >= 0 && scaleSize.height() >= 0); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 return false; | 592 return false; |
| 593 } | 593 } |
| 594 if (index > fCount - 1) { | 594 if (index > fCount - 1) { |
| 595 return false; | 595 return false; |
| 596 } | 596 } |
| 597 if (levelPtr) { | 597 if (levelPtr) { |
| 598 *levelPtr = fLevels[index]; | 598 *levelPtr = fLevels[index]; |
| 599 } | 599 } |
| 600 return true; | 600 return true; |
| 601 } | 601 } |
| OLD | NEW |