public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0) { uint bpp = GetBytesPerPixel(Format); GTX.GX2Surface surf = new GTX.GX2Surface(); surf.bpp = bpp; surf.height = image.Height; surf.width = image.Width; surf.aa = (uint)GTX.GX2AAMode.GX2_AA_MODE_1X; surf.alignment = image.Alignment; surf.depth = 1; surf.dim = (uint)GTX.GX2SurfaceDimension.DIM_2D; surf.format = (uint)FTEX.ConvertToGx2Format(Format); surf.use = (uint)GTX.GX2SurfaceUse.USE_COLOR_BUFFER; surf.pitch = 0; surf.data = ImageData; surf.numMips = 1; surf.mipOffset = new uint[0]; surf.mipData = ImageData; surf.tileMode = (uint)GTX.GX2TileMode.MODE_2D_TILED_THIN1; surf.swizzle = image.swizzle; surf.numArray = 1; var surfaces = GTX.Decode(surf); return(surfaces[ArrayLevel][MipLevel]); }
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0) { Console.WriteLine(""); Console.WriteLine("// ----- GX2Surface Info ----- "); Console.WriteLine(" dim = " + surface.dim); Console.WriteLine(" width = " + surface.width); Console.WriteLine(" height = " + surface.height); Console.WriteLine(" depth = " + surface.depth); Console.WriteLine(" numMips = " + surface.numMips); Console.WriteLine(" format = " + surface.format); Console.WriteLine(" aa = " + surface.aa); Console.WriteLine(" use = " + surface.use); Console.WriteLine(" imageSize = " + surface.imageSize); Console.WriteLine(" mipSize = " + surface.mipSize); Console.WriteLine(" tileMode = " + surface.tileMode); Console.WriteLine(" swizzle = " + surface.swizzle); Console.WriteLine(" alignment = " + surface.alignment); Console.WriteLine(" pitch = " + surface.pitch); Console.WriteLine(" bits per pixel = " + (surface.bpp << 3)); Console.WriteLine(" bytes per pixel = " + surface.bpp); Console.WriteLine(" data size = " + surface.data.Length); Console.WriteLine(" mip size = " + surface.mipData.Length); Console.WriteLine(" realSize = " + surface.imageSize); var surfaces = GTX.Decode(surface); return(surfaces[ArrayLevel][MipLevel]); }
public void Read(Texture tex) { ImageKey = "Texture"; SelectedImageKey = "Texture"; Text = tex.Name; ChannelRed = tex.CompSelR; ChannelGreen = tex.CompSelG; ChannelBlue = tex.CompSelB; ChannelAlpha = tex.CompSelA; renderedTex.width = (int)tex.Width; renderedTex.height = (int)tex.Height; format = (int)tex.Format; int swizzle = (int)tex.Swizzle; int pitch = (int)tex.Pitch; uint bpp = GTX.surfaceGetBitsPerPixel((uint)format) >> 3; GTX.GX2Surface surf = new GTX.GX2Surface(); surf.bpp = bpp; for (int surfaceLevel = 0; surfaceLevel < tex.ArrayLength; surfaceLevel++) { } GTX.Decode(surf, tex.MipData); }
public void Read(Texture tex) { ImageKey = "Texture"; SelectedImageKey = "Texture"; Text = tex.Name; texture = tex; Width = tex.Width; Height = tex.Height; Format = ConvertFormat(tex.Format); format = (int)tex.Format; int swizzle = (int)tex.Swizzle; int pitch = (int)tex.Pitch; uint bpp = GTX.surfaceGetBitsPerPixel((uint)format) >> 3; GTX.GX2Surface surf = new GTX.GX2Surface(); surf.bpp = bpp; surf.height = tex.Height; surf.width = tex.Width; surf.aa = (uint)tex.AAMode; surf.alignment = tex.Alignment; surf.depth = tex.Depth; surf.dim = (uint)tex.Dim; surf.format = (uint)tex.Format; surf.use = (uint)tex.Use; surf.pitch = tex.Pitch; surf.data = tex.Data; surf.numMips = tex.MipCount; surf.mipOffset = tex.MipOffsets; surf.mipData = tex.MipData; surf.tileMode = (uint)tex.TileMode; surf.swizzle = tex.Swizzle; //Determine tex2 botw files to get mip maps string Tex1 = GetFilePath(); if (Tex1.Contains(".Tex1")) { string Tex2 = Tex1.Replace(".Tex1", ".Tex2"); Console.WriteLine(Tex2); if (System.IO.File.Exists(Tex2)) { ResFile resFile2 = new ResFile(new System.IO.MemoryStream( EveryFileExplorer.YAZ0.Decompress(Tex2))); if (resFile2.Textures.ContainsKey(tex.Name)) { surf.mipData = resFile2.Textures[tex.Name].MipData; surf.mipOffset = resFile2.Textures[tex.Name].MipOffsets; } } } if (surf.mipData == null) { surf.numMips = 1; } List <byte[]> mips = GTX.Decode(surf); Surfaces.Add(new Surface() { mipmaps = mips }); RenderableTex.LoadOpenGLTexture(this); }
private void ReadGx2(FileReader reader) { reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; header = new GTXHeader(); header.Read(reader); Console.WriteLine("header size " + header.HeaderSize); uint surfBlockType; uint dataBlockType; uint mipBlockType; if (header.MajorVersion == 6) { surfBlockType = 0x0A; dataBlockType = 0x0B; mipBlockType = 0x0C; } else if (header.MajorVersion == 7) { surfBlockType = 0x0B; dataBlockType = 0x0C; mipBlockType = 0x0D; } else { throw new Exception($"Unsupported GTX version {header.MajorVersion}"); } if (header.GpuVersion != 2) { throw new Exception($"Unsupported GPU version {header.GpuVersion}"); } reader.Position = header.HeaderSize; bool blockB = false; bool blockC = false; uint ImageInfo = 0; uint images = 0; while (reader.Position < reader.BaseStream.Length) { GTXDataBlock block = new GTXDataBlock(); block.Read(reader); blocks.Add(block); //Here we use "if" instead of "case" statements as types vary between versions if ((uint)block.BlockType == surfBlockType) { ImageInfo += 1; blockB = true; var surface = new SurfaceInfoParse(); surface.Read(new FileReader(block.data)); if (surface.numMips > 14) { throw new Exception($"Invalid number of mip maps {surface.numMips}!"); } TextureData textureData = new TextureData(); textureData.surface = surface; textureData.Text = "Texture" + ImageInfo; Nodes.Add(textureData); textures.Add(textureData); } else if ((uint)block.BlockType == dataBlockType) { images += 1; blockC = true; data.Add(block.data); } else if ((uint)block.BlockType == mipBlockType) { mipMaps.Add(block.data); } } if (textures.Count != data.Count) { throw new Exception($"Bad size! {textures.Count} {data.Count}"); } int curTex = 0; int curMip = 0; foreach (var node in Nodes) { TextureData tex = (TextureData)node; tex.surface.data = data[curTex]; tex.surface.bpp = GTX.surfaceGetBitsPerPixel(tex.surface.format) >> 3; Console.WriteLine(); if (tex.surface.numMips > 1) { tex.surface.mipData = mipMaps[curMip++]; } else { tex.surface.mipData = new byte[0]; } Console.WriteLine(""); Console.WriteLine("// ----- GX2Surface Info ----- "); Console.WriteLine(" dim = " + tex.surface.dim); Console.WriteLine(" width = " + tex.surface.width); Console.WriteLine(" height = " + tex.surface.height); Console.WriteLine(" depth = " + tex.surface.depth); Console.WriteLine(" numMips = " + tex.surface.numMips); Console.WriteLine(" format = " + tex.surface.format); Console.WriteLine(" aa = " + tex.surface.aa); Console.WriteLine(" use = " + tex.surface.use); Console.WriteLine(" imageSize = " + tex.surface.imageSize); Console.WriteLine(" mipSize = " + tex.surface.mipSize); Console.WriteLine(" tileMode = " + tex.surface.tileMode); Console.WriteLine(" swizzle = " + tex.surface.swizzle); Console.WriteLine(" alignment = " + tex.surface.alignment); Console.WriteLine(" pitch = " + tex.surface.pitch); Console.WriteLine(" bits per pixel = " + (tex.surface.bpp << 3)); Console.WriteLine(" bytes per pixel = " + tex.surface.bpp); Console.WriteLine(" data size = " + tex.surface.data.Length); Console.WriteLine(" mip size = " + tex.surface.mipData.Length); Console.WriteLine(" realSize = " + tex.surface.imageSize); List <byte[]> mips = GTX.Decode(tex.surface); tex.Surfaces.Add(new STGenericTexture.Surface() { mipmaps = mips }); tex.RenderableTex.LoadOpenGLTexture(tex); curTex++; } }