implemented ALD archive and QNT image formats.

This commit is contained in:
morkt 2015-04-10 06:35:06 +04:00
parent 6e472559f1
commit 9cabb73c00
5 changed files with 306 additions and 3 deletions

87
ArcFormats/ArcALD.cs Normal file
View File

@ -0,0 +1,87 @@
//! \file ArcALD.cs
//! \date Thu Apr 09 20:33:19 2015
//! \brief AliceSoft System engine resource archive.
//
// 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.AliceSoft
{
[Export(typeof(ArchiveFormat))]
public class AldOpener : ArchiveFormat
{
public override string Tag { get { return "ALD"; } }
public override string Description { get { return "AliceSoft System engine resource archive"; } }
public override uint Signature { get { return 0; } }
public override bool IsHierarchic { get { return false; } }
public override bool CanCreate { get { return false; } }
public override ArcFile TryOpen (ArcView file)
{
long index_offset = file.MaxOffset - 0x10;
if (index_offset <= 0)
return null;
if (0x014c4e != file.View.ReadUInt32 (index_offset)
|| 0x10 != file.View.ReadUInt32 (index_offset+4))
return null;
int count = file.View.ReadUInt16 (index_offset+9);
if (0 == count)
return null;
uint index_length = (file.View.ReadUInt32 (0) & 0xffffff) << 8;
if (index_length > file.View.Reserve (0, index_length))
return null;
var dir = new List<Entry> (count);
index_offset = 3;
for (int i = 0; i < count; ++i)
{
uint offset = (file.View.ReadUInt32 (index_offset) & 0xffffff) << 8;
if (0 == offset)
break;
if (offset >= file.MaxOffset)
return null;
dir.Add (new Entry { Offset = offset });
index_offset += 3;
}
foreach (var entry in dir)
{
var offset = entry.Offset;
uint header_size = file.View.ReadUInt32 (offset);
if (header_size <= 0x10)
return null;
entry.Size = file.View.ReadUInt32 (offset+4);
entry.Name = file.View.ReadString (offset+0x10, header_size-0x10);
entry.Offset = offset + header_size;
if (!entry.CheckPlacement (file.MaxOffset))
return null;
entry.Type = FormatCatalog.Instance.GetTypeFromName (entry.Name);
}
return new ArcFile (file, this, dir);
}
}
}

View File

@ -62,6 +62,7 @@
<ItemGroup>
<Compile Include="ArcADPACK.cs" />
<Compile Include="ArcAFS.cs" />
<Compile Include="ArcALD.cs" />
<Compile Include="ArcAMI.cs" />
<Compile Include="ArcAVC.cs" />
<Compile Include="ArcBGI.cs" />
@ -137,6 +138,7 @@
<Compile Include="ImageISG.cs" />
<Compile Include="ImageMNV.cs" />
<Compile Include="ImagePRS.cs" />
<Compile Include="ImageQNT.cs" />
<Compile Include="ImageRCT.cs" />
<Compile Include="ImageTGF.cs" />
<Compile Include="ImageTLG.cs" />

212
ArcFormats/ImageQNT.cs Normal file
View File

@ -0,0 +1,212 @@
//! \file ImageQNT.cs
//! \date Thu Apr 09 21:37:18 2015
//! \brief AliceSoft RGB image format.
//
// 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.ComponentModel.Composition;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GameRes.Utility;
using ZLibNet;
namespace GameRes.Formats.AliceSoft
{
public class QntMetaData : ImageMetaData
{
public uint RGBSize;
public uint AlphaSize;
}
[Export(typeof(ImageFormat))]
public class QntFormat : ImageFormat
{
public override string Tag { get { return "QNT"; } }
public override string Description { get { return "AliceSoft System image format"; } }
public override uint Signature { get { return 0x544e51; } } // 'QNT'
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("QntFormat.Write not implemented");
}
public override ImageMetaData ReadMetaData (Stream stream)
{
var header = new byte[0x44];
if (header.Length != stream.Read (header, 0, header.Length))
return null;
int version = LittleEndian.ToInt32 (header, 4);
if (version <= 0 || version > 2)
return null;
if (0x44 != LittleEndian.ToUInt32 (header, 8))
return null;
uint width = LittleEndian.ToUInt32 (header, 0x14);
uint height = LittleEndian.ToUInt32 (header, 0x18);
if (0 == width || 0 == height)
return null;
return new QntMetaData
{
Width = width,
Height = height,
OffsetX = LittleEndian.ToInt32 (header, 0x0c),
OffsetY = LittleEndian.ToInt32 (header, 0x10),
BPP = LittleEndian.ToInt32 (header, 0x1c),
RGBSize = LittleEndian.ToUInt32 (header, 0x24),
AlphaSize = LittleEndian.ToUInt32 (header, 0x28),
};
}
public override ImageData Read (Stream stream, ImageMetaData info)
{
var meta = info as QntMetaData;
if (null == meta)
throw new ArgumentException ("QntFormat.Read should be supplied with QntMetaData", "info");
stream.Position = 0x44;
using (var reader = new Reader (stream, meta))
{
reader.Unpack();
var pixels = reader.Data;
int stride = (int)info.Width * (reader.BPP / 8);
PixelFormat format = 24 == reader.BPP ? PixelFormats.Bgr24 : PixelFormats.Bgra32;
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
format, null, pixels, stride);
bitmap.Freeze();
return new ImageData (bitmap, info);
}
}
internal class Reader : IDisposable
{
byte[] m_input;
byte[] m_alpha;
byte[] m_output;
int m_bpp;
int m_width;
int m_height;
public byte[] Data { get { return m_output; } }
public int BPP { get { return m_bpp*8; } }
public Reader (Stream stream, QntMetaData info)
{
m_width = (int)info.Width;
m_height = (int)info.Height;
int w = (m_width + 1) & ~1;
int h = (m_height + 1) & ~1;
int rgb_size = h * w * 3;
m_bpp = info.AlphaSize != 0 ? 4 : 3;
m_input = new byte[rgb_size];
var alpha_pos = stream.Position + info.RGBSize;
using (var zstream = new ZLibStream (stream, CompressionMode.Decompress, true))
if (rgb_size != zstream.Read (m_input, 0, rgb_size))
throw new InvalidFormatException ("Unexpected end of file");
if (info.AlphaSize != 0)
{
int alpha_size = w * m_height;
m_alpha = new byte[alpha_size];
stream.Position = alpha_pos;
using (var zstream = new ZLibStream (stream, CompressionMode.Decompress, true))
if (alpha_size != zstream.Read (m_alpha, 0, alpha_size))
throw new InvalidFormatException ("Unexpected end of file");
}
m_output = new byte[info.Width*info.Height*m_bpp];
}
public void Unpack ()
{
int src = 0;
int dst;
int stride = m_bpp * m_width;
for (int channel = 0; channel < 3; ++channel)
{
dst = channel;
for (int y = m_height >> 1; y != 0; --y)
{
for (int x = 0; x < m_width; ++x)
{
m_output[dst] = m_input[src++];
m_output[dst+stride] = m_input[src++];
dst += m_bpp;
}
dst += stride;
src += 2 * (m_width & 1);
}
if (0 != (m_height & 1))
{
for (int x = 0; x < m_width; ++x)
{
m_output[dst] = m_input[src];
src += 2;
dst += m_bpp;
}
src += 2 * (m_width & 1);
}
}
if (3 != m_bpp)
{
src = 0;
dst = 3;
for (int y = 0; y < m_height; ++y)
{
for (int x = 0; x < m_width; ++x)
{
m_output[dst] = m_alpha[src++];
dst += 4;
}
src += m_width & 1;
}
}
dst = m_bpp;
int i;
for (i = stride-m_bpp; i != 0; --i)
{
int b = m_output[dst-m_bpp] - m_output[dst];
m_output[dst++] = (byte)b;
}
for (int j = m_height - 1; j != 0; --j)
{
for (i = 0; i != m_bpp; ++i)
{
m_output[dst] = (byte)(m_output[dst-stride] - m_output[dst]);
++dst;
}
for (i = stride-m_bpp; i != 0; --i)
{
int b = ((int)m_output[dst-stride] + m_output[dst-m_bpp]) >> 1;
b -= m_output[dst];
m_output[dst++] = (byte)b;
}
}
}
#region IDisposable Members
public void Dispose ()
{
GC.SuppressFinalize (this);
}
#endregion
}
}
}

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.36")]
[assembly: AssemblyFileVersion ("1.0.4.36")]
[assembly: AssemblyVersion ("1.0.4.37")]
[assembly: AssemblyFileVersion ("1.0.4.37")]

View File

@ -12,7 +12,7 @@ tr.odd td { background-color: #eee }
<p>Formats recognized by Game Archived Resources browser.</p>
<table>
<tr><th>Files</th><th>Signature</th><th>Create</th><th>Brand/Engine<th>Titles</th></tr>
<tr class="odd"><td>*.pak</td><td><tt>ADPACK32</tt></td><td>No</td><td rowspan="3">Active Soft</td><td rowspan="3">Bible Black<br/>Discipline<br/>Discipline LS</td></tr>
<tr class="odd"><td>*.pak</td><td><tt>ADPACK32</tt></td><td>No</td><td rowspan="3">Active Soft</td><td rowspan="3">Bible Black<br/>Discipline<br/>Discipline LS<br/>Fearless]</td></tr>
<tr class="odd"><td>*.edt</td><td><tt>.TRUE</tt></td><td>No</td></tr>
<tr class="odd"><td>*.ed8</td><td><tt>.8Bit</tt></td><td>No</td></tr>
<tr><td>*.afs</td><td><tt>AFS</tt></td><td>No</td><td rowspan="2">PlayStation 2</td><td rowspan="2">Remember11</td></tr>
@ -102,6 +102,8 @@ Swan Song<br/>
<tr class="odd"><td>*.prs</td><td><tt>YB</tt></td><td>No</td></tr>
<tr><td>*.dat</td><td>None</td><td>No</td><td rowspan="2">M no Violet</td><td rowspan="2">Nanase Ren</td></tr>
<tr><td>*</td><td><tt>gra</tt><br/><tt>mas</tt></td><td>No</td></tr>
<tr class="odd"><td>*.ald</td><td>None</td><td>No</td><td rowspan="2">Alice Soft</td><td rowspan="2">Tsuma Shibori</td></tr>
<tr class="odd"><td>*.qnt</td><td><tt>QNT</tt></td><td>No</td></tr>
</table>
<p><a name="note-1">[1]</a> Non-encrypted only</p>
</body>