aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/skdiff_main.cpp
diff options
context:
space:
mode:
authorGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-30 17:01:00 +0000
committerGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-30 17:01:00 +0000
commit8b08c3e15228cbd75ec7be206e807b77348ed6dc (patch)
treef47d1f20aca3dd932079ee4cfbb94841725809eb /tools/skdiff_main.cpp
parent29d3501e3bda5e84c47824e17937961852b4efa6 (diff)
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
Diffstat (limited to 'tools/skdiff_main.cpp')
-rw-r--r--tools/skdiff_main.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/tools/skdiff_main.cpp b/tools/skdiff_main.cpp
index 6d202a726f..3d2925b9c7 100644
--- a/tools/skdiff_main.cpp
+++ b/tools/skdiff_main.cpp
@@ -59,7 +59,8 @@ struct DiffRecord {
, 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 @@ struct DiffRecord {
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 @@ static int compare_diff_max_mismatches (DiffRecord** lhs, DiffRecord** rhs) {
/// 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 @@ static bool get_bitmaps (DiffRecord* diffRecord) {
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 @@ static void compute_diff(DiffRecord* dr,
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 @@ static void print_label_cell (SkFILEWStream* stream,
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);