void SingleStep(ButtonWidget <T> button) { m_cur_angle += m_step.value().ToDouble(); copy_img_to_img(1, 0); transform_image(m_step.value()); m_num_steps++; force_redraw(); }
line_patterns_application(PixelFormats format, AGG.UI.PlatformSupportAbstract.ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_ctrl_color = new RGBA_Bytes(0, 0.3, 0.5, 0.3); m_scale_x = new SliderWidget(5.0, 5.0, 240.0, 12.0); m_start_x = new SliderWidget(250.0, 5.0, 495.0, 12.0); m_approximation_method = new cbox_ctrl(10, 30, "Approximation Method = curve_div"); m_curve1.line_color(m_ctrl_color); m_curve2.line_color(m_ctrl_color); m_curve3.line_color(m_ctrl_color); m_curve4.line_color(m_ctrl_color); m_curve5.line_color(m_ctrl_color); m_curve6.line_color(m_ctrl_color); m_curve7.line_color(m_ctrl_color); m_curve8.line_color(m_ctrl_color); m_curve9.line_color(m_ctrl_color); m_curve1.curve(64, 19, 14, 126, 118, 266, 19, 265); m_curve2.curve(112, 113, 178, 32, 200, 132, 125, 438); m_curve3.curve(401, 24, 326, 149, 285, 11, 177, 77); m_curve4.curve(188, 427, 129, 295, 19, 283, 25, 410); m_curve5.curve(451, 346, 302, 218, 265, 441, 459, 400); m_curve6.curve(454, 198, 14, 13, 220, 291, 483, 283); m_curve7.curve(301, 398, 355, 231, 209, 211, 170, 353); m_curve8.curve(484, 101, 222, 33, 486, 435, 487, 138); m_curve9.curve(143, 147, 11, 45, 83, 427, 132, 197); AddChild(m_curve1); AddChild(m_curve2); AddChild(m_curve3); AddChild(m_curve4); AddChild(m_curve5); AddChild(m_curve6); AddChild(m_curve7); AddChild(m_curve8); AddChild(m_curve9); AddChild(m_approximation_method); m_scale_x.label("Scale X=%.2f"); m_scale_x.range(0.2, 3.0); m_scale_x.value(1.0); AddChild(m_scale_x); m_start_x.label("Start X=%.2f"); m_start_x.range(0.0, 10.0); m_start_x.value(0.0); AddChild(m_start_x); }
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); }
void transform_image(double angle) { double width = rbuf_img(0).Width; double height = rbuf_img(0).Height; #if SourceDepth24 FormatRGB pixf = new FormatRGB(rbuf_img(0), new BlenderBGR()); FormatRGB pixf_pre = new FormatRGB(rbuf_img(0), new BlenderPreMultBGR()); #else pixfmt_alpha_blend_rgba32 pixf = new pixfmt_alpha_blend_rgba32(rbuf_img(0), new blender_bgra32()); pixfmt_alpha_blend_rgba32 pixf_pre = new pixfmt_alpha_blend_rgba32(rbuf_img(0), new blender_bgra_pre()); #endif FormatClippingProxy rb = new FormatClippingProxy(pixf); FormatClippingProxy rb_pre = new FormatClippingProxy(pixf_pre); rb.Clear(new RGBA_Doubles(1.0, 1.0, 1.0)); IAffineTransformMatrix <T> src_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two); src_mtx.Translate(MatrixFactory <T> .CreateVector2D(-width / 2.0, -height / 2.0)); src_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), angle * Math.PI / 180.0); src_mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2.0, height / 2.0)); IAffineTransformMatrix <T> img_mtx = MatrixFactory <T> .CreateAffine(src_mtx); img_mtx = img_mtx.Inverse; double r = width; if (height < r) { r = height; } r *= 0.5; r -= 4.0; VertexSource.Ellipse <T> ell = new AGG.VertexSource.Ellipse <T>(width / 2.0, height / 2.0, r, r, 200); ConvTransform <T> tr = new ConvTransform <T>(ell, src_mtx); m_num_pix += r * r * Math.PI; SpanInterpolatorLinear <T> interpolator = new SpanInterpolatorLinear <T>(img_mtx); ImageFilterLookUpTable <T> filter = new ImageFilterLookUpTable <T>(); bool norm = m_normalize.status(); #if SourceDepth24 FormatRGB pixf_img = new FormatRGB(rbuf_img(1), new BlenderBGR()); #else pixfmt_alpha_blend_rgba32 pixf_img = new pixfmt_alpha_blend_rgba32(rbuf_img(1), new blender_bgra32()); #endif RasterBufferAccessorClip source = new RasterBufferAccessorClip(pixf_img, RGBA_Doubles.RgbaPre(0, 0, 0, 0)); switch (m_filters.cur_item()) { case 0: { #if SourceDepth24 SpanImageFilterRgbNN <T> sg = new SpanImageFilterRgbNN <T>(source, interpolator); #else span_image_filter_rgba_nn sg = new span_image_filter_rgba_nn(source, interpolator); #endif m_Rasterizer.AddPath(tr); Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg); } break; case 1: { #if SourceDepth24 //span_image_filter_rgb_bilinear_clip sg = new span_image_filter_rgb_bilinear_clip(pixf_img, rgba.rgba_pre(0, 0.4, 0, 0.5), interpolator); SpanImageFilterRgbBilinear <T> sg = new SpanImageFilterRgbBilinear <T>(source, interpolator); #else //span_image_filter_rgba_bilinear_clip sg = new span_image_filter_rgba_bilinear_clip(pixf_img, rgba.rgba_pre(0, 0, 0, 0), interpolator); span_image_filter_rgba_bilinear sg = new span_image_filter_rgba_bilinear(source, interpolator); #endif m_Rasterizer.AddPath(tr); Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg); } break; case 5: case 6: case 7: { switch (m_filters.cur_item()) { case 5: filter.Calculate(new ImageFilterHanning <T>(), norm); break; case 6: filter.Calculate(new ImageFilterHamming <T>(), norm); break; case 7: filter.Calculate(new ImageFilterHermite <T>(), norm); break; } SpanImageFilterRgb2x2 <T> sg = new SpanImageFilterRgb2x2 <T>(source, interpolator, filter); m_Rasterizer.AddPath(tr); Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg); } break; case 2: case 3: case 4: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: { switch (m_filters.cur_item()) { case 2: filter.Calculate(new ImageFilterBicubic <T>(), norm); break; case 3: filter.Calculate(new ImageFilterSpline16 <T>(), norm); break; case 4: filter.Calculate(new ImageFilterSpline36 <T>(), norm); break; case 8: filter.Calculate(new ImageFilterKaiser <T>(), norm); break; case 9: filter.Calculate(new ImageFilterQuadric <T>(), norm); break; case 10: filter.Calculate(new ImageFilterCatrom <T>(), norm); break; case 11: filter.Calculate(new ImageFilterGaussian <T>(), norm); break; case 12: filter.Calculate(new ImageFilterBessel <T>(), norm); break; case 13: filter.Calculate(new ImageFilterMitchell <T>(), norm); break; case 14: filter.Calculate(new ImageFilterSinc <T>(m_radius.value()), norm); break; case 15: filter.Calculate(new ImageFilterLanczos <T>(m_radius.value()), norm); break; case 16: filter.Calculate(new ImageFilterBlackman <T>(m_radius.value()), norm); break; } #if SourceDepth24 SpanImageFilterRgb <T> sg = new SpanImageFilterRgb <T>(source, interpolator, filter); #else span_image_filter_rgb sg = new span_image_filter_rgba(source, interpolator, filter); #endif m_Rasterizer.AddPath(tr); Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg); } break; } }
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(); }