diff options
author | Matt Ebb <matt@mke3.net> | 2010-01-21 03:00:45 +0300 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2010-01-21 03:00:45 +0300 |
commit | 3e1783c715201320caf87b3660bd590892277ae2 (patch) | |
tree | e596e14a74f2fa86176c4bfd77b7b13326725c4e | |
parent | 946cdd8ff6ad6e799c1aeaea9540b599e9648476 (diff) |
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 :)
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 3 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 2 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 2 | ||||
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 10 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_draw.c | 20 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 8 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 6 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 198 | ||||
-rw-r--r-- | source/blender/editors/space_node/drawnode.c | 10 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 17 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree_types.h | 1 | ||||
-rw-r--r-- | source/blender/nodes/CMP_node.h | 1 | ||||
-rw-r--r-- | source/blender/nodes/intern/CMP_nodes/CMP_huecorrect.c | 162 |
15 files changed, 344 insertions, 99 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index fe20c4d8158..6d99d1848bf 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -355,6 +355,7 @@ void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat); #define CMP_NODE_VIEW_LEVELS 258 #define CMP_NODE_COLOR_MATTE 259 #define CMP_NODE_COLORBALANCE 260 +#define CMP_NODE_HUECORRECT 261 #define CMP_NODE_GLARE 301 #define CMP_NODE_TONEMAP 302 diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 874529d9965..e4bab3fbfa1 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1947,7 +1947,7 @@ static void composit_begin_exec(bNodeTree *ntree, int is_group) } } /* cannot initialize them while using in threads */ - if(ELEM3(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB)) { + if(ELEM4(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) { curvemapping_initialize(node->storage); if(node->type==CMP_NODE_CURVE_RGB) curvemapping_premultiply(node->storage, 0); @@ -2984,6 +2984,7 @@ static void registerCompositNodes(ListBase *ntypelist) nodeRegisterType(ntypelist, &cmp_node_alphaover); nodeRegisterType(ntypelist, &cmp_node_zcombine); nodeRegisterType(ntypelist, &cmp_node_colorbalance); + nodeRegisterType(ntypelist, &cmp_node_huecorrect); nodeRegisterType(ntypelist, &cmp_node_normal); nodeRegisterType(ntypelist, &cmp_node_curve_vec); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 5b75912aa2a..c8bcc43086e 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2102,7 +2102,7 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB)) direct_link_curvemapping(fd, node->storage); else if(ntree->type==NTREE_COMPOSIT) { - if( ELEM3(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB)) + if( ELEM4(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) direct_link_curvemapping(fd, node->storage); else if(ELEM3(node->type, CMP_NODE_IMAGE, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) ((ImageUser *)node->storage)->ok= 1; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index f7bd5a0af6b..8673d847f73 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -486,7 +486,7 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) /* could be handlerized at some point, now only 1 exception still */ if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB)) write_curvemapping(wd, node->storage); - else if(ntree->type==NTREE_COMPOSIT && (node->type==CMP_NODE_TIME || node->type==CMP_NODE_CURVE_VEC || node->type==CMP_NODE_CURVE_RGB)) + else if(ntree->type==NTREE_COMPOSIT && ELEM4(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) write_curvemapping(wd, node->storage); else if(ntree->type==NTREE_TEXTURE && (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) ) write_curvemapping(wd, node->storage); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 6c03b136775..34e8f5c8e13 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -220,6 +220,16 @@ typedef struct uiLayout uiLayout; #define BUTTYPE (63<<9) +/* gradient types, for color picker HSVCUBE etc */ +#define UI_GRAD_SV 0 +#define UI_GRAD_HV 1 +#define UI_GRAD_HS 2 +#define UI_GRAD_H 3 +#define UI_GRAD_S 4 +#define UI_GRAD_V 5 + +#define UI_GRAD_V_ALT 9 + /* Drawing * * Functions to draw various shapes, taking theme settings into account. diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 5946005dc6a..090f5d38279 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -1061,7 +1061,7 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect glColor3ubv((unsigned char*)wcol->inner); glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); } - + /* grid, every .25 step */ glColor3ubvShade(wcol->inner, -16); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f); @@ -1077,6 +1077,24 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymax); glEnd(); + /* magic trigger for curve backgrounds */ + if (but->a1 != -1) { + if (but->a1 == UI_GRAD_H) { + rcti grid; + float col[3]; + + grid.xmin = rect->xmin + zoomx*(-offsx); + grid.xmax = rect->xmax + zoomx*(-offsx); + grid.ymin = rect->ymin + zoomy*(-offsy); + grid.ymax = rect->ymax + zoomy*(-offsy); + + glEnable(GL_BLEND); + ui_draw_gradient(&grid, col, UI_GRAD_H, 0.5f); + glDisable(GL_BLEND); + } + } + + /* cfra option */ /* XXX 2.48 if(cumap->flag & CUMA_DRAW_CFRA) { diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 1851255fd3b..cd89650d750 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -430,6 +430,8 @@ extern void gl_round_box(int mode, float minx, float miny, float maxx, float max extern void gl_round_box_shade(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadetop, float shadedown); extern void gl_round_box_vertical_shade(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadeLeft, float shadeRight); +void ui_draw_gradient(rcti *rect, float *rgb, int type, float alpha); + void ui_draw_but_HISTOGRAM(uiBut *but, struct uiWidgetColors *wcol, rcti *rect); void ui_draw_but_COLORBAND(uiBut *but, struct uiWidgetColors *wcol, rcti *rect); void ui_draw_but_NORMAL(uiBut *but, struct uiWidgetColors *wcol, rcti *rect); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 5af1359cd01..cbc005c0f8e 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1696,7 +1696,7 @@ static void circle_picker(uiBlock *block, PointerRNA *ptr, const char *propname) uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); /* value */ - bt= uiDefButR(block, HSVCUBE, 0, "", PICKER_W+PICKER_SPACE,0,PICKER_BAR,PICKER_H, ptr, propname, -1, 0.0, 0.0, 9, 0, ""); + bt= uiDefButR(block, HSVCUBE, 0, "", PICKER_W+PICKER_SPACE,0,PICKER_BAR,PICKER_H, ptr, propname, -1, 0.0, 0.0, UI_GRAD_V_ALT, 0, ""); uiButSetFunc(bt, do_picker_rna_cb, bt, NULL); } @@ -1744,13 +1744,13 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR circle_picker(block, ptr, propname); break; case USER_CP_SQUARE_SV: - square_picker(block, ptr, propname, 0); + square_picker(block, ptr, propname, UI_GRAD_SV); break; case USER_CP_SQUARE_HS: - square_picker(block, ptr, propname, 1); + square_picker(block, ptr, propname, UI_GRAD_HS); break; case USER_CP_SQUARE_HV: - square_picker(block, ptr, propname, 2); + square_picker(block, ptr, propname, UI_GRAD_HV); break; } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 2c6bf5f2d3c..9e0d7da50a8 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -1804,6 +1804,7 @@ static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labe uiBut *bt; float dx= UI_UNIT_X; int icon, size; + int bg=-1; block= uiLayoutGetBlock(layout); @@ -1852,6 +1853,9 @@ static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labe } else uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); + + if (labeltype=='h') + bg = UI_GRAD_H; /* operation buttons */ sub= uiLayoutRow(row, 1); @@ -1885,7 +1889,7 @@ static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labe /* curve itself */ size= uiLayoutGetWidth(layout); row= uiLayoutRow(layout, 0); - uiDefBut(block, BUT_CURVE, 0, "", 0, 0, size, MIN2(size, 200), cumap, 0.0f, 1.0f, 0, 0, ""); + uiDefBut(block, BUT_CURVE, 0, "", 0, 0, size, MIN2(size, 200), cumap, 0.0f, 1.0f, bg, 0, ""); /* black/white levels */ if(levels) { diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index bbc07e06217..c84d53748c4 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -1607,65 +1607,58 @@ 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; - } - 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; + 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; } - /* old below */ for(dx=0.0; dx<1.0; dx+= 0.05) { @@ -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); diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 3323183cb54..95e7239b50e 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -935,6 +935,13 @@ static void node_composit_buts_colorbalance(uiLayout *layout, bContext *C, Point } +static void node_composit_buts_huecorrect(uiLayout *layout, bContext *C, PointerRNA *ptr) +{ + bNode *node= ptr->data; + + uiTemplateCurveMapping(layout, ptr, "mapping", 'h', 0, 0); +} + /* only once called */ static void node_composit_set_butfunc(bNodeType *ntype) { @@ -1070,6 +1077,9 @@ static void node_composit_set_butfunc(bNodeType *ntype) case CMP_NODE_COLORBALANCE: ntype->uifunc=node_composit_buts_colorbalance; break; + case CMP_NODE_HUECORRECT: + ntype->uifunc=node_composit_buts_huecorrect; + break; default: ntype->uifunc= NULL; } diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index d151e911a9c..fa14bea4228 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -305,10 +305,11 @@ static void rna_Node_colorbalance_update(Main *bmain, Scene *scene, PointerRNA * bNode *node= (bNode*)ptr->data; NodeColorBalance *ncb = node->storage; float lift[3], gamma[3], gain[3]; - float n_one[3] = {-1.f, -1.f, -1.f}; - mul_v3_v3fl(lift, ncb->lift, 2.f); - add_v3_v3(lift, n_one); + lift[0] = (ncb->lift[0] * 2.f - 1.f)*0.5f; + lift[1] = (ncb->lift[1] * 2.f - 1.f)*0.5f; + lift[2] = (ncb->lift[2] * 2.f - 1.f)*0.5f; + mul_v3_v3fl(gamma, ncb->gamma, 2.f); mul_v3_v3fl(gain, ncb->gain, 2.f); @@ -1905,7 +1906,17 @@ static void def_cmp_colorbalance(StructRNA *srna) RNA_def_property_ui_text(prop, "Gain", "Correction for Highlights"); RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_colorbalance_update"); } + +static void def_cmp_huecorrect(StructRNA *srna) +{ + PropertyRNA *prop; + prop = RNA_def_property(srna, "mapping", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "storage"); + RNA_def_property_struct_type(prop, "CurveMapping"); + RNA_def_property_ui_text(prop, "Mapping", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); +} /* -- Texture Nodes --------------------------------------------------------- */ diff --git a/source/blender/makesrna/intern/rna_nodetree_types.h b/source/blender/makesrna/intern/rna_nodetree_types.h index 936832221f9..73a1c23af50 100644 --- a/source/blender/makesrna/intern/rna_nodetree_types.h +++ b/source/blender/makesrna/intern/rna_nodetree_types.h @@ -108,6 +108,7 @@ DefNode( CompositorNode, CMP_NODE_VIEW_LEVELS, def_cmp_levels, "LEVEL DefNode( CompositorNode, CMP_NODE_COLOR_MATTE, def_cmp_color_matte, "COLOR_MATTE", ColorMatte, "Color Matte", "" ) DefNode( CompositorNode, CMP_NODE_DIST_MATTE, def_cmp_distance_matte, "DISTANCE_MATTE", DistanceMatte, "Distance Matte", "" ) DefNode( CompositorNode, CMP_NODE_COLORBALANCE, def_cmp_colorbalance, "COLORBALANCE", ColorBalance, "Color Balance", "" ) +DefNode( CompositorNode, CMP_NODE_HUECORRECT, def_cmp_huecorrect, "HUECORRECT", HueCorrect, "Hue Correct", "" ) DefNode( TextureNode, TEX_NODE_OUTPUT, def_tex_output, "OUTPUT", Output, "Output", "" ) DefNode( TextureNode, TEX_NODE_CHECKER, 0, "CHECKER", Checker, "Checker", "" ) diff --git a/source/blender/nodes/CMP_node.h b/source/blender/nodes/CMP_node.h index 8c3f4f4a847..7bea141de64 100644 --- a/source/blender/nodes/CMP_node.h +++ b/source/blender/nodes/CMP_node.h @@ -60,6 +60,7 @@ extern bNodeType cmp_node_invert; extern bNodeType cmp_node_alphaover; extern bNodeType cmp_node_zcombine; extern bNodeType cmp_node_colorbalance; +extern bNodeType cmp_node_huecorrect; extern bNodeType cmp_node_normal; extern bNodeType cmp_node_curve_vec; diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_huecorrect.c b/source/blender/nodes/intern/CMP_nodes/CMP_huecorrect.c new file mode 100644 index 00000000000..bda327e07e7 --- /dev/null +++ b/source/blender/nodes/intern/CMP_nodes/CMP_huecorrect.c @@ -0,0 +1,162 @@ +/** + * $Id: CMP_curves.c 18313 2009-01-04 14:14:06Z ton $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2006 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Matt Ebb + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "../CMP_util.h" + +static bNodeSocketType cmp_node_huecorrect_in[]= { + { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, + { SOCK_RGBA, 1, "Image", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, + { -1, 0, "" } +}; + +static bNodeSocketType cmp_node_huecorrect_out[]= { + { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, + { -1, 0, "" } +}; + +static void do_huecorrect(bNode *node, float *out, float *in) +{ + float hsv[3], f; + + rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2); + + /* returns default 0.5 */ + f = curvemapping_evaluateF(node->storage, 0, hsv[0]); + + /* adjust saturation, scaling up to 1 */ + hsv[1] *= (f * 2.f); + + CLAMP(hsv[1], 0.f, 1.f); + + /* convert back to rgb */ + hsv_to_rgb(hsv[0], hsv[1], hsv[2], out, out+1, out+2); + + out[3]= in[3]; +} + +static void do_huecorrect_fac(bNode *node, float *out, float *in, float *fac) +{ + float hsv[3], rgb[3], f; + const float mfac = 1.f-*fac; + + rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2); + + /* returns default 0.5 */ + f = curvemapping_evaluateF(node->storage, 0, hsv[0]); + + /* adjust saturation, scaling up to 1 */ + hsv[1] *= (f * 2.f); + + CLAMP(hsv[1], 0.f, 1.f); + + /* convert back to rgb */ + hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); + + out[0]= mfac*in[0] + *fac*rgb[0]; + out[1]= mfac*in[1] + *fac*rgb[1]; + out[2]= mfac*in[2] + *fac*rgb[2]; + out[3]= in[3]; +} + +static void node_composit_exec_huecorrect(void *data, bNode *node, bNodeStack **in, bNodeStack **out) +{ + CompBuf *cbuf= in[1]->data; + CompBuf *stackbuf; + + /* stack order input: fac, image, black level, white level */ + /* stack order output: image */ + + if(out[0]->hasoutput==0) + return; + + if(in[0]->vec[0] == 0.f && in[0]->data == NULL) { + out[0]->data = pass_on_compbuf(cbuf); + return; + } + + /* input no image? then only color operation */ + if(in[1]->data==NULL) { + do_huecorrect_fac(node, out[0]->vec, in[1]->vec, in[0]->vec); + } + + if (cbuf) { + stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); /* make output size of input image */ + + if ((in[0]->data==NULL) && (in[0]->vec[0] >= 1.f)) + composit1_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, do_huecorrect, CB_RGBA); + else + composit2_pixel_processor(node, stackbuf, in[1]->data, in[1]->vec, in[0]->data, in[0]->vec, do_huecorrect_fac, CB_RGBA, CB_VAL); + + out[0]->data= stackbuf; + } + +} + +static void node_composit_init_huecorrect(bNode* node) +{ + CurveMapping *cumapping = node->storage= curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + CurveMap *cuma = &cumapping->cm[0]; + int i; + + /* set default horizontal curve */ + if(cuma->curve) + MEM_freeN(cuma->curve); + + cuma->totpoint= 9; + cuma->curve= MEM_callocN(cuma->totpoint*sizeof(CurveMapPoint), "curve points"); + + for (i=0; i < cuma->totpoint; i++) + { + cuma->curve[i].x= i / ((float)cuma->totpoint-1); + cuma->curve[i].y= 0.5; + } + + if(cuma->table) { + MEM_freeN(cuma->table); + cuma->table= NULL; + } +} + +bNodeType cmp_node_huecorrect= { + /* *next,*prev */ NULL, NULL, + /* type code */ CMP_NODE_HUECORRECT, + /* name */ "Hue Correct", + /* width+range */ 320, 140, 400, + /* class+opts */ NODE_CLASS_OP_COLOR, NODE_OPTIONS, + /* input sock */ cmp_node_huecorrect_in, + /* output sock */ cmp_node_huecorrect_out, + /* storage */ "CurveMapping", + /* execfunc */ node_composit_exec_huecorrect, + /* butfunc */ NULL, + /* initfunc */ node_composit_init_huecorrect, + /* freestoragefunc */ node_free_curves, + /* copystoragefunc */ node_copy_curves, + /* id */ NULL +}; + |