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

Unified Diff: tools/skpdiff/SkPMetric.cpp

Issue 65253002: Changes to make SkPDiff more robost. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skpdiff/SkPMetric.cpp
diff --git a/tools/skpdiff/SkPMetric.cpp b/tools/skpdiff/SkPMetric.cpp
index 5b770b08bdbdee7e5803eb36a9dd317d4d69b6c9..0ca8ee1ec33d01ec0ed7fc007182ba533352a578 100644
--- a/tools/skpdiff/SkPMetric.cpp
+++ b/tools/skpdiff/SkPMetric.cpp
@@ -123,8 +123,14 @@ static void adobergb_to_cielab(float r, float g, float b, LAB* lab) {
}
/// Converts a 8888 bitmap to LAB color space and puts it into the output
-static void bitmap_to_cielab(const SkBitmap* bitmap, ImageLAB* outImageLAB) {
- SkASSERT(bitmap->config() == SkBitmap::kARGB_8888_Config);
+static bool bitmap_to_cielab(const SkBitmap* bitmap, ImageLAB* outImageLAB) {
+ SkBitmap bm8888;
+ if (bitmap->config() != SkBitmap::kARGB_8888_Config) {
+ if (!bitmap->copyTo(&bm8888, SkBitmap::kARGB_8888_Config)) {
+ return false;
+ }
+ bitmap = &bm8888;
+ }
int width = bitmap->width();
int height = bitmap->height();
@@ -146,6 +152,7 @@ static void bitmap_to_cielab(const SkBitmap* bitmap, ImageLAB* outImageLAB) {
}
}
bitmap->unlockPixels();
+ return true;
}
// From Barten SPIE 1989
@@ -269,6 +276,12 @@ static double pmetric(const ImageLAB* baselineLAB, const ImageLAB* testLAB, SkTD
maxLevels++;
}
+ // We'll be creating new arrays with maxLevels - 2, and ImageL3D requires maxLevels > 0,
+ // so just return failure if we're less than 3.
+ if (maxLevels <= 2) {
+ return 0.0;
+ }
+
const float fov = SK_ScalarPI / 180.0f * 45.0f;
float contrastSensitivityMax = contrast_sensitivity(3.248f, 100.0f);
float pixelsPerDegree = width / (2.0f * tanf(fov * 0.5f) * 180.0f / SK_ScalarPI);
@@ -450,8 +463,9 @@ int SkPMetric::queueDiff(SkBitmap* baseline, SkBitmap* test) {
ImageLAB baselineLAB(baseline->width(), baseline->height());
ImageLAB testLAB(baseline->width(), baseline->height());
- bitmap_to_cielab(baseline, &baselineLAB);
- bitmap_to_cielab(test, &testLAB);
+ if (!bitmap_to_cielab(baseline, &baselineLAB) || !bitmap_to_cielab(test, &testLAB)) {
+ return diffID;
+ }
diff.result = pmetric(&baselineLAB, &testLAB, &diff.poi);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698