forked from bartvdbraak/blender
Fixed bug in normalition of YCbCr color space conversion (from 0..1 to
-1..1) to fix errors in keying. Simplified chroma key to not take despill into consideration (handled elsewhere). Simplified user interface for pieces not used.
This commit is contained in:
parent
247a406027
commit
e9683f4b26
@ -823,9 +823,9 @@ static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *C, Point
|
||||
uiItemR(col, ptr, "cutoff", 0, NULL, 0);
|
||||
|
||||
col= uiLayoutColumn(layout, 1);
|
||||
uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, 0);
|
||||
/*uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, NULL, 0); Removed for now */
|
||||
uiItemR(col, ptr, "gain", UI_ITEM_R_SLIDER, NULL, 0);
|
||||
uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, 0);
|
||||
/*uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, NULL, 0); Removed for now*/
|
||||
}
|
||||
|
||||
static void node_composit_buts_color_matte(uiLayout *layout, bContext *C, PointerRNA *ptr)
|
||||
|
@ -44,20 +44,38 @@ static bNodeSocketType cmp_node_chroma_out[]={
|
||||
|
||||
static void do_rgba_to_ycca_normalized(bNode *node, float *out, float *in)
|
||||
{
|
||||
/*normalize to the range -1.0 to 1.0) */
|
||||
rgb_to_ycc(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
|
||||
out[0]=((out[0])-16)/255.0;
|
||||
out[1]=((out[1])-128)/255.0;
|
||||
out[2]=((out[2])-128)/255.0;
|
||||
rgb_to_ycc(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
|
||||
|
||||
//normalize to 0..1.0
|
||||
out[0]=out[0]/255.0;
|
||||
out[1]=out[1]/255.0;
|
||||
out[2]=out[2]/255.0;
|
||||
|
||||
//rescale to -1.0..1.0
|
||||
out[0]=(out[0]*2.0)-1.0;
|
||||
out[1]=(out[1]*2.0)-1.0;
|
||||
out[2]=(out[2]*2.0)-1.0;
|
||||
|
||||
// out[0]=((out[0])-16)/255.0;
|
||||
// out[1]=((out[1])-128)/255.0;
|
||||
// out[2]=((out[2])-128)/255.0;
|
||||
out[3]=in[3];
|
||||
}
|
||||
|
||||
static void do_ycca_to_rgba_normalized(bNode *node, float *out, float *in)
|
||||
{
|
||||
/*un-normalize the normalize from above */
|
||||
in[0]=(in[0]*255.0)+16;
|
||||
in[1]=(in[1]*255.0)+128;
|
||||
in[2]=(in[2]*255.0)+128;
|
||||
/*un-normalize the normalize from above */
|
||||
in[0]=(in[0]+1.0)/2.0;
|
||||
in[1]=(in[1]+1.0)/2.0;
|
||||
in[2]=(in[2]+1.0)/2.0;
|
||||
|
||||
in[0]=(in[0]*255.0);
|
||||
in[1]=(in[1]*255.0);
|
||||
in[2]=(in[2]*255.0);
|
||||
|
||||
// in[0]=(in[0]*255.0)+16;
|
||||
// in[1]=(in[1]*255.0)+128;
|
||||
// in[2]=(in[2]*255.0)+128;
|
||||
ycc_to_rgb(in[0],in[1],in[2], &out[0], &out[1], &out[2], BLI_YCC_ITU_BT601);
|
||||
out[3]=in[3];
|
||||
}
|
||||
@ -65,47 +83,41 @@ static void do_ycca_to_rgba_normalized(bNode *node, float *out, float *in)
|
||||
static void do_chroma_key(bNode *node, float *out, float *in)
|
||||
{
|
||||
NodeChroma *c;
|
||||
float x, z, alpha;
|
||||
float theta, beta, angle;
|
||||
float kfg, newY, newCb, newCr;
|
||||
float x, z, kx, kz, alpha;
|
||||
float theta, beta, angle, angle2;
|
||||
float kfg, newY, newCb, newCr;
|
||||
|
||||
c=node->storage;
|
||||
|
||||
/* Algorithm from book "Video Demistified" */
|
||||
/* Algorithm from book "Video Demistified," does not include the spill reduction part */
|
||||
|
||||
/* find theta, the angle that the color space should be rotated based on key*/
|
||||
theta=atan2(c->key[2],c->key[1]);
|
||||
theta=atan2(c->key[2], c->key[1]);
|
||||
|
||||
/*rotate the cb and cr into x/z space */
|
||||
x=in[1]*cos(theta)+in[2]*sin(theta);
|
||||
z=in[2]*cos(theta)-in[1]*sin(theta);
|
||||
x=in[1]*cos(theta)+in[2]*sin(theta);
|
||||
z=in[2]*cos(theta)-in[1]*sin(theta);
|
||||
|
||||
/*if within the acceptance angle */
|
||||
angle=c->t1*M_PI/180.0; /* convert to radians */
|
||||
/*if within the acceptance angle */
|
||||
angle=c->t1*M_PI/180.0; /* convert to radians */
|
||||
|
||||
/* if kfg is <0 then the pixel is outside of the key color */
|
||||
kfg=x-(fabs(z)/tan(angle/2.0));
|
||||
/* if kfg is <0 then the pixel is outside of the key color */
|
||||
kfg=x-(fabs(z)/tan(angle/2.0));
|
||||
|
||||
if(kfg>0.0) { /* found a pixel that is within key color */
|
||||
out[0]=in[0];
|
||||
out[1]=in[1];
|
||||
out[2]=in[2];
|
||||
|
||||
newY=in[0]-(1-c->t3)*kfg;
|
||||
newCb=in[1]-kfg*cos((double)theta);
|
||||
newCr=in[2]-kfg*sin((double)theta);
|
||||
alpha=(kfg+c->fsize)*(c->fstrength);
|
||||
if(kfg>0.0) { /* found a pixel that is within key color */
|
||||
alpha=(1.0-kfg)*(c->fstrength);
|
||||
|
||||
beta=atan2(newCr,newCb);
|
||||
beta=beta*180.0/M_PI; /* convert to degrees for compare*/
|
||||
beta=atan2(z,x);
|
||||
angle2=c->t2*M_PI/180.0;
|
||||
|
||||
/* if beta is within the clippin angle */
|
||||
if(fabs(beta)<(c->t2/2.0)) {
|
||||
newCb=0.0;
|
||||
newCr=0.0;
|
||||
alpha=0.0;
|
||||
}
|
||||
|
||||
out[0]=newY;
|
||||
out[1]=newCb;
|
||||
out[2]=newCr;
|
||||
/* if beta is within the cutoff angle */
|
||||
if(fabs(beta)<(angle2/2.0)) {
|
||||
alpha=0.0;
|
||||
}
|
||||
|
||||
/* don't make something that was more transparent less transparent */
|
||||
if (alpha<in[3]) {
|
||||
|
@ -64,7 +64,7 @@ static void node_composit_exec_sephsva(void *data, bNode *node, bNodeStack **in,
|
||||
if(in[0]->data==NULL) {
|
||||
float h, s, v;
|
||||
|
||||
rgb_to_hsv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &h, &s, &v);
|
||||
rgb_to_hsv(in[0]->vec[0], in[0]->vec[1], in[0]->vec[2], &h, &s, &v);
|
||||
|
||||
out[0]->vec[0] = h;
|
||||
out[1]->vec[0] = s;
|
||||
|
Loading…
Reference in New Issue
Block a user