(Legacy): various 'ike' compressed resources.

This commit is contained in:
morkt 2018-03-27 14:33:36 +04:00
parent 2a0b730905
commit 3da10721c5
3 changed files with 149 additions and 3 deletions

View File

@ -23,6 +23,7 @@
// IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
@ -68,9 +69,9 @@ namespace GameRes.Formats.UMeSoft
uint signature;
if (entry.Size > 13 && file.View.AsciiEqual (entry.Offset+2, "ike"))
{
int unpacked_size = file.View.ReadByte (entry.Offset+11)
+ ((file.View.ReadByte (entry.Offset+12)
+ (file.View.ReadByte (entry.Offset+10) >> 2 << 8)) << 8);
int unpacked_size = IkeReader.DecodeSize (file.View.ReadByte (entry.Offset+10),
file.View.ReadByte (entry.Offset+11),
file.View.ReadByte (entry.Offset+12));
entry.IsPacked = true;
entry.UnpackedSize = (uint)unpacked_size;
signature = file.View.ReadUInt32 (entry.Offset+0xF);
@ -109,6 +110,19 @@ namespace GameRes.Formats.UMeSoft
m_output = new byte[unpacked_size];
}
public static int DecodeSize (byte a, byte b, byte c)
{
return b + ((c + (a >> 2 << 8)) << 8);
}
public static IBinaryStream CreateStream (IBinaryStream input, int unpacked_size)
{
input.Position = 0xD;
var ike = new IkeReader (input, unpacked_size);
var data = ike.Unpack();
return new BinMemoryStream (data);
}
public byte[] Unpack ()
{
m_bits = 2;
@ -214,6 +228,7 @@ namespace GameRes.Formats.UMeSoft
}
count = 2;
}
count = Math.Min (count, m_output.Length - dst);
Binary.CopyOverlapped (m_output, dst+offset, dst, count);
dst += count;
}

View File

@ -0,0 +1,55 @@
//! \file AudioIKE.cs
//! \date 2018 Mar 22
//! \brief ike-compressed wave file.
//
// 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;
namespace GameRes.Formats.UMeSoft
{
[Export(typeof(AudioFormat))]
public sealed class IkeAudio : AudioFormat
{
public override string Tag { get { return "WAV/IKE"; } }
public override string Description { get { return "ike-compressed WAVE audio"; } }
public override uint Signature { get { return 0x6B69899D; } }
public override bool CanWrite { get { return false; } }
public override SoundInput TryOpen (IBinaryStream file)
{
var header = file.ReadHeader (0x13);
if (!header.AsciiEqual (2, "ike") || !header.AsciiEqual (0xF, "RIFF"))
return null;
int unpacked_size = IkeReader.DecodeSize (header[10], header[11], header[12]);
var wav = IkeReader.CreateStream (file, unpacked_size);
var sound = Wav.TryOpen (wav);
if (sound != null)
file.Dispose();
else
wav.Dispose();
return sound;
}
}
}

View File

@ -0,0 +1,76 @@
//! \file ImageIKE.cs
//! \date 2018 Mar 22
//! \brief ike-compressed image.
//
// 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;
namespace GameRes.Formats.UMeSoft
{
internal class IkeMetaData : ImageMetaData
{
public int UnpackedSize;
}
[Export(typeof(ImageFormat))]
public class IkeFormat : ImageFormat
{
public override string Tag { get { return "BMP/IKE"; } }
public override string Description { get { return "ike-compressed bitmap"; } }
public override uint Signature { get { return 0x6B69899D; } }
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
var header = file.ReadHeader (0x11);
if (!header.AsciiEqual (2, "ike") || !header.AsciiEqual (0xF, "BM"))
return null;
int unpacked_size = IkeReader.DecodeSize (header[10], header[11], header[12]);
using (var bmp = IkeReader.CreateStream (file, 0x36))
{
var info = Bmp.ReadMetaData (bmp);
if (null == info)
return null;
return new IkeMetaData {
Width = info.Width,
Height = info.Height,
BPP = info.BPP,
UnpackedSize = unpacked_size,
};
}
}
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
var meta = (IkeMetaData)info;
using (var bmp = IkeReader.CreateStream (file, meta.UnpackedSize))
return Bmp.Read (bmp, info);
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("IkeFormat.Write not implemented");
}
}
}