blob: c75c496a890c0d2526d74cc93d01bf6c305ae288 [file] [log] [blame]
tfarina20108912014-06-21 10:54:17 -07001/*
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
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +00008#include "sk_tool_utils.h"
9
tfarina20108912014-06-21 10:54:17 -070010#include "SkBitmap.h"
11#include "SkCanvas.h"
12
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000013namespace sk_tool_utils {
14
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000015const char* colortype_name(SkColorType ct) {
16 switch (ct) {
17 case kUnknown_SkColorType: return "Unknown";
18 case kAlpha_8_SkColorType: return "Alpha_8";
19 case kIndex_8_SkColorType: return "Index_8";
20 case kARGB_4444_SkColorType: return "ARGB_4444";
21 case kRGB_565_SkColorType: return "RGB_565";
22 case kRGBA_8888_SkColorType: return "RGBA_8888";
23 case kBGRA_8888_SkColorType: return "BGRA_8888";
24 default:
25 SkASSERT(false);
26 return "unexpected colortype";
27 }
28}
29
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000030void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y,
31 SkColorType colorType, SkAlphaType alphaType) {
32 SkBitmap tmp(bitmap);
33 tmp.lockPixels();
skia.committer@gmail.come62513f2014-03-08 03:02:06 +000034
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000035 SkImageInfo info = tmp.info();
36 info.fColorType = colorType;
37 info.fAlphaType = alphaType;
skia.committer@gmail.come62513f2014-03-08 03:02:06 +000038
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000039 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y);
40}
41
tfarina20108912014-06-21 10:54:17 -070042} // namespace sk_tool_utils