2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
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
18 ULONG
color_distance(struct ColorMap
* cm
,
25 ** I am assuming 24 bit colors that are represented in the color map as
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
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
54 BOOL
color_equal(struct ColorMap
* cm
,
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)) )
73 ** Set an entry in the color map
75 VOID
color_set(struct ColorMap
* cm
,
81 ((UWORD
*)cm
->ColorTable
)[index
] = ((r
>> 20) & 0x0f00) |
82 ((g
>> 24) & 0x00f0) |
85 ((UWORD
*)cm
->LowColorBits
)[index
] = ((r
>> 16) & 0x0f00) |
86 ((g
>> 20) & 0x00f0) |
91 VOID
color_get(struct ColorMap
*cm
,
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;