From c0542d0e941079f5711a3097ea43aca95b3b211d Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Tue, 9 Aug 2022 22:12:40 +0200 Subject: [PATCH] Fix some texture stuff. --- Penumbra/Import/Dds/DdsFile.cs | 26 ------------------- Penumbra/Import/Dds/ImageParsing.cs | 4 +-- Penumbra/Import/Dds/TextureImporter.cs | 14 +++------- Penumbra/UI/Classes/ModEditWindow.Textures.cs | 11 -------- 4 files changed, 6 insertions(+), 49 deletions(-) diff --git a/Penumbra/Import/Dds/DdsFile.cs b/Penumbra/Import/Dds/DdsFile.cs index f9eca15f..c8ad8cab 100644 --- a/Penumbra/Import/Dds/DdsFile.cs +++ b/Penumbra/Import/Dds/DdsFile.cs @@ -224,30 +224,4 @@ public class DdsFile _ => throw new ArgumentOutOfRangeException( nameof( type ), type, null ), }; } -} - -public class TmpTexFile -{ - public TexFile.TexHeader Header; - public byte[] RgbaData = Array.Empty< byte >(); - - public void Load( BinaryReader br ) - { - Header = br.ReadStructure< TexFile.TexHeader >(); - var data = br.ReadBytes( ( int )( br.BaseStream.Length - br.BaseStream.Position ) ); - RgbaData = Header.Format switch - { - TexFile.TextureFormat.L8 => ImageParsing.DecodeUncompressedGreyscale( data, Header.Height, Header.Width ), - TexFile.TextureFormat.A8 => ImageParsing.DecodeUncompressedGreyscale( data, Header.Height, Header.Width ), - TexFile.TextureFormat.DXT1 => ImageParsing.DecodeDxt1( data, Header.Height, Header.Width ), - TexFile.TextureFormat.DXT3 => ImageParsing.DecodeDxt3( data, Header.Height, Header.Width ), - TexFile.TextureFormat.DXT5 => ImageParsing.DecodeDxt5( data, Header.Height, Header.Width ), - TexFile.TextureFormat.B8G8R8A8 => ImageParsing.DecodeUncompressedB8G8R8A8( data, Header.Height, Header.Width ), - TexFile.TextureFormat.B8G8R8X8 => ImageParsing.DecodeUncompressedR8G8B8A8( data, Header.Height, Header.Width ), - //TexFile.TextureFormat.A8R8G8B82 => ImageParsing.DecodeUncompressedR8G8B8A8( data, Header.Height, Header.Width ), - TexFile.TextureFormat.B4G4R4A4 => ImageParsing.DecodeUncompressedR4G4B4A4( data, Header.Height, Header.Width ), - TexFile.TextureFormat.B5G5R5A1 => ImageParsing.DecodeUncompressedR5G5B5A1( data, Header.Height, Header.Width ), - _ => throw new ArgumentOutOfRangeException(), - }; - } } \ No newline at end of file diff --git a/Penumbra/Import/Dds/ImageParsing.cs b/Penumbra/Import/Dds/ImageParsing.cs index c3bdd482..5170448e 100644 --- a/Penumbra/Import/Dds/ImageParsing.cs +++ b/Penumbra/Import/Dds/ImageParsing.cs @@ -12,9 +12,9 @@ public static partial class ImageParsing { var ret = new Rgba32 { - R = ( byte )( c & 0x1F ), + R = ( byte )( c >> 11 ), G = ( byte )( ( c >> 5 ) & 0x3F ), - B = ( byte )( c >> 11 ), + B = ( byte )( c & 0x1F ), A = 0xFF, }; diff --git a/Penumbra/Import/Dds/TextureImporter.cs b/Penumbra/Import/Dds/TextureImporter.cs index 8a194999..1c71f526 100644 --- a/Penumbra/Import/Dds/TextureImporter.cs +++ b/Penumbra/Import/Dds/TextureImporter.cs @@ -1,8 +1,10 @@ using System; using System.IO; using Lumina.Data.Files; +using OtterGui; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; +using Functions = Penumbra.GameData.Util.Functions; namespace Penumbra.Import.Dds; @@ -13,7 +15,7 @@ public class TextureImporter using var mem = new MemoryStream( target ); using var bw = new BinaryWriter( mem ); bw.Write( ( uint )TexFile.Attribute.TextureType2D ); - bw.Write( ( uint )TexFile.TextureFormat.B8G8R8X8 ); + bw.Write( ( uint )TexFile.TextureFormat.B8G8R8A8 ); bw.Write( ( ushort )width ); bw.Write( ( ushort )height ); bw.Write( ( ushort )1 ); @@ -71,15 +73,7 @@ public class TextureImporter texData = new byte[80 + width * height * 4]; WriteHeader( texData, width, height ); - // RGBA to BGRA. - for( var i = 0; i < rgba.Length; i += 4 ) - { - texData[ 80 + i + 0 ] = rgba[ i + 2 ]; - texData[ 80 + i + 1 ] = rgba[ i + 1 ]; - texData[ 80 + i + 2 ] = rgba[ i + 0 ]; - texData[ 80 + i + 3 ] = rgba[ i + 3 ]; - } - + rgba.CopyTo( texData.AsSpan( 80 ) ); return true; } diff --git a/Penumbra/UI/Classes/ModEditWindow.Textures.cs b/Penumbra/UI/Classes/ModEditWindow.Textures.cs index 4b8f9d7f..b0c77058 100644 --- a/Penumbra/UI/Classes/ModEditWindow.Textures.cs +++ b/Penumbra/UI/Classes/ModEditWindow.Textures.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Numerics; -using System.Reflection; using System.Threading.Tasks; using Dalamud.Interface; using Dalamud.Interface.ImGuiFileDialog; @@ -165,16 +164,6 @@ public partial class ModEditWindow { try { - if( fromDisk ) - { - var tmp = new TmpTexFile(); - using var stream = File.OpenRead( path ); - using var br = new BinaryReader( stream ); - tmp.Load(br); - return (tmp.RgbaData, tmp.Header.Width, tmp.Header.Height); - } - - var tex = fromDisk ? Dalamud.GameData.GameData.GetFileFromDisk< TexFile >( path ) : Dalamud.GameData.GetFile< TexFile >( path ); if( tex == null ) {