Index: colorblind.cpp
===================================================================
--- colorblind.cpp	(revision 15178)
+++ colorblind.cpp	(working copy)
@@ -75,9 +75,9 @@
 	double tmp;
 
 	/* Remove gamma to linearize RGB intensities */
-	red   = pow(red, 1.0 / gammaRGB[0]);
-	green = pow(green, 1.0 / gammaRGB[1]);
-	blue  = pow(blue, 1.0 / gammaRGB[2]);
+	red   = pow(red / 255.0, gammaRGB[0]);
+	green = pow(green / 255.0, gammaRGB[1]);
+	blue  = pow(blue / 255.0, gammaRGB[2]);
 
 	/* Convert to LMS (dot product with transform matrix) */
 	double redOld   = red;
@@ -122,7 +122,7 @@
 		{
 			double gray = clamp(0.3 * originalColor.red()
 						+ 0.59 * originalColor.green()
-						+ 0.11 * originalColor.blue(), 0, 255);
+						+ 0.11 * originalColor.blue());
 			red = gray;
 			green = gray;
 			blue = gray;
@@ -140,16 +140,22 @@
 	green = redOld * lms2rgb[3] + greenOld * lms2rgb[4] + blue * lms2rgb[5];
 	blue  = redOld * lms2rgb[6] + greenOld * lms2rgb[7] + blue * lms2rgb[8];
 
+    // HACK/FIXME: some values are set to < 0 - it will get a NaN from pow()
+    //             I'm not sure if it's correct solution...
+	red = red < 0 ? 0 : red;
+	green = green < 0 ? 0 : green;
+	blue = blue < 0 ? 0 : blue;
+
 	/* Apply gamma to go back to non-linear intensities */
-	red   = pow(red, gammaRGB[0]);
-	green = pow(green, gammaRGB[1]);
-	blue  = pow(blue, gammaRGB[2]);
+	red   = pow(red, 1.0 / gammaRGB[0]) * 255.0;
+	green = pow(green, 1.0 / gammaRGB[1]) * 255.0;
+	blue  = pow(blue, 1.0 / gammaRGB[2]) * 255.0;
 
 	/* Ensure that we stay within the RGB gamut */
 	/* *** FIX THIS: it would be better to desaturate than blindly clip. */
-	red   = clamp(red, 0.0, 255.0);
-	green = clamp(green, 0.0, 255.0);
-	blue  = clamp(blue, 0.0, 255.0);
+	red   = clamp(red);
+	green = clamp(green);
+	blue  = clamp(blue);
 }
 
 QColor VisionDefectColor::convertDefect(QColor c, int d)
@@ -242,9 +248,8 @@
 	return QColor(getRed(), getGreen(), getBlue());
 }
 
-double VisionDefectColor::clamp(double x, double low, double high)
+double VisionDefectColor::clamp(double x)
 {
-	double ret;
-	(x > high) ? ret = high : ((x < low) ? ret = low : ret = x);
-	return ret;
+	return (x > 255) ? 255.0 : ((x < 0) ? 0.0 : x);
 }
+
Index: colorblind.h
===================================================================
--- colorblind.h	(revision 15178)
+++ colorblind.h	(working copy)
@@ -152,11 +152,9 @@
 	/*! \brief Ensures that x is between the limits set by low and high.
 	Glib CLAMP() macro replacement for C++ speedup optimalization.
 	\param x value itself
-	\param low low border
-	\param high high border
 	\retval double value from interval
 	*/
-	double clamp(double x, double low, double high);
+	inline double clamp(double x);
 
 };
 

