Ejemplo n.º 1
0
 public static void ToBin(SegaSaturnTexture texture, Stream outputStream, bool header)
 {
     using (BinaryWriter writer = new BinaryWriter(outputStream))
     {
         if (header)
         {
             writer.Write((ushort)texture.Width);
             writer.Write((ushort)texture.Height);
         }
         for (int y = 0; y < texture.Height; y += texture.Width)
         {
             for (int x = 0; x < texture.Width; ++x)
             {
                 writer.Write(texture.GetPixel(x, y).SaturnColor);
             }
         }
     }
 }
Ejemplo n.º 2
0
        public static Bitmap ToBitmap(SegaSaturnTexture texture, SegaSaturnColor transparentColor = null)
        {
            if (texture == null)
            {
                return(null);
            }
            Bitmap toReturn = new Bitmap(texture.Width, texture.Height, PixelFormat.Format32bppArgb);

            using (BmpPixelSnoop tmp = new BmpPixelSnoop(toReturn))
            {
                for (int y = 0; y < tmp.Height; y++)
                {
                    for (int x = 0; x < tmp.Width; x++)
                    {
                        SegaSaturnColor color = texture.GetPixel(x, y);
                        toReturn.SetPixel(x, y, transparentColor != null && color == transparentColor ? Color.Transparent : (Color)color);
                    }
                }
            }
            return(toReturn);
        }
Ejemplo n.º 3
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("   3D Hardcoded image generated by SegaSaturn.NET.Converter");
                sb.AppendLine("*/");
                sb.AppendLine();
                sb.AppendLine($"#ifndef __SPRITE{texture.Name.ToUpperInvariant()}_H__");
                sb.AppendLine($"# define __SPRITE{texture.Name.ToUpperInvariant()}_H__");
                sb.AppendLine();

                #endregion
            }

            #region Bytes

            sb.AppendLine($"static const unsigned short    SpriteData{texture.Name}[] = {{");
            bool isFirstPixel = true;

            for (int y = 0; y < texture.Height; ++y)
            {
                for (int x = 0; x < texture.Width; ++x)
                {
                    if (!isFirstPixel)
                    {
                        sb.Append(',');
                    }
                    sb.Append(texture.GetPixel(x, y).SaturnHexaString);
                    isFirstPixel = false;
                }
                sb.AppendLine();
            }

            sb.AppendLine("};");
            sb.AppendLine();

            #endregion

            #region jo_img

            sb.AppendLine($"const jo_img               Sprite{texture.Name} = {{");
            sb.AppendLine($"   .width = {texture.Width},");
            sb.AppendLine($"   .height = {texture.Height},");
            sb.AppendLine($"   .data = (unsigned short *)SpriteData{texture.Name}");
            sb.AppendLine("};");
            sb.AppendLine();

            #endregion

            if (preprocessorInclusionProtection)
            {
                #region Footer

                sb.AppendLine($"#endif /* !__SPRITE{texture.Name.ToUpperInvariant()}_H__ */");

                #endregion
            }

            return(sb.ToString());
        }