bunch of stuff.

This commit is contained in:
morkt
2023-08-24 01:33:50 +04:00
parent ea096c52ef
commit 77fde27d26
119 changed files with 11078 additions and 619 deletions

View File

@@ -43,7 +43,7 @@ namespace GameRes.Formats.CandySoft
public FpkOpener ()
{
Signatures = new uint[] { 0, 1 };
ContainedFormats = new[] { "BMP", "KG", "OGG", "SCR", "TXT" };
ContainedFormats = new[] { "BMP", "KG", "OGG", "SCR", "TXT", "DAT/GENERIC" };
}
public override ArcFile TryOpen (ArcView file)
@@ -134,19 +134,19 @@ namespace GameRes.Formats.CandySoft
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
var input = arc.File.CreateStream (entry.Offset, entry.Size);
if (entry.Size <= 8)
return input;
var sign = input.Signature;
if (0x32434c5a != sign) // 'ZLC2'
return input;
using (input)
using (var reader = new Zlc2Reader (input, (int)entry.Size))
IBinaryStream input = arc.File.CreateStream (entry.Offset, entry.Size);
while (input.Length > 8 && input.Signature == 0x32434C5A) // 'ZLC2'
{
reader.Unpack();
return new BinMemoryStream (reader.Data, entry.Name);
IBinaryStream unpacked;
using (input)
using (var reader = new Zlc2Reader (input, (int)input.Length))
{
reader.Unpack();
unpacked = new BinMemoryStream (reader.Data, entry.Name);
}
input = unpacked;
}
return input.AsStream;
}
}

View File

@@ -0,0 +1,111 @@
//! \file ImageBMP.cs
//! \date 2022 Jun 06
//! \brief Candy Soft RLE-compressed bitmap.
//
// Copyright (C) 2022 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.Imaging;
// [980925][Candy Soft] Osananajimi
namespace GameRes.Formats.Interheart
{
internal class BmpRleMetaData : ImageMetaData
{
public int HeaderSize;
public int UnpackedSize;
}
[Export(typeof(ImageFormat))]
public class BmpRleFormat : ImageFormat
{
public override string Tag { get { return "BMP/RLE"; } }
public override string Description { get { return "Candy Soft RLE-compressed bitmap"; } }
public override uint Signature { get { return 0x32504D42; } } // 'BMP24'
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
var header = file.ReadHeader (0x26);
if (!header.AsciiEqual ("BMP24RLE")) // also "BMP08RLE" and "BMP16RLE"
return null;
return new BmpRleMetaData {
Width = header.ToUInt32 (0x1A),
Height = header.ToUInt32 (0x1E),
BPP = header.ToUInt16 (0x24),
HeaderSize = header.ToInt32 (0x12),
UnpackedSize = header.ToInt32 (0x0A),
};
}
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
var meta = (BmpRleMetaData)info;
var output = new byte[meta.UnpackedSize];
file.Position = 8;
file.Read (output, 0, meta.HeaderSize);
var buffer = new byte[3];
int dst = meta.HeaderSize;
// XXX BMMP08 and BMP16 bitmaps use exactly the same algorithm, just different pixel size
file.Read (buffer, 0, 3);
while (dst + 3 <= output.Length)
{
byte r = buffer[0];
byte g = buffer[1];
byte b = buffer[2];
output[dst++] = b;
output[dst++] = g;
output[dst++] = r;
file.Read (buffer, 0, 3);
if (r == buffer[0] && g == buffer[1] && b == buffer[2])
{
if (dst + 3 > output.Length)
break;
output[dst++] = b;
output[dst++] = g;
output[dst++] = r;
int count = file.ReadUInt16();
while (count --> 0)
{
output[dst++] = b;
output[dst++] = g;
output[dst++] = r;
}
file.Read (buffer, 0, 3);
}
}
using (var input = new BinMemoryStream (output))
{
var decoder = new BmpBitmapDecoder (input, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
var frame = decoder.Frames[0];
frame.Freeze();
return new ImageData (frame, info);
}
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("BmpRleFormat.Write not implemented");
}
}
}

View File

@@ -0,0 +1,96 @@
//! \file ImageHMP.cs
//! \date 2022 Jun 16
//! \brief Candy Soft hover map.
//
// Copyright (C) 2022 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 System.Windows.Media.Imaging;
namespace GameRes.Formats.Interheart
{
[Export(typeof(ImageFormat))]
public class HmpFormat : ImageFormat
{
public override string Tag { get { return "HMP"; } }
public override string Description { get { return "Interheart hover map"; } }
public override uint Signature { get { return 0; } }
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
if (!file.Name.HasExtension (".hmp"))
return null;
uint width = file.ReadUInt32();
uint height = file.ReadUInt32();
if (width == 0 || width > 0x7FFF || height == 0 || height > 0x7FFF)
return null;
return new ImageMetaData { Width = width, Height = height, BPP = 8 };
}
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
file.Position = 8;
var pixels = file.ReadBytes (info.iWidth * info.iHeight);
return ImageData.Create (info, PixelFormats.Indexed8, DefaultPalette, pixels);
// return ImageData.Create (info, PixelFormats.Gray8, null, pixels);
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("HmpFormat.Write not implemented");
}
static readonly BitmapPalette DefaultPalette = new BitmapPalette (GenerateColors());
static Color[] GenerateColors ()
{
var colors = new Color[256];
for (int i = 8; i < 256; ++i)
{
colors[i] = Color.FromRgb ((byte)i, (byte)i, (byte)i);
}
colors[0] = Color.FromRgb (0x00, 0x00, 0x00);
colors[1] = Color.FromRgb (0x00, 0x00, 0x7F);
colors[2] = Color.FromRgb (0x00, 0x7F, 0x00);
colors[3] = Color.FromRgb (0x00, 0x7F, 0x7F);
colors[4] = Color.FromRgb (0x7F, 0x00, 0x00);
colors[5] = Color.FromRgb (0x7F, 0x00, 0x7F);
colors[6] = Color.FromRgb (0x7F, 0x7F, 0x00);
colors[7] = Color.FromRgb (0x7F, 0x7F, 0x7F);
colors[8] = Color.FromRgb (0x00, 0x00, 0xFF);
colors[9] = Color.FromRgb (0x00, 0xFF, 0x00);
colors[10] = Color.FromRgb (0x00, 0xFF, 0xFF);
colors[11] = Color.FromRgb (0xFF, 0x00, 0x00);
colors[12] = Color.FromRgb (0xFF, 0x00, 0xFF);
colors[13] = Color.FromRgb (0xFF, 0xFF, 0x00);
colors[14] = Color.FromRgb (0xFF, 0xFF, 0xFF);
colors[15] = Color.FromRgb (0xFF, 0x00, 0x7F);
colors[16] = Color.FromRgb (0xFF, 0x7F, 0x00);
colors[16] = Color.FromRgb (0xFF, 0x7F, 0x7F);
colors[17] = Color.FromRgb (0x7F, 0x00, 0xFF);
colors[18] = Color.FromRgb (0xFF, 0xFF, 0x7F);
return colors;
}
}
}