public void Import(Color[] RawData, uint pwidth, uint pheight, BlockFormats format, bool Mip) { byte[] Index = new byte[] { }; Color[] Palette = new Color[] { }; byte[] MipIndex = new byte[] { }; ARGB2INDEX(RawData, ref Index, ref Palette); Flip(ref Index, (ushort)pwidth, (ushort)pheight); Swizzle(ref Index, (ushort)pwidth, (ushort)pheight); SwapPalette(ref Palette); if (Mip) { GenerateMips(Index, pwidth, pheight, ref MipIndex); } System.IO.MemoryStream Data = new System.IO.MemoryStream(); System.IO.MemoryStream Header = new System.IO.MemoryStream(); MakeInterleave(ref Data, Index, Palette, MipIndex, format); FormHeader(ref Header, format); System.IO.MemoryStream NewStream = new System.IO.MemoryStream(); System.IO.BinaryWriter NSWriter = new System.IO.BinaryWriter(NewStream); NSWriter.Write(Header.ToArray()); NSWriter.Write(Data.ToArray()); ByteStream = NewStream; System.IO.FileStream File = new System.IO.FileStream(@"C:\N", System.IO.FileMode.Create, System.IO.FileAccess.Write); System.IO.BinaryWriter Writer = new System.IO.BinaryWriter(File); Writer.Write(ByteStream.ToArray()); Writer.Close(); File.Close(); Size = (uint)ByteStream.Length; DataUpdate(); }
internal void MakeInterleave(ref System.IO.MemoryStream Data, byte[] Index, Color[] Palette, byte[] MipIndex, BlockFormats Format) { BlockFormat[][] fmt = new BlockFormat[][] { }; InitFMT(ref fmt); Data = new System.IO.MemoryStream(); System.IO.BinaryWriter DWriter = new System.IO.BinaryWriter(Data); uint ind_offset = 0; uint mip_offset = 0; uint pal_offset = 0; var format_ind = (int)Format; for (int i = 0; i <= fmt[format_ind].Length - 1; i++) { for (int j = 0; j <= fmt[format_ind][i].Index - 1; j++) { DWriter.Write(Index[j + ind_offset]); } for (int j = 0; j <= fmt[format_ind][i].Mip - 1; j++) { DWriter.Write(MipIndex[j + mip_offset]); } for (int j = 0; j <= fmt[format_ind][i].Palette / 4 - 1; j++) { DWriter.Write(Palette[j + pal_offset].R); DWriter.Write(Palette[j + pal_offset].G); DWriter.Write(Palette[j + pal_offset].B); DWriter.Write(Palette[j + pal_offset].A); } for (int j = 0; j <= fmt[format_ind][i].Space - 1; j++) { DWriter.Write(System.Convert.ToByte(255)); } ind_offset += fmt[format_ind][i].Index; mip_offset += fmt[format_ind][i].Mip; pal_offset += (uint)fmt[format_ind][i].Palette / 4; } }
internal void FormHeader(ref System.IO.MemoryStream Header, BlockFormats fmt) { Header = new System.IO.MemoryStream(228); System.IO.BinaryWriter DWriter = new System.IO.BinaryWriter(Header); Header.Position = 0; switch (fmt) { case BlockFormats.fmt128x256: { DWriter.Write(Resources._128x256); break; } case BlockFormats.fmt128x128: { DWriter.Write(Resources._128x128); break; } case BlockFormats.fmt128x128mip: { DWriter.Write(Resources._128x128mip); break; } case BlockFormats.fmt128x64: { break; } case BlockFormats.fmt128x64mip: { DWriter.Write(Resources._128x64mip); break; } case BlockFormats.fmt128x32: { break; } case BlockFormats.fmt128x32mip: { DWriter.Write(Resources._128x32mip); break; } case BlockFormats.fmt64x64: { DWriter.Write(Resources._64x64); break; } case BlockFormats.fmt64x64mip: { DWriter.Write(Resources._64x64mip); break; } case BlockFormats.fmt64x32: { break; } case BlockFormats.fmt64x32mip: { DWriter.Write(Resources._64x32mip); break; } case BlockFormats.fmt32x64: { DWriter.Write(Resources._32x64); break; } case BlockFormats.fmt32x64mip: { DWriter.Write(Resources._32x64mip); break; } case BlockFormats.fmt32x32: { break; } case BlockFormats.fmt32x32mip: { DWriter.Write(Resources._32x32mip); break; } case BlockFormats.fmt32x16: { break; } case BlockFormats.fmt32x16mip: { DWriter.Write(Resources._32x16mip); break; } case BlockFormats.fmt32x8: { DWriter.Write(Resources._32x8); break; } case BlockFormats.fmt16x16: { break; } case BlockFormats.fmt16x16mip: { DWriter.Write(Resources._16x16mip); break; } } }