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 "SkBitmapHasher.h" | 10 #include "SkBitmapHasher.h" |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 if (compare_to_expectations_if_necessary(bitmapFromDecodeSub set, | 292 if (compare_to_expectations_if_necessary(bitmapFromDecodeSub set, |
293 subsetName.c_str(), | 293 subsetName.c_str(), |
294 &gFailedSubsetDecod es)) { | 294 &gFailedSubsetDecod es)) { |
295 gSuccessfulSubsetDecodes.push_back().printf("Decoded sub set %s from %s", | 295 gSuccessfulSubsetDecodes.push_back().printf("Decoded sub set %s from %s", |
296 subsetDim.c_str(), srcPath); | 296 subsetDim.c_str(), srcPath); |
297 } | 297 } |
298 | 298 |
299 write_expectations(bitmapFromDecodeSubset, subsetName.c_str( )); | 299 write_expectations(bitmapFromDecodeSubset, subsetName.c_str( )); |
300 | 300 |
301 if (writePath != NULL) { | 301 if (writePath != NULL) { |
302 // Write the region to a file whose name includes the di mensions. | 302 // Create a subdirectory to hold the results of decodeSu bset. |
303 SkString suffix = SkStringPrintf("_%s.png", subsetDim.c_ str()); | 303 SkString dir(*writePath); |
304 SkString outPath; | 304 dir.appendf("%s%c", "subsets", SkPATH_SEPARATOR); |
305 make_outname(&outPath, writePath->c_str(), srcPath, suff ix.c_str()); | 305 if (sk_mkdir(dir.c_str())) { |
306 SkDEBUGCODE(bool success =) | 306 // Write the subset to a file whose name includes th e dimensions. |
307 write_bitmap(outPath.c_str(), &bitmapFromDecodeSubset); | 307 SkString suffix = SkStringPrintf("_%s.png", subsetDi m.c_str()); |
308 SkASSERT(success); | 308 SkString outPath; |
309 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s" , outPath.c_str()); | 309 make_outname(&outPath, dir.c_str(), srcPath, suffix. c_str()); |
310 // Also use extractSubset from the original for visual c omparison. | 310 SkAssertResult(write_bitmap(outPath.c_str(), &bitmap FromDecodeSubset)); |
311 SkBitmap extractedSubset; | 311 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", |
312 if (bitmap.extractSubset(&extractedSubset, rect)) { | 312 outPath. c_str()); |
313 suffix.printf("_%s_extracted.png", subsetDim.c_str() ); | 313 // Also use extractSubset from the original for visu al comparison. |
314 make_outname(&outPath, writePath->c_str(), srcPath, suffix.c_str()); | 314 // Write the result to a file in a separate subdirec tory. |
315 SkDEBUGCODE(success =) write_bitmap(outPath.c_str(), &extractedSubset); | 315 SkBitmap extractedSubset; |
316 SkASSERT(success); | 316 if (bitmap.extractSubset(&extractedSubset, rect)) { |
317 SkString dirExtracted(*writePath); | |
318 dirExtracted.appendf("%s%c", "extracted", SkPATH _SEPARATOR); | |
319 if (sk_mkdir(dirExtracted.c_str())) { | |
320 make_outname(&outPath, dirExtracted.c_str(), srcPath, | |
321 suffix.c_str()); | |
322 SkAssertResult(write_bitmap(outPath.c_str(), | |
323 &extractedSubset )); | |
324 } else { | |
325 gFailedSubsetDecodes.push_back().printf("Suc cessfully decoded " | |
326 "%s from %s, but " | |
327 "fai led to create a " | |
328 "dir ectory for " | |
329 "ext ractSubset " | |
330 "com parison.", | |
331 subs etDim.c_str(), | |
332 file name); | |
333 } | |
334 } else { | |
335 gFailedSubsetDecodes.push_back().printf("Success fully decoded %s " | |
336 "from %s , but failed to " | |
337 "extract a similar subset " | |
338 "for com parison.", | |
339 subsetDi m.c_str(), | |
340 filename ); | |
341 } | |
342 } else { | |
343 gFailedSubsetDecodes.push_back().printf("Successfull y decoded %s from " | |
epoger
2013/05/14 15:50:31
As we've discussed before, I think it's a lot clea
scroggo
2013/05/14 20:13:13
Done.
| |
344 "%s, but fai led to create a " | |
345 "directory t o write to.", | |
346 subsetDim.c_ str(), filename); | |
317 } | 347 } |
318 } | 348 } |
319 } else { | 349 } else { |
320 gFailedSubsetDecodes.push_back().printf("Failed to decode re gion %s from %s\n", | 350 gFailedSubsetDecodes.push_back().printf("Failed to decode re gion %s from %s", |
321 subsetDim.c_str(), s rcPath); | 351 subsetDim.c_str(), s rcPath); |
322 } | 352 } |
323 } | 353 } |
324 } | 354 } |
325 } | 355 } |
326 if (FLAGS_reencode) { | 356 if (FLAGS_reencode) { |
327 // Encode to the format the file was originally in, or PNG if the encode r for the same | 357 // Encode to the format the file was originally in, or PNG if the encode r for the same |
328 // format is unavailable. | 358 // format is unavailable. |
329 SkImageDecoder::Format format = codec->getFormat(); | 359 SkImageDecoder::Format format = codec->getFormat(); |
330 if (SkImageDecoder::kUnknown_Format == format) { | 360 if (SkImageDecoder::kUnknown_Format == format) { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 } | 535 } |
506 | 536 |
507 return failed ? -1 : 0; | 537 return failed ? -1 : 0; |
508 } | 538 } |
509 | 539 |
510 #if !defined SK_BUILD_FOR_IOS | 540 #if !defined SK_BUILD_FOR_IOS |
511 int main(int argc, char * const argv[]) { | 541 int main(int argc, char * const argv[]) { |
512 return tool_main(argc, (char**) argv); | 542 return tool_main(argc, (char**) argv); |
513 } | 543 } |
514 #endif | 544 #endif |
OLD | NEW |