Skip to content

Commit 791e3ec

Browse files
committed
wip 2
1 parent df5c07e commit 791e3ec

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

osu.Framework/Platform/MacOS/MacOSTextureLoaderStore.cs

+13-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using osu.Framework.IO.Stores;
99
using osu.Framework.Platform.Apple;
1010
using SixLabors.ImageSharp;
11+
using SixLabors.ImageSharp.Memory;
1112

1213
namespace osu.Framework.Platform.MacOS
1314
{
@@ -20,19 +21,21 @@ public MacOSTextureLoaderStore(IResourceStore<byte[]> store)
2021

2122
protected override unsafe Image<TPixel> ImageFromStream<TPixel>(Stream stream)
2223
{
23-
uint length = (uint)(stream.Length - stream.Position);
24-
using var nativeData = NSMutableData.FromLength((int)length);
24+
int length = (int)(stream.Length - stream.Position);
25+
using var buffer = MemoryAllocator.Default.Allocate<byte>(length);
26+
stream.ReadExactly(buffer.Memory.Span);
2527

26-
var bytesSpan = new Span<byte>(nativeData.MutableBytes.ToPointer(), (int)length);
27-
stream.ReadExactly(bytesSpan);
28+
fixed (byte* ptr = buffer.Memory.Span)
29+
{
30+
using var nativeData = NSData.FromBytesNoCopy((IntPtr)ptr, (nuint)length, false);
31+
using var nsImage = new NSImage(nativeData);
2832

29-
using var nsImage = new NSImage(nativeData);
33+
if (nsImage.Handle == IntPtr.Zero)
34+
throw new ArgumentException($"{nameof(Image)} could not be created from {nameof(stream)}.");
3035

31-
if (nsImage.Handle == IntPtr.Zero)
32-
throw new ArgumentException($"{nameof(Image)} could not be created from {nameof(stream)}.");
33-
34-
var cgImage = nsImage.CGImage;
35-
return ImageFromCGImage<TPixel>(cgImage);
36+
var cgImage = nsImage.CGImage;
37+
return ImageFromCGImage<TPixel>(cgImage);
38+
}
3639
}
3740
}
3841
}

0 commit comments

Comments
 (0)