Beispiel #1
0
 public CustomScanlineRasToBmp_EnlargedV2(double size, ActualImage destImage)
 {
     this.ScanlineRenderMode = Agg.ScanlineRenderMode.Custom;
     m_size   = size;
     m_square = new Square(size);
     gfx      = new AggRenderSurface(destImage);
 }
Beispiel #2
0
        protected override void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            if (!buildVxs)
            {
                destImg  = new ActualImage(400, 300, PixelFarm.Agg.PixelFormat.ARGB32);
                imgGfx2d = new ImageGraphics2D(destImg); //no platform
                p        = new AggCanvasPainter(imgGfx2d);

                buildVxs = true;
                ReadAndRender("tahoma.ttf", "A");
            }

            canvas.Clear(SKColors.White);

            using (SKBitmap bitmap = new SKBitmap(destImg.Width, destImg.Height, false))
            {
                //IntPtr pixelHeader = bitmap.GetPixels();
                //byte[] srcBuffer = ActualImage.GetBuffer(destImg);
                bitmap.LockPixels();
                //System.Runtime.InteropServices.Marshal.Copy(
                //    srcBuffer, 0,
                //    pixelHeader, srcBuffer.Length);
                //bitmap.UnlockPixels();
                PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(
                    destImg, destImg.Width, destImg.Height,
                    destImg.Stride, bitmap.GetPixels());
                bitmap.UnlockPixels();
                canvas.DrawBitmap(bitmap, 10, 10);
            }
        }
Beispiel #3
0
 public CustomScanlineRasToBmp_EnlargedV3(double size, ActualImage destImage)
 {
     this.ScanlineRenderMode = Agg.ScanlineRenderMode.Custom;
     m_size   = size;
     m_square = new Square(size);
     gfx      = Graphics2D.CreateFromImage(destImage);
 }
 public override void DrawImage(ActualImage actualImage, params AffinePlan[] affinePlans)
 {
     //1. create special graphics
     throw new NotSupportedException();
     //using (System.Drawing.Bitmap srcBmp = CreateBmpBRGA(actualImage))
     //{
     //    var bmp = _bmpStore.GetFreeBmp();
     //    using (var g2 = System.Drawing.Graphics.FromImage(bmp))
     //    {
     //        //we can use recycle tmpVxsStore
     //        Affine destRectTransform = Affine.NewMatix(affinePlans);
     //        double x0 = 0, y0 = 0, x1 = bmp.Width, y1 = bmp.Height;
     //        destRectTransform.Transform(ref x0, ref y0);
     //        destRectTransform.Transform(ref x0, ref y1);
     //        destRectTransform.Transform(ref x1, ref y1);
     //        destRectTransform.Transform(ref x1, ref y0);
     //        var matrix = new System.Drawing.Drawing2D.Matrix(
     //           (float)destRectTransform.m11, (float)destRectTransform.m12,
     //           (float)destRectTransform.m21, (float)destRectTransform.m22,
     //           (float)destRectTransform.dx, (float)destRectTransform.dy);
     //        g2.Clear(System.Drawing.Color.Transparent);
     //        g2.Transform = matrix;
     //        //------------------------
     //        g2.DrawImage(srcBmp, new System.Drawing.PointF(0, 0));
     //        this._gfx.DrawImage(bmp, new System.Drawing.Point(0, 0));
     //    }
     //    _bmpStore.RelaseBmp(bmp);
     //}
 }
Beispiel #5
0
        void RenderWithMsdfImg(Typeface typeface, char testChar, float sizeInPoint)
        {
            p.FillColor = PixelFarm.Drawing.Color.Black;
            //p.UseSubPixelRendering = chkLcdTechnique.Checked;
            p.Clear(PixelFarm.Drawing.Color.White);
            //----------------------------------------------------
            var builder  = new MyGlyphPathBuilder(typeface);
            var hintTech = (HintTechnique)cmbHintTechnique.SelectedItem;

            builder.UseTrueTypeInstructions = false; //reset
            builder.UseVerticalHinting      = false; //reset
            switch (hintTech)
            {
            case HintTechnique.TrueTypeInstruction:
                builder.UseTrueTypeInstructions = true;
                break;

            case HintTechnique.TrueTypeInstruction_VerticalOnly:
                builder.UseTrueTypeInstructions = true;
                builder.UseVerticalHinting      = true;
                break;

            case HintTechnique.CustomAutoFit:
                //custom agg autofit
                break;
            }
            //----------------------------------------------------
            builder.Build(testChar, sizeInPoint);
            //----------------------------------------------------
            var         msdfGlyphGen = new MsdfGlyphGen();
            GlyphImage2 glyphImg     = msdfGlyphGen.CreateMsdfImage(
                builder.GetOutputPoints(),
                builder.GetOutputContours(),
                builder.GetPixelScale());
            var actualImg = ActualImage.CreateFromBuffer(glyphImg.Width, glyphImg.Height, PixelFormat.ARGB32, glyphImg.GetImageBuffer());

            p.DrawImage(actualImg, 0, 0);

            //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            //{
            //    var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
            //    System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length);
            //    bmp.UnlockBits(bmpdata);
            //    bmp.Save("d:\\WImageTest\\a001_xn2_" + n + ".png");
            //}

            if (chkShowGrid.Checked)
            {
                //render grid
                RenderGrid(800, 600, _gridSize, p);
            }

            //6. use this util to copy image from Agg actual image to System.Drawing.Bitmap
            PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(destImg, winBmp);
            //---------------
            //7. just render our bitmap
            g.Clear(Color.White);
            g.DrawImage(winBmp, new Point(30, 20));
        }
Beispiel #6
0
        public static void CopyFromGdiPlusBitmapSameSize(
            Bitmap windowsBitmap,
            ActualImage actualImage)
        {
            int h = windowsBitmap.Height;
            int w = windowsBitmap.Width;
            //byte[] targetBuffer = ActualImage.GetBuffer(actualImage);

            BitmapData bitmapData1 = windowsBitmap.LockBits(
                new Rectangle(0, 0,
                              w,
                              h),
                System.Drawing.Imaging.ImageLockMode.ReadWrite,
                windowsBitmap.PixelFormat);
            IntPtr scan0  = bitmapData1.Scan0;
            int    stride = bitmapData1.Stride;

            //TODO: review here
            //use buffer copy

            unsafe
            {
                TempMemPtr targetPtr = ActualImage.GetBufferPtr(actualImage);
                //target

                int   startRowAt = ((h - 1) * stride);
                byte *src        = (byte *)scan0;

                byte *targetBuffer = (byte *)targetPtr.Ptr;
                for (int y = h; y > 0; --y)
                {
                    // byte* target = targetH + ((y - 1) * stride);

                    //System.Runtime.InteropServices.Marshal.Copy(
                    //      (IntPtr)src,//src
                    //      targetBuffer, startRowAt, stride);
                    AggMemMx.memcpy(targetBuffer + startRowAt, src, stride);
                    startRowAt -= stride;
                    src        += stride;
                }

                //////////////////////////////////////////////////////////////////
                //fixed (byte* targetH = &targetBuffer[0])
                //{
                //    byte* src = (byte*)scan0;
                //    for (int y = h; y > 0; --y)
                //    {
                //        byte* target = targetH + ((y - 1) * stride);
                //        for (int n = stride - 1; n >= 0; --n)
                //        {
                //            *target = *src;
                //            target++;
                //            src++;
                //        }
                //    }
                //}
            }
            windowsBitmap.UnlockBits(bitmapData1);
        }
Beispiel #7
0
 public CustomScanlineRasToBmp_EnlargedSubPixelRendering(double size, ActualImage destImage)
 {
     this.ScanlineRenderMode = Agg.ScanlineRenderMode.Custom;
     m_size   = size;
     m_square = new Square(size);
     gfx      = new AggRenderSurface(destImage);
     lcdLut   = new Sample_AADemoTest3.AggLcdDistributionLookupTable(primary, 2.0 / 9, 1.0 / 9);
 }
        public override void DrawImage(ActualImage actualImage, params AffinePlan[] affinePlans)
        {
            //create gl bmp
            GLBitmap glBmp = new GLBitmap(actualImage.Width, actualImage.Height, ActualImage.GetBuffer(actualImage), false);

            _canvas.DrawImage(glBmp, 0, 0);
            glBmp.Dispose();
        }
Beispiel #9
0
        void generate_alpha_mask(ScanlineRasToDestBitmapRenderer sclineRasToBmp, ScanlinePacked8 sclnPack, ScanlineRasterizer rasterizer, int width, int height)
        {
            alphaBitmap = new ActualImage(width, height, PixelFormat.GrayScale8);

            var bmpReaderWrtier = new MyImageReaderWriter(alphaBitmap);

            alphaMaskImageBuffer = new ChildImage(bmpReaderWrtier, new PixelBlenderGray(1));

            alphaMask = new AlphaMaskByteClipped(alphaMaskImageBuffer, 1, 0);

#if USE_CLIPPING_ALPHA_MASK
            //alphaMaskImageBuffer.AttachBuffer(alphaBitmap.GetBuffer(), 20 * width + 20, width - 40, height - 40, width, 8, 1);
#else
            alphaMaskImageBuffer.attach(alphaByteArray, (int)cx, (int)cy, cx, 1);
#endif

            var image = new ChildImage(alphaMaskImageBuffer, new PixelBlenderGray(1), 1, 0, 8);

            ClipProxyImage clippingProxy = new ClipProxyImage(image);


            clippingProxy.Clear(ColorRGBA.Black);

            VertexSource.Ellipse ellipseForMask = new PixelFarm.Agg.VertexSource.Ellipse();

            System.Random randGenerator = new Random(1432);


            int i;
            int num = (int)maskAlphaSliderValue;
            for (i = 0; i < num; i++)
            {
                if (i == num - 1)
                {
                    ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100);
                    rasterizer.AddPath(ellipseForMask.MakeVertexSnap());
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(0, 0, 0, 255));

                    ellipseForMask.Reset(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                    rasterizer.AddPath(ellipseForMask.MakeVertexSnap());
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(255, 0, 0, 255));
                }
                else
                {
                    ellipseForMask.Reset(randGenerator.Next() % width,
                                         randGenerator.Next() % height,
                                         randGenerator.Next() % 100 + 20,
                                         randGenerator.Next() % 100 + 20,
                                         100);
                    // set the color to draw into the alpha channel.
                    // there is not very much reason to set the alpha as you will get the amount of
                    // transparency based on the color you draw.  (you might want some type of different edeg effect but it will be minor).
                    rasterizer.AddPath(ellipseForMask.MakeVxs());
                    sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack,
                                                   ColorRGBA.Make((int)((float)i / (float)num * 255), 0, 0, 255));
                }
            }
        }
        void BlendScanline(ActualImage destImg, byte[] expandGreyBuffer,
                           PixelFarm.Drawing.Color color, int x, int y, int width)

        {
            byte[] rgb = new byte[3] {
                color.R,
                color.G,
                color.B
            };
            //-------------------------
            //destination
            byte[] destImgBuffer = ActualImage.GetBuffer(destImg);
            //start pixel
            int destImgIndex = (x * 4) + (destImg.Stride * y);
            //start img src
            int  srcImgIndex = x + (width * y);
            int  colorIndex  = 0;
            int  round       = 0;
            byte color_a     = color.alpha;

            while (width > 3)
            {
                //try
                //{

                int a0 = expandGreyBuffer[srcImgIndex] * color_a;
                int a1 = expandGreyBuffer[srcImgIndex + 1] * color_a;
                int a2 = expandGreyBuffer[srcImgIndex + 2] * color_a;

                byte ec0 = destImgBuffer[destImgIndex];     //existing color
                byte ec1 = destImgBuffer[destImgIndex + 1]; //existing color
                byte ec2 = destImgBuffer[destImgIndex + 2]; //existing color

                //------------------------------------------------------
                //please note that we swap a2 and a0 on the fly****
                //------------------------------------------------------
                byte n0 = (byte)((((rgb[colorIndex] - ec0) * a2) + (ec0 << 16)) >> 16);
                byte n1 = (byte)((((rgb[colorIndex + 1] - ec1) * a1) + (ec1 << 16)) >> 16);
                byte n2 = (byte)((((rgb[colorIndex + 2] - ec2) * a0) + (ec2 << 16)) >> 16);

                destImgBuffer[destImgIndex]     = n0;
                destImgBuffer[destImgIndex + 1] = n1;
                destImgBuffer[destImgIndex + 2] = n2;

                destImgIndex += 4;
                round         = 0;
                colorIndex    = 0;
                srcImgIndex  += 3;
                width        -= 3;

                //}
                //catch (Exception ex)
                //{

                //}
            }
        }
Beispiel #11
0
 /// <summary>
 /// copy from actual image direct to hBmpScan0
 /// </summary>
 /// <param name="actualImage"></param>
 /// <param name="hBmpScan0"></param>
 public static void CopyToWindowsBitmapSameSize(
     ActualImage actualImage,
     IntPtr hBmpScan0)
 {
     //1st, fast
     int[] rawBuffer = ActualImage.GetBuffer(actualImage);
     System.Runtime.InteropServices.Marshal.Copy(rawBuffer, 0,
                                                 hBmpScan0, rawBuffer.Length);
 }
Beispiel #12
0
 public MiniAggCanvasRenderElement(RootGraphic rootgfx, int width, int height)
     : base(rootgfx, width, height)
 {
     this.actualImage = new ActualImage(width, height, PixelFarm.Agg.PixelFormat.ARGB32);
     this._aggsx      = new AggRenderSurface(actualImage);
     this.painter     = new AggPainter((AggRenderSurface)_aggsx);
     needUpdate       = true;
     this.BackColor   = Color.White;
 }
 public void BindHostGraphics(Graphics hostControlGraphics)
 {
     g = hostControlGraphics;
     //
     destImg  = new ActualImage(400, 300, PixelFormat.ARGB32);
     imgGfx2d = new ImageGraphics2D(destImg); //no platform
     p        = new AggCanvasPainter(imgGfx2d);
     winBmp   = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
 }
Beispiel #14
0
 /// <summary>
 /// copy from actual image direct to hBmpScan0
 /// </summary>
 /// <param name="actualImage"></param>
 /// <param name="hBmpScan0"></param>
 public static void CopyToWindowsBitmapSameSize(
    ActualImage actualImage,
    IntPtr hBmpScan0)
 {
     //1st, fast
     byte[] rawBuffer = ActualImage.GetBuffer(actualImage);
     System.Runtime.InteropServices.Marshal.Copy(rawBuffer, 0,
        hBmpScan0, rawBuffer.Length);
 }
 void Blend(ActualImage destImg, byte[] greyBuff, int greyBufferWidth, int greyBufferHeight)
 {
     PixelFarm.Drawing.Color color = PixelFarm.Drawing.Color.Black;
     for (int y = 0; y < greyBufferHeight; ++y)
     {
         BlendScanline(destImg, greyBuff, color, 0, y, greyBufferWidth);
     }
     //SwapRB(destImg);
 }
 public MiniAggCanvasRenderElement(RootGraphic rootgfx, int width, int height)
     : base(rootgfx, width, height)
 {
     this.actualImage = new ActualImage(width, height, PixelFarm.Agg.PixelFormat.ARGB32);
     this.gfx2d       = Graphics2D.CreateFromImage(actualImage);
     this.painter     = new AggCanvasPainter((ImageGraphics2D)gfx2d);
     needUpdate       = true;
     this.BackColor   = Color.White;
 }
Beispiel #17
0
        public static void CopyFromWindowsBitmapSameSize(
            Bitmap windowsBitmap,
            ActualImage actualImage)
        {
            int h = windowsBitmap.Height;
            int w = windowsBitmap.Width;

            byte[]     buffer      = actualImage.GetBuffer();
            BitmapData bitmapData1 = windowsBitmap.LockBits(
                new Rectangle(0, 0,
                              w,
                              h),
                System.Drawing.Imaging.ImageLockMode.ReadWrite,
                windowsBitmap.PixelFormat);

            IntPtr scan0  = bitmapData1.Scan0;
            int    stride = bitmapData1.Stride;

            //unsafe
            //{
            //    fixed (byte* bufferH = &buffer[0])
            //    {
            //        byte* target = (byte*)scan0;
            //        for (int y = h; y > 0; --y)
            //        {
            //            byte* src = bufferH + ((y - 1) * stride);
            //            for (int n = stride - 1; n >= 0; --n)
            //            {
            //                *target = *src;
            //                target++;
            //                src++;
            //            }
            //        }
            //    }
            //}
            unsafe
            {
                //target
                fixed(byte *targetH = &buffer[0])
                {
                    byte *src = (byte *)scan0;

                    for (int y = h; y > 0; --y)
                    {
                        byte *target = targetH + ((y - 1) * stride);
                        for (int n = stride - 1; n >= 0; --n)
                        {
                            *target = *src;
                            target++;
                            src++;
                        }
                    }
                }
            }
            windowsBitmap.UnlockBits(bitmapData1);
        }
Beispiel #18
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }
            //
            _basicOptions = basicFontOptionsUserControl1.Options;
            _basicOptions.TypefaceChanged += (s, e2) =>
            {
                if (_devVxsTextPrinter != null)
                {
                    _devVxsTextPrinter.Typeface = e2.SelectedTypeface;
                }
            };
            _basicOptions.UpdateRenderOutput += (s, e2) =>
            {
                UpdateRenderOutput();
            };
            //
            //----------
            _renderOptions = glyphRenderOptionsUserControl1.Options;
            _renderOptions.UpdateRenderOutput += (s, e2) =>
            {
                UpdateRenderOutput();
            };

            //share text printer to our sample textbox
            //but you can create another text printer that specific to text textbox control

            destImg = new ActualImage(800, 600);
            aggsx   = new AggRenderSurface(destImg); //no platform
            painter = new AggPainter(aggsx);
            winBmp  = new Bitmap(destImg.Width, destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            g       = this.sampleTextBox1.CreateGraphics();

            painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14);
            var openFontStore = new Typography.TextServices.OpenFontStore();

            _devVxsTextPrinter = new VxsTextPrinter(painter, openFontStore);

            _devVxsTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
            _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont;
            _devVxsTextPrinter.FontSizeInPoints  = 10;

            _controllerForPixelFarm.BindHostGraphics(g);
            _controllerForPixelFarm.TextPrinter = _devVxsTextPrinter;

            this.sampleTextBox1.SetController(_controllerForPixelFarm);
            _readyToRender = true;
            _basicOptions.UpdateRenderOutput += (s, e2) => UpdateRenderOutput();
            //----------
            //txtInputChar.TextChanged += (s, e2) => UpdateRenderOutput();
            //----------
        }
Beispiel #19
0
        public override void DrawImage(ActualImage actualImage, double x, double y)
        {
            //create Gdi bitmap from actual image
            int w = actualImage.Width;
            int h = actualImage.Height;

            switch (actualImage.PixelFormat)
            {
            case Agg.PixelFormat.ARGB32:
            {
                using (SKBitmap newBmp = new SKBitmap(actualImage.Width, actualImage.Height))
                {
                    newBmp.LockPixels();
                    byte[] actualImgBuffer = ActualImage.GetBuffer(actualImage);
                    System.Runtime.InteropServices.Marshal.Copy(
                        actualImgBuffer,
                        0,
                        newBmp.GetPixels(),
                        actualImgBuffer.Length);
                    newBmp.UnlockPixels();
                }
                //newBmp.internalBmp.LockPixels();
                //byte[] actualImgBuffer = ActualImage.GetBuffer(actualImage);

                //System.Runtime.InteropServices.Marshal.Copy(
                //     actualImgBuffer,
                //     0,
                //      newBmp.internalBmp.GetPixels(),
                //      actualImgBuffer.Length);

                //newBmp.internalBmp.UnlockPixels();
                //return newBmp;

                //copy data from acutal buffer to internal representation bitmap
                //using (MySkBmp bmp = MySkBmp.CopyFrom(actualImage))
                //{
                //    _skCanvas.DrawBitmap(bmp.internalBmp, (float)x, (float)y);
                //}
            }
            break;

            case Agg.PixelFormat.RGB24:
            {
            }
            break;

            case Agg.PixelFormat.GrayScale8:
            {
            }
            break;

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #20
0
        private void button3_Click(object sender, EventArgs e)
        {
            //----------------------
            //1. test gdi+ font path
            char  testChar = 'b';
            float fontSize = 20;

            using (System.Drawing.Font ff = new Font("tahoma", fontSize))
                using (Graphics g = this.pictureBox1.CreateGraphics())
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.Clear(Color.White);

                    var winFont      = PixelFarm.Agg.Fonts.GdiPathFontStore.LoadFont("tahoma", (int)fontSize);
                    var winFontGlyph = winFont.GetGlyph(testChar);

                    //convert Agg vxs to bitmap
                    int bmpW = 50;
                    int bmpH = 50;
                    using (Bitmap bufferBmp = new Bitmap(bmpW, bmpH))
                    {
                        ActualImage actualImage = new ActualImage(bmpW, bmpH, PixelFarm.Agg.Image.PixelFormat.Rgba32);
                        Graphics2D  gfx         = Graphics2D.CreateFromImage(actualImage);
                        var         vxs         = winFontGlyph.originalVxs;
                        gfx.Render(vxs, ColorRGBA.Black);
                        //test subpixel rendering
                        vxs = PixelFarm.Agg.Transform.Affine.TranslateToVxs(vxs, 15, 0);
                        gfx.UseSubPixelRendering = true;
                        gfx.Render(vxs, ColorRGBA.Black);
                        PixelFarm.Agg.Image.BitmapHelper.CopyToWindowsBitmap(
                            actualImage, //src from actual img buffer
                            bufferBmp,   //dest to buffer bmp
                            new RectInt(0, 0, bmpW, bmpH));
                        //-----------------------------------------
                        bufferBmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                        g.DrawImage(bufferBmp, new Point(0, 30));
                    }
                    //----------------------------------------------



                    //----------------------------------------------
                    //compare with GraphicsPath's Font
                    using (GraphicsPath gpath = new GraphicsPath())
                    {
                        gpath.AddString(testChar.ToString(), ff.FontFamily, 1, ff.Size,
                                        new Point(0, 0), null);
                        g.FillPath(Brushes.Black, gpath);
                        //g.DrawPath(Pens.Black, gpath);
                    }
                    //-------------------------------------------------
                    //Compare with Gdi+ Font
                    g.DrawString(testChar.ToString(), ff, Brushes.Black, new PointF(0, 50));
                }
        }
        public override void Init()
        {
            UseBitmapExt = false;

            string imgFileName = "d:\\WImageTest\\lion1.png";

            if (System.IO.File.Exists(imgFileName))
            {
                lionImg = DemoHelper.LoadImage(imgFileName);
            }
        }
        public static void CopyToWindowsBitmap(ActualImage backingImageBufferByte,
                                               Bitmap windowsBitmap,
                                               RectInt rect)
        {
            int offset = 0;

            byte[] buffer = backingImageBufferByte.GetBuffer();
            BitmapHelper.CopyToWindowsBitmap(buffer, offset,
                                             backingImageBufferByte.Stride, backingImageBufferByte.Height,
                                             backingImageBufferByte.BitDepth,
                                             windowsBitmap, rect);
        }
Beispiel #23
0
 void UpdateRenderOutput()
 {
     if (g == null)
     {
         destImg  = new ActualImage(400, 300, PixelFormat.ARGB32);
         imgGfx2d = new ImageGraphics2D(destImg); //no platform
         p        = new AggCanvasPainter(imgGfx2d);
         winBmp   = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         g        = this.CreateGraphics();
     }
     ReadAndRender(_currentSelectedFontFile);
 }
Beispiel #24
0
        private void button4_Click(object sender, EventArgs e)
        {
            //----------------------
            //1. test gdi+ font path
            char  testChar = 'b';
            float fontSize = 20;


            using (Graphics g = this.pictureBox1.CreateGraphics())
            {
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.Clear(Color.White);

                //convert Agg vxs to bitmap
                int bmpW = 500;
                int bmpH = 500;
                using (Bitmap bufferBmp = new Bitmap(bmpW, bmpH))
                {
                    ActualImage actualImage = new ActualImage(bmpW, bmpH, PixelFarm.Agg.Image.PixelFormat.Rgba32);
                    Graphics2D  gfx         = Graphics2D.CreateFromImage(actualImage);
                    var         vxs         = new VertexStore();

                    //vxs.AddMoveTo(0, 0);
                    ////vxs.AddP3c(100, 0);
                    ////vxs.AddP3c(100,150);
                    ////vxs.AddLineTo(0,0);
                    //vxs.AddLineTo(0, 0);
                    //vxs.AddP3c(100, 0);
                    ////vxs.AddLineTo(100, 0);
                    ////vxs.AddLineTo(100, 150);
                    //vxs.AddP3c(100, 150);
                    //vxs.AddLineTo(0, 150);
                    //vxs.AddCloseFigure();

                    //PixelFarm.Agg.VertexSource.CurveFlattener cflat = new PixelFarm.Agg.VertexSource.CurveFlattener();
                    //vxs = cflat.MakeVxs(vxs);

                    gfx.Render(vxs, ColorRGBA.Black);
                    //test subpixel rendering
                    vxs = PixelFarm.Agg.Transform.Affine.TranslateToVxs(vxs, 15, 0);
                    gfx.UseSubPixelRendering = true;
                    gfx.Render(vxs, ColorRGBA.Black);
                    PixelFarm.Agg.Image.BitmapHelper.CopyToWindowsBitmap(
                        actualImage, //src from actual img buffer
                        bufferBmp,   //dest to buffer bmp
                        new RectInt(0, 0, bmpW, bmpH));
                    //-----------------------------------------
                    bufferBmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                    g.DrawImage(bufferBmp, new Point(0, 30));
                }
            }
        }
        static byte[] CreateGreyScaleBuffer(ActualImage img)
        {
            //assume img is 32 rgba img
            int imgW   = img.Width;
            int height = img.Height;
            //56 level grey scale buffer


            TempMemPtr srcMemPtr = ActualImage.GetBufferPtr(img);

            int greyScaleBufferLen = imgW * height;

            byte[] greyScaleBuffer = new byte[greyScaleBufferLen];

            int destIndex    = 0;
            int srcImgIndex  = 0;
            int srcImgStride = img.Stride;

            unsafe
            {
                byte *srcImgBuffer = (byte *)srcMemPtr.Ptr;
                for (int y = 0; y < height; ++y)
                {
                    srcImgIndex = srcImgStride * y;
                    destIndex   = imgW * y;
                    for (int x = 0; x < imgW; ++x)
                    {
                        byte r = srcImgBuffer[srcImgIndex];
                        byte g = srcImgBuffer[srcImgIndex + 1];
                        byte b = srcImgBuffer[srcImgIndex + 2];
                        byte a = srcImgBuffer[srcImgIndex + 3];
                        if (r != 0 || g != 0 || b != 0)
                        {
                        }
                        if (a != 255)
                        {
                        }
                        //skip alpha
                        //byte greyScaleValue =
                        //    (byte)((0.333f * (float)r) + (0.5f * (float)g) + (0.1666f * (float)b));

                        greyScaleBuffer[destIndex] = (byte)(((a + 1) / 256f) * 64f);

                        destIndex++;
                        srcImgIndex += 4;
                    }
                }
            }

            srcMemPtr.Release();
            return(greyScaleBuffer);
        }
 static ActualImage LoadImage(string filename)
 {
     //read sample image
     using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(filename))
     {
         //read to image buffer
         int         bmpW = bmp.Width;
         int         bmpH = bmp.Height;
         ActualImage img  = new ActualImage(bmpW, bmpH);
         BitmapHelper.CopyFromGdiPlusBitmapSameSizeTo32BitsBuffer(bmp, img);
         return(img);
     }
 }
Beispiel #27
0
 static ActualImage LoadImage(string filename)
 {
     //read sample image
     using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(filename))
     {
         //read to image buffer
         int         bmpW        = bmp.Width;
         int         bmpH        = bmp.Height;
         ActualImage actualImage = new ActualImage(bmpW, bmpH, PixelFormat.ARGB32);
         BitmapHelper.CopyFromGdiPlusBitmapSameSize(bmp, actualImage);
         return(actualImage);
     }
 }
Beispiel #28
0
        public void Initialize(int width, int height, int bitDepth, ActualImage actualImage)
        {
            if (width > 0 && height > 0)
            {
                this.width       = width;
                this.height      = height;
                nativeWin32Dc    = new Win32.NativeWin32MemoryDc(width, height, false);
                this.actualImage = actualImage;

                return;
            }
            throw new NotSupportedException();
        }
Beispiel #29
0
        private void button4_Click(object sender, EventArgs e)
        {
            //----------------------
            //1. test gdi+ font path
            char  testChar = 'b';
            float fontSize = 20;

            using (Graphics g = this.pictureBox1.CreateGraphics())
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.Clear(System.Drawing.Color.White);
                //convert Agg vxs to bitmap
                int bmpW = 500;
                int bmpH = 500;
                using (Bitmap bufferBmp = new Bitmap(bmpW, bmpH))
                {
                    ActualImage      actualImage = new ActualImage(bmpW, bmpH);
                    AggRenderSurface gfx         = new AggRenderSurface(actualImage);
                    var vxs = new PixelFarm.Drawing.VertexStore();
                    //vxs.AddMoveTo(0, 0);
                    ////vxs.AddP3c(100, 0);
                    ////vxs.AddP3c(100,150);
                    ////vxs.AddLineTo(0,0);
                    //vxs.AddLineTo(0, 0);
                    //vxs.AddP3c(100, 0);
                    ////vxs.AddLineTo(100, 0);
                    ////vxs.AddLineTo(100, 150);
                    //vxs.AddP3c(100, 150);
                    //vxs.AddLineTo(0, 150);
                    //vxs.AddCloseFigure();

                    //PixelFarm.Agg.VertexSource.CurveFlattener cflat = new PixelFarm.Agg.VertexSource.CurveFlattener();
                    //vxs = cflat.MakeVxs(vxs);

                    gfx.Render(vxs, PixelFarm.Drawing.Color.Black);
                    //test subpixel rendering


                    vxs = vxs.TranslateToNewVxs(15, 0, new PixelFarm.Drawing.VertexStore());
                    gfx.UseSubPixelRendering = true;
                    gfx.Render(vxs, PixelFarm.Drawing.Color.Black);
                    PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(
                        actualImage, //src from actual img buffer
                        bufferBmp    //dest to buffer bmp
                        );
                    //-----------------------------------------
                    bufferBmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                    g.DrawImage(bufferBmp, new System.Drawing.Point(0, 30));
                }
            }
        }
        public void BindHostGraphics(Graphics hostControlGraphics)
        {
            g = hostControlGraphics;
            //
            destImg  = new ActualImage(400, 300, PixelFormat.ARGB32);
            imgGfx2d = new ImageGraphics2D(destImg); //no platform
            p        = new AggCanvasPainter(imgGfx2d);
            winBmp   = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            _printer    = new VxsTextPrinter(p, null);
            _visualLine = new VisualLine();
            _visualLine.BindLine(_line);
            _visualLine.Y = 100;
        }
Beispiel #31
0
 static ActualImage LoadImage(string filename)
 {
     //read sample image
     using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(filename))
     {
         //read to image buffer
         int         bmpW        = bmp.Width;
         int         bmpH        = bmp.Height;
         PixelFormat pixFormat   = PixelFormat.Rgba32;
         ActualImage actualImage = new ActualImage(bmpW, bmpH, pixFormat);
         PixelFarm.Agg.Image.BitmapHelper.CopyFromWindowsBitmapSameSize(bmp, actualImage);
         return(actualImage);
     }
 }
        public void Initialize(int width, int height, int bitDepth, ActualImage actualImage)
        {
            if (width > 0 && height > 0)
            {
                this.width = width;
                this.height = height;

                //if (bitDepth != 32)
                //{
                //    throw new NotImplementedException("Don't support this bit depth yet.");
                //}
                //else
                //{
                //    actualImage = new ActualImage(width, height, PixelFormat.ARGB32);
                this.actualImage = actualImage;
                nativeWin32Dc = new Win32.NativeWin32MemoryDc(width, height, true);
                //    return Graphics2D.CreateFromImage(actualImage);
                //}
                return;
            }
            throw new NotSupportedException();
        }
Beispiel #33
0
        /////////////////////////////////////////////////////////////////////////////////////

        public static void CopyToGdiPlusBitmapSameSize(
            ActualImage actualImage,
            Bitmap bitmap)
        {
            //agg store image buffer head-down
            //when copy to window bmp we here to flip 
            //style1: copy row by row *** (fastest)***
            {
                //System.GC.Collect();
                //System.Diagnostics.Stopwatch sss = new System.Diagnostics.Stopwatch();
                //sss.Start();
                //for (int i = 0; i < 1000; ++i)
                //{
                int h = bitmap.Height;
                int w = bitmap.Width;
                BitmapData bitmapData1 = bitmap.LockBits(
                          new Rectangle(0, 0,
                              w,
                              h),
                              System.Drawing.Imaging.ImageLockMode.ReadWrite,
                              bitmap.PixelFormat);
                IntPtr scan0 = bitmapData1.Scan0;
                int stride = bitmapData1.Stride;
                byte[] srcBuffer = ActualImage.GetBuffer(actualImage);
                unsafe
                {
                    fixed (byte* bufferH = &srcBuffer[0])
                    {
                        byte* target = (byte*)scan0;
                        int startRowAt = ((h - 1) * stride);
                        for (int y = h; y > 0; --y)
                        {
                            //byte* src = bufferH + ((y - 1) * stride);
                            System.Runtime.InteropServices.Marshal.Copy(
                               srcBuffer,//src
                               startRowAt,
                               (IntPtr)target,
                               stride);
                            startRowAt -= stride;
                            target += stride;
                        }
                    }
                }
                bitmap.UnlockBits(bitmapData1);
                //}
                //sss.Stop();
                //long ms = sss.ElapsedMilliseconds;
            }
            //-----------------------------------
            //style2: copy all, then flip again
            //{
            //    System.GC.Collect();
            //    System.Diagnostics.Stopwatch sss = new System.Diagnostics.Stopwatch();
            //    sss.Start();
            //    for (int i = 0; i < 1000; ++i)
            //    {
            //        byte[] rawBuffer = ActualImage.GetBuffer(actualImage);
            //        var bmpdata = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
            //          System.Drawing.Imaging.ImageLockMode.ReadOnly,
            //         bitmap.PixelFormat);


            //        System.Runtime.InteropServices.Marshal.Copy(rawBuffer, 0,
            //            bmpdata.Scan0, rawBuffer.Length);

            //        bitmap.UnlockBits(bmpdata);
            //        bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            //    }

            //    sss.Stop();
            //    long ms = sss.ElapsedMilliseconds; 
            //}
            //-----------------------------------

            //-----------------------------------
            //style3: copy row by row + 
            //{
            //    System.GC.Collect();
            //    System.Diagnostics.Stopwatch sss = new System.Diagnostics.Stopwatch();
            //    sss.Start();
            //    for (int i = 0; i < 1000; ++i)
            //    {
            //        int h = bitmap.Height;
            //        int w = bitmap.Width;
            //        BitmapData bitmapData1 = bitmap.LockBits(
            //                  new Rectangle(0, 0,
            //                      w,
            //                      h),
            //                      System.Drawing.Imaging.ImageLockMode.ReadWrite,
            //                      bitmap.PixelFormat);
            //        IntPtr scan0 = bitmapData1.Scan0;
            //        int stride = bitmapData1.Stride;
            //        byte[] buffer = ActualImage.GetBuffer(actualImage);
            //        unsafe
            //        {
            //            fixed (byte* bufferH = &buffer[0])
            //            {
            //                byte* target = (byte*)scan0;
            //                for (int y = h; y > 0; --y)
            //                {
            //                    byte* src = bufferH + ((y - 1) * stride);
            //                    for (int n = stride - 1; n >= 0; --n)
            //                    {
            //                        *target = *src;
            //                        target++;
            //                        src++;
            //                    }
            //                }
            //            }
            //        }
            //        bitmap.UnlockBits(bitmapData1);
            //    }
            //    sss.Stop();
            //    long ms = sss.ElapsedMilliseconds;
            //} 
        }
Beispiel #34
0
        public static void CopyFromGdiPlusBitmapSameSize(
           Bitmap windowsBitmap,
           ActualImage actualImage)
        {
            int h = windowsBitmap.Height;
            int w = windowsBitmap.Width;
            byte[] targetBuffer = ActualImage.GetBuffer(actualImage);
            BitmapData bitmapData1 = windowsBitmap.LockBits(
                      new Rectangle(0, 0,
                          w,
                          h),
                          System.Drawing.Imaging.ImageLockMode.ReadWrite,
                          windowsBitmap.PixelFormat);
            IntPtr scan0 = bitmapData1.Scan0;
            int stride = bitmapData1.Stride;

            //TODO: review here 
            //use buffer copy

            unsafe
            {
                //target 
                int startRowAt = ((h - 1) * stride);
                byte* src = (byte*)scan0;
                for (int y = h; y > 0; --y)
                {
                    // byte* target = targetH + ((y - 1) * stride);

                    System.Runtime.InteropServices.Marshal.Copy(
                          (IntPtr)src,//src
                          targetBuffer, startRowAt, stride);
                    startRowAt -= stride;
                    src += stride;
                }

                //////////////////////////////////////////////////////////////////
                //fixed (byte* targetH = &targetBuffer[0])
                //{
                //    byte* src = (byte*)scan0;
                //    for (int y = h; y > 0; --y)
                //    {
                //        byte* target = targetH + ((y - 1) * stride);
                //        for (int n = stride - 1; n >= 0; --n)
                //        {
                //            *target = *src;
                //            target++;
                //            src++;
                //        }
                //    }
                //}
            }
            windowsBitmap.UnlockBits(bitmapData1);
        }
 ActualImage GetTransformedBitmapNoInterpolation()
 {
     var destCB = new ActualImage(rect.Width, rect.Height, PixelFormat.ARGB32);
     var destWriter = new MyImageReaderWriter();
     destWriter.ReloadImage(destCB);
     PointF ptInPlane = new PointF();
     int x1, x2, y1, y2;
     double dab, dbc, dcd, dda;
     float dx1, dx2, dy1, dy2, dx1y1, dx1y2, dx2y1, dx2y2;
     int rectWidth = rect.Width;
     int rectHeight = rect.Height;
     var ab_vec = this.AB;
     var bc_vec = this.BC;
     var cd_vec = this.CD;
     var da_vec = this.DA;
     int rectLeft = this.rect.Left;
     int rectTop = this.rect.Top;
     for (int y = 0; y < rectHeight; ++y)
     {
         for (int x = 0; x < rectWidth; ++x)
         {
             PointF srcPt = new PointF(x, y);
             srcPt.Offset(rectLeft, rectTop);
             if (!IsOnPlaneABCD(srcPt))
             {
                 continue;
             }
             x1 = (int)ptInPlane.X;
             y1 = (int)ptInPlane.Y;
             destWriter.SetPixel(x, y, srcCB.GetPixel(x1, y1));
             //-------------------------------------
             dab = Math.Abs((new Vector(vertex[0], srcPt)).CrossProduct(ab_vec));
             dbc = Math.Abs((new Vector(vertex[1], srcPt)).CrossProduct(bc_vec));
             dcd = Math.Abs((new Vector(vertex[2], srcPt)).CrossProduct(cd_vec));
             dda = Math.Abs((new Vector(vertex[3], srcPt)).CrossProduct(da_vec));
             ptInPlane.X = (float)(srcW * (dda / (dda + dbc)));
             ptInPlane.Y = (float)(srcH * (dab / (dab + dcd)));
         }
     }
     return destCB;
 }
        ActualImage GetTransformedBilinearInterpolation()
        {
            //4 points sampling
            //weight between four point
            ActualImage destCB = new ActualImage(rect.Width, rect.Height, PixelFormat.ARGB32);
            MyImageReaderWriter destWriter = new MyImageReaderWriter();
            destWriter.ReloadImage(destCB);
            PointF ptInPlane = new PointF();
            int x1, x2, y1, y2;
            double dab, dbc, dcd, dda;
            float dx1, dx2, dy1, dy2, dx1y1, dx1y2, dx2y1, dx2y2;
            int rectWidth = rect.Width;
            int rectHeight = rect.Height;
            var ab_vec = this.AB;
            var bc_vec = this.BC;
            var cd_vec = this.CD;
            var da_vec = this.DA;
            int rectLeft = this.rect.Left;
            int rectTop = this.rect.Top;
            for (int y = 0; y < rectHeight; ++y)
            {
                for (int x = 0; x < rectWidth; ++x)
                {
                    PointF srcPt = new PointF(x, y);
                    srcPt.Offset(rectLeft, rectTop);
                    if (!IsOnPlaneABCD(srcPt))
                    {
                        continue;
                    }
                    //-------------------------------------
                    dab = Math.Abs(new Vector(vertex[0], srcPt).CrossProduct(ab_vec));
                    dbc = Math.Abs(new Vector(vertex[1], srcPt).CrossProduct(bc_vec));
                    dcd = Math.Abs(new Vector(vertex[2], srcPt).CrossProduct(cd_vec));
                    dda = Math.Abs(new Vector(vertex[3], srcPt).CrossProduct(da_vec));
                    ptInPlane.X = (float)(srcW * (dda / (dda + dbc)));
                    ptInPlane.Y = (float)(srcH * (dab / (dab + dcd)));
                    x1 = (int)ptInPlane.X;
                    y1 = (int)ptInPlane.Y;
                    if (x1 >= 0 && x1 < srcW && y1 >= 0 && y1 < srcH)
                    {
                        //bilinear interpolation *** 
                        x2 = (x1 == srcW - 1) ? x1 : x1 + 1;
                        y2 = (y1 == srcH - 1) ? y1 : y1 + 1;
                        dx1 = ptInPlane.X - (float)x1;
                        if (dx1 < 0) dx1 = 0;
                        dx1 = 1f - dx1;
                        dx2 = 1f - dx1;
                        dy1 = ptInPlane.Y - (float)y1;
                        if (dy1 < 0) dy1 = 0;
                        dy1 = 1f - dy1;
                        dy2 = 1f - dy1;
                        dx1y1 = dx1 * dy1;
                        dx1y2 = dx1 * dy2;
                        dx2y1 = dx2 * dy1;
                        dx2y2 = dx2 * dy2;
                        //use 4 points

                        Drawing.Color x1y1Color = srcCB.GetPixel(x1, y1);
                        Drawing.Color x2y1Color = srcCB.GetPixel(x2, y1);
                        Drawing.Color x1y2Color = srcCB.GetPixel(x1, y2);
                        Drawing.Color x2y2Color = srcCB.GetPixel(x2, y2);
                        float a = (x1y1Color.alpha * dx1y1) + (x2y1Color.alpha * dx2y1) + (x1y2Color.alpha * dx1y2) + (x2y2Color.alpha * dx2y2);
                        float b = (x1y1Color.blue * dx1y1) + (x2y1Color.blue * dx2y1) + (x1y2Color.blue * dx1y2) + (x2y2Color.blue * dx2y2);
                        float g = (x1y1Color.green * dx1y1) + (x2y1Color.green * dx2y1) + (x1y2Color.green * dx1y2) + (x2y2Color.green * dx2y2);
                        float r = (x1y1Color.red * dx1y1) + (x2y1Color.red * dx2y1) + (x1y2Color.red * dx1y2) + (x2y2Color.red * dx2y2);
                        destWriter.SetPixel(x, y, new Drawing.Color((byte)a, (byte)b, (byte)g, (byte)r));
                        //destCB.SetColorPixel(x, y, new ColorRGBA((byte)b, (byte)g, (byte)r, (byte)a));
                    }
                }
            }
            return destCB;
        }
        ActualImage GetTransformedBicubicInterpolation()
        {
            //4 points sampling
            //weight between four point


            PointF ptInPlane = new PointF();
            int x1, x2, y1, y2;
            double dab, dbc, dcd, dda;
            float dx1, dx2, dy1, dy2, dx1y1, dx1y2, dx2y1, dx2y2;
            int rectWidth = rect.Width;
            int rectHeight = rect.Height;
            var ab_vec = this.AB;
            var bc_vec = this.BC;
            var cd_vec = this.CD;
            var da_vec = this.DA;
            byte[] buffer = srcCB.GetBuffer();
            int stride = srcCB.Stride;
            int bmpWidth = srcCB.Width;
            int bmpHeight = srcCB.Height;
            BufferReader4 reader = new BufferReader4(buffer, stride, bmpWidth, bmpHeight);
            MyColor[] pixelBuffer = new MyColor[16];
            byte[] sqPixs = new byte[16];
            //Bitmap outputbmp = new Bitmap(rectWidth, rectHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            ////-----------------------------------------------
            //var bmpdata2 = outputbmp.LockBits(new Rectangle(0, 0, rectWidth, rectHeight),
            //    System.Drawing.Imaging.ImageLockMode.ReadWrite, outputbmp.PixelFormat);
            ////-----------------------------------------

            ActualImage destCB = new ActualImage(rect.Width, rect.Height, PixelFormat.ARGB32);
            MyImageReaderWriter destWriter = new MyImageReaderWriter();
            destWriter.ReloadImage(destCB);
            //PointF ptInPlane = new PointF();

            //int stride2 = bmpdata2.Stride;
            //byte[] outputBuffer = new byte[stride2 * outputbmp.Height];

            // int targetPixelIndex = 0;
            // int startLine = 0;

            int rectLeft = this.rect.Left;
            int rectTop = this.rect.Top;
            for (int y = 0; y < rectHeight; ++y)
            {
                for (int x = 0; x < rectWidth; ++x)
                {
                    PointF srcPt = new PointF(x, y);
                    srcPt.Offset(rectLeft, rectTop);
                    if (!IsOnPlaneABCD(srcPt))
                    {
                        continue;
                    }
                    //-------------------------------------
                    dab = Math.Abs(new Vector(vertex[0], srcPt).CrossProduct(ab_vec));
                    dbc = Math.Abs(new Vector(vertex[1], srcPt).CrossProduct(bc_vec));
                    dcd = Math.Abs(new Vector(vertex[2], srcPt).CrossProduct(cd_vec));
                    dda = Math.Abs(new Vector(vertex[3], srcPt).CrossProduct(da_vec));
                    ptInPlane.X = (float)(srcW * (dda / (dda + dbc)));
                    ptInPlane.Y = (float)(srcH * (dab / (dab + dcd)));
                    x1 = (int)ptInPlane.X;
                    y1 = (int)ptInPlane.Y;
                    if (x1 >= 2 && x1 < srcW - 2 && y1 >= 2 && y1 < srcH - 2)
                    {
                        reader.SetStartPixel(x1, y1);
                        reader.Read16(pixelBuffer);
                        //do interpolate

                        //find src pixel and approximate  
                        MyColor color = GetApproximateColor_Bicubic(reader,
                           ptInPlane.X,
                           ptInPlane.Y);
                        //outputBuffer[targetPixelIndex] = (byte)color.b;
                        //outputBuffer[targetPixelIndex + 1] = (byte)color.g;
                        //outputBuffer[targetPixelIndex + 2] = (byte)color.r;
                        //outputBuffer[targetPixelIndex + 3] = (byte)color.a;
                        //targetPixelIndex += 4;

                        destWriter.SetPixel(x, y, new Drawing.Color(color.a, color.b, color.g, color.r)); //TODO:review here blue switch to red channel
                    }
                }
                //newline
                // startLine += stride2;
                //targetPixelIndex = startLine;
            }
            //------------------------
            //System.Runtime.InteropServices.Marshal.Copy(
            //outputBuffer, 0,
            //bmpdata2.Scan0, outputBuffer.Length);
            //outputbmp.UnlockBits(bmpdata2);
            ////outputbmp.Save("d:\\WImageTest\\n_lion_bicubic.png");
            //return outputbmp;
            return destCB;
        }