some fixes to accented characters
[tangerine.git] / rom / graphics / color_support.c
blob9f43c26578ca63d3c3356666b4f7ccc7314ba21f
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <exec/types.h>
10 #include <graphics/view.h>
13 ** In case the representation of colors in the ColorTable of the color map
14 ** are changed then this here should be the place where to change the
15 ** algorithms.
18 ULONG color_distance(struct ColorMap * cm,
19 ULONG r,
20 ULONG g,
21 ULONG b,
22 ULONG index)
24 /*
25 ** I am assuming 24 bit colors that are represented in the color map as
26 ** follows:
27 ** cm->ColorTable is a pointer to an array of UWORDs where every
28 ** UWORD contains the most significant 4 bits of each color.
29 ** cm->LowColorBits is a pointer to an array of UWORDs where every
30 ** UWORD contains the least significant 4 bits of each color.
31 ** for example a color r=12, g=34, b=56 would be represented as:
33 ** cm->ColorTable[x] = 0x0135
34 ** cm->LowColorBits[x] = 0x0246
37 LONG dr,dg,db;
38 UWORD c1,c2;
39 c1 = ((UWORD *)cm->ColorTable)[index];
40 c2 = ((UWORD *)cm->LowColorBits)[index];
42 dr = (LONG)(r >> (32-8)) - (LONG)(((c1 >> 4) & 0x00f0) | ((c2 >> 8) & 0x000f));
43 dg = (LONG)(g >> (32-8)) - (LONG)(((c1 >> 0) & 0x00f0) | ((c2 >> 4) & 0x000f));
44 db = (LONG)(b >> (32-8)) - (LONG)(((c1 << 4) & 0x00f0) | ((c2 >> 0) & 0x000f));
46 return dr*dr+dg*dg+db*db;
51 ** Test whether the entry in the color map equals the given
52 ** color
54 BOOL color_equal(struct ColorMap * cm,
55 ULONG r,
56 ULONG g,
57 ULONG b,
58 ULONG index)
60 if ( ((UWORD *)cm->ColorTable) [index] == (((r >> 20) & 0x0f00) |
61 ((g >> 24) & 0x00f0) |
62 ((b >> 28) & 0x000f)) &&
63 ((UWORD *)cm->LowColorBits)[index] == (((r >> 16) & 0x0f00) |
64 ((g >> 20) & 0x00f0) |
65 ((b >> 24) & 0x000f)) )
66 return TRUE;
67 else
68 return FALSE;
73 ** Set an entry in the color map
75 VOID color_set(struct ColorMap * cm,
76 ULONG r,
77 ULONG g,
78 ULONG b,
79 ULONG index)
81 ((UWORD *)cm->ColorTable)[index] = ((r >> 20) & 0x0f00) |
82 ((g >> 24) & 0x00f0) |
83 ((b >> 28) & 0x000f);
85 ((UWORD *)cm->LowColorBits)[index] = ((r >> 16) & 0x0f00) |
86 ((g >> 20) & 0x00f0) |
87 ((b >> 24) & 0x000f);
91 VOID color_get(struct ColorMap *cm,
92 ULONG *r,
93 ULONG *g,
94 ULONG *b,
95 ULONG index)
97 UWORD hibits = ((UWORD *)cm->ColorTable)[index];
98 UWORD lobits = ((UWORD *)cm->LowColorBits)[index];
100 ULONG red8 = ((hibits & 0x0f00) >> 4) | ((lobits & 0x0f00) >> 8);
101 ULONG green8 = ((hibits & 0x00f0) ) | ((lobits & 0x00f0) >> 4);
102 ULONG blue8 = ((hibits & 0x000f) << 4) | ((lobits & 0x000f) );
104 *r = red8 * 0x01010101;
105 *g = green8 * 0x01010101;
106 *b = blue8 * 0x01010101;