New Compositor node: Hue Control

Was very quick to do, now re-aquainted with node editor.

http://mke3.net/blender/devel/2.5/hue_correct_node.jpg

Todo: modes for affecting hue and value on the vertical axis as well as just saturation - or if an enterprising coder wants to give it a go, let me know and 
I can help :)
This commit is contained in:
2010-01-21 00:00:45 +00:00
parent 946cdd8ff6
commit 3e1783c715
15 changed files with 344 additions and 99 deletions

View File

@@ -1607,64 +1607,57 @@ void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
/* ************ custom buttons, old stuff ************** */
/* draws in resolution of 20x4 colors */
static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
void ui_draw_gradient(rcti *rect, float *rgb, int type, float alpha)
{
int a;
float rgb[3], h,s,v;
float dx, dy, sx1, sx2, sy, x=0.0f, y=0.0f;
float h, s, v;
float dx, dy, sx1, sx2, sy;
float col0[4][3]; // left half, rect bottom to top
float col1[4][3]; // right half, rect bottom to top
ui_get_but_vectorf(but, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], &h, &s, &v);
/* draw series of gouraud rects */
glShadeModel(GL_SMOOTH);
if(but->a1==0) { // S and V vary
hsv_to_rgb(h, 0.0, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(h, 1.0, 0.0, &col1[3][0], &col1[3][1], &col1[3][2]);
x= v; y= s;
switch(type) {
case UI_GRAD_SV:
hsv_to_rgb(h, 0.0, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(h, 1.0, 0.0, &col1[3][0], &col1[3][1], &col1[3][2]);
break;
case UI_GRAD_HV:
hsv_to_rgb(0.0, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(0.0, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(0.0, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(0.0, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]);
break;
case UI_GRAD_HS:
hsv_to_rgb(0.0, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(0.0, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(0.0, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(0.0, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
break;
case UI_GRAD_H:
hsv_to_rgb(0.0, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
VECCOPY(col1[1], col1[0]);
VECCOPY(col1[2], col1[0]);
VECCOPY(col1[3], col1[0]);
break;
case UI_GRAD_S:
hsv_to_rgb(1.0, 0.0, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]);
VECCOPY(col1[0], col1[1]);
VECCOPY(col1[2], col1[1]);
VECCOPY(col1[3], col1[1]);
break;
case UI_GRAD_V:
hsv_to_rgb(1.0, 1.0, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
VECCOPY(col1[0], col1[2]);
VECCOPY(col1[1], col1[2]);
VECCOPY(col1[3], col1[2]);
break;
}
else if(but->a1==1) { // H and V vary
hsv_to_rgb(0.0, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(0.0, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(0.0, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(0.0, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]);
x= h; y= v;
}
else if(but->a1==2) { // H and S vary
hsv_to_rgb(0.0, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(0.0, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(0.0, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(0.0, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
x= h; y= s;
}
else if(but->a1==3) { // only H
hsv_to_rgb(0.0, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
VECCOPY(col1[1], col1[0]);
VECCOPY(col1[2], col1[0]);
VECCOPY(col1[3], col1[0]);
x= h; y= 0.5;
}
else if(but->a1==4) { // only S
hsv_to_rgb(1.0, 0.0, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]);
VECCOPY(col1[0], col1[1]);
VECCOPY(col1[2], col1[1]);
VECCOPY(col1[3], col1[1]);
x= s; y= 0.5;
}
else if(but->a1==5) { // only V
hsv_to_rgb(1.0, 1.0, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
VECCOPY(col1[0], col1[2]);
VECCOPY(col1[1], col1[2]);
VECCOPY(col1[3], col1[2]);
x= v; y= 0.5;
}
/* old below */
@@ -1676,41 +1669,43 @@ static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
VECCOPY(col0[3], col1[3]);
// new color
if(but->a1==0) { // S and V vary
hsv_to_rgb(h, 0.0, dx, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(h, 1.0, dx, &col1[3][0], &col1[3][1], &col1[3][2]);
}
else if(but->a1==1) { // H and V vary
hsv_to_rgb(dx, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(dx, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(dx, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(dx, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]);
}
else if(but->a1==2) { // H and S vary
hsv_to_rgb(dx, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(dx, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(dx, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(dx, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
}
else if(but->a1==3) { // only H
hsv_to_rgb(dx, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
VECCOPY(col1[1], col1[0]);
VECCOPY(col1[2], col1[0]);
VECCOPY(col1[3], col1[0]);
}
else if(but->a1==4) { // only S
hsv_to_rgb(h, dx, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]);
VECCOPY(col1[0], col1[1]);
VECCOPY(col1[2], col1[1]);
VECCOPY(col1[3], col1[1]);
}
else if(but->a1==5) { // only V
hsv_to_rgb(h, 1.0, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
VECCOPY(col1[0], col1[2]);
VECCOPY(col1[1], col1[2]);
VECCOPY(col1[3], col1[2]);
switch(type) {
case UI_GRAD_SV:
hsv_to_rgb(h, 0.0, dx, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(h, 1.0, dx, &col1[3][0], &col1[3][1], &col1[3][2]);
break;
case UI_GRAD_HV:
hsv_to_rgb(dx, s, 0.0, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(dx, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(dx, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(dx, s, 1.0, &col1[3][0], &col1[3][1], &col1[3][2]);
break;
case UI_GRAD_HS:
hsv_to_rgb(dx, 0.0, v, &col1[0][0], &col1[0][1], &col1[0][2]);
hsv_to_rgb(dx, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
hsv_to_rgb(dx, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
hsv_to_rgb(dx, 1.0, v, &col1[3][0], &col1[3][1], &col1[3][2]);
break;
case UI_GRAD_H:
hsv_to_rgb(dx, 1.0, 1.0, &col1[0][0], &col1[0][1], &col1[0][2]);
VECCOPY(col1[1], col1[0]);
VECCOPY(col1[2], col1[0]);
VECCOPY(col1[3], col1[0]);
break;
case UI_GRAD_S:
hsv_to_rgb(h, dx, 1.0, &col1[1][0], &col1[1][1], &col1[1][2]);
VECCOPY(col1[0], col1[1]);
VECCOPY(col1[2], col1[1]);
VECCOPY(col1[3], col1[1]);
break;
case UI_GRAD_V:
hsv_to_rgb(h, 1.0, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
VECCOPY(col1[0], col1[2]);
VECCOPY(col1[1], col1[2]);
VECCOPY(col1[3], col1[2]);
break;
}
// rect
@@ -1721,16 +1716,16 @@ static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
glBegin(GL_QUADS);
for(a=0; a<3; a++, sy+=dy) {
glColor3fv(col0[a]);
glColor4f(col0[a][0], col0[a][1], col0[a][2], alpha);
glVertex2f(sx1, sy);
glColor3fv(col1[a]);
glColor4f(col1[a][0], col1[a][1], col1[a][2], alpha);
glVertex2f(sx2, sy);
glColor3fv(col1[a+1]);
glColor4f(col1[a+1][0], col1[a+1][1], col1[a+1][2], alpha);
glVertex2f(sx2, sy+dy);
glColor3fv(col0[a+1]);
glColor4f(col0[a+1][0], col0[a+1][1], col0[a+1][2], alpha);
glVertex2f(sx1, sy+dy);
}
glEnd();
@@ -1738,6 +1733,35 @@ static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
glShadeModel(GL_FLAT);
}
static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
{
float rgb[3], h,s,v;
float x=0.0f, y=0.0f;
ui_get_but_vectorf(but, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], &h, &s, &v);
ui_draw_gradient(rect, rgb, but->a1, 1.f);
switch((int)but->a1) {
case UI_GRAD_SV:
x= v; y= s; break;
case UI_GRAD_HV:
x= h; y= v; break;
case UI_GRAD_HS:
x= h; y= s; break;
case UI_GRAD_H:
x= h; y= 0.5; break;
case UI_GRAD_S:
x= s; y= 0.5; break;
case UI_GRAD_V:
x= v; y= 0.5; break;
}
/* cursor */
x= rect->xmin + x*(rect->xmax-rect->xmin);
y= rect->ymin + y*(rect->ymax-rect->ymin);