Make skdiff robust to image size differences: if the two image sizes differ,
report that fact explicitly, record 100% pixel difference, and don't try to
generate a valid delta image.
git-svn-id: http://skia.googlecode.com/svn/trunk@2767 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/skdiff_main.cpp b/tools/skdiff_main.cpp
index 6d202a7..3d2925b 100644
--- a/tools/skdiff_main.cpp
+++ b/tools/skdiff_main.cpp
@@ -59,7 +59,8 @@
, fAverageMismatchB (0)
, fMaxMismatchR (0)
, fMaxMismatchG (0)
- , fMaxMismatchB (0) {
+ , fMaxMismatchB (0)
+ , fDoImageSizesMismatch (false) {
// These asserts are valid for GM, but not for --chromium
//SkASSERT(basePath.endsWith(filename.c_str()));
//SkASSERT(comparisonPath.endsWith(filename.c_str()));
@@ -89,6 +90,10 @@
uint32_t fMaxMismatchR;
uint32_t fMaxMismatchG;
uint32_t fMaxMismatchB;
+
+ /// By the time we need to report image size mismatch, we've already
+ /// released the bitmaps, so we need to remember it when we detect it.
+ bool fDoImageSizesMismatch;
};
#define MAX2(a,b) (((b) < (a)) ? (a) : (b))
@@ -199,6 +204,16 @@
/// Parameterized routine to compute the color of a pixel in a difference image.
typedef SkPMColor (*DiffMetricProc)(SkPMColor, SkPMColor);
+static void expand_and_copy (int width, int height, SkBitmap** dest) {
+ SkBitmap* temp = new SkBitmap ();
+ temp->reset();
+ temp->setConfig((*dest)->config(), width, height);
+ temp->allocPixels();
+ (*dest)->copyPixelsTo(temp->getPixels(), temp->getSize(),
+ temp->rowBytes());
+ *dest = temp;
+}
+
static bool get_bitmaps (DiffRecord* diffRecord) {
SkFILEStream compareStream(diffRecord->fComparisonPath.c_str());
if (!compareStream.isValid()) {
@@ -221,6 +236,8 @@
return false;
}
+ // In debug, the DLL will automatically be unloaded when this is deleted,
+ // but that shouldn't be a problem in release mode.
SkAutoTDelete<SkImageDecoder> ad(codec);
baseStream.rewind();
@@ -306,6 +323,12 @@
int totalMismatchR = 0;
int totalMismatchG = 0;
int totalMismatchB = 0;
+
+ if (w != dr->fBaseWidth || h != dr->fBaseHeight) {
+ dr->fDoImageSizesMismatch = true;
+ dr->fFractionDifference = 1;
+ return;
+ }
// Accumulate fractionally different pixels, then divide out
// # of pixels at the end.
dr->fWeightedFraction = 0;
@@ -566,6 +589,11 @@
stream->writeText("<td>");
stream->writeText(diff.fFilename.c_str());
stream->writeText("<br>");
+ if (diff.fDoImageSizesMismatch) {
+ stream->writeText("Image sizes differ");
+ stream->writeText("</td>");
+ return;
+ }
char metricBuf [20];
sprintf(metricBuf, "%12.4f%%", 100 * diff.fFractionDifference);
stream->writeText(metricBuf);