Skip to content

Commit

Permalink
Fixed RGBA8888 Loading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
giroletm committed Jun 29, 2023
1 parent dc3aa9c commit 460af71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions ABStudio/FileFormats/PVR/PVRFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ABStudio/FileFormats/ZSTREAM/ZSTREAMFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down

0 comments on commit 460af71

Please sign in to comment.