From 8b9ddad110a744bdb675f80684bec15eaca269b6 Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 10 Feb 2017 18:00:42 +0400 Subject: [PATCH] implemented Software House Parsley CG archives. --- ArcFormats/ArcCG.cs | 74 -------- ArcFormats/ArcFormats.csproj | 2 +- ArcFormats/Software House Parsley/ArcCG.cs | 201 +++++++++++++++++++++ supported.html | 4 + 4 files changed, 206 insertions(+), 75 deletions(-) delete mode 100644 ArcFormats/ArcCG.cs create mode 100644 ArcFormats/Software House Parsley/ArcCG.cs diff --git a/ArcFormats/ArcCG.cs b/ArcFormats/ArcCG.cs deleted file mode 100644 index 2a1c044d..00000000 --- a/ArcFormats/ArcCG.cs +++ /dev/null @@ -1,74 +0,0 @@ -//! \file ArcCG.cs -//! \date Tue Feb 16 02:48:55 2016 -//! \brief Software House Parsley CG archive. -// -// Copyright (C) 2016 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; - -namespace GameRes.Formats.Parsley -{ - [Export(typeof(ArchiveFormat))] - public class CgOpener : ArchiveFormat - { - public override string Tag { get { return "CG/PARSLEY"; } } - public override string Description { get { return "Software House Parsley CG archive"; } } - public override uint Signature { get { return 0; } } - public override bool IsHierarchic { get { return false; } } - public override bool CanWrite { get { return false; } } - - public CgOpener () - { - Extensions = new string[] { "" }; - } - - public override ArcFile TryOpen (ArcView file) - { - int count = file.View.ReadInt32 (8); - if (!IsSaneCount (count)) - return null; - int first_offset = file.View.ReadInt32 (0x2C); - if (12 + count*0x28 != first_offset) - return null; - - uint index_offset = 0xC; - var dir = new List (count); - for (int i = 0; i < count; ++i) - { - var name = file.View.ReadString (index_offset, 0x20); - if (string.IsNullOrWhiteSpace (name)) - return null; - var entry = FormatCatalog.Instance.Create (name); - entry.Offset = file.View.ReadUInt32 (index_offset+0x20); - entry.Size = file.View.ReadUInt32 (index_offset+0x24); - if (!entry.CheckPlacement (file.MaxOffset)) - return null; - dir.Add (entry); - index_offset += 0x28; - } - return new ArcFile (file, this, dir); - } - } -} diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 5a7e7ec1..601a1da0 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -90,7 +90,7 @@ - + diff --git a/ArcFormats/Software House Parsley/ArcCG.cs b/ArcFormats/Software House Parsley/ArcCG.cs new file mode 100644 index 00000000..08129bf8 --- /dev/null +++ b/ArcFormats/Software House Parsley/ArcCG.cs @@ -0,0 +1,201 @@ +//! \file ArcCG.cs +//! \date Tue Feb 16 02:48:55 2016 +//! \brief Software House Parsley CG archive. +// +// Copyright (C) 2016-2017 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.Linq; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace GameRes.Formats.Parsley +{ + [Export(typeof(ArchiveFormat))] + public class CgOpener : ArchiveFormat + { + public override string Tag { get { return "CG/PARSLEY/2"; } } + public override string Description { get { return "Software House Parsley CG archive"; } } + public override uint Signature { get { return 0; } } + public override bool IsHierarchic { get { return false; } } + public override bool CanWrite { get { return false; } } + + public CgOpener () + { + Extensions = new string[] { "" }; + } + + public override ArcFile TryOpen (ArcView file) + { + int count = file.View.ReadInt32 (8); + if (!IsSaneCount (count)) + return null; + int first_offset = file.View.ReadInt32 (0x2C); + if (12 + count*0x28 != first_offset) + return null; + + uint index_offset = 0xC; + var dir = new List (count); + for (int i = 0; i < count; ++i) + { + var name = file.View.ReadString (index_offset, 0x20); + if (string.IsNullOrWhiteSpace (name)) + return null; + var entry = FormatCatalog.Instance.Create (name); + entry.Offset = file.View.ReadUInt32 (index_offset+0x20); + entry.Size = file.View.ReadUInt32 (index_offset+0x24); + if (!entry.CheckPlacement (file.MaxOffset)) + return null; + dir.Add (entry); + index_offset += 0x28; + } + return new ArcFile (file, this, dir); + } + } + + [Export(typeof(ArchiveFormat))] + public class CgV1Opener : ArchiveFormat + { + public override string Tag { get { return "CG/PARSLEY/1"; } } + public override string Description { get { return "Software House Parsley CG archive"; } } + public override uint Signature { get { return 0; } } + public override bool IsHierarchic { get { return false; } } + public override bool CanWrite { get { return false; } } + + public CgV1Opener () + { + Extensions = new string[] { "" }; + } + + public override ArcFile TryOpen (ArcView file) + { + int count = file.View.ReadInt32 (0); + if (!IsSaneCount (count)) + return null; + var arc_name = Path.GetFileName (file.Name); + bool is_cg = arc_name == "CG"; + + using (var index = file.CreateStream()) + { + index.Position = 4; + var dir = new List (count); + for (int i = 0; i < count; ++i) + { + var name = index.ReadCString(); + if (string.IsNullOrWhiteSpace (name) || name.Length > 0x100) + return null; + var entry = FormatCatalog.Instance.Create (name); + entry.Offset = index.ReadUInt32(); + if (entry.Offset >= file.MaxOffset || entry.Offset < index.Position) + return null; + dir.Add (entry); + } + for (int i = 0; i < count; ++i) + { + var entry = dir[i]; + long next_offset = i+1 < count ? dir[i+1].Offset : file.MaxOffset; + entry.Size = (uint)(next_offset - entry.Offset); + if (is_cg) + entry.Type = "image"; + } + if (is_cg) + { + var palette_entry = dir.FirstOrDefault (e => e.Name.Equals ("Palette", StringComparison.InvariantCultureIgnoreCase)); + if (palette_entry != null && 1 == file.View.ReadByte (palette_entry.Offset+8)) + { + var palette = ImageFormat.ReadPalette (file, palette_entry.Offset+9, 0x100, PaletteFormat.Rgb); + return new CgArchive (file, this, dir, palette); + } + } + return new ArcFile (file, this, dir); + } + } + + public override IImageDecoder OpenImage (ArcFile arc, Entry entry) + { + int type = arc.File.View.ReadByte (entry.Offset+8); + if (type > 1) + return base.OpenImage (arc, entry); + var info = new CgMetaData { + Width = arc.File.View.ReadUInt32 (entry.Offset), + Height = arc.File.View.ReadUInt32 (entry.Offset+4), + BPP = 8, + HasPalette = type == 1, + }; + var cg_arc = arc as CgArchive; + if (cg_arc != null) + info.DefaultPalette = cg_arc.DefaultPalette; + var input = arc.File.CreateStream (entry.Offset, entry.Size); + return new CgDecoder (input, info); + } + } + + internal class CgMetaData : ImageMetaData + { + public bool HasPalette; + public BitmapPalette DefaultPalette; + } + + internal class CgArchive : ArcFile + { + public readonly BitmapPalette DefaultPalette; + + public CgArchive (ArcView arc, ArchiveFormat impl, ICollection dir, BitmapPalette palette) + : base (arc, impl, dir) + { + DefaultPalette = palette; + } + } + + internal class CgDecoder : BinaryImageDecoder + { + bool m_has_palette; + BitmapPalette m_palette; + + public CgDecoder (IBinaryStream input, CgMetaData info) : base (input, info) + { + m_has_palette = info.HasPalette; + m_palette = info.DefaultPalette; + } + + protected override ImageData GetImageData () + { + m_input.Position = 9; + if (m_has_palette) + ReadPalette(); + var pixels = m_input.ReadBytes ((int)(Info.Width * Info.Height)); + if (m_palette != null) + return ImageData.Create (Info, PixelFormats.Indexed8, m_palette, pixels); + else + return ImageData.Create (Info, PixelFormats.Gray8, null, pixels); + } + + void ReadPalette () + { + m_palette = ImageFormat.ReadPalette (m_input.AsStream, 0x100, PaletteFormat.Rgb); + m_input.Position = 0x20909; + } + } +} diff --git a/supported.html b/supported.html index c55e1794..59aeccfb 100644 --- a/supported.html +++ b/supported.html @@ -1429,6 +1429,10 @@ Ikenie Reijou
Tremolo
*.opkVoiceOggPackFileNo +CG-NoSoftware House Parsley +Mugen no Meikyuu 3 Type S
+Phantom Knight Mugen no Meikyuu II
+

1 Non-encrypted only