From c358f512300ac913973fd4647eb34880d4da02c2 Mon Sep 17 00:00:00 2001 From: UlyssesWu Date: Fri, 15 Sep 2023 18:44:10 +0800 Subject: [PATCH] Set PS3 to use big endian for `RGBA8_SW` #113 #87 only works with `-dci` (PsbDecompile) for now --- .gitignore | 1 + FreeMote.PsBuild/PsbDecompiler.cs | 1 + FreeMote/FreeMoteExtension.cs | 20 +++++++++++++++++--- FreeMote/PsbEnums.cs | 6 +++++- FreeMote/RL.cs | 14 +++++++++++++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 4eb6fa7..0c85cd0 100644 --- a/.gitignore +++ b/.gitignore @@ -256,3 +256,4 @@ paket-files/ /MigrationBackup /bak +/.vscode diff --git a/FreeMote.PsBuild/PsbDecompiler.cs b/FreeMote.PsBuild/PsbDecompiler.cs index 440fc55..9c16154 100644 --- a/FreeMote.PsBuild/PsbDecompiler.cs +++ b/FreeMote.PsBuild/PsbDecompiler.cs @@ -9,6 +9,7 @@ using FreeMote.Psb.Types; using Newtonsoft.Json; using System.Collections.Concurrent; +using System.Diagnostics; using System.IO.MemoryMappedFiles; using System.Text.RegularExpressions; using System.Threading.Tasks; diff --git a/FreeMote/FreeMoteExtension.cs b/FreeMote/FreeMoteExtension.cs index 05f250c..1560ff8 100644 --- a/FreeMote/FreeMoteExtension.cs +++ b/FreeMote/FreeMoteExtension.cs @@ -129,6 +129,7 @@ public static bool UseBigEndian(this PsbSpec spec) case PsbSpec.ems: case PsbSpec.vita: //TODO: is vita or psp BigEndian? case PsbSpec.psp: + case PsbSpec.ps3: //TODO: is ps3 BigEndian? return true; default: return false; @@ -318,9 +319,21 @@ public static PsbPixelFormat ToPsbPixelFormat(this string typeStr, PsbSpec spec) else return PsbPixelFormat.LeRGBA8; case "RGBA8_SW": - return useTile - ? (spec.UseBigEndian() ? PsbPixelFormat.TileBeRGBA8_SW : PsbPixelFormat.TileLeRGBA8_SW) - : (spec.UseBigEndian() ? PsbPixelFormat.BeRGBA8_SW : spec == PsbSpec.ps3? PsbPixelFormat.FlipLeRGBA8_SW : PsbPixelFormat.LeRGBA8_SW); + if (useTile) + if (spec.UseBigEndian()) + return PsbPixelFormat.TileBeRGBA8_SW; + else + return PsbPixelFormat.TileLeRGBA8_SW; + + if (spec.UseBigEndian()) + if (spec == PsbSpec.ps3) + return PsbPixelFormat.FlipBeRGBA8_SW; + else + return PsbPixelFormat.BeRGBA8_SW; + + if (spec == PsbSpec.ps3) + return PsbPixelFormat.FlipLeRGBA8_SW; + return PsbPixelFormat.LeRGBA8_SW; case "A8_SW": return useTile ? PsbPixelFormat.TileA8_SW : PsbPixelFormat.A8_SW; case "L8_SW": @@ -356,6 +369,7 @@ public static string ToStringForPsb(this PsbPixelFormat pixelFormat) case PsbPixelFormat.TileBeRGBA8_SW: case PsbPixelFormat.TileLeRGBA8_SW: case PsbPixelFormat.FlipLeRGBA8_SW: + case PsbPixelFormat.FlipBeRGBA8_SW: return "RGBA8_SW"; case PsbPixelFormat.TileA8L8_SW: case PsbPixelFormat.A8L8_SW: diff --git a/FreeMote/PsbEnums.cs b/FreeMote/PsbEnums.cs index e55b4d8..6a249c4 100644 --- a/FreeMote/PsbEnums.cs +++ b/FreeMote/PsbEnums.cs @@ -212,10 +212,14 @@ public enum PsbPixelFormat /// LeRGBA8_SW, /// - /// LeRGBA8_SW (Swizzle, Flip) for PS3 + /// LeRGBA8_SW (Swizzle, Flip) for PS3? /// FlipLeRGBA8_SW, /// + /// BeRGBA8_SW (Swizzle, Flip) for PS3 + /// + FlipBeRGBA8_SW, + /// /// LeRGBA8_SW (Swizzle, Tile) for PS4 /// TileLeRGBA8_SW, diff --git a/FreeMote/RL.cs b/FreeMote/RL.cs index 84e0a95..4b6d7e4 100644 --- a/FreeMote/RL.cs +++ b/FreeMote/RL.cs @@ -81,6 +81,12 @@ public static Bitmap ConvertToImage(byte[] data, int width, int height, data = PostProcessing.UnswizzleTexture(data, bmp.Width, bmp.Height, bmp.PixelFormat); data = PostProcessing.FlipTexturePs3(data, width, height, bmp.PixelFormat); break; + case PsbPixelFormat.FlipBeRGBA8_SW: + data = PostProcessing.UnswizzleTexture(data, bmp.Width, bmp.Height, bmp.PixelFormat); + data = PostProcessing.FlipTexturePs3(data, width, height, bmp.PixelFormat); + Switch_0_2(ref data); + Argb2Rgba(ref data, true); + break; case PsbPixelFormat.LeRGBA4444_SW: data = Argb428(data); //Rgba2Argb(ref data); @@ -224,6 +230,12 @@ private static byte[] PixelBytesFromImage(Bitmap bmp, PsbPixelFormat pixelFormat result = PostProcessing.FlipTexturePs3(result, bmp.Width, bmp.Height, bmp.PixelFormat); result = PostProcessing.SwizzleTexture(result, bmp.Width, bmp.Height, bmp.PixelFormat); break; + case PsbPixelFormat.FlipBeRGBA8_SW: + result = PostProcessing.FlipTexturePs3(result, bmp.Width, bmp.Height, bmp.PixelFormat); + result = PostProcessing.SwizzleTexture(result, bmp.Width, bmp.Height, bmp.PixelFormat); + Argb2Rgba(ref result); + Switch_0_2(ref result); + break; case PsbPixelFormat.TileLeRGBA8_SW: result = PostProcessing.TileTexture(result, bmp.Width, bmp.Height, bmp.PixelFormat); break; @@ -511,7 +523,7 @@ public static unsafe void Switch_0_2(ref byte[] bytes) /// RGBA(BE) -> ARGB(LE BGRA) (switch A) /// /// - /// + /// false: ROR; true: ROL public static unsafe void Argb2Rgba(ref byte[] bytes, bool reverse = false) { //Actually bgra -> abgr