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 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); } }
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 }); } } } } }
public static void ToBin(Bitmap bmp, Stream outputStream, bool header) { using (BinaryWriter writer = new BinaryWriter(outputStream)) { if (header) { writer.Write((ushort)bmp.Width); writer.Write((ushort)bmp.Height); } using (BmpPixelSnoop tmp = new BmpPixelSnoop(bmp)) { for (int y = 0; y < tmp.Height; ++y) { for (int x = 0; x < tmp.Width; ++x) { writer.Write(new SegaSaturnColor(tmp.GetPixel(x, y)).SaturnColor); } } } } }