OLD | NEW |
1 #include "DMWriteTask.h" | 1 #include "DMWriteTask.h" |
2 | 2 |
3 #include "DMUtil.h" | 3 #include "DMUtil.h" |
4 #include "SkColorPriv.h" | 4 #include "SkColorPriv.h" |
5 #include "SkCommandLineFlags.h" | 5 #include "SkCommandLineFlags.h" |
6 #include "SkImageDecoder.h" | 6 #include "SkImageDecoder.h" |
7 #include "SkImageEncoder.h" | 7 #include "SkImageEncoder.h" |
8 #include "SkString.h" | 8 #include "SkString.h" |
9 #include "SkUnPreMultiply.h" | 9 #include "SkUnPreMultiply.h" |
10 | 10 |
11 DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs."); | 11 DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs."); |
12 | 12 |
13 namespace DM { | 13 namespace DM { |
14 | 14 |
15 // Splits off the last N suffixes of name (splitting on _) and appends them to o
ut. | 15 // Splits off the last N suffixes of name (splitting on _) and appends them to o
ut. |
16 // Returns the total number of characters consumed. | 16 // Returns the total number of characters consumed. |
17 static int split_suffixes(int N, const char* name, SkTArray<SkString>* out) { | 17 static int split_suffixes(int N, const char* name, SkTArray<SkString>* out) { |
18 SkTArray<SkString> split; | 18 SkTArray<SkString> split; |
19 SkStrSplit(name, "_", &split); | 19 SkStrSplit(name, "_", &split); |
20 int consumed = 0; | 20 int consumed = 0; |
21 for (int i = 0; i < N; i++) { | 21 for (int i = 0; i < N; i++) { |
22 // We're splitting off suffixes from the back to front. | 22 // We're splitting off suffixes from the back to front. |
23 out->push_back(split[split.count()-i-1]); | 23 out->push_back(split[split.count()-i-1]); |
24 consumed += out->back().size() + 1; // Add one for the _. | 24 consumed += out->back().size() + 1; // Add one for the _. |
25 } | 25 } |
26 return consumed; | 26 return consumed; |
27 } | 27 } |
28 | 28 |
29 WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) : Task(parent), fBitma
p(bitmap) { | 29 WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) : CpuTask(parent), fBi
tmap(bitmap) { |
30 const int suffixes = parent.depth() + 1; | 30 const int suffixes = parent.depth() + 1; |
31 const SkString& name = parent.name(); | 31 const SkString& name = parent.name(); |
32 const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), &fSuffi
xes); | 32 const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), &fSuffi
xes); |
33 fGmName.set(name.c_str(), name.size()-totalSuffixLength); | 33 fGmName.set(name.c_str(), name.size()-totalSuffixLength); |
34 } | 34 } |
35 | 35 |
36 void WriteTask::makeDirOrFail(SkString dir) { | 36 void WriteTask::makeDirOrFail(SkString dir) { |
37 if (!sk_mkdir(dir.c_str())) { | 37 if (!sk_mkdir(dir.c_str())) { |
38 this->fail(); | 38 this->fail(); |
39 } | 39 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 for (size_t i = 0; i < bitmap.getSize()/4; i++) { | 145 for (size_t i = 0; i < bitmap.getSize()/4; i++) { |
146 dst[i] = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(src[i]); | 146 dst[i] = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(src[i]); |
147 } | 147 } |
148 bitmap.swap(unpremul); | 148 bitmap.swap(unpremul); |
149 } | 149 } |
150 | 150 |
151 return BitmapsEqual(expected, bitmap); | 151 return BitmapsEqual(expected, bitmap); |
152 } | 152 } |
153 | 153 |
154 } // namespace DM | 154 } // namespace DM |
OLD | NEW |