Fixed a warning (missing type cast)
[tangerine.git] / rom / graphics / findcolor.c
blob391ab4faf1b9368ea2ab76f0297be5f1a445ec2d
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Find the closest matching color in a colormap
6 Lang: english
7 */
8 #include "graphics_intern.h"
9 #include <graphics/view.h>
11 /*****************************************************************************
13 NAME */
14 #include <clib/graphics_protos.h>
16 AROS_LH5(ULONG, FindColor,
18 /* SYNOPSIS */
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),
25 /* LOCATION */
26 struct GfxBase *, GfxBase, 168, Graphics)
28 /* FUNCTION
29 Find the closest matching color in the given colormap.
31 INPUTS
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.
38 RESULT
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().
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
51 INTERNALS
53 HISTORY
55 *****************************************************************************/
57 AROS_LIBFUNC_INIT
58 AROS_LIBBASE_EXT_DECL(struct GfxBase *,GfxBase)
60 ULONG retval = 0;
62 if (NULL != cm)
64 ULONG index = 0;
65 ULONG best_distance = (ULONG)-1;
66 ULONG distance;
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;
82 retval = index;
84 index++;
88 return retval;
90 AROS_LIBFUNC_EXIT
91 } /* FindColor */