public static void ToBinFile(SegaSaturnTexture texture, Stream outputStream, bool header) { using (BinaryWriter writer = new BinaryWriter(outputStream)) { if (header) { writer.Write((ushort)texture.Image.Width); writer.Write((ushort)texture.Image.Height); } using (Bitmap tmp = new Bitmap(texture.Image)) { for (int y = 0; y < tmp.Height; ++y) { for (int x = 0; x < tmp.Width; ++x) { writer.Write(SegaSaturnColor.ConvertToSegaSaturn(tmp.GetPixel(x, y))); } } } } }
public static SegaSaturnTexture ConvertFrom(Bitmap image, string name, SegaSaturnTextureCoordinates p1, SegaSaturnTextureCoordinates p2, SegaSaturnTextureCoordinates p3, SegaSaturnTextureCoordinates p4, bool isTriangleMapping) { SegaSaturnTexture toReturn = new SegaSaturnTexture { Name = name, Hash = String.Format("{0}¤{1}¤{2}¤{3}", p1.Hash, p2.Hash, p3.Hash, p4.Hash) }; Rectangle rect = SegaSaturnTexture.GetRectangleFromTextureCoordinates(p1, p2, p3, p4); if (!isTriangleMapping) { toReturn.Image = JoMapEditorTools.CropBitmap(image, rect); } else { List <IntPoint> corners = new List <IntPoint>(); corners.Add(new IntPoint(p1.X, p1.Y)); corners.Add(new IntPoint(p2.X, p2.Y)); corners.Add(new IntPoint(p3.X, p3.Y)); corners.Add(new IntPoint(p4.X, p4.Y)); SimpleQuadrilateralTransformation filter = new SimpleQuadrilateralTransformation(corners, rect.Width, rect.Height); toReturn.Image = filter.Apply(image); } if ((toReturn.Image.Width % 8) == 0) { toReturn.Image = toReturn.Image; } else { int width = (toReturn.Image.Width / 8) * 8; if (width <= 0) { width = 8; } toReturn.Image = JoMapEditorTools.ResizeImage(toReturn.Image, width, image.Height); } return(toReturn); }
public static string ToSourceFile(SegaSaturnTexture texture, bool preprocessorInclusionProtection) { if (String.IsNullOrWhiteSpace(texture.Name)) { texture.Name = "Unnamed"; } StringBuilder sb = new StringBuilder(); if (preprocessorInclusionProtection) { #region Header sb.AppendLine("/*"); sb.AppendLine(String.Format(" Hardcoded image generated by {0}", Editor.Instance.Text)); sb.AppendLine("*/"); sb.AppendLine(); sb.AppendLine(String.Format("#ifndef __SPRITE{0}_H__", texture.Name.ToUpperInvariant())); sb.AppendLine(String.Format("# define __SPRITE{0}_H__", texture.Name.ToUpperInvariant())); sb.AppendLine(); #endregion } #region Bytes sb.AppendLine(String.Format("static const unsigned short SpriteData{0}[] = {{", texture.Name)); bool isFirstPixel = true; using (Bitmap tmp = new Bitmap(texture.Image)) { for (int y = 0; y < tmp.Height; ++y) { for (int x = 0; x < tmp.Width; ++x) { if (!isFirstPixel) { sb.Append(','); } sb.Append(SegaSaturnColor.ConvertToHexString(tmp.GetPixel(x, y))); isFirstPixel = false; } sb.AppendLine(); } } sb.AppendLine("};"); sb.AppendLine(); #endregion #region jo_img sb.AppendLine(String.Format("const jo_img Sprite{0} = {{", texture.Name)); sb.AppendLine(String.Format(" .width = {0},", texture.Image.Width)); sb.AppendLine(String.Format(" .height = {0},", texture.Image.Height)); sb.AppendLine(String.Format(" .data = (unsigned short *)SpriteData{0}", texture.Name)); sb.AppendLine("};"); sb.AppendLine(); #endregion if (preprocessorInclusionProtection) { #region Footer sb.AppendLine(String.Format("#endif /* !__SPRITE{0}_H__ */", texture.Name.ToUpperInvariant())); #endregion } return(sb.ToString()); }