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

Unified Diff: src/core/SkConfig8888.cpp

Issue 2407093002: implement A8 destination fast-path for SkPixelInfo::CopyPixels (Closed)
Patch Set: add testing of readPixels in kAlpha8_SkAlphaType in ReadPixelsTest Created 4 years, 2 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/SkBitmap.cpp ('k') | tests/ReadPixelsTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkConfig8888.cpp
diff --git a/src/core/SkConfig8888.cpp b/src/core/SkConfig8888.cpp
index 31def9a92d81f54118823baf35863500d03a4e53..7c3f0214e34a173f5df40e8d20fdaefc26614f8e 100644
--- a/src/core/SkConfig8888.cpp
+++ b/src/core/SkConfig8888.cpp
@@ -167,6 +167,64 @@ static void copy_32_to_g8(void* dst, size_t dstRB, const void* src, size_t srcRB
}
}
+static bool extract_alpha(void* dst, size_t dstRB, const void* src, size_t srcRB,
+ const SkImageInfo& srcInfo, SkColorTable* ctable) {
+ uint8_t* SK_RESTRICT dst8 = (uint8_t*)dst;
+
+ const int w = srcInfo.width();
+ const int h = srcInfo.height();
+ if (srcInfo.isOpaque()) {
+ // src is opaque, so just fill alpha with 0xFF
+ for (int y = 0; y < h; ++y) {
+ memset(dst8, 0xFF, w);
+ dst8 += dstRB;
+ }
+ return true;
+ }
+ switch (srcInfo.colorType()) {
+ case kN32_SkColorType: {
+ const SkPMColor* SK_RESTRICT src32 = (const SkPMColor*)src;
+ for (int y = 0; y < h; ++y) {
+ for (int x = 0; x < w; ++x) {
+ dst8[x] = SkGetPackedA32(src32[x]);
+ }
+ dst8 += dstRB;
+ src32 = (const SkPMColor*)((const char*)src32 + srcRB);
+ }
+ break;
+ }
+ case kARGB_4444_SkColorType: {
+ const SkPMColor16* SK_RESTRICT src16 = (const SkPMColor16*)src;
+ for (int y = 0; y < h; ++y) {
+ for (int x = 0; x < w; ++x) {
+ dst8[x] = SkPacked4444ToA32(src16[x]);
+ }
+ dst8 += dstRB;
+ src16 = (const SkPMColor16*)((const char*)src16 + srcRB);
+ }
+ break;
+ }
+ case kIndex_8_SkColorType: {
+ if (nullptr == ctable) {
+ return false;
+ }
+ const SkPMColor* SK_RESTRICT table = ctable->readColors();
+ const uint8_t* SK_RESTRICT src8 = (const uint8_t*)src;
+ for (int y = 0; y < h; ++y) {
+ for (int x = 0; x < w; ++x) {
+ dst8[x] = SkGetPackedA32(table[src8[x]]);
+ }
+ dst8 += dstRB;
+ src8 += srcRB;
+ }
+ break;
+ }
+ default:
+ return false;
+ }
+ return true;
+}
+
bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRB,
SkColorTable* ctable) {
@@ -241,6 +299,11 @@ bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t
return true;
}
+ if (kAlpha_8_SkColorType == dstInfo.colorType() &&
+ extract_alpha(dstPixels, dstRB, srcPixels, srcRB, srcInfo, ctable)) {
+ return true;
+ }
+
// Can no longer draw directly into 4444, but we can manually whack it for a few combinations
if (kARGB_4444_SkColorType == dstInfo.colorType() &&
(kN32_SkColorType == srcInfo.colorType() || kIndex_8_SkColorType == srcInfo.colorType())) {
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | tests/ReadPixelsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698