35 #ifndef COLOR_UTIL_BLEND_H 36 #define COLOR_UTIL_BLEND_H 50 template <
typename rgba>
51 inline rgba
rgbaBlend(
const rgba& color_a,
const rgba& color_b,
double ratio)
53 ratio = std::min(ratio, 1.0);
54 ratio = std::max(ratio, 0.0);
56 double i_ratio = 1.0 - ratio;
59 color.r = color_a.r * i_ratio + color_b.r * ratio;
60 color.g = color_a.g * i_ratio + color_b.g * ratio;
61 color.b = color_a.b * i_ratio + color_b.b * ratio;
62 color.a = color_a.a * i_ratio + color_b.a * ratio;
73 template <
typename hsva>
74 inline hsva
hueBlend(
const hsva& color_a,
const hsva& color_b,
double ratio)
76 ratio = std::min(ratio, 1.0);
77 ratio = std::max(ratio, 0.0);
79 double i_ratio = 1.0 - ratio;
82 color.h = color_a.h * i_ratio + color_b.h * ratio;
83 color.s = color_a.s * i_ratio + color_b.s * ratio;
84 color.v = color_a.v * i_ratio + color_b.v * ratio;
85 color.a = color_a.a * i_ratio + color_b.a * ratio;
105 ratio = std::min(ratio, 1.0);
106 ratio = std::max(ratio, 0.0);
108 double i_ratio = 1.0 - ratio;
112 color.
s = color_a.
s * i_ratio + color_b.
s * ratio;
113 color.
v = color_a.
v * i_ratio + color_b.
v * ratio;
114 color.
a = color_a.
a * i_ratio + color_b.
a * ratio;
117 double start_h, end_h, diff;
118 if (color_a.
h > color_b.
h)
129 diff = end_h - start_h;
134 start_h = start_h + 1;
136 color.
h = modf(start_h + ratio * (end_h - start_h), &ipart);
140 color.
h = start_h + ratio * diff;
148 #endif // COLOR_UTIL_BLEND_H
hsva hueBlend(const hsva &color_a, const hsva &color_b, double ratio)
Return a color that is a linear blending of color_a and color_b in hsv space.
color_util::ColorHSVA hueBlendPlus(const color_util::ColorHSVA &color_a, const color_util::ColorHSVA &color_b, double ratio)
Return a color that blends color_a and color_b in hsv space, using the shortest distance between the ...
rgba rgbaBlend(const rgba &color_a, const rgba &color_b, double ratio)
Return a color that is a linear blending of color_a and color_b in rgba space.