mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-01-03 14:23:43 +01:00
Handle weird mip map/size inconsistencies, maybe?
This commit is contained in:
parent
daaee4feb6
commit
5c81970558
1 changed files with 25 additions and 0 deletions
|
|
@ -24,12 +24,37 @@ public static class TexFileParser
|
|||
throw new Exception( $"Could not obtain dimensionality from {header.Type}." );
|
||||
}
|
||||
|
||||
meta.MipLevels = CountMipLevels( data, in header );
|
||||
|
||||
var scratch = ScratchImage.Initialize( meta );
|
||||
|
||||
CopyData( scratch, r );
|
||||
|
||||
return scratch;
|
||||
}
|
||||
|
||||
private static unsafe int CountMipLevels( Stream data, in TexFile.TexHeader header )
|
||||
{
|
||||
var lastOffset = 80u;
|
||||
var levels = 1;
|
||||
for( var i = 1; i < 13; ++i )
|
||||
{
|
||||
var offset = header.OffsetToSurface[ i ];
|
||||
var diff = offset - lastOffset;
|
||||
if( offset > 0 && offset < data.Length && diff > 0 )
|
||||
{
|
||||
lastOffset = offset;
|
||||
++levels;
|
||||
}
|
||||
else
|
||||
{
|
||||
return levels;
|
||||
}
|
||||
}
|
||||
|
||||
return 13;
|
||||
}
|
||||
|
||||
private static unsafe void CopyData( ScratchImage image, BinaryReader r )
|
||||
{
|
||||
fixed( byte* ptr = image.Pixels )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue