Skip to content

Commit e11c2b4

Browse files
Copilotstephentoub
andauthored
Update SkiaSharp from 2.88.8 to 3.119.2 (#7582)
* Initial plan * Update SkiaSharp from 2.88.8 to 3.119.2 and fix breaking API changes Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Use high-quality SKCubicResampler.Mitchell for resize operations Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Address review feedback: fix csproj comment and add pixel pointer validation Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 9d809f1 commit e11c2b4

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<MicrosoftExtensionsObjectPoolVersion>9.0.4</MicrosoftExtensionsObjectPoolVersion>
2020
<MicrosoftExtensionsOptionsVersion>9.0.4</MicrosoftExtensionsOptionsVersion>
2121
<NuGetVersion>6.9.1</NuGetVersion>
22-
<SkiaSharpVersion>2.88.8</SkiaSharpVersion>
22+
<SkiaSharpVersion>3.119.2</SkiaSharpVersion>
2323
<SystemCodeDomVersion>9.0.4</SystemCodeDomVersion>
2424
<SystemCollectionsImmutableVersion>9.0.4</SystemCollectionsImmutableVersion>
2525
<SystemConfigurationConfigurationManagerVersion>9.0.4</SystemConfigurationConfigurationManagerVersion>

src/Microsoft.ML.ImageAnalytics/MLImage.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,18 @@ public byte[] GetBGRPixels
155155
/// <summary>
156156
/// Gets the image pixel data.
157157
/// </summary>
158-
public ReadOnlySpan<byte> Pixels
158+
public unsafe ReadOnlySpan<byte> Pixels
159159
{
160160
get
161161
{
162162
ThrowInvalidOperationExceptionIfDisposed();
163163
Debug.Assert(_image.Info.BytesPerPixel == 4);
164164

165-
return _image.GetPixelSpan();
165+
var pixelsPtr = _image.GetPixels();
166+
if (pixelsPtr == IntPtr.Zero || _image.ByteCount <= 0)
167+
throw new InvalidOperationException("Pixel data is unavailable.");
168+
169+
return new ReadOnlySpan<byte>(pixelsPtr.ToPointer(), _image.ByteCount);
166170
}
167171
}
168172

@@ -305,7 +309,7 @@ internal MLImage CloneWithResizing(int width, int height, ImageResizeMode mode)
305309
return new MLImage(image);
306310
}
307311

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

310314
private SKBitmap ResizeWithPadding(int width, int height)
311315
{
@@ -334,9 +338,9 @@ private SKBitmap ResizeWithPadding(int width, int height)
334338
SKRect destRect = new SKRect(destX, destY, destX + destWidth, destY + destHeight);
335339

336340
using SKCanvas canvas = new SKCanvas(destBitmap);
337-
using SKPaint paint = new SKPaint() { FilterQuality = SKFilterQuality.High };
341+
using SKImage image = SKImage.FromBitmap(_image);
338342

339-
canvas.DrawBitmap(_image, srcRect, destRect, paint);
343+
canvas.DrawImage(image, srcRect, destRect, new SKSamplingOptions(SKCubicResampler.Mitchell));
340344

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

393397
using SKCanvas canvas = new SKCanvas(dst);
394-
using SKPaint paint = new SKPaint() { FilterQuality = SKFilterQuality.High };
398+
using SKImage image = SKImage.FromBitmap(_image);
395399

396-
canvas.DrawBitmap(_image, srcRect, destRect, paint);
400+
canvas.DrawImage(image, srcRect, destRect, new SKSamplingOptions(SKCubicResampler.Mitchell));
397401

398402
return dst;
399403
}
@@ -415,7 +419,6 @@ internal MLImage CloneWithGrayscale()
415419
using SKPaint paint = new SKPaint()
416420
{
417421
ColorFilter = _grayscaleColorMatrix,
418-
FilterQuality = SKFilterQuality.High
419422
};
420423

421424
SKBitmap destBitmap = new SKBitmap(_image.Width, _image.Height, isOpaque: true);

src/Microsoft.ML.ImageAnalytics/Microsoft.ML.ImageAnalytics.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<PackageReference Include="System.Buffers" />
1212
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" />
1313

14-
<!-- SkiaSharp reference Windows, UWP, and MacOS native dependencies packages. No need to explicity reference it here. -->
14+
<PackageReference Include="SkiaSharp" />
15+
16+
<!-- SkiaSharp already includes Windows, UWP, and macOS native dependency packages; only the Linux native assets package needs to be referenced explicitly here. -->
1517
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" />
1618
</ItemGroup>
1719

0 commit comments

Comments
 (0)