(DziFormat): look for any tile formats, not PNG only.

This commit is contained in:
morkt 2016-04-09 00:37:36 +04:00
parent 1f9a8e5a09
commit c7db912dc6

View File

@ -102,7 +102,7 @@ namespace GameRes.Formats.Malie
{ {
if (!string.IsNullOrEmpty (file)) if (!string.IsNullOrEmpty (file))
{ {
var filename = VFS.CombinePath (tex.Name, file + ".png"); var filename = VFS.CombinePath (tex.Name, file);
tiles.Add (new DziTile { X = x, Y = y, FileName = filename }); tiles.Add (new DziTile { X = x, Y = y, FileName = filename });
} }
x += 256; x += 256;
@ -123,24 +123,30 @@ namespace GameRes.Formats.Malie
public override ImageData Read (Stream stream, ImageMetaData info) public override ImageData Read (Stream stream, ImageMetaData info)
{ {
var meta = info as DziMetaData; var meta = (DziMetaData)info;
if (null == meta)
throw new ArgumentException ("DziFormat.Read should be supplied with DziMetaData", "info");
PixelFormat format = PixelFormats.Bgra32; PixelFormat format = PixelFormats.Bgra32;
var bitmap = new WriteableBitmap ((int)meta.Width, (int)meta.Height, ImageData.DefaultDpiX, var bitmap = new WriteableBitmap ((int)meta.Width, (int)meta.Height, ImageData.DefaultDpiX,
ImageData.DefaultDpiY, format, null); ImageData.DefaultDpiY, format, null);
int actual_width = 0; int actual_width = 0;
int actual_height = 0; int actual_height = 0;
byte[] pixels = null;
foreach (var tile in meta.Tiles.First()) foreach (var tile in meta.Tiles.First())
{ {
using (var file = VFS.OpenStream (VFS.FindFile (tile.FileName))) var image_entry = VFS.GetFiles (tile.FileName + ".*").FirstOrDefault();
if (null == image_entry)
throw new FileNotFoundException ("Tile not found", tile.FileName);
using (var input = VFS.OpenStream (image_entry))
{ {
var decoder = new PngBitmapDecoder (file, var image = Read (image_entry.Name, input);
BitmapCreateOptions.None, BitmapCacheOption.OnLoad); if (null == image)
var converted = new FormatConvertedBitmap (decoder.Frames[0], format, null, 0); throw new FileFormatException ("Unknown DZI tile format");
var converted = image.Bitmap;
if (converted.Format != format)
converted = new FormatConvertedBitmap (converted, format, null, 0);
int stride = converted.PixelWidth * 4; int stride = converted.PixelWidth * 4;
var pixels = new byte[stride * converted.PixelHeight]; int tile_size = stride * converted.PixelHeight;
if (null == pixels || pixels.Length < tile_size)
pixels = new byte[tile_size];
converted.CopyPixels (pixels, stride, 0); converted.CopyPixels (pixels, stride, 0);
var width = Math.Min (converted.PixelWidth, bitmap.PixelWidth - tile.X); var width = Math.Min (converted.PixelWidth, bitmap.PixelWidth - tile.X);
var height = Math.Min (converted.PixelHeight, bitmap.PixelHeight - tile.Y); var height = Math.Min (converted.PixelHeight, bitmap.PixelHeight - tile.Y);