diff --git a/FinModelUtility/Fin/Fin/src/image/PixelFormat.cs b/FinModelUtility/Fin/Fin/src/image/PixelFormat.cs index 1409bbfe0..f180cfc0e 100644 --- a/FinModelUtility/Fin/Fin/src/image/PixelFormat.cs +++ b/FinModelUtility/Fin/Fin/src/image/PixelFormat.cs @@ -18,6 +18,7 @@ public enum PixelFormat { RGBA5553, RGBA8888, RGBA16161616, + AR88GB88, HILO88, diff --git a/FinModelUtility/Fin/Fin/src/image/io/tile/Ar88Gb88TileReader.cs b/FinModelUtility/Fin/Fin/src/image/io/tile/Ar88Gb88TileReader.cs new file mode 100644 index 000000000..567527b98 --- /dev/null +++ b/FinModelUtility/Fin/Fin/src/image/io/tile/Ar88Gb88TileReader.cs @@ -0,0 +1,48 @@ +using fin.image.formats; + +using schema.binary; + +using SixLabors.ImageSharp.PixelFormats; + +namespace fin.image.io.tile { + public readonly struct Ar88Gb88TileReader : ITileReader { + public IImage CreateImage(int width, int height) + => new Rgba32Image(PixelFormat.AR88GB88, width, height); + + public int TileWidth => 4; + public int TileHeight => 4; + + public unsafe void Decode(IBinaryReader br, + Rgba32* scan0, + int tileX, + int tileY, + int imageWidth, + int imageHeight) { + var x = tileX * this.TileWidth; + var y = tileY * this.TileHeight; + + for (int k = 0; k < 2; k++) { + for (int y1 = y; y1 < y + this.TileHeight; y1++) { + for (int x1 = x; x1 < x + this.TileWidth; x1++) { + var offset = y1 * imageWidth + x1; + var pixel = br.ReadUInt16(); + + if (x1 > imageWidth || y1 > imageHeight) { + continue; + } + + var rgba = scan0[offset]; + if (k == 0) { + rgba.A = (byte) (pixel >> 8); + rgba.R = (byte) (pixel & 0xff); + } else { + rgba.G = (byte) (pixel >> 8); + rgba.B = (byte) (pixel & 0xff); + } + scan0[offset] = rgba; + } + } + } + } + } +} \ No newline at end of file diff --git a/FinModelUtility/Formats/Dat/src/image/DatImageReader.cs b/FinModelUtility/Formats/Dat/src/image/DatImageReader.cs new file mode 100644 index 000000000..9250efd68 --- /dev/null +++ b/FinModelUtility/Formats/Dat/src/image/DatImageReader.cs @@ -0,0 +1,72 @@ +using fin.image; +using fin.image.io; +using fin.image.io.image; +using fin.image.io.pixel; +using fin.image.io.tile; + +using gx; + +using schema.binary; + +namespace dat.image { + public class DatImageReader : IImageReader { + private readonly IImageReader impl_; + + public DatImageReader(int width, int height, GxTextureFormat format) { + this.impl_ = this.CreateImpl_(width, height, format); + } + + private IImageReader CreateImpl_(int width, + int height, + GxTextureFormat format) { + return format switch { + GxTextureFormat.I4 => TiledImageReader.New( + width, + height, + 8, + 8, + new L2a4PixelReader()), + GxTextureFormat.I8 => TiledImageReader.New( + width, + height, + 8, + 4, + new L2a8PixelReader()), + GxTextureFormat.A4_I4 => TiledImageReader.New( + width, + height, + 8, + 4, + new Al8PixelReader()), + GxTextureFormat.A8_I8 => TiledImageReader.New( + width, + height, + 4, + 4, + new Al16PixelReader()), + GxTextureFormat.R5_G6_B5 => TiledImageReader.New( + width, + height, + 4, + 4, + new Rgb565PixelReader()), + GxTextureFormat.A3_RGB5 => TiledImageReader.New( + width, + height, + 4, + 4, + new Rgba5553PixelReader()), + GxTextureFormat.ARGB8 => TiledImageReader.New( + width, + height, + new Ar88Gb88TileReader()), + GxTextureFormat.S3TC1 => new CmprImageReader(width, height), + }; + } + + public IImage ReadImage(IBinaryReader br) => this.impl_.ReadImage(br); + + public IImage ReadImage(byte[] data, Endianness endianness) + => this.impl_.ReadImage(data, endianness); + } +} \ No newline at end of file diff --git a/FinModelUtility/Formats/Dat/src/schema/PObj.cs b/FinModelUtility/Formats/Dat/src/schema/PObj.cs index 795a616af..11917ba1c 100644 --- a/FinModelUtility/Formats/Dat/src/schema/PObj.cs +++ b/FinModelUtility/Formats/Dat/src/schema/PObj.cs @@ -223,7 +223,10 @@ public void Read(IBinaryReader br) { sbr => sbr.ReadVector2(vertexDescriptor)); break; } - default: throw new NotImplementedException(); + default: { + break; + //throw new NotImplementedException(); + } } } diff --git a/FinModelUtility/Formats/Dat/src/schema/TObj.cs b/FinModelUtility/Formats/Dat/src/schema/TObj.cs index 845dd80c8..ad42adc7d 100644 --- a/FinModelUtility/Formats/Dat/src/schema/TObj.cs +++ b/FinModelUtility/Formats/Dat/src/schema/TObj.cs @@ -1,9 +1,10 @@ using System.Drawing; +using dat.image; + using fin.image; using gx; -using gx.image; using schema.binary; @@ -40,7 +41,7 @@ public void Read(IBinaryReader br) { // TODO: Add support for indexed textures try { br.Position = imageDataOffset; - this.Image = new GxImageReader(width, height, format).ReadImage(br); + this.Image = new DatImageReader(width, height, format).ReadImage(br); } catch { this.Image = FinImage.Create1x1FromColor(Color.Magenta); } diff --git a/FinModelUtility/Formats/Gx/src/image/GxImageReader.cs b/FinModelUtility/Formats/J3d/J3d/src/image/J3dImageReader.cs similarity index 92% rename from FinModelUtility/Formats/Gx/src/image/GxImageReader.cs rename to FinModelUtility/Formats/J3d/J3d/src/image/J3dImageReader.cs index c3429ad84..43b3f741b 100644 --- a/FinModelUtility/Formats/Gx/src/image/GxImageReader.cs +++ b/FinModelUtility/Formats/J3d/J3d/src/image/J3dImageReader.cs @@ -3,13 +3,15 @@ using fin.image.io.image; using fin.image.io.pixel; +using gx; + using schema.binary; -namespace gx.image { - public class GxImageReader : IImageReader { +namespace j3d.image { + public class J3dImageReader : IImageReader { private readonly IImageReader impl_; - public GxImageReader(int width, int height, GxTextureFormat format) { + public J3dImageReader(int width, int height, GxTextureFormat format) { this.impl_ = this.CreateImpl_(width, height, format); } diff --git a/FinModelUtility/Formats/J3d/J3d/src/schema/bmd/tex1/TextureEntry.cs b/FinModelUtility/Formats/J3d/J3d/src/schema/bmd/tex1/TextureEntry.cs index 5a0e4473b..a2b2de2f4 100644 --- a/FinModelUtility/Formats/J3d/J3d/src/schema/bmd/tex1/TextureEntry.cs +++ b/FinModelUtility/Formats/J3d/J3d/src/schema/bmd/tex1/TextureEntry.cs @@ -6,7 +6,8 @@ using fin.util.color; using gx; -using gx.image; + +using j3d.image; using schema.binary; using schema.binary.attributes; @@ -126,7 +127,7 @@ private void ReadPalettes_(IBinaryReader br) { public unsafe IImage ToBitmap() { try { - return new GxImageReader(this.Width, this.Height, this.Format).ReadImage( + return new J3dImageReader(this.Width, this.Height, this.Format).ReadImage( this.Data, Endianness.BigEndian); } catch { }