mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-27 07:34:00 +08:00
(AJP): implemented version 1 images.
This commit is contained in:
parent
f1a201d571
commit
e096a407d3
@ -2,7 +2,7 @@
|
||||
//! \date Mon Sep 12 21:25:27 2016
|
||||
//! \brief AliceSoft JPEG image.
|
||||
//
|
||||
// Copyright (C) 2016 by morkt
|
||||
// Copyright (C) 2016-2018 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
|
||||
@ -27,6 +27,7 @@ using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.AliceSoft
|
||||
@ -37,6 +38,7 @@ namespace GameRes.Formats.AliceSoft
|
||||
public uint ImageSize;
|
||||
public uint AlphaOffset;
|
||||
public uint AlphaSize;
|
||||
public uint AlphaUnpacked;
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
@ -52,20 +54,23 @@ namespace GameRes.Formats.AliceSoft
|
||||
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream stream)
|
||||
{
|
||||
var header = new byte[0x18];
|
||||
stream.Position = 0xC;
|
||||
if (header.Length != stream.Read (header, 0, header.Length))
|
||||
var header = stream.ReadHeader (0x24);
|
||||
int version = header.ToInt32 (4);
|
||||
if (version < 0)
|
||||
return null;
|
||||
return new AjpMetaData
|
||||
var info = new AjpMetaData
|
||||
{
|
||||
Width = LittleEndian.ToUInt32 (header, 0),
|
||||
Height = LittleEndian.ToUInt32 (header, 4),
|
||||
Width = header.ToUInt32 (0xC),
|
||||
Height = header.ToUInt32 (0x10),
|
||||
BPP = 32,
|
||||
ImageOffset = LittleEndian.ToUInt32 (header, 8),
|
||||
ImageSize = LittleEndian.ToUInt32 (header, 0xC),
|
||||
AlphaOffset = LittleEndian.ToUInt32 (header, 0x10),
|
||||
AlphaSize = LittleEndian.ToUInt32 (header, 0x14),
|
||||
ImageOffset = header.ToUInt32 (0x14),
|
||||
ImageSize = header.ToUInt32 (0x18),
|
||||
AlphaOffset = header.ToUInt32 (0x1C),
|
||||
AlphaSize = header.ToUInt32 (0x20),
|
||||
};
|
||||
if (version > 0)
|
||||
info.AlphaUnpacked = stream.ReadUInt32();
|
||||
return info;
|
||||
}
|
||||
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
@ -89,9 +94,23 @@ namespace GameRes.Formats.AliceSoft
|
||||
pixels = new byte[stride * (int)meta.Height];
|
||||
bitmap.CopyPixels (pixels, stride, 0);
|
||||
}
|
||||
using (var mask = DecryptStream (stream.AsStream, meta.AlphaOffset, meta.AlphaSize))
|
||||
Stream mask = DecryptStream (stream.AsStream, meta.AlphaOffset, meta.AlphaSize);
|
||||
byte[] alpha;
|
||||
if (meta.AlphaUnpacked != 0)
|
||||
{
|
||||
var alpha = ReadMask (mask);
|
||||
using (mask = new ZLibStream (mask, CompressionMode.Decompress))
|
||||
{
|
||||
alpha = new byte[meta.AlphaUnpacked];
|
||||
mask.Read (alpha, 0, alpha.Length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (mask)
|
||||
{
|
||||
alpha = ReadMask (mask);
|
||||
}
|
||||
}
|
||||
int src = 0;
|
||||
for (int dst = 3; dst < pixels.Length; dst += 4)
|
||||
{
|
||||
@ -99,7 +118,6 @@ namespace GameRes.Formats.AliceSoft
|
||||
}
|
||||
return ImageData.Create (info, PixelFormats.Bgra32, null, pixels, stride);
|
||||
}
|
||||
}
|
||||
|
||||
Stream DecryptStream (Stream input, uint offset, uint size)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user