mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 20:04:13 +08:00
implemented Crowd CWL images.
This commit is contained in:
parent
230f8b8e9f
commit
d7030ecbdc
@ -166,6 +166,7 @@
|
||||
<Compile Include="ImageBMD.cs" />
|
||||
<Compile Include="ImageBMZ.cs" />
|
||||
<Compile Include="ImageCPB.cs" />
|
||||
<Compile Include="ImageCWL.cs" />
|
||||
<Compile Include="ImageCWP.cs" />
|
||||
<Compile Include="ImageDGC.cs" />
|
||||
<Compile Include="ImageDRG.cs" />
|
||||
|
123
ArcFormats/ImageCWL.cs
Normal file
123
ArcFormats/ImageCWL.cs
Normal file
@ -0,0 +1,123 @@
|
||||
//! \file ImageCWL.cs
|
||||
//! \date Sat Jun 13 09:36:33 2015
|
||||
//! \brief Crowd compressed 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.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Crowd
|
||||
{
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class CwdFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "CWD"; } }
|
||||
public override string Description { get { return "Crowd hi-color bitmap"; } }
|
||||
public override uint Signature { get { return 0x20647763u; } } // 'cwd '
|
||||
|
||||
static readonly byte[] SignatureText = Encoding.ASCII.GetBytes ("cwd format - version 1.00 -");
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
{
|
||||
var header = new byte[0x38];
|
||||
if (header.Length != stream.Read (header, 0, header.Length))
|
||||
return null;
|
||||
if (!header.Take (SignatureText.Length).SequenceEqual (SignatureText))
|
||||
return null;
|
||||
uint key = header[0x34] + 0x259Au;
|
||||
return new ImageMetaData
|
||||
{
|
||||
Width = LittleEndian.ToUInt32 (header, 0x2c) + key,
|
||||
Height = LittleEndian.ToUInt32 (header, 0x30) + key,
|
||||
BPP = 15,
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
{
|
||||
stream.Position = 0x38;
|
||||
int size = (int)info.Width * (int)info.Height * 2;
|
||||
var pixels = new byte[size];
|
||||
if (pixels.Length != stream.Read (pixels, 0, pixels.Length))
|
||||
throw new InvalidFormatException ("Unexpected end of file");
|
||||
return ImageData.Create (info, PixelFormats.Bgr555, null, pixels);
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new NotImplementedException ("CwdFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class CwlFormat : CwdFormat
|
||||
{
|
||||
public override string Tag { get { return "CWL"; } }
|
||||
public override string Description { get { return "LZ-compressed Crowd bitmap"; } }
|
||||
public override uint Signature { get { return 0x44445A53u; } } // 'SZDD'
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
{
|
||||
stream.Position = 0x0e;
|
||||
using (var lz = new LzssReader (stream, 100, 0x38)) // extract CWD header
|
||||
{
|
||||
lz.FrameSize = 0x1000;
|
||||
lz.FrameFill = 0x20;
|
||||
lz.FrameInitPos = 0x1000 - 0x10;
|
||||
lz.Unpack();
|
||||
using (var cwd = new MemoryStream (lz.Data))
|
||||
return base.ReadMetaData (cwd);
|
||||
}
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
{
|
||||
if (stream.Length > int.MaxValue)
|
||||
throw new FileSizeException();
|
||||
var header = new byte[14];
|
||||
if (header.Length != stream.Read (header, 0, header.Length))
|
||||
throw new InvalidFormatException();
|
||||
int data_length = LittleEndian.ToInt32 (header, 10);
|
||||
int input_length = (int)(stream.Length-stream.Position);
|
||||
using (var lz = new LzssReader (stream, input_length, data_length))
|
||||
{
|
||||
lz.FrameSize = 0x1000;
|
||||
lz.FrameFill = 0x20;
|
||||
lz.FrameInitPos = 0x1000 - 0x10;
|
||||
lz.Unpack();
|
||||
using (var cwd = new MemoryStream (lz.Data))
|
||||
return base.Read (cwd, info);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new NotImplementedException ("CwlFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
}
|
@ -187,13 +187,15 @@ Onna Kyoushi
|
||||
<tr class="odd"><td>*.bg_<br/>*.cg_</td><td><tt>AP</tt></td><td>Yes</td></tr>
|
||||
<tr><td>*.dpk</td><td>DPK</td><td>No</td><td rowspan="2">DAC</td><td rowspan="2">Yumemiru Tsuki no Lunalutia</td></tr>
|
||||
<tr><td>*.dgc</td><td>DGC</td><td>No</td></tr>
|
||||
<tr class="odd"><td>*.pck</td><td>-</td><td>No</td><td rowspan="4">Crowd</td><td rowspan="4">
|
||||
<tr class="odd"><td>*.pck</td><td>-</td><td>No</td><td rowspan="5">Crowd</td><td rowspan="5">
|
||||
X Change R<br/>
|
||||
X Change<br/>
|
||||
X Change 2<br/>
|
||||
</td></tr>
|
||||
<tr class="odd"><td>*.cwp</td><td><tt>CWDP</tt></td><td>Yes</td></tr>
|
||||
<tr class="odd"><td>*.cwd</td><td><tt>cwd</tt></td><td>No</td></tr>
|
||||
<tr class="odd"><td>*.eog</td><td><tt>CRM</tt></td><td>No</td></tr>
|
||||
<tr class="odd"><td>*.zbm</td><td><tt>SZDD</tt></td><td>No</td></tr>
|
||||
<tr class="odd"><td>*.zbm<br/>*.cwl</td><td><tt>SZDD</tt></td><td>No</td></tr>
|
||||
</table>
|
||||
<p><a name="note-1">[1]</a> Non-encrypted only</p>
|
||||
</body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user