OLD | NEW |
(Empty) | |
| 1 #include "DMWriteTask.h" |
| 2 |
| 3 #include "DMUtil.h" |
| 4 #include "SkCommandLineFlags.h" |
| 5 #include "SkImageEncoder.h" |
| 6 |
| 7 #include <string.h> |
| 8 |
| 9 DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs."); |
| 10 |
| 11 namespace DM { |
| 12 |
| 13 WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) |
| 14 : Task(parent) |
| 15 , fBitmap(bitmap) { |
| 16 // Split parent's name <gmName>_<config> into gmName and config. |
| 17 const char* parentName = parent.name().c_str(); |
| 18 const char* fromLastUnderscore = strrchr(parentName, '_'); |
| 19 const ptrdiff_t gmNameLength = fromLastUnderscore - parentName; |
| 20 |
| 21 fConfig.set(fromLastUnderscore+1); |
| 22 fGmName.set(parentName, gmNameLength); |
| 23 } |
| 24 |
| 25 void WriteTask::draw() { |
| 26 const char* root = FLAGS_writePath[0]; |
| 27 const SkString dir = SkOSPath::SkPathJoin(root, fConfig.c_str()); |
| 28 if (!sk_mkdir(root) || |
| 29 !sk_mkdir(dir.c_str()) || |
| 30 !SkImageEncoder::EncodeFile(png(SkOSPath::SkPathJoin(dir.c_str(), fGmNam
e.c_str())).c_str(), |
| 31 fBitmap, |
| 32 SkImageEncoder::kPNG_Type, |
| 33 100/*quality*/)) |
| 34 { |
| 35 this->fail(); |
| 36 } |
| 37 } |
| 38 |
| 39 SkString WriteTask::name() const { |
| 40 return SkStringPrintf("writing %s/%s.png", fConfig.c_str(), fGmName.c_str())
; |
| 41 } |
| 42 |
| 43 bool WriteTask::shouldSkip() const { |
| 44 return FLAGS_writePath.isEmpty(); |
| 45 } |
| 46 |
| 47 } // namespace DM |
OLD | NEW |