OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "picture_utils.h" | 8 #include "picture_utils.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 } | 23 } |
24 | 24 |
25 SkAutoLockPixels lock(bitmap); | 25 SkAutoLockPixels lock(bitmap); |
26 for (int y = 0; y < bitmap.height(); y++) { | 26 for (int y = 0; y < bitmap.height(); y++) { |
27 for (int x = 0; x < bitmap.width(); x++) { | 27 for (int x = 0; x < bitmap.width(); x++) { |
28 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); | 28 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
29 } | 29 } |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 void replace_char(SkString* str, const char oldChar, const char newChar) { | |
34 if (NULL == str) { | |
35 return; | |
36 } | |
37 for (size_t i = 0; i < str->size(); ++i) { | |
38 if (oldChar == str->operator[](i)) { | |
39 str->operator[](i) = newChar; | |
40 } | |
41 } | |
42 } | |
43 | |
44 bool is_percentage(const char* const string) { | 33 bool is_percentage(const char* const string) { |
45 SkString skString(string); | 34 SkString skString(string); |
46 return skString.endsWith("%"); | 35 return skString.endsWith("%"); |
47 } | 36 } |
48 | 37 |
49 void setup_bitmap(SkBitmap* bitmap, int width, int height) { | 38 void setup_bitmap(SkBitmap* bitmap, int width, int height) { |
50 bitmap->allocN32Pixels(width, height); | 39 bitmap->allocN32Pixels(width, height); |
51 bitmap->eraseColor(SK_ColorTRANSPARENT); | 40 bitmap->eraseColor(SK_ColorTRANSPARENT); |
52 } | 41 } |
53 | 42 |
54 bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath, | 43 bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath, |
55 const char *subdirOrNull, const SkString& baseName
) { | 44 const char *subdirOrNull, const SkString& baseName
) { |
56 SkString partialPath; | 45 SkString partialPath; |
57 if (subdirOrNull) { | 46 if (subdirOrNull) { |
58 partialPath = SkOSPath::Join(dirPath.c_str(), subdirOrNull); | 47 partialPath = SkOSPath::Join(dirPath.c_str(), subdirOrNull); |
59 sk_mkdir(partialPath.c_str()); | 48 sk_mkdir(partialPath.c_str()); |
60 } else { | 49 } else { |
61 partialPath.set(dirPath); | 50 partialPath.set(dirPath); |
62 } | 51 } |
63 SkString fullPath = SkOSPath::Join(partialPath.c_str(), baseName.c_str()
); | 52 SkString fullPath = SkOSPath::Join(partialPath.c_str(), baseName.c_str()
); |
64 if (SkImageEncoder::EncodeFile(fullPath.c_str(), bm, SkImageEncoder::kPN
G_Type, 100)) { | 53 if (SkImageEncoder::EncodeFile(fullPath.c_str(), bm, SkImageEncoder::kPN
G_Type, 100)) { |
65 return true; | 54 return true; |
66 } else { | 55 } else { |
67 SkDebugf("Failed to write the bitmap to %s.\n", fullPath.c_str()); | 56 SkDebugf("Failed to write the bitmap to %s.\n", fullPath.c_str()); |
68 return false; | 57 return false; |
69 } | 58 } |
70 } | 59 } |
71 | 60 |
72 } // namespace sk_tools | 61 } // namespace sk_tools |
OLD | NEW |