Restored 16bpp support

This commit is contained in:
2025-01-25 20:46:56 +01:00
parent 9ddafca929
commit 854d14af03

View File

@@ -60,10 +60,13 @@ namespace PSXSplash.RuntimeCode
public int Height { get; set; } public int Height { get; set; }
public int[] Pixels { get; set; } public int[] Pixels { get; set; }
public List<VRAMPixel> ColorPalette = new List<VRAMPixel>(); public List<VRAMPixel> ColorPalette = new List<VRAMPixel>();
public PSXBPP BitDepth; public PSXBPP BitDepth { get; set; }
private int _maxColors; private int _maxColors;
// Used only for 16bpp
public ushort[] ImageData { get; set; }
public static PSXTexture2D CreateFromTexture2D(Texture2D inputTexture, PSXBPP bitDepth, bool dither) public static PSXTexture2D CreateFromTexture2D(Texture2D inputTexture, PSXBPP bitDepth, bool dither)
{ {
PSXTexture2D psxTex = new PSXTexture2D(); PSXTexture2D psxTex = new PSXTexture2D();
@@ -72,6 +75,19 @@ namespace PSXSplash.RuntimeCode
psxTex.Height = inputTexture.height; psxTex.Height = inputTexture.height;
psxTex.BitDepth = bitDepth; psxTex.BitDepth = bitDepth;
if (bitDepth == PSXBPP.TEX_16BIT)
{
psxTex.ImageData = new ushort[inputTexture.width * inputTexture.height];
int i = 0;
foreach (Color pixel in inputTexture.GetPixels())
{
VRAMPixel vramPixel = new VRAMPixel { R = (ushort)(pixel.r * 31), G = (ushort)(pixel.g * 31), B = (ushort)(pixel.b * 31) };
psxTex.ImageData[i] = vramPixel.Pack();
i++;
}
return psxTex;
}
psxTex._maxColors = (int)Mathf.Pow((int)bitDepth, 2); psxTex._maxColors = (int)Mathf.Pow((int)bitDepth, 2);
ImageQuantizer quantizer = new ImageQuantizer(); ImageQuantizer quantizer = new ImageQuantizer();
@@ -90,6 +106,27 @@ namespace PSXSplash.RuntimeCode
public Texture2D GeneratePreview() public Texture2D GeneratePreview()
{ {
Texture2D tex = new Texture2D(Width, Height); Texture2D tex = new Texture2D(Width, Height);
if (BitDepth == PSXBPP.TEX_16BIT)
{
Color[] colors16 = new Color[Width * Height];
// An instance for the Unpack method
VRAMPixel pixel = new VRAMPixel();
for (int i = 0; i < ImageData.Length; i++)
{
ushort packedValue = ImageData[i];
pixel.Unpack(packedValue);
float r = pixel.R / 31f;
float g = pixel.G / 31f;
float b = pixel.B / 31f;
colors16[i] = new Color(r,g,b);
}
tex.SetPixels(colors16);
tex.Apply();
return tex;
}
List<Color> colors = new List<Color>(); List<Color> colors = new List<Color>();
for (int y = 0; y < Height; y++) for (int y = 0; y < Height; y++)
@@ -114,6 +151,10 @@ namespace PSXSplash.RuntimeCode
public Texture2D GenerateVramPreview() public Texture2D GenerateVramPreview()
{ {
if(BitDepth == PSXBPP.TEX_16BIT) {
return GeneratePreview();
}
int adjustedWidth = Width; int adjustedWidth = Width;
if (BitDepth == PSXBPP.TEX_4BIT) if (BitDepth == PSXBPP.TEX_4BIT)