public override void RenderTo(Image destImg, int srcX, int srcYy, int srcW, int srcH) { //render back buffer to target image unsafe { CpuBlit.MemBitmap memBmp = destImg as CpuBlit.MemBitmap; if (memBmp != null) { CpuBlit.Imaging.TempMemPtr tmpPtr = CpuBlit.MemBitmap.GetBufferPtr(memBmp); byte *head = (byte *)tmpPtr.Ptr; _gdigsx.RenderTo(head); tmpPtr.Dispose(); } } }
/// <summary> /// we STORE membitmap inside this rgn, /// </summary> /// <param name="bmp"></param> public BitmapBasedRegion(CpuBlit.MemBitmap bmp) { _bmp = bmp; _bounds = new Rectangle(0, 0, _bmp.Width, _bmp.Height); }
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(); } }
public void DrawString(char[] textBuffer, int startAt, int len, double x, double y) { //TODO: review performance _memdc.PatBlt(Win32.NativeWin32MemoryDC.PatBltColor.White, 0, 0, _bmpWidth, _bmpHeight); _memdc.TextOut(textBuffer); //memdc.BitBltTo(destHdc); // Win32.Win32Utils.BitBlt(hdc, 0, 0, bmpWidth, 50, memHdc, 0, 0, Win32.MyWin32.SRCCOPY); //--------------- int stride = 4 * ((_bmpWidth * 32 + 31) / 32); //Bitmap newBmp = new Bitmap(bmpWidth, 50, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //var bmpData = newBmp.LockBits(new Rectangle(0, 0, bmpWidth, 50), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); byte[] tmp1 = new byte[stride * 50]; System.Runtime.InteropServices.Marshal.Copy(_memdc.PPVBits, tmp1, 0, tmp1.Length); //--------------- int pos = 3; for (int r = 0; r < 50; ++r) { for (int c = 0; c < stride; ++c) { tmp1[pos] = 255; pos += 4; c += 4; } } _memdc.MeasureTextSize(textBuffer, out _bmpWidth, out _bmpHeight); var memBmp = new CpuBlit.MemBitmap(_bmpWidth, _bmpHeight); #if DEBUG memBmp._dbugNote = "WinGdiFontPrinter.DrawString"; #endif //------------------------------------------------------ //copy bmp from specific bmp area //and convert to GLBmp unsafe { using (CpuBlit.Imaging.TempMemPtr.FromBmp(memBmp, out byte *dest0)) { byte *header = (byte *)_memdc.PPVBits; { byte *dest = dest0; byte *rowHead = header; int rowLen = _bmpWidth * 4; for (int h = 0; h < _bmpHeight; ++h) { header = rowHead; for (int n = 0; n < rowLen;) { //move next *(dest + 0) = *(header + 0); *(dest + 1) = *(header + 1); *(dest + 2) = *(header + 2); //*(dest + 3) = *(header + 3); *(dest + 3) = 255; header += 4; dest += 4; n += 4; } //finish one row rowHead += stride; } } } } //------------------------------------------------------ GLBitmap glBmp = new GLBitmap(new MemBitmapBinder(memBmp, false)); _pcx.DrawImage(glBmp, (float)x, (float)y); glBmp.Dispose(); }