home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1996 by Raphael Quinet. All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation. If more than a few
- * lines of this code are used in a program which displays a copyright
- * notice or credit notice, the following acknowledgment must also be
- * displayed on the same screen: "This product includes software
- * developed by Raphael Quinet for use in the Quake Editing Utilities
- * project." THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR
- * IMPLIED WARRANTY.
- *
- * More information about the QEU project can be found on the WWW:
- * "http://www.montefiore.ulg.ac.be/~quinet/games/editing.html" or by
- * mail: Raphael Quinet, 9 rue des Martyrs, B-4550 Nandrin, Belgium.
- */
-
- /*
- * G_COLCNV.C - Color conversion routines (24 bit <-> 256 colors <-> 16 colors)
- */
-
- #include "qeu.h"
- #include "q_misc.h"
- #include "g_colcnv.h"
-
- /*
- * Return the palette index of the color which is closest to the given
- * color.
- */
- UInt8 GetPaletteMatch(struct RGB color, struct RGB *palette256)
- {
- int i;
- int besti;
- Int32 dR, dG, dB;
- UInt32 dist;
- UInt32 bestdist;
-
- /* naive version which uses RGB distances - to be improved later! */
- besti = 0;
- bestdist = 3L * 255L * 255L;
- for (i = 1; i < 256; i++)
- {
- dR = color.R - palette256[i].R;
- dG = color.G - palette256[i].G;
- dB = color.B - palette256[i].B;
- dist = dR * dR + dG * dG + dB * dB;
- if (dist < bestdist)
- {
- bestdist = dist;
- besti = i;
- }
- }
- return (UInt8)besti;
- }
-
- /* end of file */
-