Exemplo n.º 1
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();
                    }
                }
            }
        }
Exemplo n.º 2
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
            }
        }
Exemplo n.º 3
0
 public unsafe virtual void BlendColorHSpan(int x, int y, uint len, RGBA_Bytes *colors, byte *covers, byte cover)
 {
     m_pixf.BlendColorHSpan(x, y, len, colors, covers, cover);
 }