static VertexStore BuildCatmullRomSpline1() { using (VxsTemp.Borrow(out var v1, out var v2, out var v3)) using (VectorToolBox.Borrow(out CurveFlattener flatten)) using (VectorToolBox.Borrow(v1, out PathWriter w)) { w.MoveTo(10, 10); //w.CatmullRomToCurve4( // 10, 10, // 50, 10, // 50, 50, // 60, 50); w.CatmullRomSegmentToCurve4( 10, 10, 25, 10, //p1 25, 25, //p2 10, 25); w.CatmullRomSegmentToCurve4( 25, 10, 25, 25, //p1 10, 25, //p2 10, 10); w.CloseFigure(); //v1.ScaleToNewVxs(3, v2); return(flatten.MakeVxs(v1, v3).CreateTrim()); } }
void DrawD(Painter painter) { painter.Clear(PixelFarm.Drawing.Color.White); painter.StrokeColor = PixelFarm.Drawing.Color.Red; using (VxsTemp.Borrow(out var v1)) using (VectorToolBox.Borrow(v1, out PathWriter ps)) { //p.Line(10, 10, 50, 10); //p.Line(50, 10, 50, 50); //p.Line(50, 50, 10, 50); //p.Line(50, 10, 10, 10); ps.Clear(); ps.MoveTo(10, 10); ps.LineTo(50, 10); ps.LineTo(50, 50); ps.LineTo(10, 50); ps.CloseFigure(); // //ps.MoveTo(15, 15); //ps.LineTo(15, 45); //ps.LineTo(45, 45); //ps.LineTo(45, 15); //ps.CloseFigure(); // //p.Fill(ps.Vxs, PixelFarm.Drawing.Color.Black); painter.Draw(v1, PixelFarm.Drawing.Color.Red); } }
VertexStore CreateVxsFromPathDefinition(char[] patgDefinition) { using (VectorToolBox.Borrow(out CurveFlattener curveFlattener)) using (VxsTemp.Borrow(out var v1, out var v2)) using (VectorToolBox.Borrow(v1, out PathWriter pathWriter)) { _pathDataParser.SetPathWriter(pathWriter); _pathDataParser.Parse(patgDefinition); curveFlattener.MakeVxs(v1, v2); //create a small copy of the vxs return(v2.CreateTrim()); } }
void DrawE(Painter painter) { painter.Clear(PixelFarm.Drawing.Color.White); painter.StrokeColor = PixelFarm.Drawing.Color.Red; //p.Line(10, 10, 50, 10); //p.Line(50, 10, 50, 50); //p.Line(50, 50, 10, 50); //p.Line(50, 10, 10, 10); using (VxsTemp.Borrow(out var v1, out var v2)) using (VectorToolBox.Borrow(v1, out PathWriter ps)) { ps.Clear(); //ps.MoveTo(10, 10); //ps.LineTo(50, 10); //ps.LineTo(50, 50); //ps.MoveTo(10, 10); //ps.LineTo(50, 10); //ps.LineTo(10, 20); ps.MoveTo(150, 10); ps.LineTo(110, 10); ps.LineTo(150, 20); //ps.MoveTo(50, 50); //ps.LineTo(40, 50); //ps.LineTo(80, 70); //ps.CloseFigure(); //p.Fill(ps.Vxs, PixelFarm.Drawing.Color.Black); StrokeGen2 gen2 = new StrokeGen2(); //under construction! gen2.LineCapStyle = LineCap.Butt; gen2.LineJoinStyle = LineJoin.Miter; gen2.HalfStrokeWidth = 7;// gen2.Generate(v1, v2); //----------------------------------------------------- painter.Fill(v2, PixelFarm.Drawing.Color.Red); painter.StrokeWidth = 1f; painter.Draw(v1, PixelFarm.Drawing.Color.Black); } }
public GradientDemo() { //1. linear gradient _linearGrBrush = new LinearGradientBrush( new PointF(0, 0), new PointF(200, 200), new ColorStop[] { new ColorStop(0.0f, Drawing.Color.Black), new ColorStop(0.20f, Drawing.Color.Red), new ColorStop(0.50f, Drawing.Color.OrangeRed), new ColorStop(0.75f, Drawing.Color.Yellow) }); //2. circular gradient _circularGrBrush = new RadialGradientBrush( new PointF(50, 20), new PointF(300, 20), new ColorStop[] { new ColorStop(0.0f, Drawing.Color.Yellow), new ColorStop(0.25f, Drawing.Color.Blue), new ColorStop(0.50f, Drawing.Color.Green), new ColorStop(0.75f, Drawing.Color.Yellow), }); //3. polygon gradient: this version, just a simple rect PolygonGradientBrush.ColorVertex2d[] vertices = new PolygonGradientBrush.ColorVertex2d[] { new PolygonGradientBrush.ColorVertex2d(0, 0, Color.OrangeRed), new PolygonGradientBrush.ColorVertex2d(300, 0, Color.Black), new PolygonGradientBrush.ColorVertex2d(300, 400, Color.Yellow), new PolygonGradientBrush.ColorVertex2d(0, 400, Color.Blue), }; _polygonGradientBrush = new PolygonGradientBrush(vertices); using (VxsTemp.Borrow(out var v1)) using (VectorToolBox.Borrow(v1, out PathWriter p)) { p.MoveTo(0, 0); p.LineToRel(100, 100); p.LineToRel(100, -100); p.CloseFigure(); _triangleVxs = v1.CreateTrim(); } }
public override void Draw(Painter p) { //this specific for agg if (p is AggPainter) { AggPainter p2 = (AggPainter)p; AggRenderSurface aggsx = p2.RenderSurface; PixelProcessing.SubBitmapBlender subImg = PixelProcessing.BitmapBlenderExtension.CreateSubBitmapBlender(aggsx.DestBitmapBlender, aggsx.GetClippingRect()); //TODO: review here again PixelBlenderBGRA blenderWithGamma = new PixelProcessing.PixelBlenderBGRA(); SubBitmapBlender rasterGamma = new SubBitmapBlender(subImg, blenderWithGamma); ClipProxyImage clippingProxyNormal = new ClipProxyImage(subImg); ClipProxyImage clippingProxyGamma = new ClipProxyImage(rasterGamma); clippingProxyNormal.Clear(Color.White); ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer; var sl = new ScanlineUnpacked8(); int size_mul = this.PixelSize; var sclineToBmpEn2 = new CustomRas_EnlargeV2(size_mul, aggsx.DestBitmap); rasterizer.Reset(); rasterizer.MoveTo(_x[0] / size_mul, _y[0] / size_mul); rasterizer.LineTo(_x[1] / size_mul, _y[1] / size_mul); rasterizer.LineTo(_x[2] / size_mul, _y[2] / size_mul); sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); DestBitmapRasterizer bmpRas = aggsx.BitmapRasterizer; bmpRas.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); //----------------------------------------------------------------------------------------------------------- rasterizer.ResetGamma(new GammaNone()); using (VxsTemp.Borrow(out var v1, out var v2)) using (VectorToolBox.Borrow(v1, out PathWriter ps)) { ps.Clear(); ps.MoveTo(_x[0], _y[0]); ps.LineTo(_x[1], _y[1]); ps.LineTo(_x[2], _y[2]); ps.LineTo(_x[0], _y[0]); rasterizer.AddPath((new Stroke(2)).MakeVxs(v1, v2)); bmpRas.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160)); } } }
void DrawC(Painter p) { AggPainter aggPainter = p as AggPainter; if (aggPainter == null) { return; //temp } p.Clear(PixelFarm.Drawing.Color.White); //-------------------------- p.StrokeColor = PixelFarm.Drawing.Color.Black; p.StrokeWidth = 2.0f; if (_lineDashGen == null) { //create line dash gen _lineDashGen = new LineDashGenerator(); _lineDashGen.SetDashPattern(4, 2, 2, 2); } aggPainter.LineDashGen = _lineDashGen; // using (VxsTemp.Borrow(out var vxs)) using (VectorToolBox.Borrow(vxs, out PathWriter writer)) { // //writer.MoveTo(20, 10); //writer.LineTo(60, 10); //writer.LineTo(20, 200); //writer.LineTo(20, 0); writer.MoveTo(20, 10); writer.LineTo(60, 10); writer.LineTo(20, 200); writer.CloseFigure(); p.Draw(vxs); } //writer.MoveTo(20, 100); //writer.LineTo(20, 15); //writer.CloseFigure(); aggPainter.LineDashGen = null; }
public static TempContext <Stroke> BorrowStroke(out Stroke stroke) => VectorToolBox.Borrow(out stroke);
//TODO: add agressive inlining... public static TempContext <Arc> BorrowArc(out Arc arc) => VectorToolBox.Borrow(out arc);
public static TempContext <PathWriter> BorrowPathWriter(VertexStore vxs, out PathWriter pathWriter) => VectorToolBox.Borrow(vxs, out pathWriter);
void DrawA(Painter p) { p.Clear(PixelFarm.Drawing.Color.White); //-------------------------- p.StrokeColor = PixelFarm.Drawing.Color.Black; p.StrokeWidth = 2.0f; p.FillColor = PixelFarm.Drawing.Color.Black; // using (VxsTemp.Borrow(out var vxs)) using (VectorToolBox.Borrow(vxs, out PathWriter writer)) { writer.MoveTo(30, 10); writer.LineTo(60, 10); writer.MoveTo(10, 100); writer.LineTo(10, 50); p.Draw(vxs); } //writer.MoveTo(100, 100); //writer.LineTo(20, 200); //aggPainter.LineJoin = this.LineJoin; //aggPainter.LineCap = this.LineCap; // //---------------------------------------------------- ////create a dash line //VertexStore dashOutputVxs = new VertexStore(); //LineWalker dashGenLineWalker = new LineWalker(); ////*** ////you can customize what happend with the line segment //dashGenLineWalker.AddMark(10, LineWalkDashStyle.Solid); //dashGenLineWalker.AddMark(10, LineWalkDashStyle.Blank); ////dashGenLineWalker.AddMark(2, LineWalkDashStyle.Solid); ////dashGenLineWalker.AddMark(2, LineWalkDashStyle.Blank); //dashGenLineWalker.Walk(vxs, dashOutputVxs); ////---------------------------------------------------- //aggPainter.Draw(dashOutputVxs); ////test drawline //int n = newvxs.Count; //double px = 0, py = 0; //for (int i = 0; i < n; ++i) //{ // double x, y; // VertexCmd cmd = newvxs.GetVertex(i, out x, out y); // switch (cmd) // { // case VertexCmd.MoveTo: // px = x; // py = y; // break; // case VertexCmd.LineTo: // aggPainter.Line(px, py, x, y); // break; // } // px = x; // py = y; //} }
void DrawB(Painter p) { p.Clear(PixelFarm.Drawing.Color.White); //-------------------------- p.StrokeColor = PixelFarm.Drawing.Color.Black; p.StrokeWidth = 2.0f; using (VxsTemp.Borrow(out var v1, out var v2)) using (VectorToolBox.Borrow(v1, out PathWriter writer)) { writer.MoveTo(20, 10); writer.LineTo(60, 10); writer.LineTo(20, 200); writer.CloseFigure(); //aggPainter.LineJoin = this.LineJoin; //aggPainter.LineCap = this.LineCap; // //---------------------------------------------------- //create a dash line _dashGenLineWalker.ClearMarks(); //clear previous markers //*** //you can customize what happend with the line segment _dashGenLineWalker.AddMark(10, (outputVxs, cmd, x, y) => { //solid switch (cmd) { case VertexCmd.MoveTo: outputVxs.AddMoveTo(x, y); break; case VertexCmd.LineTo: outputVxs.AddLineTo(x, y); break; } }); _dashGenLineWalker.AddMark(10, (outputVxs, cmd, x, y) => { //whitespace, do nothing }); //then generate dash by walking along v1 _dashGenLineWalker.Walk(v1, v2); //aggPainter.Draw(vxs); //test drawline int n = v2.Count; double px = 0, py = 0; for (int i = 0; i < n; ++i) { double x, y; VertexCmd cmd = v2.GetVertex(i, out x, out y); switch (cmd) { case VertexCmd.MoveTo: px = x; py = y; break; case VertexCmd.LineTo: p.DrawLine(px, py, x, y); break; } px = x; py = y; } } //aggPainter.Draw(newvxs); }
public override void Draw(Painter p) { //specific for agg if (p is PixelFarm.CpuBlit.AggPainter) { var p2 = (PixelFarm.CpuBlit.AggPainter)p; AggRenderSurface aggsx = p2.RenderSurface; ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer; var widgetsSubImage = PixelProcessing.BitmapBlenderExtension.CreateSubBitmapBlender(aggsx.DestBitmapBlender, aggsx.GetClippingRect()); aggsx.UseSubPixelLcdEffect = false; PixelProcessing.PixelBlenderBGRA normalBlender = new PixelProcessing.PixelBlenderBGRA(); PixelProcessing.PixelBlenderBGRA gammaBlender = new PixelProcessing.PixelBlenderBGRA(); //TODO: revisit, and fix this again gammaBlender.GammaValue = this.GammaValue; gammaBlender.EnableGamma = true; var rasterGamma = new PixelProcessing.SubBitmapBlender(widgetsSubImage, gammaBlender); ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage); ClipProxyImage clippingProxyGamma = new ClipProxyImage(rasterGamma); clippingProxyNormal.Clear(Color.White); ScanlineUnpacked8 sl = new ScanlineUnpacked8(); int size_mul = (int)this.PixelSize; CustomScanlineRasToBmp_EnlargedSubPixelRendering ren_en = new CustomScanlineRasToBmp_EnlargedSubPixelRendering(size_mul, aggsx.DestBitmap); rasterizer.Reset(); rasterizer.MoveTo(_x[0] / size_mul, _y[0] / size_mul); rasterizer.LineTo(_x[1] / size_mul, _y[1] / size_mul); rasterizer.LineTo(_x[2] / size_mul, _y[2] / size_mul); ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); //---------------------------------------- DestBitmapRasterizer sclineRasToBmp = aggsx.BitmapRasterizer; aggsx.UseSubPixelLcdEffect = false; sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); rasterizer.ResetGamma(new GammaNone()); aggsx.UseSubPixelLcdEffect = false; //---------------------------------------- using (VxsTemp.Borrow(out var v1, out var v2)) using (VectorToolBox.Borrow(v1, out PathWriter ps)) { ps.Clear(); ps.MoveTo(_x[0], _y[0]); ps.LineTo(_x[1], _y[1]); ps.LineTo(_x[2], _y[2]); ps.LineTo(_x[0], _y[0]); rasterizer.AddPath(_stroke.MakeVxs(v1, v2)); } //---------------------------------------- //Stroke stroke = new Stroke(ps); //stroke.Width = 2; //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs())); //---------------------------------------- sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160)); } }
public override void Draw(Painter p) { if (UseBitmapExt) { p.RenderQuality = RenderQuality.Fast; } else { p.RenderQuality = RenderQuality.HighQuality; } int width = 800; int height = 600; //clear the image to white // draw a circle p.Clear(Drawing.Color.White); //Ellipse ellipseVxsGen = new Ellipse(0, 0, 100, 50); using (VectorToolBox.Borrow(out Ellipse ellipseVxsGen)) using (VectorToolBox.Borrow(out Stroke stroke)) { ellipseVxsGen.Set(0, 0, 100, 50); stroke.Width = 3; for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5) { var mat = Affine.NewMatix( AffinePlan.Rotate(MathHelper.DegreesToRadians(angleDegrees)), AffinePlan.Translate(width / 2, 150)); using (VxsTemp.Borrow(out var v1, out var v2, out var v3)) { ellipseVxsGen.MakeVxs(mat, v2); p.FillColor = Drawing.Color.Yellow; p.Fill(v2); //------------------------------------ p.FillColor = Drawing.Color.Blue; p.Fill(stroke.MakeVxs(v2, v3)); } } } // and a little polygon using (VxsTemp.Borrow(out var v1)) using (VectorToolBox.Borrow(v1, out PathWriter littlePoly)) { littlePoly.MoveTo(50, 50); littlePoly.LineTo(150, 50); littlePoly.LineTo(200, 200); littlePoly.LineTo(50, 150); littlePoly.LineTo(50, 50); p.FillColor = Drawing.Color.Blue; p.Fill(v1); } //--- //---- //test draw img // //g.Render(littlePoly.MakeVertexSnap(), ColorRGBA.Cyan); // draw some text // draw some text //var textPrinter = new TextPrinter(); //textPrinter.CurrentActualFont = svgFontStore.LoadFont(SvgFontStore.DEFAULT_SVG_FONTNAME, 30); //new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center); //VertexStore vxs = textPrinter.CreateVxs("Printing from a printer".ToCharArray()); //var affTx = Affine.NewTranslation(width / 2, height / 4 * 3); //VertexStore s1 = affTx.TransformToVxs(vxs); //p.FillColor = Drawing.Color.Black; //p.Fill(s1); ////g.Render(s1, ColorRGBA.Black); //p.FillColor = Drawing.Color.Red; //p.Fill(StrokeHelp.MakeVxs(s1, 1)); ////g.Render(StrokeHelp.MakeVxs(s1, 1), ColorRGBA.Red); //var aff2 = Affine.NewMatix( // AffinePlan.Rotate(MathHelper.DegreesToRadians(90)), // AffinePlan.Translate(40, height / 2)); //p.FillColor = Drawing.Color.Black; //p.Fill(aff2.TransformToVertexSnap(vxs)); ////g.Render(aff2.TransformToVertexSnap(vxs), ColorRGBA.Black); }
public override void Draw(PixelFarm.Drawing.Painter p) { p.Clear(Drawing.Color.White); p.StrokeColor = Color.Black; p.StrokeWidth = 2; p.StrokeColor = Color.Green; p.Draw(_triangleVxs); if (!ShowReconstructionCurve) { return; } //draw Ci line p.StrokeColor = Color.OrangeRed; DrawLine(p, a01, a12); DrawLine(p, a12, a20); DrawLine(p, a20, a01); //find B //DrawPoint(p, a01); //DrawPoint(p, a12); //DrawPoint(p, a20); BezierControllerArmPair c1 = BezierControllerArmPair.ReconstructControllerArms(v0, v1, v2); BezierControllerArmPair c2 = BezierControllerArmPair.ReconstructControllerArms(v1, v2, v0); BezierControllerArmPair c0 = BezierControllerArmPair.ReconstructControllerArms(v2, v0, v1); c0.UniformSmoothCoefficient = SmoothCoefficientValue; c1.UniformSmoothCoefficient = SmoothCoefficientValue; c2.UniformSmoothCoefficient = SmoothCoefficientValue; //DrawPoint(p, c0 = FindB(v0, v1, v2, out c1)); //DrawPoint(p, b2 = FindB(v1, v2, v0, out c2)); //DrawPoint(p, b0 = FindB(v2, v0, v1, out c0)); p.StrokeColor = Color.Red; DrawControllerPair(p, c0); DrawControllerPair(p, c1); DrawControllerPair(p, c2); p.StrokeColor = Color.Blue; using (VxsTemp.Borrow(out var tmpVxs1, out var tmpVxs2)) using (VectorToolBox.Borrow(tmpVxs1, out PathWriter pw)) { pw.MoveTo(c0.mid.X, c0.mid.y); pw.Curve4(c0.right.x, c0.right.y, c1.left.x, c1.left.y, c1.mid.x, c1.mid.y); //1st curve pw.Curve4(c1.right.x, c1.right.y, c2.left.x, c2.left.y, c2.mid.x, c2.mid.y); //2nd curve pw.Curve4(c2.right.x, c2.right.y, c0.left.x, c0.left.y, c0.mid.x, c0.mid.y); //3rd curve _curveflattener.MakeVxs(tmpVxs1, tmpVxs2); p.Draw(tmpVxs2); } }