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); } }
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)); }