Color Balance Node

changes from sequencer applied to compositor mostly noticable is how the lift works.

Before & After,
http://www.graphicall.org/ftp/ideasman42/color_balance_before_after.png

even with lower values these kinds of errors can be seen.
This commit is contained in:
Campbell Barton 2010-07-05 14:29:16 +00:00
parent d89d1aa098
commit b1cdc52b30
4 changed files with 27 additions and 17 deletions

@ -1525,13 +1525,12 @@ static StripColorBalance calc_cb(StripColorBalance * cb_)
return cb; return cb;
} }
/* compiler should inline */ /* pow(p[c] * cb.gain[c] + cb.lift[c], cb.gamma[c]) * mul;*/
MINLINE float color_balance_fl(float v, float lift, float gain, float gamma, float mul) MINLINE float color_balance_fl(const float v, const float lift, const float gain, const float gamma, const float mul)
{ {
return pow(pow(v * gain, lift), gamma) * mul; return powf(powf(v * gain, lift), gamma) * mul;
} }
static void make_cb_table_byte(float lift, float gain, float gamma, static void make_cb_table_byte(float lift, float gain, float gamma,
unsigned char * table, float mul) unsigned char * table, float mul)
{ {

@ -311,6 +311,9 @@ typedef struct NodeColorBalance {
float lift[3]; float lift[3];
float gamma[3]; float gamma[3];
float gain[3]; float gain[3];
/* temp storage for inverted lift */
float lift_lgg[3];
} NodeColorBalance; } NodeColorBalance;
typedef struct NodeColorspill { typedef struct NodeColorspill {

@ -72,8 +72,8 @@ typedef struct StripColorBalance {
float gain[3]; float gain[3];
int flag; int flag;
int pad; int pad;
float exposure; // float exposure;
float saturation; // float saturation;
} StripColorBalance; } StripColorBalance;
typedef struct StripProxy { typedef struct StripProxy {

@ -56,8 +56,8 @@ DO_INLINE float colorbalance_cdl(float in, float offset, float power, float slop
DO_INLINE float colorbalance_lgg(float in, float lift, float gamma, float gain) DO_INLINE float colorbalance_lgg(float in, float lift, float gamma, float gain)
{ {
float x = gain*(in+(lift-1)*(1-in)); float x= powf(in * gain, lift);
/* prevent NaN */ /* prevent NaN */
if (x < 0.f) x = 0.f; if (x < 0.f) x = 0.f;
@ -88,10 +88,10 @@ static void do_colorbalance_cdl_fac(bNode *node, float* out, float *in, float *f
static void do_colorbalance_lgg(bNode *node, float* out, float *in) static void do_colorbalance_lgg(bNode *node, float* out, float *in)
{ {
NodeColorBalance *n= (NodeColorBalance *)node->storage; NodeColorBalance *n= (NodeColorBalance *)node->storage;
out[0] = colorbalance_lgg(in[0], n->lift[0], n->gamma[0], n->gain[0]); out[0] = colorbalance_lgg(in[0], n->lift_lgg[0], n->gamma[0], n->gain[0]);
out[1] = colorbalance_lgg(in[1], n->lift[1], n->gamma[1], n->gain[1]); out[1] = colorbalance_lgg(in[1], n->lift_lgg[1], n->gamma[1], n->gain[1]);
out[2] = colorbalance_lgg(in[2], n->lift[2], n->gamma[2], n->gain[2]); out[2] = colorbalance_lgg(in[2], n->lift_lgg[2], n->gamma[2], n->gain[2]);
out[3] = in[3]; out[3] = in[3];
} }
@ -99,10 +99,10 @@ static void do_colorbalance_lgg_fac(bNode *node, float* out, float *in, float *f
{ {
NodeColorBalance *n= (NodeColorBalance *)node->storage; NodeColorBalance *n= (NodeColorBalance *)node->storage;
const float mfac= 1.0f - *fac; 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[0] = mfac*in[0] + *fac * colorbalance_lgg(in[0], n->lift_lgg[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[1] = mfac*in[1] + *fac * colorbalance_lgg(in[1], n->lift_lgg[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[2] = mfac*in[2] + *fac * colorbalance_lgg(in[2], n->lift_lgg[2], n->gamma[2], n->gain[2]);
out[3] = in[3]; out[3] = in[3];
} }
@ -119,7 +119,15 @@ static void node_composit_exec_colorbalance(void *data, bNode *node, bNodeStack
out[0]->data = pass_on_compbuf(cbuf); out[0]->data = pass_on_compbuf(cbuf);
return; return;
} }
{
NodeColorBalance *n= (NodeColorBalance *)node->storage;
int c;
for (c = 0; c < 3; c++) {
n->lift_lgg[c] = 2.0f - pow(n->lift[c], 2);
}
}
if (cbuf) { if (cbuf) {
stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* create output based on image input */ stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* create output based on image input */