From 880f2189f5d73445e0d068c0748923f042ecf142 Mon Sep 17 00:00:00 2001 From: morkt Date: Wed, 17 Jan 2018 02:11:30 +0400 Subject: [PATCH] (PngFormat): added HeaderBytes static field. --- ArcFormats/ImageMNG.cs | 6 ++---- ArcFormats/Malie/ImageMGF.cs | 6 ++---- ArcFormats/Morning/ArcPAK.cs | 3 +-- ArcFormats/Palette/ImagePGA.cs | 2 +- GameRes/ImagePNG.cs | 2 ++ 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/ArcFormats/ImageMNG.cs b/ArcFormats/ImageMNG.cs index d3698fdf..9de4dc50 100644 --- a/ArcFormats/ImageMNG.cs +++ b/ArcFormats/ImageMNG.cs @@ -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 { diff --git a/ArcFormats/Malie/ImageMGF.cs b/ArcFormats/Malie/ImageMGF.cs index fc324859..dd12b376 100644 --- a/ArcFormats/Malie/ImageMGF.cs +++ b/ArcFormats/Malie/ImageMGF.cs @@ -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)) diff --git a/ArcFormats/Morning/ArcPAK.cs b/ArcFormats/Morning/ArcPAK.cs index 57f8575b..a01bd6fb 100644 --- a/ArcFormats/Morning/ArcPAK.cs +++ b/ArcFormats/Morning/ArcPAK.cs @@ -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) diff --git a/ArcFormats/Palette/ImagePGA.cs b/ArcFormats/Palette/ImagePGA.cs index e42f748e..9186f13f 100644 --- a/ArcFormats/Palette/ImagePGA.cs +++ b/ArcFormats/Palette/ImagePGA.cs @@ -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) diff --git a/GameRes/ImagePNG.cs b/GameRes/ImagePNG.cs index 4de63b2d..24d7fc74 100644 --- a/GameRes/ImagePNG.cs +++ b/GameRes/ImagePNG.cs @@ -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,