public GradientToolContentRenderer(IRenderer <ColorBgra> layerSource, GradientToolChanges changes, uint ditherSeed) : base(layerSource.Width, layerSource.Height, false)
        {
            ColorBgra        startColor       = changes.ReverseColors ? changes.SecondaryColor : changes.PrimaryColor;
            ColorBgra        endColor         = changes.ReverseColors ? changes.PrimaryColor : changes.SecondaryColor;
            GradientShape    gradientShape    = CreateGradientShape(changes.GradientType, changes.RepeatType, changes.GradientStartPoint, changes.GradientEndPoint);
            GradientRepeater gradientRepeater = CreateGradientRepeater(changes.RepeatType);
            bool             antialiasing     = changes.Antialiasing;
            bool             isAntiAliased    = changes.Antialiasing && this.IsAntialiasingRequiredForShape(changes.GradientType, changes.RepeatType, changes.GradientStartPoint, changes.GradientEndPoint);

            if (changes.IsAlphaOnly)
            {
                IRenderer <ColorAlpha8> renderer2;
                byte startAlpha = changes.ReverseColors ? ((byte)(0xff - startColor.A)) : startColor.A;
                byte endAlpha   = changes.ReverseColors ? endColor.A : ((byte)(0xff - endColor.A));
                IRenderer <ColorAlpha8> second = CreateAlphaRenderer(layerSource.Width, layerSource.Height, gradientShape, gradientRepeater, startAlpha, endAlpha, isAntiAliased, antialiasing, ditherSeed);
                if (changes.BlendMode.IsCompositionOp())
                {
                    IRenderer <ColorAlpha8> first = new ExtractAlpha8FromBgra32Renderer(layerSource);
                    renderer2 = new MultiplyRendererAlpha8(first, second);
                }
                else
                {
                    renderer2 = second;
                }
                this.renderer = new ReplaceAlphaChannelRendererBgra32(layerSource, renderer2);
            }
            else
            {
                this.renderer = CreateColorRenderer(layerSource.Width, layerSource.Height, gradientShape, gradientRepeater, startColor, endColor, isAntiAliased, antialiasing, ditherSeed);
            }
        }
Пример #2
0
        /// <summary>
        /// Supports concentration gradients.
        /// </summary>
        /// <param name="DropletPrintStyleModel"></param>
        public DropletModel(DropletPrintStyleModel DropletPrintStyleModel)
        {
            _interpolateDistance = DropletPrintStyleModel.InterpolateDistance;
            _gradientShape       = DropletPrintStyleModel.GradientShape;
            _gradientScaling     = DropletPrintStyleModel.GradientScaling;

            Point3D point1 = new Point3D(DropletPrintStyleModel.X1, DropletPrintStyleModel.Y1, DropletPrintStyleModel.Z1);
            Point3D point2 = new Point3D(DropletPrintStyleModel.X2, DropletPrintStyleModel.Y2, DropletPrintStyleModel.Z2);
            Point3D point3 = new Point3D(DropletPrintStyleModel.X3, DropletPrintStyleModel.Y3, DropletPrintStyleModel.Z3);

            switch (DropletPrintStyleModel.GradientShape)
            {
            case GradientShape.None:
                _gradientModel = null;
                break;

            case GradientShape.Point:
                _gradientModel = new PointModel(_gradientScaling, DropletPrintStyleModel.PercentPerMm, point1);
                break;

            case GradientShape.Line:
                _gradientModel = new LineModel(_gradientScaling, DropletPrintStyleModel.PercentPerMm, point1, point2);
                break;

            case GradientShape.Plane:
                _gradientModel = new PlaneModel(_gradientScaling, DropletPrintStyleModel.PercentPerMm, point1, point2, point3);
                break;
            }
        }
        private static IRenderer <ColorBgra> CreateColorRenderer(int width, int height, GradientShape gradientShape, GradientRepeater gradientRepeater, ColorBgra startColor, ColorBgra endColor, bool isAntiAliased, bool isDithered, uint ditherSeed)
        {
            GradientBlender <ColorBgra> blender;

            if ((gradientShape == null) || (startColor == endColor))
            {
                return(new SolidColorRendererBgra(width, height, endColor));
            }
            if (isDithered)
            {
                if ((startColor.A == 0xff) && (endColor.A == 0xff))
                {
                    blender = new GradientBlenders.RgbSolidColor(startColor, endColor, ditherSeed);
                }
                else
                {
                    blender = new GradientBlenders.RgbColor(startColor, endColor, ditherSeed);
                }
            }
            else
            {
                blender = new GradientBlenders.FastColor(startColor, endColor);
            }
            return(new GradientColorRenderer(width, height, gradientShape, gradientRepeater, blender, isAntiAliased));
        }
 private static IRenderer <ColorAlpha8> CreateAlphaRenderer(int width, int height, GradientShape gradientShape, GradientRepeater gradientRepeater, int startAlpha, int endAlpha, bool isAntiAliased, bool isDithered, uint ditherSeed)
 {
     if ((gradientShape == null) || (startAlpha == endAlpha))
     {
         return(new FillRendererAlpha8(width, height, new ColorAlpha8((byte)endAlpha)));
     }
     return(new GradientAlphaRenderer(width, height, gradientShape, gradientRepeater, new GradientBlenders.Alpha(startAlpha, endAlpha, ditherSeed, isDithered), isAntiAliased));
 }