IBinaryStream migration.

This commit is contained in:
morkt
2016-10-16 09:22:53 +04:00
parent d0c1d5da01
commit bb18303eb4
251 changed files with 3277 additions and 3630 deletions

View File

@@ -27,7 +27,6 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using GameRes.Utility;
namespace GameRes.Formats.Pajamas
{
@@ -84,10 +83,9 @@ namespace GameRes.Formats.Pajamas
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
if (!entry.Name.Equals ("textdata.bin", StringComparison.InvariantCultureIgnoreCase))
if (!entry.Name.EndsWith ("textdata.bin", StringComparison.InvariantCultureIgnoreCase))
return arc.File.CreateStream (entry.Offset, entry.Size);
var data = new byte[entry.Size];
arc.File.View.Read (entry.Offset, data, 0, entry.Size);
var data = arc.File.View.ReadBytes (entry.Offset, entry.Size);
// encrypted PJADV
if (0x95 == data[0] && 0x6B == data[1] && 0x3C == data[2]
&& 0x9D == data[3] && 0x63 == data[4])
@@ -99,7 +97,7 @@ namespace GameRes.Formats.Pajamas
key += 0x5C;
}
}
return new MemoryStream (data);
return new BinMemoryStream (data, entry.Name);
}
}
}

View File

@@ -56,41 +56,35 @@ namespace GameRes.Formats.Pajamas
throw new NotImplementedException ("EpaFormat.Write not implemented");
}
public override ImageMetaData ReadMetaData (Stream stream)
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
using (var header = new ArcView.Reader (stream))
var info = new EpaMetaData();
info.Mode = file.ReadInt32() >> 24;
info.ColorType = file.ReadInt32() & 0xff;
switch (info.ColorType)
{
var info = new EpaMetaData();
info.Mode = header.ReadInt32() >> 24;
info.ColorType = header.ReadInt32() & 0xff;
switch (info.ColorType)
{
case 0: info.BPP = 8; break;
case 1: info.BPP = 24; break;
case 2: info.BPP = 32; break;
case 3: info.BPP = 15; break;
case 4: info.BPP = 8; break;
default: return null;
}
info.Width = header.ReadUInt32();
info.Height = header.ReadUInt32();
if (2 == info.Mode)
{
info.OffsetX = header.ReadInt32();
info.OffsetY = header.ReadInt32();
}
return info;
case 0: info.BPP = 8; break;
case 1: info.BPP = 24; break;
case 2: info.BPP = 32; break;
case 3: info.BPP = 15; break;
case 4: info.BPP = 8; break;
default: return null;
}
info.Width = file.ReadUInt32();
info.Height = file.ReadUInt32();
if (2 == info.Mode)
{
info.OffsetX = file.ReadInt32();
info.OffsetY = file.ReadInt32();
}
return info;
}
public override ImageData Read (Stream stream, ImageMetaData info)
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
var meta = info as EpaMetaData;
if (null == meta)
throw new ArgumentException ("EpaFormat.Read should be supplied with EpaMetaData", "info");
stream.Position = 2 == meta.Mode ? 0x18 : 0x10;
var reader = new Reader (stream, meta);
var meta = (EpaMetaData)info as EpaMetaData;
file.Position = 2 == meta.Mode ? 0x18 : 0x10;
var reader = new Reader (file.AsStream, meta);
reader.Unpack();
return ImageData.Create (meta, reader.Format, reader.Palette, reader.Data);
}