Clear the argument array before passing it to ReadArgs(). No more junk
[AROS.git] / rom / graphics / color_support.c
blob4b690ec41c805becb29edfb650e22b405a978a4b
1 /*
2 Copyright © 1995-2012, 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
36 ** m68k graphics.library preserves high nibble of ColorTable value when changing it
37 ** in SetRGB32cm() and SetRGB4cm() functions.
38 ** Perhaps this has something to do with genlock support (alpha value?)
39 ** Note that fields below ColorTable are present only if Type > COLORMAP_TYPE_V1_2
42 WORD dr,dg,db;
44 UWORD c1 = cm->ColorTable[index];
45 LONG r1 = (LONG)(c1 >> 4) & 0x00f0;
46 LONG g1 = (LONG)(c1 >> 0) & 0x00f0;
47 LONG b1 = (LONG)(c1 << 4) & 0x00f0;
49 if (cm->Type > COLORMAP_TYPE_V1_2) {
50 UWORD c2 = cm->LowColorBits[index];
52 r1 |= (c2 >> 8) & 0x000f;
53 g1 |= (c2 >> 4) & 0x000f;
54 b1 |= (c2 >> 0) & 0x000f;
57 dr = (WORD)(r >> (32-8)) - (WORD)r1;
58 dg = (WORD)(g >> (32-8)) - (WORD)g1;
59 db = (WORD)(b >> (32-8)) - (WORD)b1;
61 return (UWORD)(dr*dr)+(UWORD)(dg*dg)+(UWORD)(db*db);
66 ** Test whether the entry in the color map equals the given
67 ** color
69 BOOL color_equal(struct ColorMap * cm,
70 ULONG r,
71 ULONG g,
72 ULONG b,
73 ULONG index)
75 if (cm->ColorTable[index] != (((r >> 20) & 0x0f00) |
76 ((g >> 24) & 0x00f0) |
77 ((b >> 28) & 0x000f)))
78 return FALSE;
80 if ((cm->Type > COLORMAP_TYPE_V1_2) &&
81 cm->LowColorBits[index] != (((r >> 16) & 0x0f00) |
82 ((g >> 20) & 0x00f0) |
83 ((b >> 24) & 0x000f)))
84 return FALSE;
86 return TRUE;
89 VOID color_get(struct ColorMap *cm,
90 ULONG *r,
91 ULONG *g,
92 ULONG *b,
93 ULONG index)
95 UWORD hibits = cm->ColorTable[index];
97 ULONG red8 = (hibits & 0x0f00) >> 4;
98 ULONG green8 = (hibits & 0x00f0);
99 ULONG blue8 = (hibits & 0x000f) << 4;
101 if (cm->Type > COLORMAP_TYPE_V1_2) {
102 UWORD lobits = cm->LowColorBits[index];
104 red8 |= (lobits & 0x0f00) >> 8;
105 green8 |= (lobits & 0x00f0) >> 4;
106 blue8 |= (lobits & 0x000f);
109 *r = red8 * 0x01010101;
110 *g = green8 * 0x01010101;
111 *b = blue8 * 0x01010101;