Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<MicrosoftExtensionsObjectPoolVersion>9.0.4</MicrosoftExtensionsObjectPoolVersion>
<MicrosoftExtensionsOptionsVersion>9.0.4</MicrosoftExtensionsOptionsVersion>
<NuGetVersion>6.9.1</NuGetVersion>
<SkiaSharpVersion>2.88.8</SkiaSharpVersion>
<SkiaSharpVersion>3.119.2</SkiaSharpVersion>
<SystemCodeDomVersion>9.0.4</SystemCodeDomVersion>
<SystemCollectionsImmutableVersion>9.0.4</SystemCollectionsImmutableVersion>
<SystemConfigurationConfigurationManagerVersion>9.0.4</SystemConfigurationConfigurationManagerVersion>
Expand Down
19 changes: 11 additions & 8 deletions src/Microsoft.ML.ImageAnalytics/MLImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,18 @@ public byte[] GetBGRPixels
/// <summary>
/// Gets the image pixel data.
/// </summary>
public ReadOnlySpan<byte> Pixels
public unsafe ReadOnlySpan<byte> Pixels
{
get
{
ThrowInvalidOperationExceptionIfDisposed();
Debug.Assert(_image.Info.BytesPerPixel == 4);

return _image.GetPixelSpan();
var pixelsPtr = _image.GetPixels();
if (pixelsPtr == IntPtr.Zero || _image.ByteCount <= 0)
throw new InvalidOperationException("Pixel data is unavailable.");

return new ReadOnlySpan<byte>(pixelsPtr.ToPointer(), _image.ByteCount);
}
}

Expand Down Expand Up @@ -305,7 +309,7 @@ internal MLImage CloneWithResizing(int width, int height, ImageResizeMode mode)
return new MLImage(image);
}

private SKBitmap ResizeFull(int width, int height) => _image.Resize(new SKSizeI(width, height), SKFilterQuality.None);
private SKBitmap ResizeFull(int width, int height) => _image.Resize(new SKSizeI(width, height), new SKSamplingOptions(SKFilterMode.Nearest));

private SKBitmap ResizeWithPadding(int width, int height)
{
Expand Down Expand Up @@ -334,9 +338,9 @@ private SKBitmap ResizeWithPadding(int width, int height)
SKRect destRect = new SKRect(destX, destY, destX + destWidth, destY + destHeight);

using SKCanvas canvas = new SKCanvas(destBitmap);
using SKPaint paint = new SKPaint() { FilterQuality = SKFilterQuality.High };
using SKImage image = SKImage.FromBitmap(_image);

canvas.DrawBitmap(_image, srcRect, destRect, paint);
canvas.DrawImage(image, srcRect, destRect, new SKSamplingOptions(SKCubicResampler.Mitchell));

return destBitmap;
}
Expand Down Expand Up @@ -391,9 +395,9 @@ private SKBitmap ResizeWithCrop(int width, int height, ImageResizeMode mode)
SKRect destRect = new SKRect(destX, destY, destX + destWidth, destY + destHeight);

using SKCanvas canvas = new SKCanvas(dst);
using SKPaint paint = new SKPaint() { FilterQuality = SKFilterQuality.High };
using SKImage image = SKImage.FromBitmap(_image);

canvas.DrawBitmap(_image, srcRect, destRect, paint);
canvas.DrawImage(image, srcRect, destRect, new SKSamplingOptions(SKCubicResampler.Mitchell));

return dst;
}
Expand All @@ -415,7 +419,6 @@ internal MLImage CloneWithGrayscale()
using SKPaint paint = new SKPaint()
{
ColorFilter = _grayscaleColorMatrix,
FilterQuality = SKFilterQuality.High
};

SKBitmap destBitmap = new SKBitmap(_image.Width, _image.Height, isOpaque: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<PackageReference Include="System.Buffers" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" />

<!-- SkiaSharp reference Windows, UWP, and MacOS native dependencies packages. No need to explicity reference it here. -->
<PackageReference Include="SkiaSharp" />

<!-- SkiaSharp already includes Windows, UWP, and macOS native dependency packages; only the Linux native assets package needs to be referenced explicitly here. -->
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" />
</ItemGroup>

Expand Down
Loading