| mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 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()) || |
| commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 30 | !SkImageEncoder::EncodeFile(Png(SkOSPath::SkPathJoin(dir.c_str(), fGmName.c_str())).c_str(), |
| mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 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 |