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 "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
10 #include "SkBitmap.h" | 11 #include "SkImageEncoder.h" |
| 12 #include "SkOSFile.h" |
11 #include "SkPicture.h" | 13 #include "SkPicture.h" |
| 14 #include "SkStream.h" |
12 #include "SkString.h" | 15 #include "SkString.h" |
13 #include "SkStream.h" | |
14 | 16 |
15 static bool is_path_seperator(const char chr) { | 17 static bool is_path_seperator(const char chr) { |
16 #if defined(SK_BUILD_FOR_WIN) | 18 #if defined(SK_BUILD_FOR_WIN) |
17 return chr == '\\' || chr == '/'; | 19 return chr == '\\' || chr == '/'; |
18 #else | 20 #else |
19 return chr == '/'; | 21 return chr == '/'; |
20 #endif | 22 #endif |
21 } | 23 } |
22 | 24 |
23 namespace sk_tools { | 25 namespace sk_tools { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 bool is_percentage(const char* const string) { | 94 bool is_percentage(const char* const string) { |
93 SkString skString(string); | 95 SkString skString(string); |
94 return skString.endsWith("%"); | 96 return skString.endsWith("%"); |
95 } | 97 } |
96 | 98 |
97 void setup_bitmap(SkBitmap* bitmap, int width, int height) { | 99 void setup_bitmap(SkBitmap* bitmap, int width, int height) { |
98 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); | 100 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
99 bitmap->allocPixels(); | 101 bitmap->allocPixels(); |
100 bitmap->eraseColor(SK_ColorTRANSPARENT); | 102 bitmap->eraseColor(SK_ColorTRANSPARENT); |
101 } | 103 } |
102 } | 104 |
| 105 bool write_bitmap_to_disk(const SkBitmap& bm, const SkString& dirPath, |
| 106 const char *subdirOrNull, const SkString& baseName
) { |
| 107 SkString partialPath; |
| 108 if (subdirOrNull) { |
| 109 partialPath = SkOSPath::SkPathJoin(dirPath.c_str(), subdirOrNull); |
| 110 sk_mkdir(partialPath.c_str()); |
| 111 } else { |
| 112 partialPath.set(dirPath); |
| 113 } |
| 114 SkString fullPath = SkOSPath::SkPathJoin(partialPath.c_str(), baseName.c
_str()); |
| 115 if (SkImageEncoder::EncodeFile(fullPath.c_str(), bm, SkImageEncoder::kPN
G_Type, 100)) { |
| 116 return true; |
| 117 } else { |
| 118 SkDebugf("Failed to write the bitmap to %s.\n", fullPath.c_str()); |
| 119 return false; |
| 120 } |
| 121 } |
| 122 |
| 123 } // namespace sk_tools |
OLD | NEW |