/// <summary>
        /// for fill shape
        /// </summary>
        /// <param name="sclineRas"></param>
        /// <param name="scline"></param>
        /// <param name="color"></param>
        /// <param name="shapeHint"></param>
        public void FillWithColor(GLScanlineRasterizer sclineRas,
                                  GLScanline scline,
                                  PixelFarm.Drawing.Color color)
        {
            //early exit
            if (color.A == 0)
            {
                return;
            }
            if (!sclineRas.RewindScanlines())
            {
                return;
            }
            //-----------------------------------------------

            scline.ResetSpans(sclineRas.MinX, sclineRas.MaxX);
            //-----------------------------------------------
            var lineBuff = this.myLineBuffer;

            lineBuff.Clear();

            while (sclineRas.SweepScanline(scline))
            {
                int y = scline.Y;
                lineBuff.BeginNewLine(y);

                int    num_spans = scline.SpanCount;
                byte[] covers    = scline.GetCovers();

                //copy data from scanline to lineBuff
                //TODO: move linebuf built into the scanline?

                for (int i = 1; i <= num_spans; ++i)
                {
                    ScanlineSpan span = scline.GetSpan(i);
                    if (span.len > 0)
                    {
                        //outline
                        GLBlendSolidHSpan(span.x, span.len, true, lineBuff, color.A, covers, span.cover_index);
                    }
                    else
                    {
                        //fill
                        int x  = span.x;
                        int x2 = (x - span.len - 1);
                        GLBlendHLine(x, x2, true, lineBuff, color.A, covers[span.cover_index]);
                    }
                }

                lineBuff.CloseLine();
            }
            //----------------------------------
            int nelements = myLineBuffer.Count;

            if (nelements > 0)
            {
                this.scanlineShader.AggDrawLines(myLineBuffer, nelements, color);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// for fill shape
        /// </summary>
        /// <param name="sclineRas"></param>
        /// <param name="scline"></param>
        /// <param name="color"></param>
        /// <param name="shapeHint"></param>
        public void FillWithColor(GLScanlineRasterizer sclineRas,
                                  GLScanline scline,
                                  PixelFarm.Drawing.Color color)
        {
            //early exit
            if (color.A == 0)
            {
                return;
            }
            if (!sclineRas.RewindScanlines())
            {
                return;
            }
            //-----------------------------------------------

            scline.ResetSpans(sclineRas.MinX, sclineRas.MaxX);
            //-----------------------------------------------



            this.mySinglePixelBuffer.Clear();
            this.myLineBuffer.Clear();

            while (sclineRas.SweepScanline(scline))
            {
                int    y         = scline.Y;
                int    num_spans = scline.SpanCount;
                byte[] covers    = scline.GetCovers();
                for (int i = 1; i <= num_spans; ++i)
                {
                    ScanlineSpan span = scline.GetSpan(i);
                    if (span.len > 0)
                    {
                        //outline
                        GLBlendSolidHSpan(span.x, y, span.len, color, covers, span.cover_index);
                    }
                    else
                    {
                        //fill
                        int x  = span.x;
                        int x2 = (x - span.len - 1);
                        GLBlendHLine(x, y, x2, color, covers[span.cover_index]);
                    }
                }
            }


            DrawPointAndLineWithVertices();
        }
Esempio n. 3
0
        //--------------------------------------------------------------------
        internal bool SweepScanline(GLScanline scline)
        {
            for (; ; )
            {
                if (m_scan_y > m_cellAARas.MaxY)
                {
                    return false;
                }

                scline.ResetSpans();

                CellAA[] cells;
                int offset;
                int num_cells;

                m_cellAARas.GetCells(m_scan_y, out cells, out offset, out num_cells);

                int cover = 0;

                while (num_cells != 0)
                {
                    unsafe
                    {
                        fixed (CellAA* cur_cell_h = &cells[0])
                        {
                            CellAA* cur_cell_ptr = cur_cell_h + offset;

                            int alpha;
                            int x = cur_cell_ptr->x;
                            int area = cur_cell_ptr->area;
                            cover += cur_cell_ptr->cover;

                            //accumulate all cells with the same X
                            while (--num_cells != 0)
                            {
                                offset++; //move next
                                cur_cell_ptr++; //move next

                                if (cur_cell_ptr->x != x)
                                {
                                    break;
                                }

                                area += cur_cell_ptr->area;
                                cover += cur_cell_ptr->cover;
                            }

                            if (area != 0)
                            {
                                alpha = CalculateAlpha((cover << (poly_subpix.SHIFT + 1)) - area);
                                if (alpha != 0)
                                {
                                    scline.AddCell(x, alpha);
                                }
                                x++;
                            }

                            if ((num_cells != 0) && (cur_cell_ptr->x > x))
                            {
                                alpha = CalculateAlpha(cover << (poly_subpix.SHIFT + 1));
                                if (alpha != 0)
                                {
                                    scline.AddSpan(x, (cur_cell_ptr->x - x), alpha);
                                }
                            }
                        }
                    }
                }

                if (scline.SpanCount != 0) { break; }

                ++m_scan_y;
            }

            scline.CloseLine(m_scan_y);
            ++m_scan_y;
            return true;
        }