Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tools/skimage_main.cpp

Issue 646213002: Eliminate one copy of replace_char() function. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add another test with some weird characters Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 "a digest\n", srcPath); 456 "a digest\n", srcPath);
457 return; 457 return;
458 } 458 }
459 if (!lengthLessDigest.equals(digest)) { 459 if (!lengthLessDigest.equals(digest)) {
460 gDecodeFailures.push_back().appendf("Without using getLength, %s did not match digest " 460 gDecodeFailures.push_back().appendf("Without using getLength, %s did not match digest "
461 "that uses getLength\n", srcPath); 461 "that uses getLength\n", srcPath);
462 } 462 }
463 } 463 }
464 #endif // defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) 464 #endif // defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
465 465
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) { 466 static void decodeFileAndWrite(const char srcPath[], const SkString* writePath) {
485 SkBitmap bitmap; 467 SkBitmap bitmap;
486 SkFILEStream stream(srcPath); 468 SkFILEStream stream(srcPath);
487 if (!stream.isValid()) { 469 if (!stream.isValid()) {
488 gInvalidStreams.push_back().set(srcPath); 470 gInvalidStreams.push_back().set(srcPath);
489 return; 471 return;
490 } 472 }
491 473
492 SkImageDecoder* codec = SkImageDecoder::Factory(&stream); 474 SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
493 if (NULL == codec) { 475 if (NULL == codec) {
494 gMissingCodecs.push_back().set(srcPath); 476 gMissingCodecs.push_back().set(srcPath);
495 return; 477 return;
496 } 478 }
497 479
498 SkAutoTDelete<SkImageDecoder> ad(codec); 480 SkAutoTDelete<SkImageDecoder> ad(codec);
499 481
500 codec->setSkipWritingZeroes(FLAGS_skip); 482 codec->setSkipWritingZeroes(FLAGS_skip);
501 codec->setSampleSize(FLAGS_sampleSize); 483 codec->setSampleSize(FLAGS_sampleSize);
502 stream.rewind(); 484 stream.rewind();
503 485
504 // Create a string representing just the filename itself, for use in json ex pectations. 486 // Create a string representing just the filename itself, for use in json ex pectations.
505 SkString basename = SkOSPath::Basename(srcPath); 487 SkString basename = SkOSPath::Basename(srcPath);
506 // Replace '_' with '-', so that the names can fit gm_json.py's IMAGE_FILENA ME_PATTERN 488 // Replace '_' with '-', so that the names can fit gm_json.py's IMAGE_FILENA ME_PATTERN
507 replace_char(&basename, '_', '-'); 489 basename.replace('_', '-');
508 // Replace '.' with '-', so the output filename can still retain the origina l file extension, 490 // 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. 491 // but still end up with only one '.', which denotes the actual extension of the final file.
510 replace_char(&basename, '.', '-'); 492 basename.replace('.', '-');
511 const char* filename = basename.c_str(); 493 const char* filename = basename.c_str();
512 494
513 if (!codec->decode(&stream, &bitmap, gPrefColorType, SkImageDecoder::kDecode Pixels_Mode)) { 495 if (!codec->decode(&stream, &bitmap, gPrefColorType, SkImageDecoder::kDecode Pixels_Mode)) {
514 if (gJsonExpectations.get()) { 496 if (gJsonExpectations.get()) {
515 const SkString name_config = create_json_key(filename); 497 const SkString name_config = create_json_key(filename);
516 skiagm::Expectations jsExpectations = gJsonExpectations->get(name_co nfig.c_str()); 498 skiagm::Expectations jsExpectations = gJsonExpectations->get(name_co nfig.c_str());
517 if (jsExpectations.ignoreFailure()) { 499 if (jsExpectations.ignoreFailure()) {
518 // This is a known failure. 500 // This is a known failure.
519 gKnownFailures.push_back().appendf( 501 gKnownFailures.push_back().appendf(
520 "failed to decode %s, which is a known failure.", srcPath); 502 "failed to decode %s, which is a known failure.", srcPath);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 print_strings("Known failures", gKnownFailures); 816 print_strings("Known failures", gKnownFailures);
835 817
836 return failed ? -1 : 0; 818 return failed ? -1 : 0;
837 } 819 }
838 820
839 #if !defined SK_BUILD_FOR_IOS 821 #if !defined SK_BUILD_FOR_IOS
840 int main(int argc, char * const argv[]) { 822 int main(int argc, char * const argv[]) {
841 return tool_main(argc, (char**) argv); 823 return tool_main(argc, (char**) argv);
842 } 824 }
843 #endif 825 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698