public MyGdiBackbuffer(int w, int h)
        {
            _w = w;
            _h = h;

            _memBitmap = new CpuBlit.MemBitmap(w, h);
        }
Esempio n. 2
0
        public MemBitmap LoadImage(Stream input, OutputImageFormat format)
        {
            ImageTools.ExtendedImage extendedImg = new ImageTools.ExtendedImage();
            //TODO: review img loading, we should not use only its extension
            switch (format)
            {
            case OutputImageFormat.Jpeg:
            {
                var decoder = new ImageTools.IO.Jpeg.JpegDecoder();
                var dst     = new JpegDecoderDst();
                extendedImg.JpegDecompressDest = dst;
                extendedImg.Load(input, decoder);
                //copy from

                return(dst.MemBitmapOutput);
            }
            break;

            case OutputImageFormat.Png:
            {
                var decoder = new ImageTools.IO.Png.PngDecoder();
                extendedImg.Load(input, decoder);
            }
            break;

            default:
                throw new System.NotSupportedException();
            }

            //assume 32 bit ??
            byte[] pixels = extendedImg.Pixels;
            unsafe
            {
                fixed(byte *p_src = &pixels[0])
                {
                    PixelFarm.CpuBlit.MemBitmap memBmp = PixelFarm.CpuBlit.MemBitmap.CreateFromCopy(
                        extendedImg.PixelWidth,
                        extendedImg.PixelHeight,
                        (IntPtr)p_src,
                        pixels.Length,
                        false
                        );

                    memBmp.IsBigEndian = true;
                    return(memBmp);
                }
            }

            ////PixelFarm.CpuBlit.MemBitmap memBmp = PixelFarm.CpuBlit.MemBitmap.CreateFromCopy(
            ////    extendedImg.PixelWidth,
            ////    extendedImg.PixelHeight,
            ////    extendedImg.PixelWidth * 4, //assume
            ////    32, //assume?
            ////    extendedImg.Pixels,
            ////    false
            ////    );
            ////the imgtools load data as BigEndian
            //memBmp.IsBigEndian = true;
            //return memBmp;
        }
Esempio n. 3
0
        public override void UpdateViewContent(FormRenderUpdateEventArgs formRenderUpdateEventArgs)
        {
            //1. create platform bitmap
            // create the surface
            int w = 800;
            int h = 600;

            if (myImg == null)
            {
                myImg = new PixelFarm.CpuBlit.MemBitmap(w, h);
                //test1
                // create the surface
                var info = new SKImageInfo(w, h, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
                using (var surface = SKSurface.Create(info, PixelFarm.CpuBlit.MemBitmap.GetBufferPtr(myImg).Ptr, myImg.Stride))
                {
                    // start drawing
                    SKCanvas canvas = surface.Canvas;
                    DrawWithSkia(canvas);
                    surface.Canvas.Flush();
                }
            }

            var glBmp = new PixelFarm.DrawingGL.GLBitmap(myImg);

            _pcx.DrawImage(glBmp, 0, 600);
            glBmp.Dispose();
        }
 public override void Dispose()
 {
     if (_memBitmap != null)
     {
         _memBitmap.Dispose();
         _memBitmap = null;
     }
 }
 static PixelFarm.CpuBlit.MemBitmap LoadBmp(string filename)
 {
     using (System.Drawing.Bitmap bmp = new Bitmap(filename))
     {
         var bmpdata = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         PixelFarm.CpuBlit.MemBitmap membmp = PixelFarm.CpuBlit.MemBitmap.CreateFromCopy(bmp.Width, bmp.Height, bmp.Width * bmp.Height * 4, bmpdata.Scan0);
         bmp.UnlockBits(bmpdata);
         return(membmp);
     }
 }
 static PixelFarm.CpuBlit.MemBitmap LoadBmp2(byte[] buffer)
 {
     using (MemoryStream ms = new MemoryStream(buffer))
         using (System.Drawing.Bitmap bmp = new Bitmap(ms))
         {
             var bmpdata = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
             PixelFarm.CpuBlit.MemBitmap membmp = PixelFarm.CpuBlit.MemBitmap.CreateFromCopy(bmp.Width, bmp.Height, bmp.Width * bmp.Height * 4, bmpdata.Scan0);
             bmp.UnlockBits(bmpdata);
             return(membmp);
         }
 }
        public void TestSaveCurrentFrameBuffer()
        {
            //attach spefic frame to the _pcx and make current before copy pixel

            //------------
            unsafe
            {
                //test only!
                //copy from gl to MemBitmap
                using (PixelFarm.CpuBlit.MemBitmap outputBuffer = new PixelFarm.CpuBlit.MemBitmap(_surface1.Width, _surface1.Height))
                {
                    _surface1.CopySurface(0, 0, _surface1.Width, _surface1.Height, outputBuffer);
                    //then save ....
                    //need to swap image buffer from opengl surface
                    outputBuffer.SaveImage("d:\\WImageTest\\outputfrom_framebuffer.png");
                }
            }
        }
Esempio n. 8
0
        static PixelFarm.CpuBlit.MemBitmap ScaleImageInternal(PixelFarm.CpuBlit.MemBitmap bmp, float x_scale, float y_scale)
        {
            System.Drawing.Bitmap gdiBmp = new System.Drawing.Bitmap(bmp.Width, bmp.Height);
            PixelFarm.CpuBlit.BitmapHelper.CopyToGdiPlusBitmapSameSizeNotFlip(bmp, gdiBmp);
            //save exported img to tmp file system?
            //--------------
            int paddingLeftRight = 10;
            int paddingTopBottom = 10;
            int newW             = (int)(gdiBmp.Width * x_scale);
            int newH             = (int)(gdiBmp.Height * y_scale);
            int newBmpW          = newW + paddingLeftRight;
            int newBmpH          = newH + paddingTopBottom;

            System.Drawing.Bitmap resize = ResizeImage(gdiBmp, newBmpW, newBmpH, 0, 0, newW, newH);


            PixelFarm.CpuBlit.MemBitmap newBmp = new PixelFarm.CpuBlit.MemBitmap(newBmpW, newBmpH);
            PixelFarm.CpuBlit.BitmapHelper.CopyFromGdiPlusBitmapSameSizeTo32BitsBuffer(resize, newBmp);
            return(newBmp);
        }
Esempio n. 9
0
        static PixelFarm.CpuBlit.MemBitmap LoadImage(string filename)
        {
            ImageTools.ExtendedImage extendedImg = new ImageTools.ExtendedImage();
            using (var fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                //TODO: review img loading, we should not use only its extension
                //
                string fileExt = System.IO.Path.GetExtension(filename).ToLower();
                switch (fileExt)
                {
                case ".png":
                {
                    var decoder = new ImageTools.IO.Png.PngDecoder();
                    extendedImg.Load(fs, decoder);
                }
                break;

                case ".jpg":
                {
                    var decoder = new ImageTools.IO.Jpeg.JpegDecoder();
                    extendedImg.Load(fs, decoder);
                }
                break;

                default:
                    throw new System.NotSupportedException();
                }
                //var decoder = new ImageTools.IO.Png.PngDecoder();
            }
            //assume 32 bit

            PixelFarm.CpuBlit.MemBitmap memBmp = PixelFarm.CpuBlit.MemBitmap.CreateFromCopy(
                extendedImg.PixelWidth,
                extendedImg.PixelHeight,
                extendedImg.Pixels32
                );
            //the imgtools load data as BigEndian
            memBmp.IsBigEndian = true;
            return(memBmp);
        }
Esempio n. 10
0
        public MemBitmap LoadImage(Stream input, OutputImageFormat format)
        {
            ImageTools.ExtendedImage extendedImg = new ImageTools.ExtendedImage();
            //TODO: review img loading, we should not use only its extension
            switch (format)
            {
            case OutputImageFormat.Png:
            {
                var decoder = new ImageTools.IO.Png.PngDecoder();
                extendedImg.Load(input, decoder);
            }
            break;

            case OutputImageFormat.Jpeg:
            {
                var decoder = new ImageTools.IO.Jpeg.JpegDecoder();
                extendedImg.Load(input, decoder);
            }
            break;

            default:
                throw new System.NotSupportedException();
            }
            //var decoder = new ImageTools.IO.Png.PngDecoder();


            //assume 32 bit

            PixelFarm.CpuBlit.MemBitmap memBmp = PixelFarm.CpuBlit.MemBitmap.CreateFromCopy(
                extendedImg.PixelWidth,
                extendedImg.PixelHeight,
                extendedImg.Pixels32
                );
            //the imgtools load data as BigEndian
            memBmp.IsBigEndian = true;
            return(memBmp);
        }
Esempio n. 11
0
        public void BuildMultiFontSize(string multiFontSizrAtlasFilename, string imgOutputFilename)
        {
            //merge to the new one
            //1. ensure same atlas width
            int atlasW      = 0;
            int j           = _simpleFontInfoList.Count;
            int totalHeight = 0;

            const int interAtlasSpace = 2;

            for (int i = 0; i < j; ++i)
            {
                SimpleFontAtlasInfo atlasInfo = _simpleFontInfoList[i];
                SimpleFontAtlas     fontAtlas = atlasInfo.fontAtlasFile.ResultSimpleFontAtlasList[0];
                totalHeight += fontAtlas.Height + interAtlasSpace;
                if (i == 0)
                {
                    atlasW = fontAtlas.Width;
                }
                else
                {
                    if (atlasW != fontAtlas.Width)
                    {
                        throw new NotSupportedException();
                    }
                }
            }
            //--------------------------------------------
            //in this version, the glyph offsetY is measure from bottom***
            int[] offsetFromBottoms = new int[j];
            int   offsetFromBottom  = interAtlasSpace;//start offset

            for (int i = j - 1; i >= 0; --i)
            {
                SimpleFontAtlasInfo atlasInfo = _simpleFontInfoList[i];
                SimpleFontAtlas     fontAtlas = atlasInfo.fontAtlasFile.ResultSimpleFontAtlasList[0];
                offsetFromBottoms[i] = offsetFromBottom;
                offsetFromBottom    += fontAtlas.Height + interAtlasSpace;
            }
            //--------------------------------------------
            //merge all img to one
            int top = 0;

            using (PixelFarm.CpuBlit.MemBitmap memBitmap = new CpuBlit.MemBitmap(atlasW, totalHeight))
            {
                PixelFarm.CpuBlit.AggPainter painter = PixelFarm.CpuBlit.AggPainter.Create(memBitmap);
                for (int i = 0; i < j; ++i)
                {
                    SimpleFontAtlasInfo atlasInfo = _simpleFontInfoList[i];
                    FontAtlasFile       atlasFile = atlasInfo.fontAtlasFile;
                    SimpleFontAtlas     fontAtlas = atlasInfo.fontAtlasFile.ResultSimpleFontAtlasList[0];

                    atlasInfo.NewCloneLocations = SimpleFontAtlas.CloneLocationWithOffset(fontAtlas, 0, offsetFromBottoms[i]);

                    using (System.IO.Stream fontImgStream = PixelFarm.Platforms.StorageService.Provider.ReadDataStream(atlasInfo.imgFile))
                        using (PixelFarm.CpuBlit.MemBitmap atlasBmp = PixelFarm.CpuBlit.MemBitmap.LoadBitmap(fontImgStream))
                        {
                            painter.DrawImage(atlasBmp, 0, top);
                            top += atlasBmp.Height + interAtlasSpace;
                        }
                }
                memBitmap.SaveImage(imgOutputFilename);
            }
            //--------------------------------------------
            //save merged font atlas
            //TODO: use 'File' provider to access system file
            using (FileStream fs = new FileStream(multiFontSizrAtlasFilename, FileMode.Create))
                using (BinaryWriter w = new BinaryWriter(fs))
                {
                    //-----------
                    //overview
                    //total img info
                    FontAtlasFile fontAtlasFile = new FontAtlasFile();
                    fontAtlasFile.StartWrite(fs);

                    //1. simple atlas count
                    fontAtlasFile.WriteOverviewMultiSizeFontInfo((ushort)j);
                    //2.
                    for (int i = 0; i < j; ++i)
                    {
                        SimpleFontAtlasInfo atlasInfo = _simpleFontInfoList[i];
                        RequestFont         reqFont   = atlasInfo.reqFont;
                        fontAtlasFile.WriteOverviewFontInfo(reqFont.Name, reqFont.FontKey, reqFont.SizeInPoints);//size in points

                        fontAtlasFile.WriteTotalImageInfo(
                            (ushort)atlasW,
                            (ushort)top,
                            4,
                            atlasInfo.textureKind);
                        //
                        //
                        fontAtlasFile.WriteGlyphList(atlasInfo.NewCloneLocations);
                    }
                    fontAtlasFile.EndWrite();
                }
        }
Esempio n. 12
0
        protected override void PaintImp(PaintVisitor p)
        {
#if DEBUG
            p.dbugEnterNewContext(this, PaintVisitor.PaintVisitorContextName.Init);
#endif
            DrawBoard drawBoard = p.InnerDrawBoard;

            if (DisableBmpCache)
            {
                PixelFarm.CpuBlit.AggPainter painter = drawBoard.GetPainter() as PixelFarm.CpuBlit.AggPainter;
                if (painter == null)
                {
                    return;
                }
                //TODO: review here
                //temp fix
                if (s_openfontTextService == null)
                {
                    s_openfontTextService = new OpenFontTextService();
                }

                //painter.CurrentFont = new RequestFont("tahoma", 14);
                //var textPrinter = new PixelFarm.Drawing.Fonts.VxsTextPrinter(painter, s_openfontTextService);
                //painter.TextPrinter = textPrinter;
                //painter.Clear(Color.White);
                //
                double prevStrokeW = painter.StrokeWidth;
                //Color fillColor = painter.FillColor;
                //painter.StrokeWidth = 1;//default
                //painter.FillColor = Color.Black;

                using (Tools.More.BorrowVgPaintArgs(painter, out var paintArgs))
                {
                    if (_vgVisualElem.CoordTx != null)
                    {
                    }
                    _vgVisualElem.Paint(paintArgs);
                }


                painter.StrokeWidth = prevStrokeW;//restore
                //painter.FillColor = fillColor;////restore

                return;
            }


            if (_vgVisualElem.HasBitmapSnapshot)
            {
                Image backimg = _vgVisualElem.BackingImage;
                drawBoard.DrawImage(backimg, new RectangleF(0, 0, backimg.Width, backimg.Height));
            }
            else
            {
                PixelFarm.CpuBlit.RectD bound = _vgVisualElem.GetRectBounds();
                //create
                PixelFarm.CpuBlit.MemBitmap backimg = new PixelFarm.CpuBlit.MemBitmap((int)bound.Width + 10, (int)bound.Height + 10);
#if DEBUG
                backimg._dbugNote = "cssBoxSvgRoot";
#endif
                PixelFarm.CpuBlit.AggPainter painter = PixelFarm.CpuBlit.AggPainter.Create(backimg);
                //TODO: review here
                //temp fix
                if (s_openfontTextService == null)
                {
                    s_openfontTextService = new OpenFontTextService();
                }


                //
                double prevStrokeW = painter.StrokeWidth;

                using (Tools.More.BorrowVgPaintArgs(painter, out VgPaintArgs paintArgs))
                {
                    if (_vgVisualElem.CoordTx != null)
                    {
                    }
                    _vgVisualElem.Paint(paintArgs);
                }

                painter.StrokeWidth = prevStrokeW;//restore
                //painter.FillColor = fillColor;////restore
#if DEBUG
                //test
                //PixelFarm.CpuBlit.Imaging.PngImageWriter.dbugSaveToPngFile(backimg, "d:\\WImageTest\\subimg1.png");
#endif
                _vgVisualElem.SetBitmapSnapshot(backimg, true);
                drawBoard.DrawImage(backimg, new RectangleF(0, 0, backimg.Width, backimg.Height));
            }
        }