sk_tool_utils.cpp revision 2010891425f10257363ae6eb0da70453746dc087
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 8#include "sk_tool_utils.h" 9 10#include "SkBitmap.h" 11#include "SkCanvas.h" 12 13namespace sk_tool_utils { 14 15const char* colortype_name(SkColorType ct) { 16 switch (ct) { 17 case kUnknown_SkColorType: return "Unknown"; 18 case kAlpha_8_SkColorType: return "Alpha_8"; 19 case kIndex_8_SkColorType: return "Index_8"; 20 case kARGB_4444_SkColorType: return "ARGB_4444"; 21 case kRGB_565_SkColorType: return "RGB_565"; 22 case kRGBA_8888_SkColorType: return "RGBA_8888"; 23 case kBGRA_8888_SkColorType: return "BGRA_8888"; 24 default: 25 SkASSERT(false); 26 return "unexpected colortype"; 27 } 28} 29 30void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, 31 SkColorType colorType, SkAlphaType alphaType) { 32 SkBitmap tmp(bitmap); 33 tmp.lockPixels(); 34 35 SkImageInfo info = tmp.info(); 36 info.fColorType = colorType; 37 info.fAlphaType = alphaType; 38 39 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); 40} 41 42} // namespace sk_tool_utils 43