Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2012-05-15 22:34:00 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2012-05-15 22:34:00 +0400
commit7aa21d677aea676fcedf76f330775f4c38e71f3f (patch)
tree7a2a2ac1b87c700923467f4d69854bb473ff05e6
parent37552ac167fabb9c8dcc6d5dfd9ae8c61cd17bd3 (diff)
Python/CurveMapping: add Curve Mapping functions to add/remove curve points,
evaluate the curve and update after changes.
-rw-r--r--source/blender/blenkernel/BKE_colortools.h11
-rw-r--r--source/blender/blenkernel/intern/colortools.c46
-rw-r--r--source/blender/makesrna/intern/rna_color.c49
3 files changed, 93 insertions, 13 deletions
diff --git a/source/blender/blenkernel/BKE_colortools.h b/source/blender/blenkernel/BKE_colortools.h
index b85f0efe7e3..d67e1a9118e 100644
--- a/source/blender/blenkernel/BKE_colortools.h
+++ b/source/blender/blenkernel/BKE_colortools.h
@@ -33,6 +33,7 @@
struct CurveMapping;
struct CurveMap;
+struct CurveMapPoint;
struct Scopes;
struct ImBuf;
struct rctf;
@@ -52,12 +53,14 @@ void curvemapping_set_black_white(struct CurveMapping *cumap, con
#define CURVEMAP_SLOPE_NEGATIVE 0
#define CURVEMAP_SLOPE_POSITIVE 1
-void curvemap_reset(struct CurveMap *cuma, struct rctf *clipr, int preset, int slope);
-void curvemap_remove(struct CurveMap *cuma, int flag);
-void curvemap_insert(struct CurveMap *cuma, float x, float y);
-void curvemap_sethandle(struct CurveMap *cuma, int type);
+void curvemap_reset(struct CurveMap *cuma, struct rctf *clipr, int preset, int slope);
+void curvemap_remove(struct CurveMap *cuma, int flag);
+void curvemap_remove_point(struct CurveMap *cuma, struct CurveMapPoint *cmp);
+struct CurveMapPoint *curvemap_insert(struct CurveMap *cuma, float x, float y);
+void curvemap_sethandle(struct CurveMap *cuma, int type);
void curvemapping_changed(struct CurveMapping *cumap, int rem_doubles);
+void curvemapping_changed_all(struct CurveMapping *cumap);
/* single curve, no table check */
float curvemap_evaluateF(struct CurveMap *cuma, float value);
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index 7ba117861bb..d15f678f1c5 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -146,6 +146,32 @@ void curvemapping_set_black_white(CurveMapping *cumap, const float black[3], con
/* ***************** operations on single curve ************* */
/* ********** NOTE: requires curvemapping_changed() call after ******** */
+/* remove specified point */
+void curvemap_remove_point(CurveMap *cuma, CurveMapPoint *point)
+{
+ CurveMapPoint *cmp;
+ int a, b, removed = 0;
+
+ /* must have 2 points minimum */
+ if (cuma->totpoint <= 2)
+ return;
+
+ cmp = MEM_mallocN((cuma->totpoint) * sizeof(CurveMapPoint), "curve points");
+
+ /* well, lets keep the two outer points! */
+ for (a = 0, b = 0; a < cuma->totpoint; a++) {
+ if (&cuma->curve[a] != point) {
+ cmp[b] = cuma->curve[a];
+ b++;
+ }
+ else removed++;
+ }
+
+ MEM_freeN(cuma->curve);
+ cuma->curve = cmp;
+ cuma->totpoint -= removed;
+}
+
/* removes with flag set */
void curvemap_remove(CurveMap *cuma, int flag)
{
@@ -168,9 +194,10 @@ void curvemap_remove(CurveMap *cuma, int flag)
cuma->totpoint -= removed;
}
-void curvemap_insert(CurveMap *cuma, float x, float y)
+CurveMapPoint *curvemap_insert(CurveMap *cuma, float x, float y)
{
CurveMapPoint *cmp = MEM_callocN((cuma->totpoint + 1) * sizeof(CurveMapPoint), "curve points");
+ CurveMapPoint *newcmp = NULL;
int a, b, foundloc = 0;
/* insert fragments of the old one and the new point to the new curve */
@@ -181,6 +208,7 @@ void curvemap_insert(CurveMap *cuma, float x, float y)
cmp[a].y = y;
cmp[a].flag = CUMA_SELECT;
foundloc = 1;
+ newcmp = &cmp[a];
}
else {
cmp[a].x = cuma->curve[b].x;
@@ -195,6 +223,8 @@ void curvemap_insert(CurveMap *cuma, float x, float y)
/* free old curve and replace it with new one */
MEM_freeN(cuma->curve);
cuma->curve = cmp;
+
+ return newcmp;
}
void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope)
@@ -670,6 +700,20 @@ void curvemapping_changed(CurveMapping *cumap, int rem_doubles)
curvemap_make_table(cuma, clipr);
}
+void curvemapping_changed_all(CurveMapping *cumap)
+{
+ int a, cur = cumap->cur;
+
+ for (a = 0; a < CM_TOT; a++) {
+ if (cumap->cm[a].curve) {
+ cumap->cur = a;
+ curvemapping_changed(cumap, 0);
+ }
+ }
+
+ cumap->cur = cur;
+}
+
/* table should be verified */
float curvemap_evaluateF(CurveMap *cuma, float value)
{
diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c
index 76116602711..381d0f46c28 100644
--- a/source/blender/makesrna/intern/rna_color.c
+++ b/source/blender/makesrna/intern/rna_color.c
@@ -320,18 +320,14 @@ static void rna_def_curvemappoint(BlenderRNA *brna)
srna = RNA_def_struct(brna, "CurveMapPoint", NULL);
RNA_def_struct_ui_text(srna, "CurveMapPoint", "Point of a curve used for a curve mapping");
- /* not editable for now, need to have CurveMapping to do curvemapping_changed */
-
prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
RNA_def_property_float_sdna(prop, NULL, "x");
RNA_def_property_array(prop, 2);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the curve point");
prop = RNA_def_property(srna, "handle_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
RNA_def_property_enum_items(prop, prop_handle_type_items);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Handle Type", "Curve interpolation at this point: Bezier or vector");
prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
@@ -339,10 +335,38 @@ static void rna_def_curvemappoint(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Select", "Selection state of the curve point");
}
+static void rna_def_curvemap_points_api(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ PropertyRNA *parm;
+ FunctionRNA *func;
+
+ RNA_def_property_srna(cprop, "CurveMapPoints");
+ srna = RNA_def_struct(brna, "CurveMapPoints", NULL);
+ RNA_def_struct_sdna(srna, "CurveMap");
+ RNA_def_struct_ui_text(srna, "Curve Map Point", "Collection of Curve Map Points");
+
+ func = RNA_def_function(srna, "new", "curvemap_insert");
+ RNA_def_function_ui_description(func, "Add point to CurveMap");
+ parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to add point", -FLT_MAX, FLT_MAX);
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of point", -FLT_MAX, FLT_MAX);
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "New point");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "remove", "curvemap_remove_point");
+ RNA_def_function_ui_description(func, "Delete point from CurveMap");
+ parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "PointElement to remove");
+ RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
+}
+
static void rna_def_curvemap(BlenderRNA *brna)
{
StructRNA *srna;
- PropertyRNA *prop;
+ PropertyRNA *prop, *parm;
+ FunctionRNA *func;
+
static EnumPropertyItem prop_extend_items[] = {
{0, "HORIZONTAL", 0, "Horizontal", ""},
{CUMA_EXTEND_EXTRAPOLATE, "EXTRAPOLATED", 0, "Extrapolated", ""},
@@ -352,24 +376,30 @@ static void rna_def_curvemap(BlenderRNA *brna)
srna = RNA_def_struct(brna, "CurveMap", NULL);
RNA_def_struct_ui_text(srna, "CurveMap", "Curve in a curve mapping");
- /* not editable for now, need to have CurveMapping to do curvemapping_changed */
-
prop = RNA_def_property(srna, "extend", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
RNA_def_property_enum_items(prop, prop_extend_items);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Extend", "Extrapolate the curve or extend it horizontally");
prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "curve", "totpoint");
RNA_def_property_struct_type(prop, "CurveMapPoint");
RNA_def_property_ui_text(prop, "Points", "");
+ rna_def_curvemap_points_api(brna, prop);
+
+ func = RNA_def_function(srna, "evaluate", "curvemap_evaluateF");
+ RNA_def_function_ui_description(func, "Evaluate curve at given location");
+ parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to evaluate curve at", -FLT_MAX, FLT_MAX);
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of curve at given location", -FLT_MAX, FLT_MAX);
+ RNA_def_function_return(func, parm);
}
static void rna_def_curvemapping(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
+ FunctionRNA *func;
srna = RNA_def_struct(brna, "CurveMapping", NULL);
RNA_def_struct_ui_text(srna, "CurveMapping",
@@ -423,6 +453,9 @@ static void rna_def_curvemapping(BlenderRNA *brna)
RNA_def_property_range(prop, -1000.0f, 1000.0f);
RNA_def_property_ui_text(prop, "White Level", "For RGB curves, the color that white is mapped to");
RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_white_level_set", NULL);
+
+ func = RNA_def_function(srna, "update", "curvemapping_changed_all");
+ RNA_def_function_ui_description(func, "Update curve mapping after making changes");
}
static void rna_def_color_ramp_element(BlenderRNA *brna)