reorganized project directory structure.

This commit is contained in:
morkt
2015-08-19 21:40:32 +04:00
parent dd2c19c8c1
commit b05c253e8b
178 changed files with 6029 additions and 6016 deletions

View File

@@ -0,0 +1,112 @@
//! \file ArcS25.cs
//! \date Sat Apr 18 15:56:57 2015
//! \brief ShiinaRio image resource.
//
// 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.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GameRes.Utility;
namespace GameRes.Formats.ShiinaRio
{
[Export(typeof(ArchiveFormat))]
public class S25Opener : ArchiveFormat
{
public override string Tag { get { return "S25"; } }
public override string Description { get { return "ShiinaRio engine multi-image"; } }
public override uint Signature { get { return 0x00353253; } } // 'S25'
public override bool IsHierarchic { get { return false; } }
public override bool CanCreate { get { return false; } }
public override ArcFile TryOpen (ArcView file)
{
int count = file.View.ReadInt32 (4);
if (count <= 0 || count > 0xfffff)
return null;
var base_name = Path.GetFileNameWithoutExtension (file.Name);
var dir = new List<Entry> (count);
uint index_offset = 8;
for (int i = 0; i < count; ++i)
{
uint offset = file.View.ReadUInt32 (index_offset);
index_offset += 4;
if (offset > 0 && offset <= file.MaxOffset)
{
var entry = new Entry
{
Name = string.Format ("{0}@{1:D4}.tga", base_name, i),
Type = "image",
Offset = offset,
};
dir.Add (entry);
}
}
dir.Sort ((a, b) => (int)(a.Offset - b.Offset));
for (int i = 0; i < dir.Count; ++i)
{
long next_offset;
if (i+1 == dir.Count)
next_offset = file.MaxOffset;
else
next_offset = dir[i+1].Offset;
dir[i].Size = (uint)(next_offset - dir[i].Offset);
}
return new ArcFile (file, this, dir);
}
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
// emulate TGA image
var offset = entry.Offset;
var info = new S25MetaData
{
Width = arc.File.View.ReadUInt32 (offset),
Height = arc.File.View.ReadUInt32 (offset+4),
OffsetX = arc.File.View.ReadInt32 (offset+8),
OffsetY = arc.File.View.ReadInt32 (offset+12),
BPP = 32,
FirstOffset = (uint)(offset + 0x14),
Incremental = 0 != (arc.File.View.ReadUInt32 (offset+0x10) & 0x80000000u),
};
using (var input = arc.File.CreateStream (0, (uint)arc.File.MaxOffset))
using (var reader = new S25Format.Reader (input, info))
{
var pixels = reader.Unpack();
var header = new byte[0x12];
header[2] = 2;
LittleEndian.Pack ((short)info.OffsetX, header, 8);
LittleEndian.Pack ((short)info.OffsetY, header, 0xa);
LittleEndian.Pack ((ushort)info.Width, header, 0xc);
LittleEndian.Pack ((ushort)info.Height, header, 0xe);
header[0x10] = 32;
header[0x11] = 0x20;
return new PrefixStream (header, new MemoryStream (pixels));
}
}
}
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
//! \file AudioOGV.cs
//! \date Sat Apr 18 14:18:47 2015
//! \brief ShiinaRio Ogg/Vorbis audio 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.ComponentModel.Composition;
using System.IO;
using GameRes.Utility;
namespace GameRes.Formats.ShiinaRio
{
[Export(typeof(AudioFormat))]
public class OgvAudio : OggAudio
{
public override string Tag { get { return "OGV"; } }
public override string Description { get { return "ShiinaRio audio format (Ogg/Vorbis)"; } }
public override uint Signature { get { return 0x0056474f; } } // 'OGV'
public override SoundInput TryOpen (Stream file)
{
file.Position = 0xc;
var header = new byte[8];
if (8 != file.Read (header, 0, 8))
return null;
if (!Binary.AsciiEqual (header, 0, "fmt "))
return null;
uint offset = LittleEndian.ToUInt32 (header, 4);
file.Seek (offset, SeekOrigin.Current);
if (8 != file.Read (header, 0, 8))
return null;
if (!Binary.AsciiEqual (header, 0, "data"))
return null;
var input = new StreamRegion (file, file.Position);
return new OggInput (input);
// input is left undisposed in case of exception.
}
}
}

View File

@@ -0,0 +1,183 @@
//! \file AudioPAD.cs
//! \date Sun Jun 21 23:44:18 2015
//! \brief ShiinaRio compressed audio 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 GameRes.Utility;
namespace GameRes.Formats.ShiinaRio
{
[Export(typeof(AudioFormat))]
public class PadAudio : AudioFormat
{
public override string Tag { get { return "PAD"; } }
public override string Description { get { return "ShiinaRio compressed audio format"; } }
public override uint Signature { get { return 0x444150; } } // 'PAD'
public override SoundInput TryOpen (Stream file)
{
var wav_header = new byte[0x2c];
if (0x2c != file.Read (wav_header, 0, 0x2c))
return null;
int pcm_size = LittleEndian.ToInt32 (wav_header, 0x28);
int channels = LittleEndian.ToUInt16 (wav_header, 0x16);
wav_header[0] = (byte)'R';
wav_header[1] = (byte)'I';
wav_header[2] = (byte)'F';
wav_header[3] = (byte)'F';
LittleEndian.Pack (pcm_size+0x24, wav_header, 4);
var decoder = new PadDecoder (file, pcm_size, channels);
decoder.Unpack();
var data = new MemoryStream (decoder.Data, 0, pcm_size);
var wav = new PrefixStream (wav_header, data);
try
{
return new WaveInput (wav);
}
catch
{
wav.Dispose();
throw;
}
}
}
internal class PadDecoder
{
byte[] m_input;
byte[] m_output;
int m_pcm_size;
int m_packed_size;
int m_channels;
public byte[] Data { get { return m_output; } }
public PadDecoder (Stream input, int pcm_size, int channels)
{
m_packed_size = (int)(input.Length - input.Position);
m_pcm_size = pcm_size;
m_channels = channels;
m_output = new byte[pcm_size + 0x9c];
m_input = new byte[m_packed_size];
if (m_packed_size != input.Read (m_input, 0, m_packed_size))
throw new InvalidFormatException ("Unexpected end of file");
}
public byte[] Unpack ()
{
int v10;
double v3 = 0;
double v27 = 0;
double v28 = 0;
int v30 = 0;
var table = new double[69];
table[4] = 0.9375; // 0x3FEE000000000000
table[6] = 1.796875; // 0x3FFCC00000000000
table[7] = -0.8125; // 0xBFEA000000000000
table[8] = 1.53125; // 0x3FF8800000000000
table[9] = -0.859375; // 0xBFEB800000000000
table[10] = 1.90625; // 0x3FFE800000000000
table[11] = -0.9375; // 0xBFEE000000000000
int dst = 0;
int src = 0;
int v5 = m_input[src++];
while (v5 != 0xff)
{
int v7 = m_input[src++];
int v29 = v7 >> 4;
int v9 = v7 & 0xF;
if (2 == m_channels)
{
int next = m_input[src+1];
v10 = next & 0xF;
v30 = next >> 4;
long v = BitConverter.DoubleToInt64Bits (table[12]) & 0xffffffffL;
table[12] = BitConverter.Int64BitsToDouble (v | (long)v10 << 32);
src += 2;
}
else
{
v10 = (int)(BitConverter.DoubleToInt64Bits (table[12]) >> 32);
}
int v12 = 14; // within table
for (int i = 0; i < 14; ++i)
{
int v13 = m_input[src++];
int v14 = (v13 & 0xF) << 12;
if (0 != (v14 & 0x8000))
v14 |= ~0xFFFF;
int v15 = (v13 & 0xF0) << 8;
table[v12 - 1] = (double)(v14 >> v9);
if (0 != (v15 & 0x8000))
v15 |= ~0xFFFF;
table[v12] = (double)(v15 >> v9);
v12 += 2;
}
if (2 == m_channels)
{
v12 = 42; // within table
for (int i = 0; i < 14; ++i)
{
int v18 = m_input[src++];
int v19 = (v18 & 0xF) << 12;
if (0 != (v19 & 0x8000))
v19 |= ~0xFFFF;
int v20 = (byte)(v18 & 0xF0) << 8;
table[v12 - 1] = (double)(v19 >> v10);
if (0 != (v20 & 0x8000))
v20 |= ~0xFFFF;
table[v12] = (double)(v20 >> v10);
v12 += 2;
}
}
v12 = 41; // within table
for (int i = 0; i < 28; ++i)
{
double v22 = v27 * table[2 * v29 + 3];
v27 = table[0];
table[v12 - 28] += v22 + v27 * table[2 * v29 + 2];
table[0] = table[v12 - 28];
LittleEndian.Pack ((short)(table[v12 - 28] + 0.5), m_output, dst);
dst += 2;
if (2 == m_channels)
{
table[v12] += v28 * table[2 * v30 + 3] + v3 * table[2 * v30 + 2];
v28 = v3;
v3 = table[v12];
LittleEndian.Pack ((short)(table[v12] + 0.5), m_output, dst);
dst += 2;
}
++v12;
}
v5 = m_input[src++];
}
return m_output;
}
}
}

View File

@@ -0,0 +1,219 @@
//! \file ImageMI4.cs
//! \date Sun Jul 12 15:40:39 2015
//! \brief ShiinaRio engine 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.Windows.Media;
namespace GameRes.Formats.ShiinaRio
{
[Export(typeof(ImageFormat))]
public class Mi4Format : ImageFormat
{
public override string Tag { get { return "MI4"; } }
public override string Description { get { return "ShiinaRio image format"; } }
public override uint Signature { get { return 0x3449414D; } } // 'MAI4'
public override ImageMetaData ReadMetaData (Stream stream)
{
stream.Seek (8, SeekOrigin.Current);
using (var input = new ArcView.Reader (stream))
{
uint width = input.ReadUInt32();
uint height = input.ReadUInt32();
return new ImageMetaData
{
Width = width,
Height = height,
BPP = 24,
};
}
}
public override ImageData Read (Stream stream, ImageMetaData info)
{
stream.Position = 0x10;
using (var reader = new Reader (stream, (int)info.Width, (int)info.Height))
{
reader.Unpack ();
return ImageData.Create (info, PixelFormats.Bgr24, null, reader.Data);
}
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("Mi4Format.Write not implemented");
}
internal sealed class Reader : IDisposable
{
BinaryReader m_input;
byte[] m_output;
int m_stride;
public byte[] Data { get { return m_output; } }
public Reader (Stream file, int width, int height)
{
m_input = new ArcView.Reader (file);
m_stride = width * 3;
m_output = new byte[m_stride*height];
}
uint m_bit_count;
uint m_bits;
void ResetBits ()
{
m_bits = m_input.ReadUInt32();
m_bit_count = 32;
}
uint GetBit ()
{
uint bit = m_bits >> 31;
m_bits <<= 1;
if (0 == --m_bit_count)
{
m_bits = m_input.ReadUInt32();
m_bit_count = 32;
}
return bit;
}
uint GetBits (int count)
{
uint bits = 0;
while (count --> 0)
{
bits = (bits << 1) | GetBit();
}
return bits;
}
public void Unpack ()
{
ResetBits();
int dst = 0;
byte b = 0, g = 0, r = 0;
while (dst < m_output.Length)
{
if (GetBit() == 0)
{
if (GetBit() != 0)
{
b = m_input.ReadByte();
g = m_input.ReadByte();
r = m_input.ReadByte();
}
else if (GetBit() != 0)
{
byte v = (byte)(GetBits(2));
if (3 == v)
{
b = m_output[dst - m_stride];
g = m_output[dst - m_stride + 1];
r = m_output[dst - m_stride + 2];
}
else
{
b += (byte)(v - 1);
v = (byte)GetBits (2);
if (3 == v)
{
if (GetBit() != 0)
{
b = m_output[dst - m_stride - 3];
g = m_output[dst - m_stride - 2];
r = m_output[dst - m_stride - 1];
}
else
{
b = m_output[dst - m_stride + 3];
g = m_output[dst - m_stride + 4];
r = m_output[dst - m_stride + 5];
}
}
else
{
g += (byte)(v - 1);
r += (byte)(GetBits(2) - 1);
}
}
}
else if (GetBit() != 0)
{
byte v = (byte)(GetBits(3));
if (7 == v)
{
b = m_output[dst - m_stride];
g = m_output[dst - m_stride + 1];
r = m_output[dst - m_stride + 2];
b += (byte)(GetBits(3) - 3);
g += (byte)(GetBits(3) - 3);
r += (byte)(GetBits(3) - 3);
}
else
{
b += (byte)(v - 3);
g += (byte)(GetBits(3) - 3);
r += (byte)(GetBits(3) - 3);
}
}
else if (GetBit() != 0)
{
b += (byte)(GetBits(4) - 7);
g += (byte)(GetBits(4) - 7);
r += (byte)(GetBits(4) - 7);
}
else
{
b += (byte)(GetBits(5) - 15);
g += (byte)(GetBits(5) - 15);
r += (byte)(GetBits(5) - 15);
}
}
m_output[dst++] = b;
m_output[dst++] = g;
m_output[dst++] = r;
}
}
#region IDisposable Members
bool disposed = false;
public void Dispose ()
{
if (!disposed)
{
m_input.Dispose ();
disposed = true;
}
GC.SuppressFinalize (this);
}
#endregion
}
}
}

View File

@@ -0,0 +1,384 @@
//! \file ImageS25.cs
//! \date Sat Apr 18 17:00:54 2015
//! \brief ShiinaRio S25 multi-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.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GameRes.Utility;
namespace GameRes.Formats.ShiinaRio
{
internal class S25MetaData : ImageMetaData
{
public uint FirstOffset;
public bool Incremental;
}
[Export(typeof(ImageFormat))]
public class S25Format : ImageFormat
{
public override string Tag { get { return "S25"; } }
public override string Description { get { return "ShiinaRio image format"; } }
public override uint Signature { get { return 0x00353253; } } // 'S25'
// in current implementation, only the first frame is returned.
// per-frame access is provided by S25Opener class.
public override ImageMetaData ReadMetaData (Stream stream)
{
using (var input = new ArcView.Reader (stream))
{
input.ReadUInt32();
int count = input.ReadInt32();
if (count < 0 || count > 0xfffff)
return null;
uint first_offset = input.ReadUInt32();
if (0 == first_offset)
return null;
input.BaseStream.Position = first_offset;
var info = new S25MetaData();
info.Width = input.ReadUInt32();
info.Height = input.ReadUInt32();
info.OffsetX = input.ReadInt32();
info.OffsetY = input.ReadInt32();
info.FirstOffset = first_offset+0x14;
info.Incremental = 0 != (input.ReadUInt32() & 0x80000000u);
info.BPP = 32;
return info;
}
}
public override ImageData Read (Stream stream, ImageMetaData info)
{
var meta = info as S25MetaData;
if (null == meta)
throw new ArgumentException ("S25Format.Read should be supplied with S25MetaData", "info");
using (var reader = new Reader (stream, meta))
{
var pixels = reader.Unpack();
return ImageData.Create (info, PixelFormats.Bgra32, null, pixels);
}
}
public override void Write (Stream file, ImageData image)
{
throw new NotImplementedException ("S25Format.Write not implemented");
}
internal class Reader : IDisposable
{
BinaryReader m_input;
int m_width;
int m_height;
uint m_origin;
byte[] m_output;
bool m_incremental;
public byte[] Data { get { return m_output; } }
public Reader (Stream file, S25MetaData info)
{
m_width = (int)info.Width;
m_height = (int)info.Height;
m_output = new byte[m_width * m_height * 4];
m_input = new ArcView.Reader (file);
m_origin = info.FirstOffset;
m_incremental = info.Incremental;
}
public byte[] Unpack ()
{
m_input.BaseStream.Position = m_origin;
if (m_incremental)
return UnpackIncremental();
var rows = new uint[m_height];
for (int i = 0; i < rows.Length; ++i)
rows[i] = m_input.ReadUInt32();
var row_buffer = new byte[m_width];
int dst = 0;
for (int y = 0; y < m_height && dst < m_output.Length; ++y)
{
uint row_pos = rows[y];
m_input.BaseStream.Position = row_pos;
int row_length = m_input.ReadUInt16();
row_pos += 2;
if (0 != (row_pos & 1))
{
m_input.ReadByte();
--row_length;
}
if (row_buffer.Length < row_length)
row_buffer = new byte[row_length];
m_input.Read (row_buffer, 0, row_length);
dst = UnpackLine (row_buffer, dst);
}
return m_output;
}
void UpdateRepeatCount (Dictionary<uint, int> rows_count)
{
m_input.BaseStream.Position = 4;
int count = m_input.ReadInt32();
var frames = new List<uint> (count);
for (int i = 0; i < count; ++i)
{
var offset = m_input.ReadUInt32();
if (0 != offset)
frames.Add (offset);
}
foreach (var offset in frames)
{
if (offset+0x14 == m_origin)
continue;
m_input.BaseStream.Position = offset+4;
int height = m_input.ReadInt32();
m_input.BaseStream.Position = offset+0x14;
for (int i = 0; i < height; ++i)
{
var row_offset = m_input.ReadUInt32();
if (rows_count.ContainsKey (row_offset))
++rows_count[row_offset];
}
}
}
byte[] UnpackIncremental ()
{
var rows = new uint[m_height];
var rows_count = new Dictionary<uint, int> (m_height);
for (int i = 0; i < rows.Length; ++i)
{
uint offset = m_input.ReadUInt32();
rows[i] = offset;
if (rows_count.ContainsKey (offset))
++rows_count[offset];
else
rows_count[offset] = 1;
}
UpdateRepeatCount (rows_count);
var input_rows = new Dictionary<uint, byte[]> (m_height);
var input_lines = new byte[m_height][];
for (int y = 0; y < m_height; ++y)
{
uint row_pos = rows[y];
// if (183 == y)
// System.Diagnostics.Debugger.Break();
// if (0x82 == y)
// System.Diagnostics.Debugger.Break();
if (input_rows.ContainsKey (row_pos))
{
input_lines[y] = input_rows[row_pos];
continue;
}
var row = ReadLine (row_pos, rows_count[row_pos]);
input_rows[row_pos] = row;
input_lines[y] = row;
}
int dst = 0;
foreach (var line in input_lines)
{
dst = UnpackLine (line, dst);
}
return m_output;
}
int UnpackLine (byte[] line, int dst)
{
int row_pos = 0;
for (int x = m_width; x > 0 && dst < m_output.Length && row_pos < line.Length; )
{
if (0 != (row_pos & 1))
{
++row_pos;
}
int count = LittleEndian.ToUInt16 (line, row_pos);
row_pos += 2;
int method = count >> 13;
int skip = (count >> 11) & 3;
if (0 != skip)
{
row_pos += skip;
}
count &= 0x7ff;
if (0 == count)
{
count = LittleEndian.ToInt32 (line, row_pos);
row_pos += 4;
}
if (count > x) count = x;
x -= count;
byte b, g, r, a;
switch (method)
{
case 2:
for (int i = 0; i < count && row_pos < line.Length; ++i)
{
m_output[dst++] = line[row_pos++];
m_output[dst++] = line[row_pos++];
m_output[dst++] = line[row_pos++];
m_output[dst++] = 0xff;
}
break;
case 3:
b = line[row_pos++];
g = line[row_pos++];
r = line[row_pos++];
for (int i = 0; i < count; ++i)
{
m_output[dst++] = b;
m_output[dst++] = g;
m_output[dst++] = r;
m_output[dst++] = 0xff;
}
break;
case 4:
for (int i = 0; i < count && row_pos < line.Length; ++i)
{
a = line[row_pos++];
m_output[dst++] = line[row_pos++];
m_output[dst++] = line[row_pos++];
m_output[dst++] = line[row_pos++];
m_output[dst++] = a;
}
break;
case 5:
a = line[row_pos++];
b = line[row_pos++];
g = line[row_pos++];
r = line[row_pos++];
for (int i = 0; i < count; ++i)
{
m_output[dst++] = b;
m_output[dst++] = g;
m_output[dst++] = r;
m_output[dst++] = a;
}
break;
default:
dst += count * 4;
break;
}
}
return dst;
}
byte[] ReadLine (uint offset, int repeat)
{
m_input.BaseStream.Position = offset;
int row_length = m_input.ReadUInt16();
if (0 != (offset & 1))
{
m_input.ReadByte();
--row_length;
}
var row = new byte[row_length];
m_input.Read (row, 0, row.Length);
int row_pos = 0;
for (int x = m_width; x > 0; )
{
if (0 != (row_pos & 1))
{
++row_pos;
}
int count = LittleEndian.ToUInt16 (row, row_pos);
row_pos += 2;
int method = count >> 13;
int skip = (count >> 11) & 3;
if (0 != skip)
{
row_pos += skip;
}
count &= 0x7ff;
if (0 == count)
{
count = LittleEndian.ToInt32 (row, row_pos);
row_pos += 4;
}
if (count < 0 || count > x) count = x;
x -= count;
switch (method)
{
case 2:
for (int j = 0; j < repeat; ++j)
{
for (int i = 3; i < count*3 && row_pos+i < row.Length; ++i)
{
row[row_pos+i] += row[row_pos+i-3];
}
}
row_pos += count*3;
break;
case 3:
row_pos += 3;
break;
case 4:
for (int j = 0; j < repeat; ++j)
{
for (int i = 4; i < count*4 && row_pos+i < row.Length; ++i)
{
row[row_pos+i] += row[row_pos+i-4];
}
}
row_pos += count*4;
break;
case 5:
row_pos += 4;
break;
default:
break;
}
}
return row;
}
#region IDisposable Members
bool disposed = false;
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
if (!disposed)
{
if (disposing)
m_input.Dispose();
disposed = true;
}
}
#endregion
}
}
}

View File

@@ -0,0 +1,19 @@
<Grid x:Class="GameRes.Formats.GUI.WidgetWARC"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:fmt="clr-namespace:GameRes.Formats.ShiinaRio"
xmlns:p="clr-namespace:GameRes.Formats.Properties"
MaxWidth="250">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<ComboBox Name="Scheme" ItemsSource="{Binding Source={x:Static fmt:Decoder.KnownSchemes}, Mode=OneWay}"
SelectedValue="{Binding Source={x:Static p:Settings.Default}, Path=WARCScheme, Mode=TwoWay}"
SelectedValuePath="Name"
DisplayMemberPath="Name"
Width="200" Grid.Row="0"/>
<TextBox Name="Original" Background="Transparent" BorderThickness="0" Text="{Binding Path=OriginalTitle}"
IsReadOnly="True" TextWrapping="NoWrap" Grid.Row="1" Margin="0,3,0,3"
DataContext="{Binding ElementName=Scheme, Path=SelectedItem}"/>
</Grid>

View File

@@ -0,0 +1,22 @@
using System.Windows;
using System.Windows.Controls;
using System.Linq;
using GameRes.Formats.Properties;
using GameRes.Formats.Strings;
namespace GameRes.Formats.GUI
{
/// <summary>
/// Interaction logic for WidgetWARC.xaml
/// </summary>
public partial class WidgetWARC : Grid
{
public WidgetWARC ()
{
InitializeComponent();
// select the most recent scheme as default
if (-1 == Scheme.SelectedIndex)
Scheme.SelectedIndex = Scheme.ItemsSource.Cast<object>().Count()-1;
}
}
}