diff options
-rw-r--r-- | gm/filterbitmap.cpp | 5 | ||||
-rw-r--r-- | gm/showmiplevels.cpp | 34 | ||||
-rw-r--r-- | tools/sk_tool_utils.cpp | 30 | ||||
-rw-r--r-- | tools/sk_tool_utils.h | 3 |
4 files changed, 37 insertions, 35 deletions
diff --git a/gm/filterbitmap.cpp b/gm/filterbitmap.cpp index ec20e6efbe..c9ff295b48 100644 --- a/gm/filterbitmap.cpp +++ b/gm/filterbitmap.cpp @@ -11,6 +11,7 @@ #include "SkGradientShader.h" #include "SkStream.h" #include "SkTypeface.h" +#include "sk_tool_utils.h" static void setTypeface(SkPaint* paint, const char name[], SkFontStyle style) { sk_tool_utils::set_portable_typeface(paint, name, style); @@ -169,7 +170,7 @@ public: } if (fConvertToG8) { SkBitmap tmp; - fBM.copyTo(&tmp, kGray_8_SkColorType); + sk_tool_utils::copy_to_g8(&tmp, fBM); fBM = tmp; } } @@ -203,7 +204,7 @@ protected: if (fConvertToG8) { SkBitmap tmp; - fBM.copyTo(&tmp, kGray_8_SkColorType); + sk_tool_utils::copy_to_g8(&tmp, fBM); fBM = tmp; } } diff --git a/gm/showmiplevels.cpp b/gm/showmiplevels.cpp index 0394b57318..36e81010e8 100644 --- a/gm/showmiplevels.cpp +++ b/gm/showmiplevels.cpp @@ -216,41 +216,9 @@ DEF_GM( return new ShowMipLevels(256); ) /////////////////////////////////////////////////////////////////////////////////////////////////// -static void copy_32_to_g8(void* dst, size_t dstRB, const void* src, const SkImageInfo& srcInfo, - size_t srcRB) { - 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; - } -} - void copy_to(SkBitmap* dst, SkColorType dstColorType, const SkBitmap& src) { if (kGray_8_SkColorType == dstColorType) { - SkImageInfo grayInfo = src.info().makeColorType(kGray_8_SkColorType); - dst->allocPixels(grayInfo); - copy_32_to_g8(dst->getPixels(), dst->rowBytes(), src.getPixels(), src.info(), - src.rowBytes()); - return; + return sk_tool_utils::copy_to_g8(dst, src); } src.copyTo(dst, dstColorType); 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 diff --git a/tools/sk_tool_utils.h b/tools/sk_tool_utils.h index b097757ccd..ffe8084f7f 100644 --- a/tools/sk_tool_utils.h +++ b/tools/sk_tool_utils.h @@ -251,6 +251,9 @@ namespace sk_tool_utils { }; return sk_make_sp<EncodeImagePixelSerializer>(); } + + void copy_to_g8(SkBitmap* dst, const SkBitmap& src); + } // namespace sk_tool_utils #endif // sk_tool_utils_DEFINED |