OLD | NEW |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
1 #include "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
2 | 9 |
| 10 #include "SkBitmap.h" |
| 11 #include "SkCanvas.h" |
| 12 |
3 namespace sk_tool_utils { | 13 namespace sk_tool_utils { |
4 | 14 |
5 const char* colortype_name(SkColorType ct) { | 15 const char* colortype_name(SkColorType ct) { |
6 switch (ct) { | 16 switch (ct) { |
7 case kUnknown_SkColorType: return "Unknown"; | 17 case kUnknown_SkColorType: return "Unknown"; |
8 case kAlpha_8_SkColorType: return "Alpha_8"; | 18 case kAlpha_8_SkColorType: return "Alpha_8"; |
9 case kIndex_8_SkColorType: return "Index_8"; | 19 case kIndex_8_SkColorType: return "Index_8"; |
10 case kARGB_4444_SkColorType: return "ARGB_4444"; | 20 case kARGB_4444_SkColorType: return "ARGB_4444"; |
11 case kRGB_565_SkColorType: return "RGB_565"; | 21 case kRGB_565_SkColorType: return "RGB_565"; |
12 case kRGBA_8888_SkColorType: return "RGBA_8888"; | 22 case kRGBA_8888_SkColorType: return "RGBA_8888"; |
13 case kBGRA_8888_SkColorType: return "BGRA_8888"; | 23 case kBGRA_8888_SkColorType: return "BGRA_8888"; |
14 default: | 24 default: |
15 SkASSERT(false); | 25 SkASSERT(false); |
16 return "unexpected colortype"; | 26 return "unexpected colortype"; |
17 } | 27 } |
18 } | 28 } |
19 | 29 |
20 void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, | 30 void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, |
21 SkColorType colorType, SkAlphaType alphaType) { | 31 SkColorType colorType, SkAlphaType alphaType) { |
22 SkBitmap tmp(bitmap); | 32 SkBitmap tmp(bitmap); |
23 tmp.lockPixels(); | 33 tmp.lockPixels(); |
24 | 34 |
25 SkImageInfo info = tmp.info(); | 35 SkImageInfo info = tmp.info(); |
26 info.fColorType = colorType; | 36 info.fColorType = colorType; |
27 info.fAlphaType = alphaType; | 37 info.fAlphaType = alphaType; |
28 | 38 |
29 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); | 39 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); |
30 } | 40 } |
31 | 41 |
32 } | 42 } // namespace sk_tool_utils |
OLD | NEW |