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

Unified Diff: src/core/SkConfig8888.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/SkBitmapProcState_procs.h ('k') | src/core/SkImageInfo.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 85e208f2875b987edc253a925f75b7d46ea5f81d..d28941c27cf79120d3cd2a041ca577988c7bd82c 100644
--- a/src/core/SkConfig8888.cpp
+++ b/src/core/SkConfig8888.cpp
@@ -137,6 +137,47 @@ static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB,
}
}
+static void copy_g8_to_32(void* dst, size_t dstRB, const void* src, size_t srcRB, int w, int h) {
+ uint32_t* dst32 = (uint32_t*)dst;
+ const uint8_t* src8 = (const uint8_t*)src;
+
+ for (int y = 0; y < h; ++y) {
+ for (int x = 0; x < w; ++x) {
+ dst32[x] = SkPackARGB32(0xFF, src8[x], src8[x], src8[x]);
+ }
+ dst32 = (uint32_t*)((char*)dst32 + dstRB);
+ src8 += srcRB;
+ }
+}
+
+static void copy_32_to_g8(void* dst, size_t dstRB, const void* src, size_t srcRB,
+ const SkImageInfo& srcInfo) {
+ uint8_t* dst8 = (uint8_t*)dst;
+ const uint32_t* src32 = (const uint32_t*)src;
+
+ const int w = srcInfo.width();
+ const int h = srcInfo.height();
+ const bool isBGRA = (kBGRA_8888_SkColorType == srcInfo.colorType());
+
+ for (int y = 0; y < h; ++y) {
+ if (isBGRA) {
+ // BGRA
+ for (int x = 0; x < w; ++x) {
+ uint32_t s = src32[x];
+ dst8[x] = SkComputeLuminance((s >> 16) & 0xFF, (s >> 8) & 0xFF, s & 0xFF);
+ }
+ } else {
+ // RGBA
+ for (int x = 0; x < w; ++x) {
+ uint32_t s = src32[x];
+ dst8[x] = SkComputeLuminance(s & 0xFF, (s >> 8) & 0xFF, (s >> 16) & 0xFF);
+ }
+ }
+ src32 = (const uint32_t*)((const char*)src32 + srcRB);
+ dst8 += dstRB;
+ }
+}
+
bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRB,
SkColorTable* ctable) {
@@ -170,6 +211,7 @@ bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t
switch (srcInfo.colorType()) {
case kRGB_565_SkColorType:
case kAlpha_8_SkColorType:
+ case kGray_8_SkColorType:
break;
case kIndex_8_SkColorType:
case kARGB_4444_SkColorType:
@@ -189,6 +231,15 @@ bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t
* are supported.
*/
+ if (kGray_8_SkColorType == srcInfo.colorType() && 4 == dstInfo.bytesPerPixel()) {
+ copy_g8_to_32(dstPixels, dstRB, srcPixels, srcRB, width, height);
+ return true;
+ }
+ if (kGray_8_SkColorType == dstInfo.colorType() && 4 == srcInfo.bytesPerPixel()) {
+ copy_32_to_g8(dstPixels, dstRB, srcPixels, srcRB, srcInfo);
+ 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/SkBitmapProcState_procs.h ('k') | src/core/SkImageInfo.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698