summaryrefslogtreecommitdiff
path: root/src/i_video.c
diff options
context:
space:
mode:
authorSimon Howard2011-09-24 16:30:24 +0000
committerSimon Howard2011-09-24 16:30:24 +0000
commit73f27119add06b37dadc4a62343e1301585a828f (patch)
tree05fcb8054d2d6aaf4b1d4282bad5adb395d89c4f /src/i_video.c
parent90bb584b4b9c8e04204732d5b19f228631b174b2 (diff)
downloadchocolate-doom-73f27119add06b37dadc4a62343e1301585a828f.tar.gz
chocolate-doom-73f27119add06b37dadc4a62343e1301585a828f.tar.bz2
chocolate-doom-73f27119add06b37dadc4a62343e1301585a828f.zip
Rework mouse speed box drawing code and move to common code, so that it
can be added to other games. Subversion-branch: /branches/v2-branch Subversion-revision: 2395
Diffstat (limited to 'src/i_video.c')
-rw-r--r--src/i_video.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/i_video.c b/src/i_video.c
index 925bf3dc..dfb8086e 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1131,6 +1131,36 @@ void I_SetPalette (byte *doompalette)
palette_to_set = true;
}
+// Given an RGB value, find the closest matching palette index.
+
+int I_GetPaletteIndex(int r, int g, int b)
+{
+ int best, best_diff, diff;
+ int i;
+
+ best = 0; best_diff = INT_MAX;
+
+ for (i = 0; i < 256; ++i)
+ {
+ diff = (r - palette[i].r) * (r - palette[i].r)
+ + (g - palette[i].g) * (g - palette[i].g)
+ + (b - palette[i].b) * (b - palette[i].b);
+
+ if (diff < best_diff)
+ {
+ best = i;
+ best_diff = diff;
+ }
+
+ if (diff == 0)
+ {
+ break;
+ }
+ }
+
+ return best;
+}
+
//
// Set the window title
//