blob: 3eb55554b6dc780042b49c2b2587be073e147cf4 [file] [log] [blame]
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +00001#include "sk_tool_utils.h"
2
3namespace sk_tool_utils {
4
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +00005const char* colortype_name(SkColorType ct) {
6 switch (ct) {
7 case kUnknown_SkColorType: return "Unknown";
8 case kAlpha_8_SkColorType: return "Alpha_8";
9 case kIndex_8_SkColorType: return "Index_8";
10 case kARGB_4444_SkColorType: return "ARGB_4444";
11 case kRGB_565_SkColorType: return "RGB_565";
12 case kRGBA_8888_SkColorType: return "RGBA_8888";
13 case kBGRA_8888_SkColorType: return "BGRA_8888";
14 default:
15 SkASSERT(false);
16 return "unexpected colortype";
17 }
18}
19
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000020void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y,
21 SkColorType colorType, SkAlphaType alphaType) {
22 SkBitmap tmp(bitmap);
23 tmp.lockPixels();
skia.committer@gmail.come62513f2014-03-08 03:02:06 +000024
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000025 SkImageInfo info = tmp.info();
26 info.fColorType = colorType;
27 info.fAlphaType = alphaType;
skia.committer@gmail.come62513f2014-03-08 03:02:06 +000028
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000029 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y);
30}
31
32}