|
2 | 2 | // Licensed under the Apache License, Version 2.0. |
3 | 3 |
|
4 | 4 | using System; |
| 5 | +using System.IO; |
5 | 6 | using Microsoft.DotNet.RemoteExecutor; |
| 7 | +using SixLabors.ImageSharp.Advanced; |
| 8 | +using SixLabors.ImageSharp.Formats; |
6 | 9 | using SixLabors.ImageSharp.Memory; |
7 | 10 | using SixLabors.ImageSharp.PixelFormats; |
8 | 11 | using SixLabors.ImageSharp.Processing; |
@@ -32,9 +35,40 @@ static void RunTest() |
32 | 35 | Configuration configuration = Configuration.Default.Clone(); |
33 | 36 | configuration.PreferContiguousImageBuffers = true; |
34 | 37 |
|
35 | | - using var image = new Image<Rgba32>(configuration, 8192, 4096); |
| 38 | + using var image = new Image<Rgba32>(configuration, 2048, 2048); |
36 | 39 | Assert.True(image.DangerousTryGetSinglePixelMemory(out Memory<Rgba32> mem)); |
37 | | - Assert.Equal(8192 * 4096, mem.Length); |
| 40 | + Assert.Equal(2048 * 2048, mem.Length); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + [Theory] |
| 45 | + [InlineData("bmp")] |
| 46 | + [InlineData("png")] |
| 47 | + [InlineData("jpeg")] |
| 48 | + [InlineData("gif")] |
| 49 | + [InlineData("tiff")] |
| 50 | + [InlineData("webp")] |
| 51 | + public void PreferContiguousImageBuffers_LoadImage_BufferIsContiguous(string formatOuter) |
| 52 | + { |
| 53 | + // Run remotely to avoid large allocation in the test process: |
| 54 | + RemoteExecutor.Invoke(RunTest, formatOuter).Dispose(); |
| 55 | + |
| 56 | + static void RunTest(string formatInner) |
| 57 | + { |
| 58 | + Configuration configuration = Configuration.Default.Clone(); |
| 59 | + configuration.PreferContiguousImageBuffers = true; |
| 60 | + IImageEncoder encoder = configuration.ImageFormatsManager.FindEncoder( |
| 61 | + configuration.ImageFormatsManager.FindFormatByFileExtension(formatInner)); |
| 62 | + string dir = TestEnvironment.CreateOutputDirectory(".Temp"); |
| 63 | + string path = Path.Combine(dir, $"{Guid.NewGuid().ToString()}.{formatInner}"); |
| 64 | + using (Image<Rgba32> temp = new(2048, 2048)) |
| 65 | + { |
| 66 | + temp.Save(path, encoder); |
| 67 | + } |
| 68 | + |
| 69 | + using var image = Image.Load<Rgba32>(configuration, path); |
| 70 | + File.Delete(path); |
| 71 | + Assert.Equal(1, image.GetPixelMemoryGroup().Count); |
38 | 72 | } |
39 | 73 | } |
40 | 74 |
|
|
0 commit comments