2006-07-05 Roland Levillain <roland(a)lrde.epita.fr>
Fix color conversions.
* oln/convert/float_cmp.hh: New file.
* oln/convert/rgbhsv.hh: Include it.
(f_rgb_to_hsv::doit, f_hsv_to_rgb::doit): Use approx_eq and
(resp. approx_neq) to compare float values instead of plain ==
(resp. !=).
* oln/convert/rgbhsl.hh (f_rgb_to_hsl::doit, f_hsl_to_rgb::doit):
Likewise.
* tests/convert/conv.cc: Typo.
* oln/makefile.src (OLN_DEP): Add convert/float_cmp.hh.
Index: 10.232/olena/tests/convert/conv.cc
--- 10.232/olena/tests/convert/conv.cc Thu, 31 Jul 2003 15:42:27 +0200 reda
(oln/u/12_conv.cc 1.2 600)
+++ 10.232(w)/olena/tests/convert/conv.cc Wed, 05 Jul 2006 17:43:16 +0200 levill_r
(oln/u/12_conv.cc 1.2 600)
@@ -2,8 +2,7 @@
/* The extra indirection to the _STR and _CONC macros is required so that
if the arguments to STR() (or CONC()) are themselves macros, they will
- ls
- be expanded before being quoted. */
+ be expanded before being quoted. */
#ifndef STR
# define _STR(arg) #arg
# define STR(arg) _STR(arg)
Index: 10.232/olena/oln/convert/rgbhsv.hh
--- 10.232/olena/oln/convert/rgbhsv.hh Sat, 26 Jun 2004 23:19:24 +0200 thivol_d
(oln/j/35_rgbhsv.hh 1.4 600)
+++ 10.232(w)/olena/oln/convert/rgbhsv.hh Tue, 04 Jul 2006 19:25:50 +0200 levill_r
(oln/j/35_rgbhsv.hh 1.4 600)
@@ -31,6 +31,7 @@
# include <oln/basics.hh>
# include <oln/convert/abstract/colorconv.hh>
+# include <oln/convert/float_cmp.hh>
# include <ntg/basics.hh>
# include <ntg/color/rgb.hh>
@@ -71,17 +72,17 @@
out[hsv_V] = max_in;
- if (max_in != 0)
+ if (approx_neq(max_in, 0))
out[hsv_S] = delta / max_in;
else
out[hsv_S] = 0;
- if (out[hsv_S] == 0)
+ if (approx_eq(out[hsv_S], 0))
out[hsv_H] = -1; // undefined
else {
- if (in[rgb_R] == max_in)
+ if (approx_eq(in[rgb_R], max_in))
out[hsv_H] = (in[rgb_G] - in[rgb_B]) / delta;
- else if (in[rgb_G] == max_in)
+ else if (approx_eq(in[rgb_G], max_in))
out[hsv_H] = 2 + (in[rgb_B] - in[rgb_R]) / delta;
else
out[hsv_H] = 4 + (in[rgb_R] - in[rgb_G]) / delta;
@@ -129,7 +130,7 @@
vec<3, float> in = v.to_float();
vec<3, float> out;
- if(in[hsv_S] == 0)
+ if(approx_eq(in[hsv_S], 0))
out[rgb_G] = out[rgb_B] = out[rgb_R] = in[hsv_V];
else
{
Index: 10.232/olena/oln/convert/rgbhsl.hh
--- 10.232/olena/oln/convert/rgbhsl.hh Sat, 26 Jun 2004 23:19:24 +0200 thivol_d
(oln/j/36_rgbhsl.hh 1.6 600)
+++ 10.232(w)/olena/oln/convert/rgbhsl.hh Wed, 05 Jul 2006 17:50:01 +0200 levill_r
(oln/j/36_rgbhsl.hh 1.6 600)
@@ -31,6 +31,7 @@
# include <oln/basics.hh>
# include <oln/convert/abstract/colorconv.hh>
+# include <oln/convert/float_cmp.hh>
# include <ntg/basics.hh>
# include <ntg/color/rgb.hh>
@@ -95,10 +96,11 @@
float diff = max_in-min_in;
out[hsl_L] = (max_in + min_in) / 2;
- if (std::abs(diff) <= FLT_EPSILON){
- out[hsl_S] = 0;
- out[hsl_H] = 0; // undefined
- }
+ if (approx_eq (diff, 0))
+ {
+ out[hsl_S] = 0;
+ out[hsl_H] = 0; // undefined
+ }
else {
if (out[hsl_L] <= 0.5)
out[hsl_S] = diff / (max_in + min_in);
@@ -110,11 +112,11 @@
float g_dist = (max_in - in[rgb_G]) / diff;
float b_dist = (max_in - in[rgb_B]) / diff;
- if (in[rgb_R] == max_in)
+ if (approx_eq(in[rgb_R], max_in))
out[hsl_H] = b_dist - g_dist;
- else if(in[rgb_G] == max_in)
+ else if(approx_eq(in[rgb_G], max_in))
out[hsl_H] = 2 + r_dist - b_dist;
- else if(in[rgb_B] == max_in)
+ else if(approx_eq(in[rgb_B], max_in))
out[hsl_H] = 4 + g_dist - r_dist;
out[hsl_H] *= 60;
@@ -187,7 +189,7 @@
float p1 = 2 * in[hsl_L] - p2;
- if(in[hsl_S] == 0)
+ if(approx_eq (in[hsl_S], 0))
out[rgb_R] = out[rgb_G] = out[rgb_B] = in[hsl_L];
else
{
Index: 10.232/olena/oln/makefile.src
--- 10.232/olena/oln/makefile.src Thu, 09 Sep 2004 11:24:20 +0200 palma_g (oln/rOnly in
10.232(w): olena/oln/convert/float_cmp.hh
/4_makefile.s 1.7 600)
+++ 10.232(w)/olena/oln/makefile.src Wed, 05 Jul 2006 18:11:16 +0200 levill_r
(oln/r/4_makefile.s 1.7 600)
@@ -20,6 +20,7 @@
convert/abstract/conversion.hh \
convert/conversion.hh \
convert/conversion_ng_se.hh \
+ convert/float_cmp.hh \
convert/force.hh \
convert/nrgbxyz.hh \
convert/rgbyiq.hh \
Show replies by date