From 2d1f18903abaae24e2fc5562cbe7ea0e2dcb7866 Mon Sep 17 00:00:00 2001 From: morkt Date: Mon, 12 Oct 2015 12:16:23 +0400 Subject: [PATCH] use ImageData.Create method instead of BitmapSource.Create. --- ArcFormats/ActiveSoft/ImageEDT.cs | 12 ++---------- ArcFormats/AliceSoft/ImageQNT.cs | 6 +----- ArcFormats/CatSystem/ImageHG3.cs | 15 +++------------ ArcFormats/GSD/ImageBMD.cs | 6 +----- ArcFormats/Ikura/ImageDRG.cs | 5 +---- ArcFormats/ImageAinos.cs | 6 +----- ArcFormats/ImageISG.cs | 7 +------ ArcFormats/ImageMAI.cs | 7 +------ ArcFormats/Kaas/ImageKAAS.cs | 6 +----- ArcFormats/KiriKiri/ImageTLG.cs | 7 ++----- ArcFormats/Majiro/ImageRCT.cs | 6 +----- ArcFormats/Marble/ImagePRS.cs | 6 +----- ArcFormats/MnoViolet/ImageGRA.cs | 7 +------ ArcFormats/Silky/ImageIGF.cs | 6 +----- ArcFormats/Silky/ImageMFG.cs | 5 +---- ArcFormats/Will/ImageWIP.cs | 10 +++------- 16 files changed, 22 insertions(+), 95 deletions(-) diff --git a/ArcFormats/ActiveSoft/ImageEDT.cs b/ArcFormats/ActiveSoft/ImageEDT.cs index 0ad9f82c..b8e6a71d 100644 --- a/ArcFormats/ActiveSoft/ImageEDT.cs +++ b/ArcFormats/ActiveSoft/ImageEDT.cs @@ -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 diff --git a/ArcFormats/AliceSoft/ImageQNT.cs b/ArcFormats/AliceSoft/ImageQNT.cs index 5da97bb9..68106fca 100644 --- a/ArcFormats/AliceSoft/ImageQNT.cs +++ b/ArcFormats/AliceSoft/ImageQNT.cs @@ -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); } } diff --git a/ArcFormats/CatSystem/ImageHG3.cs b/ArcFormats/CatSystem/ImageHG3.cs index b05b9b0e..7a206524 100644 --- a/ArcFormats/CatSystem/ImageHG3.cs +++ b/ArcFormats/CatSystem/ImageHG3.cs @@ -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); } } } diff --git a/ArcFormats/GSD/ImageBMD.cs b/ArcFormats/GSD/ImageBMD.cs index 7fbf9637..9423e713 100644 --- a/ArcFormats/GSD/ImageBMD.cs +++ b/ArcFormats/GSD/ImageBMD.cs @@ -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); } } diff --git a/ArcFormats/Ikura/ImageDRG.cs b/ArcFormats/Ikura/ImageDRG.cs index 3b8e5c27..810ae045 100644 --- a/ArcFormats/Ikura/ImageDRG.cs +++ b/ArcFormats/Ikura/ImageDRG.cs @@ -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) diff --git a/ArcFormats/ImageAinos.cs b/ArcFormats/ImageAinos.cs index ceca72ba..e8ac08c2 100644 --- a/ArcFormats/ImageAinos.cs +++ b/ArcFormats/ImageAinos.cs @@ -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); } } diff --git a/ArcFormats/ImageISG.cs b/ArcFormats/ImageISG.cs index a58c27ca..c7371923 100644 --- a/ArcFormats/ImageISG.cs +++ b/ArcFormats/ImageISG.cs @@ -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); } } diff --git a/ArcFormats/ImageMAI.cs b/ArcFormats/ImageMAI.cs index 7f0fd411..34449391 100644 --- a/ArcFormats/ImageMAI.cs +++ b/ArcFormats/ImageMAI.cs @@ -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 diff --git a/ArcFormats/Kaas/ImageKAAS.cs b/ArcFormats/Kaas/ImageKAAS.cs index c2bc90c5..d1a50553 100644 --- a/ArcFormats/Kaas/ImageKAAS.cs +++ b/ArcFormats/Kaas/ImageKAAS.cs @@ -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); } } diff --git a/ArcFormats/KiriKiri/ImageTLG.cs b/ArcFormats/KiriKiri/ImageTLG.cs index c3a1f0dc..9b781b14 100644 --- a/ArcFormats/KiriKiri/ImageTLG.cs +++ b/ArcFormats/KiriKiri/ImageTLG.cs @@ -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); } } diff --git a/ArcFormats/Majiro/ImageRCT.cs b/ArcFormats/Majiro/ImageRCT.cs index 716563a6..55911dbe 100644 --- a/ArcFormats/Majiro/ImageRCT.cs +++ b/ArcFormats/Majiro/ImageRCT.cs @@ -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); } } diff --git a/ArcFormats/Marble/ImagePRS.cs b/ArcFormats/Marble/ImagePRS.cs index 3d47614d..b1e1eeb5 100644 --- a/ArcFormats/Marble/ImagePRS.cs +++ b/ArcFormats/Marble/ImagePRS.cs @@ -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); } } diff --git a/ArcFormats/MnoViolet/ImageGRA.cs b/ArcFormats/MnoViolet/ImageGRA.cs index d7c7e06c..cf4486f3 100644 --- a/ArcFormats/MnoViolet/ImageGRA.cs +++ b/ArcFormats/MnoViolet/ImageGRA.cs @@ -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); } } } diff --git a/ArcFormats/Silky/ImageIGF.cs b/ArcFormats/Silky/ImageIGF.cs index 78fee5e6..1d806b50 100644 --- a/ArcFormats/Silky/ImageIGF.cs +++ b/ArcFormats/Silky/ImageIGF.cs @@ -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) diff --git a/ArcFormats/Silky/ImageMFG.cs b/ArcFormats/Silky/ImageMFG.cs index 56000c5c..12e7cf43 100644 --- a/ArcFormats/Silky/ImageMFG.cs +++ b/ArcFormats/Silky/ImageMFG.cs @@ -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); } } } diff --git a/ArcFormats/Will/ImageWIP.cs b/ArcFormats/Will/ImageWIP.cs index db97ea92..0448d2d6 100644 --- a/ArcFormats/Will/ImageWIP.cs +++ b/ArcFormats/Will/ImageWIP.cs @@ -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); } }