OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
11 #include "SkRunnable.h" | 11 #include "SkRunnable.h" |
12 #include "SkSize.h" | 12 #include "SkSize.h" |
13 #include "SkStream.h" | 13 #include "SkStream.h" |
14 #include "SkTDict.h" | 14 #include "SkTDict.h" |
15 #include "SkTaskGroup.h" | 15 #include "SkTaskGroup.h" |
16 | 16 |
17 // from the tools directory for replace_char(...) | 17 // from the tools directory for replace_char(...) |
18 #include "picture_utils.h" | 18 #include "picture_utils.h" |
19 | 19 |
20 #include "SkDiffContext.h" | 20 #include "SkDiffContext.h" |
21 #include "SkImageDiffer.h" | 21 #include "SkImageDiffer.h" |
22 #include "skpdiff_util.h" | 22 #include "skpdiff_util.h" |
23 | 23 |
24 SkDiffContext::SkDiffContext() { | 24 SkDiffContext::SkDiffContext() { |
25 fDiffers = NULL; | 25 fDiffers = NULL; |
26 fDifferCount = 0; | 26 fDifferCount = 0; |
27 } | 27 } |
28 | 28 |
29 SkDiffContext::~SkDiffContext() { | 29 SkDiffContext::~SkDiffContext() { |
30 if (NULL != fDiffers) { | 30 if (fDiffers) { |
31 SkDELETE_ARRAY(fDiffers); | 31 SkDELETE_ARRAY(fDiffers); |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 void SkDiffContext::setAlphaMaskDir(const SkString& path) { | 35 void SkDiffContext::setAlphaMaskDir(const SkString& path) { |
36 if (!path.isEmpty() && sk_mkdir(path.c_str())) { | 36 if (!path.isEmpty() && sk_mkdir(path.c_str())) { |
37 fAlphaMaskDir = path; | 37 fAlphaMaskDir = path; |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 void SkDiffContext::setRgbDiffDir(const SkString& path) { | 41 void SkDiffContext::setRgbDiffDir(const SkString& path) { |
42 if (!path.isEmpty() && sk_mkdir(path.c_str())) { | 42 if (!path.isEmpty() && sk_mkdir(path.c_str())) { |
43 fRgbDiffDir = path; | 43 fRgbDiffDir = path; |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 void SkDiffContext::setWhiteDiffDir(const SkString& path) { | 47 void SkDiffContext::setWhiteDiffDir(const SkString& path) { |
48 if (!path.isEmpty() && sk_mkdir(path.c_str())) { | 48 if (!path.isEmpty() && sk_mkdir(path.c_str())) { |
49 fWhiteDiffDir = path; | 49 fWhiteDiffDir = path; |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 void SkDiffContext::setLongNames(const bool useLongNames) { | 53 void SkDiffContext::setLongNames(const bool useLongNames) { |
54 longNames = useLongNames; | 54 longNames = useLongNames; |
55 } | 55 } |
56 | 56 |
57 void SkDiffContext::setDiffers(const SkTDArray<SkImageDiffer*>& differs) { | 57 void SkDiffContext::setDiffers(const SkTDArray<SkImageDiffer*>& differs) { |
58 // Delete whatever the last array of differs was | 58 // Delete whatever the last array of differs was |
59 if (NULL != fDiffers) { | 59 if (fDiffers) { |
60 SkDELETE_ARRAY(fDiffers); | 60 SkDELETE_ARRAY(fDiffers); |
61 fDiffers = NULL; | 61 fDiffers = NULL; |
62 fDifferCount = 0; | 62 fDifferCount = 0; |
63 } | 63 } |
64 | 64 |
65 // Copy over the new differs | 65 // Copy over the new differs |
66 fDifferCount = differs.count(); | 66 fDifferCount = differs.count(); |
67 fDiffers = SkNEW_ARRAY(SkImageDiffer*, fDifferCount); | 67 fDiffers = SkNEW_ARRAY(SkImageDiffer*, fDifferCount); |
68 differs.copy(fDiffers); | 68 differs.copy(fDiffers); |
69 } | 69 } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 stream.writeText("var SkPDiffRecords = {\n"); | 299 stream.writeText("var SkPDiffRecords = {\n"); |
300 } else { | 300 } else { |
301 stream.writeText("{\n"); | 301 stream.writeText("{\n"); |
302 } | 302 } |
303 | 303 |
304 // TODO(djsollen): Would it be better to use the jsoncpp library to write ou
t the JSON? | 304 // TODO(djsollen): Would it be better to use the jsoncpp library to write ou
t the JSON? |
305 // This manual approach is probably more efficient, but it sure is ugly. | 305 // This manual approach is probably more efficient, but it sure is ugly. |
306 // See http://skbug.com/2713 ('make skpdiff use jsoncpp library to write out | 306 // See http://skbug.com/2713 ('make skpdiff use jsoncpp library to write out |
307 // JSON output, instead of manual writeText() calls?') | 307 // JSON output, instead of manual writeText() calls?') |
308 stream.writeText(" \"records\": [\n"); | 308 stream.writeText(" \"records\": [\n"); |
309 while (NULL != currentRecord) { | 309 while (currentRecord) { |
310 stream.writeText(" {\n"); | 310 stream.writeText(" {\n"); |
311 | 311 |
312 SkString baselineAbsPath = get_absolute_path(currentRecord->fBaselin
ePath); | 312 SkString baselineAbsPath = get_absolute_path(currentRecord->fBaselin
ePath); |
313 SkString testAbsPath = get_absolute_path(currentRecord->fTestPath); | 313 SkString testAbsPath = get_absolute_path(currentRecord->fTestPath); |
314 | 314 |
315 stream.writeText(" \"commonName\": \""); | 315 stream.writeText(" \"commonName\": \""); |
316 stream.writeText(currentRecord->fCommonName.c_str()); | 316 stream.writeText(currentRecord->fCommonName.c_str()); |
317 stream.writeText("\",\n"); | 317 stream.writeText("\",\n"); |
318 | 318 |
319 stream.writeText(" \"differencePath\": \""); | 319 stream.writeText(" \"differencePath\": \""); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 } | 378 } |
379 stream.writeText(" \n"); | 379 stream.writeText(" \n"); |
380 } | 380 } |
381 stream.writeText(" ]\n"); | 381 stream.writeText(" ]\n"); |
382 | 382 |
383 stream.writeText(" }"); | 383 stream.writeText(" }"); |
384 | 384 |
385 currentRecord = iter.next(); | 385 currentRecord = iter.next(); |
386 | 386 |
387 // JSON does not allow trailing commas | 387 // JSON does not allow trailing commas |
388 if (NULL != currentRecord) { | 388 if (currentRecord) { |
389 stream.writeText(","); | 389 stream.writeText(","); |
390 } | 390 } |
391 stream.writeText("\n"); | 391 stream.writeText("\n"); |
392 } | 392 } |
393 stream.writeText(" ]\n"); | 393 stream.writeText(" ]\n"); |
394 if (useJSONP) { | 394 if (useJSONP) { |
395 stream.writeText("};\n"); | 395 stream.writeText("};\n"); |
396 } else { | 396 } else { |
397 stream.writeText("}\n"); | 397 stream.writeText("}\n"); |
398 } | 398 } |
399 } | 399 } |
400 | 400 |
401 void SkDiffContext::outputCsv(SkWStream& stream) { | 401 void SkDiffContext::outputCsv(SkWStream& stream) { |
402 SkTDict<int> columns(2); | 402 SkTDict<int> columns(2); |
403 int cntColumns = 0; | 403 int cntColumns = 0; |
404 | 404 |
405 stream.writeText("key"); | 405 stream.writeText("key"); |
406 | 406 |
407 SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_
IterStart); | 407 SkTLList<DiffRecord>::Iter iter(fRecords, SkTLList<DiffRecord>::Iter::kHead_
IterStart); |
408 DiffRecord* currentRecord = iter.get(); | 408 DiffRecord* currentRecord = iter.get(); |
409 | 409 |
410 // Write CSV header and create a dictionary of all columns. | 410 // Write CSV header and create a dictionary of all columns. |
411 while (NULL != currentRecord) { | 411 while (currentRecord) { |
412 for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffI
ndex++) { | 412 for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffI
ndex++) { |
413 DiffData& data = currentRecord->fDiffs[diffIndex]; | 413 DiffData& data = currentRecord->fDiffs[diffIndex]; |
414 if (!columns.find(data.fDiffName)) { | 414 if (!columns.find(data.fDiffName)) { |
415 columns.set(data.fDiffName, cntColumns); | 415 columns.set(data.fDiffName, cntColumns); |
416 stream.writeText(", "); | 416 stream.writeText(", "); |
417 stream.writeText(data.fDiffName); | 417 stream.writeText(data.fDiffName); |
418 cntColumns++; | 418 cntColumns++; |
419 } | 419 } |
420 } | 420 } |
421 currentRecord = iter.next(); | 421 currentRecord = iter.next(); |
422 } | 422 } |
423 stream.writeText("\n"); | 423 stream.writeText("\n"); |
424 | 424 |
425 double values[100]; | 425 double values[100]; |
426 SkASSERT(cntColumns < 100); // Make the array larger, if we ever have so ma
ny diff types. | 426 SkASSERT(cntColumns < 100); // Make the array larger, if we ever have so ma
ny diff types. |
427 | 427 |
428 SkTLList<DiffRecord>::Iter iter2(fRecords, SkTLList<DiffRecord>::Iter::kHead
_IterStart); | 428 SkTLList<DiffRecord>::Iter iter2(fRecords, SkTLList<DiffRecord>::Iter::kHead
_IterStart); |
429 currentRecord = iter2.get(); | 429 currentRecord = iter2.get(); |
430 while (NULL != currentRecord) { | 430 while (currentRecord) { |
431 for (int i = 0; i < cntColumns; i++) { | 431 for (int i = 0; i < cntColumns; i++) { |
432 values[i] = -1; | 432 values[i] = -1; |
433 } | 433 } |
434 | 434 |
435 for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffI
ndex++) { | 435 for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffI
ndex++) { |
436 DiffData& data = currentRecord->fDiffs[diffIndex]; | 436 DiffData& data = currentRecord->fDiffs[diffIndex]; |
437 int index = -1; | 437 int index = -1; |
438 SkAssertResult(columns.find(data.fDiffName, &index)); | 438 SkAssertResult(columns.find(data.fDiffName, &index)); |
439 SkASSERT(index >= 0 && index < cntColumns); | 439 SkASSERT(index >= 0 && index < cntColumns); |
440 values[index] = data.fResult.result; | 440 values[index] = data.fResult.result; |
(...skipping 10 matching lines...) Expand all Loading... |
451 for (int i = 0; i < cntColumns; i++) { | 451 for (int i = 0; i < cntColumns; i++) { |
452 SkString str; | 452 SkString str; |
453 str.printf(", %f", values[i]); | 453 str.printf(", %f", values[i]); |
454 stream.writeText(str.c_str()); | 454 stream.writeText(str.c_str()); |
455 } | 455 } |
456 stream.writeText("\n"); | 456 stream.writeText("\n"); |
457 | 457 |
458 currentRecord = iter2.next(); | 458 currentRecord = iter2.next(); |
459 } | 459 } |
460 } | 460 } |
OLD | NEW |