// Token: 0x06000021 RID: 33 RVA: 0x00003448 File Offset: 0x00002048 public void Write(StreamHelper streamHelper) { streamHelper.Write <int>(this.Length, ByteEncoding.None); streamHelper.Write <int>(this.Dummy, ByteEncoding.None); streamHelper.Write <int>(this.Dummy, ByteEncoding.None); streamHelper.Write <short>(this.Width, ByteEncoding.None); streamHelper.Write <short>(this.Height, ByteEncoding.None); this.PrepareColors(); int num = (this.Length - 16) / 4; if (num <= 16) { for (int i = 0; i < this.Colors.Count; i++) { PaletteBlock.WriteColor(streamHelper, this.Colors[i]); } return; } int num2 = 0; for (int j = 0; j < num / 8 / 4; j++) { List <Color> colorBlock = this.GetColorBlock(num2++); List <Color> colorBlock2 = this.GetColorBlock(num2++); List <Color> colorBlock3 = this.GetColorBlock(num2++); List <Color> colorBlock4 = this.GetColorBlock(num2++); this.WriteColorList(streamHelper, colorBlock); this.WriteColorList(streamHelper, colorBlock3); this.WriteColorList(streamHelper, colorBlock2); this.WriteColorList(streamHelper, colorBlock4); } }
// Token: 0x0600001F RID: 31 RVA: 0x00003304 File Offset: 0x00001F04 private void WriteColorList(StreamHelper streamHelper, List <Color> colorList) { foreach (Color color in colorList) { PaletteBlock.WriteColor(streamHelper, color); } }
// Token: 0x06000020 RID: 32 RVA: 0x00003354 File Offset: 0x00001F54 public static PaletteBlock Read(StreamHelper streamHelper) { PaletteBlock paletteBlock = new PaletteBlock(); paletteBlock.Length = streamHelper.ReadInt32(ByteEncoding.None); paletteBlock.Dummy = streamHelper.ReadInt32(ByteEncoding.None); paletteBlock.Dummy2 = streamHelper.ReadInt32(ByteEncoding.None); paletteBlock.Width = streamHelper.ReadInt16(ByteEncoding.None); paletteBlock.Height = streamHelper.ReadInt16(ByteEncoding.None); paletteBlock.Colors = new List <Color>(); int num = (paletteBlock.Length - 16) / 4; if (num <= 16) { for (int i = 0; i < num; i++) { paletteBlock.Colors.Add(PaletteBlock.ReadColor(streamHelper)); } } else { for (int j = 0; j < num / 8 / 4; j++) { List <Color> collection = PaletteBlock.ReadColorBlock(streamHelper); List <Color> collection2 = PaletteBlock.ReadColorBlock(streamHelper); List <Color> collection3 = PaletteBlock.ReadColorBlock(streamHelper); List <Color> collection4 = PaletteBlock.ReadColorBlock(streamHelper); paletteBlock.Colors.AddRange(collection); paletteBlock.Colors.AddRange(collection3); paletteBlock.Colors.AddRange(collection2); paletteBlock.Colors.AddRange(collection4); } } return(paletteBlock); }
// Token: 0x0600001D RID: 29 RVA: 0x000032BC File Offset: 0x00001EBC private static List <Color> ReadColorBlock(StreamHelper streamHelper) { List <Color> list = new List <Color>(8); for (int i = 0; i < 8; i++) { list.Add(PaletteBlock.ReadColor(streamHelper)); } return(list); }
// Token: 0x06000041 RID: 65 RVA: 0x00003D64 File Offset: 0x00002964 public void SetImage(Bitmap bitmap) { TextureBlock textureBlock = this.TextureBlocks.FirstOrDefault <TextureBlock>(); PaletteBlock paletteBlock = this.PaletteBlocks.FirstOrDefault <PaletteBlock>(); Bitmap bitmap2 = MedianCut.Quantize(bitmap, paletteBlock.Colors.Count); List <Color> allColors = MedianCut.GetAllColors(bitmap2); Dictionary <Color, int> dictionary = new Dictionary <Color, int>(); foreach (Color key in allColors) { if (!dictionary.ContainsKey(key)) { dictionary.Add(key, dictionary.Count); } } paletteBlock.Colors = dictionary.Keys.ToList <Color>(); textureBlock.ApplyBitmapData(bitmap2, dictionary); }
// Token: 0x06000040 RID: 64 RVA: 0x00003CE8 File Offset: 0x000028E8 public Bitmap GetImage(TextureBlock textureBlock = null, PaletteBlock paletteBlock = null) { if (textureBlock == null) { textureBlock = this.TextureBlocks.FirstOrDefault <TextureBlock>(); } if (paletteBlock == null) { paletteBlock = this.PaletteBlocks.FirstOrDefault <PaletteBlock>(); } Bitmap bitmap = new Bitmap((int)textureBlock.Width, (int)textureBlock.Height, PixelFormat.Format32bppArgb); Dictionary <int, Color> dictionary = new Dictionary <int, Color>(); for (int i = 0; i < paletteBlock.Colors.Count; i++) { dictionary.Add(i, paletteBlock.Colors[i]); } textureBlock.ApplyTextureData(bitmap, dictionary); return(bitmap); }
// Token: 0x0600003E RID: 62 RVA: 0x00003B2C File Offset: 0x0000272C public static TM2 ReadBinary(string fileName) { TM2 tm = new TM2(); using (StreamHelper streamHelper = new StreamHelper(fileName, ByteEncoding.Little, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read)) { tm.Header = Header.Read(streamHelper); tm.PaletteBlocks = new List <PaletteBlock>(); tm.TextureBlocks = new List <TextureBlock>(); for (int i = 0; i < (int)tm.Header.CountPalette; i++) { tm.PaletteBlocks.Add(PaletteBlock.Read(streamHelper)); } for (int j = 0; j < (int)tm.Header.CountTextures; j++) { tm.TextureBlocks.Add(TextureBlock.Read(streamHelper)); } } return(tm); }