Example #1
0
        private void RenderSolidSingleScanLine(IImageFloat destImage, IScanlineCache scanLine, RGBA_Floats color)
        {
            int          y            = scanLine.y();
            int          num_spans    = scanLine.num_spans();
            ScanlineSpan scanlineSpan = scanLine.begin();

            byte[] ManagedCoversArray = scanLine.GetCovers();
            for (; ;)
            {
                int x = scanlineSpan.x;
                if (scanlineSpan.len > 0)
                {
                    destImage.blend_solid_hspan(x, y, scanlineSpan.len, color, ManagedCoversArray, scanlineSpan.cover_index);
                }
                else
                {
                    int x2 = (x - (int)scanlineSpan.len - 1);
                    destImage.blend_hline(x, y, x2, color, ManagedCoversArray[scanlineSpan.cover_index]);
                }
                if (--num_spans == 0)
                {
                    break;
                }
                scanlineSpan = scanLine.GetNextScanlineSpan();
            }
        }
Example #2
0
        private void GenerateAndRenderSingleScanline(IScanlineCache scanLineCache, IImageFloat destImageFloat, span_allocator alloc, ISpanGeneratorFloat span_gen)
        {
            int          y            = scanLineCache.y();
            int          num_spans    = scanLineCache.num_spans();
            ScanlineSpan scanlineSpan = scanLineCache.begin();

            byte[] ManagedCoversArray = scanLineCache.GetCovers();
            for (; ;)
            {
                int x   = scanlineSpan.x;
                int len = scanlineSpan.len;
                if (len < 0)
                {
                    len = -len;
                }

                if (tempSpanColorsFloats.Capacity() < len)
                {
                    tempSpanColorsFloats.Capacity(len);
                }

                span_gen.generate(tempSpanColorsFloats.Array, 0, x, y, len);
                bool useFirstCoverForAll = scanlineSpan.len < 0;
                destImageFloat.blend_color_hspan(x, y, len, tempSpanColorsFloats.Array, 0, ManagedCoversArray, scanlineSpan.cover_index, useFirstCoverForAll);

                if (--num_spans == 0)
                {
                    break;
                }
                scanlineSpan = scanLineCache.GetNextScanlineSpan();
            }
        }
Example #3
0
        protected override void RenderSolidSingleScanLine(IImageByte destImage, IScanlineCache scanLineCache, Color color)
        {
            int          y            = scanLineCache.y();
            int          num_spans    = scanLineCache.num_spans();
            ScanlineSpan scanlineSpan = scanLineCache.begin();

            byte[] ManagedCoversArray = scanLineCache.GetCovers();
            for (; ;)
            {
                int x          = scanlineSpan.x;
                int num_pix    = scanlineSpan.len;
                int coverIndex = scanlineSpan.cover_index;

                do
                {
                    int a = (ManagedCoversArray[coverIndex++] * color.Alpha0To255) >> 8;
                    m_square.draw(destImage.NewGraphics2D().Rasterizer, m_sl, destImage,
                                  new Color(color.Red0To255, color.Green0To255, color.Blue0To255, a),
                                  x, y);
                    ++x;
                }while (--num_pix > 0);
                if (--num_spans == 0)
                {
                    break;
                }
                scanlineSpan = scanLineCache.GetNextScanlineSpan();
            }
        }
Example #4
0
        //========================================================render_all_paths
        public static void RenderSolidAllPaths(IPixelFormat pixFormat,
            IRasterizer<T> ras,
            IScanlineCache sl,
            IVertexSource<T> vs,
            RGBA_Bytes[] color_storage,
            uint[] path_id,
            uint num_paths)
        {
            for (uint i = 0; i < num_paths; i++)
            {
                ras.Reset();

#if use_timers
                AddPathTimer.Start();
#endif
                ras.AddPath(vs, path_id[i]);
#if use_timers
                AddPathTimer.Stop();
#endif


#if use_timers
                RenderSLTimer.Start();
#endif
                RenderSolid(pixFormat, ras, sl, color_storage[i]);
#if use_timers
                RenderSLTimer.Stop();
#endif
            }
        }
Example #5
0
		protected override void RenderSolidSingleScanLine(IImageByte destImage, IScanlineCache scanLineCache, RGBA_Bytes color)
		{
			int y = scanLineCache.y();
			int num_spans = scanLineCache.num_spans();
			ScanlineSpan scanlineSpan = scanLineCache.begin();

			byte[] ManagedCoversArray = scanLineCache.GetCovers();
			for (; ; )
			{
				int x = scanlineSpan.x;
				int num_pix = scanlineSpan.len;
				int coverIndex = scanlineSpan.cover_index;

				do
				{
					int a = (ManagedCoversArray[coverIndex++] * color.Alpha0To255) >> 8;
					m_square.draw(destImage.NewGraphics2D().Rasterizer, m_sl, destImage,
									new RGBA_Bytes(color.Red0To255, color.Green0To255, color.Blue0To255, a),
									x, y);
					++x;
				}
				while (--num_pix > 0);
				if (--num_spans == 0) break;
				scanlineSpan = scanLineCache.GetNextScanlineSpan();
			}
		}
Example #6
0
 public void RenderSolid(IImageFloat destImage, IRasterizer rasterizer, IScanlineCache scanLine, RGBA_Floats color)
 {
     if (rasterizer.rewind_scanlines())
     {
         scanLine.reset(rasterizer.min_x(), rasterizer.max_x());
         while (rasterizer.sweep_scanline(scanLine))
         {
             RenderSolidSingleScanLine(destImage, scanLine, color);
         }
     }
 }
Example #7
0
		public void RenderSolid(IImageFloat destImage, IRasterizer rasterizer, IScanlineCache scanLine, RGBA_Floats color)
		{
			if (rasterizer.rewind_scanlines())
			{
				scanLine.reset(rasterizer.min_x(), rasterizer.max_x());
				while (rasterizer.sweep_scanline(scanLine))
				{
					RenderSolidSingleScanLine(destImage, scanLine, color);
				}
			}
		}
Example #8
0
		public void draw(ScanlineRasterizer ras, IScanlineCache sl, IImageByte destImage, RGBA_Bytes color,
				  double x, double y)
		{
			ras.reset();
			ras.move_to_d(x * m_size, y * m_size);
			ras.line_to_d(x * m_size + m_size, y * m_size);
			ras.line_to_d(x * m_size + m_size, y * m_size + m_size);
			ras.line_to_d(x * m_size, y * m_size + m_size);
			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.RenderSolid(destImage, ras, sl, color);
		}
Example #9
0
 public void draw(ScanlineRasterizer ras, IScanlineCache sl, IImageByte destImage, RGBA_Bytes color,
           double x, double y)
 {
     ras.reset();
     ras.move_to_d(x * m_size, y * m_size);
     ras.line_to_d(x * m_size + m_size, y * m_size);
     ras.line_to_d(x * m_size + m_size, y * m_size + m_size);
     ras.line_to_d(x * m_size, y * m_size + m_size);
     ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
     scanlineRenderer.render_scanlines_aa_solid(destImage, ras, sl, color);
 }
Example #10
0
 public void GenerateAndRender(IRasterizer rasterizer, IScanlineCache scanlineCache, IImageFloat destImage, span_allocator spanAllocator, ISpanGeneratorFloat spanGenerator)
 {
     if (rasterizer.rewind_scanlines())
     {
         scanlineCache.reset(rasterizer.min_x(), rasterizer.max_x());
         spanGenerator.prepare();
         while (rasterizer.sweep_scanline(scanlineCache))
         {
             GenerateAndRenderSingleScanline(scanlineCache, destImage, spanAllocator, spanGenerator);
         }
     }
 }
Example #11
0
        public PixMap(PixelFormat format, uint width, uint height)
            : this()
        {
            Guard.GreaterThan(width, 0u);
            Guard.GreaterThan(height, 0u);
            _pixelFormat = _injector.Resolve <IPixelFormatFactory>().CreatePixelFormat(format, width, height, out imageBytes);
            _buffer      = _pixelFormat.GetRenderingBuffer();

            _renderer      = this._injector.Resolve <RendererBase>();
            _scanlineCache = this._injector.Resolve <IScanlineCache>();
            _rasterizer    = this._injector.Resolve <IRasterizer>();
        }
Example #12
0
        public PixMap(PixelFormat format, uint width, uint height)
            : this()
        {
            Guard.GreaterThan(width, 0u);
            Guard.GreaterThan(height, 0u);
            _pixelFormat = _injector.Resolve<IPixelFormatFactory>().CreatePixelFormat(format, width, height, out imageBytes);
            _buffer = _pixelFormat.GetRenderingBuffer();

            _renderer = this._injector.Resolve<RendererBase>();
            _scanlineCache = this._injector.Resolve<IScanlineCache>();
            _rasterizer = this._injector.Resolve<IRasterizer>();
        }
Example #13
0
 //=====================================================render_scanlines_aa
 public static void GenerateAndRender(IRasterizer<T> ras, IScanlineCache sl, IPixelFormat ren,
                          SpanAllocator alloc, ISpanGenerator<T> span_gen)
 {
     if (ras.RewindScanlines())
     {
         sl.Reset(ras.MinX, ras.MaxX);
         span_gen.Prepare();
         while (ras.SweepScanline(sl))
         {
             GenerateAndRenderSingleScanline(sl, ren, alloc, span_gen);
         }
     }
 }
Example #14
0
        public void RenderSolidAllPaths(IImageByte destImage,
                                        IRasterizer ras,
                                        IScanlineCache sl,
                                        IVertexSource vs,
                                        RGBA_Bytes[] color_storage,
                                        int[] path_id,
                                        int num_paths)
        {
            for (int i = 0; i < num_paths; i++)
            {
                ras.reset();

                ras.add_path(vs, path_id[i]);

                RenderSolid(destImage, ras, sl, color_storage[i]);
            }
        }
Example #15
0
		public void RenderSolidAllPaths(IImageByte destImage,
			IRasterizer ras,
			IScanlineCache sl,
			IVertexSource vs,
			RGBA_Bytes[] color_storage,
			int[] path_id,
			int num_paths)
		{
			for (int i = 0; i < num_paths; i++)
			{
				ras.reset();

				ras.add_path(vs, path_id[i]);

				RenderSolid(destImage, ras, sl, color_storage[i]);
			}
		}
Example #16
0
        //================================================render_scanline_aa_solid
        private static void RenderSolidSingleScanLine(IPixelFormat pixFormat, IScanlineCache scanLine, RGBA_Bytes color)
        {
#if use_timers
            render_scanline_aa_solidTimer.Start();
#endif
            int y = scanLine.Y;
            uint num_spans = scanLine.NumSpans;
            ScanlineSpan scanlineSpan = scanLine.Begin();

            byte[] ManagedCoversArray = scanLine.Covers;
            unsafe
            {
                fixed (byte* pCovers = ManagedCoversArray)
                {
                    for (; ; )
                    {
                        int x = scanlineSpan.X;
                        if (scanlineSpan.Len > 0)
                        {
#if use_timers
                            render_scanline_aa_solid_blend_solid_hspan.Start();
#endif
                            pixFormat.BlendSolidHSpan(x, y, (uint)scanlineSpan.Len, color, &pCovers[scanlineSpan.CoverIndex]);
#if use_timers
                            render_scanline_aa_solid_blend_solid_hspan.Stop();
#endif
                        }
                        else
                        {
#if use_timers
                            render_scanline_aa_solid_blend_hline.Start();
#endif
                            pixFormat.BlendHLine(x, y, (x - (int)scanlineSpan.Len - 1), color, pCovers[scanlineSpan.CoverIndex]);
#if use_timers
                            render_scanline_aa_solid_blend_hline.Stop();
#endif
                        }
                        if (--num_spans == 0) break;
                        scanlineSpan = scanLine.GetNextScanlineSpan();
                    }
                }
            }
#if use_timers
            render_scanline_aa_solidTimer.Stop();
#endif
        }
Example #17
0
        internal void render_gouraud(IImageByte backBuffer, IScanlineCache sl, IRasterizer ras, RenderPoint[] points)
        {
            ImageBuffer image = new ImageBuffer();

            image.Attach(backBuffer, new BlenderZBuffer());

            ImageClippingProxy ren_base = new ImageClippingProxy(image);

            MatterHackers.Agg.span_allocator span_alloc = new span_allocator();
            span_gouraud_rgba span_gen = new span_gouraud_rgba();

            span_gen.colors(points[0].color, points[1].color, points[2].color);
            span_gen.triangle(points[0].position.x, points[0].position.y, points[1].position.x, points[1].position.y, points[2].position.x, points[2].position.y);
            ras.add_path(span_gen);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);
        }
Example #18
0
        //======================================================render_scanline_aa
        private static void GenerateAndRenderSingleScanline(IScanlineCache sl, IPixelFormat ren,
                                SpanAllocator alloc, ISpanGenerator<T> span_gen)
        {
            int y = sl.Y;
            uint num_spans = sl.NumSpans;
            ScanlineSpan scanlineSpan = sl.Begin();

            byte[] ManagedCoversArray = sl.Covers;
            unsafe
            {
                fixed (byte* pCovers = ManagedCoversArray)
                {
                    for (; ; )
                    {
                        int x = scanlineSpan.X;
                        int len = scanlineSpan.Len;
                        if (len < 0) len = -len;

                        if (tempSpanColors.Capacity() < len)
                        {
                            tempSpanColors.Allocate((uint)(len));
                        }

                        fixed (RGBA_Bytes* pColors = tempSpanColors.Array)
                        {
                            span_gen.Generate(pColors, x, y, (uint)len);
#if use_timers
                            blend_color_hspan.Start();
#endif
                            ren.BlendColorHSpan(x, y, (uint)len, pColors, (scanlineSpan.Len < 0) ? null : &pCovers[scanlineSpan.CoverIndex], pCovers[scanlineSpan.CoverIndex]);
#if use_timers
                            blend_color_hspan.Stop();
#endif
                        }

                        if (--num_spans == 0) break;
                        scanlineSpan = sl.GetNextScanlineSpan();
                    }
                }
            }
        }
Example #19
0
		private void RenderSolidSingleScanLine(IImageFloat destImage, IScanlineCache scanLine, RGBA_Floats color)
		{
			int y = scanLine.y();
			int num_spans = scanLine.num_spans();
			ScanlineSpan scanlineSpan = scanLine.begin();

			byte[] ManagedCoversArray = scanLine.GetCovers();
			for (; ; )
			{
				int x = scanlineSpan.x;
				if (scanlineSpan.len > 0)
				{
					destImage.blend_solid_hspan(x, y, scanlineSpan.len, color, ManagedCoversArray, scanlineSpan.cover_index);
				}
				else
				{
					int x2 = (x - (int)scanlineSpan.len - 1);
					destImage.blend_hline(x, y, x2, color, ManagedCoversArray[scanlineSpan.cover_index]);
				}
				if (--num_spans == 0) break;
				scanlineSpan = scanLine.GetNextScanlineSpan();
			}
		}
        // Sweeps one scanline with one style index. The style ID can be
        // determined by calling style().
        //template<class Scanline>
        public bool sweep_scanline(IScanlineCache sl, int style_idx)
        {
            int scan_y = m_scan_y - 1;

            if (scan_y > m_Rasterizer.max_y())
            {
                return(false);
            }

            sl.ResetSpans();

            int master_alpha = aa_mask;

            if (style_idx < 0)
            {
                style_idx = 0;
            }
            else
            {
                style_idx++;
                master_alpha = m_master_alpha[(int)(m_ast[(int)style_idx] + m_min_style - 1)];
            }

            style_info st = m_styles[m_ast[style_idx]];

            int     num_cells  = (int)st.num_cells;
            int     CellOffset = st.start_cell;
            cell_aa cell       = m_cells[CellOffset];

            int cover = 0;

            while (num_cells-- != 0)
            {
                int alpha;
                int x    = cell.x;
                int area = cell.area;

                cover += cell.cover;

                cell = m_cells[++CellOffset];

                if (area != 0)
                {
                    alpha = calculate_alpha((cover << (poly_subpixel_shift + 1)) - area,
                                            master_alpha);
                    sl.add_cell(x, alpha);
                    x++;
                }

                if (num_cells != 0 && cell.x > x)
                {
                    alpha = calculate_alpha(cover << (poly_subpixel_shift + 1),
                                            master_alpha);
                    if (alpha != 0)
                    {
                        sl.add_span(x, cell.x - x, alpha);
                    }
                }
            }

            if (sl.num_spans() == 0)
            {
                return(false);
            }
            sl.finalize(scan_y);
            return(true);
        }
		internal void render_gouraud(IImageByte backBuffer, IScanlineCache sl, IRasterizer ras, RenderPoint[] points)
		{
			ImageBuffer image = new ImageBuffer();
			image.Attach(backBuffer, new BlenderZBuffer());

			ImageClippingProxy ren_base = new ImageClippingProxy(image);

			MatterHackers.Agg.span_allocator span_alloc = new span_allocator();
			span_gouraud_rgba span_gen = new span_gouraud_rgba();

			span_gen.colors(points[0].color, points[1].color, points[2].color);
			span_gen.triangle(points[0].position.x, points[0].position.y, points[1].position.x, points[1].position.y, points[2].position.x, points[2].position.y);
			ras.add_path(span_gen);
			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);
		}
Example #22
0
 public bool SweepScanline(IScanlineCache sl)
 {
     throw new NotImplementedException ();
 }
        // Sweeps one scanline with one style index. The style ID can be 
        // determined by calling style(). 
        //template<class Scanline> 
        public bool sweep_scanline(IScanlineCache sl, int style_idx)
        {
            int scan_y = m_scan_y - 1;
            if(scan_y > m_Rasterizer.max_y()) return false;

            sl.ResetSpans();

            int master_alpha = aa_mask;

            if(style_idx < 0) 
            {
                style_idx = 0;
            }
            else 
            {
                style_idx++;
                master_alpha = m_master_alpha[(int)(m_ast[(int)style_idx] + m_min_style - 1)];
            }

            style_info st = m_styles[m_ast[style_idx]];

            int num_cells = (int)st.num_cells;
            int CellOffset = st.start_cell;
            cell_aa cell = m_cells[CellOffset];

            int cover = 0;
            while(num_cells-- != 0)
            {
                int alpha;
                int x = cell.x;
                int area = cell.area;

                cover += cell.cover;

                cell = m_cells[++CellOffset];

                if(area != 0)
                {
                    alpha = calculate_alpha((cover << (poly_subpixel_shift + 1)) - area,
                                            master_alpha);
                    sl.add_cell(x, alpha);
                    x++;
                }

                if(num_cells != 0 && cell.x > x)
                {
                    alpha = calculate_alpha(cover << (poly_subpixel_shift + 1),
                                            master_alpha);
                    if(alpha != 0)
                    {
                        sl.add_span(x, cell.x - x, alpha);
                    }
                }
            }

            if(sl.num_spans() == 0) return false;
            sl.finalize(scan_y);
            return true;
        }
 public bool sweep_scanline(IScanlineCache sl)
 {
     throw new System.NotImplementedException();
 }
Example #25
0
		//template<class Scanline, class Ras>
		public void render_gouraud(IImageByte backBuffer, IScanlineCache sl, IRasterizer ras)
		{
			double alpha = m_alpha.Value;
			double brc = 1;
#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr());
#else
			ImageBuffer image = new ImageBuffer();
			image.Attach(backBuffer, new BlenderBGRA());
#endif
			ImageClippingProxy ren_base = new ImageClippingProxy(image);

			MatterHackers.Agg.span_allocator span_alloc = new span_allocator();
			span_gouraud_rgba span_gen = new span_gouraud_rgba();

			ras.gamma(new gamma_linear(0.0, m_gamma.Value));

			double d = m_dilation.Value;

			// 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);

			span_gen.colors(new RGBA_Floats(1, 0, 0, alpha),
							new RGBA_Floats(0, 1, 0, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d);
			ras.add_path(span_gen);
			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

			span_gen.colors(new RGBA_Floats(0, 1, 0, alpha),
							new RGBA_Floats(0, 0, 1, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d);
			ras.add_path(span_gen);
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

			span_gen.colors(new RGBA_Floats(0, 0, 1, alpha),
							new RGBA_Floats(1, 0, 0, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d);
			ras.add_path(span_gen);
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

			brc = 1 - brc;
			span_gen.colors(new RGBA_Floats(1, 0, 0, alpha),
							new RGBA_Floats(0, 1, 0, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d);
			ras.add_path(span_gen);
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

			span_gen.colors(new RGBA_Floats(0, 1, 0, alpha),
							new RGBA_Floats(0, 0, 1, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d);
			ras.add_path(span_gen);
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

			span_gen.colors(new RGBA_Floats(0, 0, 1, alpha),
							new RGBA_Floats(1, 0, 0, alpha),
							new RGBA_Floats(brc, brc, brc, alpha));
			span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d);
			ras.add_path(span_gen);
			scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);
		}
Example #26
0
		public ImageGraphics2D(IImageByte destImage, ScanlineRasterizer rasterizer, IScanlineCache scanlineCache)
			: base(destImage, rasterizer)
		{
			m_ScanlineCache = scanlineCache;
		}
Example #27
0
 public ImageGraphics2D(IImageByte destImage, ScanlineRasterizer rasterizer, IScanlineCache scanlineCache)
     : base(destImage, rasterizer)
 {
     this.scanlineCache = scanlineCache;
 }
Example #28
0
		private void GenerateAndRenderSingleScanline(IScanlineCache scanLineCache, IImageFloat destImageFloat, span_allocator alloc, ISpanGeneratorFloat span_gen)
		{
			int y = scanLineCache.y();
			int num_spans = scanLineCache.num_spans();
			ScanlineSpan scanlineSpan = scanLineCache.begin();

			byte[] ManagedCoversArray = scanLineCache.GetCovers();
			for (; ; )
			{
				int x = scanlineSpan.x;
				int len = scanlineSpan.len;
				if (len < 0) len = -len;

				if (tempSpanColorsFloats.Capacity() < len)
				{
					tempSpanColorsFloats.Capacity(len);
				}

				span_gen.generate(tempSpanColorsFloats.Array, 0, x, y, len);
				bool useFirstCoverForAll = scanlineSpan.len < 0;
				destImageFloat.blend_color_hspan(x, y, len, tempSpanColorsFloats.Array, 0, ManagedCoversArray, scanlineSpan.cover_index, useFirstCoverForAll);

				if (--num_spans == 0) break;
				scanlineSpan = scanLineCache.GetNextScanlineSpan();
			}
		}
Example #29
0
		public void RenderCompound(rasterizer_compound_aa ras, IScanlineCache sl_aa, IScanlineCache sl_bin, IImageByte imageFormat, span_allocator alloc, IStyleHandler sh)
		{
#if false
            unsafe
            {
                if (ras.rewind_scanlines())
                {
                    int min_x = ras.min_x();
                    int len = ras.max_x() - min_x + 2;
                    sl_aa.reset(min_x, ras.max_x());
                    sl_bin.reset(min_x, ras.max_x());

                    //typedef typename BaseRenderer::color_type color_type;
                    ArrayPOD<RGBA_Bytes> color_span = alloc.allocate((int)len * 2);
                    byte[] ManagedCoversArray = sl_aa.GetCovers();
                    fixed (byte* pCovers = ManagedCoversArray)
                    {
                        fixed (RGBA_Bytes* pColorSpan = color_span.Array)
                        {
                            int mix_bufferOffset = len;
                            int num_spans;

                            int num_styles;
                            int style;
                            bool solid;
                            while ((num_styles = ras.sweep_styles()) > 0)
                            {
                                if (num_styles == 1)
                                {
                                    // Optimization for a single style. Happens often
                                    //-------------------------
                                    if (ras.sweep_scanline(sl_aa, 0))
                                    {
                                        style = ras.style(0);
                                        if (sh.is_solid(style))
                                        {
                                            // Just solid fill
                                            //-----------------------
                                            RenderSolidSingleScanLine(imageFormat, sl_aa, sh.color(style));
                                        }
                                        else
                                        {
                                            // Arbitrary span generator
                                            //-----------------------
                                            ScanlineSpan span_aa = sl_aa.Begin();
                                            num_spans = sl_aa.num_spans();
                                            for (; ; )
                                            {
                                                len = span_aa.len;
                                                sh.generate_span(pColorSpan,
                                                                 span_aa.x,
                                                                 sl_aa.y(),
                                                                 (int)len,
                                                                 style);

                                                imageFormat.blend_color_hspan(span_aa.x,
                                                                      sl_aa.y(),
                                                                      (int)span_aa.len,
                                                                      pColorSpan,
                                                                      &pCovers[span_aa.cover_index], 0);
                                                if (--num_spans == 0) break;
                                                span_aa = sl_aa.GetNextScanlineSpan();
                                            }
                                        }
                                    }
                                }
                                else // there are multiple styles
                                {
                                    if (ras.sweep_scanline(sl_bin, -1))
                                    {
                                        // Clear the spans of the mix_buffer
                                        //--------------------
                                        ScanlineSpan span_bin = sl_bin.Begin();
                                        num_spans = sl_bin.num_spans();
                                        for (; ; )
                                        {
                                            agg_basics.MemClear((byte*)&pColorSpan[mix_bufferOffset + span_bin.x - min_x],
                                                   span_bin.len * sizeof(RGBA_Bytes));

                                            if (--num_spans == 0) break;
                                            span_bin = sl_bin.GetNextScanlineSpan();
                                        }

                                        for (int i = 0; i < num_styles; i++)
                                        {
                                            style = ras.style(i);
                                            solid = sh.is_solid(style);

                                            if (ras.sweep_scanline(sl_aa, (int)i))
                                            {
                                                //IColorType* colors;
                                                //IColorType* cspan;
                                                //typename ScanlineAA::cover_type* covers;
                                                ScanlineSpan span_aa = sl_aa.Begin();
                                                num_spans = sl_aa.num_spans();
                                                if (solid)
                                                {
                                                    // Just solid fill
                                                    //-----------------------
                                                    for (; ; )
                                                    {
                                                        RGBA_Bytes c = sh.color(style);
                                                        len = span_aa.len;
                                                        RGBA_Bytes* colors = &pColorSpan[mix_bufferOffset + span_aa.x - min_x];
                                                        byte* covers = &pCovers[span_aa.cover_index];
                                                        do
                                                        {
                                                            if (*covers == cover_full)
                                                            {
                                                                *colors = c;
                                                            }
                                                            else
                                                            {
                                                                colors->add(c, *covers);
                                                            }
                                                            ++colors;
                                                            ++covers;
                                                        }
                                                        while (--len != 0);
                                                        if (--num_spans == 0) break;
                                                        span_aa = sl_aa.GetNextScanlineSpan();
                                                    }
                                                }
                                                else
                                                {
                                                    // Arbitrary span generator
                                                    //-----------------------
                                                    for (; ; )
                                                    {
                                                        len = span_aa.len;
                                                        RGBA_Bytes* colors = &pColorSpan[mix_bufferOffset + span_aa.x - min_x];
                                                        RGBA_Bytes* cspan = pColorSpan;
                                                        sh.generate_span(cspan,
                                                                         span_aa.x,
                                                                         sl_aa.y(),
                                                                         (int)len,
                                                                         style);
                                                        byte* covers = &pCovers[span_aa.cover_index];
                                                        do
                                                        {
                                                            if (*covers == cover_full)
                                                            {
                                                                *colors = *cspan;
                                                            }
                                                            else
                                                            {
                                                                colors->add(*cspan, *covers);
                                                            }
                                                            ++cspan;
                                                            ++colors;
                                                            ++covers;
                                                        }
                                                        while (--len != 0);
                                                        if (--num_spans == 0) break;
                                                        span_aa = sl_aa.GetNextScanlineSpan();
                                                    }
                                                }
                                            }
                                        }

                                        // Emit the blended result as a color hspan
                                        //-------------------------
                                        span_bin = sl_bin.Begin();
                                        num_spans = sl_bin.num_spans();
                                        for (; ; )
                                        {
                                            imageFormat.blend_color_hspan(span_bin.x,
                                                                  sl_bin.y(),
                                                                  (int)span_bin.len,
                                                                  &pColorSpan[mix_bufferOffset + span_bin.x - min_x],
                                                                  null,
                                                                  cover_full);
                                            if (--num_spans == 0) break;
                                            span_bin = sl_bin.GetNextScanlineSpan();
                                        }
                                    } // if(ras.sweep_scanline(sl_bin, -1))
                                } // if(num_styles == 1) ... else
                            } // while((num_styles = ras.sweep_styles()) > 0)
                        }
                    }
                } // if(ras.rewind_scanlines())
            }
#endif
		}
Example #30
0
        public void RenderCompound(rasterizer_compound_aa ras, IScanlineCache sl_aa, IScanlineCache sl_bin, IImageByte imageFormat, span_allocator alloc, IStyleHandler sh)
        {
#if false
            unsafe
            {
                if (ras.rewind_scanlines())
                {
                    int min_x = ras.min_x();
                    int len   = ras.max_x() - min_x + 2;
                    sl_aa.reset(min_x, ras.max_x());
                    sl_bin.reset(min_x, ras.max_x());

                    //typedef typename BaseRenderer::color_type color_type;
                    ArrayPOD <RGBA_Bytes> color_span = alloc.allocate((int)len * 2);
                    byte[] ManagedCoversArray        = sl_aa.GetCovers();
                    fixed(byte *pCovers = ManagedCoversArray)
                    {
                        fixed(RGBA_Bytes *pColorSpan = color_span.Array)
                        {
                            int mix_bufferOffset = len;
                            int num_spans;

                            int  num_styles;
                            int  style;
                            bool solid;

                            while ((num_styles = ras.sweep_styles()) > 0)
                            {
                                if (num_styles == 1)
                                {
                                    // Optimization for a single style. Happens often
                                    //-------------------------
                                    if (ras.sweep_scanline(sl_aa, 0))
                                    {
                                        style = ras.style(0);
                                        if (sh.is_solid(style))
                                        {
                                            // Just solid fill
                                            //-----------------------
                                            RenderSolidSingleScanLine(imageFormat, sl_aa, sh.color(style));
                                        }
                                        else
                                        {
                                            // Arbitrary span generator
                                            //-----------------------
                                            ScanlineSpan span_aa = sl_aa.Begin();
                                            num_spans = sl_aa.num_spans();
                                            for (; ;)
                                            {
                                                len = span_aa.len;
                                                sh.generate_span(pColorSpan,
                                                                 span_aa.x,
                                                                 sl_aa.y(),
                                                                 (int)len,
                                                                 style);

                                                imageFormat.blend_color_hspan(span_aa.x,
                                                                              sl_aa.y(),
                                                                              (int)span_aa.len,
                                                                              pColorSpan,
                                                                              &pCovers[span_aa.cover_index], 0);
                                                if (--num_spans == 0)
                                                {
                                                    break;
                                                }
                                                span_aa = sl_aa.GetNextScanlineSpan();
                                            }
                                        }
                                    }
                                }
                                else // there are multiple styles
                                {
                                    if (ras.sweep_scanline(sl_bin, -1))
                                    {
                                        // Clear the spans of the mix_buffer
                                        //--------------------
                                        ScanlineSpan span_bin = sl_bin.Begin();
                                        num_spans = sl_bin.num_spans();
                                        for (; ;)
                                        {
                                            agg_basics.MemClear((byte *)&pColorSpan[mix_bufferOffset + span_bin.x - min_x],
                                                                span_bin.len * sizeof(RGBA_Bytes));

                                            if (--num_spans == 0)
                                            {
                                                break;
                                            }
                                            span_bin = sl_bin.GetNextScanlineSpan();
                                        }

                                        for (int i = 0; i < num_styles; i++)
                                        {
                                            style = ras.style(i);
                                            solid = sh.is_solid(style);

                                            if (ras.sweep_scanline(sl_aa, (int)i))
                                            {
                                                //IColorType* colors;
                                                //IColorType* cspan;
                                                //typename ScanlineAA::cover_type* covers;
                                                ScanlineSpan span_aa = sl_aa.Begin();
                                                num_spans = sl_aa.num_spans();
                                                if (solid)
                                                {
                                                    // Just solid fill
                                                    //-----------------------
                                                    for (; ;)
                                                    {
                                                        RGBA_Bytes c = sh.color(style);
                                                        len = span_aa.len;
                                                        RGBA_Bytes *colors = &pColorSpan[mix_bufferOffset + span_aa.x - min_x];
                                                        byte *      covers = &pCovers[span_aa.cover_index];
                                                        do
                                                        {
                                                            if (*covers == cover_full)
                                                            {
                                                                *colors = c;
                                                            }
                                                            else
                                                            {
                                                                colors->add(c, *covers);
                                                            }
                                                            ++colors;
                                                            ++covers;
                                                        }while (--len != 0);
                                                        if (--num_spans == 0)
                                                        {
                                                            break;
                                                        }
                                                        span_aa = sl_aa.GetNextScanlineSpan();
                                                    }
                                                }
                                                else
                                                {
                                                    // Arbitrary span generator
                                                    //-----------------------
                                                    for (; ;)
                                                    {
                                                        len = span_aa.len;
                                                        RGBA_Bytes *colors = &pColorSpan[mix_bufferOffset + span_aa.x - min_x];
                                                        RGBA_Bytes *cspan  = pColorSpan;
                                                        sh.generate_span(cspan,
                                                                         span_aa.x,
                                                                         sl_aa.y(),
                                                                         (int)len,
                                                                         style);
                                                        byte *covers = &pCovers[span_aa.cover_index];
                                                        do
                                                        {
                                                            if (*covers == cover_full)
                                                            {
                                                                *colors = *cspan;
                                                            }
                                                            else
                                                            {
                                                                colors->add(*cspan, *covers);
                                                            }
                                                            ++cspan;
                                                            ++colors;
                                                            ++covers;
                                                        }while (--len != 0);
                                                        if (--num_spans == 0)
                                                        {
                                                            break;
                                                        }
                                                        span_aa = sl_aa.GetNextScanlineSpan();
                                                    }
                                                }
                                            }
                                        }

                                        // Emit the blended result as a color hspan
                                        //-------------------------
                                        span_bin  = sl_bin.Begin();
                                        num_spans = sl_bin.num_spans();
                                        for (; ;)
                                        {
                                            imageFormat.blend_color_hspan(span_bin.x,
                                                                          sl_bin.y(),
                                                                          (int)span_bin.len,
                                                                          &pColorSpan[mix_bufferOffset + span_bin.x - min_x],
                                                                          null,
                                                                          cover_full);
                                            if (--num_spans == 0)
                                            {
                                                break;
                                            }
                                            span_bin = sl_bin.GetNextScanlineSpan();
                                        }
                                    } // if(ras.sweep_scanline(sl_bin, -1))
                                }     // if(num_styles == 1) ... else
                            }         // while((num_styles = ras.sweep_styles()) > 0)
                        }
                    }
                } // if(ras.rewind_scanlines())
            }
#endif
        }
        // Sweeps one scanline with one style index. The style ID can be
        // determined by calling style().
        //template<class Scanline>
        public bool SweepScanline(IScanlineCache sl, int style_idx)
        {
            int scan_y = m_scan_y - 1;

            if (scan_y > m_Rasterizer.MaxY)
            {
                return(false);
            }

            sl.ResetSpans();

            uint master_alpha = AAMask;

            if (style_idx < 0)
            {
                style_idx = 0;
            }
            else
            {
                style_idx++;
                master_alpha = m_master_alpha[(uint)(m_ast[(uint)style_idx] + m_min_style - 1)];
            }

            StyleInfo st = m_styles[m_ast[style_idx]];

            int    num_cells  = (int)st.num_cells;
            uint   CellOffset = st.start_cell;
            CellAA cell       = m_cells[CellOffset];

            int cover = 0;

            while (num_cells-- != 0)
            {
                uint alpha;
                int  x    = cell.X;
                int  area = cell.Area;

                cover += cell.Cover;

                cell = m_cells[++CellOffset];

                if (area != 0)
                {
                    alpha = CalculateAlpha((cover << (PolySubpixelShift + 1)) - area,
                                           master_alpha);
                    sl.AddCell(x, alpha);
                    x++;
                }

                if (num_cells != 0 && cell.X > x)
                {
                    alpha = CalculateAlpha(cover << (PolySubpixelShift + 1),
                                           master_alpha);
                    if (alpha != 0)
                    {
                        sl.AddSpan(x, cell.X - x, alpha);
                    }
                }
            }

            if (sl.NumSpans == 0)
            {
                return(false);
            }
            sl.Finalize(scan_y);
            return(true);
        }
Example #32
0
        //========================================================render_scanlines
        public static void RenderSolid(IPixelFormat pixFormat, IRasterizer<T> rasterizer, IScanlineCache scanLine, RGBA_Bytes color)
        {
            if (rasterizer.RewindScanlines())
            {
                scanLine.Reset(rasterizer.MinX, rasterizer.MaxX);
#if use_timers
                PrepareTimer.Start();
#endif
                //renderer.prepare();
#if use_timers
                PrepareTimer.Stop();
#endif
                while (rasterizer.SweepScanline(scanLine))
                {
                    Renderer<T>.RenderSolidSingleScanLine(pixFormat, scanLine, color);
                }
            }
        }
Example #33
0
 public Renderer(IPixelFormat PixelFormat, RasterizerScanlineAA<T> Rasterizer, IScanlineCache ScanlineCache)
     : base(PixelFormat, Rasterizer)
 {
     m_ScanlineCache = ScanlineCache;
 }
Example #34
0
        public static void RenderCompound(RasterizerCompoundAA<T> ras,
                                       IScanlineCache sl_aa,
                                       IScanlineCache sl_bin,
                                       IPixelFormat pixelFormat,
                                       SpanAllocator alloc,
                                       IStyleHandler sh)
        {
#if true
            unsafe
            {
                if (ras.RewindScanlines())
                {
                    int min_x = ras.MinX;
                    int len = ras.MaxX - min_x + 2;
                    sl_aa.Reset(min_x, ras.MaxX);
                    sl_bin.Reset(min_x, ras.MaxX);

                    //typedef typename BaseRenderer::color_type color_type;
                    ArrayPOD<RGBA_Bytes> color_span = alloc.Allocate((uint)len * 2);
                    byte[] ManagedCoversArray = sl_aa.Covers;
                    fixed (byte* pCovers = ManagedCoversArray)
                    {
                        fixed (RGBA_Bytes* pColorSpan = color_span.Array)
                        {
                            int mix_bufferOffset = len;
                            uint num_spans;

                            uint num_styles;
                            uint style;
                            bool solid;
                            while ((num_styles = ras.SweepStyles()) > 0)
                            {
                                if (num_styles == 1)
                                {
                                    // Optimization for a single style. Happens often
                                    //-------------------------
                                    if (ras.SweepScanline(sl_aa, 0))
                                    {
                                        style = ras.Style(0);
                                        if (sh.IsSolid(style))
                                        {
                                            // Just solid fill
                                            //-----------------------
                                            RenderSolidSingleScanLine(pixelFormat, sl_aa, sh.Color(style));
                                        }
                                        else
                                        {
                                            // Arbitrary span generator
                                            //-----------------------
                                            ScanlineSpan span_aa = sl_aa.Begin();
                                            num_spans = sl_aa.NumSpans;
                                            for (; ; )
                                            {
                                                len = span_aa.Len;
                                                sh.GenerateSpan(pColorSpan,
                                                                 span_aa.X,
                                                                 sl_aa.Y,
                                                                 (uint)len,
                                                                 style);

                                                pixelFormat.BlendColorHSpan(span_aa.X,
                                                                      sl_aa.Y,
                                                                      (uint)span_aa.Len,
                                                                      pColorSpan,
                                                                      &pCovers[span_aa.CoverIndex], 0);
                                                if (--num_spans == 0) break;
                                                span_aa = sl_aa.GetNextScanlineSpan();
                                            }
                                        }
                                    }
                                }
                                else // there are multiple styles
                                {
                                    if (ras.SweepScanline(sl_bin, -1))
                                    {
                                        // Clear the spans of the mix_buffer
                                        //--------------------
                                        ScanlineSpan span_bin = sl_bin.Begin();
                                        num_spans = sl_bin.NumSpans;
                                        for (; ; )
                                        {
                                            Basics.MemClear((byte*)&pColorSpan[mix_bufferOffset + span_bin.X - min_x],
                                                   span_bin.Len * sizeof(RGBA_Bytes));

                                            if (--num_spans == 0) break;
                                            span_bin = sl_bin.GetNextScanlineSpan();
                                        }

                                        for (uint i = 0; i < num_styles; i++)
                                        {
                                            style = ras.Style(i);
                                            solid = sh.IsSolid(style);

                                            if (ras.SweepScanline(sl_aa, (int)i))
                                            {
                                                //IColorType* colors;
                                                //IColorType* cspan;
                                                //typename ScanlineAA::cover_type* covers;
                                                ScanlineSpan span_aa = sl_aa.Begin();
                                                num_spans = sl_aa.NumSpans;
                                                if (solid)
                                                {
                                                    // Just solid fill
                                                    //-----------------------
                                                    for (; ; )
                                                    {
                                                        RGBA_Bytes c = sh.Color(style);
                                                        len = span_aa.Len;
                                                        RGBA_Bytes* colors = &pColorSpan[mix_bufferOffset + span_aa.X - min_x];
                                                        byte* covers = &pCovers[span_aa.CoverIndex];
                                                        do
                                                        {
                                                            if (*covers == CoverFull)
                                                            {
                                                                *colors = c;
                                                            }
                                                            else
                                                            {
                                                                colors->Add(c, *covers);
                                                            }
                                                            ++colors;
                                                            ++covers;
                                                        }
                                                        while (--len != 0);
                                                        if (--num_spans == 0) break;
                                                        span_aa = sl_aa.GetNextScanlineSpan();
                                                    }
                                                }
                                                else
                                                {
                                                    // Arbitrary span generator
                                                    //-----------------------
                                                    for (; ; )
                                                    {
                                                        len = span_aa.Len;
                                                        RGBA_Bytes* colors = &pColorSpan[mix_bufferOffset + span_aa.X - min_x];
                                                        RGBA_Bytes* cspan = pColorSpan;
                                                        sh.GenerateSpan(cspan,
                                                                         span_aa.X,
                                                                         sl_aa.Y,
                                                                         (uint)len,
                                                                         style);
                                                        byte* covers = &pCovers[span_aa.CoverIndex];
                                                        do
                                                        {
                                                            if (*covers == CoverFull)
                                                            {
                                                                *colors = *cspan;
                                                            }
                                                            else
                                                            {
                                                                colors->Add(*cspan, *covers);
                                                            }
                                                            ++cspan;
                                                            ++colors;
                                                            ++covers;
                                                        }
                                                        while (--len != 0);
                                                        if (--num_spans == 0) break;
                                                        span_aa = sl_aa.GetNextScanlineSpan();
                                                    }
                                                }
                                            }
                                        }

                                        // Emit the blended result as a color hspan
                                        //-------------------------
                                        span_bin = sl_bin.Begin();
                                        num_spans = sl_bin.NumSpans;
                                        for (; ; )
                                        {
                                            pixelFormat.BlendColorHSpan(span_bin.X,
                                                                  sl_bin.Y,
                                                                  (uint)span_bin.Len,
                                                                  &pColorSpan[mix_bufferOffset + span_bin.X - min_x],
                                                                  null,
                                                                  CoverFull);
                                            if (--num_spans == 0) break;
                                            span_bin = sl_bin.GetNextScanlineSpan();
                                        }
                                    } // if(ras.sweep_scanline(sl_bin, -1))
                                } // if(num_styles == 1) ... else
                            } // while((num_styles = ras.sweep_styles()) > 0)
                        }
                    }
                } // if(ras.rewind_scanlines())
#endif
            }
        }
Example #35
0
 public bool sweep_scanline(IScanlineCache sl)
 {
     throw new System.NotImplementedException();
 }
Example #36
0
        //--------------------------------------------------------------------
        public bool sweep_scanline(IScanlineCache scanlineCache)
        {
            for (; ;)
            {
                if (m_scan_y > m_outline.max_y())
                {
                    return(false);
                }

                scanlineCache.ResetSpans();
                int       num_cells = (int)m_outline.scanline_num_cells(m_scan_y);
                cell_aa[] cells;
                int       Offset;
                m_outline.scanline_cells(m_scan_y, out cells, out Offset);
                int cover = 0;

                while (num_cells != 0)
                {
                    cell_aa cur_cell = cells[Offset];
                    int     x        = cur_cell.x;
                    int     area     = cur_cell.area;
                    int     alpha;

                    cover += cur_cell.cover;

                    //accumulate all cells with the same X
                    while (--num_cells != 0)
                    {
                        Offset++;
                        cur_cell = cells[Offset];
                        if (cur_cell.x != x)
                        {
                            break;
                        }

                        area  += cur_cell.area;
                        cover += cur_cell.cover;
                    }

                    if (area != 0)
                    {
                        alpha = calculate_alpha((cover << ((int)poly_subpixel_scale_e.poly_subpixel_shift + 1)) - area);
                        if (alpha != 0)
                        {
                            scanlineCache.add_cell(x, alpha);
                        }
                        x++;
                    }

                    if ((num_cells != 0) && (cur_cell.x > x))
                    {
                        alpha = calculate_alpha(cover << ((int)poly_subpixel_scale_e.poly_subpixel_shift + 1));
                        if (alpha != 0)
                        {
                            scanlineCache.add_span(x, (cur_cell.x - x), alpha);
                        }
                    }
                }

                if (scanlineCache.num_spans() != 0)
                {
                    break;
                }
                ++m_scan_y;
            }

            scanlineCache.finalize(m_scan_y);
            ++m_scan_y;
            return(true);
        }
Example #37
0
		public void GenerateAndRender(IRasterizer rasterizer, IScanlineCache scanlineCache, IImageFloat destImage, span_allocator spanAllocator, ISpanGeneratorFloat spanGenerator)
		{
			if (rasterizer.rewind_scanlines())
			{
				scanlineCache.reset(rasterizer.min_x(), rasterizer.max_x());
				spanGenerator.prepare();
				while (rasterizer.sweep_scanline(scanlineCache))
				{
					GenerateAndRenderSingleScanline(scanlineCache, destImage, spanAllocator, spanGenerator);
				}
			}
		}
Example #38
0
        //template<class Scanline, class Ras>
        public void render_gouraud(IScanlineCache sl, IRasterizer <T> ras)
        {
            T alpha = m_alpha.value();
            T brc   = M.One <T>();

#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr());
#else
            FormatRGBA pf = new FormatRGBA(rbuf_window(), new BlenderBGRA());
#endif
            FormatClippingProxy ren_base = new FormatClippingProxy(pf);

            AGG.SpanAllocator   span_alloc = new SpanAllocator();
            SpanGouraudRgba <T> span_gen   = new SpanGouraudRgba <T>();

            ras.Gamma(new GammaLinear(0.0, m_gamma.value().ToDouble()));

            T d = m_dilation.value();

            // Six triangles
            T xc = m_x[0].Add(m_x[1]).Add(m_x[2]).Divide(3.0);
            T yc = m_y[0].Add(m_y[1]).Add(m_y[2]).Divide(3.0);

            T x1 = m_x[1].Add(m_x[0]).Divide(2).Subtract(xc.Subtract(m_x[1].Add(m_x[0]).Divide(2)));
            T y1 = m_y[1].Add(m_y[0]).Divide(2).Subtract(yc.Subtract(m_y[1].Add(m_y[0]).Divide(2)));

            T x2 = m_x[2].Add(m_x[1]).Divide(2).Subtract(xc.Subtract(m_x[2].Add(m_x[1]).Divide(2)));
            T y2 = m_y[2].Add(m_y[1]).Divide(2).Subtract(yc.Subtract(m_y[2].Add(m_y[1]).Divide(2)));

            T x3 = m_x[0].Add(m_x[2]).Divide(2).Subtract(xc.Subtract(m_x[0].Add(m_x[2]).Divide(2)));
            T y3 = m_y[0].Add(m_y[2]).Divide(2).Subtract(yc.Subtract(m_y[0].Add(m_y[2]).Divide(2)));

            span_gen.Colors(new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            brc = M.One <T>().Subtract(brc);
            span_gen.Colors(new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 1, 0, alpha.ToDouble()),
                            new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);


            span_gen.Colors(new RGBA_Doubles(0, 0, 1, alpha.ToDouble()),
                            new RGBA_Doubles(1, 0, 0, alpha.ToDouble()),
                            new RGBA_Doubles(brc.ToDouble(), brc.ToDouble(), brc.ToDouble(), alpha.ToDouble()));
            span_gen.Triangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d);
            ras.AddPath(span_gen);
            Renderer <T> .GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);
        }
Example #39
0
        //template<class Scanline, class Ras>
        public void render_gouraud(IImageByte backBuffer, IScanlineCache sl, IRasterizer ras)
        {
            double alpha = m_alpha.Value;
            double brc   = 1;

#if SourceDepth24
            pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr());
#else
            ImageBuffer image = new ImageBuffer();
            image.Attach(backBuffer, new BlenderBGRA());
#endif
            ImageClippingProxy ren_base = new ImageClippingProxy(image);

            MatterHackers.Agg.span_allocator span_alloc = new span_allocator();
            span_gouraud_rgba span_gen = new span_gouraud_rgba();

            ras.gamma(new gamma_linear(0.0, m_gamma.Value));

            double d = m_dilation.Value;

            // 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);

            span_gen.colors(new RGBA_Floats(1, 0, 0, alpha),
                            new RGBA_Floats(0, 1, 0, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d);
            ras.add_path(span_gen);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

            span_gen.colors(new RGBA_Floats(0, 1, 0, alpha),
                            new RGBA_Floats(0, 0, 1, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d);
            ras.add_path(span_gen);
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

            span_gen.colors(new RGBA_Floats(0, 0, 1, alpha),
                            new RGBA_Floats(1, 0, 0, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d);
            ras.add_path(span_gen);
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

            brc = 1 - brc;
            span_gen.colors(new RGBA_Floats(1, 0, 0, alpha),
                            new RGBA_Floats(0, 1, 0, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d);
            ras.add_path(span_gen);
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

            span_gen.colors(new RGBA_Floats(0, 1, 0, alpha),
                            new RGBA_Floats(0, 0, 1, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d);
            ras.add_path(span_gen);
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);

            span_gen.colors(new RGBA_Floats(0, 0, 1, alpha),
                            new RGBA_Floats(1, 0, 0, alpha),
                            new RGBA_Floats(brc, brc, brc, alpha));
            span_gen.triangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d);
            ras.add_path(span_gen);
            scanlineRenderer.GenerateAndRender(ras, sl, ren_base, span_alloc, span_gen);
        }
Example #40
0
        //--------------------------------------------------------------------
        public bool SweepScanline(IScanlineCache sl)
        {
#if use_timers
            SweepSacanLine.Start();
#endif
            for (; ;)
            {
                if (m_scan_y > m_outline.MaxY)
                {
#if use_timers
                    SweepSacanLine.Stop();
#endif
                    return(false);
                }

                sl.ResetSpans();
                uint scan_y_uint = 0; // it is going to get initialize to 0 anyway so make it clear.
                if (m_scan_y > 0)
                {
                    scan_y_uint = (uint)m_scan_y;
                }
                uint     num_cells = m_outline.ScanlineNumCells(scan_y_uint);
                CellAA[] cells;
                uint     Offset;
                m_outline.ScanlineCells(scan_y_uint, out cells, out Offset);
                int cover = 0;

                while (num_cells != 0)
                {
                    CellAA cur_cell = cells[Offset];
                    int    x        = cur_cell.X;
                    int    area     = cur_cell.Area;
                    uint   alpha;

                    cover += cur_cell.Cover;

                    //accumulate all cells with the same X
                    while (--num_cells != 0)
                    {
                        Offset++;
                        cur_cell = cells[Offset];
                        if (cur_cell.X != x)
                        {
                            break;
                        }

                        area  += cur_cell.Area;
                        cover += cur_cell.Cover;
                    }

                    if (area != 0)
                    {
                        alpha = CalculateAlpha((cover << ((int)poly_subpixel_scale_e.Shift + 1)) - area);
                        if (alpha != 0)
                        {
                            sl.AddCell(x, alpha);
                        }
                        x++;
                    }

                    if ((num_cells != 0) && (cur_cell.X > x))
                    {
                        alpha = CalculateAlpha(cover << ((int)poly_subpixel_scale_e.Shift + 1));
                        if (alpha != 0)
                        {
                            sl.AddSpan(x, (cur_cell.X - x), alpha);
                        }
                    }
                }

                if (sl.NumSpans != 0)
                {
                    break;
                }
                ++m_scan_y;
            }

            sl.Finalize(m_scan_y);
            ++m_scan_y;
#if use_timers
            SweepSacanLine.Stop();
#endif
            return(true);
        }
Example #41
0
 public Renderer(IImage destImage, rasterizer_scanline_aa rasterizer, IScanlineCache scanlineCache)
     : base(destImage, rasterizer)
 {
     m_ScanlineCache = scanlineCache;
 }
Example #42
0
		//--------------------------------------------------------------------
		public bool sweep_scanline(IScanlineCache scanlineCache)
		{
			for (; ; )
			{
				if (m_scan_y > m_outline.max_y())
				{
					return false;
				}

				scanlineCache.ResetSpans();
				int num_cells = (int)m_outline.scanline_num_cells(m_scan_y);
				cell_aa[] cells;
				int Offset;
				m_outline.scanline_cells(m_scan_y, out cells, out Offset);
				int cover = 0;

				while (num_cells != 0)
				{
					cell_aa cur_cell = cells[Offset];
					int x = cur_cell.x;
					int area = cur_cell.area;
					int alpha;

					cover += cur_cell.cover;

					//accumulate all cells with the same X
					while (--num_cells != 0)
					{
						Offset++;
						cur_cell = cells[Offset];
						if (cur_cell.x != x)
						{
							break;
						}

						area += cur_cell.area;
						cover += cur_cell.cover;
					}

					if (area != 0)
					{
						alpha = calculate_alpha((cover << ((int)poly_subpixel_scale_e.poly_subpixel_shift + 1)) - area);
						if (alpha != 0)
						{
							scanlineCache.add_cell(x, alpha);
						}
						x++;
					}

					if ((num_cells != 0) && (cur_cell.x > x))
					{
						alpha = calculate_alpha(cover << ((int)poly_subpixel_scale_e.poly_subpixel_shift + 1));
						if (alpha != 0)
						{
							scanlineCache.add_span(x, (cur_cell.x - x), alpha);
						}
					}
				}

				if (scanlineCache.num_spans() != 0) break;
				++m_scan_y;
			}

			scanlineCache.finalize(m_scan_y);
			++m_scan_y;
			return true;
		}