diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-15 22:34:00 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-15 22:34:00 +0400 |
commit | 7aa21d677aea676fcedf76f330775f4c38e71f3f (patch) | |
tree | 7a2a2ac1b87c700923467f4d69854bb473ff05e6 /source/blender/blenkernel | |
parent | 37552ac167fabb9c8dcc6d5dfd9ae8c61cd17bd3 (diff) |
Python/CurveMapping: add Curve Mapping functions to add/remove curve points,
evaluate the curve and update after changes.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_colortools.h | 11 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/colortools.c | 46 |
2 files changed, 52 insertions, 5 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) { |