Added option to composite/viewer nodes which specifys whether alpha input
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 10 Feb 2013 12:20:10 +0000 (12:20 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 10 Feb 2013 12:20:10 +0000 (12:20 +0000)
is straight or not (premultiplied is default).

This is useful in cases when you want to check on output of such nodes
as keying which does have straight alpha output.

Also added missing do_version code to previous compo do_versions.

14 files changed:
source/blender/blenloader/intern/readfile.c
source/blender/compositor/nodes/COM_CompositorNode.cpp
source/blender/compositor/nodes/COM_ViewerNode.cpp
source/blender/compositor/operations/COM_CompositorOperation.cpp
source/blender/compositor/operations/COM_CompositorOperation.h
source/blender/compositor/operations/COM_ViewerBaseOperation.cpp
source/blender/compositor/operations/COM_ViewerBaseOperation.h
source/blender/compositor/operations/COM_ViewerOperation.cpp
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_draw.c
source/blender/makesrna/intern/rna_nodetree.c
source/blender/makesrna/intern/rna_nodetree_types.h
source/blender/nodes/composite/nodes/node_composite_composite.c
source/blender/nodes/composite/nodes/node_composite_viewer.c

index 93bc050..de5e69b 100644 (file)
@@ -8795,13 +8795,15 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        // add storage for compositor translate nodes when not existing
        if (!MAIN_VERSION_ATLEAST(main, 265, 10)) {
                bNodeTreeType *ntreetype;
+               bNodeTree *ntree;
 
                ntreetype = ntreeGetType(NTREE_COMPOSIT);
                if (ntreetype && ntreetype->foreach_nodetree)
                        ntreetype->foreach_nodetree(main, NULL, do_version_node_fix_translate_wrapping);
-       }
-
 
+               for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
+                       do_version_node_fix_translate_wrapping(NULL, NULL, ntree);
+       }
 
        // if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 7)) {
 
index e331375..e5c01c7 100644 (file)
@@ -41,6 +41,7 @@ void CompositorNode::convertToOperations(ExecutionSystem *graph, CompositorConte
        compositorOperation->setSceneName(editorNode->id->name);
        compositorOperation->setRenderData(context->getRenderData());
        compositorOperation->setbNodeTree(context->getbNodeTree());
+       compositorOperation->setStraightAlpha(editorNode->custom2 & 1);
        imageSocket->relinkConnections(compositorOperation->getInputSocket(0), 0, graph);
        alphaSocket->relinkConnections(compositorOperation->getInputSocket(1));
        depthSocket->relinkConnections(compositorOperation->getInputSocket(2));
index f44470a..7625014 100644 (file)
@@ -47,6 +47,7 @@ void ViewerNode::convertToOperations(ExecutionSystem *graph, CompositorContext *
        viewerOperation->setChunkOrder((OrderOfChunks)editorNode->custom1);
        viewerOperation->setCenterX(editorNode->custom3);
        viewerOperation->setCenterY(editorNode->custom4);
+       viewerOperation->setStraightAlpha(editorNode->custom2 & 1);
 
        viewerOperation->setViewSettings(context->getViewSettings());
        viewerOperation->setDisplaySettings(context->getDisplaySettings());
index e6a4908..7cb3a61 100644 (file)
@@ -49,6 +49,8 @@ CompositorOperation::CompositorOperation() : NodeOperation()
        this->m_alphaInput = NULL;
        this->m_depthInput = NULL;
 
+       this->m_straightAlpha = false;
+
        this->m_sceneName[0] = '\0';
 }
 
@@ -141,6 +143,10 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber)
                        if (this->m_alphaInput != NULL) {
                                this->m_alphaInput->read(&(color[3]), x, y, COM_PS_NEAREST);
                        }
+
+                       if (this->m_straightAlpha)
+                               straight_to_premul_v4(color);
+
                        copy_v4_v4(buffer + offset4, color);
 
                        if (this->m_depthInput != NULL) {
index c1d91c1..e60862b 100644 (file)
@@ -65,6 +65,10 @@ private:
         * @brief local reference to the depth operation
         */
        SocketReader *m_depthInput;
+
+       /* node input has got straight alpha which shall be premultiplied */
+       bool m_straightAlpha;
+
 public:
        CompositorOperation();
        void executeRegion(rcti *rect, unsigned int tileNumber);
@@ -75,5 +79,6 @@ public:
        void deinitExecution();
        const CompositorPriority getRenderPriority() const { return COM_PRIORITY_MEDIUM; }
        void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
+       void setStraightAlpha(bool value) { this->m_straightAlpha = value; }
 };
 #endif
index d5f2c28..87d7a81 100644 (file)
@@ -48,6 +48,7 @@ ViewerBaseOperation::ViewerBaseOperation() : NodeOperation()
        this->m_doDepthBuffer = false;
        this->m_viewSettings = NULL;
        this->m_displaySettings = NULL;
+       this->m_straightAlpha = false;
 }
 
 void ViewerBaseOperation::initExecution()
index f7d479e..1f773c5 100644 (file)
@@ -39,6 +39,7 @@ protected:
        OrderOfChunks m_chunkOrder;
        bool m_doDepthBuffer;
        ImBuf *m_ibuf;
+       bool m_straightAlpha;
 
        const ColorManagedViewSettings *m_viewSettings;
        const ColorManagedDisplaySettings *m_displaySettings;
@@ -59,6 +60,7 @@ public:
        OrderOfChunks getChunkOrder() { return this->m_chunkOrder; }
        const CompositorPriority getRenderPriority() const;
        bool isViewerOperation() { return true; }
+       void setStraightAlpha(bool value) { this->m_straightAlpha = value; }
 
        void setViewSettings(const ColorManagedViewSettings *viewSettings) { this->m_viewSettings = viewSettings; }
        void setDisplaySettings(const ColorManagedDisplaySettings *displaySettings) { this->m_displaySettings = displaySettings; }
index d1ac7d7..f1ac893 100644 (file)
@@ -98,6 +98,9 @@ void ViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber)
                                depthbuffer[offset] = depth[0];
                        }
 
+                       if (this->m_straightAlpha)
+                               straight_to_premul_v4(buffer + offset4);
+
                        offset ++;
                        offset4 += 4;
                }
index 9b342ed..9dd588e 100644 (file)
@@ -2654,10 +2654,21 @@ static void node_composit_buts_ellipsemask(uiLayout *layout, bContext *UNUSED(C)
        uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE);
 }
 
+static void node_composit_buts_composite(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+       uiItemR(layout, ptr, "use_straight_alpha", 0, NULL, ICON_NONE);
+}
+
+static void node_composit_buts_viewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+       uiItemR(layout, ptr, "use_straight_alpha", 0, NULL, ICON_NONE);
+}
+
 static void node_composit_buts_viewer_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
        uiLayout *col;
        
+       uiItemR(layout, ptr, "use_straight_alpha", 0, NULL, ICON_NONE);
        uiItemR(layout, ptr, "tile_order", 0, NULL, ICON_NONE);
        if (RNA_enum_get(ptr, "tile_order") == 0) {
                col = uiLayoutColumn(layout, TRUE);
@@ -2965,10 +2976,13 @@ static void node_composit_set_butfunc(bNodeType *ntype)
                        ntype->uifunc = node_composit_buts_bokehblur;
                        break;
                case CMP_NODE_VIEWER:
-                       ntype->uifunc = NULL;
+                       ntype->uifunc = node_composit_buts_viewer;
                        ntype->uifuncbut = node_composit_buts_viewer_but;
                        ntype->uibackdropfunc = node_composit_backdrop_viewer;
                        break;
+               case CMP_NODE_COMPOSITE:
+                       ntype->uifunc = node_composit_buts_composite;
+                       break;
                case CMP_NODE_MASK:
                        ntype->uifunc = node_composit_buts_mask;
                        break;
index d5d2ace..34f7799 100644 (file)
@@ -368,7 +368,8 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node)
        }
 
        /* buttons rect? */
-       if ((node->flag & NODE_OPTIONS) && node->typeinfo->uifunc) {
+       /* TODO: NODE_OPTION shall be cleaned up */
+       if (/*(node->flag & NODE_OPTIONS) && */node->typeinfo->uifunc) {
                dy -= NODE_DYS / 2;
 
                /* set this for uifunc() that don't use layout engine yet */
index fee4b42..cf60e3b 100644 (file)
@@ -4083,6 +4083,21 @@ static void def_cmp_viewer(StructRNA *srna)
        RNA_def_property_range(prop, 0.0f, 1.0f);
        RNA_def_property_ui_text(prop, "Y", "");
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+       prop = RNA_def_property(srna, "use_straight_alpha", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1);
+       RNA_def_property_ui_text(prop, "Straight Alpha", "Treat alpha input of this node as straight");
+       RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
+static void def_cmp_composite(StructRNA *srna)
+{
+       PropertyRNA *prop;
+
+       prop = RNA_def_property(srna, "use_straight_alpha", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1);
+       RNA_def_property_ui_text(prop, "Straight Alpha", "Treat alpha input of this node as straight");
+       RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
 static void def_cmp_keyingscreen(StructRNA *srna)
index d6e0ce2..35d3c32 100644 (file)
@@ -124,7 +124,7 @@ DefNode( CompositorNode, CMP_NODE_SETALPHA,       0,                      "SETAL
 DefNode( CompositorNode, CMP_NODE_HUE_SAT,        def_cmp_hue_saturation, "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,      0,                      "COMPOSITE",      Composite,        "Composite",         ""              )
+DefNode( CompositorNode, CMP_NODE_COMPOSITE,      def_cmp_composite,      "COMPOSITE",      Composite,        "Composite",         ""              )
 DefNode( CompositorNode, CMP_NODE_OUTPUT_FILE,    def_cmp_output_file,    "OUTPUT_FILE",    OutputFile,       "File Output",       ""              )
 DefNode( CompositorNode, CMP_NODE_TEXTURE,        def_texture,            "TEXTURE",        Texture,          "Texture",           ""              )
 DefNode( CompositorNode, CMP_NODE_TRANSLATE,      def_cmp_translate,      "TRANSLATE",      Translate,        "Translate",         ""              )
index ca12b50..6cff403 100644 (file)
@@ -43,7 +43,7 @@ void register_node_type_cmp_composite(bNodeTreeType *ttype)
 {
        static bNodeType ntype;
 
-       node_type_base(ttype, &ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_PREVIEW);
+       node_type_base(ttype, &ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_OPTIONS | NODE_PREVIEW);
        node_type_socket_templates(&ntype, cmp_node_composite_in, NULL);
        node_type_size(&ntype, 80, 60, 200);
 
index 24affc8..233a062 100644 (file)
@@ -56,7 +56,7 @@ void register_node_type_cmp_viewer(bNodeTreeType *ttype)
 {
        static bNodeType ntype;
 
-       node_type_base(ttype, &ntype, CMP_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW);
+       node_type_base(ttype, &ntype, CMP_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_OPTIONS | NODE_PREVIEW);
        node_type_socket_templates(&ntype, cmp_node_viewer_in, NULL);
        node_type_size(&ntype, 80, 60, 200);
        node_type_init(&ntype, node_composit_init_viewer);