Cleanup: extract BKE_colorband from BKE_texture
authorCampbell Barton <ideasman42@gmail.com>
Thu, 7 Dec 2017 04:36:26 +0000 (15:36 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 7 Dec 2017 04:40:11 +0000 (15:40 +1100)
35 files changed:
source/blender/blenkernel/BKE_colorband.h [new file with mode: 0644]
source/blender/blenkernel/BKE_texture.h
source/blender/blenkernel/CMakeLists.txt
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/colorband.c [new file with mode: 0644]
source/blender/blenkernel/intern/dynamicpaint.c
source/blender/blenkernel/intern/linestyle.c
source/blender/blenkernel/intern/texture.c
source/blender/collada/DocumentImporter.cpp
source/blender/compositor/operations/COM_ColorRampOperation.cpp
source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
source/blender/depsgraph/intern/builder/deg_builder_relations.cc
source/blender/editors/interface/interface_draw.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/resources.c
source/blender/editors/object/object_add.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_image_2d.c
source/blender/editors/sculpt_paint/paint_image_proj.c
source/blender/editors/space_view3d/drawvolume.c
source/blender/freestyle/intern/python/BPy_Freestyle.cpp
source/blender/gpu/intern/gpu_material.c
source/blender/makesrna/intern/rna_brush.c
source/blender/makesrna/intern/rna_color.c
source/blender/makesrna/intern/rna_material.c
source/blender/makesrna/intern/rna_smoke.c
source/blender/makesrna/intern/rna_texture.c
source/blender/nodes/composite/node_composite_util.h
source/blender/nodes/shader/node_shader_util.h
source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c
source/blender/nodes/texture/node_texture_util.h
source/blender/render/intern/source/pointdensity.c
source/blender/render/intern/source/render_texture.c
source/blender/render/intern/source/shadeoutput.c

diff --git a/source/blender/blenkernel/BKE_colorband.h b/source/blender/blenkernel/BKE_colorband.h
new file mode 100644 (file)
index 0000000..09ed9a6
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef __BKE_COLORBAND_H__
+#define __BKE_COLORBAND_H__
+
+/** \file BKE_colorband.h
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ColorBand;
+
+/*  in ColorBand struct */
+#define MAXCOLORBAND 32
+
+void init_colorband(struct ColorBand *coba, bool rangetype);
+struct ColorBand *add_colorband(bool rangetype);
+bool do_colorband(const struct ColorBand *coba, float in, float out[4]);
+void colorband_table_RGBA(struct ColorBand *coba, float **array, int *size);
+struct CBData *colorband_element_add(struct ColorBand *coba, float position);
+int colorband_element_remove(struct ColorBand *coba, int index);
+void colorband_update_sort(struct ColorBand *coba);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_COLORBAND_H__ */
index 8a9171673ea3de837c0b43c86d4f148eab1a1a5e..4e98852c995d3bec5fdc0996eff89731a1c86fa9 100644 (file)
@@ -60,14 +60,6 @@ struct World;
 #define MAXCOLORBAND 32
 
 
-void init_colorband(struct ColorBand *coba, bool rangetype);
-struct ColorBand *add_colorband(bool rangetype);
-bool do_colorband(const struct ColorBand *coba, float in, float out[4]);
-void colorband_table_RGBA(struct ColorBand *coba, float **array, int *size);
-struct CBData *colorband_element_add(struct ColorBand *coba, float position);
-int colorband_element_remove(struct ColorBand *coba, int index);
-void colorband_update_sort(struct ColorBand *coba);
-
 void         BKE_texture_free(struct Tex *tex);
 void         BKE_texture_default(struct Tex *tex);
 void         BKE_texture_copy_data(struct Main *bmain, struct Tex *tex_dst, const struct Tex *tex_src, const int flag);
index 96c653dee23e0bd28cc05abed20eb9bb4b8f84cf..3fc2c3f8eb0ed4abbed91ee02146e80b924811f4 100644 (file)
@@ -87,6 +87,7 @@ set(SRC
        intern/cdderivedmesh.c
        intern/cloth.c
        intern/collision.c
+       intern/colorband.c
        intern/colortools.c
        intern/constraint.c
        intern/context.c
@@ -216,6 +217,7 @@ set(SRC
        BKE_cdderivedmesh.h
        BKE_cloth.h
        BKE_collision.h
+       BKE_colorband.h
        BKE_colortools.h
        BKE_constraint.h
        BKE_context.h
index 9dae4c5eae70d91c9a42f164a2637f74e28d3661..b588cd07aec1079eba37ab928ceb676ccd0bea6f 100644 (file)
@@ -52,6 +52,7 @@
 #include "BLI_task.h"
 
 #include "BKE_cdderivedmesh.h"
+#include "BKE_colorband.h"
 #include "BKE_editmesh.h"
 #include "BKE_key.h"
 #include "BKE_library.h"
@@ -62,7 +63,6 @@
 #include "BKE_object.h"
 #include "BKE_object_deform.h"
 #include "BKE_paint.h"
-#include "BKE_texture.h"
 #include "BKE_multires.h"
 #include "BKE_bvhutils.h"
 #include "BKE_deform.h"
diff --git a/source/blender/blenkernel/intern/colorband.c b/source/blender/blenkernel/intern/colorband.c
new file mode 100644 (file)
index 0000000..b1f6431
--- /dev/null
@@ -0,0 +1,396 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/colorband.c
+ *  \ingroup bke
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+#include "BLI_math_color.h"
+
+#include "DNA_key_types.h"
+#include "DNA_texture_types.h"
+
+#include "BKE_colorband.h"
+#include "BKE_material.h"
+#include "BKE_key.h"
+
+void init_colorband(ColorBand *coba, bool rangetype)
+{
+       int a;
+
+       coba->data[0].pos = 0.0;
+       coba->data[1].pos = 1.0;
+
+       if (rangetype == 0) {
+               coba->data[0].r = 0.0;
+               coba->data[0].g = 0.0;
+               coba->data[0].b = 0.0;
+               coba->data[0].a = 0.0;
+
+               coba->data[1].r = 1.0;
+               coba->data[1].g = 1.0;
+               coba->data[1].b = 1.0;
+               coba->data[1].a = 1.0;
+       }
+       else {
+               coba->data[0].r = 0.0;
+               coba->data[0].g = 0.0;
+               coba->data[0].b = 0.0;
+               coba->data[0].a = 1.0;
+
+               coba->data[1].r = 1.0;
+               coba->data[1].g = 1.0;
+               coba->data[1].b = 1.0;
+               coba->data[1].a = 1.0;
+       }
+
+       for (a = 2; a < MAXCOLORBAND; a++) {
+               coba->data[a].r = 0.5;
+               coba->data[a].g = 0.5;
+               coba->data[a].b = 0.5;
+               coba->data[a].a = 1.0;
+               coba->data[a].pos = 0.5;
+       }
+
+       coba->tot = 2;
+       coba->color_mode = COLBAND_BLEND_RGB;
+}
+
+ColorBand *add_colorband(bool rangetype)
+{
+       ColorBand *coba;
+
+       coba = MEM_callocN(sizeof(ColorBand), "colorband");
+       init_colorband(coba, rangetype);
+
+       return coba;
+}
+
+/* ------------------------------------------------------------------------- */
+
+static float colorband_hue_interp(
+        const int ipotype_hue,
+        const float mfac, const float fac,
+        float h1, float h2)
+{
+       float h_interp;
+       int mode = 0;
+
+#define HUE_INTERP(h_a, h_b) ((mfac * (h_a)) + (fac * (h_b)))
+#define HUE_MOD(h) (((h) < 1.0f) ? (h) : (h) - 1.0f)
+
+       h1 = HUE_MOD(h1);
+       h2 = HUE_MOD(h2);
+
+       BLI_assert(h1 >= 0.0f && h1 < 1.0f);
+       BLI_assert(h2 >= 0.0f && h2 < 1.0f);
+
+       switch (ipotype_hue) {
+               case COLBAND_HUE_NEAR:
+               {
+                       if      ((h1 < h2) && (h2 - h1) > +0.5f) mode = 1;
+                       else if ((h1 > h2) && (h2 - h1) < -0.5f) mode = 2;
+                       else                                     mode = 0;
+                       break;
+               }
+               case COLBAND_HUE_FAR:
+               {
+                       if      ((h1 < h2) && (h2 - h1) < +0.5f) mode = 1;
+                       else if ((h1 > h2) && (h2 - h1) > -0.5f) mode = 2;
+                       else                                     mode = 0;
+                       break;
+               }
+               case COLBAND_HUE_CCW:
+               {
+                       if (h1 > h2) mode = 2;
+                       else         mode = 0;
+                       break;
+               }
+               case COLBAND_HUE_CW:
+               {
+                       if (h1 < h2) mode = 1;
+                       else         mode = 0;
+                       break;
+               }
+       }
+
+       switch (mode) {
+               case 0:
+                       h_interp = HUE_INTERP(h1, h2);
+                       break;
+               case 1:
+                       h_interp = HUE_INTERP(h1 + 1.0f, h2);
+                       h_interp = HUE_MOD(h_interp);
+                       break;
+               case 2:
+                       h_interp = HUE_INTERP(h1, h2 + 1.0f);
+                       h_interp = HUE_MOD(h_interp);
+                       break;
+       }
+
+       BLI_assert(h_interp >= 0.0f && h_interp < 1.0f);
+
+#undef HUE_INTERP
+#undef HUE_MOD
+
+       return h_interp;
+}
+
+bool do_colorband(const ColorBand *coba, float in, float out[4])
+{
+       const CBData *cbd1, *cbd2, *cbd0, *cbd3;
+       float fac;
+       int ipotype;
+       int a;
+
+       if (coba == NULL || coba->tot == 0) return false;
+
+       cbd1 = coba->data;
+
+       ipotype = (coba->color_mode == COLBAND_BLEND_RGB) ? coba->ipotype : COLBAND_INTERP_LINEAR;
+
+       if (coba->tot == 1) {
+               out[0] = cbd1->r;
+               out[1] = cbd1->g;
+               out[2] = cbd1->b;
+               out[3] = cbd1->a;
+       }
+       else if ((in <= cbd1->pos) && ELEM(ipotype, COLBAND_INTERP_LINEAR, COLBAND_INTERP_EASE)) {
+               out[0] = cbd1->r;
+               out[1] = cbd1->g;
+               out[2] = cbd1->b;
+               out[3] = cbd1->a;
+       }
+       else {
+               CBData left, right;
+
+               /* we're looking for first pos > in */
+               for (a = 0; a < coba->tot; a++, cbd1++) {
+                       if (cbd1->pos > in) {
+                               break;
+                       }
+               }
+
+               if (a == coba->tot) {
+                       cbd2 = cbd1 - 1;
+                       right = *cbd2;
+                       right.pos = 1.0f;
+                       cbd1 = &right;
+               }
+               else if (a == 0) {
+                       left = *cbd1;
+                       left.pos = 0.0f;
+                       cbd2 = &left;
+               }
+               else {
+                       cbd2 = cbd1 - 1;
+               }
+
+               if ((in >= cbd1->pos) && ELEM(ipotype, COLBAND_INTERP_LINEAR, COLBAND_INTERP_EASE)) {
+                       out[0] = cbd1->r;
+                       out[1] = cbd1->g;
+                       out[2] = cbd1->b;
+                       out[3] = cbd1->a;
+               }
+               else {
+
+                       if (cbd2->pos != cbd1->pos) {
+                               fac = (in - cbd1->pos) / (cbd2->pos - cbd1->pos);
+                       }
+                       else {
+                               /* was setting to 0.0 in 2.56 & previous, but this
+                                * is incorrect for the last element, see [#26732] */
+                               fac = (a != coba->tot) ? 0.0f : 1.0f;
+                       }
+
+                       if (ipotype == COLBAND_INTERP_CONSTANT) {
+                               /* constant */
+                               out[0] = cbd2->r;
+                               out[1] = cbd2->g;
+                               out[2] = cbd2->b;
+                               out[3] = cbd2->a;
+                       }
+                       else if (ipotype >= COLBAND_INTERP_B_SPLINE) {
+                               /* ipo from right to left: 3 2 1 0 */
+                               float t[4];
+
+                               if (a >= coba->tot - 1) cbd0 = cbd1;
+                               else cbd0 = cbd1 + 1;
+                               if (a < 2) cbd3 = cbd2;
+                               else cbd3 = cbd2 - 1;
+
+                               CLAMP(fac, 0.0f, 1.0f);
+
+                               if (ipotype == COLBAND_INTERP_CARDINAL) {
+                                       key_curve_position_weights(fac, t, KEY_CARDINAL);
+                               }
+                               else {
+                                       key_curve_position_weights(fac, t, KEY_BSPLINE);
+                               }
+
+                               out[0] = t[3] * cbd3->r + t[2] * cbd2->r + t[1] * cbd1->r + t[0] * cbd0->r;
+                               out[1] = t[3] * cbd3->g + t[2] * cbd2->g + t[1] * cbd1->g + t[0] * cbd0->g;
+                               out[2] = t[3] * cbd3->b + t[2] * cbd2->b + t[1] * cbd1->b + t[0] * cbd0->b;
+                               out[3] = t[3] * cbd3->a + t[2] * cbd2->a + t[1] * cbd1->a + t[0] * cbd0->a;
+                               CLAMP(out[0], 0.0f, 1.0f);
+                               CLAMP(out[1], 0.0f, 1.0f);
+                               CLAMP(out[2], 0.0f, 1.0f);
+                               CLAMP(out[3], 0.0f, 1.0f);
+                       }
+                       else {
+                               float mfac;
+
+                               if (ipotype == COLBAND_INTERP_EASE) {
+                                       mfac = fac * fac;
+                                       fac = 3.0f * mfac - 2.0f * mfac * fac;
+                               }
+
+                               mfac = 1.0f - fac;
+
+                               if (UNLIKELY(coba->color_mode == COLBAND_BLEND_HSV)) {
+                                       float col1[3], col2[3];
+
+                                       rgb_to_hsv_v(&cbd1->r, col1);
+                                       rgb_to_hsv_v(&cbd2->r, col2);
+
+                                       out[0] = colorband_hue_interp(coba->ipotype_hue, mfac, fac, col1[0], col2[0]);
+                                       out[1] = mfac * col1[1] + fac * col2[1];
+                                       out[2] = mfac * col1[2] + fac * col2[2];
+                                       out[3] = mfac * cbd1->a + fac * cbd2->a;
+
+                                       hsv_to_rgb_v(out, out);
+                               }
+                               else if (UNLIKELY(coba->color_mode == COLBAND_BLEND_HSL)) {
+                                       float col1[3], col2[3];
+
+                                       rgb_to_hsl_v(&cbd1->r, col1);
+                                       rgb_to_hsl_v(&cbd2->r, col2);
+
+                                       out[0] = colorband_hue_interp(coba->ipotype_hue, mfac, fac, col1[0], col2[0]);
+                                       out[1] = mfac * col1[1] + fac * col2[1];
+                                       out[2] = mfac * col1[2] + fac * col2[2];
+                                       out[3] = mfac * cbd1->a + fac * cbd2->a;
+
+                                       hsl_to_rgb_v(out, out);
+                               }
+                               else {
+                                       /* COLBAND_BLEND_RGB */
+                                       out[0] = mfac * cbd1->r + fac * cbd2->r;
+                                       out[1] = mfac * cbd1->g + fac * cbd2->g;
+                                       out[2] = mfac * cbd1->b + fac * cbd2->b;
+                                       out[3] = mfac * cbd1->a + fac * cbd2->a;
+                               }
+                       }
+               }
+       }
+       return true;   /* OK */
+}
+
+void colorband_table_RGBA(ColorBand *coba, float **array, int *size)
+{
+       int a;
+
+       *size = CM_TABLE + 1;
+       *array = MEM_callocN(sizeof(float) * (*size) * 4, "ColorBand");
+
+       for (a = 0; a < *size; a++)
+               do_colorband(coba, (float)a / (float)CM_TABLE, &(*array)[a * 4]);
+}
+
+static int vergcband(const void *a1, const void *a2)
+{
+       const CBData *x1 = a1, *x2 = a2;
+
+       if (x1->pos > x2->pos) return 1;
+       else if (x1->pos < x2->pos) return -1;
+       return 0;
+}
+
+void colorband_update_sort(ColorBand *coba)
+{
+       int a;
+
+       if (coba->tot < 2)
+               return;
+
+       for (a = 0; a < coba->tot; a++)
+               coba->data[a].cur = a;
+
+       qsort(coba->data, coba->tot, sizeof(CBData), vergcband);
+
+       for (a = 0; a < coba->tot; a++) {
+               if (coba->data[a].cur == coba->cur) {
+                       coba->cur = a;
+                       break;
+               }
+       }
+}
+
+CBData *colorband_element_add(struct ColorBand *coba, float position)
+{
+       if (coba->tot == MAXCOLORBAND) {
+               return NULL;
+       }
+       else {
+               CBData *xnew;
+
+               xnew = &coba->data[coba->tot];
+               xnew->pos = position;
+
+               if (coba->tot != 0) {
+                       do_colorband(coba, position, &xnew->r);
+               }
+               else {
+                       zero_v4(&xnew->r);
+               }
+       }
+
+       coba->tot++;
+       coba->cur = coba->tot - 1;
+
+       colorband_update_sort(coba);
+
+       return coba->data + coba->cur;
+}
+
+int colorband_element_remove(struct ColorBand *coba, int index)
+{
+       int a;
+
+       if (coba->tot < 2)
+               return 0;
+
+       if (index < 0 || index >= coba->tot)
+               return 0;
+
+       coba->tot--;
+       for (a = index; a < coba->tot; a++) {
+               coba->data[a] = coba->data[a + 1];
+       }
+       if (coba->cur) coba->cur--;
+       return 1;
+}
index ae896176b6d14c83a00aa6d8448c98e53c3a126e..b809e13d1a0121b93fa79fcf357d6d48d1763b0d 100644 (file)
@@ -55,6 +55,7 @@
 #include "BKE_animsys.h"
 #include "BKE_armature.h"
 #include "BKE_bvhutils.h"   /* bvh tree        */
+#include "BKE_colorband.h"
 #include "BKE_cdderivedmesh.h"
 #include "BKE_constraint.h"
 #include "BKE_customdata.h"
@@ -72,7 +73,6 @@
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
 #include "BKE_scene.h"
-#include "BKE_texture.h"
 
 /* for image output    */
 #include "IMB_imbuf_types.h"
index f07cb97d47600b054435c1c2899dc23268461177..653b79709e664cca1432be004e08e43659d05f7d 100644 (file)
 #include "BLI_string_utils.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_colorband.h"
 #include "BKE_context.h"
 #include "BKE_freestyle.h"
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_linestyle.h"
 #include "BKE_node.h"
-#include "BKE_texture.h"
 #include "BKE_colortools.h"
 #include "BKE_animsys.h"
 
index 122b605f16096f6f156ef889676dbc2a8e78372b..fc41815737d42b2a45d97f804af0755566a5efa9 100644 (file)
@@ -58,6 +58,7 @@
 #include "BKE_global.h"
 #include "BKE_main.h"
 
+#include "BKE_colorband.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
 #include "BKE_library_remap.h"
@@ -198,365 +199,6 @@ void BKE_texture_colormapping_default(ColorMapping *colormap)
        colormap->blend_factor = 0.0f;
 }
 
-/* ****************** COLORBAND ******************* */
-
-void init_colorband(ColorBand *coba, bool rangetype)
-{
-       int a;
-       
-       coba->data[0].pos = 0.0;
-       coba->data[1].pos = 1.0;
-       
-       if (rangetype == 0) {
-               coba->data[0].r = 0.0;
-               coba->data[0].g = 0.0;
-               coba->data[0].b = 0.0;
-               coba->data[0].a = 0.0;
-
-               coba->data[1].r = 1.0;
-               coba->data[1].g = 1.0;
-               coba->data[1].b = 1.0;
-               coba->data[1].a = 1.0;
-       }
-       else {
-               coba->data[0].r = 0.0;
-               coba->data[0].g = 0.0;
-               coba->data[0].b = 0.0;
-               coba->data[0].a = 1.0;
-
-               coba->data[1].r = 1.0;
-               coba->data[1].g = 1.0;
-               coba->data[1].b = 1.0;
-               coba->data[1].a = 1.0;
-       }
-
-       for (a = 2; a < MAXCOLORBAND; a++) {
-               coba->data[a].r = 0.5;
-               coba->data[a].g = 0.5;
-               coba->data[a].b = 0.5;
-               coba->data[a].a = 1.0;
-               coba->data[a].pos = 0.5;
-       }
-       
-       coba->tot = 2;
-       coba->color_mode = COLBAND_BLEND_RGB;
-}
-
-ColorBand *add_colorband(bool rangetype)
-{
-       ColorBand *coba;
-       
-       coba = MEM_callocN(sizeof(ColorBand), "colorband");
-       init_colorband(coba, rangetype);
-       
-       return coba;
-}
-
-/* ------------------------------------------------------------------------- */
-
-static float colorband_hue_interp(
-        const int ipotype_hue,
-        const float mfac, const float fac,
-        float h1, float h2)
-{
-       float h_interp;
-       int mode = 0;
-
-#define HUE_INTERP(h_a, h_b) ((mfac * (h_a)) + (fac * (h_b)))
-#define HUE_MOD(h) (((h) < 1.0f) ? (h) : (h) - 1.0f)
-
-       h1 = HUE_MOD(h1);
-       h2 = HUE_MOD(h2);
-
-       BLI_assert(h1 >= 0.0f && h1 < 1.0f);
-       BLI_assert(h2 >= 0.0f && h2 < 1.0f);
-
-       switch (ipotype_hue) {
-               case COLBAND_HUE_NEAR:
-               {
-                       if      ((h1 < h2) && (h2 - h1) > +0.5f) mode = 1;
-                       else if ((h1 > h2) && (h2 - h1) < -0.5f) mode = 2;
-                       else                                     mode = 0;
-                       break;
-               }
-               case COLBAND_HUE_FAR:
-               {
-                       if      ((h1 < h2) && (h2 - h1) < +0.5f) mode = 1;
-                       else if ((h1 > h2) && (h2 - h1) > -0.5f) mode = 2;
-                       else                                     mode = 0;
-                       break;
-               }
-               case COLBAND_HUE_CCW:
-               {
-                       if (h1 > h2) mode = 2;
-                       else         mode = 0;
-                       break;
-               }
-               case COLBAND_HUE_CW:
-               {
-                       if (h1 < h2) mode = 1;
-                       else         mode = 0;
-                       break;
-               }
-       }
-
-       switch (mode) {
-               case 0:
-                       h_interp = HUE_INTERP(h1, h2);
-                       break;
-               case 1:
-                       h_interp = HUE_INTERP(h1 + 1.0f, h2);
-                       h_interp = HUE_MOD(h_interp);
-                       break;
-               case 2:
-                       h_interp = HUE_INTERP(h1, h2 + 1.0f);
-                       h_interp = HUE_MOD(h_interp);
-                       break;
-       }
-
-       BLI_assert(h_interp >= 0.0f && h_interp < 1.0f);
-
-#undef HUE_INTERP
-#undef HUE_MOD
-
-       return h_interp;
-}
-
-bool do_colorband(const ColorBand *coba, float in, float out[4])
-{
-       const CBData *cbd1, *cbd2, *cbd0, *cbd3;
-       float fac;
-       int ipotype;
-       int a;
-       
-       if (coba == NULL || coba->tot == 0) return false;
-       
-       cbd1 = coba->data;
-
-       ipotype = (coba->color_mode == COLBAND_BLEND_RGB) ? coba->ipotype : COLBAND_INTERP_LINEAR;
-
-       if (coba->tot == 1) {
-               out[0] = cbd1->r;
-               out[1] = cbd1->g;
-               out[2] = cbd1->b;
-               out[3] = cbd1->a;
-       }
-       else if ((in <= cbd1->pos) && ELEM(ipotype, COLBAND_INTERP_LINEAR, COLBAND_INTERP_EASE)) {
-               out[0] = cbd1->r;
-               out[1] = cbd1->g;
-               out[2] = cbd1->b;
-               out[3] = cbd1->a;
-       }
-       else {
-               CBData left, right;
-
-               /* we're looking for first pos > in */
-               for (a = 0; a < coba->tot; a++, cbd1++) {
-                       if (cbd1->pos > in) {
-                               break;
-                       }
-               }
-
-               if (a == coba->tot) {
-                       cbd2 = cbd1 - 1;
-                       right = *cbd2;
-                       right.pos = 1.0f;
-                       cbd1 = &right;
-               }
-               else if (a == 0) {
-                       left = *cbd1;
-                       left.pos = 0.0f;
-                       cbd2 = &left;
-               }
-               else {
-                       cbd2 = cbd1 - 1;
-               }
-
-               if ((in >= cbd1->pos) && ELEM(ipotype, COLBAND_INTERP_LINEAR, COLBAND_INTERP_EASE)) {
-                       out[0] = cbd1->r;
-                       out[1] = cbd1->g;
-                       out[2] = cbd1->b;
-                       out[3] = cbd1->a;
-               }
-               else {
-
-                       if (cbd2->pos != cbd1->pos) {
-                               fac = (in - cbd1->pos) / (cbd2->pos - cbd1->pos);
-                       }
-                       else {
-                               /* was setting to 0.0 in 2.56 & previous, but this
-                                * is incorrect for the last element, see [#26732] */
-                               fac = (a != coba->tot) ? 0.0f : 1.0f;
-                       }
-
-                       if (ipotype == COLBAND_INTERP_CONSTANT) {
-                               /* constant */
-                               out[0] = cbd2->r;
-                               out[1] = cbd2->g;
-                               out[2] = cbd2->b;
-                               out[3] = cbd2->a;
-                       }
-                       else if (ipotype >= COLBAND_INTERP_B_SPLINE) {
-                               /* ipo from right to left: 3 2 1 0 */
-                               float t[4];
-
-                               if (a >= coba->tot - 1) cbd0 = cbd1;
-                               else cbd0 = cbd1 + 1;
-                               if (a < 2) cbd3 = cbd2;
-                               else cbd3 = cbd2 - 1;
-
-                               CLAMP(fac, 0.0f, 1.0f);
-
-                               if (ipotype == COLBAND_INTERP_CARDINAL) {
-                                       key_curve_position_weights(fac, t, KEY_CARDINAL);
-                               }
-                               else {
-                                       key_curve_position_weights(fac, t, KEY_BSPLINE);
-                               }
-
-                               out[0] = t[3] * cbd3->r + t[2] * cbd2->r + t[1] * cbd1->r + t[0] * cbd0->r;
-                               out[1] = t[3] * cbd3->g + t[2] * cbd2->g + t[1] * cbd1->g + t[0] * cbd0->g;
-                               out[2] = t[3] * cbd3->b + t[2] * cbd2->b + t[1] * cbd1->b + t[0] * cbd0->b;
-                               out[3] = t[3] * cbd3->a + t[2] * cbd2->a + t[1] * cbd1->a + t[0] * cbd0->a;
-                               CLAMP(out[0], 0.0f, 1.0f);
-                               CLAMP(out[1], 0.0f, 1.0f);
-                               CLAMP(out[2], 0.0f, 1.0f);
-                               CLAMP(out[3], 0.0f, 1.0f);
-                       }
-                       else {
-                               float mfac;
-
-                               if (ipotype == COLBAND_INTERP_EASE) {
-                                       mfac = fac * fac;
-                                       fac = 3.0f * mfac - 2.0f * mfac * fac;
-                               }
-
-                               mfac = 1.0f - fac;
-
-                               if (UNLIKELY(coba->color_mode == COLBAND_BLEND_HSV)) {
-                                       float col1[3], col2[3];
-
-                                       rgb_to_hsv_v(&cbd1->r, col1);
-                                       rgb_to_hsv_v(&cbd2->r, col2);
-
-                                       out[0] = colorband_hue_interp(coba->ipotype_hue, mfac, fac, col1[0], col2[0]);
-                                       out[1] = mfac * col1[1] + fac * col2[1];
-                                       out[2] = mfac * col1[2] + fac * col2[2];
-                                       out[3] = mfac * cbd1->a + fac * cbd2->a;
-
-                                       hsv_to_rgb_v(out, out);
-                               }
-                               else if (UNLIKELY(coba->color_mode == COLBAND_BLEND_HSL)) {
-                                       float col1[3], col2[3];
-
-                                       rgb_to_hsl_v(&cbd1->r, col1);
-                                       rgb_to_hsl_v(&cbd2->r, col2);
-
-                                       out[0] = colorband_hue_interp(coba->ipotype_hue, mfac, fac, col1[0], col2[0]);
-                                       out[1] = mfac * col1[1] + fac * col2[1];
-                                       out[2] = mfac * col1[2] + fac * col2[2];
-                                       out[3] = mfac * cbd1->a + fac * cbd2->a;
-
-                                       hsl_to_rgb_v(out, out);
-                               }
-                               else {
-                                       /* COLBAND_BLEND_RGB */
-                                       out[0] = mfac * cbd1->r + fac * cbd2->r;
-                                       out[1] = mfac * cbd1->g + fac * cbd2->g;
-                                       out[2] = mfac * cbd1->b + fac * cbd2->b;
-                                       out[3] = mfac * cbd1->a + fac * cbd2->a;
-                               }
-                       }
-               }
-       }
-       return true;   /* OK */
-}
-
-void colorband_table_RGBA(ColorBand *coba, float **array, int *size)
-{
-       int a;
-       
-       *size = CM_TABLE + 1;
-       *array = MEM_callocN(sizeof(float) * (*size) * 4, "ColorBand");
-
-       for (a = 0; a < *size; a++)
-               do_colorband(coba, (float)a / (float)CM_TABLE, &(*array)[a * 4]);
-}
-
-static int vergcband(const void *a1, const void *a2)
-{
-       const CBData *x1 = a1, *x2 = a2;
-
-       if (x1->pos > x2->pos) return 1;
-       else if (x1->pos < x2->pos) return -1;
-       return 0;
-}
-
-void colorband_update_sort(ColorBand *coba)
-{
-       int a;
-       
-       if (coba->tot < 2)
-               return;
-       
-       for (a = 0; a < coba->tot; a++)
-               coba->data[a].cur = a;
-
-       qsort(coba->data, coba->tot, sizeof(CBData), vergcband);
-
-       for (a = 0; a < coba->tot; a++) {
-               if (coba->data[a].cur == coba->cur) {
-                       coba->cur = a;
-                       break;
-               }
-       }
-}
-
-CBData *colorband_element_add(struct ColorBand *coba, float position)
-{
-       if (coba->tot == MAXCOLORBAND) {
-               return NULL;
-       }
-       else {
-               CBData *xnew;
-
-               xnew = &coba->data[coba->tot];
-               xnew->pos = position;
-
-               if (coba->tot != 0) {
-                       do_colorband(coba, position, &xnew->r);
-               }
-               else {
-                       zero_v4(&xnew->r);
-               }
-       }
-
-       coba->tot++;
-       coba->cur = coba->tot - 1;
-
-       colorband_update_sort(coba);
-
-       return coba->data + coba->cur;
-}
-
-int colorband_element_remove(struct ColorBand *coba, int index)
-{
-       int a;
-
-       if (coba->tot < 2)
-               return 0;
-
-       if (index < 0 || index >= coba->tot)
-               return 0;
-
-       coba->tot--;
-       for (a = index; a < coba->tot; a++) {
-               coba->data[a] = coba->data[a + 1];
-       }
-       if (coba->cur) coba->cur--;
-       return 1;
-}
-
 /* ******************* TEX ************************ */
 
 /** Free (or release) any data used by this texture (does not free the texure itself). */
index f7fdfb06a405413c35553f42b64a94be05beab84..eada4b2bf9838ddb9295fedea9d8cae04f9088f9 100644 (file)
@@ -60,7 +60,6 @@ extern "C" {
 #include "BKE_main.h"
 #include "BKE_lamp.h"
 #include "BKE_library.h"
-#include "BKE_texture.h"
 #include "BKE_fcurve.h"
 #include "BKE_depsgraph.h"
 #include "BKE_scene.h"
index 84d36034ec6dd8dc2b5c47358bd9b677f558bdcc..bbc09747ae17991ca2e4fa89cb9a18c8c68e0d97 100644 (file)
@@ -25,7 +25,7 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-#  include "BKE_texture.h"
+#  include "BKE_colorband.h"
 #ifdef __cplusplus
 }
 #endif
index fdeeb0de16f4b73a67c9e6b6bd157b894f0be90b..6de6feb32f26fbbf5dcb4663a8eb22b1a6c01031 100644 (file)
@@ -92,7 +92,6 @@ extern "C" {
 #include "BKE_particle.h"
 #include "BKE_rigidbody.h"
 #include "BKE_sound.h"
-#include "BKE_texture.h"
 #include "BKE_tracking.h"
 #include "BKE_world.h"
 
index f607fbd5380aa2bdc08c87df0d416a6359dc1d88..f44d8f2c02972a9482d33f4cce0377b450f69d83 100644 (file)
@@ -88,7 +88,6 @@ extern "C" {
 #include "BKE_particle.h"
 #include "BKE_rigidbody.h"
 #include "BKE_sound.h"
-#include "BKE_texture.h"
 #include "BKE_tracking.h"
 #include "BKE_world.h"
 
index 01ea1e953fa558ba85a08cdd19c2547b0c544167..04e0a20243b1389c85d11587df903d4f7347295f 100644 (file)
@@ -40,9 +40,9 @@
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_colorband.h"
 #include "BKE_colortools.h"
 #include "BKE_node.h"
-#include "BKE_texture.h"
 #include "BKE_tracking.h"
 
 
index 4dfb1a92bf680b25c53fbb76c644070210f76065..06196b5722072a59e1c1c88c6fe7a6578fde89f4 100644 (file)
@@ -61,6 +61,7 @@
 
 #include "PIL_time.h"
 
+#include "BKE_colorband.h"
 #include "BKE_blender_undo.h"
 #include "BKE_brush.h"
 #include "BKE_colortools.h"
@@ -68,7 +69,6 @@
 #include "BKE_idprop.h"
 #include "BKE_report.h"
 #include "BKE_screen.h"
-#include "BKE_texture.h"
 #include "BKE_tracking.h"
 #include "BKE_unit.h"
 #include "BKE_paint.h"
index e1e18b1f102a1bd867990bd15ca9a03617bdf1dc..37d1146e97b467e7ac00c2f72fe31bb864f9c5aa 100644 (file)
@@ -53,6 +53,7 @@
 #include "BLF_api.h"
 #include "BLT_translation.h"
 
+#include "BKE_colorband.h"
 #include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
@@ -70,7 +71,6 @@
 #include "BKE_report.h"
 #include "BKE_sca.h"
 #include "BKE_screen.h"
-#include "BKE_texture.h"
 
 #include "ED_screen.h"
 #include "ED_object.h"
index 4b47d0da13ee96f9fe1725426017b40ddd55eccd..a73ecbac85fc522d923fbf5cfc0f5bdf58446137 100644 (file)
 #include "BLI_math.h"
 
 #include "BKE_appdir.h"
+#include "BKE_colorband.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
-#include "BKE_texture.h"
 
 #include "BIF_gl.h"
 
index 3f82298f5b3df5df49ac155acb24783906fff06b..5048b70546c663710d2c01307d710585937e0813 100644 (file)
@@ -90,7 +90,6 @@
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_speaker.h"
-#include "BKE_texture.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
index 6b197bbb3921625cd4ff317c60e5d4e3ae003c01..427d4a7bb7b0640853cbcc622635187a933fe20d 100644 (file)
@@ -50,6 +50,7 @@
 #include "DNA_node_types.h"
 #include "DNA_object_types.h"
 
+#include "BKE_colorband.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_DerivedMesh.h"
@@ -59,7 +60,6 @@
 #include "BKE_material.h"
 #include "BKE_node.h"
 #include "BKE_paint.h"
-#include "BKE_texture.h"
 
 #include "UI_interface.h"
 #include "UI_view2d.h"
index 09b0847b3064c067939d8ba4f8435caed3b872fc..766942a5fce0686829130345a281d26cd023cf09 100644 (file)
 #include "BLI_bitmap.h"
 #include "BLI_task.h"
 
+#include "BKE_colorband.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_brush.h"
 #include "BKE_image.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
-#include "BKE_texture.h"
 
 #include "ED_paint.h"
 #include "ED_screen.h"
index 6fa45f1932a30299ced54633a02ddc37db7946ca..60a4cd86aa586dbca4623537a5716bd91e5ca75f 100644 (file)
@@ -62,6 +62,7 @@
 #include "DNA_object_types.h"
 
 #include "BKE_camera.h"
+#include "BKE_colorband.h"
 #include "BKE_context.h"
 #include "BKE_colortools.h"
 #include "BKE_depsgraph.h"
index c076bfb4aa4d822acc185c755c4b16344504f619..dafe25a70721527459a1756cfa84c32cdc2d632b 100644 (file)
@@ -41,7 +41,7 @@
 #include "BLI_math.h"
 
 #include "BKE_DerivedMesh.h"
-#include "BKE_texture.h"
+#include "BKE_colorband.h"
 #include "BKE_particle.h"
 
 #include "smoke_API.h"
index f8aef2a08ae29601930019a10d21d965eebd6e49..b2a6d53f992dd189307e143a14ffc7df0ab463c5 100644 (file)
@@ -157,7 +157,7 @@ static PyObject *Freestyle_blendRamp(PyObject * /*self*/, PyObject *args)
        return Vector_CreatePyObject(a, 3, NULL);
 }
 
-#include "BKE_texture.h" /* do_colorband() */
+#include "BKE_colorband.h" /* do_colorband() */
 
 static char Freestyle_evaluateColorRamp___doc__[] =
 ".. function:: evaluateColorRamp(ramp, in)\n"
index f39cad20b9be864ea3146a36126b56bae59942e7..b46a1b6f48eade584f974e8ad5bf3921df61af6f 100644 (file)
 #include "BLI_utildefines.h"
 
 #include "BKE_anim.h"
+#include "BKE_colorband.h"
 #include "BKE_colortools.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
 #include "BKE_scene.h"
-#include "BKE_texture.h"
 #include "BKE_group.h"
 
 #include "IMB_imbuf_types.h"
index 78614bebceb2b2885cd15eaf490d567ad0f9d4f7..816ab5783c6a24c3d544696e59a4a91848307e1f 100644 (file)
@@ -128,7 +128,7 @@ const EnumPropertyItem rna_enum_brush_image_tool_items[] = {
 
 #include "RNA_access.h"
 
-#include "BKE_texture.h"
+#include "BKE_colorband.h"
 #include "BKE_brush.h"
 #include "BKE_icons.h"
 #include "BKE_paint.h"
index 51c7e93f3ef203ae86ba78439f6edf2a6328eac8..95b14ab11ddf56ca7253521530104f01a4b087f5 100644 (file)
 
 #include "MEM_guardedalloc.h"
 
+#include "BKE_colorband.h"
 #include "BKE_colortools.h"
 #include "BKE_depsgraph.h"
 #include "BKE_image.h"
 #include "BKE_movieclip.h"
 #include "BKE_node.h"
 #include "BKE_sequencer.h"
-#include "BKE_texture.h"
 #include "BKE_linestyle.h"
 
 #include "ED_node.h"
index bb0005e7a3eae964972a68a88332a8b0df9bf620..ea712f993f120d403b9fe75a632be6cea30d4c7b 100644 (file)
@@ -85,6 +85,7 @@ const EnumPropertyItem rna_enum_ramp_blend_items[] = {
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 
+#include "BKE_colorband.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_main.h"
index 77d7f7833c6fb21800e62f154d785ce18a3c958a..4ffd1f004264c98974932a031f060d59fb3df5f9 100644 (file)
 
 #ifdef RNA_RUNTIME
 
+#include "BKE_colorband.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_particle.h"
-#include "BKE_texture.h"
 
 #include "smoke_API.h"
 
index a78b3242a66613ab51dfeccbc983d665c3dea21d..831fc8beb89fa106b1ad2fe74134cb580ab0e28c 100644 (file)
@@ -112,6 +112,7 @@ static const EnumPropertyItem blend_type_items[] = {
 
 #include "RNA_access.h"
 
+#include "BKE_colorband.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_image.h"
index 2dac0cc639a3a10b338ad4d9718fd4456b3ac067..22c5e6f9507cd7951599fbe0f4c110bd9e4ef7a3 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "BLT_translation.h"
 
+#include "BKE_colorband.h"
 #include "BKE_colortools.h"
 #include "BKE_image.h"
 #include "BKE_texture.h"
index 4cb39e0f13bde96390c0c03de3db29926c9913d1..a902ede8aa7d0814329c3be547a7adb8b6cf592d 100644 (file)
@@ -55,6 +55,7 @@
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_colorband.h"
 #include "BKE_colortools.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
index 8748c884a25b3e656640b8841c42fb9bdda02e45..436eeeefb4a122c1d846e8c9cf817a4bbb33e74a 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "../node_shader_util.h"
 
-#include "BKE_texture.h"
 
 #include "RE_render_ext.h"
 
index 2263c271ccf6f8c9ac2c9235a0c88080053c9cce..f6af5b1b6ca2b1be07b48075c46d61b16075af57 100644 (file)
@@ -53,6 +53,7 @@
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_colorband.h"
 #include "BKE_colortools.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
index fb047aad897d3cde2db7a283ce68e8569778e175..1fd6cec0d4d7eb52ccc11a495e7dd329f77f6ba9 100644 (file)
@@ -48,6 +48,7 @@
 #include "DNA_particle_types.h"
 #include "DNA_texture_types.h"
 
+#include "BKE_colorband.h"
 #include "BKE_deform.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_lattice.h"
@@ -55,7 +56,6 @@
 #include "BKE_object.h"
 #include "BKE_particle.h"
 #include "BKE_scene.h"
-#include "BKE_texture.h"
 #include "BKE_colortools.h"
 
 #include "render_types.h"
index 91d1f63a1beab3a611e26952013089cbb7402907..db0f2b57d901016e4a16b2ff143a24bf7d24fc15 100644 (file)
@@ -54,6 +54,7 @@
 #include "BKE_node.h"
 
 #include "BKE_animsys.h"
+#include "BKE_colorband.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
index 8dea0930b9e63e123847fc41fe7d9854e818a4ef..75fb6e8a2408a76911010332115b6edbc281033a 100644 (file)
@@ -27,7 +27,6 @@
  *  \ingroup render
  */
 
-
 #include <stdio.h>
 #include <float.h>
 #include <math.h>
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_colorband.h"
 #include "BKE_colortools.h"
 #include "BKE_material.h"
-#include "BKE_texture.h"
-
 
 #include "DNA_group_types.h"
 #include "DNA_lamp_types.h"