Exemple #1
0
        public BlendNode(int w, int h, GraphPixelType p = GraphPixelType.RGBA) : base()
        {
            Name = "Blend";

            width  = w;
            height = h;

            alpha     = 1;
            alphaMode = AlphaModeType.Background;
            mode      = BlendType.Copy;

            previewProcessor = new BasicImageRenderer();
            processor        = new BlendProcessor();

            internalPixelType = p;

            tileX = tileY = 1;

            Id = Guid.NewGuid().ToString();

            Output = new NodeOutput(NodeType.Color | NodeType.Gray, this);
            first  = new NodeInput(NodeType.Color | NodeType.Gray, this, "Foreground");
            second = new NodeInput(NodeType.Color | NodeType.Gray, this, "Background");
            mask   = new NodeInput(NodeType.Gray, this, "Mask");

            Inputs.Add(first);
            Inputs.Add(second);
            Inputs.Add(mask);
            Outputs.Add(Output);
        }
Exemple #2
0
        public override void Dispose()
        {
            base.Dispose();

            if (processor != null)
            {
                processor.Release();
                processor = null;
            }
        }
Exemple #3
0
        /// <summary>
        /// Use this one only for when restoring
        /// from json
        /// </summary>
        public Layer(int w, int h, Graph parent)
        {
            opacityModes = new Dictionary <LayerPasses, float>();
            blendModes   = new Dictionary <LayerPasses, BlendType>();

            width       = w;
            height      = h;
            Id          = Guid.NewGuid().ToString();
            ParentGraph = parent;
            processor   = new BlendProcessor();

            InitDefaultModes();
        }
Exemple #4
0
        /// <summary>
        /// Combines the given image together with the current one by blending their pixels.
        /// </summary>
        /// <param name="source">The image this method extends.</param>
        /// <param name="image">The image to blend with the currently processing image.</param>
        /// <typeparam name="T">The pixel format.</typeparam>
        /// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
        /// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
        /// <param name="rectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
        /// </param>
        /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
        /// <returns>The <see cref="Image{T,TP}"/>.</returns>
        public static Image <T, TP> Blend <T, TP>(this Image <T, TP> source, ImageBase <T, TP> image, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null)
            where T : IPackedVector <TP>
            where TP : struct
        {
            BlendProcessor <T, TP> processor = new BlendProcessor <T, TP>(image, percent);

            processor.OnProgress += progressHandler;

            try
            {
                return(source.Process(rectangle, processor));
            }
            finally
            {
                processor.OnProgress -= progressHandler;
            }
        }
Exemple #5
0
        public void Dispose()
        {
            if (processor != null)
            {
                processor.Release();
                processor = null;
            }

            if (Mask != null)
            {
                Mask = null;
            }

            if (Core != null)
            {
                Core.Dispose();
                Core = null;
            }
        }
Exemple #6
0
        public Layer(Layer other)
        {
            opacityModes = new Dictionary <LayerPasses, float>();
            blendModes   = new Dictionary <LayerPasses, BlendType>();

            Id          = Guid.NewGuid().ToString();
            width       = other.width;
            height      = other.height;
            ParentGraph = other.ParentGraph;
            FromJson(other, other.ParentGraph);
            processor = new BlendProcessor();
            name     += " copy";

            foreach (LayerPasses pass in other.blendModes.Keys)
            {
                blendModes[pass]   = other.blendModes[pass];
                opacityModes[pass] = other.opacityModes[pass];
            }
        }
Exemple #7
0
        public Layer(string name, int w, int h, Graph parent)
        {
            opacityModes = new Dictionary <LayerPasses, float>();
            blendModes   = new Dictionary <LayerPasses, BlendType>();

            Id               = Guid.NewGuid().ToString();
            Name             = name;
            width            = w;
            height           = h;
            Core             = new ImageGraph(name, w, h);
            Core.ParentGraph = parent;

            ParentGraph = parent;

            Blending  = BlendType.Copy;
            Opacity   = 1.0f;
            processor = new BlendProcessor();

            InitDefaultModes();
        }
Exemple #8
0
        protected static bool CombineOutputTypes(OutputType type, float opacity, BlendType blending, Graph previous, Dictionary <OutputType, Node> render, Node mask, BlendProcessor processor)
        {
            if (previous == null || render == null || processor == null)
            {
                return(false);
            }

            Node node = null;

            foreach (string k in previous.OutputNodes)
            {
                Node n = null;
                if (previous.NodeLookup.TryGetValue(k, out n))
                {
                    OutputNode output = n as OutputNode;
                    if (output != null && output.OutType == type)
                    {
                        node = n;
                        break;
                    }
                }
            }

            Node renderLayer = null;

            render.TryGetValue(type, out renderLayer);

            if (node != null && renderLayer != null && renderLayer.GetActiveBuffer() != null && renderLayer.GetActiveBuffer().Id != 0 && node.GetActiveBuffer() != null && node.GetActiveBuffer().Id != 0)
            {
                processor.Alpha      = opacity;
                processor.AlphaMode  = (int)AlphaModeType.Add;
                processor.BlendMode  = (int)blending;
                processor.Luminosity = 1.0f;
                processor.Process(node.Width, node.Height, node.GetActiveBuffer(), renderLayer.GetActiveBuffer(), mask?.GetActiveBuffer(), renderLayer.GetActiveBuffer());
                processor.Complete();
                return(true);
            }

            return(false);
        }