2014-06-21 17:54:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-03-07 03:25:16 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2014-06-23 18:25:00 +00:00
|
|
|
#include "../src/fonts/SkTestScalerContext.h"
|
2014-03-07 03:25:16 +00:00
|
|
|
|
2014-06-21 17:54:17 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
|
2014-03-07 03:25:16 +00:00
|
|
|
namespace sk_tool_utils {
|
|
|
|
|
2014-06-23 18:25:00 +00:00
|
|
|
bool gEnablePortableTypeface = false;
|
|
|
|
|
2014-03-17 21:31:26 +00:00
|
|
|
const char* colortype_name(SkColorType ct) {
|
|
|
|
switch (ct) {
|
|
|
|
case kUnknown_SkColorType: return "Unknown";
|
|
|
|
case kAlpha_8_SkColorType: return "Alpha_8";
|
|
|
|
case kIndex_8_SkColorType: return "Index_8";
|
|
|
|
case kARGB_4444_SkColorType: return "ARGB_4444";
|
|
|
|
case kRGB_565_SkColorType: return "RGB_565";
|
|
|
|
case kRGBA_8888_SkColorType: return "RGBA_8888";
|
|
|
|
case kBGRA_8888_SkColorType: return "BGRA_8888";
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return "unexpected colortype";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 18:25:00 +00:00
|
|
|
SkPaint::FontMetrics create_font(SkTDArray<SkPath*>& , SkTDArray<SkFixed>& );
|
|
|
|
|
|
|
|
void set_portable_typeface(SkPaint* paint, SkTypeface::Style style) {
|
|
|
|
if (gEnablePortableTypeface) {
|
|
|
|
SkSafeUnref(paint->setTypeface(CreateTestTypeface(create_font, style)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-07 03:25:16 +00:00
|
|
|
void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y,
|
|
|
|
SkColorType colorType, SkAlphaType alphaType) {
|
|
|
|
SkBitmap tmp(bitmap);
|
|
|
|
tmp.lockPixels();
|
2014-03-08 03:02:06 +00:00
|
|
|
|
2014-03-07 03:25:16 +00:00
|
|
|
SkImageInfo info = tmp.info();
|
|
|
|
info.fColorType = colorType;
|
|
|
|
info.fAlphaType = alphaType;
|
2014-03-08 03:02:06 +00:00
|
|
|
|
2014-03-07 03:25:16 +00:00
|
|
|
canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y);
|
|
|
|
}
|
|
|
|
|
2014-06-21 17:54:17 +00:00
|
|
|
} // namespace sk_tool_utils
|