public byte[] GetData() { switch (PixelFormat) { case PixelFormat.Rgba8888: case PixelFormat.Rgbx8888: return(GetData32bpp(_data)); case PixelFormat.Indexed8: if (_uploadPixelFormat == Tm2.GsPSM.GS_PSMCT32) { return(Ps2.Decode8(Ps2.Encode32(_data, Size.Width / 128, Size.Height / 64), Size.Width / 128, Size.Height / 64)); } return(_data); case PixelFormat.Indexed4: if (_uploadPixelFormat == Tm2.GsPSM.GS_PSMCT32) { return(Ps2.Decode4(Ps2.Encode32(_data, Size.Width / 128, Size.Height / 128), Size.Width / 128, Size.Height / 128)); } return(_data); default: throw new NotSupportedException($"The format {PixelFormat} is not supported."); } }
private byte[] GetData32bpp() { var newData = new byte[Data.Length]; for (var i = 0; i < newData.Length - 3; i += 4) { newData[i + 0] = Data[i + 2]; newData[i + 1] = Data[i + 1]; newData[i + 2] = Data[i + 0]; newData[i + 3] = Ps2.FromPs2Alpha(Data[i + 3]); } return newData; }
private byte[] GetClut4() { var data = new byte[16 * 4]; for (var i = 0; i < 16; i++) { data[i * 4 + 0] = Clut[(i & 15) * 4 + 0]; data[i * 4 + 1] = Clut[(i & 15) * 4 + 1]; data[i * 4 + 2] = Clut[(i & 15) * 4 + 2]; data[i * 4 + 3] = Ps2.FromPs2Alpha(Clut[(i & 15) * 4 + 3]); } return data; }
private static byte[] GetData32bpp(byte[] data) { var newData = new byte[data.Length]; for (var i = 0; i < newData.Length - 3; i += 4) { newData[i + 0] = data[i + 2]; newData[i + 1] = data[i + 1]; newData[i + 2] = data[i + 0]; newData[i + 3] = Ps2.FromPs2Alpha(data[i + 3]); } return(newData); }
private byte[] GetClut8() { var data = new byte[256 * 4]; for (var i = 0; i < 256; i++) { var srcIndex = Ps2.Repl(i); data[i * 4 + 0] = Clut[srcIndex * 4 + 0]; data[i * 4 + 1] = Clut[srcIndex * 4 + 1]; data[i * 4 + 2] = Clut[srcIndex * 4 + 2]; data[i * 4 + 3] = Ps2.FromPs2Alpha(Clut[srcIndex * 4 + 3]); } return data; }
public byte[] GetData() { switch (format) { case Format32bpp: return GetData32bpp(); case Format8bpp: return IsSwizzled ? Ps2.Decode8(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 64), Size.Width / 128, Size.Height / 64) : Data; case Format4bpp: return IsSwizzled ? Ps2.Decode4(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 128), Size.Width / 128, Size.Height / 128) : Data; default: throw new NotSupportedException($"The format {format} is not supported."); } }
private static byte[] GetBitmapFrom8bpp(byte[] src, byte[] palette, int width, int height) { var dst = new byte[width * height * 4]; for (int i = 0; i < dst.Length; i += 4) { var index = Ps2.Repl(src[i / 4]); dst[i + 0] = (byte)Math.Max(0, palette[index * 4 + 2] * 2 - 1); dst[i + 1] = (byte)Math.Max(0, palette[index * 4 + 1] * 2 - 1); dst[i + 2] = (byte)Math.Max(0, palette[index * 4 + 0] * 2 - 1); dst[i + 3] = (byte)Math.Max(0, palette[index * 4 + 3] * 2 - 1); } return(dst); }
private static byte[] GetKh2Clut8(byte[] rawClut) { var inputColorCount = rawClut.Length / 4; var newClut = new byte[256 * 4]; for (var i = 0; i < inputColorCount; i++) { var dstIndex = Ps2.Repl(i); newClut[dstIndex * 4 + 0] = rawClut[i * 4 + 0]; newClut[dstIndex * 4 + 1] = rawClut[i * 4 + 1]; newClut[dstIndex * 4 + 2] = rawClut[i * 4 + 2]; newClut[dstIndex * 4 + 3] = ToPs2Alpha(rawClut[i * 4 + 3]); } return(newClut); }
private static byte[] GetClut8(byte[] clut, int cbp, int csa) { var data = new byte[256 * 4]; for (var i = 0; i < 256; i++) { var srcIndex = GetClutPointer(i, cbp, csa); data[i * 4 + 0] = clut[srcIndex * 4 + 0]; data[i * 4 + 1] = clut[srcIndex * 4 + 1]; data[i * 4 + 2] = clut[srcIndex * 4 + 2]; data[i * 4 + 3] = Ps2.FromPs2Alpha(clut[srcIndex * 4 + 3]); } return(data); }
public byte[] GetBitmap() { var swizzled = 0; switch (format) { case 0x13: return(GetBitmapFrom8bpp( swizzled == 7 ? Ps2.Decode8(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 64), Size.Width / 128, Size.Height / 64) : Data , Palette, Size.Width, Size.Height)); case 0x14: return(GetBitmapFrom4bpp( swizzled == 7 ? Ps2.Decode4(Ps2.Encode32(Data, Size.Width / 128, Size.Height / 128), Size.Width / 128, Size.Height / 128) : Data , Palette, Size.Width, Size.Height)); default: throw new NotSupportedException($"The format {format} is not supported."); } }
private static byte[] GetKh2Clut8(byte[] rawClut) { var newClut = new byte[256 * 4]; if (rawClut.Length < newClut.Length) { throw new ArgumentException( $"The clut must be at least {newClut.Length} bytes long."); } for (var i = 0; i < 256; i++) { var dstIndex = Ps2.Repl(i); newClut[dstIndex * 4 + 0] = rawClut[i * 4 + 0]; newClut[dstIndex * 4 + 1] = rawClut[i * 4 + 1]; newClut[dstIndex * 4 + 2] = rawClut[i * 4 + 2]; newClut[dstIndex * 4 + 3] = ToPs2Alpha(rawClut[i * 4 + 3]); } return(newClut); }
private static byte[] Swizzle8bpp(Size size, byte[] data) { data = Ps2.Encode8(data, size.Width / 128, size.Height / 64); return(Ps2.Decode32(data, size.Width / 128, size.Height / 64)); }