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:
authorMatt Ebb <matt@mke3.net>2010-01-27 03:22:29 +0300
committerMatt Ebb <matt@mke3.net>2010-01-27 03:22:29 +0300
commit0bb36e9ced06b04b961300b21211f456c7035bcf (patch)
tree9e38b0b5e9b84a22a7a03c5cad4139106168685c /source/blender/nodes
parentebafb7e484fa45aed0f4be75cfb5d570d7d43f81 (diff)
Fixes to Color Balance node:
* The Lift/Gamma/Gain formula previously was incorrect, fixed this and removed conversions - now the RNA values are the same as what goes into the formula. * Because of this, added the ability for the Value slider to map to a wider range than 0.0-1.0. The black/white gradient remains the same, in this case just indicating darker/brighter rather than absolute colour values. Also added ability for color wheels to be locked at full brightness (useful for this case, where the color value itself is dark). * Added an alternate formula - offset/power/slope (asc-cdl). This fits the standard Color Decision List formula, here for compatibility with other systems, though default Lift/Gamma/Gain is easier to use and gives nicer results.
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/intern/CMP_nodes/CMP_colorbalance.c88
1 files changed, 64 insertions, 24 deletions
diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_colorbalance.c b/source/blender/nodes/intern/CMP_nodes/CMP_colorbalance.c
index 9d3a670fad2..09dccd8e3c4 100644
--- a/source/blender/nodes/intern/CMP_nodes/CMP_colorbalance.c
+++ b/source/blender/nodes/intern/CMP_nodes/CMP_colorbalance.c
@@ -43,34 +43,66 @@ static bNodeSocketType cmp_node_colorbalance_out[]={
{-1,0,""}
};
-DO_INLINE float colorbalance(float in, float slope, float offset, float power)
+DO_INLINE float colorbalance_cdl(float in, float offset, float power, float slope)
{
float x = in * slope + offset;
/* prevent NaN */
if (x < 0.f) x = 0.f;
- return powf(x, power);
+ //powf(in * slope + offset, power)
+ return powf(x, 1.f/power);
}
-static void do_colorbalance(bNode *node, float* out, float *in)
+DO_INLINE float colorbalance_lgg(float in, float lift, float gamma, float gain)
+{
+ float x = gain*(in+lift*(1-in));
+
+ /* prevent NaN */
+ if (x < 0.f) x = 0.f;
+
+ return powf(x, (1.f/gamma));
+}
+
+static void do_colorbalance_cdl(bNode *node, float* out, float *in)
{
NodeColorBalance *n= (NodeColorBalance *)node->storage;
- out[0] = colorbalance(in[0], n->slope[0], n->offset[0], n->power[0]);
- out[1] = colorbalance(in[1], n->slope[1], n->offset[1], n->power[1]);
- out[2] = colorbalance(in[2], n->slope[2], n->offset[2], n->power[2]);
+ out[0] = colorbalance_cdl(in[0], n->lift[0], n->gamma[0], n->gain[0]);
+ out[1] = colorbalance_cdl(in[1], n->lift[1], n->gamma[1], n->gain[1]);
+ out[2] = colorbalance_cdl(in[2], n->lift[2], n->gamma[2], n->gain[2]);
out[3] = in[3];
}
-static void do_colorbalance_fac(bNode *node, float* out, float *in, float *fac)
+static void do_colorbalance_cdl_fac(bNode *node, float* out, float *in, float *fac)
{
NodeColorBalance *n= (NodeColorBalance *)node->storage;
const float mfac= 1.0f - *fac;
- out[0] = mfac*in[0] + *fac * colorbalance(in[0], n->slope[0], n->offset[0], n->power[0]);
- out[1] = mfac*in[1] + *fac * colorbalance(in[1], n->slope[1], n->offset[1], n->power[1]);
- out[2] = mfac*in[2] + *fac * colorbalance(in[2], n->slope[2], n->offset[2], n->power[2]);
+ out[0] = mfac*in[0] + *fac * colorbalance_cdl(in[0], n->lift[0], n->gamma[0], n->gain[0]);
+ out[1] = mfac*in[1] + *fac * colorbalance_cdl(in[1], n->lift[1], n->gamma[1], n->gain[1]);
+ out[2] = mfac*in[2] + *fac * colorbalance_cdl(in[2], n->lift[2], n->gamma[2], n->gain[2]);
+ out[3] = in[3];
+}
+
+static void do_colorbalance_lgg(bNode *node, float* out, float *in)
+{
+ NodeColorBalance *n= (NodeColorBalance *)node->storage;
+
+ out[0] = colorbalance_lgg(in[0], n->lift[0], n->gamma[0], n->gain[0]);
+ out[1] = colorbalance_lgg(in[1], n->lift[1], n->gamma[1], n->gain[1]);
+ out[2] = colorbalance_lgg(in[2], n->lift[2], n->gamma[2], n->gain[2]);
+ out[3] = in[3];
+}
+
+static void do_colorbalance_lgg_fac(bNode *node, float* out, float *in, float *fac)
+{
+ NodeColorBalance *n= (NodeColorBalance *)node->storage;
+ const float mfac= 1.0f - *fac;
+
+ out[0] = mfac*in[0] + *fac * colorbalance_lgg(in[0], n->lift[0], n->gamma[0], n->gain[0]);
+ out[1] = mfac*in[1] + *fac * colorbalance_lgg(in[1], n->lift[1], n->gamma[1], n->gain[1]);
+ out[2] = mfac*in[2] + *fac * colorbalance_lgg(in[2], n->lift[2], n->gamma[2], n->gain[2]);
out[3] = in[3];
}
@@ -90,12 +122,24 @@ static void node_composit_exec_colorbalance(void *data, bNode *node, bNodeStack
if (cbuf) {
stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* create output based on image input */
-
- if ((in[0]->data==NULL) && (in[0]->vec[0] == 1.f)) {
- composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_colorbalance, CB_RGBA);
- }
- else {
- composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_colorbalance_fac, CB_RGBA, CB_VAL);
+
+ if (node->custom1 == 0) {
+ /* lift gamma gain */
+ if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) {
+ composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_colorbalance_lgg, CB_RGBA);
+ }
+ else {
+ composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_colorbalance_lgg_fac, CB_RGBA, CB_VAL);
+ }
+ } else {
+ /* offset/power/slope : ASC-CDL */
+ if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) {
+ composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_colorbalance_cdl, CB_RGBA);
+ }
+ else {
+ composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_colorbalance_cdl_fac, CB_RGBA, CB_VAL);
+ }
+
}
out[0]->data=stackbuf;
@@ -105,14 +149,10 @@ static void node_composit_exec_colorbalance(void *data, bNode *node, bNodeStack
static void node_composit_init_colorbalance(bNode *node)
{
NodeColorBalance *n= node->storage= MEM_callocN(sizeof(NodeColorBalance), "node colorbalance");
- n->slope[0] = n->slope[1] = n->slope[2] = 1.f;
- n->offset[0] = n->offset[1] = n->offset[2] = 0.f;
- n->power[0] = n->power[1] = n->power[2] = 1.f;
-
- /* for ui, converted to slope/offset/power in RNA */
- n->lift[0] = n->lift[1] = n->lift[2] = 0.5f;
- n->gamma[0] = n->gamma[1] = n->gamma[2] = 0.5f;
- n->gain[0] = n->gain[1] = n->gain[2] = 0.5f;
+
+ n->lift[0] = n->lift[1] = n->lift[2] = 0.0f;
+ n->gamma[0] = n->gamma[1] = n->gamma[2] = 1.0f;
+ n->gain[0] = n->gain[1] = n->gain[2] = 1.0f;
}
bNodeType cmp_node_colorbalance={