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" |
11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
12 #include "SkCommandLineFlags.h" | 12 #include "SkCommandLineFlags.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
14 #include "SkGraphics.h" | 14 #include "SkGraphics.h" |
15 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
16 #include "SkImageEncoder.h" | 16 #include "SkImageEncoder.h" |
17 #include "SkOSFile.h" | 17 #include "SkOSFile.h" |
| 18 #include "SkOSPathUtils.h" |
18 #include "SkRandom.h" | 19 #include "SkRandom.h" |
19 #include "SkStream.h" | 20 #include "SkStream.h" |
20 #include "SkTArray.h" | 21 #include "SkTArray.h" |
21 #include "SkTemplates.h" | 22 #include "SkTemplates.h" |
22 | 23 |
23 DEFINE_string(createExpectationsPath, "", "Path to write JSON expectations."); | 24 DEFINE_string(createExpectationsPath, "", "Path to write JSON expectations."); |
24 DEFINE_string2(readPath, r, "", "Folder(s) and files to decode images. Required.
"); | 25 DEFINE_string2(readPath, r, "", "Folder(s) and files to decode images. Required.
"); |
25 DEFINE_string(readExpectationsPath, "", "Path to read JSON expectations from."); | 26 DEFINE_string(readExpectationsPath, "", "Path to read JSON expectations from."); |
26 DEFINE_string2(writePath, w, "", "Write rendered images into this directory."); | 27 DEFINE_string2(writePath, w, "", "Write rendered images into this directory."); |
27 DEFINE_bool(reencode, true, "Reencode the images to test encoding."); | 28 DEFINE_bool(reencode, true, "Reencode the images to test encoding."); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 64 |
64 static SkImageDecoder::Format guess_format_from_suffix(const char suffix[]) { | 65 static SkImageDecoder::Format guess_format_from_suffix(const char suffix[]) { |
65 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { | 66 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { |
66 if (strcmp(suffix, gFormats[i].fSuffix) == 0) { | 67 if (strcmp(suffix, gFormats[i].fSuffix) == 0) { |
67 return gFormats[i].fFormat; | 68 return gFormats[i].fFormat; |
68 } | 69 } |
69 } | 70 } |
70 return SkImageDecoder::kUnknown_Format; | 71 return SkImageDecoder::kUnknown_Format; |
71 } | 72 } |
72 | 73 |
73 /** | |
74 * Return the name of the file, ignoring the directory structure. | |
75 * Does not create a new string. | |
76 * @param fullPath Full path to the file. | |
77 * @return string The basename of the file - anything beyond the final slash, o
r the full name | |
78 * if there is no slash. | |
79 * TODO: Might this be useful as a utility function in SkOSFile? Would it be mo
re appropriate to | |
80 * create a new string? | |
81 */ | |
82 static const char* SkBasename(const char* fullPath) { | |
83 const char* filename = strrchr(fullPath, SkPATH_SEPARATOR); | |
84 if (NULL == filename || *++filename == '\0') { | |
85 filename = fullPath; | |
86 } | |
87 return filename; | |
88 } | |
89 | |
90 static void make_outname(SkString* dst, const char outDir[], const char src[], | 74 static void make_outname(SkString* dst, const char outDir[], const char src[], |
91 const char suffix[]) { | 75 const char suffix[]) { |
92 const char* basename = SkBasename(src); | 76 const char* basename = SkBasename(src); |
93 dst->set(skiagm::SkPathJoin(outDir, basename)); | 77 dst->set(SkPathJoin(outDir, basename)); |
94 if (!dst->endsWith(suffix)) { | 78 if (!dst->endsWith(suffix)) { |
95 const char* cstyleDst = dst->c_str(); | 79 const char* cstyleDst = dst->c_str(); |
96 const char* dot = strrchr(cstyleDst, '.'); | 80 const char* dot = strrchr(cstyleDst, '.'); |
97 if (dot != NULL) { | 81 if (dot != NULL) { |
98 int32_t index = SkToS32(dot - cstyleDst); | 82 int32_t index = SkToS32(dot - cstyleDst); |
99 dst->remove(index, dst->size() - index); | 83 dst->remove(index, dst->size() - index); |
100 } | 84 } |
101 dst->append(suffix); | 85 dst->append(suffix); |
102 } | 86 } |
103 } | 87 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 static bool write_subset(const char* writePath, const char* filename, const char
* subsetDim, | 250 static bool write_subset(const char* writePath, const char* filename, const char
* subsetDim, |
267 SkBitmap* bitmapFromDecodeSubset, SkIRect rect, | 251 SkBitmap* bitmapFromDecodeSubset, SkIRect rect, |
268 const SkBitmap& originalBitmap) { | 252 const SkBitmap& originalBitmap) { |
269 // All parameters must be valid. | 253 // All parameters must be valid. |
270 SkASSERT(writePath != NULL); | 254 SkASSERT(writePath != NULL); |
271 SkASSERT(filename != NULL); | 255 SkASSERT(filename != NULL); |
272 SkASSERT(subsetDim != NULL); | 256 SkASSERT(subsetDim != NULL); |
273 SkASSERT(bitmapFromDecodeSubset != NULL); | 257 SkASSERT(bitmapFromDecodeSubset != NULL); |
274 | 258 |
275 // Create a subdirectory to hold the results of decodeSubset. | 259 // Create a subdirectory to hold the results of decodeSubset. |
276 // TODO: Move SkPathJoin into SkOSFile.h | 260 SkString dir = SkPathJoin(writePath, "subsets"); |
277 SkString dir = skiagm::SkPathJoin(writePath, "subsets"); | |
278 if (!sk_mkdir(dir.c_str())) { | 261 if (!sk_mkdir(dir.c_str())) { |
279 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " | 262 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " |
280 "create a directory to write to.
", subsetDim, | 263 "create a directory to write to.
", subsetDim, |
281 filename); | 264 filename); |
282 return false; | 265 return false; |
283 } | 266 } |
284 | 267 |
285 // Write the subset to a file whose name includes the dimensions. | 268 // Write the subset to a file whose name includes the dimensions. |
286 SkString suffix = SkStringPrintf("_%s.png", subsetDim); | 269 SkString suffix = SkStringPrintf("_%s.png", subsetDim); |
287 SkString outPath; | 270 SkString outPath; |
288 make_outname(&outPath, dir.c_str(), filename, suffix.c_str()); | 271 make_outname(&outPath, dir.c_str(), filename, suffix.c_str()); |
289 SkAssertResult(write_bitmap(outPath.c_str(), bitmapFromDecodeSubset)); | 272 SkAssertResult(write_bitmap(outPath.c_str(), bitmapFromDecodeSubset)); |
290 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", outPath.c_str()); | 273 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", outPath.c_str()); |
291 | 274 |
292 // Also use extractSubset from the original for visual comparison. | 275 // Also use extractSubset from the original for visual comparison. |
293 // Write the result to a file in a separate subdirectory. | 276 // Write the result to a file in a separate subdirectory. |
294 SkBitmap extractedSubset; | 277 SkBitmap extractedSubset; |
295 if (!originalBitmap.extractSubset(&extractedSubset, rect)) { | 278 if (!originalBitmap.extractSubset(&extractedSubset, rect)) { |
296 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " | 279 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " |
297 "extract a similar subset for co
mparison.", | 280 "extract a similar subset for co
mparison.", |
298 subsetDim, filename); | 281 subsetDim, filename); |
299 return false; | 282 return false; |
300 } | 283 } |
301 | 284 |
302 SkString dirExtracted = skiagm::SkPathJoin(writePath, "extracted"); | 285 SkString dirExtracted = SkPathJoin(writePath, "extracted"); |
303 if (!sk_mkdir(dirExtracted.c_str())) { | 286 if (!sk_mkdir(dirExtracted.c_str())) { |
304 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " | 287 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " |
305 "create a directory for extractS
ubset comparison.", | 288 "create a directory for extractS
ubset comparison.", |
306 subsetDim, filename); | 289 subsetDim, filename); |
307 return false; | 290 return false; |
308 } | 291 } |
309 | 292 |
310 make_outname(&outPath, dirExtracted.c_str(), filename, suffix.c_str()); | 293 make_outname(&outPath, dirExtracted.c_str(), filename, suffix.c_str()); |
311 SkAssertResult(write_bitmap(outPath.c_str(), &extractedSubset)); | 294 SkAssertResult(write_bitmap(outPath.c_str(), &extractedSubset)); |
312 return true; | 295 return true; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 } | 548 } |
566 | 549 |
567 return failed ? -1 : 0; | 550 return failed ? -1 : 0; |
568 } | 551 } |
569 | 552 |
570 #if !defined SK_BUILD_FOR_IOS | 553 #if !defined SK_BUILD_FOR_IOS |
571 int main(int argc, char * const argv[]) { | 554 int main(int argc, char * const argv[]) { |
572 return tool_main(argc, (char**) argv); | 555 return tool_main(argc, (char**) argv); |
573 } | 556 } |
574 #endif | 557 #endif |
OLD | NEW |