SkDiffContext.h revision a95959c3fb4c502b45bc78f15b65cda1f21620e6
1945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com/* 2945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * Copyright 2013 Google Inc. 3945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * 4945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * Use of this source code is governed by a BSD-style license that can be 5945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * found in the LICENSE file. 6945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com */ 7945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 8945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com#ifndef SkDiffContext_DEFINED 9945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com#define SkDiffContext_DEFINED 10945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 11945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com#include "SkString.h" 12945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com#include "SkTArray.h" 13945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com#include "SkTDArray.h" 14945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 15945708ad9494322e2bc26776ccb741776205b4b8zachr@google.comclass SkWStream; 16945708ad9494322e2bc26776ccb741776205b4b8zachr@google.comclass SkImageDiffer; 17945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 18945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com/** 19945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * Collects records of diffs and outputs them as JSON. 20945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com */ 21945708ad9494322e2bc26776ccb741776205b4b8zachr@google.comclass SkDiffContext { 22945708ad9494322e2bc26776ccb741776205b4b8zachr@google.compublic: 23945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com SkDiffContext(); 24945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com ~SkDiffContext(); 25945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 26945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com /** 27945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * Sets the differs to be used in each diff. Already started diffs will not retroactively use 28945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * these. 29945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * @param differs An array of differs to use. The array is copied, but not the differs 30945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * themselves. 31945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com */ 32945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com void setDiffers(const SkTDArray<SkImageDiffer*>& differs); 33945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 34945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com /** 35945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * Compares two directories of images with the given differ 36945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * @param baselinePath The baseline directory's path 37945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * @param testPath The test directory's path 38945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com */ 39945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com void diffDirectories(const char baselinePath[], const char testPath[]); 40945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 41945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com /** 42945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * Compares two sets of images identified by glob style patterns with the given differ 43945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * @param baselinePattern A pattern for baseline files 44945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * @param testPattern A pattern for test files that matches each file of the baseline file 45945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com */ 46945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com void diffPatterns(const char baselinePattern[], const char testPattern[]); 47945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 48945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com /** 49945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * Compares the images at the given paths 50945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * @param baselinePath The baseline file path 51945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * @param testPath The matching test file path 52945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com */ 53945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com void addDiff(const char* baselinePath, const char* testPath); 54945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 55945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com /** 56945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * Output the records of each diff in JSON. 57945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * 58945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * The format of the JSON document is one top level array named "records". 59945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * Each record in the array is an object with both a "baselinePath" and "testPath" string field. 60945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * They also have an array named "diffs" with each element being one diff record for the two 61945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * images indicated in the above field. 62945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * A diff record includes: 63945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * "differName" : string name of the diff metric used 64945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * "result" : numerical result of the diff 65945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * "pointsOfInterest" : an array of coordinates (stored as a 2-array of ints) of interesting 66945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * points 67945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * 68945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * Here is an example: 69945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * 70945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * { 71945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * "records": [ 72945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * { 73945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * "baselinePath": "queue.png", 74945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * "testPath": "queue.png", 75945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * "diffs": [ 76945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * { 77945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * "differName": "different_pixels", 78945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * "result": 1, 79945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * "pointsOfInterest": [ 80945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * [285,279], 81945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * ] 82945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * } 83945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * ] 84945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * } 85945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * ] 86945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * } 87945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com * 88a95959c3fb4c502b45bc78f15b65cda1f21620e6zachr@google.com * @param stream The stream to output the diff to 89a95959c3fb4c502b45bc78f15b65cda1f21620e6zachr@google.com * @param useJSONP True to adding padding to the JSON output to make it cross-site requestable. 90945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com */ 91a95959c3fb4c502b45bc78f15b65cda1f21620e6zachr@google.com void outputRecords(SkWStream& stream, bool useJSONP); 92945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 93945708ad9494322e2bc26776ccb741776205b4b8zachr@google.comprivate: 94945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com struct DiffData { 95945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com const char* fDiffName; 96945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com double fResult; 97945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com SkTDArray<SkIPoint> fPointsOfInterest; 98945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com }; 99945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 100945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com struct DiffRecord { 101945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com SkString fBaselinePath; 102945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com SkString fTestPath; 103945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com SkTArray<DiffData> fDiffs; 104945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com DiffRecord* fNext; 105945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com }; 106945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 107945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com // We use linked list for the records so that their pointers remain stable. A resizable array 108945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com // might change its pointers, which would make it harder for async diffs to record their 109945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com // results. 110945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com DiffRecord * fRecords; 111945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 112945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com SkImageDiffer** fDiffers; 113945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com int fDifferCount; 114945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com}; 115945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com 116945708ad9494322e2bc26776ccb741776205b4b8zachr@google.com#endif 117