| 1 |
/* |
| 2 |
* Portions of this file are copyright Rebirth contributors and licensed as |
| 3 |
* described in COPYING.txt. |
| 4 |
* Portions of this file are copyright Parallax Software and licensed |
| 5 |
* according to the Parallax license below. |
| 6 |
* See COPYING.txt for license details. |
| 7 |
|
| 8 |
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
| 9 |
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
| 10 |
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
| 11 |
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
| 12 |
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
| 13 |
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
| 14 |
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
| 15 |
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
| 16 |
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
| 17 |
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <algorithm> |
| 21 |
#include <cstdint> |
| 22 |
#include "d_underlying_value.h" |
| 23 |
#include "fwd-gr.h" |
| 24 |
|
| 25 |
namespace dcx { |
| 26 |
|
| 27 |
namespace { |
| 28 |
|
| 29 |
uint8_t gr_palette_gamma_param; |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
palette_array_t gr_palette; |
| 34 |
palette_array_t gr_current_pal; |
| 35 |
gft_array1 gr_fade_table; |
| 36 |
|
| 37 |
uint8_t gr_palette_gamma; |
| 38 |
|
| 39 |
void copy_bound_palette(palette_array_t &d, const palette_array_t &s) |
| 40 |
{ |
| 41 |
std::ranges::transform(s, d.begin(), [](const rgb_t c) { |
| 42 |
constexpr uint8_t bound{63}; |
| 43 |
return rgb_t{ |
| 44 |
.r = std::min(c.r, bound), |
| 45 |
.g = std::min(c.g, bound), |
| 46 |
.b = std::min(c.b, bound) |
| 47 |
}; |
| 48 |
}); |
| 49 |
} |
| 50 |
|
| 51 |
void gr_palette_set_gamma(uint8_t gamma) |
| 52 |
{ |
| 53 |
if ( gamma > 16 ) gamma = 16; //was 8 |
| 54 |
|
| 55 |
if (gr_palette_gamma_param != gamma ) { |
| 56 |
gr_palette_gamma_param = gamma; |
| 57 |
gr_palette_gamma = gamma; |
| 58 |
gr_palette_load( gr_palette ); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
uint8_t gr_palette_get_gamma() |
| 63 |
{ |
| 64 |
return gr_palette_gamma_param; |
| 65 |
} |
| 66 |
|
| 67 |
color_palette_index gr_find_closest_color_15bpp(const packed_color_r5g5b5 rgb) |
| 68 |
{ |
| 69 |
const auto urgb = underlying_value(rgb); |
| 70 |
return gr_find_closest_color( |
| 71 |
((urgb >> 9) & 62), |
| 72 |
((urgb >> 4) & 62), |
| 73 |
((urgb << 1) & 62) |
| 74 |
); |
| 75 |
} |
| 76 |
|
| 77 |
} |