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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 "a digest\n", srcPath); | 457 "a digest\n", srcPath); |
458 return; | 458 return; |
459 } | 459 } |
460 if (!lengthLessDigest.equals(digest)) { | 460 if (!lengthLessDigest.equals(digest)) { |
461 gDecodeFailures.push_back().appendf("Without using getLength, %s did not
match digest " | 461 gDecodeFailures.push_back().appendf("Without using getLength, %s did not
match digest " |
462 "that uses getLength\n", srcPath); | 462 "that uses getLength\n", srcPath); |
463 } | 463 } |
464 } | 464 } |
465 #endif // defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) | 465 #endif // defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) |
466 | 466 |
467 /** | |
468 * Replaces all instances of oldChar with newChar in str. | |
469 * | |
470 * TODO: This function appears here and in picture_utils.[cpp|h] ; | |
471 * we should add the implementation to src/core/SkString.cpp, write tests for it
, | |
472 * and remove it from elsewhere. | |
473 */ | |
474 static void replace_char(SkString* str, const char oldChar, const char newChar)
{ | |
475 if (NULL == str) { | |
476 return; | |
477 } | |
478 for (size_t i = 0; i < str->size(); ++i) { | |
479 if (oldChar == str->operator[](i)) { | |
480 str->operator[](i) = newChar; | |
481 } | |
482 } | |
483 } | |
484 | |
485 static void decodeFileAndWrite(const char srcPath[], const SkString* writePath)
{ | 467 static void decodeFileAndWrite(const char srcPath[], const SkString* writePath)
{ |
486 SkBitmap bitmap; | 468 SkBitmap bitmap; |
487 SkFILEStream stream(srcPath); | 469 SkFILEStream stream(srcPath); |
488 if (!stream.isValid()) { | 470 if (!stream.isValid()) { |
489 gInvalidStreams.push_back().set(srcPath); | 471 gInvalidStreams.push_back().set(srcPath); |
490 return; | 472 return; |
491 } | 473 } |
492 | 474 |
493 SkImageDecoder* codec = SkImageDecoder::Factory(&stream); | 475 SkImageDecoder* codec = SkImageDecoder::Factory(&stream); |
494 if (NULL == codec) { | 476 if (NULL == codec) { |
495 gMissingCodecs.push_back().set(srcPath); | 477 gMissingCodecs.push_back().set(srcPath); |
496 return; | 478 return; |
497 } | 479 } |
498 | 480 |
499 SkAutoTDelete<SkImageDecoder> ad(codec); | 481 SkAutoTDelete<SkImageDecoder> ad(codec); |
500 | 482 |
501 codec->setSkipWritingZeroes(FLAGS_skip); | 483 codec->setSkipWritingZeroes(FLAGS_skip); |
502 codec->setSampleSize(FLAGS_sampleSize); | 484 codec->setSampleSize(FLAGS_sampleSize); |
503 codec->setRequireUnpremultipliedColors(FLAGS_unpremul); | 485 codec->setRequireUnpremultipliedColors(FLAGS_unpremul); |
504 stream.rewind(); | 486 stream.rewind(); |
505 | 487 |
506 // Create a string representing just the filename itself, for use in json ex
pectations. | 488 // Create a string representing just the filename itself, for use in json ex
pectations. |
507 SkString basename = SkOSPath::Basename(srcPath); | 489 SkString basename = SkOSPath::Basename(srcPath); |
508 // Replace '_' with '-', so that the names can fit gm_json.py's IMAGE_FILENA
ME_PATTERN | 490 // Replace '_' with '-', so that the names can fit gm_json.py's IMAGE_FILENA
ME_PATTERN |
509 replace_char(&basename, '_', '-'); | 491 basename.replace('_', '-'); |
510 // Replace '.' with '-', so the output filename can still retain the origina
l file extension, | 492 // Replace '.' with '-', so the output filename can still retain the origina
l file extension, |
511 // but still end up with only one '.', which denotes the actual extension of
the final file. | 493 // but still end up with only one '.', which denotes the actual extension of
the final file. |
512 replace_char(&basename, '.', '-'); | 494 basename.replace('.', '-'); |
513 const char* filename = basename.c_str(); | 495 const char* filename = basename.c_str(); |
514 | 496 |
515 if (!codec->decode(&stream, &bitmap, gPrefColorType, SkImageDecoder::kDecode
Pixels_Mode)) { | 497 if (!codec->decode(&stream, &bitmap, gPrefColorType, SkImageDecoder::kDecode
Pixels_Mode)) { |
516 if (gJsonExpectations.get()) { | 498 if (gJsonExpectations.get()) { |
517 const SkString name_config = create_json_key(filename); | 499 const SkString name_config = create_json_key(filename); |
518 skiagm::Expectations jsExpectations = gJsonExpectations->get(name_co
nfig.c_str()); | 500 skiagm::Expectations jsExpectations = gJsonExpectations->get(name_co
nfig.c_str()); |
519 if (jsExpectations.ignoreFailure()) { | 501 if (jsExpectations.ignoreFailure()) { |
520 // This is a known failure. | 502 // This is a known failure. |
521 gKnownFailures.push_back().appendf( | 503 gKnownFailures.push_back().appendf( |
522 "failed to decode %s, which is a known failure.", srcPath); | 504 "failed to decode %s, which is a known failure.", srcPath); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 print_strings("Known failures", gKnownFailures); | 818 print_strings("Known failures", gKnownFailures); |
837 | 819 |
838 return failed ? -1 : 0; | 820 return failed ? -1 : 0; |
839 } | 821 } |
840 | 822 |
841 #if !defined SK_BUILD_FOR_IOS | 823 #if !defined SK_BUILD_FOR_IOS |
842 int main(int argc, char * const argv[]) { | 824 int main(int argc, char * const argv[]) { |
843 return tool_main(argc, (char**) argv); | 825 return tool_main(argc, (char**) argv); |
844 } | 826 } |
845 #endif | 827 #endif |
OLD | NEW |