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