From 7347e5fac586cfbd03536c942d325806a525179f Mon Sep 17 00:00:00 2001 From: morkt Date: Sun, 5 Jun 2016 23:36:27 +0400 Subject: [PATCH] implemented SYG images. --- ArcFormats/ArcFormats.csproj | 2 + ArcFormats/WestVision/ImageSYG.cs | 97 +++++++++++++++++++++++++++++++ supported.html | 4 ++ 3 files changed, 103 insertions(+) create mode 100644 ArcFormats/WestVision/ImageSYG.cs diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 8769bcfa..18e7c3b4 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -321,6 +321,7 @@ Code + @@ -651,6 +652,7 @@ + perl "$(SolutionDir)inc-revision.pl" "$(ProjectPath)" $(ConfigurationName) diff --git a/ArcFormats/WestVision/ImageSYG.cs b/ArcFormats/WestVision/ImageSYG.cs new file mode 100644 index 00000000..268e4bfb --- /dev/null +++ b/ArcFormats/WestVision/ImageSYG.cs @@ -0,0 +1,97 @@ +//! \file ImageSYG.cs +//! \date Sun Jun 05 19:14:11 2016 +//! \brief West Vision 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.WestVision +{ + internal class SygMetaData : ImageMetaData + { + public uint AlphaOffset; + } + + [Export(typeof(ImageFormat))] + public class SygFormat : ImageFormat + { + public override string Tag { get { return "SYG"; } } + public override string Description { get { return "West Vision image format"; } } + public override uint Signature { get { return 0x47595324; } } // '$SYG' + + public override ImageMetaData ReadMetaData (Stream stream) + { + var header = new byte[0x20]; + if (header.Length != stream.Read (header, 0, header.Length)) + return null; + uint alpha_offset = LittleEndian.ToUInt32 (header, 0x1C); + return new SygMetaData + { + Width = LittleEndian.ToUInt32 (header, 0x10), + Height = LittleEndian.ToUInt32 (header, 0x14), + BPP = 0 == alpha_offset ? 24 : 32, + AlphaOffset = alpha_offset, + }; + } + + public override ImageData Read (Stream stream, ImageMetaData info) + { + var meta = (SygMetaData)info; + int pixel_count = (int)meta.Width * (int)meta.Height; + var pixels = new byte[pixel_count * 3]; + stream.Position = 0x20; + if (pixels.Length != stream.Read (pixels, 0, pixels.Length)) + throw new EndOfStreamException ("Unexpected end of file"); + var format = PixelFormats.Bgr24; + if (meta.AlphaOffset != 0) + { + var alpha = new byte[pixel_count]; + stream.Position = 0x20 + meta.AlphaOffset; + if (alpha.Length == stream.Read (alpha, 0, alpha.Length)) + { + var output = new byte[pixel_count * 4]; + int dst = 0; + int src = 0; + for (int i = 0; i < pixel_count; ++i) + { + output[dst++] = pixels[src++]; + output[dst++] = pixels[src++]; + output[dst++] = pixels[src++]; + output[dst++] = alpha[i]; + } + pixels = output; + format = PixelFormats.Bgra32; + } + } + return ImageData.Create (info, format, null, pixels); + } + + public override void Write (Stream file, ImageData image) + { + throw new System.NotImplementedException ("SygFormat.Write not implemented"); + } + } +} diff --git a/supported.html b/supported.html index 86181010..e1e0823d 100644 --- a/supported.html +++ b/supported.html @@ -863,6 +863,10 @@ Tsujidou-san no Virgin Road
*.pakPACKNoStudio Nekopunch Uso x Mote ~Usonko Motemote-shon~
+*.syg$SYGNoWest Vision +Chijoku Yuugi
+Taiiku Souko ~Shoujotachi no Sange~
+

1 Non-encrypted only