mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-23 19:34:15 +08:00
(BipFormat.Read): refactored.
This commit is contained in:
parent
6e11938080
commit
2871af397a
@ -86,6 +86,7 @@ namespace GameRes.Formats.PS2
|
||||
if (0 == w || 0 == h)
|
||||
return null;
|
||||
var meta = new BipMetaData { Width = w, Height = h, BPP = 32 };
|
||||
meta.Tiles.Capacity = tile_count;
|
||||
for (int i = 0; i < tile_count; ++i)
|
||||
{
|
||||
input.ReadInt64();
|
||||
@ -112,14 +113,13 @@ namespace GameRes.Formats.PS2
|
||||
if (null == meta)
|
||||
throw new ArgumentException ("BipFormat.Read should be supplied with BipMetaData", "info");
|
||||
|
||||
using (var input = new BinaryReader (stream, Encoding.ASCII, true))
|
||||
{
|
||||
var header = new byte[0x7c];
|
||||
var bitmap = new WriteableBitmap ((int)meta.Width, (int)meta.Height, 96, 96, PixelFormats.Bgra32, null);
|
||||
var bitmap = new WriteableBitmap ((int)meta.Width, (int)meta.Height,
|
||||
ImageData.DefaultDpiX, ImageData.DefaultDpiY, PixelFormats.Bgra32, null);
|
||||
foreach (var tile in meta.Tiles)
|
||||
{
|
||||
input.BaseStream.Position = tile.Offset;
|
||||
if (header.Length != input.Read (header, 0, header.Length))
|
||||
stream.Position = tile.Offset;
|
||||
if (header.Length != stream.Read (header, 0, header.Length))
|
||||
throw new InvalidFormatException ("Invalid tile header");
|
||||
if (!Binary.AsciiEqual (header, "PNGFILE2"))
|
||||
throw new InvalidFormatException ("Unknown tile format");
|
||||
@ -127,10 +127,7 @@ namespace GameRes.Formats.PS2
|
||||
int alpha = LittleEndian.ToInt32 (header, 0x68);
|
||||
int x = LittleEndian.ToInt32 (header, 0x6c);
|
||||
int y = LittleEndian.ToInt32 (header, 0x70);
|
||||
var data = new byte[data_size];
|
||||
if (data_size != input.Read (data, 0, data_size))
|
||||
throw new InvalidFormatException ("Unexpected end of file");
|
||||
using (var png = new MemoryStream (data, false))
|
||||
using (var png = new StreamRegion (stream, stream.Position, data_size, true))
|
||||
{
|
||||
var decoder = new PngBitmapDecoder (png,
|
||||
BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
@ -158,4 +155,3 @@ namespace GameRes.Formats.PS2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user