private static byte[] StitchMap(Map map) { byte[] defaultSegFile = File.ReadAllBytes(map.DefaultSegment.Filename); Bitmap defaultSeg = new MtxtTexture(new DataBuffer(defaultSegFile, Game.XBX, 0)).ToBitmap(); using (var bitmap = new Bitmap(map.Width * 256, map.Height * 256, PixelFormat.Format32bppArgb)) using (Graphics img = Graphics.FromImage(bitmap)) { for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { img.DrawImage(defaultSeg, x * 256, y * 256); } } foreach (Segment seg in map.Segments) { byte[] segFile = File.ReadAllBytes(seg.Filename); var segmentTex = new MtxtTexture(new DataBuffer(segFile, Game.XBX, 0)); Bitmap segBitmap = segmentTex.ToBitmap(); img.DrawImage(segBitmap, seg.X * 256, seg.Y * 256); } return(bitmap.ToPng()); } }
public static void Deswizzle(MtxtTexture texture, int bppPower) { uint bpp = (uint)(1 << bppPower); uint bypp = bpp / 8; uint pipeSwizzle = (uint)((texture.Swizzle >> 8) & 1); uint bankSwizzle = (uint)((texture.Swizzle >> 9) & 3); int len = texture.Data.Length; uint originWidth = (uint)((texture.Width + 3) / 4); int originHeight = (texture.Height + 3) / 4; var result = new byte[len]; uint posOut = 0; for (uint y = 0; y < originHeight; y++) { for (uint x = 0; x < originWidth; x++) { uint pos = (uint)AddrLib_computeSurfaceAddrFromCoordMacroTiled(x, y, bpp, (uint)texture.Pitch, (uint)texture.Height, (uint)texture.TileMode, pipeSwizzle, bankSwizzle); if (posOut + bypp <= len && pos + bypp <= len) { Array.Copy(texture.Data, pos, result, posOut, bypp); } posOut += bypp; } } texture.Data = result; }
public static void ReadMtxt(DataBuffer file, string name, string outDir) { var texture = new MtxtTexture(file); byte[] png = texture.ToPng(); if (png == null) { Console.WriteLine($"{texture.Format} decoding not implemented. Converting to DDS."); throw new NotImplementedException("Just kidding. Not yet."); } File.WriteAllBytes(Path.Combine(outDir, name + ".png"), png); }