OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "gm_expectations.h" | 8 #include "gm_expectations.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 * If directory is non null and does not end with a path separator, append one. | 482 * If directory is non null and does not end with a path separator, append one. |
483 * @param directory SkString representing the path to a directory. If the last character is not a | 483 * @param directory SkString representing the path to a directory. If the last character is not a |
484 * path separator (specific to the current OS), append one. | 484 * path separator (specific to the current OS), append one. |
485 */ | 485 */ |
486 static void append_path_separator_if_necessary(SkString* directory) { | 486 static void append_path_separator_if_necessary(SkString* directory) { |
487 if (directory != NULL && directory->c_str()[directory->size() - 1] != SkPATH _SEPARATOR) { | 487 if (directory != NULL && directory->c_str()[directory->size() - 1] != SkPATH _SEPARATOR) { |
488 directory->appendf("%c", SkPATH_SEPARATOR); | 488 directory->appendf("%c", SkPATH_SEPARATOR); |
489 } | 489 } |
490 } | 490 } |
491 | 491 |
492 /** | |
493 * Return true if the filename represents an image. | |
494 */ | |
495 static bool is_image_file(const char* filename) { | |
496 const char* gImageExtensions[] = { | |
497 ".png", ".PNG", ".jpg", ".JPG", ".jpeg", ".JPEG", ".bmp", ".BMP", | |
498 ".webp", ".WEBP", ".ico", ".ICO", ".wbmp", ".WBMP", ".gif", ".GIF" | |
499 }; | |
borenet
2013/06/28 20:02:02
I agree that this is cumbersome, but I think it's
| |
500 for (size_t i = 0; i < SK_ARRAY_COUNT(gImageExtensions); ++i) { | |
501 if (SkStrEndsWith(filename, gImageExtensions[i])) { | |
502 return true; | |
503 } | |
504 } | |
505 return false; | |
506 } | |
507 | |
492 int tool_main(int argc, char** argv); | 508 int tool_main(int argc, char** argv); |
493 int tool_main(int argc, char** argv) { | 509 int tool_main(int argc, char** argv) { |
494 SkCommandLineFlags::SetUsage("Decode files, and optionally write the results to files."); | 510 SkCommandLineFlags::SetUsage("Decode files, and optionally write the results to files."); |
495 SkCommandLineFlags::Parse(argc, argv); | 511 SkCommandLineFlags::Parse(argc, argv); |
496 | 512 |
497 if (FLAGS_readPath.count() < 1) { | 513 if (FLAGS_readPath.count() < 1) { |
498 SkDebugf("Folder(s) or image(s) to decode are required.\n"); | 514 SkDebugf("Folder(s) or image(s) to decode are required.\n"); |
499 return -1; | 515 return -1; |
500 } | 516 } |
501 | 517 |
(...skipping 19 matching lines...) Expand all Loading... | |
521 for (int i = 0; i < FLAGS_readPath.count(); i++) { | 537 for (int i = 0; i < FLAGS_readPath.count(); i++) { |
522 const char* readPath = FLAGS_readPath[i]; | 538 const char* readPath = FLAGS_readPath[i]; |
523 if (strlen(readPath) < 1) { | 539 if (strlen(readPath) < 1) { |
524 break; | 540 break; |
525 } | 541 } |
526 if (sk_isdir(readPath)) { | 542 if (sk_isdir(readPath)) { |
527 const char* dir = readPath; | 543 const char* dir = readPath; |
528 SkOSFile::Iter iter(dir); | 544 SkOSFile::Iter iter(dir); |
529 SkString filename; | 545 SkString filename; |
530 while (iter.next(&filename)) { | 546 while (iter.next(&filename)) { |
547 if (!is_image_file(filename.c_str())) { | |
548 continue; | |
549 } | |
531 SkString fullname = SkOSPath::SkPathJoin(dir, filename.c_str()); | 550 SkString fullname = SkOSPath::SkPathJoin(dir, filename.c_str()); |
532 decodeFileAndWrite(fullname.c_str(), outDirPtr); | 551 decodeFileAndWrite(fullname.c_str(), outDirPtr); |
533 } | 552 } |
534 } else if (sk_exists(readPath)) { | 553 } else if (sk_exists(readPath) && is_image_file(readPath)) { |
535 decodeFileAndWrite(readPath, outDirPtr); | 554 decodeFileAndWrite(readPath, outDirPtr); |
536 } | 555 } |
537 } | 556 } |
538 | 557 |
539 if (!FLAGS_createExpectationsPath.isEmpty()) { | 558 if (!FLAGS_createExpectationsPath.isEmpty()) { |
540 // Use an empty value for everything besides expectations, since the rea der only cares | 559 // Use an empty value for everything besides expectations, since the rea der only cares |
541 // about the expectations. | 560 // about the expectations. |
542 Json::Value nullValue; | 561 Json::Value nullValue; |
543 Json::Value root = skiagm::CreateJsonTree(gExpectationsToWrite, nullValu e, nullValue, | 562 Json::Value root = skiagm::CreateJsonTree(gExpectationsToWrite, nullValu e, nullValue, |
544 nullValue, nullValue); | 563 nullValue, nullValue); |
(...skipping 16 matching lines...) Expand all Loading... | |
561 } | 580 } |
562 | 581 |
563 return failed ? -1 : 0; | 582 return failed ? -1 : 0; |
564 } | 583 } |
565 | 584 |
566 #if !defined SK_BUILD_FOR_IOS | 585 #if !defined SK_BUILD_FOR_IOS |
567 int main(int argc, char * const argv[]) { | 586 int main(int argc, char * const argv[]) { |
568 return tool_main(argc, (char**) argv); | 587 return tool_main(argc, (char**) argv); |
569 } | 588 } |
570 #endif | 589 #endif |
OLD | NEW |