Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: tools/skimage_main.cpp

Issue 15747004: Add path utils, plus a test for it. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove unnecessary changes. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/utils/SkOSFile.cpp ('K') | « tests/OSPathUtilsTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 static SkImageDecoder::Format guess_format_from_suffix(const char suffix[]) { 64 static SkImageDecoder::Format guess_format_from_suffix(const char suffix[]) {
65 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { 65 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
66 if (strcmp(suffix, gFormats[i].fSuffix) == 0) { 66 if (strcmp(suffix, gFormats[i].fSuffix) == 0) {
67 return gFormats[i].fFormat; 67 return gFormats[i].fFormat;
68 } 68 }
69 } 69 }
70 return SkImageDecoder::kUnknown_Format; 70 return SkImageDecoder::kUnknown_Format;
71 } 71 }
72 72
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[], 73 static void make_outname(SkString* dst, const char outDir[], const char src[],
91 const char suffix[]) { 74 const char suffix[]) {
92 const char* basename = SkBasename(src); 75 SkString basename = SkOSPathUtils::SkBasename(src);
93 dst->set(skiagm::SkPathJoin(outDir, basename)); 76 dst->set(SkOSPathUtils::SkPathJoin(outDir, basename.c_str()));
94 if (!dst->endsWith(suffix)) { 77 if (!dst->endsWith(suffix)) {
95 const char* cstyleDst = dst->c_str(); 78 const char* cstyleDst = dst->c_str();
96 const char* dot = strrchr(cstyleDst, '.'); 79 const char* dot = strrchr(cstyleDst, '.');
97 if (dot != NULL) { 80 if (dot != NULL) {
98 int32_t index = SkToS32(dot - cstyleDst); 81 int32_t index = SkToS32(dot - cstyleDst);
99 dst->remove(index, dst->size() - index); 82 dst->remove(index, dst->size() - index);
100 } 83 }
101 dst->append(suffix); 84 dst->append(suffix);
102 } 85 }
103 } 86 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 static bool write_subset(const char* writePath, const char* filename, const char * subsetDim, 249 static bool write_subset(const char* writePath, const char* filename, const char * subsetDim,
267 SkBitmap* bitmapFromDecodeSubset, SkIRect rect, 250 SkBitmap* bitmapFromDecodeSubset, SkIRect rect,
268 const SkBitmap& originalBitmap) { 251 const SkBitmap& originalBitmap) {
269 // All parameters must be valid. 252 // All parameters must be valid.
270 SkASSERT(writePath != NULL); 253 SkASSERT(writePath != NULL);
271 SkASSERT(filename != NULL); 254 SkASSERT(filename != NULL);
272 SkASSERT(subsetDim != NULL); 255 SkASSERT(subsetDim != NULL);
273 SkASSERT(bitmapFromDecodeSubset != NULL); 256 SkASSERT(bitmapFromDecodeSubset != NULL);
274 257
275 // Create a subdirectory to hold the results of decodeSubset. 258 // Create a subdirectory to hold the results of decodeSubset.
276 // TODO: Move SkPathJoin into SkOSFile.h 259 SkString dir = SkOSPathUtils::SkPathJoin(writePath, "subsets");
277 SkString dir = skiagm::SkPathJoin(writePath, "subsets");
278 if (!sk_mkdir(dir.c_str())) { 260 if (!sk_mkdir(dir.c_str())) {
279 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s , but failed to " 261 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s , but failed to "
280 "create a directory to write to. ", subsetDim, 262 "create a directory to write to. ", subsetDim,
281 filename); 263 filename);
282 return false; 264 return false;
283 } 265 }
284 266
285 // Write the subset to a file whose name includes the dimensions. 267 // Write the subset to a file whose name includes the dimensions.
286 SkString suffix = SkStringPrintf("_%s.png", subsetDim); 268 SkString suffix = SkStringPrintf("_%s.png", subsetDim);
287 SkString outPath; 269 SkString outPath;
288 make_outname(&outPath, dir.c_str(), filename, suffix.c_str()); 270 make_outname(&outPath, dir.c_str(), filename, suffix.c_str());
289 SkAssertResult(write_bitmap(outPath.c_str(), bitmapFromDecodeSubset)); 271 SkAssertResult(write_bitmap(outPath.c_str(), bitmapFromDecodeSubset));
290 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", outPath.c_str()); 272 gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", outPath.c_str());
291 273
292 // Also use extractSubset from the original for visual comparison. 274 // Also use extractSubset from the original for visual comparison.
293 // Write the result to a file in a separate subdirectory. 275 // Write the result to a file in a separate subdirectory.
294 SkBitmap extractedSubset; 276 SkBitmap extractedSubset;
295 if (!originalBitmap.extractSubset(&extractedSubset, rect)) { 277 if (!originalBitmap.extractSubset(&extractedSubset, rect)) {
296 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 "
297 "extract a similar subset for co mparison.", 279 "extract a similar subset for co mparison.",
298 subsetDim, filename); 280 subsetDim, filename);
299 return false; 281 return false;
300 } 282 }
301 283
302 SkString dirExtracted = skiagm::SkPathJoin(writePath, "extracted"); 284 SkString dirExtracted = SkOSPathUtils::SkPathJoin(writePath, "extracted");
303 if (!sk_mkdir(dirExtracted.c_str())) { 285 if (!sk_mkdir(dirExtracted.c_str())) {
304 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s , but failed to " 286 gFailedSubsetDecodes.push_back().printf("Successfully decoded %s from %s , but failed to "
305 "create a directory for extractS ubset comparison.", 287 "create a directory for extractS ubset comparison.",
306 subsetDim, filename); 288 subsetDim, filename);
307 return false; 289 return false;
308 } 290 }
309 291
310 make_outname(&outPath, dirExtracted.c_str(), filename, suffix.c_str()); 292 make_outname(&outPath, dirExtracted.c_str(), filename, suffix.c_str());
311 SkAssertResult(write_bitmap(outPath.c_str(), &extractedSubset)); 293 SkAssertResult(write_bitmap(outPath.c_str(), &extractedSubset));
312 return true; 294 return true;
(...skipping 16 matching lines...) Expand all
329 SkAutoTDelete<SkImageDecoder> ad(codec); 311 SkAutoTDelete<SkImageDecoder> ad(codec);
330 312
331 stream.rewind(); 313 stream.rewind();
332 if (!codec->decode(&stream, &bitmap, SkBitmap::kARGB_8888_Config, 314 if (!codec->decode(&stream, &bitmap, SkBitmap::kARGB_8888_Config,
333 SkImageDecoder::kDecodePixels_Mode)) { 315 SkImageDecoder::kDecodePixels_Mode)) {
334 gDecodeFailures.push_back().set(srcPath); 316 gDecodeFailures.push_back().set(srcPath);
335 return; 317 return;
336 } 318 }
337 319
338 // Create a string representing just the filename itself, for use in json ex pectations. 320 // Create a string representing just the filename itself, for use in json ex pectations.
339 const char* filename = SkBasename(srcPath); 321 SkString basename = SkOSPathUtils::SkBasename(srcPath);
322 const char* filename = basename.c_str();
340 323
341 if (compare_to_expectations_if_necessary(bitmap, filename, &gDecodeFailures) ) { 324 if (compare_to_expectations_if_necessary(bitmap, filename, &gDecodeFailures) ) {
342 gSuccessfulDecodes.push_back().printf("%s [%d %d]", srcPath, bitmap.widt h(), 325 gSuccessfulDecodes.push_back().printf("%s [%d %d]", srcPath, bitmap.widt h(),
343 bitmap.height()); 326 bitmap.height());
344 } 327 }
345 328
346 write_expectations(bitmap, filename); 329 write_expectations(bitmap, filename);
347 330
348 if (FLAGS_testSubsetDecoding) { 331 if (FLAGS_testSubsetDecoding) {
349 SkDEBUGCODE(bool couldRewind =) stream.rewind(); 332 SkDEBUGCODE(bool couldRewind =) stream.rewind();
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« src/utils/SkOSFile.cpp ('K') | « tests/OSPathUtilsTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698