-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb07a37
commit 9dea008
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.IO; | ||
using osu.Framework.IO.Stores; | ||
using osu.Framework.Platform.Apple; | ||
using osu.Framework.Platform.Apple.Native; | ||
using osu.Framework.Platform.MacOS.Native; | ||
using SixLabors.ImageSharp; | ||
|
||
namespace osu.Framework.Platform.MacOS | ||
{ | ||
internal class MacOSTextureLoaderStore : AppleTextureLoaderStore | ||
{ | ||
public MacOSTextureLoaderStore(IResourceStore<byte[]> store) | ||
: base(store) | ||
{ | ||
} | ||
|
||
protected override unsafe Image<TPixel> ImageFromStream<TPixel>(Stream stream) | ||
{ | ||
int length = (int)(stream.Length - stream.Position); | ||
using var nativeData = NSMutableData.FromLength(length); | ||
|
||
var bytesSpan = new Span<byte>(nativeData.MutableBytes, length); | ||
stream.ReadExactly(bytesSpan); | ||
|
||
using var nsImage = NSImage.LoadFromData(nativeData); | ||
if (nsImage.Handle == IntPtr.Zero) | ||
throw new ArgumentException($"{nameof(Image)} could not be created from {nameof(stream)}."); | ||
|
||
var cgImage = nsImage.CGImage; | ||
return ImageFromCGImage<TPixel>(cgImage); | ||
} | ||
} | ||
} |