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"
10 #include "SkColorPriv.h"
11 #include "SkImageEncoder.h"
13 #include "SkPicture.h"
18 void force_all_opaque(const SkBitmap& bitmap) {
19 SkASSERT(NULL == bitmap.getTexture());
20 SkASSERT(kN32_SkColorType == bitmap.colorType());
21 if (bitmap.getTexture() || kN32_SkColorType == bitmap.colorType()) {
25 SkAutoLockPixels lock(bitmap);
26 for (int y = 0; y < bitmap.height(); y++) {
27 for (int x = 0; x < bitmap.width(); x++) {
28 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
33 void replace_char(SkString* str, const char oldChar, const char newChar) {
37 for (size_t i = 0; i < str->size(); ++i) {
38 if (oldChar == str->operator[](i)) {
39 str->operator[](i) = newChar;
44 bool is_percentage(const char* const string) {
45 SkString skString(string);
46 return skString.endsWith("%");
49 void setup_bitmap(SkBitmap* bitmap, int width, int height) {
50 bitmap->allocN32Pixels(width, height);
51 bitmap->eraseColor(SK_ColorTRANSPARENT);
54 bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath,
55 const char *subdirOrNull, const SkString& baseName) {
58 partialPath = SkOSPath::Join(dirPath.c_str(), subdirOrNull);
59 sk_mkdir(partialPath.c_str());
61 partialPath.set(dirPath);
63 SkString fullPath = SkOSPath::Join(partialPath.c_str(), baseName.c_str());
64 if (SkImageEncoder::EncodeFile(fullPath.c_str(), bm, SkImageEncoder::kPNG_Type, 100)) {
67 SkDebugf("Failed to write the bitmap to %s.\n", fullPath.c_str());
72 } // namespace sk_tools