2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Find the closest matching color in a colormap
8 #include "graphics_intern.h"
9 #include <graphics/view.h>
11 /*****************************************************************************
14 #include <clib/graphics_protos.h>
16 AROS_LH5(ULONG
, FindColor
,
19 AROS_LHA(struct ColorMap
*, cm
, A3
),
20 AROS_LHA(ULONG
, r
, D1
),
21 AROS_LHA(ULONG
, g
, D2
),
22 AROS_LHA(ULONG
, b
, D3
),
23 AROS_LHA(ULONG
, maxpen
, D4
),
26 struct GfxBase
*, GfxBase
, 168, Graphics
)
29 Find the closest matching color in the given colormap.
32 cm - colormap structure
33 r - red level (32 bit left justified fraction)
34 g - green level (32 bit left justified fraction)
35 b - blue level (32 bit left justified fraction)
36 maxpen - the maximum entry in the color table to search.
39 The pen number with the closest match will be returned.
40 No new pens are allocated and therefore the returned pen
41 should not be released via ReleasePen().
55 *****************************************************************************/
58 AROS_LIBBASE_EXT_DECL(struct GfxBase
*,GfxBase
)
65 ULONG best_distance
= (ULONG
)-1;
68 if (-1 == maxpen
&& NULL
!= cm
->PalExtra
)
70 /* pe_SharableColors is not the number of colors but the last color index! */
71 maxpen
= cm
->PalExtra
->pe_SharableColors
;
74 if (maxpen
>= cm
->Count
) maxpen
= cm
->Count
- 1;
76 while (index
<= maxpen
)
78 distance
= color_distance(cm
,r
,g
,b
,index
);
79 if (distance
< best_distance
)
81 best_distance
= distance
;