[Bf-blender-cvs] [cc811d1fd63] master: Cleanup: extract BKE_colorband from BKE_texture

Campbell Barton noreply at git.blender.org
Thu Dec 7 05:55:09 CET 2017


Commit: cc811d1fd63425e180ec50f7d13a0b9fe3a6e2eb
Author: Campbell Barton
Date:   Thu Dec 7 15:36:26 2017 +1100
Branches: master
https://developer.blender.org/rBcc811d1fd63425e180ec50f7d13a0b9fe3a6e2eb

Cleanup: extract BKE_colorband from BKE_texture

===================================================================

A	source/blender/blenkernel/BKE_colorband.h
M	source/blender/blenkernel/BKE_texture.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/DerivedMesh.c
A	source/blender/blenkernel/intern/colorband.c
M	source/blender/blenkernel/intern/dynamicpaint.c
M	source/blender/blenkernel/intern/linestyle.c
M	source/blender/blenkernel/intern/texture.c
M	source/blender/collada/DocumentImporter.cpp
M	source/blender/compositor/operations/COM_ColorRampOperation.cpp
M	source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M	source/blender/editors/interface/interface_draw.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/interface/resources.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_image_2d.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/space_view3d/drawvolume.c
M	source/blender/freestyle/intern/python/BPy_Freestyle.cpp
M	source/blender/gpu/intern/gpu_material.c
M	source/blender/makesrna/intern/rna_brush.c
M	source/blender/makesrna/intern/rna_color.c
M	source/blender/makesrna/intern/rna_material.c
M	source/blender/makesrna/intern/rna_smoke.c
M	source/blender/makesrna/intern/rna_texture.c
M	source/blender/nodes/composite/node_composite_util.h
M	source/blender/nodes/shader/node_shader_util.h
M	source/blender/nodes/shader/nodes/node_shader_tex_pointdensity.c
M	source/blender/nodes/texture/node_texture_util.h
M	source/blender/render/intern/source/pointdensity.c
M	source/blender/render/intern/source/render_texture.c
M	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
index 00000000000..09ed9a60477
--- /dev/null
+++ b/source/blender/blenkernel/BKE_colorband.h
@@ -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__ */
diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h
index 8a9171673ea..4e98852c995 100644
--- a/source/blender/blenkernel/BKE_texture.h
+++ b/source/blender/blenkernel/BKE_texture.h
@@ -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);
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 96c653dee23..3fc2c3f8eb0 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -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
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 9dae4c5eae7..b588cd07aec 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -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
index 00000000000..b1f6431019d
--- /dev/null
+++ b/source/blender/blenkernel/intern/colorband.c
@@ -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] * c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list