Beispiel #1
0
 public static void To24BitsTga(Bitmap bitmap, string path, SegaSaturnColor transparentColor = null)
 {
     using (Stream file = File.Create(path))
     {
         SegaSaturnImageConverter.To24BitsTga(bitmap, file, transparentColor);
     }
 }
Beispiel #2
0
 public static void To24BitsTga(SegaSaturnTexture texture, Stream output, SegaSaturnColor transparentColor = null)
 {
     using (Bitmap bmp = SegaSaturnImageConverter.ToBitmap(texture))
     {
         SegaSaturnImageConverter.To24BitsTga(bmp, output, transparentColor);
     }
 }
Beispiel #3
0
        public static SegaSaturnTexture LoadFromBitmap(Bitmap bitmap, SegaSaturnColor transparentColor = null)
        {
            if (bitmap == null)
            {
                return(null);
            }
            SegaSaturnTexture toReturn = new SegaSaturnTexture(bitmap.Width, bitmap.Height);

            using (BmpPixelSnoop tmp = new BmpPixelSnoop(bitmap))
            {
                for (int y = 0; y < tmp.Height; y++)
                {
                    for (int x = 0; x < tmp.Width; x++)
                    {
                        Color c = tmp.GetPixel(x, y);
                        if (c.A != 255 && transparentColor != null && transparentColor.A == 255)
                        {
                            c = transparentColor;
                        }
                        toReturn.SetPixel(x, y, c);
                    }
                }
            }
            return(toReturn);
        }
 public uint LoadTexture(string path, SegaSaturnColor transparentColor = null)
 {
     using (Bitmap bmp = SegaSaturnImageConverter.LoadBitmapFromFile(path, transparentColor))
     {
         BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
         uint       id         = Gl.GenTexture();
         Gl.BindTexture(TextureTarget.Texture2d, id);
         Gl.TexImage2D(TextureTarget.Texture2d, 0, InternalFormat.Rgb8, bmp.Width, bmp.Height, 0, OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, bitmapData.Scan0);
         bmp.UnlockBits(bitmapData);
         Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMaxLevel, 0);
         Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
         Gl.TexParameter(TextureTarget.Texture2d, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
         return(id);
     }
 }
 public static void ReplaceColor(this Bitmap img, SegaSaturnColor src, SegaSaturnColor dest)
 {
     using (BmpPixelSnoop tmp = new BmpPixelSnoop(img))
     {
         int srcColor = src.ToArgb();
         for (int y = 0; y < tmp.Height; ++y)
         {
             for (int x = 0; x < tmp.Width; ++x)
             {
                 if (tmp.GetPixel(x, y).ToArgb() == srcColor)
                 {
                     tmp.SetPixel(x, y, dest);
                 }
             }
         }
     }
 }
 public static bool ContainsColor(this Bitmap img, SegaSaturnColor toFind)
 {
     using (BmpPixelSnoop tmp = new BmpPixelSnoop(img))
     {
         for (int y = 0; y < tmp.Height; ++y)
         {
             for (int x = 0; x < tmp.Width; ++x)
             {
                 if (tmp.GetPixel(x, y) == toFind)
                 {
                     return(true);
                 }
             }
         }
         return(true);
     }
 }
 public static bool IsTransparent(this Bitmap img, SegaSaturnColor transparentColor)
 {
     using (BmpPixelSnoop tmp = new BmpPixelSnoop(img))
     {
         int tc = transparentColor.ToArgb();
         for (int y = 0; y < tmp.Height; ++y)
         {
             for (int x = 0; x < tmp.Width; ++x)
             {
                 Color c = tmp.GetPixel(x, y);
                 if (c.A > 0 || c.ToArgb() == tc)
                 {
                     return(false);
                 }
             }
         }
         return(true);
     }
 }
Beispiel #8
0
 public static void To24BitsTga(Bitmap bitmap, Stream output, SegaSaturnColor transparentColor = null)
 {
     using (BinaryWriter writer = new BinaryWriter(output))
     {
         using (BmpPixelSnoop tmp = new BmpPixelSnoop(bitmap))
         {
             writer.Write(new byte[]
             {
                 0, // ID length
                 0, // no color map
                 2, // uncompressed, true color
                 0, 0, 0, 0,
                 0,
                 0, 0, 0, 0, // x and y origin
                 (byte)(tmp.Width & 0x00FF),
                 (byte)((tmp.Width & 0xFF00) >> 8),
                 (byte)(tmp.Height & 0x00FF),
                 (byte)((tmp.Height & 0xFF00) >> 8),
                 24, // 24 bit bitmap
                 0
             });
             for (int y = 0; y < tmp.Height; y++)
             {
                 for (int x = 0; x < tmp.Width; x++)
                 {
                     Color c = tmp.GetPixel(x, tmp.Height - y - 1);
                     if (c.A != 255 && transparentColor != null && transparentColor.A == 255)
                     {
                         c = transparentColor;
                     }
                     writer.Write(new[]
                     {
                         c.B,
                         c.G,
                         c.R
                     });
                 }
             }
         }
     }
 }
Beispiel #9
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);
        }
Beispiel #10
0
        public static Bitmap LoadBitmapFromFile(string path, SegaSaturnColor transparentColor = null)
        {
            if (Path.GetExtension(path).ToLowerInvariant() == ".bin")
            {
                using (Stream stream = File.Open(path, FileMode.Open))
                {
                    using (BinaryReader streamReader = new BinaryReader(stream))
                    {
                        Bitmap bin = new Bitmap(streamReader.ReadUInt16(), streamReader.ReadUInt16(), PixelFormat.Format32bppArgb);
                        using (BmpPixelSnoop tmp = new BmpPixelSnoop(bin))
                        {
                            for (int y = 0; y < tmp.Height; ++y)
                            {
                                for (int x = 0; x < tmp.Width; ++x)
                                {
                                    tmp.SetPixel(x, y, new SegaSaturnColor(streamReader.ReadUInt16()));
                                }
                            }
                        }
                        return(bin);
                    }
                }
            }
            if (Path.GetExtension(path).ToLowerInvariant() == ".tga")
            {
                Bitmap tga = TargaImage.LoadTargaImage(path);
                if (transparentColor != null)
                {
                    tga.ReplaceColor(transparentColor, Color.Transparent);
                }
                return(tga);
            }
            Bitmap bitmap = (Bitmap)Bitmap.FromFile(path);

            if (transparentColor != null)
            {
                bitmap.ReplaceColor(transparentColor, Color.Transparent);
            }
            return(bitmap);
        }
Beispiel #11
0
 public static void ToPng(SegaSaturnTexture texture, string path, SegaSaturnColor transparentColor = null)
 {
     SegaSaturnImageConverter.ToBitmap(texture, transparentColor).Save(path, ImageFormat.Png);
 }
Beispiel #12
0
 public static SegaSaturnTexture LoadTextureFromFile(string path, SegaSaturnColor transparentColor = null)
 {
     return(SegaSaturnImageConverter.LoadFromBitmap(SegaSaturnImageConverter.LoadBitmapFromFile(path), transparentColor));
 }