Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Unified Diff: tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp

Issue 325413003: rebaseline_server: use just skpdiff, not Python Image Library (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: attempt to fix "'abs' : ambiguous call to overloaded function" on Windows Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/skpdiff/SkDifferentPixelsMetric.h ('k') | tools/skpdiff/SkDifferentPixelsMetric_opencl.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp
diff --git a/tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp b/tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp
index e528b78f4fa850746177e254d4cbf148bccdc240..7194e805bf36dc859a2250f841f8a53a45b4293d 100644
--- a/tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp
+++ b/tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp
@@ -14,7 +14,8 @@ const char* SkDifferentPixelsMetric::getName() const {
return "different_pixels";
}
-bool SkDifferentPixelsMetric::diff(SkBitmap* baseline, SkBitmap* test, bool computeMask,
+bool SkDifferentPixelsMetric::diff(SkBitmap* baseline, SkBitmap* test,
+ const BitmapsToCreate& bitmapsToCreate,
Result* result) const {
double startTime = get_seconds();
@@ -22,17 +23,34 @@ bool SkDifferentPixelsMetric::diff(SkBitmap* baseline, SkBitmap* test, bool comp
if (baseline->width() != test->width() || baseline->height() != test->height() ||
baseline->width() <= 0 || baseline->height() <= 0 ||
baseline->colorType() != test->colorType()) {
+ SkASSERT(baseline->width() == test->width());
+ SkASSERT(baseline->height() == test->height());
+ SkASSERT(baseline->width() > 0);
+ SkASSERT(baseline->height() > 0);
+ SkASSERT(baseline->colorType() == test->colorType());
return false;
}
int width = baseline->width();
int height = baseline->height();
+ int maxRedDiff = 0;
+ int maxGreenDiff = 0;
+ int maxBlueDiff = 0;
- // Prepare the POI alpha mask if needed
- if (computeMask) {
+ // Prepare any bitmaps we will be filling in
+ if (bitmapsToCreate.alphaMask) {
result->poiAlphaMask.allocPixels(SkImageInfo::MakeA8(width, height));
result->poiAlphaMask.eraseARGB(SK_AlphaOPAQUE, 0, 0, 0);
}
+ if (bitmapsToCreate.rgbDiff) {
+ result->rgbDiffBitmap.allocPixels(SkImageInfo::Make(width, height, baseline->colorType(),
+ kPremul_SkAlphaType));
+ result->rgbDiffBitmap.eraseARGB(SK_AlphaTRANSPARENT, 0, 0, 0);
+ }
+ if (bitmapsToCreate.whiteDiff) {
+ result->whiteDiffBitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height));
+ result->whiteDiffBitmap.eraseARGB(SK_AlphaOPAQUE, 0, 0, 0);
+ }
// Prepare the pixels for comparison
result->poiCount = 0;
@@ -40,24 +58,60 @@ bool SkDifferentPixelsMetric::diff(SkBitmap* baseline, SkBitmap* test, bool comp
test->lockPixels();
for (int y = 0; y < height; y++) {
// Grab a row from each image for easy comparison
- unsigned char* baselineRow = (unsigned char*)baseline->getAddr(0, y);
- unsigned char* testRow = (unsigned char*)test->getAddr(0, y);
+ // TODO(epoger): The code below already assumes 4 bytes per pixel, so I think
+ // we could just call getAddr32() to save a little time.
+ // OR, if we want to play it safe, call ComputeBytesPerPixel instead
+ // of assuming 4 bytes per pixel.
+ uint32_t* baselineRow = static_cast<uint32_t *>(baseline->getAddr(0, y));
+ uint32_t* testRow = static_cast<uint32_t *>(test->getAddr(0, y));
for (int x = 0; x < width; x++) {
// Compare one pixel at a time so each differing pixel can be noted
- if (memcmp(&baselineRow[x * 4], &testRow[x * 4], 4) != 0) {
+ // TODO(epoger): This loop looks like a good place to work on performance,
+ // but we should run the code through a profiler to be sure.
+ uint32_t baselinePixel = baselineRow[x];
+ uint32_t testPixel = testRow[x];
+ if (baselinePixel != testPixel) {
result->poiCount++;
- if (computeMask) {
+
+ int redDiff = abs(static_cast<int>(SkColorGetR(baselinePixel) -
+ SkColorGetR(testPixel)));
+ if (redDiff > maxRedDiff) {maxRedDiff = redDiff;}
+ int greenDiff = abs(static_cast<int>(SkColorGetG(baselinePixel) -
+ SkColorGetG(testPixel)));
+ if (greenDiff > maxGreenDiff) {maxGreenDiff = greenDiff;}
+ int blueDiff = abs(static_cast<int>(SkColorGetB(baselinePixel) -
+ SkColorGetB(testPixel)));
+ if (blueDiff > maxBlueDiff) {maxBlueDiff = blueDiff;}
+
+ if (bitmapsToCreate.alphaMask) {
*result->poiAlphaMask.getAddr8(x,y) = SK_AlphaTRANSPARENT;
}
+ if (bitmapsToCreate.rgbDiff) {
+ *result->rgbDiffBitmap.getAddr32(x,y) =
+ SkColorSetRGB(redDiff, greenDiff, blueDiff);
+ }
+ if (bitmapsToCreate.whiteDiff) {
+ *result->whiteDiffBitmap.getAddr32(x,y) = SK_ColorWHITE;
+ }
}
}
}
test->unlockPixels();
baseline->unlockPixels();
- if (computeMask) {
+ result->maxRedDiff = maxRedDiff;
+ result->maxGreenDiff = maxGreenDiff;
+ result->maxBlueDiff = maxBlueDiff;
+
+ if (bitmapsToCreate.alphaMask) {
result->poiAlphaMask.unlockPixels();
}
+ if (bitmapsToCreate.rgbDiff) {
+ result->rgbDiffBitmap.unlockPixels();
+ }
+ if (bitmapsToCreate.whiteDiff) {
+ result->whiteDiffBitmap.unlockPixels();
+ }
// Calculates the percentage of identical pixels
result->result = 1.0 - ((double)result->poiCount / (width * height));
« no previous file with comments | « tools/skpdiff/SkDifferentPixelsMetric.h ('k') | tools/skpdiff/SkDifferentPixelsMetric_opencl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698