Пример #1
0
 public void Render(VertexStore vxStorage, ColorRGBA c)
 {
     Render(new VertexStoreSnap(vxStorage), c);
 }
Пример #2
0
 public abstract void Clear(ColorRGBA color);
Пример #3
0
 //------------------------------------------------------------------------
 //render vertices
 public abstract void Render(VertexStoreSnap vertexSource, ColorRGBA colorBytes);
Пример #4
0
        public override void Draw(Graphics2D graphics2D)
        {
            if (graphics2D.DestImage != null)
            {
                IImageReaderWriter backBuffer          = graphics2D.DestImage;
                IPixelBlender      currentPixelBlender = graphics2D.PixelBlender;

                int distBetween = backBuffer.BytesBetweenPixelsInclusive;


                //use different pixel blender
                var redImageBuffer   = new ChildImage(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.R, 8);
                var greenImageBuffer = new ChildImage(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.G, 8);
                var blueImageBuffer  = new ChildImage(backBuffer, new PixelBlenderGray(distBetween), distBetween, CO.B, 8);


                ClipProxyImage clippingProxy      = new ClipProxyImage(backBuffer);
                ClipProxyImage clippingProxyRed   = new ClipProxyImage(redImageBuffer);
                ClipProxyImage clippingProxyGreen = new ClipProxyImage(greenImageBuffer);
                ClipProxyImage clippingProxyBlue  = new ClipProxyImage(blueImageBuffer);

                ScanlineRasterizer sclineRas = graphics2D.ScanlineRasterizer;
                ScanlinePacked8    scline    = graphics2D.ScanlinePacked8;

                ColorRGBA clearColor = this.UseBlackBlackground ? new ColorRGBA(0, 0, 0) : new ColorRGBA(255, 255, 255);
                clippingProxy.Clear(clearColor);

                ColorRGBA fillColor = this.UseBlackBlackground ?
                                      new ColorRGBA(255, 255, 255, (byte)(this.AlphaValue)) :
                                      new ColorRGBA(0, 0, 0, (byte)(this.AlphaValue));

                ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;

                VertexSource.Ellipse er = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                sclineRas.AddPath(er.MakeVertexSnap());
                sclineRasToBmp.RenderWithColor(clippingProxyRed, sclineRas, scline, fillColor);

                VertexSource.Ellipse eg = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                sclineRas.AddPath(eg.MakeVertexSnap());
                sclineRasToBmp.RenderWithColor(clippingProxyGreen, sclineRas, scline, fillColor);

                VertexSource.Ellipse eb = new PixelFarm.Agg.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
                sclineRas.AddPath(eb.MakeVertexSnap());
                sclineRasToBmp.RenderWithColor(clippingProxyBlue, sclineRas, scline, fillColor);
            }
            //            else if (graphics2D.DestImageFloat != null)
            //            {
            //#if false
            //                IImageFloat backBuffer = graphics2D.DestImageFloat;

            //                int distBetween = backBuffer.GetFloatsBetweenPixelsInclusive();
            //                ImageBufferFloat redImageBuffer = new ImageBufferFloat();
            //                redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8);
            //                ImageBufferFloat greenImageBuffer = new ImageBufferFloat();
            //                greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8);
            //                ImageBufferFloat blueImageBuffer = new ImageBufferFloat();
            //                blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8);

            //                ImageClippingProxy clippingProxy = new ImageClippingProxy(backBuffer);
            //                ImageClippingProxy clippingProxyRed = new ImageClippingProxy(redImageBuffer);
            //                ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer);
            //                ImageClippingProxy clippingProxyBlue = new ImageClippingProxy(blueImageBuffer);

            //                ScanlineRasterizer ras = new ScanlineRasterizer();
            //                ScanlineCachePacked8 sl = new ScanlineCachePacked8();

            //                RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255);
            //                clippingProxy.clear(clearColor);
            //                alphaSlider.View.BackGroundColor = clearColor;

            //                RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value));

            //                VertexSource.Ellipse er = new AGG.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
            //                ras.add_path(er);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor);

            //                VertexSource.Ellipse eg = new AGG.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
            //                ras.add_path(eg);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor);

            //                VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
            //                ras.add_path(eb);
            //                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
            //#endif
            //            }
        }
Пример #5
0
        public override void Clear(ColorRGBA color)
        {
            RectInt clippingRectInt = GetClippingRect();
            var     destImage       = this.DestImage;
            int     width           = destImage.Width;
            int     height          = destImage.Height;

            byte[] buffer = destImage.GetBuffer();
            switch (destImage.BitDepth)
            {
            case 8:
            {
                //int bytesBetweenPixels = destImage.BytesBetweenPixelsInclusive;
                //byte byteColor = color.Red0To255;
                //int clipRectLeft = clippingRectInt.Left;

                //for (int y = clippingRectInt.Bottom; y < clippingRectInt.Top; ++y)
                //{
                //    int bufferOffset = destImage.GetBufferOffsetXY(clipRectLeft, y);
                //    for (int x = 0; x < clippingRectInt.Width; ++x)
                //    {
                //        buffer[bufferOffset] = color.blue;
                //        bufferOffset += bytesBetweenPixels;
                //    }
                //}
                throw new NotSupportedException("temp");
            }

            case 24:
            {
                //int bytesBetweenPixels = destImage.BytesBetweenPixelsInclusive;
                //int clipRectLeft = clippingRectInt.Left;
                //for (int y = clippingRectInt.Bottom; y < clippingRectInt.Top; y++)
                //{
                //    int bufferOffset = destImage.GetBufferOffsetXY(clipRectLeft, y);
                //    for (int x = 0; x < clippingRectInt.Width; ++x)
                //    {
                //        buffer[bufferOffset + 0] = color.blue;
                //        buffer[bufferOffset + 1] = color.green;
                //        buffer[bufferOffset + 2] = color.red;
                //        bufferOffset += bytesBetweenPixels;
                //    }
                //}
                throw new NotSupportedException("temp");
            }
            break;

            case 32:
            {
                //------------------------------
                //fast clear buffer
                //skip clipping ****
                //TODO: reimplement clipping***
                //------------------------------
                if (color == ColorRGBA.White)
                {
                    //fast cleat with white color
                    int n = buffer.Length / 4;
                    unsafe
                    {
                        fixed(void *head = &buffer[0])
                        {
                            uint *head_i32 = (uint *)head;

                            for (int i = n - 1; i >= 0; --i)
                            {
                                *head_i32 = 0xffffffff;         //white (ARGB)
                                head_i32++;
                            }
                        }
                    }
                }
                else if (color == ColorRGBA.Black)
                {
                    //fast cleat with black color
                    int n = buffer.Length / 4;
                    unsafe
                    {
                        fixed(void *head = &buffer[0])
                        {
                            uint *head_i32 = (uint *)head;

                            for (int i = n - 1; i >= 0; --i)
                            {
                                *head_i32 = 0xff000000;         //black (ARGB)
                                head_i32++;
                            }
                        }
                    }
                }
                else
                {
                    //other color
                    uint colorARGB = (uint)((color.alpha << 24) | ((color.red << 16) | (color.green << 8) | color.blue));
                    int  n         = buffer.Length / 4;
                    unsafe
                    {
                        fixed(void *head = &buffer[0])
                        {
                            uint *head_i32 = (uint *)head;

                            for (int i = n - 1; i >= 0; --i)
                            {
                                *head_i32 = colorARGB;
                                head_i32++;
                            }
                        }
                    }
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }
        }
Пример #6
0
 public ColorRGBA ToColorRGBA()
 {
     return(ColorRGBA.Make(Red0To255, Green0To255, Blue0To255, Alpha0To255));
 }
Пример #7
0
 public ColorRGBA Blend(ColorRGBA other, float weight)
 {
     return(this * (1 - weight) + other * weight);
 }
        public void RenderWithColor(IImageReaderWriter dest,
                                    ScanlineRasterizer sclineRas,
                                    Scanline scline,
                                    ColorRGBA color)
        {
            if (!sclineRas.RewindScanlines())
            {
                return;
            }                                             //early exit
            //-----------------------------------------------
            scline.ResetSpans(sclineRas.MinX, sclineRas.MaxX);

            switch (this.ScanlineRenderMode)
            {
            default:
            {
                //prev mode
                //this mode
                while (sclineRas.SweepScanline(scline))
                {
                    //render solid single scanline
                    int    y         = scline.Y;
                    int    num_spans = scline.SpanCount;
                    byte[] covers    = scline.GetCovers();

                    //render each span in the scanline
                    for (int i = 1; i <= num_spans; ++i)
                    {
                        ScanlineSpan span = scline.GetSpan(i);
                        if (span.len > 0)
                        {
                            //positive len
                            dest.BlendSolidHSpan(span.x, y, span.len, color, covers, span.cover_index);
                        }
                        else
                        {
                            //fill the line, same coverage area
                            int x  = span.x;
                            int x2 = (x - span.len - 1);
                            dest.BlendHL(x, y, x2, color, covers[span.cover_index]);
                        }
                    }
                }
            } break;

            case Agg.ScanlineRenderMode.SubPixelRendering:
            {
                int dbugMinScanlineCount = 0;
                while (sclineRas.SweepScanline(scline))
                {
                    //render solid single scanline
                    //if (dbugMinScanlineCount == 8)
                    //{

                    //}
                    SubPixRender(dest, scline, color);
                    //if (dbugMinScanlineCount == 8)
                    //{
                    //    break;
                    //}
                    dbugMinScanlineCount++;
                    //if (dbugMinScanlineCount > 2)
                    //{
                    //    break;
                    //}
                }
            } break;

            case Agg.ScanlineRenderMode.Custom:
            {
                while (sclineRas.SweepScanline(scline))
                {
                    CustomRenderSingleScanLine(dest, scline, color);
                }
            } break;
            }
        }
        void SubPixRender(IImageReaderWriter dest, Scanline scanline, ColorRGBA color)
        {
            byte[] covers    = scanline.GetCovers();
            int    num_spans = scanline.SpanCount;
            int    y         = scanline.Y;

            byte[]        buffer  = dest.GetBuffer();
            IPixelBlender blender = dest.GetRecieveBlender();

            int       last_x       = int.MinValue;
            int       prev_cover   = 0;
            int       bufferOffset = 0;
            ColorRGBA prevColor    = ColorRGBA.White;

            for (int i = 1; i <= num_spans; ++i)
            {
                //render span by span

                ScanlineSpan span = scanline.GetSpan(i);

                if (span.x != last_x + 1)
                {
                    bufferOffset = dest.GetBufferOffsetXY(span.x, y);

                    //when skip  then reset
                    prev_cover = 0;
                    prevColor  = ColorRGBA.White;
                }

                last_x = span.x;
                int num_pix = span.len;

                if (num_pix < 0)
                {
                    //special encode***
                    num_pix = -num_pix; //make it positive value
                    last_x += (num_pix - 1);

                    //long span with coverage
                    int coverageValue = covers[span.cover_index];
                    //-------------------------------------------
                    if (coverageValue >= 255)
                    {
                        //100% cover
                        int       a           = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                        ColorRGBA newc        = prevColor = new ColorRGBA(color.red, color.green, color.blue);
                        ColorRGBA todrawColor = new ColorRGBA(newc, a);
                        prev_cover = 255;//full
                        while (num_pix > 0)
                        {
                            blender.BlendPixel(buffer, bufferOffset, todrawColor);
                            bufferOffset += 4; //1 pixel 4 bytes
                            --num_pix;
                        }
                    }
                    else
                    {
                        prev_cover = coverageValue;
                        int       a           = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                        ColorRGBA newc        = prevColor = new ColorRGBA(color.red, color.green, color.blue);
                        ColorRGBA todrawColor = new ColorRGBA(newc, a);
                        while (num_pix > 0)
                        {
                            blender.BlendPixel(buffer, bufferOffset, todrawColor);
                            bufferOffset += 4; //1 pixel 4 bytes
                            --num_pix;
                        }
                    }
                }
                else
                {
                    int coverIndex = span.cover_index;
                    last_x += (num_pix - 1);
                    while (num_pix > 0)
                    {
                        int coverageValue = covers[coverIndex++];
                        if (coverageValue >= 255)
                        {
                            //100% cover
                            ColorRGBA newc = new ColorRGBA(color.red, color.green, color.blue);
                            prevColor = newc;
                            int a = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                            blender.BlendPixel(buffer, bufferOffset, new ColorRGBA(newc, a));
                            prev_cover = 255;//full
                        }
                        else
                        {
                            //check direction :


                            bool isLeftToRight = coverageValue >= prev_cover;
                            prev_cover = coverageValue;

                            byte  c_r, c_g, c_b;
                            float subpix_percent = ((float)(coverageValue) / 256f);

                            if (coverageValue < cover_1_3)
                            {
                                if (isLeftToRight)
                                {
                                    c_r = 255;
                                    c_g = 255;
                                    c_b = (byte)(255 - (255f * (subpix_percent)));
                                }
                                else
                                {
                                    c_r = (byte)(255 - (255f * (subpix_percent)));
                                    c_g = 255;
                                    c_b = 255;
                                }

                                ColorRGBA newc = prevColor = new ColorRGBA(c_r, c_g, c_b);
                                int       a    = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                                blender.BlendPixel(buffer, bufferOffset, new ColorRGBA(newc, a));
                            }
                            else if (coverageValue < cover_2_3)
                            {
                                if (isLeftToRight)
                                {
                                    c_r = prevColor.blue;
                                    c_g = (byte)(255 - (255f * (subpix_percent)));
                                    c_b = color.blue;
                                }
                                else
                                {
                                    c_r = color.blue;
                                    c_g = (byte)(255 - (255f * (subpix_percent)));
                                    c_b = 255;
                                }
                                ColorRGBA newc = prevColor = new ColorRGBA(c_r, c_g, c_b);
                                int       a    = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                                blender.BlendPixel(buffer, bufferOffset, new ColorRGBA(newc, a));
                            }
                            else
                            {
                                //cover > 2/3 but not full
                                if (isLeftToRight)
                                {
                                    c_r = (byte)(255 - (255f * (subpix_percent)));
                                    c_g = color.green;
                                    c_b = color.blue;
                                }
                                else
                                {
                                    c_r = prevColor.green;
                                    c_g = prevColor.blue;
                                    c_b = (byte)(255 - (255f * (subpix_percent)));
                                }

                                ColorRGBA newc = prevColor = new ColorRGBA(c_r, c_g, c_b);
                                int       a    = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                                blender.BlendPixel(buffer, bufferOffset, new ColorRGBA(newc, a));
                            }
                        }
                        bufferOffset += 4; //1 pixel 4 bits
                        --num_pix;
                    }
                }
            }
        }
Пример #10
0
 public static void FillRectangle(this Graphics2D gx, Vector2 leftBottom,
                                  Vector2 rightTop, ColorRGBA fillColor)
 {
     gx.FillRectangle(leftBottom.x, leftBottom.y, rightTop.x, rightTop.y, fillColor);
 }
Пример #11
0
        public static void Circle(this Graphics2D g, double x, double y, double radius, ColorRGBA color)
        {
            Ellipse elipse = new Ellipse(x, y, radius, radius);

            g.Render(elipse.MakeVxs(), color);
        }
Пример #12
0
 public static void FillRectangle(this Graphics2D gx, RectInt rect, ColorRGBA fillColor)
 {
     gx.FillRectangle(rect.Left, rect.Bottom, rect.Right, rect.Top, fillColor);
 }
Пример #13
0
 public static void Rectangle(this Graphics2D gx, RectInt rect, ColorRGBA color)
 {
     gx.Rectangle(rect.Left, rect.Bottom, rect.Right, rect.Top, color);
 }
Пример #14
0
 public static void Rectangle(this Graphics2D gx, RectD rect, ColorRGBA color, double strokeWidth = 1)
 {
     gx.Rectangle(rect.Left, rect.Bottom, rect.Right, rect.Top, color, strokeWidth);
 }
Пример #15
0
        public static void Rectangle(this Graphics2D gx, double left, double bottom, double right, double top, ColorRGBA color, double strokeWidth = 1)
        {
            RoundedRect rect = new RoundedRect(left + .5, bottom + .5, right - .5, top - .5, 0);

            gx.Render(new Stroke(strokeWidth).MakeVxs(rect.MakeVxs()), color);
        }
Пример #16
0
 public static void Circle(this Graphics2D g, Vector2 origin, double radius, ColorRGBA color)
 {
     Circle(g, origin.x, origin.y, radius, color);
 }