tfarina | 2010891 | 2014-06-21 10:54:17 -0700 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 8 | #include "sk_tool_utils.h" |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 9 | #include "../src/fonts/SkTestScalerContext.h" |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 10 | |
tfarina | 2010891 | 2014-06-21 10:54:17 -0700 | [diff] [blame] | 11 | #include "SkBitmap.h" |
| 12 | #include "SkCanvas.h" |
| 13 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 14 | namespace sk_tool_utils { |
| 15 | |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 16 | bool gEnablePortableTypeface = false; |
| 17 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 18 | const 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 | |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 33 | SkPaint::FontMetrics create_font(SkTDArray<SkPath*>& , SkTDArray<SkFixed>& ); |
| 34 | |
| 35 | void 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.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 41 | void 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.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 45 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 46 | SkImageInfo info = tmp.info(); |
| 47 | info.fColorType = colorType; |
| 48 | info.fAlphaType = alphaType; |
skia.committer@gmail.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 49 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 50 | canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); |
| 51 | } |
| 52 | |
tfarina | 2010891 | 2014-06-21 10:54:17 -0700 | [diff] [blame] | 53 | } // namespace sk_tool_utils |