2 Copyright © 1995-2007, 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 *****************************************************************************/
64 ULONG best_distance
= (ULONG
)-1;
67 if (-1 == maxpen
&& NULL
!= cm
->PalExtra
)
69 /* pe_SharableColors is not the number of colors but the last color index! */
70 maxpen
= cm
->PalExtra
->pe_SharableColors
;
73 if (maxpen
>= cm
->Count
) maxpen
= cm
->Count
- 1;
75 while (index
<= maxpen
)
77 distance
= color_distance(cm
,r
,g
,b
,index
);
78 if (distance
< best_distance
)
80 best_distance
= distance
;