Ejemplo n.º 1
0
        public void PaintLayerOnLayerMasked(ILayerMasked valueLayer, ILayerMasked maskedLayer, ILayerMasked returnLayer)
        {
            if (valueLayer.Resolution != maskedLayer.Resolution || maskedLayer.Resolution != returnLayer.Resolution)
            {
                throw new ArgumentException(error_sizeDoesNotMatch);
            }
            if (maskedLayer.Mask == null || maskedLayer.Mask.Resolution != maskedLayer.Resolution)
            {
                throw new ArgumentException();
            }

            for (int y = maskedLayer.ValueArea.Top; y < valueLayer.ValueArea.Bottom; y++)
            {
                for (int x = maskedLayer.ValueArea.Left; x < valueLayer.ValueArea.Right; x++)
                {
                    var source = maskedLayer[x, y];
                    var alpha  = maskedLayer.Mask[x, y];

                    if (source.HasValue && alpha.HasValue && alpha.Value > thres)
                    {
                        var target = valueLayer[x, y];
                        if (target.HasValue)
                        {
                            returnLayer[x, y] = ab.Blend(target.Value, source.Value, alpha.Value);
                        }
                        else
                        {
                            returnLayer[x, y] = source.Value;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private ILayerMasked merge(IBlendModeAlpha ablend, ILayerMasked baseLayer, IList <DescribedLayer> pars)
        {
            onMergeStarted();
            if (pars == null || pars.Count == 0)
            {
                throw new ArgumentException();
            }

            var final = baseLayer;

            foreach (var describ in pars)
            {
                var current   = describ.Layer;
                var blendMode = describ.GlobalParameters.BlendMode;
                var offset    = describ.GlobalParameters.Offset - .5f;

                var minY = JryMath.Max(0, -current.Offset.Y);
                var minX = JryMath.Max(0, -current.Offset.X);
                var maxY = JryMath.Min(current.Resolution.Y, final.Resolution.Y - current.Offset.Y);
                var maxX = JryMath.Min(current.Resolution.X, final.Resolution.X - current.Offset.X);
                for (int y = minY; y < maxY; y++)
                {
                    for (int x = minX; x < maxX; x++)
                    {
                        int ix = x + current.Offset.X;
                        int iy = y + current.Offset.Y;


                        var curVal = current[x, y];
                        if (!curVal.HasValue || !final[ix, iy].HasValue || !current.HasMask)
                        {
                            continue;
                        }
                        var maskValue = current.Mask[x, y];
                        if (!maskValue.HasValue)
                        {
                            continue;
                        }


                        var currentLayerValue     = curVal.Value + offset;
                        var currentLayerMaskValue = maskValue.Value;
                        //currentLayerMaskValue = 1;
                        var upToThisPointGeneratedLayerValue = final[ix, iy].Value;


                        var blended = blendMode.Blend(upToThisPointGeneratedLayerValue, currentLayerValue * currentLayerMaskValue);
                        final[ix, iy] = ablend.Blend(upToThisPointGeneratedLayerValue, blended, currentLayerMaskValue);
                        if (final[ix, iy] > 0.05f)
                        {
                        }
                    }
                }
            }

            return(baseLayer);
        }