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