|
| 1 | +//! \file ArcCHR.cs |
| 2 | +//! \date 2018 Apr 08 |
| 3 | +//! \brief Airyu archive format. |
| 4 | +// |
| 5 | +// Copyright (C) 2018 by morkt |
| 6 | +// |
| 7 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +// of this software and associated documentation files (the "Software"), to |
| 9 | +// deal in the Software without restriction, including without limitation the |
| 10 | +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 11 | +// sell copies of the Software, and to permit persons to whom the Software is |
| 12 | +// furnished to do so, subject to the following conditions: |
| 13 | +// |
| 14 | +// The above copyright notice and this permission notice shall be included in |
| 15 | +// all copies or substantial portions of the Software. |
| 16 | +// |
| 17 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 23 | +// IN THE SOFTWARE. |
| 24 | +// |
| 25 | + |
| 26 | +using System.Collections.Generic; |
| 27 | +using System.ComponentModel.Composition; |
| 28 | +using System.Windows.Media; |
| 29 | + |
| 30 | +namespace GameRes.Formats.Airyu |
| 31 | +{ |
| 32 | + [Export(typeof(ArchiveFormat))] |
| 33 | + public class ChrOpener : ArchiveFormat |
| 34 | + { |
| 35 | + public override string Tag { get { return "CHR/AIRYU"; } } |
| 36 | + public override string Description { get { return "Airyu resource archive"; } } |
| 37 | + public override uint Signature { get { return 0; } } |
| 38 | + public override bool IsHierarchic { get { return false; } } |
| 39 | + public override bool CanWrite { get { return false; } } |
| 40 | + |
| 41 | + public override ArcFile TryOpen (ArcView file) |
| 42 | + { |
| 43 | + if (!file.Name.HasExtension (".chr")) |
| 44 | + return null; |
| 45 | + int count = (int)(file.MaxOffset / 0x96000); |
| 46 | + if (!IsSaneCount (count) || count * 0x96000 != file.MaxOffset) |
| 47 | + return null; |
| 48 | + |
| 49 | + uint offset = 0; |
| 50 | + var dir = new List<Entry> (count); |
| 51 | + for (int i = 0; i < count; ++i) |
| 52 | + { |
| 53 | + var entry = new Entry { |
| 54 | + Name = i.ToString ("D5"), |
| 55 | + Type = "image", |
| 56 | + Offset = offset, |
| 57 | + Size = 0x96000, |
| 58 | + }; |
| 59 | + dir.Add (entry); |
| 60 | + offset += 0x96000; |
| 61 | + } |
| 62 | + return new ArcFile (file, this, dir); |
| 63 | + } |
| 64 | + |
| 65 | + public override IImageDecoder OpenImage (ArcFile arc, Entry entry) |
| 66 | + { |
| 67 | + var input = arc.File.CreateStream (entry.Offset, entry.Size); |
| 68 | + return new ChrImageDecoder (input); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + internal class ChrImageDecoder : BinaryImageDecoder |
| 73 | + { |
| 74 | + public ChrImageDecoder (IBinaryStream input) : base (input) |
| 75 | + { |
| 76 | + Info = new ImageMetaData { Width = 640, Height = 480, BPP = 16 }; |
| 77 | + } |
| 78 | + |
| 79 | + protected override ImageData GetImageData () |
| 80 | + { |
| 81 | + var pixels = m_input.ReadBytes (0x96000); |
| 82 | + return ImageData.CreateFlipped (Info, PixelFormats.Bgr555, null, pixels, 640*2); |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments