33 coba->
data[0].
r = 0.0;
34 coba->
data[0].
g = 0.0;
35 coba->
data[0].
b = 0.0;
36 coba->
data[0].
a = 0.0;
38 coba->
data[1].
r = 1.0;
39 coba->
data[1].
g = 1.0;
40 coba->
data[1].
b = 1.0;
41 coba->
data[1].
a = 1.0;
44 coba->
data[0].
r = 0.0;
45 coba->
data[0].
g = 0.0;
46 coba->
data[0].
b = 0.0;
47 coba->
data[0].
a = 1.0;
49 coba->
data[1].
r = 1.0;
50 coba->
data[1].
g = 1.0;
51 coba->
data[1].
b = 1.0;
52 coba->
data[1].
a = 1.0;
56 coba->
data[a].
r = 0.5;
57 coba->
data[a].
g = 0.5;
58 coba->
data[a].
b = 0.5;
59 coba->
data[a].
a = 1.0;
70 const float (*
array)[4],
74 const float eps = (1.0f / 255.0f) + 1e-6f;
78 const float step_size = 1.0f /
float(
max_ii(stops - 1, 1));
80 for (
int i_step = 0; i_step < stops; i_step++) {
86 coba->
data[i_curr].
pos = i_step * step_size;
87 coba->
data[i_curr].
cur = i_curr;
89 coba->
tot = i_curr + 1;
95 coba->
data[0].
a = 1.0f;
122 if (c->
next ==
nullptr || c->
prev ==
nullptr) {
127 float xy_prev[2], xy_curr[2], xy_next[2];
131 for (
int i = 0; i < 4; i++) {
133 xy_curr[1] = c->
rgba[i];
141 for (
int i = 0; i < 4; i++) {
144 area +=
fabsf((xpc * ycn) + (ypc * xnc));
153 const float gaussfac = 1.6f;
154 const float two_gaussfac2 = 2.0f * gaussfac * gaussfac;
155 x *= 3.0f * gaussfac;
156 return 1.0f /
sqrtf(
float(
M_PI) * two_gaussfac2) *
expf(-
x *
x / two_gaussfac2);
160 const float (*
array)[4],
165 const float eps_2x = ((1.0f / 255.0f) + 1e-6f);
168 int carr_len = array_len;
171 const float step_size = 1.0f /
float(array_len - 1);
172 for (
int i = 0; i < array_len; i++, c++) {
176 c->
pos = i * step_size;
179 carr[0].
prev =
nullptr;
180 carr[array_len - 1].
next =
nullptr;
185 for (
int i = 0; i < array_len; i++, c++) {
200 c_prev->
next = c_next;
201 c_next->
prev = c_prev;
207 for (
int i = 0; i < 2; i++) {
209 if (c_other->
node !=
nullptr) {
216 c_other->
node =
nullptr;
227 if (filter_samples ==
false) {
228 for (c = carr; c !=
nullptr; c = c->
next, i++) {
235 for (c = carr; c !=
nullptr; c = c->
next, i++) {
236 const int steps_prev = c->
prev ? (c - c->
prev) - 1 : 0;
237 const int steps_next = c->
next ? (c->
next - c) - 1 : 0;
238 if (steps_prev == 0 && steps_next == 0) {
243 float rgba_accum = 1;
247 const float step_size = 1.0 /
float(steps_prev + 1);
250 const float step_pos =
float(j) * step_size;
251 BLI_assert(step_pos > 0.0f && step_pos < 1.0f);
258 const float step_size = 1.0 /
float(steps_next + 1);
261 const float step_pos =
float(j) * step_size;
262 BLI_assert(step_pos > 0.0f && step_pos < 1.0f);
283 const float (*
array)[4],
305 coba = MEM_new<ColorBand>(
"colorband");
314 const int ipotype_hue,
const float mfac,
const float fac,
float h1,
float h2)
319#define HUE_INTERP(h_a, h_b) ((mfac * (h_a)) + (fac * (h_b)))
320#define HUE_MOD(h) (((h) < 1.0f) ? (h) : (h) - 1.0f)
328 switch (ipotype_hue) {
330 if ((h1 < h2) && (h2 - h1) > +0.5f) {
333 else if ((h1 > h2) && (h2 - h1) < -0.5f) {
346 else if ((h1 < h2) && (h2 - h1) < +0.5f) {
349 else if ((h1 > h2) && (h2 - h1) > -0.5f) {
391 BLI_assert(h_interp >= 0.0f && h_interp < 1.0f);
401 const CBData *cbd1, *cbd2, *cbd0, *cbd3;
406 if (coba ==
nullptr || coba->
tot == 0) {
417 if (coba->
tot == 1) {
436 for (a = 0; a < coba->
tot; a++, cbd1++) {
437 if (cbd1->
pos >
in) {
442 if (a == coba->
tot) {
457 if ((a == coba->
tot) &&
474 if (cbd2->
pos != cbd1->
pos) {
480 fac = (a != coba->
tot) ? 0.0f : 1.0f;
487 if (a >= coba->
tot - 1) {
500 CLAMP(fac, 0.0f, 1.0f);
509 out[0] = t[3] * cbd3->
r + t[2] * cbd2->
r + t[1] * cbd1->
r + t[0] * cbd0->
r;
510 out[1] = t[3] * cbd3->
g + t[2] * cbd2->
g + t[1] * cbd1->
g + t[0] * cbd0->
g;
511 out[2] = t[3] * cbd3->
b + t[2] * cbd2->
b + t[1] * cbd1->
b + t[0] * cbd0->
b;
512 out[3] = t[3] * cbd3->
a + t[2] * cbd2->
a + t[1] * cbd1->
a + t[0] * cbd0->
a;
517 const float fac2 = fac * fac;
518 fac = 3.0f * fac2 - 2.0f * fac2 * fac;
520 const float mfac = 1.0f - fac;
523 float col1[3], col2[3];
529 out[1] = mfac * col1[1] + fac * col2[1];
530 out[2] = mfac * col1[2] + fac * col2[2];
531 out[3] = mfac * cbd1->
a + fac * cbd2->
a;
536 float col1[3], col2[3];
542 out[1] = mfac * col1[1] + fac * col2[1];
543 out[2] = mfac * col1[2] + fac * col2[2];
544 out[3] = mfac * cbd1->
a + fac * cbd2->
a;
550 out[0] = mfac * cbd1->
r + fac * cbd2->
r;
551 out[1] = mfac * cbd1->
g + fac * cbd2->
g;
552 out[2] = mfac * cbd1->
b + fac * cbd2->
b;
553 out[3] = mfac * cbd1->
a + fac * cbd2->
a;
569 for (a = 0; a < *size; a++) {
576 const CBData *x1 =
static_cast<const CBData *
>(a1), *x2 =
static_cast<const CBData *
>(a2);
578 if (x1->
pos > x2->pos) {
581 if (x1->
pos < x2->pos) {
595 for (a = 0; a < coba->
tot; a++) {
601 for (a = 0; a < coba->
tot; a++) {
620 if (coba->
tot != 0) {
628 coba->
cur = coba->
tot - 1;
641 if (index < 0 || index >= coba->
tot) {
646 for (
int a =
index; a < coba->
tot; a++) {
658 for (
int a = 0; a < coba->
tot; a++) {
A min-heap / priority queue ADT.
Read Blender memory allocation and freeing.
#define HUE_INTERP(h_a, h_b)
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void void bool BLI_heap_is_empty(const Heap *heap) ATTR_NONNULL(1)
Heap * BLI_heap_new_ex(unsigned int reserve_num) ATTR_WARN_UNUSED_RESULT
void BKE_colorband_init(ColorBand *coba, bool rangetype)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void void BLI_heap_remove(Heap *heap, HeapNode *node) ATTR_NONNULL(1
static void colorband_init_from_table_rgba_resample(ColorBand *coba, const float(*array)[4], const int array_len, bool filter_samples)
void rgb_to_hsl_v(const float rgb[3], float r_hsl[3])
MINLINE void mul_v4_v4fl(float r[4], const float a[4], float f)
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) ATTR_NONNULL(1)
ColorBand * BKE_colorband_add(bool rangetype)
MINLINE int max_ii(int a, int b)
bool BKE_colorband_evaluate(const ColorBand *coba, float in, float out[4])
MINLINE float cross_tri_v2(const float v1[2], const float v2[2], const float v3[2])
void * BLI_heap_pop_min(Heap *heap) ATTR_NONNULL(1)
static float filter_gauss(float x)
MINLINE bool compare_v4v4(const float v1[4], const float v2[4], float limit) ATTR_WARN_UNUSED_RESULT
void BKE_colorband_foreach_working_space_color(ColorBand *coba, const IDTypeForeachColorFunctionCallback &fn)
MINLINE void zero_v4(float r[4])
void BKE_colorband_evaluate_table_rgba(const ColorBand *coba, float **array, int *size)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
static float colorband_hue_interp(const int ipotype_hue, const float mfac, const float fac, float h1, float h2)
float BLI_heap_top_value(const Heap *heap) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
HeapNode * BLI_heap_insert(Heap *heap, float value, void *ptr) ATTR_NONNULL(1)
MINLINE void clamp_v4(float vec[4], float min, float max)
void BKE_colorband_update_sort(ColorBand *coba)
MINLINE void zero_v3(float r[3])
static int vergcband(const void *a1, const void *a2)
void hsl_to_rgb_v(const float hsl[3], float r_rgb[3])
CBData * BKE_colorband_element_add(ColorBand *coba, float position)
void BKE_colorband_init_from_table_rgba(ColorBand *coba, const float(*array)[4], int array_len, bool filter_samples)
void BLI_heap_node_value_update(Heap *heap, HeapNode *node, float value) ATTR_NONNULL(1
static float color_sample_remove_cost(const ColorResampleElem *c)
bool BKE_colorband_element_remove(ColorBand *coba, int index)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void key_curve_position_weights(float t, float data[4], KeyInterpolationType type)
static void colorband_init_from_table_rgba_simple(ColorBand *coba, const float(*array)[4], const int array_len)
MINLINE int min_ii(int a, int b)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
@ COLBAND_INTERP_CARDINAL
@ COLBAND_INTERP_B_SPLINE
@ COLBAND_INTERP_CONSTANT
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eColorBand_ColorMode color_mode
eColorBand_Interp ipotype
eColorBand_HueInterp ipotype_hue