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