Skip to content

Commit

Permalink
Change mipmap handling again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Sep 23, 2022
1 parent cadaafb commit 3158d3d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
37 changes: 26 additions & 11 deletions Penumbra/Import/Textures/TexFileParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static ScratchImage Parse( Stream data )
throw new Exception( $"Could not obtain dimensionality from {header.Type}." );
}

meta.MipLevels = CountMipLevels( data, in header );
meta.MipLevels = CountMipLevels( data, in meta, in header );

var scratch = ScratchImage.Initialize( meta );

Expand All @@ -33,23 +33,38 @@ public static ScratchImage Parse( Stream data )
return scratch;
}

private static unsafe int CountMipLevels( Stream data, in TexFile.TexHeader header )
private static unsafe int CountMipLevels( Stream data, in TexMeta meta, in TexFile.TexHeader header )
{
var lastOffset = 80u;
var levels = 1;
for( var i = 1; i < 13; ++i )
var width = meta.Width;
var height = meta.Height;
var bits = meta.Format.BitsPerPixel();

var lastOffset = 0L;
var lastSize = 80L;
for( var i = 0; i < 13; ++i )
{
var offset = header.OffsetToSurface[ i ];
var diff = offset - lastOffset;
if( offset > 0 && offset < data.Length && diff > 0 )
if( offset == 0 )
{
return i;
}

var requiredSize = width * height * bits / 8;
if( offset + requiredSize > data.Length )
{
lastOffset = offset;
++levels;
return i;
}
else

var diff = offset - lastOffset;
if( diff != lastSize )
{
return levels;
return i;
}

width = Math.Max( width / 2, 4 );
height = Math.Max( height / 2, 4 );
lastOffset = offset;
lastSize = requiredSize;
}

return 13;
Expand Down
12 changes: 10 additions & 2 deletions Penumbra/UI/Classes/ModEditWindow.Textures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ private void DrawInputChild( string label, Texture tex, Vector2 size, Vector2 im
}

ImGui.NewLine();
tex.Draw( imageSize );
using var child2 = ImRaii.Child( "image" );
if( child2 )
{
tex.Draw( imageSize );
}
}

private void SaveAsCombo()
Expand Down Expand Up @@ -157,7 +161,11 @@ private void DrawOutputChild( Vector2 size, Vector2 imageSize )
ImGuiUtil.TextWrapped( _center.SaveException.ToString() );
}

_center.Draw( imageSize );
using var child2 = ImRaii.Child( "image" );
if( child2 )
{
_center.Draw( imageSize );
}
}

private Vector2 GetChildWidth()
Expand Down

0 comments on commit 3158d3d

Please sign in to comment.