mirror of
https://github.com/crskycode/GARbro.git
synced 2025-01-11 04:29:15 +08:00
use ImageData.Create method instead of BitmapSource.Create.
This commit is contained in:
parent
43b1631e67
commit
2d1f18903a
@ -141,11 +141,7 @@ namespace GameRes.Formats.AdPack
|
||||
using (var reader = new Reader (stream, meta))
|
||||
{
|
||||
reader.Unpack();
|
||||
byte[] pixels = reader.Data;
|
||||
var bitmap = BitmapSource.Create ((int)meta.Width, (int)meta.Height, 96, 96,
|
||||
PixelFormats.Bgr24, null, pixels, (int)meta.Width*3);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, meta);
|
||||
return ImageData.Create (meta, PixelFormats.Bgr24, null, reader.Data, (int)meta.Width*3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,12 +317,8 @@ namespace GameRes.Formats.AdPack
|
||||
stream.Position = 0x1a;
|
||||
var reader = new Reader (stream, meta);
|
||||
reader.Unpack();
|
||||
byte[] pixels = reader.Data;
|
||||
var palette = new BitmapPalette (reader.Palette);
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
||||
PixelFormats.Indexed8, palette, pixels, (int)info.Width);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, info);
|
||||
return ImageData.Create (info, PixelFormats.Indexed8, palette, reader.Data, (int)info.Width);
|
||||
}
|
||||
|
||||
internal class Reader : BitReader
|
||||
|
@ -87,13 +87,9 @@ namespace GameRes.Formats.AliceSoft
|
||||
using (var reader = new Reader (stream, meta))
|
||||
{
|
||||
reader.Unpack();
|
||||
var pixels = reader.Data;
|
||||
int stride = (int)info.Width * (reader.BPP / 8);
|
||||
PixelFormat format = 24 == reader.BPP ? PixelFormats.Bgr24 : PixelFormats.Bgra32;
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
||||
format, null, pixels, stride);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, info);
|
||||
return ImageData.Create (info, format, null, reader.Data, stride);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,19 +108,10 @@ namespace GameRes.Formats.CatSystem
|
||||
decoder.Unpack();
|
||||
var pixels = decoder.Data;
|
||||
int stride = (int)info.Width * 4;
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
||||
PixelFormats.Bgra32, null, pixels, stride);
|
||||
if (flipped)
|
||||
{
|
||||
var flipped_bitmap = new TransformedBitmap();
|
||||
flipped_bitmap.BeginInit();
|
||||
flipped_bitmap.Source = bitmap;
|
||||
flipped_bitmap.Transform = new ScaleTransform { ScaleY = -1 };
|
||||
flipped_bitmap.EndInit();
|
||||
bitmap = flipped_bitmap;
|
||||
}
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, info);
|
||||
return ImageData.CreateFlipped (info, PixelFormats.Bgra32, null, pixels, stride);
|
||||
else
|
||||
return ImageData.Create (info, PixelFormats.Bgra32, null, pixels, stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,11 +78,7 @@ namespace GameRes.Formats.BlackRainbow
|
||||
{
|
||||
PixelFormat format = meta.Flag != 0 ? PixelFormats.Bgra32 : PixelFormats.Bgr32;
|
||||
reader.Unpack();
|
||||
byte[] pixels = reader.Data;
|
||||
var bitmap = BitmapSource.Create ((int)meta.Width, (int)meta.Height, 96, 96,
|
||||
format, null, pixels, (int)meta.Width*4);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, meta);
|
||||
return ImageData.Create (meta, format, null, reader.Data, (int)meta.Width*4);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,10 +93,7 @@ namespace GameRes.Formats.Ikura
|
||||
var pixel_data = DecodeStream (file, stride*(int)info.Height);
|
||||
if (null == pixel_data)
|
||||
throw new InvalidFormatException();
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
||||
format, null, pixel_data, stride);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, info);
|
||||
return ImageData.Create (info, format, null, pixel_data, stride);
|
||||
}
|
||||
|
||||
byte[] DecodeStream (Stream input, int pixel_count)
|
||||
|
@ -146,11 +146,7 @@ namespace GameRes.Formats.Ainos
|
||||
reader.UnpackRGB();
|
||||
else
|
||||
reader.UnpackIndexed();
|
||||
byte[] pixels = reader.Data;
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
||||
PixelFormats.Bgr24, null, pixels, (int)info.Width*3);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, info);
|
||||
return ImageData.Create (info, PixelFormats.Bgr24, null, reader.Data, (int)info.Width*3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,13 +92,8 @@ namespace GameRes.Formats.ISM
|
||||
input.Unpack21();
|
||||
else
|
||||
input.Unpack10();
|
||||
byte[] pixels = input.Data;
|
||||
var palette = new BitmapPalette (input.Palette);
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
||||
PixelFormats.Indexed8, palette, pixels, (int)info.Width);
|
||||
var flipped = new TransformedBitmap (bitmap, new ScaleTransform { ScaleY = -1 });
|
||||
flipped.Freeze();
|
||||
return new ImageData (flipped, info);
|
||||
return ImageData.CreateFlipped (info, PixelFormats.Indexed8, palette, input.Data, (int)info.Width);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,12 +91,7 @@ namespace GameRes.Formats.MAI
|
||||
|
||||
var reader = new Reader (stream, meta);
|
||||
reader.Unpack();
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height,
|
||||
ImageData.DefaultDpiX, ImageData.DefaultDpiY,
|
||||
reader.Format, reader.Palette, reader.Data, reader.Stride);
|
||||
var flipped = new TransformedBitmap (bitmap, new ScaleTransform { ScaleY = -1 });
|
||||
flipped.Freeze();
|
||||
return new ImageData (flipped, info);
|
||||
return ImageData.CreateFlipped (info, reader.Format, reader.Palette, reader.Data, reader.Stride);
|
||||
}
|
||||
|
||||
internal class Reader
|
||||
|
@ -102,11 +102,7 @@ namespace GameRes.Formats.KAAS
|
||||
using (var reader = new Reader (stream, meta))
|
||||
{
|
||||
reader.Unpack();
|
||||
byte[] pixels = reader.Data;
|
||||
var bitmap = BitmapSource.Create ((int)meta.Width, (int)meta.Height, 96, 96,
|
||||
PixelFormats.Bgr24, null, pixels, (int)meta.Width*3);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, meta);
|
||||
return ImageData.Create (meta, PixelFormats.Bgr24, null, reader.Data, (int)meta.Width*3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,7 +248,7 @@ namespace GameRes.Formats.KiriKiri
|
||||
{
|
||||
int stride = width * 4;
|
||||
PixelFormat format = 32 == info.BPP ? PixelFormats.Bgra32 : PixelFormats.Bgr32;
|
||||
var bitmap = BitmapSource.Create(width, height, 96, 96,
|
||||
var bitmap = BitmapSource.Create(width, height, ImageData.DefaultDpiX, ImageData.DefaultDpiY,
|
||||
format, null, (IntPtr) data, height * stride, stride);
|
||||
bitmap.Freeze();
|
||||
return new ImageData(bitmap, info);
|
||||
@ -369,10 +369,7 @@ namespace GameRes.Formats.KiriKiri
|
||||
}
|
||||
}
|
||||
PixelFormat format = 4 == colors ? PixelFormats.Bgra32 : PixelFormats.Bgr32;
|
||||
var bitmap = BitmapSource.Create (width, height, 96, 96,
|
||||
format, null, image_bits, stride);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, info);
|
||||
return ImageData.Create (info, format, null, image_bits, stride);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -611,12 +611,8 @@ namespace GameRes.Formats.Majiro
|
||||
using (var reader = new Reader (file, info))
|
||||
{
|
||||
reader.Unpack();
|
||||
byte[] pixels = reader.Data;
|
||||
var palette = new BitmapPalette (reader.Palette);
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
||||
PixelFormats.Indexed8, palette, pixels, (int)info.Width);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, info);
|
||||
return ImageData.Create (info, PixelFormats.Indexed8, palette, reader.Data, (int)info.Width);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,11 +81,7 @@ namespace GameRes.Formats.Marble
|
||||
using (var reader = new Reader (stream, meta))
|
||||
{
|
||||
reader.Unpack();
|
||||
byte[] pixels = reader.Data;
|
||||
var bitmap = BitmapSource.Create ((int)meta.Width, (int)meta.Height, 96, 96,
|
||||
PixelFormats.Bgr24, null, pixels, (int)meta.Width*3);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, meta);
|
||||
return ImageData.Create (meta, PixelFormats.Bgr24, null, reader.Data, (int)meta.Width*3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,17 +87,12 @@ namespace GameRes.Formats.MnoViolet
|
||||
{
|
||||
reader.Unpack();
|
||||
int stride = (int)info.Width*info.BPP/8;
|
||||
var pixels = reader.Data;
|
||||
PixelFormat format;
|
||||
if (24 == info.BPP)
|
||||
format = PixelFormats.Bgr24;
|
||||
else
|
||||
format = PixelFormats.Gray8;
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
||||
format, null, pixels, stride);
|
||||
var flipped = new TransformedBitmap (bitmap, new ScaleTransform { ScaleY = -1 });
|
||||
flipped.Freeze();
|
||||
return new ImageData (flipped, info);
|
||||
return ImageData.CreateFlipped (info, format, null, reader.Data, stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,11 +100,7 @@ namespace GameRes.Formats.Silky
|
||||
format = PixelFormats.Bgra32;
|
||||
else
|
||||
format = PixelFormats.Gray8;
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height,
|
||||
ImageData.DefaultDpiX, ImageData.DefaultDpiY, format, null, pixels, stride);
|
||||
var flipped = new TransformedBitmap (bitmap, new ScaleTransform { ScaleY = -1 });
|
||||
flipped.Freeze();
|
||||
return new ImageData (flipped, info);
|
||||
return ImageData.CreateFlipped (info, format, null, pixels, stride);
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
|
@ -107,10 +107,7 @@ namespace GameRes.Formats.Silky
|
||||
format = PixelFormats.Bgr24;
|
||||
else
|
||||
format = PixelFormats.Bgra32;
|
||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
||||
format, null, pixels, meta.Stride);
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, info);
|
||||
return ImageData.Create (info, format, null, pixels, meta.Stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,6 @@ namespace GameRes.Formats.Will
|
||||
using (var reader = new Reader (file, meta))
|
||||
{
|
||||
reader.Unpack();
|
||||
BitmapSource bitmap;
|
||||
if (24 == meta.BPP)
|
||||
{
|
||||
byte[] raw = reader.Data;
|
||||
@ -123,19 +122,16 @@ namespace GameRes.Formats.Will
|
||||
pixels[i*3+1] = raw[i+size];
|
||||
pixels[i*3+2] = raw[i+size*2];
|
||||
}
|
||||
bitmap = BitmapSource.Create ((int)meta.Width, (int)meta.Height, 96, 96,
|
||||
PixelFormats.Bgr24, null, pixels, (int)meta.Width*3);
|
||||
return ImageData.Create (meta, PixelFormats.Bgr24, null, pixels, (int)meta.Width*3);
|
||||
}
|
||||
else if (8 == meta.BPP)
|
||||
{
|
||||
byte[] pixels = reader.Data;
|
||||
bitmap = BitmapSource.Create ((int)meta.Width, (int)meta.Height, 96, 96,
|
||||
PixelFormats.Indexed8, new BitmapPalette (palette), pixels, (int)meta.Width);
|
||||
var bmp_palette = new BitmapPalette (palette);
|
||||
return ImageData.Create (meta, PixelFormats.Indexed8, bmp_palette, pixels, (int)meta.Width);
|
||||
}
|
||||
else
|
||||
throw new InvalidFormatException();
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user