Skip to content

Commit

Permalink
support for brtex & brplt pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
Venomalia committed Jun 13, 2023
1 parent a02787d commit eab2ff1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion TextureExtraction tool/Data/ScanBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ protected virtual bool TryExtract(ScanObjekt so)
else
{
ArchiveFile file = so.File;
archive.FileRequest = new Events.FileRequestDelegate(N => ((ArchiveFile)file.Parent[N]).FileData);
archive.FileRequest = new Events.FileRequestDelegate(N => ((ArchiveFile)file?.Parent[N]).FileData);
}
archive.Open(so.Stream, so.SubPath.ToString());
long size = archive.Root.Size;
Expand Down
31 changes: 30 additions & 1 deletion lib/AuroraLip/Archives/Formats/bres.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,26 @@ protected override void Read(Stream stream)
throw new InvalidIdentifierException("root");
uint RootSize = stream.ReadUInt32(ByteOrder);
Root = new ArchiveDirectory() { Name = "root", OwnerArchive = this };
ReadIndex(stream, (int)(stream.Position + RootSize - 8), Root);
//Index Group
ReadIndex(stream, (int)(stream.Position + RootSize - 8), Root);

//is brtex & brplt pair
if (Root.Items.Count == 1 && Root.ItemExists("Textures(NW4R)"))
{
//try to request an external file.
string datname = Path.ChangeExtension(Path.GetFileNameWithoutExtension(FullPath), ".brplt");
try
{
reference_stream = FileRequest.Invoke(datname);
Bres plt = new (reference_stream, FullPath);
foreach (var item in plt.Root.Items)
{
Root.Items.Add(item.Key, item.Value);
}
}
catch (Exception)
{ }
}
}

private void ReadIndex(Stream stream, in int EndOfRoot, ArchiveDirectory ParentDirectory)
Expand Down Expand Up @@ -118,6 +136,17 @@ protected override void Write(Stream ArchiveFile)
throw new NotImplementedException();
}

private Stream reference_stream;

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
reference_stream?.Dispose();
}
}

public unsafe struct Header
{
private fixed char magic[4];
Expand Down
10 changes: 7 additions & 3 deletions lib/AuroraLip/Texture/Formats/TEX0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ protected void Read(Stream stream, byte[] PaletteData, GXPaletteFormat PaletteFo
Archive ParentBres = substream.Parent.OwnerArchive;
if (ParentBres.ItemExists("Palettes(NW4R)"))
{
var PalletNames = ((ArchiveDirectory)ParentBres["Palettes(NW4R)"]).FindItems(name + "*");
List<string> PalletNames = ((ArchiveDirectory)ParentBres["Palettes(NW4R)"]).FindItems(name + "*");

if (PalletNames.Count == 0)
{
throw new PaletteException("No palette data could be found");
throw new PaletteException("No linked pallete palette data could be found");
}

stream.Position = SectionOffsets;
var tex = new TexEntry(stream, Format, ImageWidth, ImageHeight, TotalImageCount - 1)
TexEntry tex = new TexEntry(stream, Format, ImageWidth, ImageHeight, TotalImageCount - 1)
{
LODBias = 0,
MagnificationFilter = GXFilterMode.Nearest,
Expand All @@ -103,6 +103,10 @@ protected void Read(Stream stream, byte[] PaletteData, GXPaletteFormat PaletteFo
Add(tex);
return;
}
else
{
throw new PaletteException("No palette data could be found");
}
}
}
stream.Position = SectionOffsets;
Expand Down
4 changes: 4 additions & 0 deletions lib/AuroraLip/Texture/ImageEX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SixLabors.ImageSharp.Processing.Processors.Transforms;
using System.Drawing;
using System.Numerics;
using System.Reflection.PortableExecutable;

namespace AuroraLib.Texture
{
Expand Down Expand Up @@ -75,6 +76,9 @@ public static Image DecodeImage<TPixel>(this GXImageFormat Format, ReadOnlySpan<

public static Image<XPixel> ApplyPalette<TPixel, XPixel>(this Image<TPixel> image, ReadOnlySpan<XPixel> palette, Converter<TPixel, int> pixelToIndex) where TPixel : unmanaged, IPixel<TPixel> where XPixel : unmanaged, IPixel<XPixel>
{
if (palette.Length == 0)
throw new PaletteException("No palette data to apply.");

Image<XPixel> paletteImage = new(image.Width, image.Height);

IMemoryGroup<XPixel> pixelsPalette = paletteImage.GetPixelMemoryGroup();
Expand Down

0 comments on commit eab2ff1

Please sign in to comment.