OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "LazyDecodeBitmap.h" | 8 #include "LazyDecodeBitmap.h" |
9 #include "CopyTilesRenderer.h" | 9 #include "CopyTilesRenderer.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 * Write the raw encoded bitmap data to a file. | 116 * Write the raw encoded bitmap data to a file. |
117 */ | 117 */ |
118 static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitma
p) { | 118 static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitma
p) { |
119 SkASSERT(!FLAGS_writePath.isEmpty()); | 119 SkASSERT(!FLAGS_writePath.isEmpty()); |
120 SkMemoryStream memStream(buffer, size); | 120 SkMemoryStream memStream(buffer, size); |
121 SkString outPath; | 121 SkString outPath; |
122 SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&memStream); | 122 SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&memStream); |
123 SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++
, | 123 SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++
, |
124 get_suffix_from_format(format)); | 124 get_suffix_from_format(format)); |
125 SkString dir(FLAGS_writePath[0]); | 125 SkString dir(FLAGS_writePath[0]); |
126 outPath = SkOSPath::SkPathJoin(dir.c_str(), name.c_str()); | 126 outPath = SkOSPath::Join(dir.c_str(), name.c_str()); |
127 SkFILEWStream fileStream(outPath.c_str()); | 127 SkFILEWStream fileStream(outPath.c_str()); |
128 if (!(fileStream.isValid() && fileStream.write(buffer, size))) { | 128 if (!(fileStream.isValid() && fileStream.write(buffer, size))) { |
129 SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str()); | 129 SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str()); |
130 } | 130 } |
131 // Put in a dummy bitmap. | 131 // Put in a dummy bitmap. |
132 return SkImageDecoder::DecodeStream(&memStream, bitmap, kUnknown_SkColorType
, | 132 return SkImageDecoder::DecodeStream(&memStream, bitmap, kUnknown_SkColorType
, |
133 SkImageDecoder::kDecodeBounds_Mode); | 133 SkImageDecoder::kDecodeBounds_Mode); |
134 } | 134 } |
135 | 135 |
136 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 136 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
137 | 137 |
138 /** | 138 /** |
139 * Called only by render_picture(). | 139 * Called only by render_picture(). |
140 */ | 140 */ |
141 static bool render_picture_internal(const SkString& inputPath, const SkString* w
ritePath, | 141 static bool render_picture_internal(const SkString& inputPath, const SkString* w
ritePath, |
142 const SkString* mismatchPath, | 142 const SkString* mismatchPath, |
143 sk_tools::PictureRenderer& renderer, | 143 sk_tools::PictureRenderer& renderer, |
144 SkBitmap** out) { | 144 SkBitmap** out) { |
145 SkString inputFilename = SkOSPath::SkBasename(inputPath.c_str()); | 145 SkString inputFilename = SkOSPath::Basename(inputPath.c_str()); |
146 SkString writePathString; | 146 SkString writePathString; |
147 if (NULL != writePath && writePath->size() > 0 && !FLAGS_writeEncodedImages)
{ | 147 if (NULL != writePath && writePath->size() > 0 && !FLAGS_writeEncodedImages)
{ |
148 writePathString.set(*writePath); | 148 writePathString.set(*writePath); |
149 } | 149 } |
150 SkString mismatchPathString; | 150 SkString mismatchPathString; |
151 if (NULL != mismatchPath && mismatchPath->size() > 0) { | 151 if (NULL != mismatchPath && mismatchPath->size() > 0) { |
152 mismatchPathString.set(*mismatchPath); | 152 mismatchPathString.set(*mismatchPath); |
153 } | 153 } |
154 | 154 |
155 SkFILEStream inputStream; | 155 SkFILEStream inputStream; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 for (int i = 1; i <= 255; ++i) { | 338 for (int i = 1; i <= 255; ++i) { |
339 if(diffs[i] > 0) { | 339 if(diffs[i] > 0) { |
340 SkDebugf("Number of pixels with max diff of %i is %i\n", i, diff
s[i]); | 340 SkDebugf("Number of pixels with max diff of %i is %i\n", i, diff
s[i]); |
341 } | 341 } |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 if (FLAGS_writeWholeImage) { | 345 if (FLAGS_writeWholeImage) { |
346 sk_tools::force_all_opaque(*bitmap); | 346 sk_tools::force_all_opaque(*bitmap); |
347 | 347 |
348 SkString inputFilename = SkOSPath::SkBasename(inputPath.c_str()); | 348 SkString inputFilename = SkOSPath::Basename(inputPath.c_str()); |
349 SkString outputFilename(inputFilename); | 349 SkString outputFilename(inputFilename); |
350 sk_tools::replace_char(&outputFilename, '.', '_'); | 350 sk_tools::replace_char(&outputFilename, '.', '_'); |
351 outputFilename.append(".png"); | 351 outputFilename.append(".png"); |
352 | 352 |
353 if (NULL != jsonSummaryPtr) { | 353 if (NULL != jsonSummaryPtr) { |
354 sk_tools::ImageDigest imageDigest(*bitmap); | 354 sk_tools::ImageDigest imageDigest(*bitmap); |
355 jsonSummaryPtr->add(inputFilename.c_str(), outputFilename.c_str(), i
mageDigest); | 355 jsonSummaryPtr->add(inputFilename.c_str(), outputFilename.c_str(), i
mageDigest); |
356 if ((NULL != mismatchPath) && !mismatchPath->isEmpty() && | 356 if ((NULL != mismatchPath) && !mismatchPath->isEmpty() && |
357 !jsonSummaryPtr->matchesExpectation(inputFilename.c_str(), image
Digest)) { | 357 !jsonSummaryPtr->matchesExpectation(inputFilename.c_str(), image
Digest)) { |
358 success &= sk_tools::write_bitmap_to_disk(*bitmap, *mismatchPath
, NULL, | 358 success &= sk_tools::write_bitmap_to_disk(*bitmap, *mismatchPath
, NULL, |
(...skipping 13 matching lines...) Expand all Loading... |
372 | 372 |
373 static int process_input(const char* input, const SkString* writePath, | 373 static int process_input(const char* input, const SkString* writePath, |
374 const SkString* mismatchPath, sk_tools::PictureRenderer
& renderer, | 374 const SkString* mismatchPath, sk_tools::PictureRenderer
& renderer, |
375 sk_tools::ImageResultsAndExpectations *jsonSummaryPtr)
{ | 375 sk_tools::ImageResultsAndExpectations *jsonSummaryPtr)
{ |
376 SkOSFile::Iter iter(input, "skp"); | 376 SkOSFile::Iter iter(input, "skp"); |
377 SkString inputFilename; | 377 SkString inputFilename; |
378 int failures = 0; | 378 int failures = 0; |
379 SkDebugf("process_input, %s\n", input); | 379 SkDebugf("process_input, %s\n", input); |
380 if (iter.next(&inputFilename)) { | 380 if (iter.next(&inputFilename)) { |
381 do { | 381 do { |
382 SkString inputPath = SkOSPath::SkPathJoin(input, inputFilename.c_str
()); | 382 SkString inputPath = SkOSPath::Join(input, inputFilename.c_str()); |
383 if (!render_picture(inputPath, writePath, mismatchPath, renderer, js
onSummaryPtr)) { | 383 if (!render_picture(inputPath, writePath, mismatchPath, renderer, js
onSummaryPtr)) { |
384 ++failures; | 384 ++failures; |
385 } | 385 } |
386 } while(iter.next(&inputFilename)); | 386 } while(iter.next(&inputFilename)); |
387 } else if (SkStrEndsWith(input, ".skp")) { | 387 } else if (SkStrEndsWith(input, ".skp")) { |
388 SkString inputPath(input); | 388 SkString inputPath(input); |
389 if (!render_picture(inputPath, writePath, mismatchPath, renderer, jsonSu
mmaryPtr)) { | 389 if (!render_picture(inputPath, writePath, mismatchPath, renderer, jsonSu
mmaryPtr)) { |
390 ++failures; | 390 ++failures; |
391 } | 391 } |
392 } else { | 392 } else { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]); | 482 jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]); |
483 } | 483 } |
484 return 0; | 484 return 0; |
485 } | 485 } |
486 | 486 |
487 #if !defined SK_BUILD_FOR_IOS | 487 #if !defined SK_BUILD_FOR_IOS |
488 int main(int argc, char * const argv[]) { | 488 int main(int argc, char * const argv[]) { |
489 return tool_main(argc, (char**) argv); | 489 return tool_main(argc, (char**) argv); |
490 } | 490 } |
491 #endif | 491 #endif |
OLD | NEW |