summaryrefslogtreecommitdiff
path: root/src/generic
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-12-19 12:11:37 -0800
committerCedric BAIL <cedric@osg.samsung.com>2016-12-19 16:33:46 -0800
commit3751e29a9b8127a2730b1d54a1268eac0ed9be10 (patch)
treee724fca3fca8d87f43fb35a021680f31abf0195e /src/generic
parent3d0c4ac0f61e6032cf197946b3f0f6b1e4f3284f (diff)
xcf: fix float comparison in xcf generic loader.
Diffstat (limited to 'src/generic')
-rw-r--r--src/generic/evas/xcf/pixelfuncs.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/generic/evas/xcf/pixelfuncs.c b/src/generic/evas/xcf/pixelfuncs.c
index 67d66d8129..a243c79b55 100644
--- a/src/generic/evas/xcf/pixelfuncs.c
+++ b/src/generic/evas/xcf/pixelfuncs.c
@@ -20,6 +20,10 @@
20 20
21#include "common.h" 21#include "common.h"
22 22
23#include <float.h>
24
25#define EINA_FLT_CMP(a, b) (fabsf((float)a - (float)b) <= FLT_EPSILON)
26
23#define RS R_VAL(src + s_idx) 27#define RS R_VAL(src + s_idx)
24#define GS G_VAL(src + s_idx) 28#define GS G_VAL(src + s_idx)
25#define BS B_VAL(src + s_idx) 29#define BS B_VAL(src + s_idx)
@@ -128,7 +132,7 @@ hls_to_rgb (DATA8 *hue, DATA8 *lightness, DATA8 *saturation)
128 l = *lightness; 132 l = *lightness;
129 s = *saturation; 133 s = *saturation;
130 134
131 if (s == 0) 135 if (EINA_FLT_CMP(s, 0))
132 { 136 {
133 /* achromatic case */ 137 /* achromatic case */
134 *hue = l; 138 *hue = l;
@@ -138,9 +142,9 @@ hls_to_rgb (DATA8 *hue, DATA8 *lightness, DATA8 *saturation)
138 else 142 else
139 { 143 {
140 if (l < 128) 144 if (l < 128)
141 m2 = (l * (255 + s)) / 65025.0; 145 m2 = (l * (255 + s)) / 65025.0;
142 else 146 else
143 m2 = (l + s - (l * s) / 255.0) / 255.0; 147 m2 = (l + s - (l * s) / 255.0) / 255.0;
144 148
145 m1 = (l / 127.5) - m2; 149 m1 = (l / 127.5) - m2;
146 150
@@ -184,23 +188,23 @@ rgb_to_hsv (DATA8 *red, DATA8 *green, DATA8 *blue)
184 else 188 else
185 s = 0; 189 s = 0;
186 190
187 if (s == 0) 191 if (EINA_FLT_CMP(s, 0))
188 h = 0; 192 h = 0;
189 else 193 else
190 { 194 {
191 delta = max - min; 195 delta = max - min;
192 if (r == max) 196 if (r == max)
193 h = (g - b) / (double) delta; 197 h = (g - b) / (double) delta;
194 else if (g == max) 198 else if (g == max)
195 h = 2 + (b - r) / (double) delta; 199 h = 2 + (b - r) / (double) delta;
196 else if (b == max) 200 else if (b == max)
197 h = 4 + (r - g) / (double) delta; 201 h = 4 + (r - g) / (double) delta;
198 h *= 42.5; 202 h *= 42.5;
199 203
200 if (h < 0) 204 if (h < 0)
201 h += 255; 205 h += 255;
202 if (h > 255) 206 if (h > 255)
203 h -= 255; 207 h -= 255;
204 } 208 }
205 209
206 *red = h; 210 *red = h;