Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/tmux/dist Replace needless use of double math j...
details: https://anonhg.NetBSD.org/src/rev/471505bd994e
branches: trunk
changeset: 768598:471505bd994e
user: he <he%NetBSD.org@localhost>
date: Mon Aug 22 06:52:35 2011 +0000
description:
Replace needless use of double math just to compare colour distances
with integer arithmetic. Reported to and discussed with upstream maintainer.
diffstat:
external/bsd/tmux/dist/colour.c | 17 ++++++++---------
1 files changed, 8 insertions(+), 9 deletions(-)
diffs (64 lines):
diff -r c00a8a5e226e -r 471505bd994e external/bsd/tmux/dist/colour.c
--- a/external/bsd/tmux/dist/colour.c Mon Aug 22 02:37:15 2011 +0000
+++ b/external/bsd/tmux/dist/colour.c Mon Aug 22 06:52:35 2011 +0000
@@ -1,4 +1,4 @@
-/* $Id: colour.c,v 1.1.1.2 2011/08/17 18:40:04 jmmv Exp $ */
+/* $Id: colour.c,v 1.2 2011/08/22 06:52:35 he Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm%users.sourceforge.net@localhost>
@@ -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 *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. */
@@ -90,8 +89,8 @@
}
}
-/* Get colour RGB distance. */
-double
+/* Get a measure of colour RGB distance. */
+u_int
colour_rgb_distance(struct colour_rgb *rgb1, struct colour_rgb *rgb2)
{
int r, g, b;
@@ -99,22 +98,22 @@
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 distance, lowest;
u_int colour, i;
if (colour_rgb_256 == NULL)
colour_rgb_generate256();
colour = 16;
- lowest = INFINITY;
- for (i = 0; i < 240; i++) {
+ lowest = UINT_MAX;
+ for (i = 1; i < 240; i++) {
distance = colour_rgb_distance(&colour_rgb_256[i], rgb);
if (distance < lowest) {
lowest = distance;
Home |
Main Index |
Thread Index |
Old Index