public override void Render(IVertexSource <T> vertexSource, uint pathIndexToRender, RGBA_Bytes colorBytes) { #if use_timers OpenGLRenderTimer.Start(); #endif PushOrthoProjection(); vertexSource.Rewind(pathIndexToRender); RGBA_Doubles color = colorBytes.GetAsRGBA_Doubles(); Gl.glColor4d(color.R, color.G, color.B, color.A); IAffineTransformMatrix <T> transform = GetTransform(); if (!transform.Equals(MatrixFactory <T> .NewIdentity(VectorDimension.Two))) { vertexSource = new ConvTransform <T>(vertexSource, transform); } if (m_ForceTexturedEdgeAntiAliasing) { DrawAAShape(vertexSource); } else { SendShapeToTeselator(m_RenderNowTesselator, vertexSource); } PopOrthoProjection(); #if use_timers OpenGLRenderTimer.Stop(); #endif }
protected override void DoDraw(RendererBase <T> destRenderer) { IAffineTransformMatrix <T> Final = MatrixFactory <T> .NewIdentity(VectorDimension.Two); Final.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_Rotation.ToDouble()); Final.Translate(m_Position); ConvTransform <T> TransformedShip = new ConvTransform <T>(m_PlayerToDraw, Final); destRenderer.Render(TransformedShip, new RGBA_Bytes(.9, .4, .2, 1)); }
public override void Render(IVertexSource<T> vertexSource, uint pathIndexToRender, RGBA_Bytes colorBytes) { m_Rasterizer.Reset(); IAffineTransformMatrix<T> transform = GetTransform(); if (!transform.Equals(MatrixFactory<T>.NewIdentity(VectorDimension.Two))) { vertexSource = new ConvTransform<T>(vertexSource, transform); } m_Rasterizer.AddPath(vertexSource, pathIndexToRender); Renderer<T>.RenderSolid(m_PixelFormat, m_Rasterizer, m_ScanlineCache, colorBytes); }
void DrawAATest() { PathStorage <T> PolgonToDraw = new PathStorage <T>(); T Angle = M.Zero <T>(); bool DrawTrinagle = true; if (DrawTrinagle) { PolgonToDraw.MoveTo(Angle.Cos(), Angle.Sin()); Angle.AddEquals(120.0 / 180.0 * Math.PI); PolgonToDraw.LineTo(Angle.Cos(), Angle.Sin()); Angle.AddEquals(120.0 / 180.0 * Math.PI); PolgonToDraw.LineTo(Angle.Cos(), Angle.Sin()); Angle.AddEquals(120.0 / 180.0 * Math.PI); //Triangle.line_to(Math.Cos(Angle), Math.Sin(Angle)); PolgonToDraw.ClosePolygon(); } else { PolgonToDraw.MoveTo(M.Zero <T>(), M.Zero <T>()); PolgonToDraw.LineTo(M.One <T>(), M.Zero <T>()); PolgonToDraw.LineTo(M.One <T>(), M.One <T>()); PolgonToDraw.LineTo(M.Zero <T>(), M.One <T>()); PolgonToDraw.ClosePolygon(); } IAffineTransformMatrix <T> tran = MatrixFactory <T> .NewScaling(VectorDimension.Two, M.New <T>(80)); tran.RotateAlong(MatrixFactory <T> .CreateVector2D(M.Zero <T>(), M.Zero <T>()), Math.PI / 8); tran.Translate(MatrixFactory <T> .CreateVector2D(M.New <T>(500), M.New <T>(100))); ConvTransform <T> TransformedPolygon = new ConvTransform <T>(PolgonToDraw, tran); ((RendererOpenGL <T>)GetRenderer()).m_ForceTexturedEdgeAntiAliasing = true; GetRenderer().Render(TransformedPolygon, new RGBA_Bytes(0, 0, 0)); Ellipse <T> testEllipse = new Ellipse <T>(M.New <T>(300), M.New <T>(250), M.New <T>(60), M.New <T>(60)); GetRenderer().Render(testEllipse, new RGBA_Bytes(205, 23, 12, 120)); ((RendererOpenGL <T>)GetRenderer()).m_ForceTexturedEdgeAntiAliasing = false; //conv_stroke OutLine = new conv_stroke(TransformedPolygon); //OutLine.width(2); //conv_transform TransformedOutLine = new conv_transform(OutLine, Affine.NewTranslation(100, 0)); //GetRenderer().Render(TransformedOutLine, new RGBA_Bytes(0, 0, 0)); //conv_transform TransformedOutLine2 = new conv_transform(OutLine, Affine.NewScaling(6) * Affine.NewTranslation(200, 0)); //conv_stroke OutLineOutLine = new conv_stroke(TransformedOutLine2); //GetRenderer().Render(OutLineOutLine, new RGBA_Bytes(0, 0, 0)); }
public override void OnDraw() { int width = (int)rbuf_window().Width; int height = (int)rbuf_window().Height; IPixelFormat pixf = new FormatRGB(rbuf_window(), new BlenderBGR()); FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); clippingProxy.Clear(new RGBA_Doubles(1, 1, 1)); IAffineTransformMatrix <T> mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two); mtx.Translate(MatrixFactory <T> .CreateVector2D(g_base_dx.Negative(), g_base_dy.Negative())); mtx.Scale(g_scale); mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), g_angle.Add(Math.PI).ToDouble()); mtx.Shear(MatrixFactory <T> .CreateVector2D(g_skew_x.Divide(1000.0), g_skew_y.Divide(1000.0))); mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2, height / 2)); if (m_scanline.status()) { g_rasterizer.SetVectorClipBox(0, 0, width, height); ConvStroke <T> stroke = new ConvStroke <T>(g_path); stroke.Width = m_width_slider.value(); stroke.LineJoin = LineJoin.RoundJoin; ConvTransform <T> trans = new ConvTransform <T>(stroke, mtx); Renderer <T> .RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths); } else { /* * double w = m_width_slider.Value() * mtx.scale(); * * line_profile_aa profile = new line_profile_aa(w, new gamma_none()); * renderer_outline_aa ren = new renderer_outline_aa(rb, profile); * rasterizer_outline_aa ras = new rasterizer_outline_aa(ren); * * conv_transform trans = new conv_transform(g_path, mtx); * * ras.render_all_paths(trans, g_colors, g_path_idx, g_npaths); */ } base.OnDraw(); }
public override void OnDraw() { #if use_timers AllTimer.Start(); #endif int width = (int)rbuf_window().Width; int height = (int)rbuf_window().Height; uint i; for (i = 0; i < m_NumPaths; i++) { // g_colors[i].A_Byte = (byte)(m_AlphaSlider.value() * 255); g_colors[i] = RGBA_Bytes.ModifyComponent(g_colors[i], Component.A, (byte)(m_AlphaSlider.value().ToDouble() * 255)); } IAffineTransformMatrix <T> transform = MatrixFactory <T> .NewIdentity(VectorDimension.Two); transform.Translate(MatrixFactory <T> .CreateVector2D(g_base_dx.Negative(), g_base_dy.Negative())); transform.Scale(MatrixFactory <T> .CreateVector2D(g_scale, g_scale)); transform.RotateAlong(MatrixFactory <T> .CreateVector2D(M.Zero <T>(), M.Zero <T>()), g_angle + Math.PI); transform.Shear(MatrixFactory <T> .CreateVector2D(g_skew_x.Divide(1000.0), g_skew_y.Divide(1000.0))); transform.Translate(MatrixFactory <T> .CreateVector2D(M.New <T>(width).Divide(2), M.New <T>(height).Divide(2))); // This code renders the lion: ConvTransform <T> transformedPathStorage = new ConvTransform <T>(g_PathStorage, transform); #if use_timers Lion50Timer.Start(); for (uint j = 0; j < 200; j++) #endif { this.GetRenderer().Render(transformedPathStorage, g_colors, g_path_idx, m_NumPaths); } #if use_timers Lion50Timer.Stop(); #endif #if use_timers AllTimer.Stop(); CExecutionTimer.Instance.AppendResultsToFile("TimingTest.txt", AllTimer.GetTotalSeconds()); CExecutionTimer.Instance.Reset(); #endif base.OnDraw(); }
public override void OnDraw() { IPixelFormat pixf; if (this.bpp() == 32) { pixf = new FormatRGBA(rbuf_window(), new BlenderBGRA()); //pixf = new pixfmt_alpha_blend_rgba32(rbuf_window(), new blender_rgba32()); } else { if (bpp() != 24) { throw new System.NotSupportedException(); } pixf = new FormatRGB(rbuf_window(), new BlenderBGR()); } FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); clippingProxy.Clear(new RGBA_Doubles(1, 1, 1)); g_rasterizer.SetVectorClipBox(M.Zero <T>(), M.Zero <T>(), width(), height()); if (m_trans_type.cur_item() == 0) { Bilinear <T> tr = new Bilinear <T>(g_x1, g_y1, g_x2, g_y2, m_quad.polygon()); if (tr.IsValid()) { //-------------------------- // Render transformed lion // ConvTransform <T> trans = new ConvTransform <T>(g_path, tr); Renderer <T> .RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths); //-------------------------- //-------------------------- // Render transformed ellipse // VertexSource.Ellipse <T> ell = new AGG.VertexSource.Ellipse <T>(g_x1.Add(g_x2).Multiply(0.5), g_y1.Add(g_y2).Multiply(0.5), g_x2.Subtract(g_x1).Multiply(0.5), g_y2.Subtract(g_y1).Multiply(0.5), 200); ConvStroke <T> ell_stroke = new ConvStroke <T>(ell); ell_stroke.Width = M.New <T>(3.0); ConvTransform <T> trans_ell = new ConvTransform <T>(ell, tr); ConvTransform <T> trans_ell_stroke = new ConvTransform <T>(ell_stroke, tr); g_rasterizer.AddPath(trans_ell); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3)); g_rasterizer.AddPath(trans_ell_stroke); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0)); } } else { Perspective <T> tr = new Perspective <T>(g_x1, g_y1, g_x2, g_y2, m_quad.polygon()); if (tr.IsValid()) { // Render transformed lion ConvTransform <T> trans = new ConvTransform <T>(g_path, tr); Renderer <T> .RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths); // Render transformed ellipse VertexSource.Ellipse <T> FilledEllipse = new AGG.VertexSource.Ellipse <T>(g_x1.Add(g_x2).Multiply(0.5), g_y1.Add(g_y2).Multiply(0.5), g_x2.Subtract(g_x1).Multiply(0.5), g_y2.Subtract(g_y1).Multiply(0.5), 200); ConvStroke <T> EllipseOutline = new ConvStroke <T>(FilledEllipse); EllipseOutline.Width = M.New <T>(3.0); ConvTransform <T> TransformedFilledEllipse = new ConvTransform <T>(FilledEllipse, tr); ConvTransform <T> TransformedEllipesOutline = new ConvTransform <T>(EllipseOutline, tr); g_rasterizer.AddPath(TransformedFilledEllipse); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3)); g_rasterizer.AddPath(TransformedEllipesOutline); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0)); } } //-------------------------- // Render the "quad" tool and controls g_rasterizer.AddPath(m_quad); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0.3, 0.5, 0.6)); //m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy); base.OnDraw(); }
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 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(); }
public override void OnDraw() { int width = (int)rbuf_window().Width; int height = (int)rbuf_window().Height; if (m_num_cb.value().NotEqual(m_slider_value)) { generate_alpha_mask(width, height); m_slider_value = m_num_cb.value(); } g_rasterizer.SetVectorClipBox(0, 0, width, height); IPixelFormat pf = new FormatRGB(rbuf_window(), new BlenderBGR()); unsafe { fixed(byte *pAlphaBuffer = m_alpha_buf) { m_alpha_mask_rbuf.attach(pAlphaBuffer, (uint)width, (uint)height, width, 1); AGG.PixelFormat.AlphaMaskAdaptor pixFormatAlphaMaskAdaptor = new AGG.PixelFormat.AlphaMaskAdaptor(pf, m_alpha_mask); FormatClippingProxy alphaMaskClippingProxy = new FormatClippingProxy(pixFormatAlphaMaskAdaptor); FormatClippingProxy clippingProxy = new FormatClippingProxy(pf); IAffineTransformMatrix <T> mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two); mtx.Translate(MatrixFactory <T> .CreateVector2D(g_base_dx.Negative(), g_base_dy.Negative())); mtx.Scale(g_scale); mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), g_angle.Add(Math.PI).ToDouble()); mtx.Shear(MatrixFactory <T> .CreateVector2D(g_skew_x.Divide(1000.0), g_skew_y.Divide(1000.0))); mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2, height / 2)); clippingProxy.Clear(new RGBA_Doubles(1, 1, 1)); // draw a background to show how the mask is working better int RectWidth = 30; for (int i = 0; i < 40; i++) { for (int j = 0; j < 40; j++) { if ((i + j) % 2 != 0) { VertexSource.RoundedRect <T> rect = new VertexSource.RoundedRect <T>(i * RectWidth, j * RectWidth, (i + 1) * RectWidth, (j + 1) * RectWidth, 0); rect.NormalizeRadius(); // Drawing as an outline g_rasterizer.AddPath(rect); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(.9, .9, .9)); } } } //int x, y; // Render the lion ConvTransform <T> trans = new ConvTransform <T>(g_path, mtx); Renderer <T> .RenderSolidAllPaths(alphaMaskClippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths); /* * // 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); } m_alpha_mask_rbuf.dettachBuffer(); } base.OnDraw(); }
public override void OnDraw() { RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>(); ScanlineUnpacked8 sl = new ScanlineUnpacked8(); #if SourceDepth24 FormatRGB pixf = new FormatRGB(rbuf_window(), new BlenderBGR()); #else FormatRGBA pixf = new FormatRGBA(rbuf_window(), new blender_bgra32()); #endif FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); clippingProxy.Clear(new RGBA_Doubles(0, 0, 0)); m_profile.text_size(8.0); //m_profile.Render(ras, sl, clippingProxy); //m_spline_r.Render(ras, sl, clippingProxy); //m_spline_g.Render(ras, sl, clippingProxy); //m_spline_b.Render(ras, sl, clippingProxy); //m_spline_a.Render(ras, sl, clippingProxy); //m_GradTypeRBox.Render(ras, sl, clippingProxy); //m_GradWrapRBox.Render(ras, sl, clippingProxy); // draw a background to show how the alpha is working int RectWidth = 32; int xoffset = 238; int yoffset = 171; for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { if ((i + j) % 2 != 0) { VertexSource.RoundedRect <T> rect = new VertexSource.RoundedRect <T>(i * RectWidth + xoffset, j * RectWidth + yoffset, (i + 1) * RectWidth + xoffset, (j + 1) * RectWidth + yoffset, 2); rect.NormalizeRadius(); // Drawing as an outline ras.AddPath(rect); Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(.9, .9, .9)); } } } double ini_scale = 1.0; IAffineTransformMatrix <T> mtx1 = MatrixFactory <T> .NewIdentity(VectorDimension.Two); mtx1.Scale(MatrixFactory <T> .CreateVector2D(ini_scale, ini_scale)); mtx1.Translate(MatrixFactory <T> .CreateVector2D(center_x, center_y)); mtx1.Add(trans_affine_resizing()); VertexSource.Ellipse <T> e1 = new AGG.VertexSource.Ellipse <T>(); e1.Init(0.0, 0.0, 110.0, 110.0, 64); IAffineTransformMatrix <T> mtx_g1 = MatrixFactory <T> .NewIdentity(VectorDimension.Two); mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(ini_scale, ini_scale)); mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(m_SaveData.m_scale, m_SaveData.m_scale)); mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(m_scale_x, m_scale_y)); mtx_g1.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_SaveData.m_angle.ToDouble()); mtx_g1.Translate(MatrixFactory <T> .CreateVector2D(m_SaveData.m_center_x, m_SaveData.m_center_y)); mtx_g1.Add(trans_affine_resizing()); mtx_g1 = mtx_g1.Inverse; RGBA_Bytes[] color_profile = new RGBA_Bytes[256]; // color_type is defined in pixel_formats.h for (int i = 0; i < 256; i++) { color_profile[i] = new RGBA_Bytes(m_spline_r.spline()[i].ToInt(), m_spline_g.spline()[i].ToInt(), m_spline_b.spline()[i].ToInt(), m_spline_a.spline()[i].ToInt()); } ConvTransform <T> t1 = new ConvTransform <T>(e1, mtx1); IGradient innerGradient = null; switch (m_GradTypeRBox.cur_item()) { case 0: innerGradient = new GradientRadial(); break; case 1: innerGradient = new GradientDiamond(); break; case 2: innerGradient = new GradientX(); break; case 3: innerGradient = new GradientXY(); break; case 4: innerGradient = new GradientSqrtXY(); break; case 5: innerGradient = new GradientConic(); break; } IGradient outerGradient = null; switch (m_GradWrapRBox.cur_item()) { case 0: outerGradient = new GradientReflectAdaptor(innerGradient); break; case 1: outerGradient = new GradientRepeatAdaptor(innerGradient); break; case 2: outerGradient = new GradientClampAdaptor(innerGradient); break; } SpanAllocator span_alloc = new SpanAllocator(); ColorFunctionProfile colors = new ColorFunctionProfile(color_profile, m_profile.gamma()); SpanInterpolatorLinear <T> inter = new SpanInterpolatorLinear <T>(mtx_g1); SpanGradient <T> span_gen = new SpanGradient <T>(inter, outerGradient, colors, 0, 150); ras.AddPath(t1); Renderer <T> .GenerateAndRender(ras, sl, clippingProxy, span_alloc, span_gen); base.OnDraw(); }
public void Draw(IAffineTransformMatrix <T> Position, RendererBase <T> renderer) { T TextHeight = m_Position[1].Subtract(20); T Range = (m_DataViewMaxY.Subtract(m_DataViewMinY)); ConvTransform <T> TransformedLinesToDraw; ConvStroke <T> StrockedTransformedLinesToDraw; RoundedRect <T> BackGround = new RoundedRect <T>(m_Position[0], m_Position[1].Subtract(1), m_Position[0].Add(m_Width), m_Position[1].Subtract(1).Add(m_Height).Add(2), M.New <T>(5)); ConvTransform <T> TransformedBackGround = new ConvTransform <T>(BackGround, Position); renderer.Render(TransformedBackGround, new RGBA_Bytes(0, 0, 0, .5)); // if the 0 line is within the window than draw it. if (m_DataViewMinY.LessThan(0) && m_DataViewMaxY.GreaterThan(0)) { m_LinesToDraw.RemoveAll(); m_LinesToDraw.MoveTo(m_Position[0], m_Position[1].Add(m_DataViewMinY.Negative().Multiply(M.New <T>(m_Height).Divide(Range)))); m_LinesToDraw.LineTo(m_Position[0].Add((double)m_Width), m_Position[1].Add(m_DataViewMinY.Negative().Multiply(M.New <T>((double)m_Height).Divide(Range)))); TransformedLinesToDraw = new ConvTransform <T>(m_LinesToDraw, Position); StrockedTransformedLinesToDraw = new ConvStroke <T>(TransformedLinesToDraw); renderer.Render(StrockedTransformedLinesToDraw, new RGBA_Bytes(0, 0, 0, 1)); } T MaxMax = M.New <T>(-999999999); T MinMin = M.New <T>(999999999); T MaxAverage = M.Zero <T>(); foreach (KeyValuePair <String, HistoryData> historyKeyValue in m_DataHistoryArray) { HistoryData history = historyKeyValue.Value; m_LinesToDraw.RemoveAll(); MaxMax = M.Max(MaxMax, history.GetMaxValue()); MinMin = M.Min(MinMin, history.GetMinValue()); MaxAverage = M.Max(MaxAverage, history.GetAverageValue()); for (int i = 0; i < m_Width - 1; i++) { if (i == 0) { m_LinesToDraw.MoveTo(m_Position[0].Add(i), m_Position[1].Add(history.GetItem(i).Subtract(m_DataViewMinY).Multiply(M.New <T>(m_Height).Divide(Range)))); } else { m_LinesToDraw.LineTo(m_Position[0].Add(i), m_Position[1].Add(history.GetItem(i).Subtract(m_DataViewMinY).Multiply(M.New <T>((double)m_Height).Divide(Range)))); } } TransformedLinesToDraw = new ConvTransform <T>(m_LinesToDraw, Position); StrockedTransformedLinesToDraw = new ConvStroke <T>(TransformedLinesToDraw); renderer.Render(StrockedTransformedLinesToDraw, history.m_Color); String Text = historyKeyValue.Key + ": Min:" + MinMin.ToString("0.0") + " Max:" + MaxMax.ToString("0.0"); renderer.DrawString(Text, m_Position[0], TextHeight.Subtract(m_Height)); TextHeight.SubtractEquals(20); } RoundedRect <T> BackGround2 = new RoundedRect <T>( m_Position[0], m_Position[1].Subtract(1), m_Position[0].Add((double)m_Width), m_Position[1].Subtract(1 + m_Height + 2), M.New <T>(5)); ConvTransform <T> TransformedBackGround2 = new ConvTransform <T>(BackGround2, Position); ConvStroke <T> StrockedTransformedBackGround = new ConvStroke <T>(TransformedBackGround2); renderer.Render(StrockedTransformedBackGround, new RGBA_Bytes(0.0, 0, 0, 1)); //renderer.Color = BoxColor; //renderer.DrawRect(m_Position.x, m_Position.y - 1, m_Width, m_Height + 2); }
public override void OnDraw() { //typedef agg::renderer_base<pixfmt> renderer_base; //typedef agg::renderer_base<pixfmt_pre> renderer_base_pre; #if SourceDepth24 pixfmt_alpha_blend_rgb pixf = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr()); pixfmt_alpha_blend_rgb pixf_pre = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr_pre()); #else FormatRGBA pixf = new FormatRGBA(rbuf_window(), new BlenderBGRA()); FormatRGBA pixf_pre = new FormatRGBA(rbuf_window(), new BlenderPreMultBGRA()); #endif FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); FormatClippingProxy clippingProxy_pre = new FormatClippingProxy(pixf_pre); clippingProxy.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(initial_width().Negative().Divide(2).Subtract(10), initial_height().Negative().Divide(2).Subtract(30))); src_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_angle.value().Multiply(Math.PI / 180.0).ToDouble()); src_mtx.Scale(m_scale.value()); src_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Divide(2), initial_height().Divide(2).Add(20))); src_mtx.Multiply(trans_affine_resizing()); IAffineTransformMatrix <T> img_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two); img_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Negative().Divide(2).Add(10), initial_height().Negative().Divide(2).Add(30))); img_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_angle.value().Multiply(Math.PI / 180.0).ToDouble()); img_mtx.Scale(m_scale.value()); img_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Divide(2), initial_height().Divide(2).Add(20))); img_mtx.Multiply(trans_affine_resizing()); img_mtx = img_mtx.Inverse; AGG.SpanAllocator sa = new SpanAllocator(); SpanInterpolatorLinear <T> interpolator = new SpanInterpolatorLinear <T>(img_mtx); #if SourceDepth24 pixfmt_alpha_blend_rgb img_pixf = new pixfmt_alpha_blend_rgb(rbuf_img(0), new blender_bgr()); #else FormatRGBA img_pixf = new FormatRGBA(rbuf_img(0), new BlenderBGRA()); #endif #if SourceDepth24 span_image_filter_rgb_bilinear_clip sg; sg = new span_image_filter_rgb_bilinear_clip(img_pixf, rgba.rgba_pre(0, 0.4, 0, 0.5), interpolator); #else SpanImageFilterRgbaBilinearClip <T> sg; RasterBufferAccessorClip source = new RasterBufferAccessorClip(img_pixf, RGBA_Doubles.RgbaPre(0, 0, 0, 0)); sg = new SpanImageFilterRgbaBilinearClip <T>(source, RGBA_Doubles.RgbaPre(0, 0.4, 0, 0.5), interpolator); #endif RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>(); ras.SetVectorClipBox(M.Zero <T>(), M.Zero <T>(), width(), height()); //agg.scanline_packed_8 sl = new scanline_packed_8(); ScanlineUnpacked8 sl = new ScanlineUnpacked8(); T r = initial_width(); if (initial_height().Subtract(60).LessThan(r)) { r = initial_height().Subtract(60); } Ellipse <T> ell = new Ellipse <T>(initial_width().Divide(2.0).Add(10), initial_height().Divide(2.0).Add(30), r.Divide(2.0).Add(16.0), r.Divide(2.0).Add(16.0), 200); ConvTransform <T> tr = new ConvTransform <T>(ell, src_mtx); ras.AddPath(tr); #if use_timers for (uint j = 0; j < 10; j++) { Renderer.GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg); } AllTimer.Start(); image1_100_Times.Start(); for (uint i = 0; i < 500; i++) { #endif //clippingProxy_pre.SetClippingBox(30, 0, (int)width(), (int)height()); //clippingProxy.SetClippingBox(30, 0, (int)width(), (int)height()); Renderer <T> .GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg); #if use_timers } image1_100_Times.Stop(); #endif //m_angle.SetTransform(trans_affine_resizing()); //m_scale.SetTransform(trans_affine_resizing()); #if use_timers AllTimer.Stop(); CExecutionTimer.Instance.AppendResultsToFile("TimingTest.txt", AllTimer.GetTotalSeconds()); CExecutionTimer.Instance.Reset(); #endif base.OnDraw(); }