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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 static SkImageDecoder::Format guess_format_from_suffix(const char suffix[]) { | 63 static SkImageDecoder::Format guess_format_from_suffix(const char suffix[]) { |
64 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { | 64 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { |
65 if (strcmp(suffix, gFormats[i].fSuffix) == 0) { | 65 if (strcmp(suffix, gFormats[i].fSuffix) == 0) { |
66 return gFormats[i].fFormat; | 66 return gFormats[i].fFormat; |
67 } | 67 } |
68 } | 68 } |
69 return SkImageDecoder::kUnknown_Format; | 69 return SkImageDecoder::kUnknown_Format; |
70 } | 70 } |
71 | 71 |
72 /** | |
73 * Return the name of the file, ignoring the directory structure. | |
74 * Does not create a new string. | |
75 * @param fullPath Full path to the file. | |
76 * @return string The basename of the file - anything beyond the final slash, o
r the full name | |
77 * if there is no slash. | |
78 * TODO: Might this be useful as a utility function in SkOSFile? Would it be mo
re appropriate to | |
79 * create a new string? | |
80 */ | |
81 static const char* SkBasename(const char* fullPath) { | |
82 const char* filename = strrchr(fullPath, SkPATH_SEPARATOR); | |
83 if (NULL == filename || *++filename == '\0') { | |
84 filename = fullPath; | |
85 } | |
86 return filename; | |
87 } | |
88 | |
89 static void make_outname(SkString* dst, const char outDir[], const char src[], | 72 static void make_outname(SkString* dst, const char outDir[], const char src[], |
90 const char suffix[]) { | 73 const char suffix[]) { |
91 const char* basename = SkBasename(src); | 74 SkString basename = SkOSPath::SkBasename(src); |
92 dst->set(skiagm::SkPathJoin(outDir, basename)); | 75 dst->set(SkOSPath::SkPathJoin(outDir, basename.c_str())); |
93 if (!dst->endsWith(suffix)) { | 76 if (!dst->endsWith(suffix)) { |
94 const char* cstyleDst = dst->c_str(); | 77 const char* cstyleDst = dst->c_str(); |
95 const char* dot = strrchr(cstyleDst, '.'); | 78 const char* dot = strrchr(cstyleDst, '.'); |
96 if (dot != NULL) { | 79 if (dot != NULL) { |
97 int32_t index = SkToS32(dot - cstyleDst); | 80 int32_t index = SkToS32(dot - cstyleDst); |
98 dst->remove(index, dst->size() - index); | 81 dst->remove(index, dst->size() - index); |
99 } | 82 } |
100 dst->append(suffix); | 83 dst->append(suffix); |
101 } | 84 } |
102 } | 85 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 static bool write_subset(const char* writePath, const char* filename, const char
* subsetDim, | 248 static bool write_subset(const char* writePath, const char* filename, const char
* subsetDim, |
266 SkBitmap* bitmapFromDecodeSubset, SkIRect rect, | 249 SkBitmap* bitmapFromDecodeSubset, SkIRect rect, |
267 const SkBitmap& originalBitmap) { | 250 const SkBitmap& originalBitmap) { |
268 // All parameters must be valid. | 251 // All parameters must be valid. |
269 SkASSERT(writePath != NULL); | 252 SkASSERT(writePath != NULL); |
270 SkASSERT(filename != NULL); | 253 SkASSERT(filename != NULL); |
271 SkASSERT(subsetDim != NULL); | 254 SkASSERT(subsetDim != NULL); |
272 SkASSERT(bitmapFromDecodeSubset != NULL); | 255 SkASSERT(bitmapFromDecodeSubset != NULL); |
273 | 256 |
274 // Create a subdirectory to hold the results of decodeSubset. | 257 // Create a subdirectory to hold the results of decodeSubset. |
275 // TODO: Move SkPathJoin into SkOSFile.h | 258 SkString dir = SkOSPath::SkPathJoin(writePath, "subsets"); |
276 SkString dir = skiagm::SkPathJoin(writePath, "subsets"); | |
277 if (!sk_mkdir(dir.c_str())) { | 259 if (!sk_mkdir(dir.c_str())) { |
278 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " | 260 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " |
279 "create a directory to write to.
", subsetDim, | 261 "create a directory to write to.
", subsetDim, |
280 filename); | 262 filename); |
281 return false; | 263 return false; |
282 } | 264 } |
283 | 265 |
284 // Write the subset to a file whose name includes the dimensions. | 266 // Write the subset to a file whose name includes the dimensions. |
285 SkString suffix = SkStringPrintf("_%s.png", subsetDim); | 267 SkString suffix = SkStringPrintf("_%s.png", subsetDim); |
286 SkString outPath; | 268 SkString outPath; |
287 make_outname(&outPath, dir.c_str(), filename, suffix.c_str()); | 269 make_outname(&outPath, dir.c_str(), filename, suffix.c_str()); |
288 SkAssertResult(write_bitmap(outPath.c_str(), bitmapFromDecodeSubset)); | 270 SkAssertResult(write_bitmap(outPath.c_str(), bitmapFromDecodeSubset)); |
289 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", outPath.c_str()); | 271 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", outPath.c_str()); |
290 | 272 |
291 // Also use extractSubset from the original for visual comparison. | 273 // Also use extractSubset from the original for visual comparison. |
292 // Write the result to a file in a separate subdirectory. | 274 // Write the result to a file in a separate subdirectory. |
293 SkBitmap extractedSubset; | 275 SkBitmap extractedSubset; |
294 if (!originalBitmap.extractSubset(&extractedSubset, rect)) { | 276 if (!originalBitmap.extractSubset(&extractedSubset, rect)) { |
295 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " | 277 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " |
296 "extract a similar subset for co
mparison.", | 278 "extract a similar subset for co
mparison.", |
297 subsetDim, filename); | 279 subsetDim, filename); |
298 return false; | 280 return false; |
299 } | 281 } |
300 | 282 |
301 SkString dirExtracted = skiagm::SkPathJoin(writePath, "extracted"); | 283 SkString dirExtracted = SkOSPath::SkPathJoin(writePath, "extracted"); |
302 if (!sk_mkdir(dirExtracted.c_str())) { | 284 if (!sk_mkdir(dirExtracted.c_str())) { |
303 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " | 285 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s
, but failed to " |
304 "create a directory for extractS
ubset comparison.", | 286 "create a directory for extractS
ubset comparison.", |
305 subsetDim, filename); | 287 subsetDim, filename); |
306 return false; | 288 return false; |
307 } | 289 } |
308 | 290 |
309 make_outname(&outPath, dirExtracted.c_str(), filename, suffix.c_str()); | 291 make_outname(&outPath, dirExtracted.c_str(), filename, suffix.c_str()); |
310 SkAssertResult(write_bitmap(outPath.c_str(), &extractedSubset)); | 292 SkAssertResult(write_bitmap(outPath.c_str(), &extractedSubset)); |
311 return true; | 293 return true; |
(...skipping 16 matching lines...) Expand all Loading... |
328 SkAutoTDelete<SkImageDecoder> ad(codec); | 310 SkAutoTDelete<SkImageDecoder> ad(codec); |
329 | 311 |
330 stream.rewind(); | 312 stream.rewind(); |
331 if (!codec->decode(&stream, &bitmap, SkBitmap::kARGB_8888_Config, | 313 if (!codec->decode(&stream, &bitmap, SkBitmap::kARGB_8888_Config, |
332 SkImageDecoder::kDecodePixels_Mode)) { | 314 SkImageDecoder::kDecodePixels_Mode)) { |
333 gDecodeFailures.push_back().set(srcPath); | 315 gDecodeFailures.push_back().set(srcPath); |
334 return; | 316 return; |
335 } | 317 } |
336 | 318 |
337 // Create a string representing just the filename itself, for use in json ex
pectations. | 319 // Create a string representing just the filename itself, for use in json ex
pectations. |
338 const char* filename = SkBasename(srcPath); | 320 SkString basename = SkOSPath::SkBasename(srcPath); |
| 321 const char* filename = basename.c_str(); |
339 | 322 |
340 if (compare_to_expectations_if_necessary(bitmap, filename, &gDecodeFailures)
) { | 323 if (compare_to_expectations_if_necessary(bitmap, filename, &gDecodeFailures)
) { |
341 gSuccessfulDecodes.push_back().printf("%s [%d %d]", srcPath, bitmap.widt
h(), | 324 gSuccessfulDecodes.push_back().printf("%s [%d %d]", srcPath, bitmap.widt
h(), |
342 bitmap.height()); | 325 bitmap.height()); |
343 } | 326 } |
344 | 327 |
345 write_expectations(bitmap, filename); | 328 write_expectations(bitmap, filename); |
346 | 329 |
347 if (FLAGS_testSubsetDecoding) { | 330 if (FLAGS_testSubsetDecoding) { |
348 SkDEBUGCODE(bool couldRewind =) stream.rewind(); | 331 SkDEBUGCODE(bool couldRewind =) stream.rewind(); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 } | 547 } |
565 | 548 |
566 return failed ? -1 : 0; | 549 return failed ? -1 : 0; |
567 } | 550 } |
568 | 551 |
569 #if !defined SK_BUILD_FOR_IOS | 552 #if !defined SK_BUILD_FOR_IOS |
570 int main(int argc, char * const argv[]) { | 553 int main(int argc, char * const argv[]) { |
571 return tool_main(argc, (char**) argv); | 554 return tool_main(argc, (char**) argv); |
572 } | 555 } |
573 #endif | 556 #endif |
OLD | NEW |