implemented ACHV archives and GPD images.

This commit is contained in:
morkt 2018-04-24 21:00:03 +04:00
parent 12f8fd51a5
commit 12a96e229f
3 changed files with 171 additions and 0 deletions

View File

@ -0,0 +1,73 @@
//! \file ArcDAT.cs
//! \date 2018 Apr 24
//! \brief An*tique resource archive.
//
// Copyright (C) 2018 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.Collections.Generic;
using System.ComponentModel.Composition;
namespace GameRes.Formats.Antique
{
[Export(typeof(ArchiveFormat))]
public class PakOpener : ArchiveFormat
{
public override string Tag { get { return "DAT/ACHV"; } }
public override string Description { get { return "An*tique resource archive"; } }
public override uint Signature { get { return 0x56484341; } } // 'ACHV'
public override bool IsHierarchic { get { return false; } }
public override bool CanWrite { get { return false; } }
public override ArcFile TryOpen (ArcView file)
{
int count = file.View.ReadInt32 (0xC);
if (!IsSaneCount (count))
return null;
uint names_length = file.View.ReadUInt32 (0x10);
uint index_offset = 0x14;
var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i)
{
var entry = new Entry {
Offset = file.View.ReadUInt32 (index_offset),
Size = file.View.ReadUInt32 (index_offset+4),
};
if (!entry.CheckPlacement (file.MaxOffset))
return null;
dir.Add (entry);
index_offset += 0x10;
}
using (var names = file.CreateStream (index_offset, names_length))
{
foreach (var entry in dir)
{
var name = names.ReadCString();
if (string.IsNullOrEmpty (name))
return null;
entry.Name = name;
entry.Type = FormatCatalog.Instance.GetTypeFromName (name);
}
}
return new ArcFile (file, this, dir);
}
}
}

View File

@ -0,0 +1,96 @@
//! \file ImageGPD.cs
//! \date 2018 Apr 24
//! \brief An*tique image format.
//
// Copyright (C) 2018 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.ComponentModel.Composition;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GameRes.Compression;
namespace GameRes.Formats.Antique
{
internal class GpdMetaData : ImageMetaData
{
public int Colors;
}
[Export(typeof(ImageFormat))]
public class GpdFormat : ImageFormat
{
public override string Tag { get { return "GPD"; } }
public override string Description { get { return "An*tique image format"; } }
public override uint Signature { get { return 0x20445047; } } // 'GPD '
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
var header = file.ReadHeader (0x18);
return new GpdMetaData {
Width = header.ToUInt32 (8),
Height = header.ToUInt32 (0x0C),
Colors = header.ToInt32 (0x10),
BPP = header.ToInt32 (0x14),
};
}
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
var meta = (GpdMetaData)info;
PixelFormat format;
if (8 == meta.BPP)
format = PixelFormats.Indexed8;
else if (24 == meta.BPP)
format = PixelFormats.Bgr24;
else if (32 == meta.BPP)
format = PixelFormats.Bgr32;
else
throw new InvalidFormatException();
file.Position = 0x18;
BitmapPalette palette = null;
if (8 == meta.BPP)
palette = ReadPalette (file.AsStream, meta.Colors);
int stride = (int)meta.Width * meta.BPP / 8;
int unpacked_size = stride * (int)meta.Height;
var pixels = new byte[unpacked_size];
int packed_size = file.ReadInt32();
if (-1 == packed_size)
{
file.Read (pixels, 0, unpacked_size);
}
else
{
using (var lzss = new LzssStream (file.AsStream, LzssMode.Decompress, true))
lzss.Read (pixels, 0, unpacked_size);
}
return ImageData.CreateFlipped (info, format, palette, pixels, stride);
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("GpdFormat.Write not implemented");
}
}
}

View File

@ -110,6 +110,8 @@
</Compile>
<Compile Include="Ankh\ArcGRP.cs" />
<Compile Include="Ankh\AudioPCM.cs" />
<Compile Include="Antique\ArcDAT.cs" />
<Compile Include="Antique\ImageGPD.cs" />
<Compile Include="Aoi\ImageAGF.cs" />
<Compile Include="ArcARCX.cs" />
<Compile Include="Artemis\ArcMJA.cs" />