GARbro-mirror/ArcFormats/rUGP/ImageS5I.cs

84 lines
3.1 KiB
C#
Raw Permalink Normal View History

2016-11-11 21:34:25 +08:00
//! \file ImageS5I.cs
//! \date Wed Nov 09 16:25:17 2016
//! \brief rUGP engine 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;
namespace GameRes.Formats.Rugp
{
2018-02-04 00:05:39 +08:00
internal class S5iMetaData : RioMetaData
{
public int Schema;
}
2016-11-11 21:34:25 +08:00
[Export(typeof(ImageFormat))]
public class S5iFormat : ImageFormat
{
public override string Tag { get { return "S5I"; } }
public override string Description { get { return "rUGP engine image format"; } }
public override uint Signature { get { return 0; } }
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
if (file.Signature != CRioArchive.ObjectSignature)
return null;
var rio = new CRioArchive (file);
uint signature;
var class_ref = rio.LoadRioTypeCore (out signature);
uint object_pos = (uint)file.Position;
if ("CS5i" != class_ref)
return null;
file.Seek (8, SeekOrigin.Current);
2018-02-04 00:05:39 +08:00
return new S5iMetaData
2016-11-11 21:34:25 +08:00
{
Width = file.ReadUInt16(),
Height = file.ReadUInt16(),
BPP = 32,
ObjectOffset = object_pos,
2018-02-03 23:57:47 +08:00
Schema = rio.Schema,
2016-11-11 21:34:25 +08:00
};
}
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
2018-02-04 00:05:39 +08:00
var meta = (S5iMetaData)info;
2016-11-11 21:34:25 +08:00
file.Position = meta.ObjectOffset + 0x14;
2018-02-03 23:57:47 +08:00
int size;
if (meta.Schema != 0)
size = file.ReadInt32();
else
size = (int)meta.Width * (int)meta.Height * 4;
2016-11-11 21:34:25 +08:00
var pixels = file.ReadBytes (size);
return ImageData.Create (info, PixelFormats.Bgra32, null, pixels);
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("S5iFormat.Write not implemented");
}
}
}