(PngFormat): added HeaderBytes static field.

This commit is contained in:
morkt 2018-01-17 02:11:30 +04:00
parent 02853c4438
commit 880f2189f5
5 changed files with 8 additions and 11 deletions

View File

@ -79,13 +79,11 @@ namespace GameRes.Formats
return info;
}
internal static readonly byte[] PngHeader = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
var meta = (MngMetaData)info;
var body = new StreamRegion (file.AsStream, meta.PngOffset, true);
using (var png = new PrefixStream (PngHeader, body))
using (var png = new PrefixStream (PngFormat.HeaderBytes, body))
{
var decoder = new PngBitmapDecoder (png, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
var frame = decoder.Frames[0];
@ -188,7 +186,7 @@ namespace GameRes.Formats
public MngFrameDecoder (IBinaryStream input)
{
var png = new PrefixStream (MngFormat.PngHeader, input.AsStream);
var png = new PrefixStream (PngFormat.HeaderBytes, input.AsStream);
m_input = new BinaryStream (png, input.Name);
try
{

View File

@ -39,14 +39,12 @@ namespace GameRes.Formats.Malie
public override uint Signature { get { return 0x696C614D; } } // 'Mali'
public override bool CanWrite { get { return true; } }
static readonly byte[] PngHeader = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
public override ImageMetaData ReadMetaData (IBinaryStream stream)
{
var header = stream.ReadHeader (8).ToArray();
if (!Binary.AsciiEqual (header, "MalieGF"))
return null;
Buffer.BlockCopy (PngHeader, 0, header, 0, 8);
Buffer.BlockCopy (HeaderBytes, 0, header, 0, 8);
using (var data = new StreamRegion (stream.AsStream, 8, true))
using (var pre = new PrefixStream (header, data))
@ -56,7 +54,7 @@ namespace GameRes.Formats.Malie
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
{
var header = PngHeader.Clone() as byte[];
var header = HeaderBytes.Clone() as byte[];
using (var data = new StreamRegion (stream.AsStream, 8, true))
using (var pre = new PrefixStream (header, data))
using (var png = new BinaryStream (pre, stream.Name))

View File

@ -75,7 +75,6 @@ namespace GameRes.Formats.Morning
return new ArcFile (file, this, dir);
}
static readonly byte[] PngHeader = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
static readonly byte[] PngIHdr = { 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52 };
public override Stream OpenEntry (ArcFile arc, Entry entry)
@ -83,7 +82,7 @@ namespace GameRes.Formats.Morning
if (entry.Size <= 8 || !arc.File.View.BytesEqual (entry.Offset, PngIHdr))
return base.OpenEntry (arc, entry);
Stream input = arc.File.CreateStream (entry.Offset, entry.Size);
return new PrefixStream (PngHeader, input);
return new PrefixStream (PngFormat.HeaderBytes, input);
}
void DecryptIndex (byte[] data, byte[] key)

View File

@ -63,7 +63,7 @@ namespace GameRes.Formats.Palette
}
}
public static readonly byte[] PngHeader = { 0x89, 0x50, 0x4E, 0x47, 0xD, 0xA, 0x1A, 0xA };
public static byte[] PngHeader { get { return HeaderBytes; } }
public static readonly byte[] PngFooter = { 0, 0, 0, 0, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82 };
IBinaryStream DeobfuscateStream (IBinaryStream stream)

View File

@ -41,6 +41,8 @@ namespace GameRes
public override uint Signature { get { return 0x474e5089; } }
public override bool CanWrite { get { return true; } }
public static readonly byte[] HeaderBytes = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
var decoder = new PngBitmapDecoder (file.AsStream,