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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { | 73 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { |
74 if (strcmp(suffix, gFormats[i].fSuffix) == 0) { | 74 if (strcmp(suffix, gFormats[i].fSuffix) == 0) { |
75 return gFormats[i].fFormat; | 75 return gFormats[i].fFormat; |
76 } | 76 } |
77 } | 77 } |
78 return SkImageDecoder::kUnknown_Format; | 78 return SkImageDecoder::kUnknown_Format; |
79 } | 79 } |
80 | 80 |
81 static void make_outname(SkString* dst, const char outDir[], const char src[], | 81 static void make_outname(SkString* dst, const char outDir[], const char src[], |
82 const char suffix[]) { | 82 const char suffix[]) { |
83 SkString basename = SkOSPath::SkBasename(src); | 83 SkString basename = SkOSPath::Basename(src); |
84 dst->set(SkOSPath::SkPathJoin(outDir, basename.c_str())); | 84 dst->set(SkOSPath::Join(outDir, basename.c_str())); |
85 dst->append(suffix); | 85 dst->append(suffix); |
86 } | 86 } |
87 | 87 |
88 // Store the names of the filenames to report later which ones failed, succeeded
, and were | 88 // Store the names of the filenames to report later which ones failed, succeeded
, and were |
89 // invalid. | 89 // invalid. |
90 // FIXME: Add more arrays, for more specific types of errors, and make the outpu
t simpler. | 90 // FIXME: Add more arrays, for more specific types of errors, and make the outpu
t simpler. |
91 // If each array holds one type of error, the output can change from: | 91 // If each array holds one type of error, the output can change from: |
92 // | 92 // |
93 // Failures: | 93 // Failures: |
94 // <image> failed for such and such reason | 94 // <image> failed for such and such reason |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 * If false, the final image will be written out to: | 131 * If false, the final image will be written out to: |
132 * outDir/src.png | 132 * outDir/src.png |
133 * The function returns whether the file was successfully written. | 133 * The function returns whether the file was successfully written. |
134 */ | 134 */ |
135 static bool write_bitmap(const char outDir[], const char src[], | 135 static bool write_bitmap(const char outDir[], const char src[], |
136 const skiagm::BitmapAndDigest& bitmapAndDigest) { | 136 const skiagm::BitmapAndDigest& bitmapAndDigest) { |
137 SkString filename; | 137 SkString filename; |
138 if (FLAGS_writeChecksumBasedFilenames) { | 138 if (FLAGS_writeChecksumBasedFilenames) { |
139 // First create the directory for the hashtype. | 139 // First create the directory for the hashtype. |
140 const SkString hashType = bitmapAndDigest.fDigest.getHashType(); | 140 const SkString hashType = bitmapAndDigest.fDigest.getHashType(); |
141 const SkString hashDir = SkOSPath::SkPathJoin(outDir, hashType.c_str()); | 141 const SkString hashDir = SkOSPath::Join(outDir, hashType.c_str()); |
142 if (!sk_mkdir(hashDir.c_str())) { | 142 if (!sk_mkdir(hashDir.c_str())) { |
143 return false; | 143 return false; |
144 } | 144 } |
145 | 145 |
146 // Now create the name of the folder specific to this image. | 146 // Now create the name of the folder specific to this image. |
147 SkString basename = SkOSPath::SkBasename(src); | 147 SkString basename = SkOSPath::Basename(src); |
148 const SkString imageDir = SkOSPath::SkPathJoin(hashDir.c_str(), basename
.c_str()); | 148 const SkString imageDir = SkOSPath::Join(hashDir.c_str(), basename.c_str
()); |
149 if (!sk_mkdir(imageDir.c_str())) { | 149 if (!sk_mkdir(imageDir.c_str())) { |
150 return false; | 150 return false; |
151 } | 151 } |
152 | 152 |
153 // Name the file <digest>.png | 153 // Name the file <digest>.png |
154 SkString checksumBasedName = bitmapAndDigest.fDigest.getDigestValue(); | 154 SkString checksumBasedName = bitmapAndDigest.fDigest.getDigestValue(); |
155 checksumBasedName.append(".png"); | 155 checksumBasedName.append(".png"); |
156 | 156 |
157 filename = SkOSPath::SkPathJoin(imageDir.c_str(), checksumBasedName.c_st
r()); | 157 filename = SkOSPath::Join(imageDir.c_str(), checksumBasedName.c_str()); |
158 } else { | 158 } else { |
159 make_outname(&filename, outDir, src, ".png"); | 159 make_outname(&filename, outDir, src, ".png"); |
160 } | 160 } |
161 | 161 |
162 const SkBitmap& bm = bitmapAndDigest.fBitmap; | 162 const SkBitmap& bm = bitmapAndDigest.fBitmap; |
163 if (SkImageEncoder::EncodeFile(filename.c_str(), bm, SkImageEncoder::kPNG_Ty
pe, 100)) { | 163 if (SkImageEncoder::EncodeFile(filename.c_str(), bm, SkImageEncoder::kPNG_Ty
pe, 100)) { |
164 return true; | 164 return true; |
165 } | 165 } |
166 | 166 |
167 if (bm.colorType() == kN32_SkColorType) { | 167 if (bm.colorType() == kN32_SkColorType) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 const skiagm::BitmapAndDigest bitmapAndDigestFromDecod
eSubset, | 351 const skiagm::BitmapAndDigest bitmapAndDigestFromDecod
eSubset, |
352 SkIRect rect, const SkBitmap& originalBitmap) { | 352 SkIRect rect, const SkBitmap& originalBitmap) { |
353 // All parameters must be valid. | 353 // All parameters must be valid. |
354 SkASSERT(writePath != NULL); | 354 SkASSERT(writePath != NULL); |
355 | 355 |
356 SkString subsetPath; | 356 SkString subsetPath; |
357 if (FLAGS_writeChecksumBasedFilenames) { | 357 if (FLAGS_writeChecksumBasedFilenames) { |
358 subsetPath.set(writePath); | 358 subsetPath.set(writePath); |
359 } else { | 359 } else { |
360 // Create a subdirectory to hold the results of decodeSubset. | 360 // Create a subdirectory to hold the results of decodeSubset. |
361 subsetPath = SkOSPath::SkPathJoin(writePath, "subsets"); | 361 subsetPath = SkOSPath::Join(writePath, "subsets"); |
362 if (!sk_mkdir(subsetPath.c_str())) { | 362 if (!sk_mkdir(subsetPath.c_str())) { |
363 gFailedSubsetDecodes.push_back().printf("Successfully decoded subset
%s, but " | 363 gFailedSubsetDecodes.push_back().printf("Successfully decoded subset
%s, but " |
364 "failed to create a director
y to write to.", | 364 "failed to create a director
y to write to.", |
365 subsetName.c_str()); | 365 subsetName.c_str()); |
366 return false; | 366 return false; |
367 } | 367 } |
368 } | 368 } |
369 SkAssertResult(write_bitmap(subsetPath.c_str(), subsetName.c_str(), | 369 SkAssertResult(write_bitmap(subsetPath.c_str(), subsetName.c_str(), |
370 bitmapAndDigestFromDecodeSubset)); | 370 bitmapAndDigestFromDecodeSubset)); |
371 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", subsetName.c_str()
); | 371 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", subsetName.c_str()
); |
372 | 372 |
373 if (!FLAGS_writeChecksumBasedFilenames) { | 373 if (!FLAGS_writeChecksumBasedFilenames) { |
374 // FIXME: The goal of extracting the subset is for visual comparison/usi
ng skdiff/skpdiff. | 374 // FIXME: The goal of extracting the subset is for visual comparison/usi
ng skdiff/skpdiff. |
375 // Currently disabling for writeChecksumBasedFilenames since it will be
trickier to | 375 // Currently disabling for writeChecksumBasedFilenames since it will be
trickier to |
376 // determine which files to compare. | 376 // determine which files to compare. |
377 | 377 |
378 // Also use extractSubset from the original for visual comparison. | 378 // Also use extractSubset from the original for visual comparison. |
379 // Write the result to a file in a separate subdirectory. | 379 // Write the result to a file in a separate subdirectory. |
380 SkBitmap extractedSubset; | 380 SkBitmap extractedSubset; |
381 if (!originalBitmap.extractSubset(&extractedSubset, rect)) { | 381 if (!originalBitmap.extractSubset(&extractedSubset, rect)) { |
382 gFailedSubsetDecodes.push_back().printf("Successfully decoded subset
%s, but failed " | 382 gFailedSubsetDecodes.push_back().printf("Successfully decoded subset
%s, but failed " |
383 "to extract a similar subset
for comparison.", | 383 "to extract a similar subset
for comparison.", |
384 subsetName.c_str()); | 384 subsetName.c_str()); |
385 return false; | 385 return false; |
386 } | 386 } |
387 | 387 |
388 SkString dirExtracted = SkOSPath::SkPathJoin(writePath, "extracted"); | 388 SkString dirExtracted = SkOSPath::Join(writePath, "extracted"); |
389 if (!sk_mkdir(dirExtracted.c_str())) { | 389 if (!sk_mkdir(dirExtracted.c_str())) { |
390 gFailedSubsetDecodes.push_back().printf("Successfully decoded subset
%s, but failed " | 390 gFailedSubsetDecodes.push_back().printf("Successfully decoded subset
%s, but failed " |
391 "to create a directory for e
xtractSubset " | 391 "to create a directory for e
xtractSubset " |
392 "comparison.", | 392 "comparison.", |
393 subsetName.c_str()); | 393 subsetName.c_str()); |
394 return false; | 394 return false; |
395 } | 395 } |
396 | 396 |
397 skiagm::BitmapAndDigest bitmapAndDigestFromExtractSubset(extractedSubset
); | 397 skiagm::BitmapAndDigest bitmapAndDigestFromExtractSubset(extractedSubset
); |
398 SkAssertResult(write_bitmap(dirExtracted.c_str(), subsetName.c_str(), | 398 SkAssertResult(write_bitmap(dirExtracted.c_str(), subsetName.c_str(), |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 return; | 495 return; |
496 } | 496 } |
497 | 497 |
498 SkAutoTDelete<SkImageDecoder> ad(codec); | 498 SkAutoTDelete<SkImageDecoder> ad(codec); |
499 | 499 |
500 codec->setSkipWritingZeroes(FLAGS_skip); | 500 codec->setSkipWritingZeroes(FLAGS_skip); |
501 codec->setSampleSize(FLAGS_sampleSize); | 501 codec->setSampleSize(FLAGS_sampleSize); |
502 stream.rewind(); | 502 stream.rewind(); |
503 | 503 |
504 // Create a string representing just the filename itself, for use in json ex
pectations. | 504 // Create a string representing just the filename itself, for use in json ex
pectations. |
505 SkString basename = SkOSPath::SkBasename(srcPath); | 505 SkString basename = SkOSPath::Basename(srcPath); |
506 // Replace '_' with '-', so that the names can fit gm_json.py's IMAGE_FILENA
ME_PATTERN | 506 // Replace '_' with '-', so that the names can fit gm_json.py's IMAGE_FILENA
ME_PATTERN |
507 replace_char(&basename, '_', '-'); | 507 replace_char(&basename, '_', '-'); |
508 // Replace '.' with '-', so the output filename can still retain the origina
l file extension, | 508 // 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. | 509 // but still end up with only one '.', which denotes the actual extension of
the final file. |
510 replace_char(&basename, '.', '-'); | 510 replace_char(&basename, '.', '-'); |
511 const char* filename = basename.c_str(); | 511 const char* filename = basename.c_str(); |
512 | 512 |
513 if (!codec->decode(&stream, &bitmap, gPrefColorType, SkImageDecoder::kDecode
Pixels_Mode)) { | 513 if (!codec->decode(&stream, &bitmap, gPrefColorType, SkImageDecoder::kDecode
Pixels_Mode)) { |
514 if (NULL != gJsonExpectations.get()) { | 514 if (NULL != gJsonExpectations.get()) { |
515 const SkString name_config = create_json_key(filename); | 515 const SkString name_config = create_json_key(filename); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 break; | 789 break; |
790 } | 790 } |
791 if (sk_isdir(readPath)) { | 791 if (sk_isdir(readPath)) { |
792 const char* dir = readPath; | 792 const char* dir = readPath; |
793 SkOSFile::Iter iter(dir); | 793 SkOSFile::Iter iter(dir); |
794 SkString filename; | 794 SkString filename; |
795 while (iter.next(&filename)) { | 795 while (iter.next(&filename)) { |
796 if (!is_image_file(filename.c_str())) { | 796 if (!is_image_file(filename.c_str())) { |
797 continue; | 797 continue; |
798 } | 798 } |
799 SkString fullname = SkOSPath::SkPathJoin(dir, filename.c_str()); | 799 SkString fullname = SkOSPath::Join(dir, filename.c_str()); |
800 decodeFileAndWrite(fullname.c_str(), outDirPtr); | 800 decodeFileAndWrite(fullname.c_str(), outDirPtr); |
801 } | 801 } |
802 } else if (sk_exists(readPath) && is_image_file(readPath)) { | 802 } else if (sk_exists(readPath) && is_image_file(readPath)) { |
803 decodeFileAndWrite(readPath, outDirPtr); | 803 decodeFileAndWrite(readPath, outDirPtr); |
804 } | 804 } |
805 } | 805 } |
806 | 806 |
807 if (!FLAGS_createExpectationsPath.isEmpty()) { | 807 if (!FLAGS_createExpectationsPath.isEmpty()) { |
808 // Use an empty value for everything besides expectations, since the rea
der only cares | 808 // Use an empty value for everything besides expectations, since the rea
der only cares |
809 // about the expectations. | 809 // about the expectations. |
(...skipping 24 matching lines...) Expand all Loading... |
834 print_strings("Known failures", gKnownFailures); | 834 print_strings("Known failures", gKnownFailures); |
835 | 835 |
836 return failed ? -1 : 0; | 836 return failed ? -1 : 0; |
837 } | 837 } |
838 | 838 |
839 #if !defined SK_BUILD_FOR_IOS | 839 #if !defined SK_BUILD_FOR_IOS |
840 int main(int argc, char * const argv[]) { | 840 int main(int argc, char * const argv[]) { |
841 return tool_main(argc, (char**) argv); | 841 return tool_main(argc, (char**) argv); |
842 } | 842 } |
843 #endif | 843 #endif |
OLD | NEW |