New Compositor node: Hue Control
authorMatt Ebb <matt@mke3.net>
Thu, 21 Jan 2010 00:00:45 +0000 (00:00 +0000)
committerMatt Ebb <matt@mke3.net>
Thu, 21 Jan 2010 00:00:45 +0000 (00:00 +0000)
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 :)

15 files changed:
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_draw.c
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_regions.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/interface_widgets.c
source/blender/editors/space_node/drawnode.c
source/blender/makesrna/intern/rna_nodetree.c
source/blender/makesrna/intern/rna_nodetree_types.h
source/blender/nodes/CMP_node.h
source/blender/nodes/intern/CMP_nodes/CMP_huecorrect.c [new file with mode: 0644]

index fe20c4d8158f5ede47767a1a7ab4e16f21ad8cd4..6d99d1848bf480747beca7844ec4c4cbfff5f712 100644 (file)
@@ -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
index 874529d9965418065ec0f857338d4c476c8a04c8..e4bab3fbfa1ab7c591fef1d118c17388591888f3 100644 (file)
@@ -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);
index 5b75912aa2a9e289a2ef98745c8a7dc0c5d7f1bc..c8bcc43086ee003c1faebce67883b8558d2e5ceb 100644 (file)
@@ -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;
index f7bd5a0af6bc6e4524ca7f9ac1e4d893b918dbe2..8673d847f73ee8494c21197df61b934d34d80ce7 100644 (file)
@@ -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);
index 6c03b136775410ad16aad6c19d2e33ca4d385a76..34e8f5c8e139299f3aff0449f175b430a60449ae 100644 (file)
@@ -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.
index 5946005dc6a64284fc0c9eb4968d8a6f69083efb..090f5d38279310cb5c64a94d0df6dd40c2d4c905 100644 (file)
@@ -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) {
index 1851255fd3badf4c2efe57b299efb6547ef86784..cd89650d750001d38d0def36ec5902816957008f 100644 (file)
@@ -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);
index 5af1359cd01f2ee661bbfd66f58c17f1b5b82fba..cbc005c0f8e02b7fd67821dee1369129fb9a5f80 100644 (file)
@@ -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;
        }
        
index 2c6bf5f2d3c8821438111c7f8954632dd8604df9..9e0d7da50a8de0482cc511cb44f6f309918607bc 100644 (file)
@@ -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) {
index bbc07e06217bb2878c29ec6fa5e85c9785482948..c84d53748c46aee4846033b3b509c014806c99cf 100644 (file)
@@ -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);
index 3323183cb542638a6af1ab833def13d539de0bdc..95e7239b50e7ea53b6f17cedd592d9df5e5bb541 100644 (file)
@@ -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;
        }
index d151e911a9ccb6e0e12a8275786794a11c8c7e99..fa14bea42286607a529e3a5517a1bdaabebf7771 100644 (file)
@@ -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 --------------------------------------------------------- */
index 936832221f981b9a1b3e0cb0516ba1f0f7152204..73a1c23af50e54418db805981a64dc28004a3ad6 100644 (file)
@@ -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",           ""              )
index 8c3f4f4a847587f51de9ecc04878a5f5582d6ac8..7bea141de64e82eb6f8ec09e5ca4c3b707d33cda 100644 (file)
@@ -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 (file)
index 0000000..bda327e
--- /dev/null
@@ -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
+};
+