internal ImageRenderer(ImageBuffer owner) : base() { m_Owner = owner; rasterizer_scanline_aa rasterizer = new rasterizer_scanline_aa(); ImageClippingProxy imageClippingProxy = new ImageClippingProxy(owner); Initialize(imageClippingProxy, rasterizer); ScanlineCache = new scanline_packed_8(); }
/* * void draw_curve(Pattern patt, IRasterizer ras, Renderer ren, PatternSource src, IVertexSource vs) * { * patt.create(src); * ren.scale_x(m_scale_x.value()); * ren.start_x(m_start_x.value()); * ras.add_path(vs); * } */ public override void OnDraw() { #if SourceDepth24 FormatRGB pf = new FormatRGB(rbuf_window(), new BlenderBGR()); #else FormatRGBA pf = new FormatRGBA(rbuf_window(), new BlenderBGRA()); #endif FormatClippingProxy ren_base = new FormatClippingProxy(pf); ren_base.clear(new RGBA_Doubles(1.0, 1.0, .95)); rasterizer_scanline_aa ras = new rasterizer_scanline_aa(); scanline_packed_8 sl = new scanline_packed_8(); // Pattern source. Must have an interface: // width() const // height() const // pixel(int x, int y) const // Any agg::renderer_base<> or derived // is good for the use as a source. //----------------------------------- pattern_src_brightness_to_alpha_RGBA_Bytes p1 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(0)); pattern_src_brightness_to_alpha_RGBA_Bytes p2 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(1)); pattern_src_brightness_to_alpha_RGBA_Bytes p3 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(2)); pattern_src_brightness_to_alpha_RGBA_Bytes p4 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(3)); pattern_src_brightness_to_alpha_RGBA_Bytes p5 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(4)); pattern_src_brightness_to_alpha_RGBA_Bytes p6 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(5)); pattern_src_brightness_to_alpha_RGBA_Bytes p7 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(6)); pattern_src_brightness_to_alpha_RGBA_Bytes p8 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(7)); pattern_src_brightness_to_alpha_RGBA_Bytes p9 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(8)); //pattern_filter_bilinear_rgba pattern_filter_bilinear_RGBA_Bytes fltr; // Filtering functor // agg::line_image_pattern is the main container for the patterns. It creates // a copy of the patterns extended according to the needs of the filter. // agg::line_image_pattern can operate with arbitrary image width, but if the // width of the pattern is power of 2, it's better to use the modified // version agg::line_image_pattern_pow2 because it works about 15-25 percent // faster than agg::line_image_pattern (because of using simple masking instead // of expensive '%' operation). //typedef agg::line_image_pattern<agg::pattern_filter_bilinear_RGBA_Bytes> pattern_type; //typedef agg::renderer_base<pixfmt> base_ren_type; //typedef agg::renderer_outline_image<base_ren_type, pattern_type> renderer_type; //typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type; //-- Create with specifying the source //pattern_type patt(fltr, src); //-- Create uninitialized and set the source line_image_pattern patt = new line_image_pattern(new pattern_filter_bilinear_RGBA_Bytes()); //renderer_outline_image ren_img = new renderer_outline_image(, patt); /* * renderer_type ren_img(ren_base, patt); * rasterizer_type ras_img(ren_img); * * draw_curve(patt, ras_img, ren_img, p1, m_curve1.curve()); * draw_curve(patt, ras_img, ren_img, p2, m_curve2.curve()); * draw_curve(patt, ras_img, ren_img, p3, m_curve3.curve()); * draw_curve(patt, ras_img, ren_img, p4, m_curve4.curve()); * draw_curve(patt, ras_img, ren_img, p5, m_curve5.curve()); * draw_curve(patt, ras_img, ren_img, p6, m_curve6.curve()); * draw_curve(patt, ras_img, ren_img, p7, m_curve7.curve()); * draw_curve(patt, ras_img, ren_img, p8, m_curve8.curve()); * draw_curve(patt, ras_img, ren_img, p9, m_curve9.curve()); */ base.OnDraw(); }
public override void OnDraw(RendererBase renderer) { GammaLookUpTable gamma = new GammaLookUpTable(m_gamma.value()); IBlender NormalBlender = new BlenderBGRA(); IBlender GammaBlender = new BlenderGammaBGRA(gamma); ImageBuffer rasterNormal = new ImageBuffer(NewRenderer().DestImage, NormalBlender); ImageBuffer rasterGamma = new ImageBuffer(NewRenderer().DestImage, GammaBlender); ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal); ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma); clippingProxyNormal.clear(new RGBA_Doubles(0,0,0)); rasterizer_scanline_aa ras = new rasterizer_scanline_aa(); scanline_packed_8 sl = new scanline_packed_8(); VertexSource.Ellipse e = new VertexSource.Ellipse(); // TODO: If you drag the control circles below the bottom of the window we get an exception. This does not happen in AGG. // It needs to be debugged. Turning on clipping fixes it. But standard agg works without clipping. Could be a bigger problem than this. //ras.clip_box(0, 0, width(), height()); // Render two "control" circles e.init(m_x[0], m_y[0], 3, 3, 16); ras.add_path(e); Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127)); e.init(m_x[1], m_y[1], 3, 3, 16); ras.add_path(e); Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127)); // Creating a rounded rectangle VertexSource.RoundedRect r = new VertexSource.RoundedRect(m_x[0], m_y[0], m_x[1], m_y[1], 10); r.normalize_radius(); // Drawing as an outline conv_stroke p = new conv_stroke(r); p.width(1.0); ras.add_path(p); //Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(0, 0, 0)); Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(255, 1, 1)); /* int i; // radial line test //------------------------- dashed_line<rasterizer_type, renderer_scanline_type, scanline_type> dash(ras, ren_sl, sl); double cx = width() / 2.0; double cy = height() / 2.0; ren_sl.color(agg::rgba(1.0, 1.0, 1.0, 0.2)); for(i = 180; i > 0; i--) { double n = 2.0 * agg::pi * i / 180.0; dash.draw(cx + min(cx, cy) * sin(n), cy + min(cx, cy) * cos(n), cx, cy, 1.0, (i < 90) ? i : 0.0); } typedef agg::gradient_x gradient_func_type; typedef agg::span_interpolator_linear<> interpolator_type; typedef agg::span_allocator<color_type> span_allocator_type; typedef agg::pod_auto_array<color_type, 256> color_array_type; typedef agg::span_gradient<color_type, interpolator_type, gradient_func_type, color_array_type> span_gradient_type; typedef agg::renderer_scanline_aa<renderer_base_type, span_allocator_type, span_gradient_type> renderer_gradient_type; gradient_func_type gradient_func; // The gradient function agg::trans_affine gradient_mtx; // Affine transformer interpolator_type span_interpolator(gradient_mtx); // Span interpolator span_allocator_type span_allocator; // Span Allocator color_array_type gradient_colors; // The gradient colors span_gradient_type span_gradient(span_interpolator, gradient_func, gradient_colors, 0, 100); renderer_gradient_type ren_gradient(ren_base, span_allocator, span_gradient); dashed_line<rasterizer_type, renderer_gradient_type, scanline_type> dash_gradient(ras, ren_gradient, sl); double x1, y1, x2, y2; for(i = 1; i <= 20; i++) { ren_sl.color(agg::rgba(1,1,1)); // integral point sizes 1..20 //---------------- agg::ellipse ell; ell.init(20 + i * (i + 1) + 0.5, 20.5, i / 2.0, i / 2.0, 8 + i); ras.reset(); ras.add_path(ell); agg::render_scanlines(ras, sl, ren_sl); // fractional point sizes 0..2 //---------------- ell.init(18 + i * 4 + 0.5, 33 + 0.5, i/20.0, i/20.0, 8); ras.reset(); ras.add_path(ell); agg::render_scanlines(ras, sl, ren_sl); // fractional point positioning //--------------- ell.init(18 + i * 4 + (i-1) / 10.0 + 0.5, 27 + (i - 1) / 10.0 + 0.5, 0.5, 0.5, 8); ras.reset(); ras.add_path(ell); agg::render_scanlines(ras, sl, ren_sl); // integral line widths 1..20 //---------------- fill_color_array(gradient_colors, agg::rgba(1,1,1), agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25)); x1 = 20 + i* (i + 1); y1 = 40.5; x2 = 20 + i * (i + 1) + (i - 1) * 4; y2 = 100.5; calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx); dash_gradient.draw(x1, y1, x2, y2, i, 0); fill_color_array(gradient_colors, agg::rgba(1,0,0), agg::rgba(0,0,1)); // fractional line lengths H (red/blue) //---------------- x1 = 17.5 + i * 4; y1 = 107; x2 = 17.5 + i * 4 + i/6.66666667; y2 = 107; calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx); dash_gradient.draw(x1, y1, x2, y2, 1.0, 0); // fractional line lengths V (red/blue) //--------------- x1 = 18 + i * 4; y1 = 112.5; x2 = 18 + i * 4; y2 = 112.5 + i / 6.66666667; calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx); dash_gradient.draw(x1, y1, x2, y2, 1.0, 0); // fractional line positioning (red) //--------------- fill_color_array(gradient_colors, agg::rgba(1,0,0), agg::rgba(1,1,1)); x1 = 21.5; y1 = 120 + (i - 1) * 3.1; x2 = 52.5; y2 = 120 + (i - 1) * 3.1; calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx); dash_gradient.draw(x1, y1, x2, y2, 1.0, 0); // fractional line width 2..0 (green) fill_color_array(gradient_colors, agg::rgba(0,1,0), agg::rgba(1,1,1)); x1 = 52.5; y1 = 118 + i * 3; x2 = 83.5; y2 = 118 + i * 3; calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx); dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 0); // stippled fractional width 2..0 (blue) fill_color_array(gradient_colors, agg::rgba(0,0,1), agg::rgba(1,1,1)); x1 = 83.5; y1 = 119 + i * 3; x2 = 114.5; y2 = 119 + i * 3; calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx); dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 3.0); ren_sl.color(agg::rgba(1,1,1)); if(i <= 10) { // integral line width, horz aligned (mipmap test) //------------------- dash.draw(125.5, 119.5 + (i + 2) * (i / 2.0), 135.5, 119.5 + (i + 2) * (i / 2.0), i, 0.0); } // fractional line width 0..2, 1 px H //----------------- dash.draw(17.5 + i * 4, 192, 18.5 + i * 4, 192, i / 10.0, 0); // fractional line positioning, 1 px H //----------------- dash.draw(17.5 + i * 4 + (i - 1) / 10.0, 186, 18.5 + i * 4 + (i - 1) / 10.0, 186, 1.0, 0); } // Triangles //--------------- for (int i = 1; i <= 13; i++) { fill_color_array(gradient_colors, agg::rgba(1,1,1), agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25)); calc_linear_gradient_transform(width() - 150, height() - 20 - i * (i + 1.5), width() - 20, height() - 20 - i * (i + 1), gradient_mtx); ras.reset(); ras.move_to_d(width() - 150, height() - 20 - i * (i + 1.5)); ras.line_to_d(width() - 20, height() - 20 - i * (i + 1)); ras.line_to_d(width() - 20, height() - 20 - i * (i + 2)); agg::render_scanlines(ras, sl, ren_gradient); } */ base.OnDraw(renderer); }
/* void draw_curve(Pattern patt, IRasterizer ras, Renderer ren, PatternSource src, IVertexSource vs) { patt.create(src); ren.scale_x(m_scale_x.value()); ren.start_x(m_start_x.value()); ras.add_path(vs); } */ public override void OnDraw() { #if SourceDepth24 FormatRGB pf = new FormatRGB(rbuf_window(), new BlenderBGR()); #else FormatRGBA pf = new FormatRGBA(rbuf_window(), new BlenderBGRA()); #endif FormatClippingProxy ren_base = new FormatClippingProxy(pf); ren_base.clear(new RGBA_Doubles(1.0, 1.0, .95)); rasterizer_scanline_aa ras = new rasterizer_scanline_aa(); scanline_packed_8 sl = new scanline_packed_8(); // Pattern source. Must have an interface: // width() const // height() const // pixel(int x, int y) const // Any agg::renderer_base<> or derived // is good for the use as a source. //----------------------------------- pattern_src_brightness_to_alpha_RGBA_Bytes p1 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(0)); pattern_src_brightness_to_alpha_RGBA_Bytes p2 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(1)); pattern_src_brightness_to_alpha_RGBA_Bytes p3 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(2)); pattern_src_brightness_to_alpha_RGBA_Bytes p4 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(3)); pattern_src_brightness_to_alpha_RGBA_Bytes p5 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(4)); pattern_src_brightness_to_alpha_RGBA_Bytes p6 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(5)); pattern_src_brightness_to_alpha_RGBA_Bytes p7 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(6)); pattern_src_brightness_to_alpha_RGBA_Bytes p8 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(7)); pattern_src_brightness_to_alpha_RGBA_Bytes p9 = new pattern_src_brightness_to_alpha_RGBA_Bytes(rbuf_img(8)); //pattern_filter_bilinear_rgba pattern_filter_bilinear_RGBA_Bytes fltr; // Filtering functor // agg::line_image_pattern is the main container for the patterns. It creates // a copy of the patterns extended according to the needs of the filter. // agg::line_image_pattern can operate with arbitrary image width, but if the // width of the pattern is power of 2, it's better to use the modified // version agg::line_image_pattern_pow2 because it works about 15-25 percent // faster than agg::line_image_pattern (because of using simple masking instead // of expensive '%' operation). //typedef agg::line_image_pattern<agg::pattern_filter_bilinear_RGBA_Bytes> pattern_type; //typedef agg::renderer_base<pixfmt> base_ren_type; //typedef agg::renderer_outline_image<base_ren_type, pattern_type> renderer_type; //typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type; //-- Create with specifying the source //pattern_type patt(fltr, src); //-- Create uninitialized and set the source line_image_pattern patt = new line_image_pattern(new pattern_filter_bilinear_RGBA_Bytes()); //renderer_outline_image ren_img = new renderer_outline_image(, patt); /* renderer_type ren_img(ren_base, patt); rasterizer_type ras_img(ren_img); draw_curve(patt, ras_img, ren_img, p1, m_curve1.curve()); draw_curve(patt, ras_img, ren_img, p2, m_curve2.curve()); draw_curve(patt, ras_img, ren_img, p3, m_curve3.curve()); draw_curve(patt, ras_img, ren_img, p4, m_curve4.curve()); draw_curve(patt, ras_img, ren_img, p5, m_curve5.curve()); draw_curve(patt, ras_img, ren_img, p6, m_curve6.curve()); draw_curve(patt, ras_img, ren_img, p7, m_curve7.curve()); draw_curve(patt, ras_img, ren_img, p8, m_curve8.curve()); draw_curve(patt, ras_img, ren_img, p9, m_curve9.curve()); */ base.OnDraw(); }
void DrawImage(IImage sourceImage, double DestX, double DestY, double HotspotOffsetX, double HotspotOffsetY, double ScaleX, double ScaleY, double AngleRad, RGBA_Bytes Color32, ref RectangleD pFinalBlitBounds, bool doDrawing, bool oneMinusSourceAlphaOne) { Affine destRectTransform = Affine.NewIdentity(); if (HotspotOffsetX != 0.0f || HotspotOffsetY != 0.0f) { destRectTransform *= Affine.NewTranslation(-HotspotOffsetX, -HotspotOffsetY); } if (ScaleX != 1 || ScaleY != 1) { destRectTransform *= Affine.NewScaling(ScaleX, ScaleY); } if (AngleRad != 0) { destRectTransform *= Affine.NewRotation(AngleRad); } if (DestX != 0 || DestY != 0) { destRectTransform *= Affine.NewTranslation(DestX, DestY); } int SourceBufferWidth = (int)sourceImage.Width(); int SourceBufferHeight = (int)sourceImage.Height(); RectPath.Clear(); RectPath.MoveTo(0, 0); RectPath.LineTo(SourceBufferWidth, 0); RectPath.LineTo(SourceBufferWidth, SourceBufferHeight); RectPath.LineTo(0, SourceBufferHeight); RectPath.ClosePolygon(); // Calculate the bounds. LBB [10/5/2004] const int ERROR_ADD = 0; double BoundXDouble, BoundYDouble; BoundXDouble = 0; BoundYDouble = 0; destRectTransform.Transform(ref BoundXDouble, ref BoundYDouble); double BoundX = (double)BoundXDouble; double BoundY = (double)BoundYDouble; pFinalBlitBounds.Left = Math.Floor(BoundX - ERROR_ADD); pFinalBlitBounds.Right = Math.Ceiling(BoundX + ERROR_ADD); pFinalBlitBounds.Top = Math.Floor(BoundY - ERROR_ADD); pFinalBlitBounds.Bottom = Math.Ceiling(BoundY + ERROR_ADD); BoundXDouble = SourceBufferWidth; BoundYDouble = 0; destRectTransform.Transform(ref BoundXDouble, ref BoundYDouble); BoundX = (double)BoundXDouble; BoundY = (double)BoundYDouble; pFinalBlitBounds.Left = Math.Min((long)Math.Floor(BoundX - ERROR_ADD), pFinalBlitBounds.Left); pFinalBlitBounds.Right = Math.Max((long)Math.Ceiling(BoundX + ERROR_ADD), pFinalBlitBounds.Right); pFinalBlitBounds.Top = Math.Min((long)Math.Floor(BoundY - ERROR_ADD), pFinalBlitBounds.Top); pFinalBlitBounds.Bottom = Math.Max((long)Math.Ceiling(BoundY + ERROR_ADD), pFinalBlitBounds.Bottom); BoundXDouble = SourceBufferWidth; BoundYDouble = SourceBufferHeight; destRectTransform.Transform(ref BoundXDouble, ref BoundYDouble); BoundX = (double)BoundXDouble; BoundY = (double)BoundYDouble; pFinalBlitBounds.Left = Math.Min((long)Math.Floor(BoundX - ERROR_ADD), pFinalBlitBounds.Left); pFinalBlitBounds.Right = Math.Max((long)Math.Ceiling(BoundX + ERROR_ADD), pFinalBlitBounds.Right); pFinalBlitBounds.Top = Math.Min((long)Math.Floor(BoundY - ERROR_ADD), pFinalBlitBounds.Top); pFinalBlitBounds.Bottom = Math.Max((long)Math.Ceiling(BoundY + ERROR_ADD), pFinalBlitBounds.Bottom); BoundXDouble = 0; BoundYDouble = SourceBufferHeight; destRectTransform.Transform(ref BoundXDouble, ref BoundYDouble); BoundX = (double)BoundXDouble; BoundY = (double)BoundYDouble; pFinalBlitBounds.Left = Math.Min((long)Math.Floor(BoundX - ERROR_ADD), pFinalBlitBounds.Left); pFinalBlitBounds.Right = Math.Max((long)Math.Ceiling(BoundX + ERROR_ADD), pFinalBlitBounds.Right); pFinalBlitBounds.Top = Math.Min((long)Math.Floor(BoundY - ERROR_ADD), pFinalBlitBounds.Top); pFinalBlitBounds.Bottom = Math.Max((long)Math.Ceiling(BoundY + ERROR_ADD), pFinalBlitBounds.Bottom); if (!doDrawing) { return; } if (m_DestImage.OriginOffset.x != 0 || m_DestImage.OriginOffset.y != 0) { destRectTransform *= Affine.NewTranslation(-m_DestImage.OriginOffset.x, -m_DestImage.OriginOffset.y); } Affine sourceRectTransform = new Affine(destRectTransform); // We invert it because it is the transform to make the image go to the same position as the polygon. LBB [2/24/2004] sourceRectTransform.Invert(); span_allocator spanAllocator = new span_allocator(); span_interpolator_linear interpolator = new span_interpolator_linear(sourceRectTransform); ImageBuffer sourceImageWithBlender = (ImageBuffer)sourceImage;// new ImageBuffer(sourceImage, new BlenderBGRA()); span_image_filter_rgba_bilinear_clip spanImageFilter; ImageBufferAccessorClip source = new ImageBufferAccessorClip(sourceImageWithBlender, RGBA_Doubles.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes()); spanImageFilter = new span_image_filter_rgba_bilinear_clip(source, RGBA_Doubles.rgba_pre(0, 0, 0, 0), interpolator); rasterizer_scanline_aa rasterizer = new rasterizer_scanline_aa(); rasterizer.SetVectorClipBox(0, 0, m_DestImage.Width(), m_DestImage.Height()); scanline_packed_8 scanlineCache = new scanline_packed_8(); //scanline_unpacked_8 scanlineCache = new scanline_unpacked_8(); conv_transform transfromedRect = new conv_transform(RectPath, destRectTransform); rasterizer.add_path(transfromedRect); #if false bool HighQualityFilter = (BlitXParams.m_OptionalFlags & CBlitXParams::BlitHighQualityFilter) != 0 && (BlitXParams.m_OptionalFlags & CBlitXParams::RenderOneMinusScrAlpha_One) == 0; if (HighQualityFilter) {