private static unsafe Bitmap SimpleRender2(byte[] data, Palette256 palette, Rectangle frameRect) { try { Bitmap bitmap = new Bitmap(frameRect.Width, frameRect.Height); BitmapData bitmapdata = bitmap.LockBits(frameRect, ImageLockMode.WriteOnly, bitmap.PixelFormat); for (int index1 = 0; index1 < frameRect.Height; ++index1) { byte *numPtr = (byte *)((int)(void *)bitmapdata.Scan0 + (int)index1 * bitmapdata.Stride); for (int index2 = 0; index2 < frameRect.Width; ++index2) { int index3 = (int)data[index1 * frameRect.Width + index2]; if (index3 > 0 && bitmapdata.PixelFormat == PixelFormat.Format32bppArgb) { numPtr[((int)index2 * 4)] = palette[index3].B; numPtr[index2 * 4 + 1] = palette[index3].G; numPtr[index2 * 4 + 2] = palette[index3].R; numPtr[index2 * 4 + 3] = palette[index3].A; } } } bitmap.UnlockBits(bitmapdata); return(bitmap); } catch (ArgumentException ex) { return(new Bitmap(1, 1)); } }
public static Palette256 FromArchive(string file, bool ignoreCase, DATArchive archive) { if (!archive.Contains(file, ignoreCase)) { return((Palette256)null); } return(Palette256.FromRawData(archive.ExtractFile(file, ignoreCase))); }
public static Bitmap RenderImage(EPFFrame epf, Palette256 palette) { if (epf.Width == 1 && epf.Height == 1) { return(new Bitmap(1, 1)); } return(DAGraphics.SimpleRender(epf.RawData, palette, new Rectangle(epf.Left, epf.Top, epf.Width, epf.Height))); }
private static Palette256 LoadPalette(Stream stream) { stream.Seek(0L, SeekOrigin.Begin); BinaryReader binaryReader = new BinaryReader(stream); Palette256 palette256 = new Palette256(); for (int index = 0; index < 256; ++index) { palette256.colors[index] = Color.FromArgb((int)binaryReader.ReadByte(), (int)binaryReader.ReadByte(), (int)binaryReader.ReadByte()); } return(palette256); }
public static Palette256 ApplyDye(Palette256 pal, int dye) { if (dye <= 0) { return(pal); } StreamReader streamReader = new StreamReader(Application.StartupPath + "\\color.tbl"); Color[,] colorArray = new Color[Convert.ToInt32(streamReader.ReadLine()), 6]; while (!streamReader.EndOfStream) { int int32_1 = Convert.ToInt32(streamReader.ReadLine()); for (int index = 0; index < 6; ++index) { string[] strArray = streamReader.ReadLine().Trim().Split(','); if (strArray.Length == 3) { int int32_2 = Convert.ToInt32(strArray[0]); int int32_3 = Convert.ToInt32(strArray[1]); int int32_4 = Convert.ToInt32(strArray[2]); if (int32_2 > (int)byte.MaxValue) { int32_2 -= (int)byte.MaxValue; } if (int32_3 > (int)byte.MaxValue) { int32_3 -= (int)byte.MaxValue; } if (int32_4 > (int)byte.MaxValue) { int32_4 -= (int)byte.MaxValue; } colorArray[int32_1, index] = Color.FromArgb((int)byte.MaxValue, int32_2, int32_3, int32_4); } } } streamReader.Close(); Palette256 palette256 = new Palette256(); for (int index = 0; index < 256; ++index) { palette256[index] = pal[index]; } palette256[98] = colorArray[dye, 0]; palette256[99] = colorArray[dye, 1]; palette256[100] = colorArray[dye, 2]; palette256[101] = colorArray[dye, 3]; palette256[102] = colorArray[dye, 4]; palette256[103] = colorArray[dye, 5]; return(palette256); }
public static Palette256 FromRawData(byte[] data) { return(Palette256.LoadPalette((Stream) new MemoryStream(data))); }
public static Palette256 FromFile(string file) { return(Palette256.LoadPalette((Stream) new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))); }
public int LoadPalettes(string pattern, string path) { string[] files = Directory.GetFiles(path, pattern + "*.PAL", SearchOption.TopDirectoryOnly); this.palettes.Clear(); foreach (string str in files) { if (Path.GetFileName(str).ToUpper().EndsWith(".PAL") && Path.GetFileName(str).ToUpper().StartsWith(pattern.ToUpper())) { this.palettes.Add(Convert.ToInt32(Path.GetFileNameWithoutExtension(str).Remove(0, pattern.Length)), Palette256.FromFile(str)); } } return(this.palettes.Count); }
public int LoadPalettes(string pattern, DATArchive archive) { this.palettes.Clear(); foreach (DATFileEntry file in archive.Files) { if (file.Name.Length == 11 && file.Name.ToUpper().EndsWith(".PAL") && file.Name.ToUpper().StartsWith(pattern.ToUpper())) { this.palettes.Add(Convert.ToInt32(Path.GetFileNameWithoutExtension(file.Name).Remove(0, pattern.Length)), Palette256.FromArchive(file.Name, archive)); } } return(this.palettes.Count); }