aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2011-08-25 21:11:16 +0000
committerTiago Cunha <tcunha@gmx.com>2011-08-25 21:11:16 +0000
commita54e67030141ea32985d56e2e6ea684fef742361 (patch)
tree130aac2b88b8729bbc20613c3ab7625b47b1a9f6
parent2651c0d69c95a0a114bb65a684d83c89a8a49a36 (diff)
downloadrtmux-a54e67030141ea32985d56e2e6ea684fef742361.tar.gz
rtmux-a54e67030141ea32985d56e2e6ea684fef742361.tar.bz2
rtmux-a54e67030141ea32985d56e2e6ea684fef742361.zip
Sync OpenBSD patchset 948:
There is no need to use sqrt()/INFINITY here which simplifies the code and makes it more portable, from Havard Eidnes.
-rw-r--r--colour.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/colour.c b/colour.c
index 7ac02e10..3166b137 100644
--- a/colour.c
+++ b/colour.c
@@ -19,7 +19,6 @@
#include <sys/types.h>
#include <ctype.h>
-#include <math.h>
#include <stdlib.h>
#include <string.h>
@@ -41,7 +40,7 @@ struct colour_rgb {
struct colour_rgb *colour_rgb_256;
void colour_rgb_generate256(void);
-double colour_rgb_distance(struct colour_rgb *, struct colour_rgb *);
+u_int colour_rgb_distance(struct colour_rgb *, struct colour_rgb *);
int colour_rgb_find(struct colour_rgb *);
/* Generate 256 colour RGB table. */
@@ -91,7 +90,7 @@ colour_rgb_generate256(void)
}
/* Get colour RGB distance. */
-double
+u_int
colour_rgb_distance(struct colour_rgb *rgb1, struct colour_rgb *rgb2)
{
int r, g, b;
@@ -99,21 +98,20 @@ colour_rgb_distance(struct colour_rgb *rgb1, struct colour_rgb *rgb2)
r = rgb1->r - rgb2->r;
g = rgb1->g - rgb2->g;
b = rgb1->b - rgb2->b;
- return (sqrt(r * r + g * g + b * b));
+ return (r * r + g * g + b * b);
}
/* Work out the nearest colour from the 256 colour set. */
int
colour_rgb_find(struct colour_rgb *rgb)
{
- double distance, lowest;
- u_int colour, i;
+ u_int distance, lowest, colour, i;
if (colour_rgb_256 == NULL)
colour_rgb_generate256();
colour = 16;
- lowest = INFINITY;
+ lowest = UINT_MAX;
for (i = 0; i < 240; i++) {
distance = colour_rgb_distance(&colour_rgb_256[i], rgb);
if (distance < lowest) {