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

Unified Diff: src/core/SkMipMap.cpp

Issue 1010343002: add kGray_8_SkColorType (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « src/core/SkImageInfo.cpp ('k') | src/gpu/SkGr.cpp » ('j') | 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 9e0e5e1f5206132b473e414321e62997ed99347c..1b410856e4ed07d7a134897f4bb43fdae6327d52 100644
--- a/src/core/SkMipMap.cpp
+++ b/src/core/SkMipMap.cpp
@@ -135,6 +135,39 @@ static void downsample4444(void* dst, int x, int y, const void* srcPtr, const Sk
*((uint16_t*)dst) = (uint16_t)collaps4444(c >> 2);
}
+static void downsample8_nocheck(void* dst, int, int, const void* srcPtr, const SkBitmap& srcBM) {
+ const size_t rb = srcBM.rowBytes();
+ const uint8_t* p = static_cast<const uint8_t*>(srcPtr);
+ *(uint8_t*)dst = (p[0] + p[1] + p[rb] + p[rb + 1]) >> 2;
+}
+
+static void downsample8_check(void* dst, int x, int y, const void* srcPtr, const SkBitmap& srcBM) {
+ const uint8_t* p = static_cast<const uint8_t*>(srcPtr);
+ const uint8_t* baseP = p;
+
+ x <<= 1;
+ y <<= 1;
+ SkASSERT(srcBM.getAddr8(x, y) == p);
+
+ unsigned c = *p;
+ if (x < srcBM.width() - 1) {
+ p += 1;
+ }
+ c += *p;
+
+ p = baseP;
+ if (y < srcBM.height() - 1) {
+ p += srcBM.rowBytes();
+ }
+ c += *p;
+ if (x < srcBM.width() - 1) {
+ p += 1;
+ }
+ c += *p;
+
+ *(uint8_t*)dst = c >> 2;
+}
+
size_t SkMipMap::AllocLevelsSize(int levelCount, size_t pixelSize) {
if (levelCount < 0) {
return 0;
@@ -167,6 +200,11 @@ SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) {
proc_check = downsample4444;
proc_nocheck = proc_check;
break;
+ case kAlpha_8_SkColorType:
+ case kGray_8_SkColorType:
+ proc_check = downsample8_check;
+ proc_nocheck = downsample8_nocheck;
+ break;
default:
return NULL; // don't build mipmaps for any other colortypes (yet)
}
« no previous file with comments | « src/core/SkImageInfo.cpp ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698