Compositor: Make HSV node inputs a real sockets
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 7 Dec 2016 12:52:12 +0000 (13:52 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 26 Jan 2017 14:20:13 +0000 (15:20 +0100)
This is much more flexible solution which will allow doing some
more procedural features.

Reviewers: brecht, dfelinto, mont29

Reviewed By: mont29

Subscribers: Severin

Differential Revision: https://developer.blender.org/D2403

source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/readfile.h
source/blender/blenloader/intern/versioning_270.c
source/blender/compositor/nodes/COM_HueSaturationValueNode.cpp
source/blender/compositor/operations/COM_ChangeHSVOperation.cpp
source/blender/compositor/operations/COM_ChangeHSVOperation.h
source/blender/editors/space_node/drawnode.c
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.c
source/blender/nodes/NOD_static_types.h
source/blender/nodes/composite/nodes/node_composite_hueSatVal.c

index 4396fa218b62ba920a1c247babd1b3dc5f1e91d7..dce079ff20d17b38f4b21d538bf9a38ac5b13c81 100644 (file)
@@ -8393,9 +8393,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
 
 static void do_versions_after_linking(Main *main)
 {
-       UNUSED_VARS(main);
 //     printf("%s for %s (%s), %d.%d\n", __func__, main->curlib ? main->curlib->name : main->name,
 //            main->curlib ? "LIB" : "MAIN", main->versionfile, main->subversionfile);
+
+       do_versions_after_linking_270(main);
 }
 
 static void lib_link_all(FileData *fd, Main *main)
index 7719aaa2b0d13ce0c0625c46f1e3243828ca9645..d97bef13a787ff7243ab0ba46421af4740652a98 100644 (file)
@@ -170,5 +170,7 @@ void blo_do_versions_250(struct FileData *fd, struct Library *lib, struct Main *
 void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main *main);
 void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *main);
 
+void do_versions_after_linking_270(struct Main *main);
+
 #endif
 
index 805542c35a6963f1712f811c51c83265595ca241..c9ea077e6f675350d5f37eb308107e267ebb8628 100644 (file)
@@ -34,6 +34,7 @@
 /* allow readfile to use deprecated functionality */
 #define DNA_DEPRECATED_ALLOW
 
+#include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_brush_types.h"
 #include "DNA_camera_types.h"
@@ -58,6 +59,7 @@
 
 #include "DNA_genfile.h"
 
+#include "BKE_animsys.h"
 #include "BKE_colortools.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
@@ -76,6 +78,9 @@
 
 #include "BLO_readfile.h"
 
+#include "NOD_common.h"
+#include "NOD_socket.h"
+
 #include "readfile.h"
 
 #include "MEM_guardedalloc.h"
@@ -195,6 +200,50 @@ static void do_version_bones_super_bbone(ListBase *lb)
        }
 }
 
+/* TODO(sergey): Consider making it somewhat more generic function in BLI_anim.h. */
+static void anim_change_prop_name(FCurve *fcu,
+                                  const char *prefix,
+                                  const char *old_prop_name,
+                                  const char *new_prop_name)
+{
+       const char *old_path = BLI_sprintfN("%s.%s", prefix, old_prop_name);
+       if (STREQ(fcu->rna_path, old_path)) {
+               MEM_freeN(fcu->rna_path);
+               fcu->rna_path = BLI_sprintfN("%s.%s", prefix, new_prop_name);
+       }
+       MEM_freeN((char *)old_path);
+}
+
+static void do_version_hue_sat_node(bNodeTree *ntree, bNode *node)
+{
+       /* Make sure new sockets are properly created. */
+       node_verify_socket_templates(ntree, node);
+       /* Convert value from old storage to new sockets. */
+       NodeHueSat *nhs = node->storage;
+       bNodeSocket *hue = nodeFindSocket(node, SOCK_IN, "Hue"),
+                   *saturation = nodeFindSocket(node, SOCK_IN, "Saturation"),
+                   *value = nodeFindSocket(node, SOCK_IN, "Value");
+       ((bNodeSocketValueFloat *)hue->default_value)->value = nhs->hue;
+       ((bNodeSocketValueFloat *)saturation->default_value)->value = nhs->sat;
+       ((bNodeSocketValueFloat *)value->default_value)->value = nhs->val;
+       /* Take care of possible animation. */
+       AnimData *adt = BKE_animdata_from_id(&ntree->id);
+       if (adt != NULL && adt->action != NULL) {
+               const char *prefix = BLI_sprintfN("nodes[\"%s\"]", node->name);
+               for (FCurve *fcu = adt->action->curves.first; fcu != NULL; fcu = fcu->next) {
+                       if (STRPREFIX(fcu->rna_path, prefix)) {
+                               anim_change_prop_name(fcu, prefix, "color_hue", "inputs[1].default_value");
+                               anim_change_prop_name(fcu, prefix, "color_saturation", "inputs[2].default_value");
+                               anim_change_prop_name(fcu, prefix, "color_value", "inputs[3].default_value");
+                       }
+               }
+               MEM_freeN((char *)prefix);
+       }
+       /* Free storage, it is no longer used. */
+       MEM_freeN(node->storage);
+       node->storage = NULL;
+}
+
 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 {
        if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
@@ -1521,5 +1570,23 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                                }
                        }
                }
+
+       }
+}
+
+void do_versions_after_linking_270(Main *main)
+{
+       /* To be added to next subversion bump! */
+       {
+               FOREACH_NODETREE(main, ntree, id) {
+                       if (ntree->type == NTREE_COMPOSIT) {
+                               ntreeSetTypes(NULL, ntree);
+                               for (bNode *node = ntree->nodes.first; node; node = node->next) {
+                                       if (node->type == CMP_NODE_HUE_SAT) {
+                                               do_version_hue_sat_node(ntree, node);
+                                       }
+                               }
+                       }
+               } FOREACH_NODETREE_END
        }
 }
index 29c296a896d096f22fa34c195421fb468f3336cb..b8971fffe3e64881b20f4ebc01c8b635c9298da3 100644 (file)
@@ -37,8 +37,11 @@ HueSaturationValueNode::HueSaturationValueNode(bNode *editorNode) : Node(editorN
 
 void HueSaturationValueNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const
 {
-       NodeInput *valueSocket = this->getInputSocket(0);
-       NodeInput *colorSocket = this->getInputSocket(1);
+       NodeInput *colorSocket = this->getInputSocket(0);
+       NodeInput *hueSocket = this->getInputSocket(1);
+       NodeInput *saturationSocket = this->getInputSocket(2);
+       NodeInput *valueSocket = this->getInputSocket(3);
+       NodeInput *facSocket = this->getInputSocket(4);
        NodeOutput *outputSocket = this->getOutputSocket(0);
        bNode *editorsnode = getbNode();
        NodeHueSat *storage = (NodeHueSat *)editorsnode->storage;
@@ -50,9 +53,9 @@ void HueSaturationValueNode::convertToOperations(NodeConverter &converter, const
        converter.addOperation(hsvToRGB);
        
        ChangeHSVOperation *changeHSV = new ChangeHSVOperation();
-       changeHSV->setHue(storage->hue);
-       changeHSV->setSaturation(storage->sat);
-       changeHSV->setValue(storage->val);
+       converter.mapInputSocket(hueSocket, changeHSV->getInputSocket(1));
+       converter.mapInputSocket(saturationSocket, changeHSV->getInputSocket(2));
+       converter.mapInputSocket(valueSocket, changeHSV->getInputSocket(3));
        converter.addOperation(changeHSV);
        
        MixBlendOperation *blend = new MixBlendOperation();
@@ -64,6 +67,6 @@ void HueSaturationValueNode::convertToOperations(NodeConverter &converter, const
        converter.addLink(changeHSV->getOutputSocket(), hsvToRGB->getInputSocket(0));
        converter.addLink(hsvToRGB->getOutputSocket(), blend->getInputSocket(2));
        converter.mapInputSocket(colorSocket, blend->getInputSocket(1));
-       converter.mapInputSocket(valueSocket, blend->getInputSocket(0));
+       converter.mapInputSocket(facSocket, blend->getInputSocket(0));
        converter.mapOutputSocket(outputSocket, blend->getOutputSocket());
 }
index 964f1d6466797d14b5619c0ec234c1c198c13981..7ea974a41dc8db37ef729f3f64e8eed62a0a7dd2 100644 (file)
@@ -25,6 +25,9 @@
 ChangeHSVOperation::ChangeHSVOperation() : NodeOperation()
 {
        this->addInputSocket(COM_DT_COLOR);
+       this->addInputSocket(COM_DT_VALUE);
+       this->addInputSocket(COM_DT_VALUE);
+       this->addInputSocket(COM_DT_VALUE);
        this->addOutputSocket(COM_DT_COLOR);
        this->m_inputOperation = NULL;
 }
@@ -32,24 +35,34 @@ ChangeHSVOperation::ChangeHSVOperation() : NodeOperation()
 void ChangeHSVOperation::initExecution()
 {
        this->m_inputOperation = getInputSocketReader(0);
+       this->m_hueOperation = getInputSocketReader(1);
+       this->m_saturationOperation = getInputSocketReader(2);
+       this->m_valueOperation = getInputSocketReader(3);
 }
 
 void ChangeHSVOperation::deinitExecution()
 {
        this->m_inputOperation = NULL;
+       this->m_hueOperation = NULL;
+       this->m_saturationOperation = NULL;
+       this->m_valueOperation = NULL;
 }
 
 void ChangeHSVOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
 {
        float inputColor1[4];
+       float hue[4], saturation[4], value[4];
        
        this->m_inputOperation->readSampled(inputColor1, x, y, sampler);
+       this->m_hueOperation->readSampled(hue, x, y, sampler);
+       this->m_saturationOperation->readSampled(saturation, x, y, sampler);
+       this->m_valueOperation->readSampled(value, x, y, sampler);
        
-       output[0] = inputColor1[0] + (this->m_hue - 0.5f);
+       output[0] = inputColor1[0] + (hue[0] - 0.5f);
        if      (output[0] > 1.0f) output[0] -= 1.0f;
        else if (output[0] < 0.0f) output[0] += 1.0f;
-       output[1] = inputColor1[1] * this->m_saturation;
-       output[2] = inputColor1[2] * this->m_value;
+       output[1] = inputColor1[1] * saturation[0];
+       output[2] = inputColor1[2] * value[0];
        output[3] = inputColor1[3];
 }
 
index 76025e86b7a013215cf63fe38f1a3fdec34605b9..800c09c05ffae0fe59c79d242e0fada4eb12867e 100644 (file)
 class ChangeHSVOperation : public NodeOperation {
 private:
        SocketReader *m_inputOperation;
-
-       float m_hue;
-       float m_saturation;
-       float m_value;
+       SocketReader *m_hueOperation;
+       SocketReader *m_saturationOperation;
+       SocketReader *m_valueOperation;
 
 public:
        /**
@@ -51,9 +50,5 @@ public:
         */
        void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
 
-       void setHue(float hue) { this->m_hue = hue; }
-       void setSaturation(float saturation) { this->m_saturation = saturation; }
-       void setValue(float value) { this->m_value = value; }
-
 };
 #endif
index 7b08b8368ba9afb99d61b595c0bcac97cc76b20f..d31a475e45e2f0f4e709421daa8dc3e9d3a81677 100644 (file)
@@ -1629,17 +1629,6 @@ static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C), P
        uiItemR(col, ptr, "use_antialias_z", 0, NULL, ICON_NONE);
 }
 
-
-static void node_composit_buts_hue_sat(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
-       uiLayout *col;
-       
-       col = uiLayoutColumn(layout, false);
-       uiItemR(col, ptr, "color_hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
-       uiItemR(col, ptr, "color_saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
-       uiItemR(col, ptr, "color_value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
-}
-
 static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
        uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
@@ -2580,9 +2569,6 @@ static void node_composit_set_butfunc(bNodeType *ntype)
                case CMP_NODE_ALPHAOVER:
                        ntype->draw_buttons = node_composit_buts_alphaover;
                        break;
-               case CMP_NODE_HUE_SAT:
-                       ntype->draw_buttons = node_composit_buts_hue_sat;
-                       break;
                case CMP_NODE_TEXTURE:
                        ntype->draw_buttons = node_buts_texture;
                        break;
index 3a7e2b6f7f85a18ba36d645fc2f2096a3ffb68f5..fd601e555503c2d25a3415584ed4ff296441e8d0 100644 (file)
@@ -595,6 +595,7 @@ typedef struct NodeBilateralBlurData {
        short iter, pad;
 } NodeBilateralBlurData;
 
+/* NOTE: Only for do-version code. */
 typedef struct NodeHueSat {
        float hue, sat, val;
 } NodeHueSat;
index a9e78428212c948b712ec1d91fce07d979c5d102..b35142f2a58efad3dfcafbe93dd2519ff5546e59 100644 (file)
@@ -4443,34 +4443,6 @@ static void def_cmp_alpha_over(StructRNA *srna)
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
-static void def_cmp_hue_saturation(StructRNA *srna)
-{
-       PropertyRNA *prop;
-
-       RNA_def_struct_sdna_from(srna, "NodeHueSat", "storage");
-       
-       prop = RNA_def_property(srna, "color_hue", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_float_sdna(prop, NULL, "hue");
-       RNA_def_property_range(prop, 0.0f, 1.0f);
-       RNA_def_property_float_default(prop, 0.5f);
-       RNA_def_property_ui_text(prop, "Hue", "");
-       RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
-       
-       prop = RNA_def_property(srna, "color_saturation", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_float_sdna(prop, NULL, "sat");
-       RNA_def_property_range(prop, 0.0f, 2.0f);
-       RNA_def_property_ui_text(prop, "Saturation", "");
-       RNA_def_property_float_default(prop, 1.0f);
-       RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
-       
-       prop = RNA_def_property(srna, "color_value", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_float_sdna(prop, NULL, "val");
-       RNA_def_property_range(prop, 0.0f, 2.0f);
-       RNA_def_property_ui_text(prop, "Value", "");
-       RNA_def_property_float_default(prop, 1.0f);
-       RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
-}
-
 static void def_cmp_blur(StructRNA *srna)
 {
        PropertyRNA *prop;
index 171d5313c1d6dedc5413877d3acc8f99b3df3aaa..a9c0df7d7e8dcea366f0366d58fc08e193abe02f 100644 (file)
@@ -145,7 +145,7 @@ DefNode( CompositorNode, CMP_NODE_VECBLUR,        def_cmp_vector_blur,    "VECBL
 DefNode( CompositorNode, CMP_NODE_SEPRGBA,        0,                      "SEPRGBA",        SepRGBA,          "Separate RGBA",     ""              )
 DefNode( CompositorNode, CMP_NODE_SEPHSVA,        0,                      "SEPHSVA",        SepHSVA,          "Separate HSVA",     ""              )
 DefNode( CompositorNode, CMP_NODE_SETALPHA,       0,                      "SETALPHA",       SetAlpha,         "Set Alpha",         ""              )
-DefNode( CompositorNode, CMP_NODE_HUE_SAT,        def_cmp_hue_saturation, "HUE_SAT",        HueSat,           "Hue Saturation Value",""            )
+DefNode( CompositorNode, CMP_NODE_HUE_SAT,        0,                      "HUE_SAT",        HueSat,           "Hue Saturation Value",""            )
 DefNode( CompositorNode, CMP_NODE_IMAGE,          def_cmp_image,          "IMAGE",          Image,            "Image",             ""              )
 DefNode( CompositorNode, CMP_NODE_R_LAYERS,       def_cmp_render_layers,  "R_LAYERS",       RLayers,          "Render Layers",     ""              )
 DefNode( CompositorNode, CMP_NODE_COMPOSITE,      def_cmp_composite,      "COMPOSITE",      Composite,        "Composite",         ""              )
index 1c31f4863cad99fb110412212721d0cde5ea56c8..952ba78aff3078376b27d20f332086e64e047bed 100644 (file)
 
 /* **************** Hue Saturation ******************** */
 static bNodeSocketTemplate cmp_node_hue_sat_in[] = {
-       {       SOCK_FLOAT, 1, N_("Fac"),                       1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
        {       SOCK_RGBA, 1, N_("Image"),                      1.0f, 1.0f, 1.0f, 1.0f},
+       {       SOCK_FLOAT, 1, N_("Hue"),                       0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+       {       SOCK_FLOAT, 1, N_("Saturation"),                1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+       {       SOCK_FLOAT, 1, N_("Value"),                     1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+       {       SOCK_FLOAT, 1, N_("Fac"),                       1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
        {       -1, 0, ""       }
 };
 static bNodeSocketTemplate cmp_node_hue_sat_out[] = {
@@ -44,23 +47,12 @@ static bNodeSocketTemplate cmp_node_hue_sat_out[] = {
        {       -1, 0, ""       }
 };
 
-static void node_composit_init_hue_sat(bNodeTree *UNUSED(ntree), bNode *node)
-{
-       NodeHueSat *nhs = MEM_callocN(sizeof(NodeHueSat), "node hue sat");
-       node->storage = nhs;
-       nhs->hue = 0.5f;
-       nhs->sat = 1.0f;
-       nhs->val = 1.0f;
-}
-
 void register_node_type_cmp_hue_sat(void)
 {
        static bNodeType ntype;
 
        cmp_node_type_base(&ntype, CMP_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0);
        node_type_socket_templates(&ntype, cmp_node_hue_sat_in, cmp_node_hue_sat_out);
-       node_type_init(&ntype, node_composit_init_hue_sat);
-       node_type_storage(&ntype, "NodeHueSat", node_free_standard_storage, node_copy_standard_storage);
 
        nodeRegisterType(&ntype);
 }