diff options
author | Matt Sarett <msarett@google.com> | 2017-01-18 11:49:33 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-19 14:04:33 +0000 |
commit | 4897fb898f62a983829e56fc72b5ce6fd1ad62e4 (patch) | |
tree | 3dbd42317af7b1ed36b329af97ba91001980a1e9 /tools/sk_tool_utils.cpp | |
parent | 1517224346e9e3e017401ec3f92bf30d98e5e995 (diff) |
Implement sk_tool_utils::copy_to_g8(), used by gms
BUG=skia:
Change-Id: Ic5b2b07fb3f408edf1f2b982235424c22795fe50
Reviewed-on: https://skia-review.googlesource.com/7187
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'tools/sk_tool_utils.cpp')
-rw-r--r-- | tools/sk_tool_utils.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp index 3e38cc4594..93f5b107f2 100644 --- a/tools/sk_tool_utils.cpp +++ b/tools/sk_tool_utils.cpp @@ -555,5 +555,35 @@ SkRect compute_tallest_occluder(const SkRRect& rr) { return SkRect::MakeLTRB(r.fLeft + maxL, r.fTop, r.fRight - maxR, r.fBottom); } +void copy_to_g8(SkBitmap* dst, const SkBitmap& src) { + SkASSERT(kBGRA_8888_SkColorType == src.colorType() || + kRGBA_8888_SkColorType == src.colorType()); + + SkImageInfo grayInfo = src.info().makeColorType(kGray_8_SkColorType); + dst->allocPixels(grayInfo); + uint8_t* dst8 = (uint8_t*)dst->getPixels(); + const uint32_t* src32 = (const uint32_t*)src.getPixels(); + + const int w = src.width(); + const int h = src.height(); + const bool isBGRA = (kBGRA_8888_SkColorType == src.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 + src.rowBytes()); + dst8 += dst->rowBytes(); + } +} } // namespace sk_tool_utils |