|
12 | 12 | using osu.Framework.Graphics.Textures;
|
13 | 13 | using osu.Framework.IO.Stores;
|
14 | 14 | using SixLabors.ImageSharp;
|
15 |
| -using SixLabors.ImageSharp.Processing; |
| 15 | +using SixLabors.ImageSharp.Advanced; |
16 | 16 | using UIKit;
|
17 | 17 |
|
18 | 18 | namespace osu.Framework.iOS.Graphics.Textures
|
@@ -53,21 +53,26 @@ protected override unsafe Image<TPixel> ImageFromStream<TPixel>(Stream stream)
|
53 | 53 | vImageBuffer accelerateImage = default;
|
54 | 54 |
|
55 | 55 | // perform initial call to retrieve preferred alignment and bytes-per-row values for the given image dimensions.
|
56 |
| - long alignment = (long)vImageBuffer_Init(&accelerateImage, (uint)height, (uint)width, 32, vImageFlags.NoAllocate); |
| 56 | + nuint alignment = (nuint)vImageBuffer_Init(&accelerateImage, (uint)height, (uint)width, 32, vImageFlags.NoAllocate); |
57 | 57 | Debug.Assert(alignment > 0);
|
58 | 58 |
|
59 | 59 | // allocate aligned memory region to contain image pixel data.
|
60 |
| - int bytesCount = accelerateImage.BytesPerRow * accelerateImage.Height; |
61 |
| - accelerateImage.Data = (IntPtr)NativeMemory.AlignedAlloc((nuint)(accelerateImage.BytesPerRow * accelerateImage.Height), (nuint)alignment); |
| 60 | + int bytesPerRow = accelerateImage.BytesPerRow; |
| 61 | + int bytesCount = bytesPerRow * accelerateImage.Height; |
| 62 | + accelerateImage.Data = (IntPtr)NativeMemory.AlignedAlloc((nuint)bytesCount, alignment); |
62 | 63 |
|
63 | 64 | var result = vImageBuffer_InitWithCGImage(&accelerateImage, &format, null, uiImage.CGImage!.Handle, vImageFlags.NoAllocate);
|
64 | 65 | Debug.Assert(result == vImageError.NoError);
|
65 | 66 |
|
66 |
| - var dataSpan = new ReadOnlySpan<byte>(accelerateImage.Data.ToPointer(), bytesCount); |
| 67 | + var image = new Image<TPixel>(width, height); |
| 68 | + byte* data = (byte*)accelerateImage.Data; |
67 | 69 |
|
68 |
| - int stride = accelerateImage.BytesPerRow / 4; |
69 |
| - var image = Image.LoadPixelData<TPixel>(dataSpan, stride, height); |
70 |
| - image.Mutate(i => i.Crop(width, height)); |
| 70 | + for (int i = 0; i < height; i++) |
| 71 | + { |
| 72 | + var imageRow = image.DangerousGetPixelRowMemory(i); |
| 73 | + var dataRow = new ReadOnlySpan<TPixel>(&data[bytesPerRow * i], width); |
| 74 | + dataRow.CopyTo(imageRow.Span); |
| 75 | + } |
71 | 76 |
|
72 | 77 | NativeMemory.AlignedFree(accelerateImage.Data.ToPointer());
|
73 | 78 | return image;
|
|
0 commit comments