mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-06 00:10:20 +01:00
gallium/util: add helper to clamp colors to valid range
v3 (Iago): - Fix comment. Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com> Reviewed-by: Iago Toral Quiroga <itoral@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13409>
This commit is contained in:
parent
da0cdc84d5
commit
fa1cd83fef
2 changed files with 30 additions and 0 deletions
|
|
@ -25,6 +25,7 @@
|
|||
*
|
||||
**************************************************************************/
|
||||
|
||||
#include "util/format/format_utils.h"
|
||||
#include "util/u_cpu_detect.h"
|
||||
#include "util/u_helpers.h"
|
||||
#include "util/u_inlines.h"
|
||||
|
|
@ -518,3 +519,29 @@ util_init_pipe_vertex_state(struct pipe_screen *screen,
|
|||
state->input.elements[i] = elements[i];
|
||||
state->input.full_velem_mask = full_velem_mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp color value to format range.
|
||||
*/
|
||||
union pipe_color_union
|
||||
util_clamp_color(enum pipe_format format,
|
||||
const union pipe_color_union *color)
|
||||
{
|
||||
union pipe_color_union clamp_color = *color;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < util_format_get_nr_components(format); i++) {
|
||||
uint8_t bits = util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, i);
|
||||
|
||||
if (util_format_is_unorm(format))
|
||||
clamp_color.ui[i] = _mesa_unorm_to_unorm(clamp_color.ui[i], bits, bits);
|
||||
else if (util_format_is_snorm(format))
|
||||
clamp_color.i[i] = _mesa_snorm_to_snorm(clamp_color.i[i], bits, bits);
|
||||
else if (util_format_is_pure_uint(format))
|
||||
clamp_color.ui[i] = _mesa_unsigned_to_unsigned(clamp_color.ui[i], bits);
|
||||
else if (util_format_is_pure_sint(format))
|
||||
clamp_color.i[i] = _mesa_signed_to_signed(clamp_color.i[i], bits);
|
||||
}
|
||||
|
||||
return clamp_color;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,6 +130,9 @@ util_init_pipe_vertex_state(struct pipe_screen *screen,
|
|||
uint32_t full_velem_mask,
|
||||
struct pipe_vertex_state *state);
|
||||
|
||||
union pipe_color_union util_clamp_color(enum pipe_format format,
|
||||
const union pipe_color_union *color);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue