void generate_alpha_mask(ScanlineRasToDestBitmapRenderer sclineRasToBmp, ScanlinePacked8 sclnPack, ScanlineRasterizer rasterizer, int width, int height) { alphaBitmap = new ActualImage(width, height, PixelFormat.GrayScale8); var bmpReaderWrtier = new MyImageReaderWriter(alphaBitmap); alphaMaskImageBuffer = new ChildImage(bmpReaderWrtier, new PixelBlenderGray(1)); alphaMask = new AlphaMaskByteClipped(alphaMaskImageBuffer, 1, 0); #if USE_CLIPPING_ALPHA_MASK //alphaMaskImageBuffer.AttachBuffer(alphaBitmap.GetBuffer(), 20 * width + 20, width - 40, height - 40, width, 8, 1); #else alphaMaskImageBuffer.attach(alphaByteArray, (int)cx, (int)cy, cx, 1); #endif var image = new ChildImage(alphaMaskImageBuffer, new PixelBlenderGray(1), 1, 0, 8); ClipProxyImage clippingProxy = new ClipProxyImage(image); clippingProxy.Clear(ColorRGBA.Black); VertexSource.Ellipse ellipseForMask = new PixelFarm.Agg.VertexSource.Ellipse(); System.Random randGenerator = new Random(1432); int i; int num = (int)maskAlphaSliderValue; for (i = 0; i < num; i++) { if (i == num - 1) { ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100); rasterizer.AddPath(ellipseForMask.MakeVertexSnap()); sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(0, 0, 0, 255)); ellipseForMask.Reset(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100); rasterizer.AddPath(ellipseForMask.MakeVertexSnap()); sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(255, 0, 0, 255)); } else { ellipseForMask.Reset(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 100 + 20, randGenerator.Next() % 100 + 20, 100); // set the color to draw into the alpha channel. // there is not very much reason to set the alpha as you will get the amount of // transparency based on the color you draw. (you might want some type of different edeg effect but it will be minor). rasterizer.AddPath(ellipseForMask.MakeVxs()); sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, ColorRGBA.Make((int)((float)i / (float)num * 255), 0, 0, 255)); } } }
public override void Draw(Painter p) { //specific for agg if (p is PixelFarm.Agg.AggPainter) { var p2 = (PixelFarm.Agg.AggPainter)p; AggRenderSurface aggsx = p2.RenderSurface; ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer; var widgetsSubImage = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect()); aggsx.UseSubPixelRendering = false; PixelBlenderBGRA normalBlender = new PixelBlenderBGRA(); PixelBlenderBGRA gammaBlender = new PixelBlenderBGRA(); //TODO: revisit, and fix this again gammaBlender.GammaValue = this.GammaValue; gammaBlender.EnableGamma = true; var rasterGamma = new SubImageRW(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.DestActualImage); rasterizer.Reset(); rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul); rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul); rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul); ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); //---------------------------------------- ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggsx.ScanlineRasToDestBitmap; aggsx.UseSubPixelRendering = false; sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); rasterizer.ResetGamma(new GammaNone()); aggsx.UseSubPixelRendering = false; //---------------------------------------- PathWriter ps = new PathWriter(); ps.Clear(); ps.MoveTo(m_x[0], m_y[0]); ps.LineTo(m_x[1], m_y[1]); ps.LineTo(m_x[2], m_y[2]); ps.LineTo(m_x[0], m_y[0]); //---------------------------------------- //Stroke stroke = new Stroke(ps); //stroke.Width = 2; //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs())); VectorToolBox.GetFreeVxs(out var v1); rasterizer.AddPath(stroke.MakeVxs(ps.Vxs, v1)); VectorToolBox.ReleaseVxs(ref v1); //---------------------------------------- sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160)); } }
public void OnDraw(Graphics2D graphics2D) { var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect()); graphics2D.UseSubPixelRendering = false; IPixelBlender NormalBlender = new PixelBlenderBGRA(); IPixelBlender GammaBlender = new PixelBlenderGammaBGRA(this.GammaValue); var rasterGamma = new ChildImage(widgetsSubImage, GammaBlender); ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage); ClipProxyImage clippingProxyGamma = new ClipProxyImage(rasterGamma); clippingProxyNormal.Clear(ColorRGBA.White); var rasterizer = graphics2D.ScanlineRasterizer; ScanlineUnpacked8 sl = new ScanlineUnpacked8(); int size_mul = (int)this.PixelSize; CustomScanlineRasToBmp_EnlargedV3 ren_en = new CustomScanlineRasToBmp_EnlargedV3(size_mul, graphics2D.DestActualImage); rasterizer.Reset(); rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul); rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul); rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul); ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black); //---------------------------------------- ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap; graphics2D.UseSubPixelRendering = true; sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black); rasterizer.ResetGamma(new GammaNone()); graphics2D.UseSubPixelRendering = false; //---------------------------------------- PathWriter ps = new PathWriter(); ps.Clear(); ps.MoveTo(m_x[0], m_y[0]); ps.LineTo(m_x[1], m_y[1]); ps.LineTo(m_x[2], m_y[2]); ps.LineTo(m_x[0], m_y[0]); //---------------------------------------- //Stroke stroke = new Stroke(ps); //stroke.Width = 2; //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs())); rasterizer.AddPath(StrokeHelp.MakeVxs(ps.Vxs, 2)); //---------------------------------------- sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new ColorRGBA(0, 150, 160, 200)); }
public void Draw( ScanlineRasToDestBitmapRenderer sclineRasToBmp, ScanlineRasterizer ras, Scanline sl, IImageReaderWriter destImage, ColorRGBA color, double x, double y) { ras.Reset(); ras.MoveTo(x * m_size, y * m_size); ras.LineTo(x * m_size + m_size, y * m_size); ras.LineTo(x * m_size + m_size, y * m_size + m_size); ras.LineTo(x * m_size, y * m_size + m_size); sclineRasToBmp.RenderWithColor(destImage, ras, sl, color); }
public override void Draw(CanvasPainter p) { //specific for agg if (p is PixelFarm.Agg.AggCanvasPainter) { var p2 = (PixelFarm.Agg.AggCanvasPainter)p; Graphics2D gx = p2.Graphics; var widgetsSubImage = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect()); gx.UseSubPixelRendering = false; IPixelBlender NormalBlender = new PixelBlenderBGRA(); IPixelBlender GammaBlender = new PixelBlenderGammaBGRA(this.GammaValue); var rasterGamma = new ChildImage(widgetsSubImage, GammaBlender); ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage); ClipProxyImage clippingProxyGamma = new ClipProxyImage(rasterGamma); clippingProxyNormal.Clear(Color.White); var rasterizer = gx.ScanlineRasterizer; ScanlineUnpacked8 sl = new ScanlineUnpacked8(); int size_mul = (int)this.PixelSize; CustomScanlineRasToBmp_EnlargedSubPixelRendering ren_en = new CustomScanlineRasToBmp_EnlargedSubPixelRendering(size_mul, gx.DestActualImage); rasterizer.Reset(); rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul); rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul); rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul); ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); //---------------------------------------- ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap; gx.UseSubPixelRendering = true; sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); rasterizer.ResetGamma(new GammaNone()); gx.UseSubPixelRendering = false; //---------------------------------------- PathWriter ps = new PathWriter(); ps.Clear(); ps.MoveTo(m_x[0], m_y[0]); ps.LineTo(m_x[1], m_y[1]); ps.LineTo(m_x[2], m_y[2]); ps.LineTo(m_x[0], m_y[0]); //---------------------------------------- //Stroke stroke = new Stroke(ps); //stroke.Width = 2; //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs())); var v1 = GetFreeVxs(); rasterizer.AddPath(stroke.MakeVxs(ps.Vxs, v1)); ReleaseVxs(ref v1); //---------------------------------------- sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160)); } }
public static void RenderSolidAllPaths(this ScanlineRasToDestBitmapRenderer sclineRasToBmp, IImageReaderWriter destImage, ScanlineRasterizer sclineRas, Scanline scline, VertexStore vxs, Drawing.Color[] colors, int[] path_id, int num_paths) { for (int i = 0; i < num_paths; ++i) { sclineRas.Reset(); sclineRas.AddPath(new VertexStoreSnap(vxs, path_id[i])); sclineRasToBmp.RenderWithColor(destImage, sclineRas, scline, colors[i]); } }
public void OnDraw(Graphics2D graphics2D) { var childImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect()); //IRecieveBlenderByte rasterBlender = new BlenderBGRA(); var rasterGamma = new ChildImage(childImage, new PixelBlenderGammaBGRA(this.GammaValue)); ClipProxyImage clippingProxyNormal = new ClipProxyImage(childImage); ClipProxyImage clippingProxyGamma = new ClipProxyImage(rasterGamma); clippingProxyNormal.Clear(ColorRGBA.White); var rasterizer = graphics2D.ScanlineRasterizer; var sl = new ScanlineUnpacked8(); int size_mul = this.PixelSize; CustomScanlineRasToBmp_EnlargedV2 sclineToBmpEn2 = new CustomScanlineRasToBmp_EnlargedV2(size_mul, graphics2D.DestActualImage); rasterizer.Reset(); rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul); rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul); rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul); sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black); ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap; sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, ColorRGBA.Black); //----------------------------------------------------------------------------------------------------------- rasterizer.ResetGamma(new GammaNone()); PathWriter ps = new PathWriter(); ps.Clear(); ps.MoveTo(m_x[0], m_y[0]); ps.LineTo(m_x[1], m_y[1]); ps.LineTo(m_x[2], m_y[2]); ps.LineTo(m_x[0], m_y[0]); rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs)); sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new ColorRGBA(0, 150, 160, 200)); }
public override void Draw(Painter p) { //this specific for agg if (p is AggPainter) { AggPainter p2 = (AggPainter)p; AggRenderSurface aggsx = p2.RenderSurface; SubImageRW subImg = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect()); //TODO: review here again PixelBlenderBGRA blenderWithGamma = new PixelBlenderBGRA(); SubImageRW rasterGamma = new SubImageRW(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 CustomScanlineRasToBmp_EnlargedV2(size_mul, aggsx.DestActualImage); rasterizer.Reset(); rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul); rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul); rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul); sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggsx.ScanlineRasToDestBitmap; sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); //----------------------------------------------------------------------------------------------------------- rasterizer.ResetGamma(new GammaNone()); PathWriter ps = new PathWriter(); ps.Clear(); ps.MoveTo(m_x[0], m_y[0]); ps.LineTo(m_x[1], m_y[1]); ps.LineTo(m_x[2], m_y[2]); ps.LineTo(m_x[0], m_y[0]); VectorToolBox.GetFreeVxs(out var v1); rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs, v1)); sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160)); VectorToolBox.ReleaseVxs(ref v1); } }
public override void Draw(CanvasPainter p) { //this specific for agg if (p is PixelFarm.Agg.AggCanvasPainter) { PixelFarm.Agg.AggCanvasPainter p2 = (PixelFarm.Agg.AggCanvasPainter)p; Graphics2D gx = p2.Graphics; var childImage = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect()); //IRecieveBlenderByte rasterBlender = new BlenderBGRA(); var rasterGamma = new ChildImage(childImage, new PixelBlenderGammaBGRA(this.GammaValue)); ClipProxyImage clippingProxyNormal = new ClipProxyImage(childImage); ClipProxyImage clippingProxyGamma = new ClipProxyImage(rasterGamma); clippingProxyNormal.Clear(Color.White); var rasterizer = gx.ScanlineRasterizer; var sl = new ScanlineUnpacked8(); int size_mul = this.PixelSize; var sclineToBmpEn2 = new CustomScanlineRasToBmp_EnlargedV2(size_mul, gx.DestActualImage); rasterizer.Reset(); rasterizer.MoveTo(m_x[0] / size_mul, m_y[0] / size_mul); rasterizer.LineTo(m_x[1] / size_mul, m_y[1] / size_mul); rasterizer.LineTo(m_x[2] / size_mul, m_y[2] / size_mul); sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap; sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); //----------------------------------------------------------------------------------------------------------- rasterizer.ResetGamma(new GammaNone()); PathWriter ps = new PathWriter(); ps.Clear(); ps.MoveTo(m_x[0], m_y[0]); ps.LineTo(m_x[1], m_y[1]); ps.LineTo(m_x[2], m_y[2]); ps.LineTo(m_x[0], m_y[0]); var v1 = GetFreeVxs(); rasterizer.AddPath((new Stroke(2)).MakeVxs(ps.Vxs, v1)); sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160)); ReleaseVxs(ref v1); } }
void DrawAsScanline(ClipProxyImage imageClippingProxy, AggRenderSurface aggsx, ScanlineRasterizer rasterizer, ScanlineRasToDestBitmapRenderer sclineRasToBmp) { SvgRenderVx renderVx = lionShape.GetRenderVx(); int num_paths = renderVx.SvgVxCount; for (int i = 0; i < num_paths; ++i) { rasterizer.Reset(); SvgPart svgPart = renderVx.GetInnerVx(i); switch (svgPart.Kind) { case SvgRenderVxKind.Path: { rasterizer.AddPath(new PixelFarm.Drawing.VertexStoreSnap(svgPart.GetVxs(), 0)); sclineRasToBmp.RenderWithColor(imageClippingProxy, rasterizer, aggsx.ScanlinePacked8, new Drawing.Color(255, 0, 0)); } break; } } }
public override void Draw(CanvasPainter p) { if (p is GdiPlusCanvasPainter) { DrawWithWinGdi((GdiPlusCanvasPainter)p); return; } AggCanvasPainter p2 = (AggCanvasPainter)p; Graphics2D gx = p2.Graphics; var widgetsSubImage = gx.DestImage; var scline = gx.ScanlinePacked8; int width = (int)widgetsSubImage.Width; int height = (int)widgetsSubImage.Height; //change value *** if (isMaskSliderValueChanged) { generate_alpha_mask(gx.ScanlineRasToDestBitmap, gx.ScanlinePacked8, gx.ScanlineRasterizer, width, height); this.isMaskSliderValueChanged = false; } var rasterizer = gx.ScanlineRasterizer; rasterizer.SetClipBox(0, 0, width, height); //alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 0, width, height, width, 8, 1); PixelFarm.Agg.Imaging.AlphaMaskAdaptor imageAlphaMaskAdaptor = new PixelFarm.Agg.Imaging.AlphaMaskAdaptor(widgetsSubImage, alphaMask); ClipProxyImage alphaMaskClippingProxy = new ClipProxyImage(imageAlphaMaskAdaptor); ClipProxyImage clippingProxy = new ClipProxyImage(widgetsSubImage); ////Affine transform = Affine.NewIdentity(); ////transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y); ////transform *= Affine.NewScaling(lionScale, lionScale); ////transform *= Affine.NewRotation(angle + Math.PI); ////transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0); ////transform *= Affine.NewTranslation(Width / 2, Height / 2); Affine transform = Affine.NewMatix( AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y), AffinePlan.Scale(lionScale, lionScale), AffinePlan.Rotate(angle + Math.PI), AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0), AffinePlan.Translate(width / 2, height / 2)); clippingProxy.Clear(Drawing.Color.White); ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap; // draw a background to show how the mask is working better int rect_w = 30; var v1 = GetFreeVxs(); for (int i = 0; i < 40; i++) { for (int j = 0; j < 40; j++) { if ((i + j) % 2 != 0) { VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * rect_w, j * rect_w, (i + 1) * rect_w, (j + 1) * rect_w, 0); rect.NormalizeRadius(); // Drawing as an outline rasterizer.AddPath(rect.MakeVxs(v1)); v1.Clear(); sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, scline, Drawing.Color.Make(.9f, .9f, .9f)); } } } ReleaseVxs(ref v1); ////int x, y; //// Render the lion ////VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform); ////var vxlist = new System.Collections.Generic.List<VertexData>(); ////trans.DoTransform(vxlist); var tmpVxs1 = new VertexStore(); transform.TransformToVxs(lionShape.Path.Vxs, tmpVxs1); sclineRasToBmp.RenderSolidAllPaths(alphaMaskClippingProxy, rasterizer, scline, tmpVxs1, lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); ///* //// Render random Bresenham lines and markers //agg::renderer_markers<amask_ren_type> m(r); //for(i = 0; i < 50; i++) //{ // m.line_color(agg::rgba8(randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // (randGenerator.Next() & 0x7F) + 0x7F)); // m.fill_color(agg::rgba8(randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // (randGenerator.Next() & 0x7F) + 0x7F)); // m.line(m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height), // m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height)); // m.marker(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 10 + 5, // agg::marker_e(randGenerator.Next() % agg::end_of_markers)); //} //// Render random anti-aliased lines //double w = 5.0; //agg::line_profile_aa profile; //profile.width(w); //typedef agg::renderer_outline_aa<amask_ren_type> renderer_type; //renderer_type ren(r, profile); //typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type; //rasterizer_type ras(ren); //ras.round_cap(true); //for(i = 0; i < 50; i++) //{ // ren.Color = agg::rgba8(randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // //255)); // (randGenerator.Next() & 0x7F) + 0x7F); // ras.move_to_d(randGenerator.Next() % width, randGenerator.Next() % height); // ras.line_to_d(randGenerator.Next() % width, randGenerator.Next() % height); // ras.render(false); //} //// Render random circles with gradient //typedef agg::gradient_linear_color<color_type> grad_color; //typedef agg::gradient_circle grad_func; //typedef agg::span_interpolator_linear<> interpolator_type; //typedef agg::span_gradient<color_type, // interpolator_type, // grad_func, // grad_color> span_grad_type; //agg::trans_affine grm; //grad_func grf; //grad_color grc(agg::rgba8(0,0,0), agg::rgba8(0,0,0)); //agg::ellipse ell; //agg::span_allocator<color_type> sa; //interpolator_type inter(grm); //span_grad_type sg(inter, grf, grc, 0, 10); //agg::renderer_scanline_aa<amask_ren_type, // agg::span_allocator<color_type>, // span_grad_type> rg(r, sa, sg); //for(i = 0; i < 50; i++) //{ // x = randGenerator.Next() % width; // y = randGenerator.Next() % height; // double r = randGenerator.Next() % 10 + 5; // grm.reset(); // grm *= agg::trans_affine_scaling(r / 10.0); // grm *= agg::trans_affine_translation(x, y); // grm.invert(); // grc.colors(agg::rgba8(255, 255, 255, 0), // agg::rgba8(randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // 255)); // sg.color_function(grc); // ell.init(x, y, r, r, 32); // g_rasterizer.add_path(ell); // agg::render_scanlines(g_rasterizer, g_scanline, rg); //} // */ ////m_num_cb.Render(g_rasterizer, g_scanline, clippingProxy); }
public override void OnDraw(Graphics2D graphics2D) { //render var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect()); int width = widgetsSubImage.Width; int height = widgetsSubImage.Height; int strokeWidth = 1; var clippedSubImage = new ChildImage(widgetsSubImage, new PixelBlenderBGRA()); ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage); imageClippingProxy.Clear(ColorRGBA.White); Affine affTx = Affine.NewMatix( AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y), AffinePlan.Scale(spriteScale, spriteScale), AffinePlan.Rotate(angle + Math.PI), AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0), AffinePlan.Translate(width / 2, height / 2)); //transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y); //transform *= Affine.NewScaling(spriteScale, spriteScale); //transform *= Affine.NewRotation(angle + Math.PI); //transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0); //transform *= Affine.NewTranslation(width / 2, height / 2); if (RenderAsScanline) { var rasterizer = graphics2D.ScanlineRasterizer; rasterizer.SetClipBox(0, 0, width, height); Stroke stroke = new Stroke(strokeWidth); stroke.LineJoin = LineJoin.Round; var vxs = affTx.TransformToVxs(lionShape.Path.Vxs); ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap; sclineRasToBmp.RenderSolidAllPaths( imageClippingProxy, rasterizer, graphics2D.ScanlinePacked8, vxs, lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); } else { double w = strokeWidth * affTx.GetScale(); LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(w, new GammaNone()); OutlineRenderer outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile); OutlineAARasterizer rasterizer = new OutlineAARasterizer(outlineRenderer); rasterizer.LineJoin = (RenderAccurateJoins ? OutlineAARasterizer.OutlineJoin.AccurateJoin : OutlineAARasterizer.OutlineJoin.Round); rasterizer.RoundCap = true; //VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform); var vxs = affTx.TransformToVxs(lionShape.Path.Vxs);// trans.DoTransformToNewVxStorage(); int j = lionShape.NumPaths; for (int i = 0; i < j; ++i) { rasterizer.RenderVertexSnap( new VertexStoreSnap(vxs, lionShape.PathIndexList[i]), lionShape.Colors[i]); } } base.OnDraw(graphics2D); }
public override void Draw(PixelFarm.Drawing.Painter p) { int strokeWidth = 1; int width = p.Width; int height = p.Height; Affine affTx = Affine.NewMatix( AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y), AffinePlan.Scale(spriteScale, spriteScale), AffinePlan.Rotate(angle + Math.PI), AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0), AffinePlan.Translate(width / 2, height / 2)); var p1 = p as AggPainter; if (p1 == null) { int j = lionShape.NumPaths; int[] pathList = lionShape.PathIndexList; Drawing.Color[] colors = lionShape.Colors; //graphics2D.UseSubPixelRendering = true; var vxs = GetFreeVxs(); affTx.TransformToVxs(lionShape.Vxs, vxs); p.StrokeWidth = 1; for (int i = 0; i < j; ++i) { p.StrokeColor = colors[i]; p.Draw(new PixelFarm.Drawing.VertexStoreSnap(vxs, pathList[i])); } //not agg Release(ref vxs); return; //** } if (UseBitmapExt) { p.RenderQuality = Drawing.RenderQualtity.Fast; int j = lionShape.NumPaths; int[] pathList = lionShape.PathIndexList; Drawing.Color[] colors = lionShape.Colors; p.Clear(Drawing.Color.White); var vxs = GetFreeVxs(); var vxs2 = stroke1.MakeVxs(affTx.TransformToVxs(lionShape.Vxs, vxs), GetFreeVxs()); p.StrokeWidth = 1; for (int i = 0; i < j; ++i) { p.StrokeColor = colors[i]; p.Draw(new PixelFarm.Drawing.VertexStoreSnap(vxs2, pathList[i])); } //not agg Release(ref vxs); Release(ref vxs2); return; //** } else { p.RenderQuality = Drawing.RenderQualtity.HighQuality; } //----------------------- AggRenderSurface aggsx = p1.RenderSurface; //var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect()); //int width = widgetsSubImage.Width; //int height = widgetsSubImage.Height; SubImageRW widgetsSubImage = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect()); SubImageRW clippedSubImage = new SubImageRW(widgetsSubImage, new PixelBlenderBGRA()); ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage); imageClippingProxy.Clear(PixelFarm.Drawing.Color.White); if (RenderAsScanline) { var rasterizer = aggsx.ScanlineRasterizer; rasterizer.SetClipBox(0, 0, width, height); //Stroke stroke = new Stroke(strokeWidth); //stroke.LineJoin = LineJoin.Round; var vxs = GetFreeVxs(); affTx.TransformToVxs(lionShape.Vxs, vxs); ScanlineRasToDestBitmapRenderer sclineRasToBmp = aggsx.ScanlineRasToDestBitmap; sclineRasToBmp.RenderSolidAllPaths( imageClippingProxy, rasterizer, aggsx.ScanlinePacked8, vxs, lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); Release(ref vxs); } else { //LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), new GammaNone()); LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), null); OutlineRenderer outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile); OutlineAARasterizer rasterizer = new OutlineAARasterizer(outlineRenderer); rasterizer.LineJoin = (RenderAccurateJoins ? OutlineAARasterizer.OutlineJoin.AccurateJoin : OutlineAARasterizer.OutlineJoin.Round); rasterizer.RoundCap = true; //VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform); var vxs = GetFreeVxs(); affTx.TransformToVxs(lionShape.Vxs, vxs);// trans.DoTransformToNewVxStorage(); int j = lionShape.NumPaths; for (int i = 0; i < j; ++i) { rasterizer.RenderVertexSnap( new PixelFarm.Drawing.VertexStoreSnap(vxs, lionShape.PathIndexList[i]), lionShape.Colors[i]); } Release(ref vxs); } base.Draw(p); }