From 3995b8abb97cc4b6ed386da8f1516f2014872d9b Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 6 May 2020 17:29:41 -0300 Subject: [PATCH] use default arguments for bitmap decoder options in platform backends. --- .../Platform/IPlatformRenderInterface.cs | 10 ++--- .../Avalonia.Skia/PlatformRenderInterface.cs | 38 +++++++++---------- .../Avalonia.Direct2D1/Direct2D1Platform.cs | 14 +------ 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs b/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs index 86662a3584..a32aeb2326 100644 --- a/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs +++ b/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs @@ -85,23 +85,21 @@ namespace Avalonia.Platform /// An . IWriteableBitmapImpl CreateWriteableBitmap(PixelSize size, Vector dpi, PixelFormat? format = null); - IBitmapImpl LoadBitmap(string fileName, BitmapDecodeOptions decodeOptions); - - IBitmapImpl LoadBitmap(Stream stream, BitmapDecodeOptions decodeOptions); - /// /// Loads a bitmap implementation from a file.. /// /// The filename of the bitmap. + /// Decode options that specify the size of the decoded bitmap. /// An . - IBitmapImpl LoadBitmap(string fileName); + IBitmapImpl LoadBitmap(string fileName, BitmapDecodeOptions? decodeOptions = null); /// /// Loads a bitmap implementation from a file.. /// /// The stream to read the bitmap from. + /// Decode options that specify the size of the decoded bitmap. /// An . - IBitmapImpl LoadBitmap(Stream stream); + IBitmapImpl LoadBitmap(Stream stream, BitmapDecodeOptions? decodeOptions = null); /// /// Loads a bitmap implementation from a pixels in memory. diff --git a/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs b/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs index b96a65186e..28a8b2b1ef 100644 --- a/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs +++ b/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs @@ -78,40 +78,36 @@ namespace Avalonia.Skia return new StreamGeometryImpl(); } - public IBitmapImpl LoadBitmap(string fileName, BitmapDecodeOptions decodeOptions) - { - using (var stream = File.OpenRead(fileName)) + /// + public unsafe IBitmapImpl LoadBitmap(Stream stream, BitmapDecodeOptions? decodeOptions = null) + { + if (decodeOptions is null) { - return LoadBitmap(stream, decodeOptions); + return new ImmutableBitmap(stream); } - } + else + { + var options = decodeOptions.Value; - public unsafe IBitmapImpl LoadBitmap(Stream stream, BitmapDecodeOptions decodeOptions) - { - var skBitmap = SKBitmap.Decode(stream); + var skBitmap = SKBitmap.Decode(stream); - skBitmap = skBitmap.Resize(new SKImageInfo(decodeOptions.DecodePixelSize.Width, decodeOptions.DecodePixelSize.Height), decodeOptions.InterpolationMode.ToSKFilterQuality()); + skBitmap = skBitmap.Resize(new SKImageInfo(options.DecodePixelSize.Width, options.DecodePixelSize.Height), options.InterpolationMode.ToSKFilterQuality()); - fixed (byte* p = skBitmap.Bytes) - { - IntPtr ptr = (IntPtr)p; + fixed (byte* p = skBitmap.Bytes) + { + IntPtr ptr = (IntPtr)p; - return LoadBitmap(PixelFormat.Bgra8888, ptr, new PixelSize(skBitmap.Width, skBitmap.Height), new Vector(96, 96), skBitmap.RowBytes); + return LoadBitmap(PixelFormat.Bgra8888, ptr, new PixelSize(skBitmap.Width, skBitmap.Height), new Vector(96, 96), skBitmap.RowBytes); + } } } /// - public IBitmapImpl LoadBitmap(Stream stream) - { - return new ImmutableBitmap(stream); - } - - /// - public IBitmapImpl LoadBitmap(string fileName) + public IBitmapImpl LoadBitmap(string fileName, BitmapDecodeOptions? decodeOptions) { using (var stream = File.OpenRead(fileName)) { - return LoadBitmap(stream); + return LoadBitmap(stream, decodeOptions); } } diff --git a/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs b/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs index 534ecdd6e6..617bae2245 100644 --- a/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs +++ b/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs @@ -180,12 +180,12 @@ namespace Avalonia.Direct2D1 public IGeometryImpl CreateRectangleGeometry(Rect rect) => new RectangleGeometryImpl(rect); public IStreamGeometryImpl CreateStreamGeometry() => new StreamGeometryImpl(); - public IBitmapImpl LoadBitmap(string fileName) + public IBitmapImpl LoadBitmap(string fileName, BitmapDecodeOptions? options = null) { return new WicBitmapImpl(fileName); } - public IBitmapImpl LoadBitmap(Stream stream) + public IBitmapImpl LoadBitmap(Stream stream, BitmapDecodeOptions? options = null) { return new WicBitmapImpl(stream); } @@ -195,16 +195,6 @@ namespace Avalonia.Direct2D1 return new WicBitmapImpl(format, data, size, dpi, stride); } - public IBitmapImpl LoadBitmap(string fileName, BitmapDecodeOptions decodeOptions) - { - throw new NotImplementedException(); - } - - public IBitmapImpl LoadBitmap(Stream stream, BitmapDecodeOptions decodeOptions) - { - throw new NotImplementedException(); - } - public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun, out double width) { var glyphTypeface = (GlyphTypefaceImpl)glyphRun.GlyphTypeface.PlatformImpl;