mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
added some IImageDecoder implementations.
This commit is contained in:
@@ -59,7 +59,7 @@ namespace GameRes.Formats.ShiinaRio
|
||||
{
|
||||
var entry = new Entry
|
||||
{
|
||||
Name = string.Format ("{0}@{1:D4}.tga", base_name, i),
|
||||
Name = string.Format ("{0}@{1:D4}", base_name, i),
|
||||
Type = "image",
|
||||
Offset = offset,
|
||||
};
|
||||
@@ -79,9 +79,8 @@ namespace GameRes.Formats.ShiinaRio
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||
public override IImageDecoder OpenImage (ArcFile arc, Entry entry)
|
||||
{
|
||||
// emulate TGA image
|
||||
var offset = entry.Offset;
|
||||
var info = new S25MetaData
|
||||
{
|
||||
@@ -93,11 +92,8 @@ namespace GameRes.Formats.ShiinaRio
|
||||
FirstOffset = (uint)(offset + 0x14),
|
||||
Incremental = 0 != (arc.File.View.ReadUInt32 (offset+0x10) & 0x80000000u),
|
||||
};
|
||||
using (var input = arc.File.CreateStream (0, (uint)arc.File.MaxOffset))
|
||||
using (var reader = new S25Format.Reader (input, info))
|
||||
{
|
||||
return TgaStream.Create (info, reader.Unpack());
|
||||
}
|
||||
var input = arc.File.CreateStream (0, (uint)arc.File.MaxOffset);
|
||||
return new S25Format.Reader (input, info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +76,7 @@ namespace GameRes.Formats.ShiinaRio
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
using (var reader = new Reader (stream, (S25MetaData)info))
|
||||
{
|
||||
var pixels = reader.Unpack();
|
||||
return ImageData.Create (info, PixelFormats.Bgra32, null, pixels);
|
||||
}
|
||||
return reader.Image;
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
@@ -87,7 +84,7 @@ namespace GameRes.Formats.ShiinaRio
|
||||
throw new NotImplementedException ("S25Format.Write not implemented");
|
||||
}
|
||||
|
||||
internal sealed class Reader : IDisposable
|
||||
internal sealed class Reader : IImageDecoder
|
||||
{
|
||||
IBinaryStream m_input;
|
||||
int m_width;
|
||||
@@ -95,6 +92,25 @@ namespace GameRes.Formats.ShiinaRio
|
||||
uint m_origin;
|
||||
byte[] m_output;
|
||||
bool m_incremental;
|
||||
ImageMetaData m_info;
|
||||
ImageData m_image;
|
||||
|
||||
public Stream Input { get { m_input.Position = 0; return m_input.AsStream; } }
|
||||
public ImageMetaData Info { get { return m_info; } }
|
||||
public ImageFormat Format { get { return null; } }
|
||||
|
||||
public ImageData Image
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == m_image)
|
||||
{
|
||||
var pixels = Unpack();
|
||||
m_image = ImageData.Create (m_info, PixelFormats.Bgra32, null, pixels);
|
||||
}
|
||||
return m_image;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] Data { get { return m_output; } }
|
||||
|
||||
@@ -106,6 +122,7 @@ namespace GameRes.Formats.ShiinaRio
|
||||
m_input = file;
|
||||
m_origin = info.FirstOffset;
|
||||
m_incremental = info.Incremental;
|
||||
m_info = info;
|
||||
}
|
||||
|
||||
public byte[] Unpack ()
|
||||
|
||||
Reference in New Issue
Block a user