implemented Kaguya "AO" images.

This commit is contained in:
morkt
2015-11-24 17:02:26 +04:00
parent 0924d385e8
commit 2f7706f228
4 changed files with 114 additions and 16 deletions

View File

@@ -29,7 +29,6 @@ using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GameRes.Utility;
namespace GameRes.Formats.Kaguya
{
@@ -66,6 +65,11 @@ namespace GameRes.Formats.Kaguya
public override ImageData Read (Stream stream, ImageMetaData info)
{
stream.Position = 12;
return ReadBitmapData (stream, info);
}
protected ImageData ReadBitmapData (Stream stream, ImageMetaData info)
{
int stride = (int)info.Width*4;
var pixels = new byte[stride*info.Height];
for (int row = (int)info.Height-1; row >= 0; --row)
@@ -86,21 +90,25 @@ namespace GameRes.Formats.Kaguya
output.Write (image.Width);
output.Write (image.Height);
output.Write ((short)24);
WriteBitmapData (file, image);
}
}
var bitmap = image.Bitmap;
if (bitmap.Format != PixelFormats.Bgra32)
{
bitmap = new FormatConvertedBitmap (bitmap, PixelFormats.Bgra32, null, 0);
}
int stride = (int)image.Width * 4;
byte[] row_data = new byte[stride];
Int32Rect rect = new Int32Rect (0, (int)image.Height, (int)image.Width, 1);
for (uint row = 0; row < image.Height; ++row)
{
--rect.Y;
bitmap.CopyPixels (rect, row_data, stride, 0);
output.Write (row_data);
}
protected void WriteBitmapData (Stream file, ImageData image)
{
var bitmap = image.Bitmap;
if (bitmap.Format != PixelFormats.Bgra32)
{
bitmap = new FormatConvertedBitmap (bitmap, PixelFormats.Bgra32, null, 0);
}
int stride = (int)image.Width * 4;
byte[] row_data = new byte[stride];
Int32Rect rect = new Int32Rect (0, (int)image.Height, (int)image.Width, 1);
for (uint row = 0; row < image.Height; ++row)
{
--rect.Y;
bitmap.CopyPixels (rect, row_data, stride, 0);
file.Write (row_data, 0, row_data.Length);
}
}
}