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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 basename->set(path.c_str(), end + 1); | 91 basename->set(path.c_str(), end + 1); |
92 } | 92 } |
93 | 93 |
94 bool is_percentage(const char* const string) { | 94 bool is_percentage(const char* const string) { |
95 SkString skString(string); | 95 SkString skString(string); |
96 return skString.endsWith("%"); | 96 return skString.endsWith("%"); |
97 } | 97 } |
98 | 98 |
99 void setup_bitmap(SkBitmap* bitmap, int width, int height) { | 99 void setup_bitmap(SkBitmap* bitmap, int width, int height) { |
100 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); | 100 bitmap->allocN32Pixels(width, height); |
101 bitmap->allocPixels(); | |
102 bitmap->eraseColor(SK_ColorTRANSPARENT); | 101 bitmap->eraseColor(SK_ColorTRANSPARENT); |
103 } | 102 } |
104 | 103 |
105 bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath, | 104 bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath, |
106 const char *subdirOrNull, const SkString& baseName
) { | 105 const char *subdirOrNull, const SkString& baseName
) { |
107 SkString partialPath; | 106 SkString partialPath; |
108 if (subdirOrNull) { | 107 if (subdirOrNull) { |
109 partialPath = SkOSPath::SkPathJoin(dirPath.c_str(), subdirOrNull); | 108 partialPath = SkOSPath::SkPathJoin(dirPath.c_str(), subdirOrNull); |
110 sk_mkdir(partialPath.c_str()); | 109 sk_mkdir(partialPath.c_str()); |
111 } else { | 110 } else { |
112 partialPath.set(dirPath); | 111 partialPath.set(dirPath); |
113 } | 112 } |
114 SkString fullPath = SkOSPath::SkPathJoin(partialPath.c_str(), baseName.c
_str()); | 113 SkString fullPath = SkOSPath::SkPathJoin(partialPath.c_str(), baseName.c
_str()); |
115 if (SkImageEncoder::EncodeFile(fullPath.c_str(), bm, SkImageEncoder::kPN
G_Type, 100)) { | 114 if (SkImageEncoder::EncodeFile(fullPath.c_str(), bm, SkImageEncoder::kPN
G_Type, 100)) { |
116 return true; | 115 return true; |
117 } else { | 116 } else { |
118 SkDebugf("Failed to write the bitmap to %s.\n", fullPath.c_str()); | 117 SkDebugf("Failed to write the bitmap to %s.\n", fullPath.c_str()); |
119 return false; | 118 return false; |
120 } | 119 } |
121 } | 120 } |
122 | 121 |
123 } // namespace sk_tools | 122 } // namespace sk_tools |
OLD | NEW |