Skip to content

Commit

Permalink
Imitate dolphin mipmap detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Venomalia committed Aug 24, 2022
1 parent 3bb82fd commit cc25707
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 16 deletions.
7 changes: 6 additions & 1 deletion TextureExtraction tool/Data/TextureExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class ExtractorOptions : Options
/// </summary>
public bool Force = false;

/// <summary>
/// Tries to Imitate dolphin mipmap detection.
/// </summary>
public bool DolphinMipDetection = true;

/// <summary>
/// Sorts the textures and removes unnecessary folders.
/// </summary>
Expand Down Expand Up @@ -350,7 +355,7 @@ private void Save(JUTTexture texture, in string subdirectory)
{
string path = GetFullSaveDirectory(subdirectory);
Directory.CreateDirectory(path);
tex[i].Save(Path.Combine(path, tex.GetDolphinTextureHash(i) + ".png"), System.Drawing.Imaging.ImageFormat.Png);
tex[i].Save(Path.Combine(path, tex.GetDolphinTextureHash(i, false, ((ExtractorOptions)Option).DolphinMipDetection) + ".png"), System.Drawing.Imaging.ImageFormat.Png);

//skip mips?
if (!((ExtractorOptions)Option).Mips) break;
Expand Down
10 changes: 10 additions & 0 deletions TextureExtraction tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ static void Main(string[] args)
options.Raw = ConsoleEx.WriteBoolPrint(ConsoleEx.ReadBool(false, ConsoleKey.T, ConsoleKey.F), "True", "\tFalse", ConsoleColor.Green, ConsoleColor.Red);
Console.WriteLine($"Tries to extract textures from unknown file formats, may cause errors. \tTrue or (False)");
options.Force = ConsoleEx.WriteBoolPrint(ConsoleEx.ReadBool(false, ConsoleKey.T, ConsoleKey.F), "True", "\tFalse", ConsoleColor.Green, ConsoleColor.Red);
Console.Write($"Tries to Imitate dolphin mipmap detection. \t(True) or False");
options.DolphinMipDetection = ConsoleEx.WriteBoolPrint(ConsoleEx.ReadBool(true, ConsoleKey.T, ConsoleKey.F), "True", "\tFalse", ConsoleColor.Green, ConsoleColor.Red);
Console.Write($"Clean up folder structure. \t(True) or False");
options.Cleanup = ConsoleEx.WriteBoolPrint(ConsoleEx.ReadBool(true, ConsoleKey.T, ConsoleKey.F), "True", "\tFalse", ConsoleColor.Green, ConsoleColor.Red);
Console.WriteLine($"High performance mode.(Multithreading) \t(True) or False");
Expand Down Expand Up @@ -203,9 +205,14 @@ static void Main(string[] args)
options.Cleanup = true;
break;
case "-cleanup:none":
case "-c:none":
case "-c:n":
options.Cleanup = false;
break;
case "-dolphinmipdetection":
case "-dm":
options.Cleanup = false;
break;
case "-tasks":
case "-t":
i++;
Expand Down Expand Up @@ -306,6 +313,7 @@ private static void PrintHelp()
Console.WriteLine("\tOption:\t -f -force\tTries to extract unknown files, may cause errors.");
Console.WriteLine("\tOption:\t -c -cleanup\tuses the default folder cleanup.");
Console.WriteLine("\tOption:\t -c:n -cleanup:none\tretains the original folder structure.");
Console.WriteLine("\tOption:\t -dmd -dolphinmipdetection\tTries to imitate dolphin mipmap detection.");
Console.WriteLine("\tOption:\t -t -tasks \"i\"\tsets the maximum number of concurrent tasks.");
Console.WriteLine($"\t\ti:\t integer that represents the maximum degree of parallelism. default:{options.Parallel.MaxDegreeOfParallelism}");
Console.WriteLine();
Expand Down Expand Up @@ -367,6 +375,8 @@ static void PrintOptions(TextureExtractor.ExtractorOptions options)
ConsoleEx.WriteBoolPrint(options.Raw, ConsoleColor.Green, ConsoleColor.Red);
Console.Write($"Force extract textures from unknown formats: ");
ConsoleEx.WriteBoolPrint(options.Force, ConsoleColor.Green, ConsoleColor.Red);
Console.Write($"Imitate dolphin mipmap detection: ");
ConsoleEx.WriteBoolPrint(options.DolphinMipDetection, ConsoleColor.Green, ConsoleColor.Red);
Console.Write($"Clean up folder structure: ");
ConsoleEx.WriteBoolPrint(options.Cleanup, ConsoleColor.Green, ConsoleColor.Red);
Console.Write($"High performance mode (Multithreading): ");
Expand Down
4 changes: 2 additions & 2 deletions TextureExtraction tool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.8.2.4")]
[assembly: AssemblyFileVersion("0.8.2.4")]
[assembly: AssemblyVersion("0.8.2.6")]
[assembly: AssemblyFileVersion("0.8.2.6")]
4 changes: 2 additions & 2 deletions lib/AuroraLip/Texture/Formats/HXTB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected override void Read(Stream stream)
stream.Seek(header_offset, SeekOrigin.Begin);
uint data_offset = stream.ReadUInt32(Endian.Big);
GXImageFormat format = (GXImageFormat)stream.ReadByte();
byte image_count = (byte)stream.ReadByte();
byte image_count = (byte)stream.ReadByte(); // max_LOD?
ushort unknown3 = stream.ReadUInt16(Endian.Big);
ushort width = stream.ReadUInt16(Endian.Big);
ushort height = stream.ReadUInt16(Endian.Big);
Expand Down Expand Up @@ -83,7 +83,7 @@ protected override void Read(Stream stream)
WrapT = GXWrapMode.CLAMP,
EnableEdgeLOD = false,
MinLOD = 0,
MaxLOD = 0
MaxLOD = image_count
};
Add(current);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/AuroraLip/Texture/Formats/NUTC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ protected override void Read(Stream stream)
ushort texturesCount = stream.ReadUInt16(Endian.Big);
stream.Position = 0x20;

if (FormatVersion != 32770)
Console.WriteLine("NUTC Version: " + FormatVersion);

for (int i = 0; i < texturesCount; i++)
{

Expand Down Expand Up @@ -84,7 +87,7 @@ protected override void Read(Stream stream)
WrapT = GXWrapMode.CLAMP,
EnableEdgeLOD = false,
MinLOD = 0,
MaxLOD = 0
MaxLOD = TotalImageCount-1
};
Add(current);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/AuroraLip/Texture/Formats/PTLG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected override void Read(Stream stream)
WrapT = GXWrapMode.CLAMP,
EnableEdgeLOD = false,
MinLOD = 0,
MaxLOD = 0
MaxLOD = Images-1
};
Add(current);

Expand Down
3 changes: 1 addition & 2 deletions lib/AuroraLip/Texture/Formats/REFT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ private void ReadREFTfile(Stream stream)
int Palettes = stream.ReadUInt16(Endian.Big);
uint PaletteSize = stream.ReadUInt32(Endian.Big);
byte images = (byte)stream.ReadByte();
if (images > 0) --images;
byte MinFilter = (byte)stream.ReadByte();
byte MaxFilter = (byte)stream.ReadByte();
byte Unknown2 = (byte)stream.ReadByte();
Expand All @@ -118,7 +117,7 @@ private void ReadREFTfile(Stream stream)
PaletteData = stream.Read((int)PaletteSize);
}
stream.Position = ImageAddress;
TexEntry current = new TexEntry(stream, PaletteData, Format, PaletteFormat, Palettes, ImageWidth, ImageHeight, images)
TexEntry current = new TexEntry(stream, PaletteData, Format, PaletteFormat, Palettes, ImageWidth, ImageHeight, images -1)
{
LODBias = LODBias,
MagnificationFilter = (GXFilterMode)MaxFilter,
Expand Down
2 changes: 1 addition & 1 deletion lib/AuroraLip/Texture/Formats/TEX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override void Read(Stream stream)
WrapT = GXWrapMode.CLAMP,
EnableEdgeLOD = false,
MinLOD = 0,
MaxLOD = 0
MaxLOD = MipMaps
};
Add(current);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/AuroraLip/Texture/Formats/TXTR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ protected override void Read(Stream stream)
PaletteFormat = (GXPaletteFormat)stream.ReadUInt32(Endian.Big);
int CWidth = stream.ReadUInt16(Endian.Big);
int CHeight = stream.ReadUInt16(Endian.Big);
ColorsCount = CHeight* CWidth;
palettedata = stream.Read(ColorsCount*2);
ColorsCount = CHeight * CWidth;
palettedata = stream.Read(ColorsCount * 2);
}

TexEntry current = new TexEntry(stream, palettedata, Format, PaletteFormat, ColorsCount, ImageWidth, ImageHeight, (int)Images-1)
TexEntry current = new TexEntry(stream, palettedata, Format, PaletteFormat, ColorsCount, ImageWidth, ImageHeight, (int)Images - 1)
{
LODBias = 0,
MagnificationFilter = GXFilterMode.Nearest,
Expand All @@ -52,7 +52,7 @@ protected override void Read(Stream stream)
WrapT = GXWrapMode.CLAMP,
EnableEdgeLOD = false,
MinLOD = 0,
MaxLOD = 0
MaxLOD = Images - 1
};
Add(current);
}
Expand Down
10 changes: 8 additions & 2 deletions lib/AuroraLip/Texture/J3D/TexEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,17 @@ public TexEntry(Bitmap Image, GXImageFormat ImageFormat = GXImageFormat.CMPR, GX
EnableEdgeLOD = EdgeLoD;
}

public string GetDolphinTextureHash(int mipmap = 0, bool UseTlut = false)
public string GetDolphinTextureHash(int mipmap = 0, bool UseTlut = false, bool DolphinMipDetection = true)
{
bool HasMips = this.Count != 1;
//dolphin seems to use the MaxLOD value to decide if it is a mipmap Texture.
//https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/VideoCommon/TextureInfo.cpp#L80
if (!HasMips && DolphinMipDetection)
HasMips = MaxLOD != 0;

return "tex1_" + this[0].Width + 'x' + this[0].Height + '_'
//Has mipmaps
+ (this.Count != 1
+ (HasMips
? "m_" : string.Empty)
// Hash
+ Hash.ToString("x").PadLeft(16, '0') + '_'
Expand Down

0 comments on commit cc25707

Please sign in to comment.