commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 1 | #include "sk_tool_utils.h" |
| 2 | |
| 3 | namespace sk_tool_utils { |
| 4 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 5 | const 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.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 20 | void 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.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 24 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 25 | SkImageInfo info = tmp.info(); |
| 26 | info.fColorType = colorType; |
| 27 | info.fAlphaType = alphaType; |
skia.committer@gmail.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 28 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 29 | canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); |
| 30 | } |
| 31 | |
| 32 | } |