-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug that occurred when reading RGBA8 images for Melee because t…
…hey're actually stored as AR8GB8.
- Loading branch information
1 parent
2f0a477
commit 58e6f13
Showing
7 changed files
with
136 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ public enum PixelFormat { | |
RGBA5553, | ||
RGBA8888, | ||
RGBA16161616, | ||
AR88GB88, | ||
|
||
HILO88, | ||
|
||
|
48 changes: 48 additions & 0 deletions
48
FinModelUtility/Fin/Fin/src/image/io/tile/Ar88Gb88TileReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Rgba32> { | ||
public IImage<Rgba32> 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; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters