Exemplo n.º 1
0
 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)));
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        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());
        }