BLI_math: add add_v3_uchar_clamped (previously color_add_v3_i)

Move color_add_v3_i to a public function,
useful for making minor color adjustments.
This commit is contained in:
Campbell Barton
2023-09-07 15:54:53 +10:00
parent 2ed423c23b
commit 3b0ced2e31
3 changed files with 11 additions and 9 deletions

View File

@@ -133,6 +133,8 @@ MINLINE void add_v4_v4v4(float r[4], const float a[4], const float b[4]);
MINLINE void add_v3fl_v3fl_v3i(float r[3], const float a[3], const int b[3]);
MINLINE void add_v3_uchar_clamped(uchar r[3], int i);
MINLINE void sub_v2_v2(float r[2], const float a[2]);
MINLINE void sub_v2_v2_db(double r[2], const double a[2]);
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2]);

View File

@@ -458,6 +458,13 @@ MINLINE void add_v4_v4v4(float r[4], const float a[4], const float b[4])
r[3] = a[3] + b[3];
}
MINLINE void add_v3_uchar_clamped(uchar r[3], int i)
{
r[0] = (uchar)clamp_i(r[0] + i, 0, 255);
r[1] = (uchar)clamp_i(r[1] + i, 0, 255);
r[2] = (uchar)clamp_i(r[2] + i, 0, 255);
}
MINLINE void sub_v2_v2(float r[2], const float a[2])
{
r[0] -= a[0];

View File

@@ -154,13 +154,6 @@ static void color_blend_v4_v4v4(uchar r_col[4],
r_col[3] = (faci * col1[3] + facm * col2[3]) / 256;
}
static void color_add_v3_i(uchar cp[3], int tint)
{
cp[0] = clamp_i(cp[0] + tint, 0, 255);
cp[1] = clamp_i(cp[1] + tint, 0, 255);
cp[2] = clamp_i(cp[2] + tint, 0, 255);
}
static void color_ensure_contrast_v3(uchar cp[3], const uchar cp_other[3], int contrast)
{
BLI_assert(contrast > 0);
@@ -169,12 +162,12 @@ static void color_ensure_contrast_v3(uchar cp[3], const uchar cp_other[3], int c
const int delta = item_value - inner_value;
if (delta >= 0) {
if (contrast > delta) {
color_add_v3_i(cp, contrast - delta);
add_v3_uchar_clamped(cp, contrast - delta);
}
}
else {
if (contrast > -delta) {
color_add_v3_i(cp, -contrast - delta);
add_v3_uchar_clamped(cp, -contrast - delta);
}
}
}