mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 21:55:34 +08:00
implemented MOE images.
This commit is contained in:
parent
1b317ae539
commit
120b4aa3cd
@ -113,6 +113,8 @@
|
||||
<Compile Include="Ipac\ImageIES.cs" />
|
||||
<Compile Include="Irrlicht\ArcARK.cs" />
|
||||
<Compile Include="Irrlicht\ArcPACK.cs" />
|
||||
<Compile Include="Ivory\ImageMMD.cs" />
|
||||
<Compile Include="Ivory\ImageMOE.cs" />
|
||||
<Compile Include="Kiss\ArcARC.cs" />
|
||||
<Compile Include="KScript\ArcKPC.cs" />
|
||||
<Compile Include="KScript\ImageKGP.cs" />
|
||||
|
155
ArcFormats/Ivory/ImageMMD.cs
Normal file
155
ArcFormats/Ivory/ImageMMD.cs
Normal file
@ -0,0 +1,155 @@
|
||||
//! \file ImageMMD.cs
|
||||
//! \date Thu Sep 08 18:23:14 2016
|
||||
//! \brief Ivory compressed image format.
|
||||
//
|
||||
// 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.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Ivory
|
||||
{
|
||||
internal class MmdMetaData : ImageMetaData
|
||||
{
|
||||
public int Colors;
|
||||
public int Size1;
|
||||
public int Size2;
|
||||
public int Size3;
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class MmdFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "MOE/MMD"; } }
|
||||
public override string Description { get { return "Ivory image format"; } }
|
||||
public override uint Signature { get { return 0x1A444D4D; } } // 'MMD'
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
{
|
||||
var header = new byte[0x18];
|
||||
if (header.Length != stream.Read (header, 0, header.Length))
|
||||
return null;
|
||||
var info = new MmdMetaData
|
||||
{
|
||||
Width = LittleEndian.ToUInt16 (header, 4),
|
||||
Height = LittleEndian.ToUInt16 (header, 6),
|
||||
BPP = 8,
|
||||
Size1 = LittleEndian.ToInt32 (header, 8),
|
||||
Size2 = LittleEndian.ToInt32 (header, 0x0C),
|
||||
Size3 = LittleEndian.ToInt32 (header, 0x10),
|
||||
Colors = LittleEndian.ToInt32 (header, 0x14),
|
||||
};
|
||||
if (info.Size1 <= 0 || info.Size2 <= info.Size1 || info.Size3 <= 0)
|
||||
return null;
|
||||
return info;
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
{
|
||||
var meta = (MmdMetaData)info;
|
||||
var pixels = new byte[info.Width * info.Height];
|
||||
stream.Position = 0x18;
|
||||
using (var input = new ArcView.Reader (stream))
|
||||
{
|
||||
var buf1 = input.ReadBytes (meta.Size1);
|
||||
var buf2 = input.ReadBytes (meta.Size2 - meta.Size1);
|
||||
int w = (int)info.Width / 4;
|
||||
var line = new byte[w];
|
||||
int mask = 0x80;
|
||||
int b1 = 0;
|
||||
int b2 = 0;
|
||||
int dst = 0;
|
||||
for (int y = (int)info.Height; y > 0; --y)
|
||||
{
|
||||
for (int x = 0; x < w; ++x)
|
||||
{
|
||||
if (0 != (mask & buf1[b1]))
|
||||
{
|
||||
line[x] ^= buf2[b2++];
|
||||
}
|
||||
mask >>= 1;
|
||||
if (0 == mask)
|
||||
{
|
||||
mask = 0x80;
|
||||
++b1;
|
||||
}
|
||||
byte p = line[x];
|
||||
int q = p >> 4;
|
||||
for (int j = 0; j < 2; ++j)
|
||||
{
|
||||
if (0 != q)
|
||||
{
|
||||
int offset = ShiftTable[q + 16] + (int)info.Width * ShiftTable[q];
|
||||
int src = dst - offset;
|
||||
pixels[dst++] = pixels[src];
|
||||
pixels[dst++] = pixels[src+1];
|
||||
}
|
||||
else
|
||||
{
|
||||
input.Read (pixels, dst, 2);
|
||||
dst += 2;
|
||||
}
|
||||
q = p & 0xF;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.Position = 0x18 + meta.Size2 + meta.Size3;
|
||||
var palette = ReadPalette (stream, meta.Colors);
|
||||
return ImageData.Create (info, PixelFormats.Indexed8, palette, pixels);
|
||||
}
|
||||
|
||||
static readonly byte[] ShiftTable = {
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16,
|
||||
0, 2, 4, 8, 0, 2, 0, 2, 4, 0, 2, 4, 0, 2, 4, 0,
|
||||
};
|
||||
|
||||
BitmapPalette ReadPalette (Stream input, int colors)
|
||||
{
|
||||
int palette_size = colors * 3;
|
||||
var palette_data = new byte[Math.Max (palette_size, 0x300)];
|
||||
if (palette_size != input.Read (palette_data, 0, palette_size))
|
||||
throw new EndOfStreamException();
|
||||
var palette = new Color[0x100];
|
||||
if (colors > 0x100)
|
||||
colors = 0x100;
|
||||
int src = 0;
|
||||
for (int i = 0; i < palette.Length; ++i)
|
||||
{
|
||||
byte r = palette_data[src++];
|
||||
byte g = palette_data[src++];
|
||||
byte b = palette_data[src++];
|
||||
palette[i] = Color.FromRgb (r, g, b);
|
||||
}
|
||||
return new BitmapPalette (palette);
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new System.NotImplementedException ("MmdFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
}
|
112
ArcFormats/Ivory/ImageMOE.cs
Normal file
112
ArcFormats/Ivory/ImageMOE.cs
Normal file
@ -0,0 +1,112 @@
|
||||
//! \file ImageMOE.cs
|
||||
//! \date Thu Sep 08 17:56:51 2016
|
||||
//! \brief Ivory image format.
|
||||
//
|
||||
// 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.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Ivory
|
||||
{
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class MoeFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "MOE"; } }
|
||||
public override string Description { get { return "Ivory image format"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
{
|
||||
var wh = FormatCatalog.ReadSignature (stream);
|
||||
uint width = wh & 0xFFFF;
|
||||
uint height = wh >> 16;
|
||||
if (0 == width || width > 800 || 0 == height || height > 600)
|
||||
return null;
|
||||
if (!IsValidInput (stream, width, height))
|
||||
return null;
|
||||
return new ImageMetaData { Width = width, Height = height, BPP = 24 };
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
{
|
||||
stream.Position = 4;
|
||||
var pixels = new byte[3 * info.Width * info.Height];
|
||||
int dst = 0;
|
||||
while (dst < pixels.Length)
|
||||
{
|
||||
int count = stream.ReadByte();
|
||||
if (-1 == count)
|
||||
throw new EndOfStreamException();
|
||||
if (0 != (count & 0x80))
|
||||
{
|
||||
count = 3 * (count & 0x7F);
|
||||
stream.Read (pixels, dst, count);
|
||||
dst += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
count *= 3;
|
||||
stream.Read (pixels, dst, 3);
|
||||
Binary.CopyOverlapped (pixels, dst, dst+3, count-3);
|
||||
dst += count;
|
||||
}
|
||||
}
|
||||
return ImageData.Create (info, PixelFormats.Bgr24, null, pixels);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to interpret input stream as a compressed image.
|
||||
/// </summary>
|
||||
bool IsValidInput (Stream input, uint width, uint height)
|
||||
{
|
||||
int total = (int)width * (int)height;
|
||||
int dst = 0;
|
||||
while (dst < total)
|
||||
{
|
||||
int count = input.ReadByte();
|
||||
if (-1 == count)
|
||||
return false;
|
||||
if (0 != (count & 0x80))
|
||||
{
|
||||
count &= 0x7F;
|
||||
input.Seek (count * 3, SeekOrigin.Current);
|
||||
}
|
||||
else
|
||||
{
|
||||
input.Seek (3, SeekOrigin.Current);
|
||||
}
|
||||
dst += count;
|
||||
if (dst > total)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new System.NotImplementedException ("MoeFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
}
|
@ -105,6 +105,7 @@ Daisaimin Rankou Gakuen<br/>
|
||||
Haitoku no Gakuen ~Yami ni Sasagerareta Otome-tachi~<br/>
|
||||
Haitoku no Gakuen 2 ~Yami o Tsugu Mono~<br/>
|
||||
Injoku Shinryuu Club<br/>
|
||||
Mashou no Nie 2<br/>
|
||||
Moon.<br/>
|
||||
Ryoujoku Famiresu Choukyou Menu<br/>
|
||||
Ryoujoku Idol Mesu Dorei<br/>
|
||||
@ -175,6 +176,7 @@ Tsukihime<br/>
|
||||
Umineko<br/>
|
||||
</td></tr>
|
||||
<tr><td>*.pac</td><td><tt>PAC</tt></td><td>No</td><td rowspan="2">NeXAS</td><td rowspan="2">
|
||||
Aqua Blue<br/>
|
||||
Baldr Sky DiveX<br/>
|
||||
Fossette ~Cafe au Le Ciel Bleu~<br/>
|
||||
Jinki Extend Re:Vision<br/>
|
||||
@ -237,6 +239,7 @@ Damegane<br/>
|
||||
Distance<br/>
|
||||
ExE<br/>
|
||||
Fair Child<br/>
|
||||
Fantasical<br/>
|
||||
Fate/stay night<br/>
|
||||
Fate/hollow ataraxia<br/>
|
||||
G-senjou no Maou<br/>
|
||||
@ -324,6 +327,7 @@ Shoujo Senki Soul Eater<br/>
|
||||
<tr><td>*.dat</td><td>-</td><td>No</td><td rowspan="2">M no Violet<br/>Snack Factory<br/></td><td rowspan="2">
|
||||
Nanase Ren<br/>
|
||||
Imouto ~Mitsutsubo Complete Edition~<br/>
|
||||
Ren no Koi<br/>
|
||||
</td></tr>
|
||||
<tr><td>*</td><td><tt>gra</tt><br/><tt>mas</tt><br/><tt>dif</tt></td><td>No</td></tr>
|
||||
<tr class="odd"><td>*.ald</td><td>-</td><td>No</td><td rowspan="5">Alice Soft</td><td rowspan="5">
|
||||
@ -388,6 +392,7 @@ Enkaku Sousa <span class="footnote">2.36 or 2.37</span><br/>
|
||||
Gohoushi Nurse ~Mayonaka no Kyousei Call~ <span class="footnote">ShiinaRio v2.50</span><br/>
|
||||
Helter Skelter <span class="footnote">ShiinaRio v2.40</span><br/>
|
||||
Hitozuma Onna Kyoushi Reika <span class="footnote">ShiinaRio v2.39</span><br/>
|
||||
Intruder <span class="footnote">ShiinaRio v2.49</span><br/>
|
||||
Itsuka, Dokoka de ~Ano Ameoto no Kioku~<span class="footnote">2.36 or 2.37</span><br/>
|
||||
Kichiku Nakadashi Suieibu<span class="footnote">ShiinaRio v2.41</span><br/>
|
||||
Mahou Shoujo no Taisetsu na Koto <span class="footnote">ShiinaRio v2.47</span><br/>
|
||||
@ -402,6 +407,7 @@ Rin×Sen <span class="footnote">ShiinaRio v2.47</span><br/>
|
||||
Sabae no Ou <span class="footnote">ShiinaRio v2.36</span><br/>
|
||||
Shinigami no Testament <span class="footnote">ShiinaRio v2.49</span><br/>
|
||||
Shojo Mama<span class="footnote">ShiinaRio v2.49</span><br/>
|
||||
Sorcery Jokers<span class="footnote">ShiinaRio v2.50</span><br/>
|
||||
Tantei Shounen A<span class="footnote">some old version, like 2.twenty-something</span><br/>
|
||||
Tekoire Princess!<span class="footnote">ShiinaRio v2.37</span><br/>
|
||||
Wana ~Hakudaku Mamire no Houkago~<span class="footnote">ShiinaRio v2.36</span><br/>
|
||||
@ -613,6 +619,7 @@ Tutorial Summer<br/>
|
||||
<tr class="odd"><td>*.wbp</td><td><tt>ARCFORM3 WBUG</tt><br/><tt>ARCFORM4 WBUG</tt></td><td>No</td><td rowspan="4">Wild Bug</td><td rowspan="4">
|
||||
Happy Planning<br/>
|
||||
Ryoujoku Hitozuma Club<br/>
|
||||
Sister Angel<br/>
|
||||
Yuukyou Gangu 2<br/>
|
||||
</td></tr>
|
||||
<tr class="odd"><td>*.wbm</td><td><tt>WPX\x1ABMP</tt></td><td>No</td></tr>
|
||||
@ -1092,6 +1099,9 @@ Inumimi Berserk<br/>
|
||||
</td></tr>
|
||||
<tr><td>*.kgp</td><td><tt>GRPH</tt></td><td>No</td></tr>
|
||||
<tr><td>*.ksl</td><td><tt>KSLM</tt></td><td>No</td></tr>
|
||||
<tr class="odd"><td>*.moe</td><td>-<br/><tt>MMD\x1A</tt></td><td>No</td><td>Ivory</td><td>
|
||||
Triangle Heart<br/>
|
||||
</td></tr>
|
||||
</table>
|
||||
<p><a name="note-1" class="footnote">1</a> Non-encrypted only</p>
|
||||
</body>
|
||||
|
Loading…
Reference in New Issue
Block a user