Browse Source

use default arguments for bitmap decoder options in platform backends.

pull/3890/head
Dan Walmsley 7 years ago
parent
commit
3995b8abb9
  1. 10
      src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs
  2. 38
      src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
  3. 14
      src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs

10
src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs

@ -85,23 +85,21 @@ namespace Avalonia.Platform
/// <returns>An <see cref="IWriteableBitmapImpl"/>.</returns>
IWriteableBitmapImpl CreateWriteableBitmap(PixelSize size, Vector dpi, PixelFormat? format = null);
IBitmapImpl LoadBitmap(string fileName, BitmapDecodeOptions decodeOptions);
IBitmapImpl LoadBitmap(Stream stream, BitmapDecodeOptions decodeOptions);
/// <summary>
/// Loads a bitmap implementation from a file..
/// </summary>
/// <param name="fileName">The filename of the bitmap.</param>
/// <param name="decodeOptions">Decode options that specify the size of the decoded bitmap.</param>
/// <returns>An <see cref="IBitmapImpl"/>.</returns>
IBitmapImpl LoadBitmap(string fileName);
IBitmapImpl LoadBitmap(string fileName, BitmapDecodeOptions? decodeOptions = null);
/// <summary>
/// Loads a bitmap implementation from a file..
/// </summary>
/// <param name="stream">The stream to read the bitmap from.</param>
/// <param name="decodeOptions">Decode options that specify the size of the decoded bitmap.</param>
/// <returns>An <see cref="IBitmapImpl"/>.</returns>
IBitmapImpl LoadBitmap(Stream stream);
IBitmapImpl LoadBitmap(Stream stream, BitmapDecodeOptions? decodeOptions = null);
/// <summary>
/// Loads a bitmap implementation from a pixels in memory.

38
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))
/// <inheritdoc />
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);
}
}
}
/// <inheritdoc />
public IBitmapImpl LoadBitmap(Stream stream)
{
return new ImmutableBitmap(stream);
}
/// <inheritdoc />
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);
}
}

14
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;

Loading…
Cancel
Save