Skip to content

Commit

Permalink
Set PS3 to use big endian for RGBA8_SW #113 #87
Browse files Browse the repository at this point in the history
only works with `-dci` (PsbDecompile) for now
  • Loading branch information
UlyssesWu committed Sep 15, 2023
1 parent bebe8dd commit c358f51
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,4 @@ paket-files/

/MigrationBackup
/bak
/.vscode
1 change: 1 addition & 0 deletions FreeMote.PsBuild/PsbDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 17 additions & 3 deletions FreeMote/FreeMoteExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion FreeMote/PsbEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,14 @@ public enum PsbPixelFormat
/// </summary>
LeRGBA8_SW,
/// <summary>
/// LeRGBA8_SW (Swizzle, Flip) for PS3
/// LeRGBA8_SW (Swizzle, Flip) for PS3?
/// </summary>
FlipLeRGBA8_SW,
/// <summary>
/// BeRGBA8_SW (Swizzle, Flip) for PS3
/// </summary>
FlipBeRGBA8_SW,
/// <summary>
/// LeRGBA8_SW (Swizzle, Tile) for PS4
/// </summary>
TileLeRGBA8_SW,
Expand Down
14 changes: 13 additions & 1 deletion FreeMote/RL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -511,7 +523,7 @@ public static unsafe void Switch_0_2(ref byte[] bytes)
/// RGBA(BE) -> ARGB(LE BGRA) (switch A)
/// </summary>
/// <param name="bytes"></param>
/// <param name="reverse"></param>
/// <param name="reverse">false: ROR; true: ROL</param>
public static unsafe void Argb2Rgba(ref byte[] bytes, bool reverse = false)
{
//Actually bgra -> abgr
Expand Down

0 comments on commit c358f51

Please sign in to comment.