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 #include "skdiff.h" | 7 #include "skdiff.h" |
8 #include "skdiff_html.h" | 8 #include "skdiff_html.h" |
9 #include "skdiff_utils.h" | 9 #include "skdiff_utils.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 get_bitmap(fileBits, resource, SkImageDecoder::kDecodeBounds_Mode); | 304 get_bitmap(fileBits, resource, SkImageDecoder::kDecodeBounds_Mode); |
305 } | 305 } |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
309 static void get_bounds(DiffRecord& drp) { | 309 static void get_bounds(DiffRecord& drp) { |
310 get_bounds(drp.fBase, "base"); | 310 get_bounds(drp.fBase, "base"); |
311 get_bounds(drp.fComparison, "comparison"); | 311 get_bounds(drp.fComparison, "comparison"); |
312 } | 312 } |
313 | 313 |
314 #define ANSI_COLOR_RED "\x1b[31m" | |
315 #define ANSI_COLOR_GREEN "\x1b[32m" | |
316 #define ANSI_COLOR_YELLOW "\x1b[33m" | |
317 #define ANSI_COLOR_RESET "\x1b[0m" | |
318 | |
319 #define VERBOSE_STATUS(status,color,filename) if (verbose) printf( "[ " color " %10s " ANSI_COLOR_RESET " ] %s\n", status, filename->c_str()) | |
bungeman-skia
2014/05/28 17:34:28
Can we ifdef SK_OS_WIN or something here so we don
humper
2014/05/28 17:55:31
Done.
| |
320 | |
314 /// Creates difference images, returns the number that have a 0 metric. | 321 /// Creates difference images, returns the number that have a 0 metric. |
315 /// If outputDir.isEmpty(), don't write out diff files. | 322 /// If outputDir.isEmpty(), don't write out diff files. |
316 static void create_diff_images (DiffMetricProc dmp, | 323 static void create_diff_images (DiffMetricProc dmp, |
317 const int colorThreshold, | 324 const int colorThreshold, |
318 RecordArray* differences, | 325 RecordArray* differences, |
319 const SkString& baseDir, | 326 const SkString& baseDir, |
320 const SkString& comparisonDir, | 327 const SkString& comparisonDir, |
321 const SkString& outputDir, | 328 const SkString& outputDir, |
322 const StringArray& matchSubstrings, | 329 const StringArray& matchSubstrings, |
323 const StringArray& nomatchSubstrings, | 330 const StringArray& nomatchSubstrings, |
324 bool recurseIntoSubdirs, | 331 bool recurseIntoSubdirs, |
325 bool getBounds, | 332 bool getBounds, |
333 bool verbose, | |
326 DiffSummary* summary) { | 334 DiffSummary* summary) { |
327 SkASSERT(!baseDir.isEmpty()); | 335 SkASSERT(!baseDir.isEmpty()); |
328 SkASSERT(!comparisonDir.isEmpty()); | 336 SkASSERT(!comparisonDir.isEmpty()); |
329 | 337 |
330 FileArray baseFiles; | 338 FileArray baseFiles; |
331 FileArray comparisonFiles; | 339 FileArray comparisonFiles; |
332 | 340 |
333 get_file_list(baseDir, matchSubstrings, nomatchSubstrings, recurseIntoSubdir s, &baseFiles); | 341 get_file_list(baseDir, matchSubstrings, nomatchSubstrings, recurseIntoSubdir s, &baseFiles); |
334 get_file_list(comparisonDir, matchSubstrings, nomatchSubstrings, recurseInto Subdirs, | 342 get_file_list(comparisonDir, matchSubstrings, nomatchSubstrings, recurseInto Subdirs, |
335 &comparisonFiles); | 343 &comparisonFiles); |
(...skipping 27 matching lines...) Expand all Loading... | |
363 comparisonPath.append(*baseFiles[i]); | 371 comparisonPath.append(*baseFiles[i]); |
364 | 372 |
365 drp->fBase.fFilename = *baseFiles[i]; | 373 drp->fBase.fFilename = *baseFiles[i]; |
366 drp->fBase.fFullPath = basePath; | 374 drp->fBase.fFullPath = basePath; |
367 drp->fBase.fStatus = DiffResource::kExists_Status; | 375 drp->fBase.fStatus = DiffResource::kExists_Status; |
368 | 376 |
369 drp->fComparison.fFilename = *baseFiles[i]; | 377 drp->fComparison.fFilename = *baseFiles[i]; |
370 drp->fComparison.fFullPath = comparisonPath; | 378 drp->fComparison.fFullPath = comparisonPath; |
371 drp->fComparison.fStatus = DiffResource::kDoesNotExist_Status; | 379 drp->fComparison.fStatus = DiffResource::kDoesNotExist_Status; |
372 | 380 |
381 VERBOSE_STATUS("MISSING", ANSI_COLOR_YELLOW, baseFiles[i]); | |
382 | |
373 ++i; | 383 ++i; |
374 } else if (v > 0) { | 384 } else if (v > 0) { |
375 // in comparisonDir, but not in baseDir | 385 // in comparisonDir, but not in baseDir |
376 drp->fResult = DiffRecord::kCouldNotCompare_Result; | 386 drp->fResult = DiffRecord::kCouldNotCompare_Result; |
377 | 387 |
378 basePath.append(*comparisonFiles[j]); | 388 basePath.append(*comparisonFiles[j]); |
379 comparisonPath.append(*comparisonFiles[j]); | 389 comparisonPath.append(*comparisonFiles[j]); |
380 | 390 |
381 drp->fBase.fFilename = *comparisonFiles[j]; | 391 drp->fBase.fFilename = *comparisonFiles[j]; |
382 drp->fBase.fFullPath = basePath; | 392 drp->fBase.fFullPath = basePath; |
383 drp->fBase.fStatus = DiffResource::kDoesNotExist_Status; | 393 drp->fBase.fStatus = DiffResource::kDoesNotExist_Status; |
384 | 394 |
385 drp->fComparison.fFilename = *comparisonFiles[j]; | 395 drp->fComparison.fFilename = *comparisonFiles[j]; |
386 drp->fComparison.fFullPath = comparisonPath; | 396 drp->fComparison.fFullPath = comparisonPath; |
387 drp->fComparison.fStatus = DiffResource::kExists_Status; | 397 drp->fComparison.fStatus = DiffResource::kExists_Status; |
388 | 398 |
399 VERBOSE_STATUS("MISSING", ANSI_COLOR_YELLOW, comparisonFiles[j]); | |
400 | |
389 ++j; | 401 ++j; |
390 } else { | 402 } else { |
391 // Found the same filename in both baseDir and comparisonDir. | 403 // Found the same filename in both baseDir and comparisonDir. |
392 SkASSERT(DiffRecord::kUnknown_Result == drp->fResult); | 404 SkASSERT(DiffRecord::kUnknown_Result == drp->fResult); |
393 | 405 |
394 basePath.append(*baseFiles[i]); | 406 basePath.append(*baseFiles[i]); |
395 comparisonPath.append(*comparisonFiles[j]); | 407 comparisonPath.append(*comparisonFiles[j]); |
396 | 408 |
397 drp->fBase.fFilename = *baseFiles[i]; | 409 drp->fBase.fFilename = *baseFiles[i]; |
398 drp->fBase.fFullPath = basePath; | 410 drp->fBase.fFullPath = basePath; |
399 drp->fBase.fStatus = DiffResource::kExists_Status; | 411 drp->fBase.fStatus = DiffResource::kExists_Status; |
400 | 412 |
401 drp->fComparison.fFilename = *comparisonFiles[j]; | 413 drp->fComparison.fFilename = *comparisonFiles[j]; |
402 drp->fComparison.fFullPath = comparisonPath; | 414 drp->fComparison.fFullPath = comparisonPath; |
403 drp->fComparison.fStatus = DiffResource::kExists_Status; | 415 drp->fComparison.fStatus = DiffResource::kExists_Status; |
404 | 416 |
405 SkAutoDataUnref baseFileBits(read_file(drp->fBase.fFullPath.c_str()) ); | 417 SkAutoDataUnref baseFileBits(read_file(drp->fBase.fFullPath.c_str()) ); |
406 if (NULL != baseFileBits) { | 418 if (NULL != baseFileBits) { |
407 drp->fBase.fStatus = DiffResource::kRead_Status; | 419 drp->fBase.fStatus = DiffResource::kRead_Status; |
420 | |
bungeman-skia
2014/05/28 17:34:28
remove extra line?
humper
2014/05/28 17:55:31
Done.
| |
408 } | 421 } |
409 SkAutoDataUnref comparisonFileBits(read_file(drp->fComparison.fFullP ath.c_str())); | 422 SkAutoDataUnref comparisonFileBits(read_file(drp->fComparison.fFullP ath.c_str())); |
410 if (NULL != comparisonFileBits) { | 423 if (NULL != comparisonFileBits) { |
411 drp->fComparison.fStatus = DiffResource::kRead_Status; | 424 drp->fComparison.fStatus = DiffResource::kRead_Status; |
412 } | 425 } |
413 if (NULL == baseFileBits || NULL == comparisonFileBits) { | 426 if (NULL == baseFileBits || NULL == comparisonFileBits) { |
414 if (NULL == baseFileBits) { | 427 if (NULL == baseFileBits) { |
415 drp->fBase.fStatus = DiffResource::kCouldNotRead_Status; | 428 drp->fBase.fStatus = DiffResource::kCouldNotRead_Status; |
429 VERBOSE_STATUS("READ FAIL", ANSI_COLOR_RED, baseFiles[i]); | |
416 } | 430 } |
417 if (NULL == comparisonFileBits) { | 431 if (NULL == comparisonFileBits) { |
418 drp->fComparison.fStatus = DiffResource::kCouldNotRead_Statu s; | 432 drp->fComparison.fStatus = DiffResource::kCouldNotRead_Statu s; |
433 VERBOSE_STATUS("READ FAIL", ANSI_COLOR_RED, comparisonFiles[ j]); | |
419 } | 434 } |
420 drp->fResult = DiffRecord::kCouldNotCompare_Result; | 435 drp->fResult = DiffRecord::kCouldNotCompare_Result; |
421 | 436 |
422 } else if (are_buffers_equal(baseFileBits, comparisonFileBits)) { | 437 } else if (are_buffers_equal(baseFileBits, comparisonFileBits)) { |
423 drp->fResult = DiffRecord::kEqualBits_Result; | 438 drp->fResult = DiffRecord::kEqualBits_Result; |
424 | 439 VERBOSE_STATUS("MATCH", ANSI_COLOR_GREEN, baseFiles[i]); |
425 } else { | 440 } else { |
426 AutoReleasePixels arp(drp); | 441 AutoReleasePixels arp(drp); |
427 get_bitmap(baseFileBits, drp->fBase, SkImageDecoder::kDecodePixe ls_Mode); | 442 get_bitmap(baseFileBits, drp->fBase, SkImageDecoder::kDecodePixe ls_Mode); |
428 get_bitmap(comparisonFileBits, drp->fComparison, | 443 get_bitmap(comparisonFileBits, drp->fComparison, |
429 SkImageDecoder::kDecodePixels_Mode); | 444 SkImageDecoder::kDecodePixels_Mode); |
445 VERBOSE_STATUS("DIFFERENT", ANSI_COLOR_RED, baseFiles[i]); | |
430 if (DiffResource::kDecoded_Status == drp->fBase.fStatus && | 446 if (DiffResource::kDecoded_Status == drp->fBase.fStatus && |
431 DiffResource::kDecoded_Status == drp->fComparison.fStatus) { | 447 DiffResource::kDecoded_Status == drp->fComparison.fStatus) { |
432 create_and_write_diff_image(drp, dmp, colorThreshold, | 448 create_and_write_diff_image(drp, dmp, colorThreshold, |
433 outputDir, drp->fBase.fFilename) ; | 449 outputDir, drp->fBase.fFilename) ; |
434 } else { | 450 } else { |
435 drp->fResult = DiffRecord::kCouldNotCompare_Result; | 451 drp->fResult = DiffRecord::kCouldNotCompare_Result; |
436 } | 452 } |
437 } | 453 } |
438 | 454 |
455 | |
bungeman-skia
2014/05/28 17:34:28
remove extra line?
humper
2014/05/28 17:55:31
Done.
| |
439 ++i; | 456 ++i; |
440 ++j; | 457 ++j; |
441 } | 458 } |
442 | 459 |
443 if (getBounds) { | 460 if (getBounds) { |
444 get_bounds(*drp); | 461 get_bounds(*drp); |
445 } | 462 } |
446 SkASSERT(DiffRecord::kUnknown_Result != drp->fResult); | 463 SkASSERT(DiffRecord::kUnknown_Result != drp->fResult); |
447 differences->push(drp); | 464 differences->push(drp); |
448 summary->add(drp); | 465 summary->add(drp); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 SkString comparisonDir; | 568 SkString comparisonDir; |
552 SkString outputDir; | 569 SkString outputDir; |
553 | 570 |
554 StringArray matchSubstrings; | 571 StringArray matchSubstrings; |
555 StringArray nomatchSubstrings; | 572 StringArray nomatchSubstrings; |
556 | 573 |
557 bool generateDiffs = true; | 574 bool generateDiffs = true; |
558 bool listFilenames = false; | 575 bool listFilenames = false; |
559 bool printDirNames = true; | 576 bool printDirNames = true; |
560 bool recurseIntoSubdirs = true; | 577 bool recurseIntoSubdirs = true; |
578 bool verbose = false; | |
561 | 579 |
562 RecordArray differences; | 580 RecordArray differences; |
563 DiffSummary summary; | 581 DiffSummary summary; |
564 | 582 |
565 bool failOnResultType[DiffRecord::kResultCount]; | 583 bool failOnResultType[DiffRecord::kResultCount]; |
566 for (int i = 0; i < DiffRecord::kResultCount; i++) { | 584 for (int i = 0; i < DiffRecord::kResultCount; i++) { |
567 failOnResultType[i] = false; | 585 failOnResultType[i] = false; |
568 } | 586 } |
569 | 587 |
570 bool failOnStatusType[DiffResource::kStatusCount][DiffResource::kStatusCount ]; | 588 bool failOnStatusType[DiffResource::kStatusCount][DiffResource::kStatusCount ]; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 continue; | 636 continue; |
619 } | 637 } |
620 if (!strcmp(argv[i], "--help")) { | 638 if (!strcmp(argv[i], "--help")) { |
621 usage(argv[0]); | 639 usage(argv[0]); |
622 return kNoError; | 640 return kNoError; |
623 } | 641 } |
624 if (!strcmp(argv[i], "--listfilenames")) { | 642 if (!strcmp(argv[i], "--listfilenames")) { |
625 listFilenames = true; | 643 listFilenames = true; |
626 continue; | 644 continue; |
627 } | 645 } |
646 if (!strcmp(argv[i], "--verbose")) { | |
647 verbose = true; | |
648 continue; | |
649 } | |
628 if (!strcmp(argv[i], "--match")) { | 650 if (!strcmp(argv[i], "--match")) { |
629 matchSubstrings.push(new SkString(argv[++i])); | 651 matchSubstrings.push(new SkString(argv[++i])); |
630 continue; | 652 continue; |
631 } | 653 } |
632 if (!strcmp(argv[i], "--nodiffs")) { | 654 if (!strcmp(argv[i], "--nodiffs")) { |
633 generateDiffs = false; | 655 generateDiffs = false; |
634 continue; | 656 continue; |
635 } | 657 } |
636 if (!strcmp(argv[i], "--nomatch")) { | 658 if (!strcmp(argv[i], "--nomatch")) { |
637 nomatchSubstrings.push(new SkString(argv[++i])); | 659 nomatchSubstrings.push(new SkString(argv[++i])); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 | 743 |
722 // If no matchSubstrings were specified, match ALL strings | 744 // If no matchSubstrings were specified, match ALL strings |
723 // (except for whatever nomatchSubstrings were specified, if any). | 745 // (except for whatever nomatchSubstrings were specified, if any). |
724 if (matchSubstrings.isEmpty()) { | 746 if (matchSubstrings.isEmpty()) { |
725 matchSubstrings.push(new SkString("")); | 747 matchSubstrings.push(new SkString("")); |
726 } | 748 } |
727 | 749 |
728 create_diff_images(diffProc, colorThreshold, &differences, | 750 create_diff_images(diffProc, colorThreshold, &differences, |
729 baseDir, comparisonDir, outputDir, | 751 baseDir, comparisonDir, outputDir, |
730 matchSubstrings, nomatchSubstrings, recurseIntoSubdirs, g enerateDiffs, | 752 matchSubstrings, nomatchSubstrings, recurseIntoSubdirs, g enerateDiffs, |
731 &summary); | 753 verbose, &summary); |
732 summary.print(listFilenames, failOnResultType, failOnStatusType); | 754 summary.print(listFilenames, failOnResultType, failOnStatusType); |
733 | 755 |
734 if (differences.count()) { | 756 if (differences.count()) { |
735 qsort(differences.begin(), differences.count(), | 757 qsort(differences.begin(), differences.count(), |
736 sizeof(DiffRecord*), sortProc); | 758 sizeof(DiffRecord*), sortProc); |
737 } | 759 } |
738 | 760 |
739 if (generateDiffs) { | 761 if (generateDiffs) { |
740 print_diff_page(summary.fNumMatches, colorThreshold, differences, | 762 print_diff_page(summary.fNumMatches, colorThreshold, differences, |
741 baseDir, comparisonDir, outputDir); | 763 baseDir, comparisonDir, outputDir); |
(...skipping 25 matching lines...) Expand all Loading... | |
767 // range [0...255] are wrapped (mod 256). Do the conversion ourselves, to | 789 // range [0...255] are wrapped (mod 256). Do the conversion ourselves, to |
768 // make sure that we only return 0 when there were no failures. | 790 // make sure that we only return 0 when there were no failures. |
769 return (num_failing_results > 255) ? 255 : num_failing_results; | 791 return (num_failing_results > 255) ? 255 : num_failing_results; |
770 } | 792 } |
771 | 793 |
772 #if !defined SK_BUILD_FOR_IOS | 794 #if !defined SK_BUILD_FOR_IOS |
773 int main(int argc, char * const argv[]) { | 795 int main(int argc, char * const argv[]) { |
774 return tool_main(argc, (char**) argv); | 796 return tool_main(argc, (char**) argv); |
775 } | 797 } |
776 #endif | 798 #endif |
OLD | NEW |