Improve float-to-uchar conversion.
authorMartin Lambers <marlam@marlam.de>
Fri, 12 Feb 2016 15:43:36 +0000 (16:43 +0100)
committerMartin Lambers <marlam@marlam.de>
Fri, 12 Feb 2016 15:43:36 +0000 (16:43 +0100)
colormap.cpp

index a9547a3..0e8c612 100644 (file)
@@ -64,7 +64,7 @@ static float uchar_to_float(unsigned char x)
 
 static unsigned char float_to_uchar(float x, bool* clipped = NULL)
 {
-    int v = x * 255.0f;
+    int v = std::round(x * 255.0f);
     if (v < 0) {
         v = 0;
         if (clipped)