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 93bc0502b1958c24909cb1169f6c7506625ac5ff..de5e69b741a38d677fa092d0adff5072476ed9d7 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 e3313750e6652e07690d3734f3f8f48f81ffe20c..e5c01c7573ae52800d704f5e489db4c9e8a58d0d 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 f44470a9b9a5a482ab510b5223b491ce9ae9a5b7..76250145214063986326ba8828feae545d055a80 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 e6a49082a7119e75403842bc52619008786ecd6e..7cb3a614022198840c8dd9b758a557b302dba804 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 c1d91c16a3cfa801848601886cd76eb4e410fcd1..e60862be410e393e77eaa0a20e23ba9584ce3d34 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 d5f2c283c72a18e806720ec88405cfce37f047ca..87d7a810d80b8384a3850d578faee1824385275d 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 f7d479eb3b895b7175228aeec7edf3540e0be89d..1f773c5151aad78761a5c3516d0a6facd82748c5 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 d1ac7d74eada874e07d2015e2571f8985090c823..f1ac893bd3fdda1d17b2226b0bf8f3c8fa752609 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 9b342ed8f44ca9a5513d5259730ce808aaf07c81..9dd588e77aed34217111e3e339c953b9a84f1abf 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 d5d2ace6fa784bc13fb26ab08bfe6e3549d10622..34f7799d47cc22f7a43927d350f032a4e7f40dd6 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 fee4b429a118f2534e85cf0b6446cb3743f5cfa7..cf60e3bd14f78d57c92e0e9a6dfe6c1aab4b62a6 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 d6e0ce2f11a1356ab7849a2921fe2f259deb861b..35d3c32c0455adebcb3a401ef53140ddce5bf921 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 ca12b500e5bab32ab7dfed3d6558b975608c970c..6cff403976761dff8c62f76d7aba3046a98038b5 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 24affc8f37483d3bb99e8b71355d1ffb8bab7505..233a0627a7a83244379527a9914c144492d0433e 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);