public static int[] ConvertToIntBmp(Msdfgen.FloatRGBBmp input) { int height = input.Height; int width = input.Width; int[] output = new int[input.Width * input.Height]; for (int y = height - 1; y >= 0; --y) { for (int x = 0; x < width; ++x) { //a b g r //---------------------------------- Msdfgen.FloatRGB pixel = input.GetPixel(x, y); //a b g r int abgr = (255 << 24) | (Msdfgen.Vector2.Clamp((int)(pixel.b * 0x100), 0xff) << 16) | (Msdfgen.Vector2.Clamp((int)(pixel.g * 0x100), 0xff) << 8) | Msdfgen.Vector2.Clamp((int)(pixel.r * 0x100), 0xff); output[(y * width) + x] = abgr; //---------------------------------- /**it++ = clamp(int(bitmap(x, y).r*0x100), 0xff); * it++ = clamp(int(bitmap(x, y).g*0x100), 0xff); * it++ = clamp(int(bitmap(x, y).b*0x100), 0xff);*/ } } return(output); }
public static GlyphImage CreateMsdfImage( this MsdfGlyphGen msdfGlyphGen, GlyphPointF[] glyphPoints, ushort[] contourEndPoints, float pxScale = 1) { // create msdf shape , then convert to actual image Msdfgen.Shape shape = msdfGlyphGen.CreateMsdfShape(glyphPoints, contourEndPoints, pxScale); double left, bottom, right, top; shape.findBounds(out left, out bottom, out right, out top); int w = (int)Math.Ceiling((right - left)); int h = (int)Math.Ceiling((top - bottom)); if (w < 5) { w = 5; } if (h < 5) { h = 5; } Msdfgen.FloatRGBBmp frgbBmp = new Msdfgen.FloatRGBBmp(w, h); Msdfgen.EdgeColoring.edgeColoringSimple(shape, 3); Msdfgen.MsdfGenerator.generateMSDF(frgbBmp, shape, 4, new Msdfgen.Vector2(1, 1), new Msdfgen.Vector2(), -1); //----------------------------------- int[] buffer = Msdfgen.MsdfGenerator.ConvertToIntBmp(frgbBmp); GlyphImage img = new Typography.Rendering.GlyphImage(w, h); img.SetImageBuffer(buffer, false); return(img); }
public static GlyphImage CreateMsdfImage(Msdfgen.Shape shape) { double left, bottom, right, top; shape.findBounds(out left, out bottom, out right, out top); int w = (int)Math.Ceiling((right - left)); int h = (int)Math.Ceiling((top - bottom)); if (w < 5) { w = 5; } if (h < 5) { h = 5; } int borderW = (int)((float)w / 5f); var translate = new Msdfgen.Vector2(left < 0 ? -left + borderW : borderW, bottom < 0 ? -bottom + borderW : borderW); w += borderW * 2; //borders,left- right h += borderW * 2; //borders, top- bottom Msdfgen.FloatRGBBmp frgbBmp = new Msdfgen.FloatRGBBmp(w, h); Msdfgen.EdgeColoring.edgeColoringSimple(shape, 3); Msdfgen.MsdfGenerator.generateMSDF(frgbBmp, shape, 4, new Msdfgen.Vector2(1, 1), //scale translate, //translate to positive quadrant -1); //----------------------------------- int[] buffer = Msdfgen.MsdfGenerator.ConvertToIntBmp(frgbBmp); GlyphImage img = new GlyphImage(w, h); img.TextureOffsetX = translate.x; img.TextureOffsetY = translate.y; img.SetImageBuffer(buffer, false); return(img); }
private void button10_Click(object sender, EventArgs e) { //-------------------------------------------- Msdfgen.Shape shape = new Msdfgen.Shape(); Msdfgen.Contour contour = new Msdfgen.Contour(); //contour.AddLine(10, 10, 25, 25); //contour.AddLine(25, 25, 15, 10); //contour.AddLine(15, 10, 10, 10); contour.AddLine(10, 10, 25, 25); contour.AddQuadraticSegment(25, 25, 15, 30, 10, 15); contour.AddLine(10, 15, 10, 10); shape.contours.Add(contour); //-+--------------------------- double left, bottom, right, top; shape.findBounds(out left, out bottom, out right, out top); Msdfgen.FloatRGBBmp frgbBmp = new Msdfgen.FloatRGBBmp((int)Math.Ceiling((right - left)), (int)Math.Ceiling((top - bottom))); double edgeThreshold = 1.00000001;//use default double angleThreshold = 1; shape.InverseYAxis = true; Msdfgen.EdgeColoring.edgeColoringSimple(shape, 3); Msdfgen.MsdfGenerator.generateMSDF(frgbBmp, shape, 4, new Msdfgen.Vector2(1, 1), new Msdfgen.Vector2(), -1); int[] buffer = Msdfgen.MsdfGenerator.ConvertToIntBmp(frgbBmp); //MsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer); using (Bitmap bmp = new Bitmap(frgbBmp.Width, frgbBmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, frgbBmp.Width, frgbBmp.Height), 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_.png"); } }
public static GlyphImage CreateMsdfImage(Msdfgen.Shape shape, MsdfGenParams genParams) { double left, bottom, right, top; shape.findBounds(out left, out bottom, out right, out top); int w = (int)Math.Ceiling((right - left)); int h = (int)Math.Ceiling((top - bottom)); if (w < genParams.minImgWidth) { w = genParams.minImgWidth; } if (h < genParams.minImgHeight) { h = genParams.minImgHeight; } //temp, for debug with glyph 'I', tahoma font //double edgeThreshold = 1.00000001;//default, if edgeThreshold < 0 then set edgeThreshold=1 //Msdfgen.Vector2 scale = new Msdfgen.Vector2(0.98714652956298199, 0.98714652956298199); //double pxRange = 4; //translate = new Msdfgen.Vector2(12.552083333333332, 4.0520833333333330); //double range = pxRange / Math.Min(scale.x, scale.y); int borderW = (int)((float)w / 5f); var translate = new Msdfgen.Vector2(left < 0 ? -left + borderW : borderW, bottom < 0 ? -bottom + borderW : borderW); w += borderW * 2; //borders,left- right h += borderW * 2; //borders, top- bottom double edgeThreshold = genParams.edgeThreshold; if (edgeThreshold < 0) { edgeThreshold = 1.00000001; //use default if edgeThreshold <0 } var scale = new Msdfgen.Vector2(genParams.scaleX, genParams.scaleY); //scale double range = genParams.pxRange / Math.Min(scale.x, scale.y); //--------- Msdfgen.FloatRGBBmp frgbBmp = new Msdfgen.FloatRGBBmp(w, h); Msdfgen.EdgeColoring.edgeColoringSimple(shape, genParams.angleThreshold); Msdfgen.MsdfGenerator.generateMSDF(frgbBmp, shape, range, scale, translate,//translate to positive quadrant edgeThreshold); //----------------------------------- int[] buffer = Msdfgen.MsdfGenerator.ConvertToIntBmp(frgbBmp); GlyphImage img = new GlyphImage(w, h); img.TextureOffsetX = (short)translate.x; img.TextureOffsetY = (short)translate.y; img.SetImageBuffer(buffer, false); return(img); }