Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
skdiff.h
Go to the documentation of this file.
1/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef skdiff_DEFINED
9#define skdiff_DEFINED
10
16
17#if defined(SK_BUILD_FOR_WIN)
18 #define PATH_DIV_STR "\\"
19 #define PATH_DIV_CHAR '\\'
20#else
21 #define PATH_DIV_STR "/"
22 #define PATH_DIV_CHAR '/'
23#endif
24
25#define MAX2(a,b) (((b) < (a)) ? (a) : (b))
26#define MAX3(a,b,c) (((b) < (a)) ? MAX2((a), (c)) : MAX2((b), (c)))
27
28
30 enum Status {
31 /** The resource was specified, exists, read, and decoded. */
33 /** The resource was specified, exists, read, but could not be decoded. */
35
36 /** The resource was specified, exists, and read. */
38 /** The resource was specified, exists, but could not be read. */
40
41 /** The resource was specified and exists. */
43 /** The resource was specified, but does not exist. */
46 /** The resource was specified. */
48 /** The resource was not specified. */
50
51 /** Nothing is yet known about the resource. */
53
54 /** NOT A VALID VALUE -- used to set up arrays and to represent an unknown value. */
56 };
57 static char const * const StatusNames[DiffResource::kStatusCount];
58
59 /** Returns the Status with this name.
60 * If there is no Status with this name, returns kStatusCount.
61 */
62 static Status getStatusByName(const char *name);
63
64 /** Returns a text description of the given Status type. */
65 static const char *getStatusDescription(Status status);
66
67 /** Returns true if the Status indicates some kind of failure. */
68 static bool isStatusFailed(Status status);
69
70 /** Sets statuses[i] if it is implied by selector, unsets it if not.
71 * Selector may be a comma delimited list of status names, "any", or "failed".
72 * Returns true if the selector was entirely understood, false otherwise.
73 */
74 static bool getMatchingStatuses(char* selector, bool statuses[kStatusCount]);
75
77
78 /** If isEmpty() indicates no filename available. */
80 /** If isEmpty() indicates no path available. */
82 /** If empty() indicates the bitmap could not be created. */
85};
86
87struct DiffRecord {
88
89 // Result of comparison for each pair of files.
90 // Listed from "better" to "worse", for sorting of results.
101 static char const * const ResultNames[DiffRecord::kResultCount];
102
103 /** Returns the Result with this name.
104 * If there is no Result with this name, returns kResultCount.
105 */
106 static Result getResultByName(const char *name);
107
108 /** Returns a text description of the given Result type. */
109 static const char *getResultDescription(Result result);
110
112 : fBase()
113 , fComparison()
114 , fDifference()
115 , fWhite()
122 , fTotalMismatchA(0)
123 , fMaxMismatchA(0)
124 , fMaxMismatchR(0)
125 , fMaxMismatchG(0)
126 , fMaxMismatchB(0)
128 }
129
134
135 /// Arbitrary floating-point metric to be used to sort images from most
136 /// to least different from baseline; values of 0 will be omitted from the
137 /// summary webpage.
140
145
147
152
153 /// Which category of diff result.
155};
156
158
159/// A wrapper for any sortProc (comparison routine) which applies a first-order
160/// sort beforehand, and a tiebreaker if the sortProc returns 0.
161template<typename T> int compare(const void* untyped_lhs, const void* untyped_rhs) {
162 const DiffRecord* lhs = reinterpret_cast<DiffRecord const *>(untyped_lhs);
163 const DiffRecord* rhs = reinterpret_cast<DiffRecord const *>(untyped_rhs);
164
165 // First-order sort... these comparisons should be applied before comparing
166 // pixel values, no matter what.
167 if (lhs->fResult != rhs->fResult) {
168 return (lhs->fResult < rhs->fResult) ? 1 : -1;
169 }
170
171 // Passed first-order sort, so call the pixel comparison routine.
172 int result = T::comparePixels(lhs, rhs);
173 if (result != 0) {
174 return result;
175 }
176
177 // Tiebreaker... if we got to this point, we don't really care
178 // which order they are sorted in, but let's at least be consistent.
179 return strcmp(lhs->fBase.fFilename.c_str(), rhs->fBase.fFilename.c_str());
180}
181
182/// Comparison routine for qsort; sorts by fFractionDifference
183/// from largest to smallest.
185public:
186 static int comparePixels(const DiffRecord* lhs, const DiffRecord* rhs) {
188 return 1;
189 }
191 return -1;
192 }
193 return 0;
194 }
195};
196
198public:
199 static int comparePixels(const DiffRecord* lhs, const DiffRecord* rhs) {
200 if (lhs->fWeightedFraction < rhs->fWeightedFraction) {
201 return 1;
202 }
203 if (lhs->fWeightedFraction > rhs->fWeightedFraction) {
204 return -1;
205 }
206 return 0;
207 }
208};
209
210/// Comparison routine for qsort; sorts by max(fAverageMismatch{RGB})
211/// from largest to smallest.
213public:
214 static int comparePixels(const DiffRecord* lhs, const DiffRecord* rhs) {
215 float leftValue = MAX3(lhs->fAverageMismatchR,
217 lhs->fAverageMismatchB);
218 float rightValue = MAX3(rhs->fAverageMismatchR,
220 rhs->fAverageMismatchB);
221 if (leftValue < rightValue) {
222 return 1;
223 }
224 if (rightValue < leftValue) {
225 return -1;
226 }
227 return 0;
228 }
229};
230
231/// Comparison routine for qsort; sorts by max(fMaxMismatch{RGB})
232/// from largest to smallest.
234public:
235 static int comparePixels(const DiffRecord* lhs, const DiffRecord* rhs) {
236 uint32_t leftValue = MAX3(lhs->fMaxMismatchR,
237 lhs->fMaxMismatchG,
238 lhs->fMaxMismatchB);
239 uint32_t rightValue = MAX3(rhs->fMaxMismatchR,
240 rhs->fMaxMismatchG,
241 rhs->fMaxMismatchB);
242 if (leftValue < rightValue) {
243 return 1;
244 }
245 if (rightValue < leftValue) {
246 return -1;
247 }
248
250 }
251};
252
253
254/// Parameterized routine to compute the color of a pixel in a difference image.
256
257// from gm
259 int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1);
260 int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1);
261 int db = SkGetPackedB32(c0) - SkGetPackedB32(c1);
262
263 return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db));
264}
265
266/** When finished, dr->fResult should have some value other than kUnknown_Result.
267 * Expects dr->fWhite.fBitmap and dr->fDifference.fBitmap to have the same bounds as
268 * dr->fBase.fBitmap and have a valid pixelref.
269 */
270void compute_diff(DiffRecord* dr, DiffMetricProc diffFunction, const int colorThreshold);
271
272#endif
#define SkGetPackedB32(packed)
Definition SkColorPriv.h:95
#define SkGetPackedR32(packed)
Definition SkColorPriv.h:93
#define SkGetPackedG32(packed)
Definition SkColorPriv.h:94
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
uint32_t SkPMColor
Definition SkColor.h:205
static int32_t SkAbs32(int32_t value)
Definition SkSafe32.h:41
static int comparePixels(const DiffRecord *lhs, const DiffRecord *rhs)
Definition skdiff.h:235
static int comparePixels(const DiffRecord *lhs, const DiffRecord *rhs)
Definition skdiff.h:214
static int comparePixels(const DiffRecord *lhs, const DiffRecord *rhs)
Definition skdiff.h:186
static int comparePixels(const DiffRecord *lhs, const DiffRecord *rhs)
Definition skdiff.h:199
const char * c_str() const
Definition SkString.h:133
GAsyncResult * result
const char * name
Definition fuchsia.cc:50
#define MAX3(a, b, c)
Definition skdiff.h:26
SkPMColor(* DiffMetricProc)(SkPMColor, SkPMColor)
Parameterized routine to compute the color of a pixel in a difference image.
Definition skdiff.h:255
void compute_diff(DiffRecord *dr, DiffMetricProc diffFunction, const int colorThreshold)
Definition skdiff.cpp:158
static SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1)
Definition skdiff.h:258
int compare(const void *untyped_lhs, const void *untyped_rhs)
Definition skdiff.h:161
skia_private::TArray< DiffRecord > RecordArray
Definition skdiff.h:157
DiffResource fDifference
Definition skdiff.h:132
static char const *const ResultNames[DiffRecord::kResultCount]
Definition skdiff.h:14
DiffRecord()
Definition skdiff.h:111
static Result getResultByName(const char *name)
Definition skdiff.cpp:23
DiffResource fComparison
Definition skdiff.h:131
float fAverageMismatchG
Definition skdiff.h:143
Result fResult
Which category of diff result.
Definition skdiff.h:154
@ kUnknown_Result
Definition skdiff.h:97
@ kEqualBits_Result
Definition skdiff.h:92
@ kCouldNotCompare_Result
Definition skdiff.h:96
@ kResultCount
Definition skdiff.h:99
@ kDifferentSizes_Result
Definition skdiff.h:95
@ kDifferentPixels_Result
Definition skdiff.h:94
@ kEqualPixels_Result
Definition skdiff.h:93
DiffResource fBase
Definition skdiff.h:130
float fAverageMismatchA
Definition skdiff.h:141
uint32_t fMaxMismatchB
Definition skdiff.h:151
uint32_t fMaxMismatchR
Definition skdiff.h:149
float fFractionDifference
Definition skdiff.h:138
uint32_t fMaxMismatchG
Definition skdiff.h:150
float fAverageMismatchB
Definition skdiff.h:144
float fWeightedFraction
Definition skdiff.h:139
uint32_t fMaxMismatchA
Definition skdiff.h:148
float fAverageMismatchR
Definition skdiff.h:142
uint32_t fTotalMismatchA
Definition skdiff.h:146
DiffResource fWhite
Definition skdiff.h:133
static const char * getResultDescription(Result result)
Definition skdiff.cpp:41
SkString fFullPath
Definition skdiff.h:81
static char const *const StatusNames[DiffResource::kStatusCount]
Definition skdiff.h:45
SkBitmap fBitmap
Definition skdiff.h:83
static Status getStatusByName(const char *name)
Definition skdiff.cpp:61
static const char * getStatusDescription(Status status)
Definition skdiff.cpp:86
static bool isStatusFailed(Status status)
Definition skdiff.cpp:90
static bool getMatchingStatuses(char *selector, bool statuses[kStatusCount])
Definition skdiff.cpp:98
@ kCouldNotDecode_Status
Definition skdiff.h:34
@ kRead_Status
Definition skdiff.h:37
@ kExists_Status
Definition skdiff.h:42
@ kCouldNotRead_Status
Definition skdiff.h:39
@ kDoesNotExist_Status
Definition skdiff.h:44
@ kStatusCount
Definition skdiff.h:55
@ kUnknown_Status
Definition skdiff.h:52
@ kSpecified_Status
Definition skdiff.h:47
@ kDecoded_Status
Definition skdiff.h:32
@ kUnspecified_Status
Definition skdiff.h:49
Status fStatus
Definition skdiff.h:84
DiffResource()
Definition skdiff.h:76
SkString fFilename
Definition skdiff.h:79