blob: 1b35005d963a19146d429a912b643f1073ade5e1 [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"
caryclark5fb6bd42014-06-23 11:25:00 -07009#include "../src/fonts/SkTestScalerContext.h"
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000010
tfarina20108912014-06-21 10:54:17 -070011#include "SkBitmap.h"
12#include "SkCanvas.h"
13
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000014namespace sk_tool_utils {
15
caryclark5fb6bd42014-06-23 11:25:00 -070016bool gEnablePortableTypeface = false;
17
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000018const char* colortype_name(SkColorType ct) {
19 switch (ct) {
20 case kUnknown_SkColorType: return "Unknown";
21 case kAlpha_8_SkColorType: return "Alpha_8";
22 case kIndex_8_SkColorType: return "Index_8";
23 case kARGB_4444_SkColorType: return "ARGB_4444";
24 case kRGB_565_SkColorType: return "RGB_565";
25 case kRGBA_8888_SkColorType: return "RGBA_8888";
26 case kBGRA_8888_SkColorType: return "BGRA_8888";
27 default:
28 SkASSERT(false);
29 return "unexpected colortype";
30 }
31}
32
caryclark5fb6bd42014-06-23 11:25:00 -070033SkPaint::FontMetrics create_font(SkTDArray<SkPath*>& , SkTDArray<SkFixed>& );
34
35void set_portable_typeface(SkPaint* paint, SkTypeface::Style style) {
36 if (gEnablePortableTypeface) {
37 SkSafeUnref(paint->setTypeface(CreateTestTypeface(create_font, style)));
38 }
39}
40
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000041void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y,
42 SkColorType colorType, SkAlphaType alphaType) {
43 SkBitmap tmp(bitmap);
44 tmp.lockPixels();
skia.committer@gmail.come62513f2014-03-08 03:02:06 +000045
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000046 SkImageInfo info = tmp.info();
47 info.fColorType = colorType;
48 info.fAlphaType = alphaType;
skia.committer@gmail.come62513f2014-03-08 03:02:06 +000049
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000050 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y);
51}
52
tfarina20108912014-06-21 10:54:17 -070053} // namespace sk_tool_utils