Silky's MFG format implementation.

This commit is contained in:
morkt 2015-04-30 21:07:11 +04:00
parent 81b34ec140
commit b6a354f52a
4 changed files with 196 additions and 2 deletions

View File

@ -86,6 +86,7 @@
<Compile Include="ArcLST.cs" />
<Compile Include="ArcMajiro.cs" />
<Compile Include="ArcMBL.cs" />
<Compile Include="ArcMFG.cs" />
<Compile Include="ArcMGPK.cs" />
<Compile Include="ArcMnoViolet.cs" />
<Compile Include="ArcNEKO.cs" />
@ -149,6 +150,7 @@
<Compile Include="ImageHG3.cs" />
<Compile Include="ImageISG.cs" />
<Compile Include="ImageKAAS.cs" />
<Compile Include="ImageMFG.cs" />
<Compile Include="ImageMNV.cs" />
<Compile Include="ImagePRS.cs" />
<Compile Include="ImagePT1.cs" />

76
ArcFormats/ArcMFG.cs Normal file
View File

@ -0,0 +1,76 @@
//! \file ArcMFG.cs
//! \date Wed Apr 29 13:22:31 2015
//! \brief MFG resourse archives implementation.
//
// Copyright (C) 2015 by morkt
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using GameRes.Utility;
namespace GameRes.Formats.Silky
{
[Export(typeof(ArchiveFormat))]
public class MfgOpener : ArchiveFormat
{
public override string Tag { get { return "MFG"; } }
public override string Description { get { return "Silky's engine resource archive"; } }
public override uint Signature { get { return 0x46504c41; } } // 'ALPF'
public override bool IsHierarchic { get { return false; } }
public override bool CanCreate { get { return false; } }
public MfgOpener ()
{
Extensions = new string[] { "mfg", "mfm", "mfs" };
}
public override ArcFile TryOpen (ArcView file)
{
int count = file.View.ReadInt32 (4);
if (count <= 0 || count > 0xfffff)
return null;
var dir = new List<Entry> (count);
long index_offset = 8;
uint next_offset = file.View.ReadUInt32 (index_offset+0x10);
for (int i = 0; i < count; ++i)
{
string name = file.View.ReadString (index_offset, 0x10);
if (0 == name.Length)
return null;
uint offset = next_offset;
index_offset += 0x14;
if (i+1 != count)
next_offset = file.View.ReadUInt32 (index_offset+0x10);
else
next_offset = (uint)file.MaxOffset;
var entry = AutoEntry.Create (file, offset, name);
entry.Size = next_offset - offset;
if (!entry.CheckPlacement (file.MaxOffset))
return null;
dir.Add (entry);
}
return new ArcFile (file, this, dir);
}
}
}

116
ArcFormats/ImageMFG.cs Normal file
View File

@ -0,0 +1,116 @@
//! \file ImageMFG.cs
//! \date Wed Apr 29 13:47:56 2015
//! \brief Silky's MFG image format implementation.
//
// Copyright (C) 2015 by morkt
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GameRes.Utility;
namespace GameRes.Formats.Silky
{
internal class MfgMetaData : ImageMetaData
{
public int Type;
public int Stride;
}
[Export (typeof (ImageFormat))]
public class MfgFormat : ImageFormat
{
public override string Tag { get { return "MFG"; } }
public override string Description { get { return "Silky's RGB image format"; } }
public override uint Signature { get { return 0x5f47464du; } } // 'MFG_'
public MfgFormat ()
{
Signatures = new uint[] { 0x5f47464d, 0x4147464d, 0x4347464d }; // 'MFG_', 'MFGA', 'MFGC'
Extensions = new string[] { "mfp" }; // made-up
}
public override void Write (Stream file, ImageData image)
{
throw new NotImplementedException ("MfgFormat.Write not implemented");
}
public override ImageMetaData ReadMetaData (Stream stream)
{
using (var file = new ArcView.Reader (stream))
{
stream.Seek (3, SeekOrigin.Current);
byte id = file.ReadByte();
uint data_size = file.ReadUInt32();
uint width = file.ReadUInt32();
uint height = file.ReadUInt32();
uint stride = file.ReadUInt32();
if (stride < width)
throw new NotSupportedException();
if (stride*height != data_size)
return null;
return new MfgMetaData
{
Width = width,
Height = height,
BPP = (int)(stride*8/width),
Type = id,
Stride = (int)stride,
};
}
}
public override ImageData Read (Stream stream, ImageMetaData info)
{
var meta = info as MfgMetaData;
if (null == meta)
throw new ArgumentException ("MfgFormat.Read should be supplied with MfgMetaData", "info");
stream.Position = 0x14;
if ('_' != meta.Type)
using (var file = new ArcView.Reader (stream))
{
for (uint i = 0; i < meta.Height; ++i)
{
uint n = file.ReadUInt32();
file.BaseStream.Seek (n*8, SeekOrigin.Current);
}
}
byte[] pixels = new byte[meta.Stride*info.Height];
if (pixels.Length != stream.Read (pixels, 0, pixels.Length))
throw new InvalidFormatException ("Unexpected end of file");
PixelFormat format;
if (24 == meta.BPP)
format = PixelFormats.Bgr24;
else
format = PixelFormats.Bgra32;
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
format, null, pixels, meta.Stride);
bitmap.Freeze();
return new ImageData (bitmap, info);
}
}
}

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion ("1.0.4.43")]
[assembly: AssemblyFileVersion ("1.0.4.43")]
[assembly: AssemblyVersion ("1.0.4.44")]
[assembly: AssemblyFileVersion ("1.0.4.44")]