4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2012 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Screen/Ramp.hpp"
30 ColorRampLookup(const short h
,
31 const ColorRamp
* ramp_colors
,
33 const unsigned char interp_levels
)
35 assert(ramp_colors
!= NULL
);
39 unsigned short is
= 1<<interp_levels
;
41 // gone past end, so use last color
42 if (h
>= ramp_colors
[numramp
- 1].h
) {
43 return Color(ramp_colors
[numramp
-1].r
,
44 ramp_colors
[numramp
-1].g
,
45 ramp_colors
[numramp
-1].b
);
47 for (int i
= numramp
- 2; i
>= 0; i
--) {
48 assert(ramp_colors
[i
].h
< ramp_colors
[i
+ 1].h
);
50 if (h
>= ramp_colors
[i
].h
) {
52 f
= (unsigned short)(h
- ramp_colors
[i
].h
) * is
53 / (unsigned short)(ramp_colors
[i
+ 1].h
- ramp_colors
[i
].h
);
56 return Color((f
* ramp_colors
[i
+ 1].r
+ of
* ramp_colors
[i
].r
) >> interp_levels
,
57 (f
* ramp_colors
[i
+ 1].g
+ of
* ramp_colors
[i
].g
) >> interp_levels
,
58 (f
* ramp_colors
[i
+ 1].b
+ of
* ramp_colors
[i
].b
) >> interp_levels
);
60 return Color(ramp_colors
[i
].r
, ramp_colors
[i
].g
, ramp_colors
[i
].b
);
65 // check if h lower than lowest
66 assert(h
<= ramp_colors
[0].h
);
68 return Color(ramp_colors
[0].r
, ramp_colors
[0].g
, ramp_colors
[0].b
);