Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Unified Diff: src/core/SkMipMap.cpp

Issue 1639693002: Adding direct access to SkMipMap levels. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/core/SkMipMap.h ('K') | « src/core/SkMipMap.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkMipMap.cpp
diff --git a/src/core/SkMipMap.cpp b/src/core/SkMipMap.cpp
index c037865fd49b3f25c555a1eb19d5aa217cd8c6bb..91c755ec8085d1b4575ea80d8a9edf453a55d582 100644
--- a/src/core/SkMipMap.cpp
+++ b/src/core/SkMipMap.cpp
@@ -8,7 +8,9 @@
#include "SkMipMap.h"
#include "SkBitmap.h"
#include "SkColorPriv.h"
+#include "SkMath.h"
#include "SkNx.h"
+#include "SkTypes.h"
//
// ColorTypeFilter is the "Type" we pass to some downsample template functions.
@@ -372,3 +374,42 @@ SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) {
return Build(srcPixmap, fact);
}
+int SkMipMap::countLevels() const {
+ return fCount;
+}
+
+void SkMipMap::getLevel(int index, Level* levelPtr) const {
+ if (NULL == fLevels) {
+ return;
+ }
+ if (index < 0) {
+ return;
+ }
+ if (index > fCount - 1) {
+ return;
+ }
+ if (levelPtr) {
+ *levelPtr = fLevels[index];
+ }
+}
+
+int SkGetMipMapLevelCount(int baseWidth, int baseHeight) {
+ // OpenGL's spec requires that each mipmap level have height/width equal to
+ // max(1, floor(original_height / 2^i)
+ // (or original_width) where i is the mipmap level.
+ // Continue scaling down until both axes are size 1.
+
+ const int largestAxis = SkTMax(baseWidth, baseHeight);
+ if (largestAxis < 0) {
+ return 0;
+ }
+ const int leadingZeros = SkCLZ(static_cast<uint32_t>(largestAxis));
+ // If the value 00011010 has 3 leading 0s then it has 5 significant bits
+ // (the bits which are not leading zeros)
+ const int significantBits = (sizeof(uint32_t) * 8) - leadingZeros;
+ // This is making the assumption that the size of a byte is 8 bits
+ // and that sizeof(uint32_t)'s implementation-defined behavior is 4.
+ const int mipLevelCount = significantBits;
+
+ return mipLevelCount;
+}
« src/core/SkMipMap.h ('K') | « src/core/SkMipMap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698