void generate_alpha_mask(ScanlineRasToDestBitmapRenderer sclineRasToBmp, ScanlinePacked8 sclnPack, ScanlineRasterizer rasterizer, int width, int height) { //create 1 8-bits chanel (grayscale8) bmp alphaBitmap = new ActualImage(width, height, PixelFormat.GrayScale8); var bmpReaderWrtier = new MyImageReaderWriter(); bmpReaderWrtier.ReloadImage(alphaBitmap); alphaMaskImageBuffer = new SubImageRW(bmpReaderWrtier, new PixelBlenderGray(1)); //create mask from alpahMaskImageBuffer 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 SubImageRW(alphaMaskImageBuffer, new PixelBlenderGray(1), 1, 0, 8); ClipProxyImage clippingProxy = new ClipProxyImage(image); clippingProxy.Clear(Drawing.Color.Black); VertexSource.Ellipse ellipseForMask = new PixelFarm.Agg.VertexSource.Ellipse(); System.Random randGenerator = new Random(1432); int i; int num = (int)maskAlphaSliderValue; VectorToolBox.GetFreeVxs(out var v1); for (i = 0; i < num; i++) { if (i == num - 1) { //for the last one ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100); rasterizer.AddPath(ellipseForMask.MakeVertexSnap(v1)); v1.Clear(); sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new Color(255, 0, 0, 0)); ellipseForMask.Reset(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100); rasterizer.AddPath(ellipseForMask.MakeVertexSnap(v1)); v1.Clear(); sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new Color(255, 255, 0, 0)); } 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(v1)); v1.Clear(); sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, ColorEx.Make((int)((float)i / (float)num * 255), 0, 0, 255)); } } VectorToolBox.ReleaseVxs(ref v1); }
void CreateAndRenderCombined(Painter p, VertexStore vxsSnap1, VertexStore vxsSnap2) { //TODO: review here again. List <VertexStore> resultPolygons = new List <VertexStore>(); PolygonClippingDemoHelper.CreateAndRenderCombined(vxsSnap1, vxsSnap2, OpOption, false, resultPolygons); if (resultPolygons.Count > 0) { //draw combine result p.Fill(resultPolygons[0], ColorEx.Make(0.5f, 0.0f, 0f, 0.5f)); } }
void CreateAndRenderCombined(Painter p, VertexStoreSnap ps1, VertexStoreSnap ps2) { List <VertexStore> combined = null; switch (this.OpOption) { default: throw new NotSupportedException(); case OperationOption.None: return; case OperationOption.OR: combined = VxsClipper.CombinePaths(ps1, ps2, VxsClipperType.Union, false); break; case OperationOption.AND: combined = VxsClipper.CombinePaths(ps1, ps2, VxsClipperType.InterSect, false); break; case OperationOption.XOR: combined = VxsClipper.CombinePaths(ps1, ps2, VxsClipperType.Xor, false); break; case OperationOption.A_B: combined = VxsClipper.CombinePaths(ps1, ps2, VxsClipperType.Difference, false); break; case OperationOption.B_A: combined = VxsClipper.CombinePaths(ps2, ps1, VxsClipperType.Difference, false); break; } if (combined != null) { p.FillColor = ColorEx.Make(0.5f, 0.0f, 0f, 0.5f); p.Fill(new VertexStoreSnap(combined[0])); //graphics2D.Render(new VertexStoreSnap(combined[0]), ColorRGBAf.MakeColorRGBA(0.5f, 0.0f, 0f, 0.5f)); } }
void RenderPolygon(Painter p) { switch (this.PolygonSet) { case PolygonExampleSet.TwoSimplePaths: { //------------------------------------ // Two simple paths using (Tools.BorrowVxs(out var v1, out var v2)) { double x = _x - Width / 2 + 100; double y = _y - Height / 2 + 100; PolygonClippingDemoHelper.WritePath1(v1, x, y); PolygonClippingDemoHelper.WritePath2(v2, x, y); p.Fill(v1, ColorEx.Make(0f, 0f, 0f, 0.1f)); p.Fill(v2, ColorEx.Make(0f, 0.6f, 0f, 0.1f)); CreateAndRenderCombined(p, v1, v2); } } break; case PolygonExampleSet.CloseStroke: { //------------------------------------ // Closed stroke using (Tools.BorrowVxs(out var v1, out var v2)) { double x = _x - Width / 2 + 100; double y = _y - Height / 2 + 100; PolygonClippingDemoHelper.WritePath1(v1, x, y); PolygonClippingDemoHelper.WritePath2(v2, x, y); p.FillStroke(v1, 2, ColorEx.Make(0f, 0f, 0f, 0.1f)); p.FillStroke(v2, 3, ColorEx.Make(0f, 0.6f, 0f, 0.1f)); CreateAndRenderCombined(p, v1, v2); } } break; case PolygonExampleSet.GBAndArrow: { //------------------------------------ // Great Britain and Arrows using (Tools.BorrowVxs(out var v1_gb_poly, out var v2_arrows)) { AffineMat mat1 = AffineMat.Iden(); mat1.Translate(-1150, -1150); mat1.Scale(2); Affine mtx1 = new Affine(mat1); PolygonClippingDemoHelper.WriteGBObject(v1_gb_poly, 0, 0, mtx1); p.Fill(v1_gb_poly, ColorEx.Make(0.5f, 0.5f, 0f, 0.1f)); p.FillStroke(v1_gb_poly, 0.1f, ColorEx.Make(0, 0, 0)); // Affine mtx2 = mtx1 * Affine.NewTranslation(_x - Width / 2, _y - Height / 2); PolygonClippingDemoHelper.WriteArrow(v2_arrows, 0, 0, mtx2); p.Fill(v2_arrows, ColorEx.Make(0f, 0.5f, 0.5f, 0.1f)); CreateAndRenderCombined(p, v1_gb_poly, v2_arrows); } } break; case PolygonExampleSet.GBAndSpiral: { //------------------------------------ // Great Britain and a Spiral // using (Tools.BorrowVxs(out var v1_gb_poly)) using (Tools.BorrowVxs(out var v2_spiral, out var v2_spiral_outline)) using (Tools.BorrowStroke(out var stroke)) { AffineMat mat = AffineMat.Iden(); mat.Translate(-1150, -1150); mat.Scale(2); Affine mtx = new Affine(mat); PolygonClippingDemoHelper.WriteGBObject(v1_gb_poly, 0, 0, mtx); PolygonClippingDemoHelper.WriteSpiral(v2_spiral, _x, _y); p.Fill(v1_gb_poly, ColorEx.Make(0.5f, 0.5f, 0f, 0.1f)); p.FillStroke(v1_gb_poly, 0.1f, Color.Black); stroke.Width = 15; p.Fill(stroke.MakeVxs(v2_spiral, v2_spiral_outline), ColorEx.Make(0.0f, 0.5f, 0.5f, 0.1f)); CreateAndRenderCombined(p, v1_gb_poly, v2_spiral_outline); } } break; case PolygonExampleSet.SprialAndGlyph: { //------------------------------------ // Spiral and glyph using (Tools.BorrowVxs(out var v1_spiral, out var v1_spiralOutline, out var v3)) using (Tools.BorrowVxs(out var glyph_vxs)) using (Tools.BorrowStroke(out var stroke)) { //Affine mtx = Affine.New( // AffinePlan.Scale(4), // AffinePlan.Translate(220, 200)); AffineMat mat = AffineMat.Iden(); mat.Scale(4); mat.Translate(220, 200); PolygonClippingDemoHelper.WriteSpiral(v1_spiral, _x, _y); PolygonClippingDemoHelper.WriteGlyphObj(glyph_vxs, 0, 0, new Affine(mat)); //----------------------------------------- stroke.Width = 1; stroke.MakeVxs(v1_spiral, v1_spiralOutline); CreateAndRenderCombined(p, v1_spiralOutline, glyph_vxs); p.Fill(v1_spiralOutline, ColorEx.Make(0f, 0f, 0f, 0.1f)); p.Fill(glyph_vxs, ColorEx.Make(0f, 0.6f, 0f, 0.1f)); } } break; } }
public override void Draw(Painter p) { Painter painter = p; if (!_didInit) { _didInit = true; OnInitialize(); } //----------------------------------- painter.Clear(Drawing.Color.White); //lionFill.Render(painter); //IBitmapBlender backBuffer = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect()); //ChildImage image; //if (backBuffer.BitDepth == 32) //{ // image = new ChildImage(backBuffer, new PixelBlenderBGRA()); //} //else //{ // if (backBuffer.BitDepth != 24) // { // throw new System.NotSupportedException(); // } // image = new ChildImage(backBuffer, new PixelBlenderBGR()); //} //ClipProxyImage dest = new ClipProxyImage(image); //gx.Clear(ColorRGBA.White); //gx.SetClippingRect(new RectInt(0, 0, Width, Height)); //ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap; //----------------------------------- RectD lionBound = _lionShape.Bounds; if (!_setQuadLion) { _quadPolygonControl.SetXN(0, lionBound.Left); _quadPolygonControl.SetYN(0, lionBound.Top); _quadPolygonControl.SetXN(1, lionBound.Right); _quadPolygonControl.SetYN(1, lionBound.Top); _quadPolygonControl.SetXN(2, lionBound.Right); _quadPolygonControl.SetYN(2, lionBound.Bottom); _quadPolygonControl.SetXN(3, lionBound.Left); _quadPolygonControl.SetYN(3, lionBound.Bottom); _setQuadLion = true; } // // //Bilinear txBilinear = Bilinear.RectToQuad(lionBound.Left, // lionBound.Bottom, // lionBound.Right, // lionBound.Top, // quadPolygonControl.GetInnerCoords()); //Ellipse ell = new Ellipse((lionBound.Left + lionBound.Right) * 0.5, // (lionBound.Bottom + lionBound.Top) * 0.5, // (lionBound.Right - lionBound.Left) * 0.5, // (lionBound.Top - lionBound.Bottom) * 0.5, // 200); //var v1 = new VertexStore(); //var trans_ell = new VertexStore(); //txBilinear.TransformToVxs(ell.MakeVxs(v1), trans_ell); ////ell.MakeVxs(v1); //painter.FillColor = ColorEx.Make(0.5f, 0.3f, 0.0f, 0.3f); //painter.Fill(trans_ell); ////outline //double prevStrokeWidth = painter.StrokeWidth; //painter.StrokeWidth = 3; //painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f); //painter.Draw(trans_ell); //painter.StrokeWidth = prevStrokeWidth; if (this.PerspectiveTransformType == Sample_Perspective.PerspectiveTransformType.Bilinear) { RectD bound = lionBound; //transform from original lionBounds to quadPolygon Bilinear txBilinear = Bilinear.RectToQuad( bound.Left, bound.Top, bound.Right, bound.Bottom, _quadPolygonControl.GetInnerCoords()); if (txBilinear.IsValid) { using (VxsTemp.Borrow(out var trans_ell_vxs)) using (VectorToolBox.Borrow(out Ellipse ellipse)) { _lionShape.Paint(painter, txBilinear); //transform before draw // ellipse.Set((lionBound.Left + lionBound.Right) * 0.5, (lionBound.Bottom + lionBound.Top) * 0.5, (lionBound.Right - lionBound.Left) * 0.5, (lionBound.Top - lionBound.Bottom) * 0.5); //ellipse=> transform coord with tx => fill to output ellipse.MakeVxs(txBilinear, trans_ell_vxs); painter.FillColor = _ellipseColor; painter.Fill(trans_ell_vxs); //------------------------------------------------------------- //outline double prevStrokeWidth = painter.StrokeWidth; painter.StrokeWidth = 3; painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f); painter.Draw(trans_ell_vxs); painter.StrokeWidth = prevStrokeWidth; } } } else { RectD r = lionBound; //var txPerspective = new Perspective( // r.Left, r.Bottom, r.Right, r.Top, // quadPolygonControl.GetInnerCoords()); var txPerspective = new Perspective( r.Left, r.Top, r.Right, r.Bottom, _quadPolygonControl.GetInnerCoords()); if (txPerspective.IsValid) { //lionFill.Draw(p); //lionShape.Paint(p, txPerspective); //transform -> paint //painter.PaintSeries(txPerspective.TransformToVxs(lionShape.Vxs, v1), // lionShape.Colors, // lionShape.PathIndexList, // lionShape.NumPaths); //-------------------------------------------------------------------------------------- //filled Ellipse //1. create original fill ellipse //RectD lionBound = lionShape.Bounds; using (VectorToolBox.Borrow(out Ellipse filledEllipse)) using (VxsTemp.Borrow(out var trans_ell_vxs)) { filledEllipse.Set((lionBound.Left + lionBound.Right) * 0.5, (lionBound.Bottom + lionBound.Top) * 0.5, (lionBound.Right - lionBound.Left) * 0.5, (lionBound.Top - lionBound.Bottom) * 0.5, 200); _lionShape.Paint(painter, txPerspective); //ellipse=> transform coord with tx => fill to output filledEllipse.MakeVxs(txPerspective, trans_ell_vxs); painter.FillColor = ColorEx.Make(0.5f, 0.3f, 0.0f, 0.3f); painter.Fill(trans_ell_vxs); //-------------------------------------------------------- double prevStrokeW = painter.StrokeWidth; painter.StrokeWidth = 3; painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f); painter.Draw(trans_ell_vxs); painter.StrokeWidth = prevStrokeW; } } //} ////-------------------------- //// Render the "quad" tool and controls //painter.FillColor = ColorEx.Make(0f, 0.3f, 0.5f, 0.6f); //VectorToolBox.GetFreeVxs(out var v4); //painter.Fill(quadPolygonControl.MakeVxs(v4)); //VectorToolBox.ReleaseVxs(ref v4); } }
//template<class Scanline, class Ras> public void RenderGourand(Painter p) { float alpha = this.AlphaValue; float brc = 1; #if SourceDepth24 pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr()); #else #endif ////var destImage = gx.DestImage; ////span_allocator span_alloc = new span_allocator(); //specific for agg AggPainter painter = p as AggPainter; if (painter == null) { return; } // AggRenderSurface aggsx = painter.RenderSurface; RGBAGouraudSpanGen gouraudSpanGen = new RGBAGouraudSpanGen(); GouraudVerticeBuilder grBuilder = new GouraudVerticeBuilder(); aggsx.ScanlineRasterizer.ResetGamma(new GammaLinear(0.0f, this.LinearGamma)); grBuilder.DilationValue = (float)this.DilationValue; // Six triangles double xc = (_x[0] + _x[1] + _x[2]) / 3.0; double yc = (_y[0] + _y[1] + _y[2]) / 3.0; double x1 = (_x[1] + _x[0]) / 2 - (xc - (_x[1] + _x[0]) / 2); double y1 = (_y[1] + _y[0]) / 2 - (yc - (_y[1] + _y[0]) / 2); double x2 = (_x[2] + _x[1]) / 2 - (xc - (_x[2] + _x[1]) / 2); double y2 = (_y[2] + _y[1]) / 2 - (yc - (_y[2] + _y[1]) / 2); double x3 = (_x[0] + _x[2]) / 2 - (xc - (_x[0] + _x[2]) / 2); double y3 = (_y[0] + _y[2]) / 2 - (yc - (_y[0] + _y[2]) / 2); grBuilder.SetColor(ColorEx.Make(1, 0, 0, alpha), ColorEx.Make(0, 1, 0, alpha), ColorEx.Make(brc, brc, brc, alpha)); grBuilder.SetTriangle(_x[0], _y[0], _x[1], _y[1], xc, yc); GouraudVerticeBuilder.CoordAndColor c0, c1, c2; grBuilder.GetArrangedVertices(out c0, out c1, out c2); gouraudSpanGen.SetColorAndCoords(c0, c1, c2); using (Tools.BorrowVxs(out var v1)) { painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen); v1.Clear(); // grBuilder.SetColor( ColorEx.Make(0, 1, 0, alpha), ColorEx.Make(0, 0, 1, alpha), ColorEx.Make(brc, brc, brc, alpha)); grBuilder.SetTriangle(_x[1], _y[1], _x[2], _y[2], xc, yc); grBuilder.GetArrangedVertices(out c0, out c1, out c2); gouraudSpanGen.SetColorAndCoords(c0, c1, c2); painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen); v1.Clear(); // grBuilder.SetColor(ColorEx.Make(0, 0, 1, alpha), ColorEx.Make(1, 0, 0, alpha), ColorEx.Make(brc, brc, brc, alpha)); grBuilder.SetTriangle(_x[2], _y[2], _x[0], _y[0], xc, yc); grBuilder.GetArrangedVertices(out c0, out c1, out c2); gouraudSpanGen.SetColorAndCoords(c0, c1, c2); painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen); v1.Clear(); // brc = 1 - brc; grBuilder.SetColor(ColorEx.Make(1, 0, 0, alpha), ColorEx.Make(0, 1, 0, alpha), ColorEx.Make(brc, brc, brc, alpha)); grBuilder.SetTriangle(_x[0], _y[0], _x[1], _y[1], x1, y1); grBuilder.GetArrangedVertices(out c0, out c1, out c2); gouraudSpanGen.SetColorAndCoords(c0, c1, c2); painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen); v1.Clear(); grBuilder.SetColor(ColorEx.Make(0, 1, 0, alpha), ColorEx.Make(0, 0, 1, alpha), ColorEx.Make(brc, brc, brc, alpha)); grBuilder.SetTriangle(_x[1], _y[1], _x[2], _y[2], x2, y2); grBuilder.GetArrangedVertices(out c0, out c1, out c2); gouraudSpanGen.SetColorAndCoords(c0, c1, c2); painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen); v1.Clear(); // grBuilder.SetColor(ColorEx.Make(0, 0, 1, alpha), ColorEx.Make(1, 0, 0, alpha), ColorEx.Make(brc, brc, brc, alpha)); grBuilder.SetTriangle(_x[2], _y[2], _x[0], _y[0], x3, y3); grBuilder.GetArrangedVertices(out c0, out c1, out c2); gouraudSpanGen.SetColorAndCoords(c0, c1, c2); painter.Fill(grBuilder.MakeVxs(v1), gouraudSpanGen); v1.Clear(); } }
void render_gpc(Painter p) { switch (this.PolygonSet) { case PolygonExampleSet.TwoSimplePaths: { //------------------------------------ // Two simple paths // PathWriter ps1 = new PathWriter(); PathWriter ps2 = new PathWriter(); double x = m_x - Width / 2 + 100; double y = m_y - Height / 2 + 100; ps1.MoveTo(x + 140, y + 145); ps1.LineTo(x + 225, y + 44); ps1.LineTo(x + 296, y + 219); ps1.CloseFigure(); // ps1.LineTo(x + 226, y + 289); ps1.LineTo(x + 82, y + 292); // ps1.MoveTo(x + 220, y + 222); ps1.LineTo(x + 363, y + 249); ps1.LineTo(x + 265, y + 331); ps1.MoveTo(x + 242, y + 243); ps1.LineTo(x + 268, y + 309); ps1.LineTo(x + 325, y + 261); ps1.MoveTo(x + 259, y + 259); ps1.LineTo(x + 273, y + 288); ps1.LineTo(x + 298, y + 266); ps1.CloseFigure(); // ps2.MoveTo(100 + 32, 100 + 77); ps2.LineTo(100 + 473, 100 + 263); ps2.LineTo(100 + 351, 100 + 290); ps2.LineTo(100 + 354, 100 + 374); ps2.CloseFigure(); p.FillColor = ColorEx.Make(0f, 0f, 0f, 0.1f); p.Fill(ps1.MakeVertexSnap()); p.FillColor = ColorEx.Make(0f, 0.6f, 0f, 0.1f); p.Fill(ps2.MakeVertexSnap()); CreateAndRenderCombined(p, ps1.MakeVertexSnap(), ps2.MakeVertexSnap()); } break; case PolygonExampleSet.CloseStroke: { //------------------------------------ // Closed stroke // PathWriter ps1 = new PathWriter(); PathWriter ps2 = new PathWriter(); Stroke stroke = new Stroke(1); stroke.Width = 10; double x = m_x - Width / 2 + 100; double y = m_y - Height / 2 + 100; //----------------------------------------- ps1.MoveTo(x + 140, y + 145); ps1.LineTo(x + 225, y + 44); ps1.LineTo(x + 296, y + 219); ps1.CloseFigure(); ps1.LineTo(x + 226, y + 289); ps1.LineTo(x + 82, y + 292); ps1.MoveTo(x + 220 - 50, y + 222); ps1.LineTo(x + 265 - 50, y + 331); ps1.LineTo(x + 363 - 50, y + 249); ps1.CloseFigureCCW(); //----------------------------------------- ps2.MoveTo(100 + 32, 100 + 77); ps2.LineTo(100 + 473, 100 + 263); ps2.LineTo(100 + 351, 100 + 290); ps2.LineTo(100 + 354, 100 + 374); ps2.CloseFigure(); p.FillColor = ColorEx.Make(0f, 0f, 0f, 0.1f); p.Fill(ps1.MakeVertexSnap()); //graphics2D.Render(ps1.MakeVertexSnap(), ColorRGBAf.MakeColorRGBA(0f, 0f, 0f, 0.1f)); var vxs = ps2.Vxs; //graphics2D.Render(stroke.MakeVxs(vxs), ColorRGBAf.MakeColorRGBA(0f, 0.6f, 0f, 0.1f)); p.FillColor = ColorEx.Make(0f, 0.6f, 0f, 0.1f); VectorToolBox.GetFreeVxs(out var v1); p.Fill(stroke.MakeVxs(vxs, v1)); VectorToolBox.ReleaseVxs(ref v1); CreateAndRenderCombined(p, ps1.MakeVertexSnap(), new VertexStoreSnap(vxs)); } break; case PolygonExampleSet.GBAndArrow: { //------------------------------------ // Great Britain and Arrows // PathWriter gb_poly = new PathWriter(); PathWriter arrows = new PathWriter(); PixelFarm.Agg.Sample_PolygonClipping.GreatBritanPathStorage.Make(gb_poly); make_arrows(arrows); //Affine mtx1 = Affine.NewIdentity(); //mtx1 *= Affine.NewTranslation(-1150, -1150); //mtx1 *= Affine.NewScaling(2.0); Affine mtx1 = Affine.NewMatix( AffinePlan.Translate(-1150, -1150), AffinePlan.Scale(2) ); //Affine.NewIdentity(); //mtx2 = mtx1; //mtx2 *= Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2); Affine mtx2 = mtx1 * Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2); //VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1); //VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx2); var trans_gb_poly = new VertexStore(); mtx1.TransformToVxs(gb_poly.Vxs, trans_gb_poly); var trans_arrows = new VertexStore(); mtx2.TransformToVxs(arrows.Vxs, trans_arrows); p.FillColor = ColorEx.Make(0.5f, 0.5f, 0f, 0.1f); p.Fill(trans_gb_poly); //graphics2D.Render(trans_gb_poly, ColorRGBAf.MakeColorRGBA(0.5f, 0.5f, 0f, 0.1f)); //stroke_gb_poly.Width = 0.1; p.FillColor = ColorEx.Make(0, 0, 0); VectorToolBox.GetFreeVxs(out var v1); p.Fill(new Stroke(0.1).MakeVxs(trans_gb_poly, v1)); VectorToolBox.ReleaseVxs(ref v1); //graphics2D.Render(new Stroke(0.1).MakeVxs(trans_gb_poly), ColorRGBAf.MakeColorRGBA(0, 0, 0)); //graphics2D.Render(trans_arrows, ColorRGBAf.MakeColorRGBA(0f, 0.5f, 0.5f, 0.1f)); p.FillColor = ColorEx.Make(0f, 0.5f, 0.5f, 0.1f); p.Fill(trans_arrows); CreateAndRenderCombined(p, new VertexStoreSnap(trans_gb_poly), new VertexStoreSnap(trans_arrows)); } break; case PolygonExampleSet.GBAndSpiral: { //------------------------------------ // Great Britain and a Spiral // spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0); PathWriter gb_poly = new PathWriter(); PixelFarm.Agg.Sample_PolygonClipping.GreatBritanPathStorage.Make(gb_poly); Affine mtx = Affine.NewMatix( AffinePlan.Translate(-1150, -1150), AffinePlan.Scale(2)); // VectorToolBox.GetFreeVxs(out var s1, out var v1); VectorToolBox.GetFreeVxs(out var v2, out var v3); mtx.TransformToVxs(gb_poly.Vxs, s1); p.FillColor = ColorEx.Make(0.5f, 0.5f, 0f, 0.1f); p.Fill(s1); //graphics2D.Render(s1, ColorRGBAf.MakeColorRGBA(0.5f, 0.5f, 0f, 0.1f)); //graphics2D.Render(new Stroke(0.1).MakeVxs(s1), ColorRGBA.Black); p.FillColor = Color.Black; p.Fill(new Stroke(0.1).MakeVxs(s1, v1)); var stroke_vxs = new Stroke(15).MakeVxs(sp.MakeVxs(v2), v3); p.FillColor = ColorEx.Make(0.0f, 0.5f, 0.5f, 0.1f); // XUolorRXBAf.MakeColorRGBA(0.0f, 0.5f, 0.5f, 0.1f); p.Fill(stroke_vxs); //graphics2D.Render(stroke_vxs, ColorRGBAf.MakeColorRGBA(0.0f, 0.5f, 0.5f, 0.1f)); CreateAndRenderCombined(p, new VertexStoreSnap(s1), new VertexStoreSnap(stroke_vxs)); VectorToolBox.ReleaseVxs(ref s1, ref v1); VectorToolBox.ReleaseVxs(ref v2, ref v3); } break; case PolygonExampleSet.SprialAndGlyph: { //------------------------------------ // Spiral and glyph // spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0); Stroke stroke = new Stroke(15); PathWriter glyph = new PathWriter(); glyph.MoveTo(28.47, 6.45); glyph.Curve3(21.58, 1.12, 19.82, 0.29); glyph.Curve3(17.19, -0.93, 14.21, -0.93); glyph.Curve3(9.57, -0.93, 6.57, 2.25); glyph.Curve3(3.56, 5.42, 3.56, 10.60); glyph.Curve3(3.56, 13.87, 5.03, 16.26); glyph.Curve3(7.03, 19.58, 11.99, 22.51); glyph.Curve3(16.94, 25.44, 28.47, 29.64); glyph.LineTo(28.47, 31.40); glyph.Curve3(28.47, 38.09, 26.34, 40.58); glyph.Curve3(24.22, 43.07, 20.17, 43.07); glyph.Curve3(17.09, 43.07, 15.28, 41.41); glyph.Curve3(13.43, 39.75, 13.43, 37.60); glyph.LineTo(13.53, 34.77); glyph.Curve3(13.53, 32.52, 12.38, 31.30); glyph.Curve3(11.23, 30.08, 9.38, 30.08); glyph.Curve3(7.57, 30.08, 6.42, 31.35); glyph.Curve3(5.27, 32.62, 5.27, 34.81); glyph.Curve3(5.27, 39.01, 9.57, 42.53); glyph.Curve3(13.87, 46.04, 21.63, 46.04); glyph.Curve3(27.59, 46.04, 31.40, 44.04); glyph.Curve3(34.28, 42.53, 35.64, 39.31); glyph.Curve3(36.52, 37.21, 36.52, 30.71); glyph.LineTo(36.52, 15.53); glyph.Curve3(36.52, 9.13, 36.77, 7.69); glyph.Curve3(37.01, 6.25, 37.57, 5.76); glyph.Curve3(38.13, 5.27, 38.87, 5.27); glyph.Curve3(39.65, 5.27, 40.23, 5.62); glyph.Curve3(41.26, 6.25, 44.19, 9.18); glyph.LineTo(44.19, 6.45); glyph.Curve3(38.72, -0.88, 33.74, -0.88); glyph.Curve3(31.35, -0.88, 29.93, 0.78); glyph.Curve3(28.52, 2.44, 28.47, 6.45); glyph.CloseFigure(); glyph.MoveTo(28.47, 9.62); glyph.LineTo(28.47, 26.66); glyph.Curve3(21.09, 23.73, 18.95, 22.51); glyph.Curve3(15.09, 20.36, 13.43, 18.02); glyph.Curve3(11.77, 15.67, 11.77, 12.89); glyph.Curve3(11.77, 9.38, 13.87, 7.06); glyph.Curve3(15.97, 4.74, 18.70, 4.74); glyph.Curve3(22.41, 4.74, 28.47, 9.62); glyph.CloseFigure(); //Affine mtx = Affine.NewIdentity(); //mtx *= Affine.NewScaling(4.0); //mtx *= Affine.NewTranslation(220, 200); Affine mtx = Affine.NewMatix( AffinePlan.Scale(4), AffinePlan.Translate(220, 200)); var t_glyph = new VertexStore(); mtx.TransformToVertexSnap(glyph.Vxs, t_glyph); VectorToolBox.GetFreeVxs(out var v1, out var v2, out var v3); var sp1 = stroke.MakeVxs(sp.MakeVxs(v1), v2); var curveVxs = new VertexStore(); curveFlattener.MakeVxs(t_glyph, curveVxs); CreateAndRenderCombined(p, new VertexStoreSnap(sp1), new VertexStoreSnap(curveVxs)); p.FillColor = ColorEx.Make(0f, 0f, 0f, 0.1f); p.Fill(stroke.MakeVxs(sp1, v3)); //graphics2D.Render(stroke.MakeVxs(sp1), ColorRGBAf.MakeColorRGBA(0f, 0f, 0f, 0.1f)); p.FillColor = ColorEx.Make(0f, 0.6f, 0f, 0.1f); p.Fill(curveVxs); //graphics2D.Render(curveVxs, ColorRGBAf.MakeColorRGBA(0f, 0.6f, 0f, 0.1f)); VectorToolBox.ReleaseVxs(ref v1, ref v2, ref v3); } break; } }
public override void Draw(Painter p) { Painter painter = p; if (!didInit) { didInit = true; OnInitialize(); } //----------------------------------- painter.Clear(Drawing.Color.White); //IImageReaderWriter backBuffer = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect()); //ChildImage image; //if (backBuffer.BitDepth == 32) //{ // image = new ChildImage(backBuffer, new PixelBlenderBGRA()); //} //else //{ // if (backBuffer.BitDepth != 24) // { // throw new System.NotSupportedException(); // } // image = new ChildImage(backBuffer, new PixelBlenderBGR()); //} //ClipProxyImage dest = new ClipProxyImage(image); //gx.Clear(ColorRGBA.White); //gx.SetClippingRect(new RectInt(0, 0, Width, Height)); //ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap; if (this.PerspectiveTransformType == Sample_Perspective.PerspectiveTransformType.Bilinear) { var bound = lionShape.Bounds; Bilinear txBilinear = Bilinear.RectToQuad(bound.Left, bound.Bottom, bound.Right, bound.Top, quadPolygonControl.GetInnerCoords()); if (txBilinear.IsValid) { var v3 = GetFreeVxs(); painter.PaintSeries(txBilinear.TransformToVxs(lionShape.Vxs, v3), lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); RectD lionBound = lionShape.Bounds; Ellipse ell = new Ellipse((lionBound.Left + lionBound.Right) * 0.5, (lionBound.Bottom + lionBound.Top) * 0.5, (lionBound.Right - lionBound.Left) * 0.5, (lionBound.Top - lionBound.Bottom) * 0.5, 200); ReleaseVxs(ref v3); var v1 = GetFreeVxs(); var trans_ell = GetFreeVxs(); txBilinear.TransformToVxs(ell.MakeVxs(v1), trans_ell); painter.FillColor = ColorEx.Make(0.5f, 0.3f, 0.0f, 0.3f); painter.Fill(trans_ell); //------------------------------------------------------------- //outline double prevStrokeWidth = painter.StrokeWidth; painter.StrokeWidth = 3; painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f); painter.Draw(trans_ell); painter.StrokeWidth = prevStrokeWidth; ReleaseVxs(ref v1); ReleaseVxs(ref trans_ell); } } else { RectD r = lionShape.Bounds; var txPerspective = new Perspective( r.Left, r.Bottom, r.Right, r.Top, quadPolygonControl.GetInnerCoords()); if (txPerspective.IsValid) { var v1 = GetFreeVxs(); painter.PaintSeries(txPerspective.TransformToVxs(lionShape.Vxs, v1), lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); //-------------------------------------------------------------------------------------- //filled Ellipse //1. create original fill ellipse RectD lionBound = lionShape.Bounds; var filledEllipse = new Ellipse((lionBound.Left + lionBound.Right) * 0.5, (lionBound.Bottom + lionBound.Top) * 0.5, (lionBound.Right - lionBound.Left) * 0.5, (lionBound.Top - lionBound.Bottom) * 0.5, 200); VertexStore v2 = GetFreeVxs(); VertexStore transformedEll = GetFreeVxs(); txPerspective.TransformToVxs(filledEllipse.MakeVxs(v2), transformedEll); painter.FillColor = ColorEx.Make(0.5f, 0.3f, 0.0f, 0.3f); painter.Fill(transformedEll); //-------------------------------------------------------- var prevStrokeW = painter.StrokeWidth; painter.StrokeWidth = 3; painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f); painter.Draw(transformedEll); painter.StrokeWidth = prevStrokeW; ReleaseVxs(ref v2); ReleaseVxs(ref v1); ReleaseVxs(ref transformedEll); } } //-------------------------- // Render the "quad" tool and controls painter.FillColor = ColorEx.Make(0f, 0.3f, 0.5f, 0.6f); var v4 = GetFreeVxs(); painter.Fill(quadPolygonControl.MakeVxs(v4)); ReleaseVxs(ref v4); }
void GenerateMaskWithWinGdiPlus(int w, int h) { //1. create 32 bits for mask image this.a_alphaBmp = new System.Drawing.Bitmap(w, h); //2. create graphics based on a_alphaBmp using (System.Drawing.Graphics gfxBmp = System.Drawing.Graphics.FromImage(a_alphaBmp)) { gfxBmp.Clear(System.Drawing.Color.Black); //ClipProxyImage clippingProxy = new ClipProxyImage(image); //clippingProxy.Clear(ColorRGBA.Black); VertexSource.Ellipse ellipseForMask = new PixelFarm.Agg.VertexSource.Ellipse(); System.Random randGenerator = new Random(1432); int num = (int)maskAlphaSliderValue; int lim = num - 1; for (int i = 0; i < lim; ++i) { ellipseForMask.Reset(randGenerator.Next() % w, randGenerator.Next() % h, 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)); VectorToolBox.GetFreeVxs(out var v1); VxsHelper.FillVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(v1), ColorEx.Make((int)((float)i / (float)num * 255), 0, 0, 255)); VectorToolBox.ReleaseVxs(ref v1); } //the last one ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100); //fill VectorToolBox.GetFreeVxs(out var v2); VxsHelper.FillVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(v2), ColorEx.Make(0, 0, 0, 255)); v2.Clear();// reuse later //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)); VxsHelper.FillVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(v2), ColorEx.Make(255, 0, 0, 255)); VectorToolBox.ReleaseVxs(ref v2); //for (i = 0; i < num; i++) //{ // if (i == num - 1) // { // ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100); // //fill // VxsHelper.DrawVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(), new ColorRGBA(0, 0, 0, 255)); // //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)); // VxsHelper.DrawVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(), new ColorRGBA(255, 0, 0, 255)); // } // else // { // ellipseForMask.Reset(randGenerator.Next() % w, // randGenerator.Next() % h, // 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)); // VxsHelper.DrawVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(), ColorRGBA.Make((int)((float)i / (float)num * 255), 0, 0, 255)); // } //} } }
public override void Draw(Painter p) { if (p is GdiPlusPainter) { DrawWithWinGdi((GdiPlusPainter)p); return; } AggPainter p2 = (AggPainter)p; AggRenderSurface aggRdsf = p2.RenderSurface; var widgetsSubImage = aggRdsf.DestImage; var scline = aggRdsf.ScanlinePacked8; int width = (int)widgetsSubImage.Width; int height = (int)widgetsSubImage.Height; //change value *** if (isMaskSliderValueChanged) { generate_alpha_mask(aggRdsf.ScanlineRasToDestBitmap, aggRdsf.ScanlinePacked8, aggRdsf.ScanlineRasterizer, width, height); this.isMaskSliderValueChanged = false; } var rasterizer = aggRdsf.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 = aggRdsf.ScanlineRasToDestBitmap; // draw a background to show how the mask is working better int rect_w = 30; VectorToolBox.GetFreeVxs(out var v1); 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, ColorEx.Make(.9f, .9f, .9f)); } } } VectorToolBox.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(); //lionShape.ApplyTransform(transform); throw new NotImplementedException(); //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); }
static System.Drawing.Bitmap CreateBackgroundBmp(int w, int h) { //---------------------------------------------------- //1. create background bitmap System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(w, h); //2. create graphics from bmp System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); // draw a background to show how the mask is working better g.Clear(System.Drawing.Color.White); int rect_w = 30; var v1 = new VertexStore();//todo; use pool 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 VxsHelper.FillVxsSnap(g, new VertexStoreSnap(rect.MakeVxs(v1)), ColorEx.Make(.9f, .9f, .9f)); v1.Clear(); } } } //---------------------------------------------------- return(bmp); }
//template<class Scanline, class Ras> public void RenderGourand(Painter p) { float alpha = this.AlphaValue; float brc = 1; #if SourceDepth24 pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr()); #else #endif ////var destImage = gx.DestImage; ////span_allocator span_alloc = new span_allocator(); //specific for agg AggPainter painter = p as AggPainter; if (painter == null) { return; } // AggRenderSurface aggRdsf = painter.RenderSurface; SpanGenGouraudRGBA gouraudSpanGen = new SpanGenGouraudRGBA(); aggRdsf.ScanlineRasterizer.ResetGamma(new GammaLinear(0.0f, this.LinearGamma)); double d = this.DilationValue; // Six triangles double xc = (m_x[0] + m_x[1] + m_x[2]) / 3.0; double yc = (m_y[0] + m_y[1] + m_y[2]) / 3.0; double x1 = (m_x[1] + m_x[0]) / 2 - (xc - (m_x[1] + m_x[0]) / 2); double y1 = (m_y[1] + m_y[0]) / 2 - (yc - (m_y[1] + m_y[0]) / 2); double x2 = (m_x[2] + m_x[1]) / 2 - (xc - (m_x[2] + m_x[1]) / 2); double y2 = (m_y[2] + m_y[1]) / 2 - (yc - (m_y[2] + m_y[1]) / 2); double x3 = (m_x[0] + m_x[2]) / 2 - (xc - (m_x[0] + m_x[2]) / 2); double y3 = (m_y[0] + m_y[2]) / 2 - (yc - (m_y[0] + m_y[2]) / 2); gouraudSpanGen.SetColor(ColorEx.Make(1, 0, 0, alpha), ColorEx.Make(0, 1, 0, alpha), ColorEx.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d); var tmpVxs = _tmpVxs; painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); gouraudSpanGen.SetColor(ColorEx.Make(0, 1, 0, alpha), ColorEx.Make(0, 0, 1, alpha), ColorEx.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d); painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); gouraudSpanGen.SetColor(ColorEx.Make(0, 0, 1, alpha), ColorEx.Make(1, 0, 0, alpha), ColorEx.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d); painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); brc = 1 - brc; gouraudSpanGen.SetColor(ColorEx.Make(1, 0, 0, alpha), ColorEx.Make(0, 1, 0, alpha), ColorEx.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d); painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); gouraudSpanGen.SetColor(ColorEx.Make(0, 1, 0, alpha), ColorEx.Make(0, 0, 1, alpha), ColorEx.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d); painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); gouraudSpanGen.SetColor(ColorEx.Make(0, 0, 1, alpha), ColorEx.Make(1, 0, 0, alpha), ColorEx.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d); painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); }
public override void Draw(Painter p) { //create painter p.SetClipBox(0, 0, Width, Height); p.Clear(Drawing.Color.White); //----------------------------------------------------------------------- //green glyph RectD r = m_shape_bounds; var txPerspective = new Perspective( r.Left, r.Bottom, r.Right, r.Top, m_shadow_ctrl.GetInnerCoords()); VertexStore s2 = this.m_pathVxs2; //if (FlattenCurveChecked) //{ // //s2 = shadow_persp.TransformToVxs(m_path_2); // s2 = shadow_persp.TransformToVxs(m_pathVxs2); //} //else //{ // s2 = shadow_persp.TransformToVxs(m_pathVxs); //} p.FillColor = ColorEx.Make(0.2f, 0.3f, 0f); p.Fill(s2); //--------------------------------------------------------------------------------------------------------- //shadow //--------------------------------------------------------------------------------------------------------- // Calculate the bounding box and extend it by the blur radius RectInt boundRect = BoundingRectInt.GetBoundingRect(s2); int m_radius = this.BlurRadius; //expand bound rect boundRect.Left -= m_radius; boundRect.Bottom -= m_radius; boundRect.Right += m_radius; boundRect.Top += m_radius; if (BlurMethod == BlurMethod.RecursiveBlur) { // The recursive blur method represents the true Gaussian Blur, // with theoretically infinite kernel. The restricted window size // results in extra influence of edge pixels. It's impossible to // solve correctly, but extending the right and top areas to another // radius value produces fair result. //------------------ boundRect.Right += m_radius; boundRect.Top += m_radius; } stopwatch.Stop(); stopwatch.Reset(); stopwatch.Start(); if (BlurMethod != BlurMethod.ChannelBlur) { // Create a new pixel renderer and attach it to the main one as a child image. // It returns true if the attachment succeeded. It fails if the rectangle // (bbox) is fully clipped. //------------------ //------------------ //create filter specfication //it will be resolve later by the platform similar to request font //------------------ if (boundRect.Clip(new RectInt(0, 0, p.Width - 1, p.Height - 1))) { //check if intersect var prevClip = p.ClipBox; p.ClipBox = boundRect; // Blur it switch (BlurMethod) { case BlurMethod.StackBlur: { //------------------ // Faster, but bore specific. // Works only for 8 bits per channel and only with radii <= 254. //------------------ //p.DoFilterBlurStack(boundRect, m_radius); p.ApplyFilter(imgFilterBlurStack); } break; default: { // True Gaussian Blur, 3-5 times slower than Stack Blur, // but still constant time of radius. Very sensitive // to precision, doubles are must here. //------------------ p.ApplyFilter(imgFilterGaussianBlur); } break; } //store back p.ClipBox = prevClip; } } double tm = stopwatch.ElapsedMilliseconds; p.FillColor = Drawing.Color.FromArgb(0.8f, 0.6f, 0.9f, 0.7f); // Render the shape itself ////------------------ //if (FlattenCurveChecked) //{ // //m_ras.AddPath(m_path_2); // p.Fill(m_path_2); //} //else //{ // //m_ras.AddPath(m_pathVxs); // p.Fill(m_pathVxs); //} p.FillColor = Drawing.Color.Black; //p.DrawString(string.Format("{0:F2} ms", tm), 140, 30); //------------------------------------------------------------- //control //m_shadow_ctrl.OnDraw(p); }