public eGFX_ImagePlane(int x, int y, eGFX_ImagePlaneType IPT) { SizeX = x; SizeY = y; Type = IPT; switch (IPT) { case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_1BPP: Data = new byte[eGFX_CALCULATE_1BPP_BUFFER_ROW_BYTE_SIZE(x) * y]; break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_4BPP: Data = new byte[eGFX_CALCULATE_4BPP_BUFFER_ROW_BYTE_SIZE(x) * y]; break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_8BPP: Data = new byte[eGFX_CALCULATE_8BPP_BUFFER_ROW_BYTE_SIZE(x) * y]; break; } Clear(); }
private void BuildFontButton_Click(object sender, EventArgs e) { string OutputFontFolder = Path.GetFullPath(Path.Combine(OutputFolder.Text, FontBaseName.Text)); eGFX_ImagePlaneType IPT = (eGFX_ImagePlaneType)Enum.Parse(typeof(eGFX_ImagePlaneType), (string)ImagePlaneTypeCB.SelectedItem); MyGFX_Tools.FontBuilder(Generate_FontName(OutputFontFolder), IPT); PostMessage("Font Build Process Finished."); }
private void GenerateTT_FontData_Click(object sender, EventArgs e) { SelectedFont = new Font((String)FontComboBox.SelectedItem, (int)FontSize.Value, GraphicsUnit.Pixel); FontBaseName.Text = GenerateTT_FontName(); string TRH_String = (string)TrueTypeRenderingHint.SelectedItem; TextRenderingHint TRH = (TextRenderingHint)Enum.Parse(typeof(TextRenderingHint), TRH_String); string OutputFontFolder = Path.GetFullPath(Path.Combine(OutputFolder.Text, FontBaseName.Text)); MyGFX_Tools.InitFontFromTrueType(OutputFontFolder, SelectedFont, TRH); eGFX_ImagePlaneType IPT = (eGFX_ImagePlaneType)Enum.Parse(typeof(eGFX_ImagePlaneType), (string)ImagePlaneTypeCB.SelectedItem); MyGFX_Tools.FontBuilder(OutputFontFolder, IPT); PostMessage("Font Process Generation Complete"); }
public static string GetImagePlaneTypePrefix(eGFX_ImagePlaneType IPT) { String s; switch(IPT) { default: case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_1BPP: s = "_1BPP"; break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_4BPP: s = "_4BPP"; break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_8BPP: s = "_8BPP"; break; } return s; }
static public string GetImagePlaneTypePrefix(eGFX_ImagePlaneType IPT) { String s; switch (IPT) { default: case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_1BPP: s = "_1BPP"; break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_4BPP: s = "_4BPP"; break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_8BPP: s = "_8BPP"; break; } return(s); }
public eGFX_ImagePlane(int x, int y, eGFX_ImagePlaneType IPT) { SizeX = x; SizeY = y; Type = IPT; switch(IPT) { case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_1BPP: Data = new byte[eGFX_CALCULATE_1BPP_BUFFER_ROW_BYTE_SIZE(x) * y]; break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_4BPP: Data = new byte[eGFX_CALCULATE_4BPP_BUFFER_ROW_BYTE_SIZE(x) * y]; break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_8BPP: Data = new byte[eGFX_CALCULATE_8BPP_BUFFER_ROW_BYTE_SIZE(x) * y]; break; } Clear(); }
public void FontBuilder(String PathToFontFolder, eGFX_ImagePlaneType IPT) { if (MessagePost == null) { MessagePost += SelfMessagePost; } #region Read In Configuration FontBuilderConfig MyFontBuilderConfig; Serializer MyConfigSerializer = new Serializer(typeof(FontBuilderConfig)); StreamReader SxR = new StreamReader(Path.Combine(PathToFontFolder, "FontConfiguration.jsx")); MyFontBuilderConfig = (FontBuilderConfig)MyConfigSerializer.Deserialize(SxR); SxR.Close(); #endregion #region Translate Bitmaps String Code = ""; String Header = ""; String CodeOutput = ""; String HeaderOutput = ""; for (byte i = STARTING_ASCII_FONT_INDEX; i < ENDING_ASCII_FONT_INDEX; i++) { string FileName = MapASCII_CodeToString(i) + ".png"; TranslateImage(Path.Combine(PathToFontFolder, "SrcImages", FileName), ref Code, ref Header, MyFontBuilderConfig.CombinedOutputName + "_" + "FontElement_", IPT); CodeOutput += Code; } CodeOutput += "\r\n\r\n"; CodeOutput += "const eGFX_Font " + MyFontBuilderConfig.CombinedOutputName + " = { \r\n"; CodeOutput += "\t\t\t\t\t\t\t{\r\n"; for (byte i = STARTING_ASCII_FONT_INDEX; i < ENDING_ASCII_FONT_INDEX; i++) { CodeOutput += "\t\t\t\t\t\t\t\t(const eGFX_ImagePlane *)&" + MyFontBuilderConfig.CombinedOutputName + "_" + "FontElement_" + MapASCII_CodeToString(i); if (i != ENDING_ASCII_FONT_INDEX - 1) { CodeOutput += ",\r\n"; } else { CodeOutput += "\r\n"; } } CodeOutput += "\t\t\t\t\t\t\t},\r\n"; CodeOutput += "\t\t\t\t\t\t\t" + MyFontBuilderConfig.Ascent + ", //TT Metric : Ascent - Scaled up by 65536 (q15.16) \r\n"; CodeOutput += "\t\t\t\t\t\t\t" + MyFontBuilderConfig.Descent + ", //TT Metric : Descent - Scaled up by 65536 (q15.16)\r\n"; CodeOutput += "\t\t\t\t\t\t\t" + MyFontBuilderConfig.LineSpacing + ", //TT Metric : Linespacing -Scaled up by 65536 (q15,16)\r\n"; CodeOutput += "\t\t\t\t\t\t\t" + MyFontBuilderConfig.SpacesPerTab + ", //Spaces per tab\r\n"; CodeOutput += "\t\t\t\t\t\t\t" + MyFontBuilderConfig.InterCharacterSpacing + ", //InterCharacterSpacing\r\n"; CodeOutput += "\t\t\t\t\t\t\t{0,0} //Padding Bytes\r\n"; CodeOutput += "\t\t\t\t\t\t};\r\n"; HeaderOutput = "extern const eGFX_Font " + MyFontBuilderConfig.CombinedOutputName + ";\r\n\r\n"; #endregion #region Write Code Files if (MyFontBuilderConfig.CombinedOutputName == "" || MyFontBuilderConfig.CombinedOutputName == null) { MyFontBuilderConfig.CombinedOutputName = "MyFont"; } TextWriter CodeTW = new StreamWriter(Path.Combine(PathToFontFolder, MyFontBuilderConfig.CombinedOutputName + ".c")); TextWriter HeaderTW = new StreamWriter(Path.Combine(PathToFontFolder, MyFontBuilderConfig.CombinedOutputName + ".h")); CodeTW.Write("#include \"stdint.h\" \r\n"); CodeTW.Write("#include \"eGFX.h\" \r\n"); CodeTW.Write("#include \"" + MyFontBuilderConfig.CombinedOutputName + ".h\" \r\n"); HeaderTW.Write("#include \"eGFX.h\" \r\n\r\n"); HeaderTW.Write("#ifndef _" + MyFontBuilderConfig.CombinedOutputName.ToUpperInvariant() + "_H\r\n"); HeaderTW.Write("#define _" + MyFontBuilderConfig.CombinedOutputName.ToUpperInvariant() + "_H\r\n\r\n"); CodeTW.Write(CodeOutput); HeaderTW.Write(HeaderOutput); HeaderTW.WriteLine("#endif\r\n"); HeaderTW.Close(); CodeTW.Close(); #endregion }
public void GenerateSprites(String SpriteDirectory, eGFX_ImagePlaneType IPT) { string OutputBaseName; String Code = ""; String Header = ""; String CodeOutput = ""; String HeaderOutput = ""; String SpritePrefixName = "Sprite" + eGFX_ImagePlane.GetImagePlaneTypePrefix(IPT); OutputBaseName = Path.GetDirectoryName(Path.Combine(SpriteDirectory, "junk.txt")); if (Directory.Exists(SpriteDirectory) == false) { MessagePost(SpriteDirectory + " does not exist\r\n"); return; } MessagePost("Scanning " + SpriteDirectory + " for files"); string[] files = System.IO.Directory.GetFiles(SpriteDirectory, "*.png", System.IO.SearchOption.AllDirectories); if (files.Length == 0) { MessagePost("No image files specified in " + SpriteDirectory); return; } #region Translate Bitmaps for (int i = 0; i < files.Length; i++) { MessagePost("Translating " + files[i] + "\r\n"); TranslateImage(files[i], ref Code, ref Header, SpritePrefixName + "_", IPT); CodeOutput += Code; HeaderOutput += Header; } #endregion #region Write Code Files if (OutputBaseName == "" || OutputBaseName == null) { OutputBaseName = "Sprites"; } OutputBaseName += eGFX_ImagePlane.GetImagePlaneTypePrefix(IPT); TextWriter CodeTW = new StreamWriter(Path.Combine(SpriteDirectory, OutputBaseName) + ".c", false); TextWriter HeaderTW = new StreamWriter(Path.Combine(SpriteDirectory, OutputBaseName) + ".h", false); CodeTW.Write("#include \"stdint.h\" \r\n"); CodeTW.Write("#include \"eGFX.h\" \r\n"); CodeTW.Write("#include \"eGFX_DataTypes.h\" \r\n"); CodeTW.Write("#include \"" + OutputBaseName + ".h\" \r\n"); HeaderTW.Write("#include \"stdint.h\" \r\n"); HeaderTW.Write("#include \"eGFX.h\" \r\n\r\n"); HeaderTW.Write("#ifndef _" + OutputBaseName.ToUpperInvariant() + "_H\r\n"); HeaderTW.Write("#define _" + OutputBaseName.ToUpperInvariant() + "_H\r\n"); CodeTW.Write(CodeOutput); HeaderTW.Write(HeaderOutput); HeaderTW.WriteLine("\r\n#endif\r\n"); HeaderTW.Close(); CodeTW.Close(); #endregion MessagePost("\r\n\r\nAll Done!\r\n\r\n"); }
void TranslateImage(string ImageFileName, ref string CodeOutput, ref string HeaderOutput, string SpriteStructNamePrefix, eGFX_ImagePlaneType IPT) { CodeOutput = ""; HeaderOutput = ""; if (File.Exists(ImageFileName) == false) { MessagePost("Could not open " + ImageFileName); return; } Bitmap NextBmp = new Bitmap(ImageFileName); MessagePost(ImageFileName + " is " + NextBmp.Width + " x " + NextBmp.Height + " pixels"); string SpriteNameBase = Path.GetFileName(ImageFileName); string [] Splits = SpriteNameBase.Split('.'); string SpriteName = Splits[0]; #region Binary Sprite Form eGFX_ImagePlane NextSprite = new eGFX_ImagePlane(NextBmp.Width, NextBmp.Height, IPT); #region Gather Sprite Data for (int y = 0; y < NextBmp.Height; y++) { for (int x = 0; x < NextBmp.Width; x++) { Color PixelColor = NextBmp.GetPixel(x, y); UInt32 Y = (UInt32)((PixelColor.R * 0.299) + (PixelColor.G * 0.587) + (PixelColor.B * 0.114)); switch (NextSprite.Type) { case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_1BPP: if (Y > 0x7f) { NextSprite.PutPixel(x, y, 0xFFFFFFFF); //median cut } else { NextSprite.PutPixel(x, y, 0); } break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_4BPP: NextSprite.PutPixel(x, y, (Y) >> 4); //median cut break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_8BPP: NextSprite.PutPixel(x, y, Y); break; } } } #endregion string RawDataArrayString = SpriteStructNamePrefix + SpriteName + "_Data"; string SpriteStructNameString = SpriteStructNamePrefix + SpriteName; CodeOutput += "\r\n"; CodeOutput += "////***************************************************************************\r\n"; CodeOutput += "//// " + SpriteStructNameString + "\r\n"; CodeOutput += "////***************************************************************************\r\n"; HeaderOutput += "\r\n"; HeaderOutput += "////***************************************************************************\r\n"; HeaderOutput += "//// " + SpriteStructNameString + "\r\n"; HeaderOutput += "////***************************************************************************\r\n\r\n"; HeaderOutput += "\r\nextern const eGFX_ImagePlane \t" + SpriteStructNameString + ";\r\n"; CodeOutput += "\r\nconst uint8_t " + RawDataArrayString + "[" + NextSprite.Data.Length + "] = { "; for (int i = 0; i < NextSprite.Data.Length; i++) { if (i % 16 == 0) { CodeOutput += "\r\n"; } CodeOutput += "0x" + String.Format("{0:X2}", NextSprite.Data[i]); if (i == NextSprite.Data.Length - 1) { CodeOutput += " }; \r\n\r\n"; } else { CodeOutput += ","; } } CodeOutput += "const eGFX_ImagePlane " + SpriteStructNameString + " = { " + IPT.ToString() + ",(uint8_t *)&" + RawDataArrayString + ",(uint16_t)" + NextBmp.Width + ",(uint16_t)" + NextBmp.Height + "};\r\n"; #endregion MessagePost(CodeOutput); }
public void GenerateSprites(String SpriteDirectory,eGFX_ImagePlaneType IPT) { string OutputBaseName; String Code = ""; String Header = ""; String CodeOutput = ""; String HeaderOutput = ""; String SpritePrefixName = "Sprite" + eGFX_ImagePlane.GetImagePlaneTypePrefix(IPT); OutputBaseName = Path.GetDirectoryName(Path.Combine(SpriteDirectory,"junk.txt")); if (Directory.Exists(SpriteDirectory) == false) { MessagePost(SpriteDirectory + " does not exist\r\n"); return; } MessagePost("Scanning " + SpriteDirectory + " for files"); string[] files = System.IO.Directory.GetFiles(SpriteDirectory, "*.png", System.IO.SearchOption.AllDirectories); if(files.Length == 0) { MessagePost("No image files specified in " + SpriteDirectory); return; } #region Translate Bitmaps for (int i = 0; i < files.Length; i++) { MessagePost("Translating " + files[i] + "\r\n"); TranslateImage(files[i], ref Code, ref Header, SpritePrefixName+"_", IPT); CodeOutput += Code; HeaderOutput += Header; } #endregion #region Write Code Files if (OutputBaseName == "" || OutputBaseName == null) { OutputBaseName = "Sprites"; } OutputBaseName += eGFX_ImagePlane.GetImagePlaneTypePrefix(IPT); TextWriter CodeTW = new StreamWriter(Path.Combine(SpriteDirectory,OutputBaseName) + ".c",false); TextWriter HeaderTW = new StreamWriter(Path.Combine(SpriteDirectory, OutputBaseName) + ".h",false); CodeTW.Write("#include \"stdint.h\" \r\n"); CodeTW.Write("#include \"eGFX.h\" \r\n"); CodeTW.Write("#include \"eGFX_DataTypes.h\" \r\n"); CodeTW.Write("#include \"" + OutputBaseName + ".h\" \r\n"); HeaderTW.Write("#include \"stdint.h\" \r\n"); HeaderTW.Write("#include \"eGFX.h\" \r\n\r\n"); HeaderTW.Write("#ifndef _" + OutputBaseName.ToUpperInvariant() + "_H\r\n"); HeaderTW.Write("#define _" + OutputBaseName.ToUpperInvariant() + "_H\r\n"); CodeTW.Write(CodeOutput); HeaderTW.Write(HeaderOutput); HeaderTW.WriteLine("\r\n#endif\r\n"); HeaderTW.Close(); CodeTW.Close(); #endregion MessagePost("\r\n\r\nAll Done!\r\n\r\n"); }
public void FontBuilder(String PathToFontFolder, eGFX_ImagePlaneType IPT) { if (MessagePost == null) MessagePost += SelfMessagePost; #region Read In Configuration FontBuilderConfig MyFontBuilderConfig; Serializer MyConfigSerializer = new Serializer(typeof(FontBuilderConfig)); StreamReader SxR = new StreamReader(Path.Combine(PathToFontFolder, "FontConfiguration.jsx")); MyFontBuilderConfig = (FontBuilderConfig)MyConfigSerializer.Deserialize(SxR); SxR.Close(); #endregion #region Translate Bitmaps String Code =""; String Header = ""; String CodeOutput = ""; String HeaderOutput = ""; for (byte i = STARTING_ASCII_FONT_INDEX; i < ENDING_ASCII_FONT_INDEX; i++) { string FileName = MapASCII_CodeToString(i) + ".png"; TranslateImage(Path.Combine(PathToFontFolder, "SrcImages", FileName), ref Code, ref Header, MyFontBuilderConfig.CombinedOutputName+"_"+"FontElement_",IPT); CodeOutput += Code; } CodeOutput += "\r\n\r\n"; CodeOutput += "const eGFX_Font " + MyFontBuilderConfig.CombinedOutputName + " = { \r\n"; CodeOutput += "\t\t\t\t\t\t\t{\r\n"; for (byte i = STARTING_ASCII_FONT_INDEX; i < ENDING_ASCII_FONT_INDEX; i++) { CodeOutput += "\t\t\t\t\t\t\t\t(const eGFX_ImagePlane *)&" + MyFontBuilderConfig.CombinedOutputName + "_" + "FontElement_"+ MapASCII_CodeToString(i); if(i!= ENDING_ASCII_FONT_INDEX-1) { CodeOutput += ",\r\n"; } else { CodeOutput += "\r\n"; } } CodeOutput += "\t\t\t\t\t\t\t},\r\n"; CodeOutput += "\t\t\t\t\t\t\t" + MyFontBuilderConfig.Ascent+ ", //TT Metric : Ascent - Scaled up by 65536 (q15.16) \r\n"; CodeOutput += "\t\t\t\t\t\t\t" + MyFontBuilderConfig.Descent + ", //TT Metric : Descent - Scaled up by 65536 (q15.16)\r\n"; CodeOutput += "\t\t\t\t\t\t\t" + MyFontBuilderConfig.LineSpacing + ", //TT Metric : Linespacing -Scaled up by 65536 (q15,16)\r\n"; CodeOutput += "\t\t\t\t\t\t\t" + MyFontBuilderConfig.SpacesPerTab + ", //Spaces per tab\r\n"; CodeOutput += "\t\t\t\t\t\t\t" + MyFontBuilderConfig.InterCharacterSpacing + ", //InterCharacterSpacing\r\n"; CodeOutput += "\t\t\t\t\t\t\t{0,0} //Padding Bytes\r\n"; CodeOutput += "\t\t\t\t\t\t};\r\n"; HeaderOutput = "extern const eGFX_Font " + MyFontBuilderConfig.CombinedOutputName + ";\r\n\r\n"; #endregion #region Write Code Files if (MyFontBuilderConfig.CombinedOutputName == "" || MyFontBuilderConfig.CombinedOutputName == null) { MyFontBuilderConfig.CombinedOutputName = "MyFont"; } TextWriter CodeTW = new StreamWriter(Path.Combine(PathToFontFolder,MyFontBuilderConfig.CombinedOutputName + ".c")); TextWriter HeaderTW = new StreamWriter(Path.Combine(PathToFontFolder, MyFontBuilderConfig.CombinedOutputName + ".h")); CodeTW.Write("#include \"stdint.h\" \r\n"); CodeTW.Write("#include \"eGFX.h\" \r\n"); CodeTW.Write("#include \"" + MyFontBuilderConfig.CombinedOutputName + ".h\" \r\n"); HeaderTW.Write("#include \"eGFX.h\" \r\n\r\n"); HeaderTW.Write("#ifndef _" + MyFontBuilderConfig.CombinedOutputName.ToUpperInvariant() + "_H\r\n"); HeaderTW.Write("#define _" +MyFontBuilderConfig.CombinedOutputName.ToUpperInvariant() + "_H\r\n\r\n"); CodeTW.Write(CodeOutput); HeaderTW.Write(HeaderOutput); HeaderTW.WriteLine("#endif\r\n"); HeaderTW.Close(); CodeTW.Close(); #endregion }
void TranslateImage(string ImageFileName, ref string CodeOutput, ref string HeaderOutput,string SpriteStructNamePrefix, eGFX_ImagePlaneType IPT) { CodeOutput = ""; HeaderOutput = ""; if (File.Exists(ImageFileName) == false) { MessagePost("Could not open " + ImageFileName); return; } Bitmap NextBmp = new Bitmap(ImageFileName); MessagePost(ImageFileName + " is " + NextBmp.Width + " x " + NextBmp.Height + " pixels"); string SpriteNameBase = Path.GetFileName(ImageFileName); string [] Splits = SpriteNameBase.Split('.'); string SpriteName = Splits[0]; #region Binary Sprite Form eGFX_ImagePlane NextSprite = new eGFX_ImagePlane(NextBmp.Width, NextBmp.Height, IPT); #region Gather Sprite Data for (int y = 0; y < NextBmp.Height; y++) { for (int x = 0; x < NextBmp.Width; x++) { Color PixelColor = NextBmp.GetPixel(x, y); UInt32 Y = (UInt32)((PixelColor.R * 0.299) + (PixelColor.G * 0.587) + (PixelColor.B * 0.114)); switch(NextSprite.Type) { case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_1BPP: if (Y > 0x7f) { NextSprite.PutPixel(x, y, 0xFFFFFFFF); //median cut } else { NextSprite.PutPixel(x, y, 0); } break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_4BPP: NextSprite.PutPixel(x, y, (Y)>>4); //median cut break; case eGFX_ImagePlaneType.eGFX_IMAGE_PLANE_8BPP: NextSprite.PutPixel(x, y, Y); break; } } } #endregion string RawDataArrayString = SpriteStructNamePrefix + SpriteName + "_Data"; string SpriteStructNameString = SpriteStructNamePrefix + SpriteName; CodeOutput += "\r\n"; CodeOutput += "////***************************************************************************\r\n"; CodeOutput += "//// " +SpriteStructNameString+ "\r\n"; CodeOutput += "////***************************************************************************\r\n"; HeaderOutput += "\r\n"; HeaderOutput += "////***************************************************************************\r\n"; HeaderOutput += "//// " + SpriteStructNameString + "\r\n"; HeaderOutput += "////***************************************************************************\r\n\r\n"; HeaderOutput += "\r\nextern const eGFX_ImagePlane \t" + SpriteStructNameString + ";\r\n"; CodeOutput += "\r\nconst uint8_t " + RawDataArrayString + "[" + NextSprite.Data.Length + "] = { "; for(int i=0;i< NextSprite.Data.Length;i++) { if(i%16 == 0) { CodeOutput += "\r\n"; } CodeOutput += "0x" + String.Format("{0:X2}",NextSprite.Data[i]); if(i == NextSprite.Data.Length - 1) { CodeOutput += " }; \r\n\r\n"; } else { CodeOutput += ","; } } CodeOutput += "const eGFX_ImagePlane " + SpriteStructNameString + " = { " + IPT.ToString() + ",(uint8_t *)&" + RawDataArrayString + ",(uint16_t)" + NextBmp.Width + ",(uint16_t)" + NextBmp.Height + "};\r\n"; #endregion MessagePost(CodeOutput); }