Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
skdiff.h File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkString.h"
#include "include/private/base/SkTArray.h"

Go to the source code of this file.

Classes

struct  DiffResource
 
struct  DiffRecord
 
class  CompareDiffMetrics
 
class  CompareDiffWeighted
 
class  CompareDiffMeanMismatches
 
class  CompareDiffMaxMismatches
 

Macros

#define PATH_DIV_STR   "/"
 
#define PATH_DIV_CHAR   '/'
 
#define MAX2(a, b)   (((b) < (a)) ? (a) : (b))
 
#define MAX3(a, b, c)   (((b) < (a)) ? MAX2((a), (c)) : MAX2((b), (c)))
 

Typedefs

typedef skia_private::TArray< DiffRecordRecordArray
 
typedef SkPMColor(* DiffMetricProc) (SkPMColor, SkPMColor)
 Parameterized routine to compute the color of a pixel in a difference image.
 

Functions

template<typename T >
int compare (const void *untyped_lhs, const void *untyped_rhs)
 
static SkPMColor compute_diff_pmcolor (SkPMColor c0, SkPMColor c1)
 
void compute_diff (DiffRecord *dr, DiffMetricProc diffFunction, const int colorThreshold)
 

Macro Definition Documentation

◆ MAX2

#define MAX2 (   a,
  b 
)    (((b) < (a)) ? (a) : (b))

Definition at line 25 of file skdiff.h.

◆ MAX3

#define MAX3 (   a,
  b,
 
)    (((b) < (a)) ? MAX2((a), (c)) : MAX2((b), (c)))

Definition at line 26 of file skdiff.h.

◆ PATH_DIV_CHAR

#define PATH_DIV_CHAR   '/'

Definition at line 22 of file skdiff.h.

◆ PATH_DIV_STR

#define PATH_DIV_STR   "/"

Definition at line 21 of file skdiff.h.

Typedef Documentation

◆ DiffMetricProc

typedef SkPMColor(* DiffMetricProc) (SkPMColor, SkPMColor)

Parameterized routine to compute the color of a pixel in a difference image.

Definition at line 255 of file skdiff.h.

◆ RecordArray

Definition at line 157 of file skdiff.h.

Function Documentation

◆ compare()

template<typename T >
int compare ( const void *  untyped_lhs,
const void *  untyped_rhs 
)

A wrapper for any sortProc (comparison routine) which applies a first-order sort beforehand, and a tiebreaker if the sortProc returns 0.

Definition at line 161 of file skdiff.h.

161 {
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}
const char * c_str() const
Definition SkString.h:133
GAsyncResult * result
Result fResult
Which category of diff result.
Definition skdiff.h:154
DiffResource fBase
Definition skdiff.h:130
SkString fFilename
Definition skdiff.h:79

◆ compute_diff()

void compute_diff ( DiffRecord dr,
DiffMetricProc  diffFunction,
const int  colorThreshold 
)

When finished, dr->fResult should have some value other than kUnknown_Result. Expects dr->fWhite.fBitmap and dr->fDifference.fBitmap to have the same bounds as dr->fBase.fBitmap and have a valid pixelref.

Definition at line 158 of file skdiff.cpp.

158 {
159 const int w = dr->fComparison.fBitmap.width();
160 const int h = dr->fComparison.fBitmap.height();
161 if (w != dr->fBase.fBitmap.width() || h != dr->fBase.fBitmap.height()) {
163 return;
164 }
165
166 int mismatchedPixels = 0;
167 int totalMismatchA = 0;
168 int totalMismatchR = 0;
169 int totalMismatchG = 0;
170 int totalMismatchB = 0;
171
172 // Accumulate fractionally different pixels, then divide out
173 // # of pixels at the end.
174 dr->fWeightedFraction = 0;
175 for (int y = 0; y < h; y++) {
176 for (int x = 0; x < w; x++) {
177 SkPMColor c0 = *dr->fBase.fBitmap.getAddr32(x, y);
178 SkPMColor c1 = *dr->fComparison.fBitmap.getAddr32(x, y);
179 SkPMColor outputDifference = diffFunction(c0, c1);
180 uint32_t thisA = SkAbs32(SkGetPackedA32(c0) - SkGetPackedA32(c1));
181 uint32_t thisR = SkAbs32(SkGetPackedR32(c0) - SkGetPackedR32(c1));
182 uint32_t thisG = SkAbs32(SkGetPackedG32(c0) - SkGetPackedG32(c1));
183 uint32_t thisB = SkAbs32(SkGetPackedB32(c0) - SkGetPackedB32(c1));
184 totalMismatchA += thisA;
185 totalMismatchR += thisR;
186 totalMismatchG += thisG;
187 totalMismatchB += thisB;
188 // In HSV, value is defined as max RGB component.
189 int value = MAX3(thisR, thisG, thisB);
190 dr->fWeightedFraction += ((float) value) / 255;
191 if (thisA > dr->fMaxMismatchA) {
192 dr->fMaxMismatchA = thisA;
193 }
194 if (thisR > dr->fMaxMismatchR) {
195 dr->fMaxMismatchR = thisR;
196 }
197 if (thisG > dr->fMaxMismatchG) {
198 dr->fMaxMismatchG = thisG;
199 }
200 if (thisB > dr->fMaxMismatchB) {
201 dr->fMaxMismatchB = thisB;
202 }
203 if (!colors_match_thresholded(c0, c1, colorThreshold)) {
204 mismatchedPixels++;
205 *dr->fDifference.fBitmap.getAddr32(x, y) = outputDifference;
206 *dr->fWhite.fBitmap.getAddr32(x, y) = PMCOLOR_WHITE;
207 } else {
208 *dr->fDifference.fBitmap.getAddr32(x, y) = 0;
209 *dr->fWhite.fBitmap.getAddr32(x, y) = PMCOLOR_BLACK;
210 }
211 }
212 }
213 if (0 == mismatchedPixels) {
215 return;
216 }
218 int pixelCount = w * h;
219 dr->fFractionDifference = ((float) mismatchedPixels) / pixelCount;
220 dr->fWeightedFraction /= pixelCount;
221 dr->fTotalMismatchA = totalMismatchA;
222 dr->fAverageMismatchA = ((float) totalMismatchA) / pixelCount;
223 dr->fAverageMismatchR = ((float) totalMismatchR) / pixelCount;
224 dr->fAverageMismatchG = ((float) totalMismatchG) / pixelCount;
225 dr->fAverageMismatchB = ((float) totalMismatchB) / pixelCount;
226}
#define SkGetPackedB32(packed)
Definition SkColorPriv.h:95
#define SkGetPackedR32(packed)
Definition SkColorPriv.h:93
#define SkGetPackedA32(packed)
Definition SkColorPriv.h:92
#define SkGetPackedG32(packed)
Definition SkColorPriv.h:94
uint32_t SkPMColor
Definition SkColor.h:205
static int32_t SkAbs32(int32_t value)
Definition SkSafe32.h:41
uint8_t value
double y
double x
SkScalar w
SkScalar h
static bool colors_match_thresholded(SkPMColor c0, SkPMColor c1, const int threshold)
Definition skdiff.cpp:143
const SkPMColor PMCOLOR_BLACK
Definition skdiff.cpp:156
const SkPMColor PMCOLOR_WHITE
Definition skdiff.cpp:155
#define MAX3(a, b, c)
Definition skdiff.h:26
@ kDifferentSizes_Result
Definition skdiff.h:95
@ kDifferentPixels_Result
Definition skdiff.h:94
@ kEqualPixels_Result
Definition skdiff.h:93

◆ compute_diff_pmcolor()

static SkPMColor compute_diff_pmcolor ( SkPMColor  c0,
SkPMColor  c1 
)
inlinestatic

Definition at line 258 of file skdiff.h.

258 {
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}
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)