public override void OnDraw() { #if SourceDepth24 FormatRGB pixf = new FormatRGB(rbuf_window(), new BlenderBGR()); #else pixfmt_alpha_blend_rgba32 pixf = new pixfmt_alpha_blend_rgba32(rbuf_window(), new blender_bgra32()); pixfmt_alpha_blend_rgba32 pixfImage = new pixfmt_alpha_blend_rgba32(rbuf_img(0), new blender_bgra32()); #endif FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); clippingProxy.Clear(new RGBA_Doubles(1.0, 1.0, 1.0)); clippingProxy.CopyFrom(rbuf_img(0), new RectInt(0, 0, (int)Width.ToInt(), (int)Height.ToInt()), 110, 35); string buf = string.Format("NSteps={0:F0}", m_num_steps); GsvText <T> t = new GsvText <T>(); t.StartPoint(10.0, 295.0); t.SetFontSize(10.0); t.Text = buf; ConvStroke <T> pt = new ConvStroke <T>(t); pt.Width = M.New <T>(1.5); m_Rasterizer.AddPath(pt); Renderer <T> .RenderSolid(clippingProxy, m_Rasterizer, m_ScanlinePacked, new RGBA_Bytes(0, 0, 0)); if (m_time1 != m_time2 && m_num_pix > 0.0) { buf = string.Format("{0:F2} Kpix/sec", m_num_pix / (m_time2 - m_time1)); t.StartPoint(10.0, 310.0); t.Text = buf; m_Rasterizer.AddPath(pt); Renderer <T> .RenderSolid(clippingProxy, m_Rasterizer, m_ScanlinePacked, new RGBA_Bytes(0, 0, 0)); } if (m_filters.cur_item() >= 14) { m_radius.Visible = true; } else { m_radius.Visible = true; } base.OnDraw(); }
public override void OnInitialize() { base.OnInitialize(); int whichHeight = 112; int whichWidth = 300; int windingHeight = 140; int windingWidth = 300; m_WhichShape = new rbox_ctrl(0.0, Height - whichHeight, whichWidth, Height); AddChild(m_WhichShape); m_WhichShape.add_item("Nested Rects All CCW"); m_WhichShape.add_item("Nested Rects CCW, CW, CW"); m_WhichShape.add_item("Rects And Triangle"); m_WhichShape.add_item("Complex Path"); m_WhichShape.cur_item(0); m_WhichShape.background_color(new RGBA_Doubles(0.0, 0.0, 0.0, 0.1)); m_WhichShape.text_size(12.0); m_WhichShape.text_thickness(2); m_WindingRule = new rbox_ctrl(whichWidth + 100, Height - windingHeight, whichWidth + 100 + windingWidth, Height); AddChild(m_WindingRule); m_WindingRule.add_item("Winding ODD"); m_WindingRule.add_item("Winding NON-ZERO"); m_WindingRule.add_item("Winding POSITIVE"); m_WindingRule.add_item("Winding NEGATIVE"); m_WindingRule.add_item("Winding ABS >= 2"); m_WindingRule.cur_item(0); m_WindingRule.background_color(new RGBA_Doubles(0.0, 0.0, 0.0, 0.1)); m_WindingRule.text_size(12.0); m_WindingRule.text_thickness(2); m_EdgeFlag = new cbox_ctrl(10, Height - whichHeight - 40, "Turn on Edge Flag"); m_EdgeFlag.status(true); AddChild(m_EdgeFlag); m_BoundryOnly = new cbox_ctrl(10, Height - whichHeight - 20, "Render Only Boundary"); AddChild(m_BoundryOnly); Tesselate_Tests test = new Tesselate_Tests(); test.MatchesGLUTesselator(); }
public override void OnDraw() { GetRenderer().Clear(new RGBA_Doubles(1, 1, 1)); Tesselator tesselator = new Tesselator(); tesselator.callBegin += new Tesselator.CallBeginDelegate(BeginCallBack); tesselator.callEnd += new Tesselator.CallEndDelegate(EndCallBack); tesselator.callVertex += new Tesselator.CallVertexDelegate(VertexCallBack); tesselator.callCombine += new Tesselator.CallCombineDelegate(CombineCallBack); switch (m_WindingRule.cur_item()) { case 0: tesselator.windingRule = Tesselator.WindingRuleType.Odd; break; case 1: tesselator.windingRule = Tesselator.WindingRuleType.NonZero; break; case 2: tesselator.windingRule = Tesselator.WindingRuleType.Positive; break; case 3: tesselator.windingRule = Tesselator.WindingRuleType.Negative; break; case 4: tesselator.windingRule = Tesselator.WindingRuleType.ABS_GEQ_Two; break; } if (m_EdgeFlag.status()) { tesselator.callEdgeFlag += new Tesselator.CallEdgeFlagDelegate(EdgeFlagCallBack); } if (m_BoundryOnly.status()) // edgesOnly { tesselator.BoundaryOnly = true; } m_TesselateTest.ParseStreamForTesselator(tesselator, m_WhichShape.cur_item()); // now render the outline { string[] instructionStream = Tesselate_Tests.m_InsructionStream[m_WhichShape.cur_item()]; bool gotFirst = false; Tesselate_Tests.Vertex firstInContour = new Tesselate_Tests.Vertex(0, 0); bool havePrev = false; Tesselate_Tests.Vertex prevVertex = new Tesselate_Tests.Vertex(0, 0); PathStorage line = new PathStorage(); conv_stroke wideLine; AGG.VertexSource.Ellipse Dot; for (int curInstruction = 0; curInstruction < instructionStream.Length; curInstruction++) { switch (instructionStream[curInstruction]) { case "BC": break; case "EC": gotFirst = false; havePrev = false; line.remove_all(); line.move_to(prevVertex.m_X + 30, prevVertex.m_Y + 100); line.line_to(firstInContour.m_X + 30, firstInContour.m_Y + 100); // Drawing as an outline wideLine = new conv_stroke(line); wideLine.width(1); GetRenderer().Render(wideLine, new RGBA_Bytes(0, 0, 0)); Dot = new Ellipse( (firstInContour.m_X * 9 + prevVertex.m_X) / 10 + 30, (firstInContour.m_Y * 9 + prevVertex.m_Y) / 10 + 100, 3, 3); GetRenderer().Render(Dot, new RGBA_Bytes(0, 0, 0)); break; case "V": double x = Convert.ToDouble(instructionStream[curInstruction + 1]); double y = Convert.ToDouble(instructionStream[curInstruction + 2]); curInstruction += 2; if (!gotFirst) { gotFirst = true; firstInContour = new Tesselate_Tests.Vertex(x, y); } if (!havePrev) { prevVertex = new Tesselate_Tests.Vertex(x, y); havePrev = true; } else { line.remove_all(); line.move_to(prevVertex.m_X + 30, prevVertex.m_Y + 100); line.line_to(x + 30, y + 100); // Drawing as an outline wideLine = new conv_stroke(line); wideLine.width(1); GetRenderer().Render(wideLine, new RGBA_Bytes(0, 0, 0)); line.remove_all(); Dot = new Ellipse( (x * 9 + prevVertex.m_X) / 10 + 30, (y * 9 + prevVertex.m_Y) / 10 + 100, 3, 3); GetRenderer().Render(Dot, new RGBA_Bytes(0, 0, 0)); prevVertex = new Tesselate_Tests.Vertex(x, y); } break; } } } base.OnDraw(); }
image_filters_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_step = new SliderWidget <T>(115, 5, 400, 11); m_radius = new SliderWidget <T>(115, 5 + 15, 400, 11 + 15); m_filters = new rbox_ctrl <T>(0.0, 0.0, 110.0, 210.0); m_normalize = new cbox_ctrl <T>(8.0, 215.0, "Normalize Filter"); m_refresh = new ButtonWidget <T>(8.0, 273.0, "Refresh", 8, 1, 1, 3); m_refresh.ButtonClick += RefreshImage; m_run = new ButtonWidget <T>(8.0, 253.0, "RUN Test!", 8, 1, 1, 3); m_run.ButtonClick += RunTest; m_single_step = new ButtonWidget <T>(8.0, 233.0, "Single Step", 8, 1, 1, 3); m_single_step.ButtonClick += SingleStep; m_cur_angle = (0.0); m_cur_filter = (1); m_num_steps = (0); m_num_pix = (0.0); m_time1 = (0); m_time2 = (0); m_ScanlinePacked = new ScanlinePacked8(); m_Rasterizer = new RasterizerScanlineAA <T>(); m_ScanlineUnpacked = new ScanlineUnpacked8(); m_SpanAllocator = new SpanAllocator(); AddChild(m_radius); AddChild(m_step); AddChild(m_filters); AddChild(m_run); AddChild(m_single_step); AddChild(m_normalize); AddChild(m_refresh); //m_single_step.text_size(7.5); m_normalize.SetFontSize(7.5); m_normalize.status(true); m_radius.label("Filter Radius={0:F2}"); m_step.label("Step={0:F2}"); m_radius.range(2.0, 8.0); m_radius.value(4.0); m_step.range(1.0, 10.0); m_step.value(5.0); m_filters.add_item("simple (NN)"); m_filters.add_item("bilinear"); m_filters.add_item("bicubic"); m_filters.add_item("spline16"); m_filters.add_item("spline36"); m_filters.add_item("hanning"); m_filters.add_item("hamming"); m_filters.add_item("hermite"); m_filters.add_item("kaiser"); m_filters.add_item("quadric"); m_filters.add_item("catrom"); m_filters.add_item("gaussian"); m_filters.add_item("bessel"); m_filters.add_item("mitchell"); m_filters.add_item("sinc"); m_filters.add_item("lanczos"); m_filters.add_item("blackman"); m_filters.cur_item(1); m_filters.border_width(0, 0); m_filters.background_color(new RGBA_Doubles(0.0, 0.0, 0.0, 0.1)); m_filters.text_size(6.0); m_filters.text_thickness(0.85); }
public blur_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_rbuf2 = new RasterBuffer(); m_shape_bounds = new RectDouble <T>(); m_method = new rbox_ctrl <T>(10.0, 10.0, 130.0, 70.0); m_radius = new SliderWidget <T>(130 + 10.0, 10.0 + 4.0, 130 + 300.0, 10.0 + 8.0 + 4.0); m_shadow_ctrl = new polygon_ctrl <T>(4); m_channel_r = new cbox_ctrl <T>(10.0, 80.0, "Red"); m_channel_g = new cbox_ctrl <T>(10.0, 95.0, "Green"); m_channel_b = new cbox_ctrl <T>(10.0, 110.0, "Blue"); m_FlattenCurves = new cbox_ctrl <T>(10, 315, "Convert And Flatten Curves"); m_FlattenCurves.status(true); AddChild(m_method); m_method.text_size(8); m_method.add_item("Stack Blur"); m_method.add_item("Recursive Blur"); m_method.add_item("Channels"); m_method.cur_item(1); AddChild(m_radius); m_radius.range(0.0, 40.0); m_radius.value(15.0); m_radius.label("Blur Radius={0:F2}"); AddChild(m_shadow_ctrl); AddChild(m_channel_r); AddChild(m_channel_g); AddChild(m_channel_b); AddChild(m_FlattenCurves); m_channel_g.status(true); m_sl = new ScanlinePacked8(); m_path = new PathStorage <T>(); m_shape = new ConvCurve <T>(m_path); m_path.RemoveAll(); m_path.MoveTo(28.47, 6.45); m_path.Curve3(21.58, 1.12, 19.82, 0.29); m_path.Curve3(17.19, -0.93, 14.21, -0.93); m_path.Curve3(9.57, -0.93, 6.57, 2.25); m_path.Curve3(3.56, 5.42, 3.56, 10.60); m_path.Curve3(3.56, 13.87, 5.03, 16.26); m_path.Curve3(7.03, 19.58, 11.99, 22.51); m_path.Curve3(16.94, 25.44, 28.47, 29.64); m_path.LineTo(28.47, 31.40); m_path.Curve3(28.47, 38.09, 26.34, 40.58); m_path.Curve3(24.22, 43.07, 20.17, 43.07); m_path.Curve3(17.09, 43.07, 15.28, 41.41); m_path.Curve3(13.43, 39.75, 13.43, 37.60); m_path.LineTo(13.53, 34.77); m_path.Curve3(13.53, 32.52, 12.38, 31.30); m_path.Curve3(11.23, 30.08, 9.38, 30.08); m_path.Curve3(7.57, 30.08, 6.42, 31.35); m_path.Curve3(5.27, 32.62, 5.27, 34.81); m_path.Curve3(5.27, 39.01, 9.57, 42.53); m_path.Curve3(13.87, 46.04, 21.63, 46.04); m_path.Curve3(27.59, 46.04, 31.40, 44.04); m_path.Curve3(34.28, 42.53, 35.64, 39.31); m_path.Curve3(36.52, 37.21, 36.52, 30.71); m_path.LineTo(36.52, 15.53); m_path.Curve3(36.52, 9.13, 36.77, 7.69); m_path.Curve3(37.01, 6.25, 37.57, 5.76); m_path.Curve3(38.13, 5.27, 38.87, 5.27); m_path.Curve3(39.65, 5.27, 40.23, 5.62); m_path.Curve3(41.26, 6.25, 44.19, 9.18); m_path.LineTo(44.19, 6.45); m_path.Curve3(38.72, -0.88, 33.74, -0.88); m_path.Curve3(31.35, -0.88, 29.93, 0.78); m_path.Curve3(28.52, 2.44, 28.47, 6.45); m_path.ClosePolygon(); m_path.MoveTo(28.47, 9.62); m_path.LineTo(28.47, 26.66); m_path.Curve3(21.09, 23.73, 18.95, 22.51); m_path.Curve3(15.09, 20.36, 13.43, 18.02); m_path.Curve3(11.77, 15.67, 11.77, 12.89); m_path.Curve3(11.77, 9.38, 13.87, 7.06); m_path.Curve3(15.97, 4.74, 18.70, 4.74); m_path.Curve3(22.41, 4.74, 28.47, 9.62); m_path.ClosePolygon(); IAffineTransformMatrix <T> shape_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two); shape_mtx.Scale(M.New <T>(4.0)); shape_mtx.Translate(MatrixFactory <T> .CreateVector2D(150, 100)); m_path.Transform(shape_mtx); BoundingRect <T> .BoundingRectSingle(m_shape, 0, ref m_shape_bounds); m_shadow_ctrl.SetXN(0, m_shape_bounds.x1); m_shadow_ctrl.SetYN(0, m_shape_bounds.y1); m_shadow_ctrl.SetXN(1, m_shape_bounds.x2); m_shadow_ctrl.SetYN(1, m_shape_bounds.y1); m_shadow_ctrl.SetXN(2, m_shape_bounds.x2); m_shadow_ctrl.SetYN(2, m_shape_bounds.y2); m_shadow_ctrl.SetXN(3, m_shape_bounds.x1); m_shadow_ctrl.SetYN(3, m_shape_bounds.y2); m_shadow_ctrl.line_color(new RGBA_Doubles(0, 0.3, 0.5, 0.3)); }
public override void OnDraw() { //typedef agg::renderer_base<agg::pixfmt_bgr24> ren_base; FormatRGB pixf = new FormatRGB(rbuf_window(), new BlenderBGR()); FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); clippingProxy.Clear(new RGBA_Doubles(1, 1, 1)); m_ras.SetVectorClipBox(0, 0, width().ToDouble(), height().ToDouble()); IAffineTransformMatrix <T> move = MatrixFactory <T> .NewTranslation(10, 10); Perspective <T> shadow_persp = new Perspective <T>(m_shape_bounds.x1, m_shape_bounds.y1, m_shape_bounds.x2, m_shape_bounds.y2, m_shadow_ctrl.polygon()); IVertexSource <T> shadow_trans; if (m_FlattenCurves.status()) { shadow_trans = new ConvTransform <T>(m_shape, shadow_persp); } else { shadow_trans = new ConvTransform <T>(m_path, shadow_persp); // this will make it very smooth after the Transform //shadow_trans = new conv_curve(shadow_trans); } // Render shadow m_ras.AddPath(shadow_trans); Renderer <T> .RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Doubles(0.2, 0.3, 0).GetAsRGBA_Bytes()); // Calculate the bounding box and extend it by the blur radius RectDouble <T> bbox = new RectDouble <T>(); BoundingRect <T> .BoundingRectSingle(shadow_trans, 0, ref bbox); bbox.x1.SubtractEquals(m_radius.value()); bbox.y1.SubtractEquals(m_radius.value()); bbox.x2.AddEquals(m_radius.value()); bbox.y2.AddEquals(m_radius.value()); if (m_method.cur_item() == 1) { // 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. //------------------ bbox.x2.AddEquals(m_radius.value()); bbox.y2.AddEquals(m_radius.value()); } start_timer(); if (m_method.cur_item() != 2) { // 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. //------------------ FormatRGB pixf2 = new FormatRGB(m_rbuf2, new BlenderBGR()); if (pixf2.Attach(pixf, (int)bbox.x1.ToInt(), (int)bbox.y1.ToInt(), (int)bbox.x2.ToInt(), (int)bbox.y2.ToInt())) { // Blur it if (m_method.cur_item() == 0) { // More general method, but 30-40% slower. //------------------ //m_stack_blur.blur(pixf2, agg::uround(m_radius.Value())); // Faster, but bore specific. // Works only for 8 bits per channel and only with radii <= 254. //------------------ // agg::stack_blur_rgb24(pixf2, agg::uround(m_radius.Value()), // agg::uround(m_radius.Value())); } else { // True Gaussian Blur, 3-5 times slower than Stack Blur, // but still constant time of radius. Very sensitive // to precision, doubles are must here. //------------------ m_recursive_blur.Blur(pixf2, m_radius.value().ToDouble()); } } } else { /* * // Blur separate channels * //------------------ * if(m_channel_r.status()) * { * typedef agg::pixfmt_alpha_blend_gray< * agg::blender_gray8, * agg::rendering_buffer, * 3, 2> pixfmt_gray8r; * * pixfmt_gray8r pixf2r(m_rbuf2); * if(pixf2r.Attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2))) * { * agg::stack_blur_gray8(pixf2r, agg::uround(m_radius.Value()), * agg::uround(m_radius.Value())); * } * } * * if(m_channel_g.status()) * { * typedef agg::pixfmt_alpha_blend_gray< * agg::blender_gray8, * agg::rendering_buffer, * 3, 1> pixfmt_gray8g; * * pixfmt_gray8g pixf2g(m_rbuf2); * if(pixf2g.Attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2))) * { * agg::stack_blur_gray8(pixf2g, agg::uround(m_radius.Value()), * agg::uround(m_radius.Value())); * } * } * * if(m_channel_b.status()) * { * typedef agg::pixfmt_alpha_blend_gray< * agg::blender_gray8, * agg::rendering_buffer, * 3, 0> pixfmt_gray8b; * * pixfmt_gray8b pixf2b(m_rbuf2); * if(pixf2b.Attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2))) * { * agg::stack_blur_gray8(pixf2b, agg::uround(m_radius.Value()), * agg::uround(m_radius.Value())); * } * } */ } double tm = elapsed_time(); //m_shadow_ctrl.Render(m_ras, m_sl, clippingProxy); // Render the shape itself //------------------ if (m_FlattenCurves.status()) { m_ras.AddPath(m_shape); } else { m_ras.AddPath(m_path); } Renderer <T> .RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Doubles(0.6, 0.9, 0.7, 0.8).GetAsRGBA_Bytes()); GsvText <T> t = new GsvText <T>(); t.SetFontSize(10.0); ConvStroke <T> st = new ConvStroke <T>(t); st.Width = M.New <T>(1.5); string buf; buf = string.Format("{0:F2} ms", tm); t.StartPoint(140.0, 30.0); t.Text = buf; m_ras.AddPath(st); Renderer <T> .RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Doubles(0, 0, 0).GetAsRGBA_Bytes()); //m_method.Render(m_ras, m_sl, clippingProxy); //m_radius.Render(m_ras, m_sl, clippingProxy); //m_channel_r.Render(m_ras, m_sl, clippingProxy); //m_channel_g.Render(m_ras, m_sl, clippingProxy); //m_channel_b.Render(m_ras, m_sl, clippingProxy); //m_FlattenCurves.Render(m_ras, m_sl, clippingProxy); base.OnDraw(); }