mirror of
https://github.com/crskycode/GARbro.git
synced 2026-06-06 05:38:48 +08:00
feat: more image formats
This commit is contained in:
176
Experimental/CatSystem/ImageATX.cs
Normal file
176
Experimental/CatSystem/ImageATX.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
//! \file ImageATX.cs
|
||||
//! \date 2026-04-04
|
||||
//! \brief CatSystem for Unity image format.
|
||||
//
|
||||
// Copyright (C) 2026 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.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using SharpZip = ICSharpCode.SharpZipLib.Zip;
|
||||
|
||||
namespace GameRes.Formats.CatSystem {
|
||||
[Serializable]
|
||||
public class LayoutInfo {
|
||||
public LayoutInfo.CanvasInfo Canvas;
|
||||
public List<LayoutInfo.BlockInfo> Block;
|
||||
|
||||
[Serializable]
|
||||
public class CanvasInfo {
|
||||
public uint Width;
|
||||
public uint Height;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class MeshInfo {
|
||||
public int texNo;
|
||||
public float offsetX;
|
||||
public float offsetY;
|
||||
public float srcOffsetX;
|
||||
public float srcOffsetY;
|
||||
public float texU1;
|
||||
public float texV1;
|
||||
public float texU2;
|
||||
public float texV2;
|
||||
public float viewX;
|
||||
public float viewY;
|
||||
public float width;
|
||||
public float height;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class AttributeInfo {
|
||||
public int id;
|
||||
public int x;
|
||||
public int y;
|
||||
public int width;
|
||||
public int height;
|
||||
public int color;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class BlockInfo {
|
||||
public string filename;
|
||||
public string filenameOld;
|
||||
public string blend;
|
||||
public int id;
|
||||
public float anchorX;
|
||||
public float anchorY;
|
||||
public float width;
|
||||
public float height;
|
||||
public float offsetX;
|
||||
public float offsetY;
|
||||
public int priority;
|
||||
public List<LayoutInfo.MeshInfo> Mesh;
|
||||
public List<LayoutInfo.AttributeInfo> Attribute;
|
||||
}
|
||||
}
|
||||
|
||||
internal class AtlasMetaData : ImageMetaData {
|
||||
public List<LayoutInfo.BlockInfo> Blocks;
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class AtxFormat : ImageFormat {
|
||||
public override string Tag { get { return "ATX"; } }
|
||||
public override string Description { get { return "CatSystem for Unity image format"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
|
||||
public AtxFormat() {
|
||||
Extensions = new string[] { "atx" };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData(IBinaryStream stream) {
|
||||
if (0x04034b50 != stream.Signature) // 'PK\3\4'
|
||||
return null;
|
||||
|
||||
var zf = new SharpZip.ZipFile(stream.AsStream);
|
||||
SharpZip.ZipEntry info_entry;
|
||||
|
||||
if ((info_entry = zf.GetEntry("atlas.json")) == null)
|
||||
return null; // protobuf decoding is not supported yet.
|
||||
using (var sr = new StreamReader(zf.GetInputStream(info_entry))) {
|
||||
var info = JsonConvert.DeserializeObject<LayoutInfo>(sr.ReadToEnd());
|
||||
return new AtlasMetaData {
|
||||
Height = info.Canvas.Height,
|
||||
Width = info.Canvas.Width,
|
||||
Blocks = info.Block,
|
||||
BPP = 32
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override ImageData Read(IBinaryStream stream, ImageMetaData info) {
|
||||
var amd = (AtlasMetaData)info;
|
||||
var zf = new SharpZip.ZipFile(stream.AsStream);
|
||||
var textures = new Dictionary<int, byte[]>();
|
||||
var bitmap = new WriteableBitmap(amd.iWidth, amd.iHeight,
|
||||
ImageData.DefaultDpiX, ImageData.DefaultDpiY, PixelFormats.Bgra32, null);
|
||||
foreach (var mesh in amd.Blocks[0].Mesh) { // only process the first image
|
||||
if (!textures.ContainsKey(mesh.texNo)) {
|
||||
SharpZip.ZipEntry tex_entry = null;
|
||||
// https://storage.googleapis.com/downloads.webmproject.org/releases/webp/WebpCodecSetup.exe
|
||||
// install this for webp codec support
|
||||
var availableFormats = new[] { "png", "jpg", "webp" };
|
||||
foreach (var format in availableFormats) {
|
||||
if ((tex_entry = zf.GetEntry($"tex{mesh.texNo}.{format}")) != null)
|
||||
break;
|
||||
}
|
||||
if (tex_entry == null)
|
||||
return null;
|
||||
using (var input = zf.GetInputStream(tex_entry))
|
||||
using (var mem = new MemoryStream()) {
|
||||
input.CopyTo(mem);
|
||||
textures[mesh.texNo] = mem.ToArray();
|
||||
}
|
||||
}
|
||||
using (var mem = new MemoryStream(textures[mesh.texNo])) {
|
||||
var decoder = BitmapDecoder.Create(mem,
|
||||
BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
BitmapSource frame = decoder.Frames[0];
|
||||
if (frame.Format.BitsPerPixel != 32)
|
||||
frame = new FormatConvertedBitmap(frame, PixelFormats.Bgra32, null, 0);
|
||||
int width = (int)mesh.width, height = (int)mesh.height;
|
||||
var rect = new Int32Rect((int)mesh.viewX, (int)mesh.viewY, width, height);
|
||||
int stride = width * 4;
|
||||
var pixels = new byte[stride * height];
|
||||
frame.CopyPixels(rect, pixels, stride, 0);
|
||||
rect = new Int32Rect(0, 0, width, height);
|
||||
bitmap.WritePixels(rect, pixels, stride, (int)mesh.srcOffsetX, (int)mesh.srcOffsetY);
|
||||
}
|
||||
}
|
||||
bitmap.Freeze();
|
||||
return new ImageData(bitmap, info);
|
||||
}
|
||||
|
||||
public override void Write(Stream file, ImageData image) {
|
||||
throw new NotImplementedException("AtxFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,12 @@
|
||||
<Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=1.3.3.11, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
@@ -150,6 +156,7 @@
|
||||
<Compile Include="Artemis\ImageIPT.cs" />
|
||||
<Compile Include="Cabinet\ArcCAB.cs" />
|
||||
<Compile Include="CatSystem\ArcIRIS.cs" />
|
||||
<Compile Include="CatSystem\ImageATX.cs" />
|
||||
<Compile Include="CellWorks\ArcDB.cs" />
|
||||
<Compile Include="Artemis\GplexBuffers.cs" />
|
||||
<Compile Include="Microsoft\ArcEXE.cs" />
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net461" />
|
||||
<package id="MSFTCompressionCab" version="1.0.0" targetFramework="net461" />
|
||||
<package id="NETStandard.Library" version="2.0.3" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net461" />
|
||||
<package id="SharpZipLib" version="1.3.3" targetFramework="net461" />
|
||||
<package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.115.5" targetFramework="net461" />
|
||||
<package id="System.AppContext" version="4.3.0" targetFramework="net461" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net461" />
|
||||
|
||||
@@ -206,6 +206,7 @@
|
||||
<Compile Include="RSystem\ArcRAD.cs" />
|
||||
<Compile Include="RSystem\ImageRSG.cs" />
|
||||
<Compile Include="Ruri\ArcKBM.cs" />
|
||||
<Compile Include="Ruri\ImageKBM.cs" />
|
||||
<Compile Include="Brownie\ArcNAF.cs" />
|
||||
<Compile Include="Brownie\AudioWAV.cs" />
|
||||
<Compile Include="Discovery\ArcDAT.cs" />
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace GameRes.Formats.PenguinWorks {
|
||||
public override ImageMetaData ReadMetaData(IBinaryStream file) {
|
||||
uint width = file.ReadUInt32();
|
||||
uint height = file.ReadUInt32();
|
||||
if (file.Length != 8 + 3 * width * height)
|
||||
return null;
|
||||
return new ImageMetaData {
|
||||
Width = width,
|
||||
Height = height,
|
||||
@@ -53,7 +55,7 @@ namespace GameRes.Formats.PenguinWorks {
|
||||
}
|
||||
|
||||
public override void Write(Stream file, ImageData image) {
|
||||
throw new System.NotImplementedException ("PxlFormat.Write not implemented");
|
||||
throw new System.NotImplementedException("PxlFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
58
Legacy/Ruri/ImageKBM.cs
Normal file
58
Legacy/Ruri/ImageKBM.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
//! \file ImageKBM.cs
|
||||
//! \date 2026-04-16
|
||||
//! \brief Ruri System image format.
|
||||
//
|
||||
// Copyright (C) 2026 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;
|
||||
|
||||
namespace GameRes.Formats.Ruri {
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class KbmFormat : ImageFormat {
|
||||
public override string Tag { get { return "KBM"; } }
|
||||
public override string Description { get { return "Ruri System image format"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public KbmFormat() {
|
||||
Extensions = new string[] { "Kbm" };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData(IBinaryStream stream) {
|
||||
if ((stream.Signature & 0xFFFFFF) != 0x4D424B)
|
||||
return null;
|
||||
stream = BinaryStream.FromStream(new StreamRegion(stream.AsStream, 0x100), stream.Name);
|
||||
return Bmp.ReadMetaData(stream);
|
||||
}
|
||||
|
||||
public override ImageData Read(IBinaryStream stream, ImageMetaData info) {
|
||||
stream = BinaryStream.FromStream(new StreamRegion(stream.AsStream, 0x100), stream.Name);
|
||||
return Bmp.Read(stream, info);
|
||||
}
|
||||
|
||||
public override void Write(Stream file, ImageData image) {
|
||||
throw new NotImplementedException("KbmFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user