2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "picture_utils.h"
9 #include "SkColorPriv.h"
11 #include "SkPicture.h"
16 void force_all_opaque(const SkBitmap& bitmap) {
17 SkASSERT(NULL == bitmap.getTexture());
18 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
19 if (NULL != bitmap.getTexture() || SkBitmap::kARGB_8888_Config == bitmap.config()) {
23 SkAutoLockPixels lock(bitmap);
24 for (int y = 0; y < bitmap.height(); y++) {
25 for (int x = 0; x < bitmap.width(); x++) {
26 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
31 void make_filepath(SkString* path, const SkString& dir, const SkString& name) {
32 size_t len = dir.size();
34 if (0 < len && '/' != dir[len - 1]) {
41 bool is_path_seperator(const char chr) {
42 #if defined(SK_BUILD_FOR_WIN)
43 return chr == '\\' || chr == '/';
50 void get_basename(SkString* basename, const SkString& path) {
51 if (path.size() == 0) {
56 size_t end = path.size() - 1;
58 // Paths pointing to directories often have a trailing slash,
59 // we remove it so the name is not empty
60 if (is_path_seperator(path[end])) {
72 if (is_path_seperator(path[i])) {
73 const char* basenameStart = path.c_str() + i + 1;
74 size_t basenameLength = end - i;
75 basename->set(basenameStart, basenameLength);
80 basename->set(path.c_str(), end + 1);
83 bool is_percentage(char* const string) {
84 SkString skString(string);
85 return skString.endsWith("%");
88 // This copies how bench does printing of test results.
89 #ifdef SK_BUILD_FOR_ANDROID
90 void print_msg(const char msg[]) { SkDebugf("%s", msg); }
92 void print_msg(const char msg[]) { printf("%s", msg); }
95 void setup_bitmap(SkBitmap* bitmap, int width, int height) {
96 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
97 bitmap->allocPixels();
98 bitmap->eraseColor(0);