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" |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils_flags.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" |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 13 | #include "SkTestScalerContext.h" |
| 14 | |
| 15 | DEFINE_bool(portableFonts, false, "Use portable fonts"); |
| 16 | DEFINE_bool(resourceFonts, false, "Use resource fonts"); |
tfarina | 2010891 | 2014-06-21 10:54:17 -0700 | [diff] [blame] | 17 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 18 | namespace sk_tool_utils { |
| 19 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 20 | const char* colortype_name(SkColorType ct) { |
| 21 | switch (ct) { |
| 22 | case kUnknown_SkColorType: return "Unknown"; |
| 23 | case kAlpha_8_SkColorType: return "Alpha_8"; |
| 24 | case kIndex_8_SkColorType: return "Index_8"; |
| 25 | case kARGB_4444_SkColorType: return "ARGB_4444"; |
| 26 | case kRGB_565_SkColorType: return "RGB_565"; |
| 27 | case kRGBA_8888_SkColorType: return "RGBA_8888"; |
| 28 | case kBGRA_8888_SkColorType: return "BGRA_8888"; |
| 29 | default: |
| 30 | SkASSERT(false); |
| 31 | return "unexpected colortype"; |
| 32 | } |
| 33 | } |
| 34 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 35 | SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style) { |
| 36 | SkTypeface* face; |
| 37 | if (FLAGS_portableFonts) { |
| 38 | face = create_font(name, style); |
| 39 | } else if (FLAGS_resourceFonts) { |
| 40 | face = resource_font(name, style); |
| 41 | } else { |
| 42 | face = SkTypeface::CreateFromName(name, style); |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 43 | } |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 44 | return face; |
| 45 | } |
| 46 | |
| 47 | void set_portable_typeface(SkPaint* paint, const char* name, SkTypeface::Style style) { |
| 48 | SkTypeface* face = create_portable_typeface(name, style); |
| 49 | SkSafeUnref(paint->setTypeface(face)); |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 50 | } |
| 51 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 52 | void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, |
| 53 | SkColorType colorType, SkAlphaType alphaType) { |
| 54 | SkBitmap tmp(bitmap); |
| 55 | tmp.lockPixels(); |
skia.committer@gmail.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 56 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 57 | const SkImageInfo info = SkImageInfo::Make(tmp.width(), tmp.height(), colorType, alphaType); |
skia.committer@gmail.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 58 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 59 | canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); |
| 60 | } |
| 61 | |
tfarina | 2010891 | 2014-06-21 10:54:17 -0700 | [diff] [blame] | 62 | } // namespace sk_tool_utils |