Flutter Engine
The Flutter Engine
Functions | Variables
skdiff.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkTypes.h"
#include "tools/skdiff/skdiff.h"

Go to the source code of this file.

Functions

static bool colors_match_thresholded (SkPMColor c0, SkPMColor c1, const int threshold)
 
void compute_diff (DiffRecord *dr, DiffMetricProc diffFunction, const int colorThreshold)
 

Variables

static char const *const ResultDescriptions [DiffRecord::kResultCount]
 
static char const *const StatusDescriptions [DiffResource::kStatusCount]
 
const SkPMColor PMCOLOR_WHITE = SkPreMultiplyColor(SK_ColorWHITE)
 
const SkPMColor PMCOLOR_BLACK = SkPreMultiplyColor(SK_ColorBLACK)
 

Function Documentation

◆ colors_match_thresholded()

static bool colors_match_thresholded ( SkPMColor  c0,
SkPMColor  c1,
const int  threshold 
)
inlinestatic

Definition at line 143 of file skdiff.cpp.

143 {
144 int da = SkGetPackedA32(c0) - SkGetPackedA32(c1);
145 int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1);
146 int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1);
147 int db = SkGetPackedB32(c0) - SkGetPackedB32(c1);
148
149 return ((SkAbs32(da) <= threshold) &&
150 (SkAbs32(dr) <= threshold) &&
151 (SkAbs32(dg) <= threshold) &&
152 (SkAbs32(db) <= threshold));
153}
#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
static int32_t SkAbs32(int32_t value)
Definition: SkSafe32.h:41

◆ 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}
uint32_t SkPMColor
Definition: SkColor.h:205
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

Variable Documentation

◆ PMCOLOR_BLACK

const SkPMColor PMCOLOR_BLACK = SkPreMultiplyColor(SK_ColorBLACK)

Definition at line 156 of file skdiff.cpp.

◆ PMCOLOR_WHITE

const SkPMColor PMCOLOR_WHITE = SkPreMultiplyColor(SK_ColorWHITE)

Definition at line 155 of file skdiff.cpp.

◆ ResultDescriptions

char const* const ResultDescriptions[DiffRecord::kResultCount]
static
Initial value:
= {
"contain exactly the same bits",
"contain the same pixel values, but not the same bits",
"have identical dimensions but some differing pixels",
"have differing dimensions",
"could not be compared",
"not compared yet",
}

Definition at line 32 of file skdiff.cpp.

◆ StatusDescriptions

char const* const StatusDescriptions[DiffResource::kStatusCount]
static
Initial value:
= {
"decoded",
"could not be decoded",
"read",
"could not be read",
"found",
"not found",
"specified",
"unspecified",
"unknown",
}

Definition at line 70 of file skdiff.cpp.