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

Unified Diff: tools/skpdiff/SkPMetric.cpp

Issue 296033004: Fix skpdiff segfault caused by NaN computation. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 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 | « 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 beba4974b770aefaeba6b7a2280de01b7c665517..47880ac2916d372fc1eaf46f6fa175eec8b2dc71 100644
--- a/tools/skpdiff/SkPMetric.cpp
+++ b/tools/skpdiff/SkPMetric.cpp
@@ -1,4 +1,5 @@
#include <cmath>
+#include <math.h>
#include "SkBitmap.h"
#include "skpdiff_util.h"
@@ -159,10 +160,12 @@ static bool bitmap_to_cielab(const SkBitmap* bitmap, ImageLAB* outImageLAB) {
static float contrast_sensitivity(float cyclesPerDegree, float luminance) {
float a = 440.0f * powf(1.0f + 0.7f / luminance, -0.2f);
float b = 0.3f * powf(1.0f + 100.0f / luminance, 0.15f);
- return a *
- cyclesPerDegree *
- expf(-b * cyclesPerDegree) *
- sqrtf(1.0f + 0.06f * expf(b * cyclesPerDegree));
+ float exp = expf(-b * cyclesPerDegree);
+ float root = sqrtf(1.0f + 0.06f * expf(b * cyclesPerDegree));
+ if (!std::isfinite(exp) || !std::isfinite(root)) {
+ return 0;
+ }
+ return a * cyclesPerDegree * exp * root;
}
#if 0
« 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