From 460af714b40996739435d715530213fbc819ae92 Mon Sep 17 00:00:00 2001 From: giroletm <112472361+giroletm@users.noreply.github.com> Date: Thu, 29 Jun 2023 21:11:54 +0200 Subject: [PATCH] Fixed RGBA8888 Loading issue --- ABStudio/FileFormats/PVR/PVRFile.cs | 13 +++++-------- ABStudio/FileFormats/ZSTREAM/ZSTREAMFile.cs | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/ABStudio/FileFormats/PVR/PVRFile.cs b/ABStudio/FileFormats/PVR/PVRFile.cs index 9691adf..fcf7434 100644 --- a/ABStudio/FileFormats/PVR/PVRFile.cs +++ b/ABStudio/FileFormats/PVR/PVRFile.cs @@ -24,6 +24,8 @@ public PVRFile(byte[] pvrData) tex = PVRTexLib.PVRTexLibCreateTextureFromData(dataPtr); if (ReferenceEquals(tex, null)) throw new Exception("Invalid PVR file."); + + Marshal.FreeHGlobal(dataPtr); } public PVRFile(Bitmap bmp, string format="r4g4b4a4") @@ -45,14 +47,6 @@ public PVRFile(Bitmap bmp, string format="r4g4b4a4") if (textureSize == 0) return; - /* - BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); - var length = bitmapData.Stride * bitmapData.Height; - byte[] bytes = new byte[length]; - Marshal.Copy(bitmapData.Scan0, bytes, 0, length); - bmp.UnlockBits(bitmapData); - */ - uint bytesPerPixel = PVRTexLib.PVRTexLibGetTextureBitsPerPixel(header) / 8U; // Number of pixel for this (2D) surface @@ -154,6 +148,9 @@ private IntPtr Transcode(ulong format) throw new Exception("Couldn't get duplicated PVR file header."); } + if (PVRTexLib.PVRTexLibGetTexturePixelFormat(newHeader) == format) + return newTex; + PVRTexLibTranscoderOptions options = new PVRTexLibTranscoderOptions(); options.SizeofStruct = 48; options.PixelFormat = format; diff --git a/ABStudio/FileFormats/ZSTREAM/ZSTREAMFile.cs b/ABStudio/FileFormats/ZSTREAM/ZSTREAMFile.cs index 7058dfa..b11d686 100644 --- a/ABStudio/FileFormats/ZSTREAM/ZSTREAMFile.cs +++ b/ABStudio/FileFormats/ZSTREAM/ZSTREAMFile.cs @@ -278,7 +278,7 @@ public Bitmap GetBitmap(string path) string fmt = ""; int n = 0x20; - while (streamData[n] != 0 || n == 0x28) { + while (streamData[n] != 0 && n < 0x28) { fmt += (char)streamData[n]; n++; }