From 32ae7cff835f2c02b80c7d04b4bc9df8a9167a21 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 14 Aug 2021 19:54:19 +0200 Subject: [PATCH] API chunks --- src/ImageSharp/ImageFrame{TPixel}.cs | 18 ++++++ src/ImageSharp/Image{TPixel}.cs | 19 ++++++ src/ImageSharp/PixelAccessor{TPixel}.cs | 62 +++++++++++++++++++ .../LoadResizeSaveParallelMemoryStress.cs | 3 + .../Program.cs | 26 +++++++- .../TestUtilities/TestEnvironment.cs | 2 +- 6 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 src/ImageSharp/PixelAccessor{TPixel}.cs diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 8249f8136..0174b249b 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -12,6 +12,8 @@ using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp { + + /// /// Represents a pixel-specific image frame containing all pixel data and . /// In case of animated formats like gif, it contains the single frame in a animation. @@ -185,6 +187,22 @@ namespace SixLabors.ImageSharp return this.PixelBuffer.GetRowSpan(rowIndex); } + public void ProcessPixelRows(PixelAccessorAction processPixels) => throw new NotImplementedException(); + + public void ProcessPixelRows( + Image image2, + PixelAccessorAction processPixels) + where TPixel2 : unmanaged, IPixel + => throw new NotImplementedException(); + + public void ProcessPixelRows( + Image image2, + Image image3, + PixelAccessorAction processPixels) + where TPixel2 : unmanaged, IPixel + where TPixel3 : unmanaged, IPixel + => throw new NotImplementedException(); + /// /// Gets the representation of the pixels as a in the source image's pixel format /// stored in row major order, if the backing buffer is contiguous. diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 1a7f84c15..c1a084611 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Buffers; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; @@ -203,6 +204,22 @@ namespace SixLabors.ImageSharp } } + public void ProcessPixelRows(PixelAccessorAction processPixels) => throw new NotImplementedException(); + + public void ProcessPixelRows( + Image image2, + PixelAccessorAction processPixels) + where TPixel2 : unmanaged, IPixel + => throw new NotImplementedException(); + + public void ProcessPixelRows( + Image image2, + Image image3, + PixelAccessorAction processPixels) + where TPixel2 : unmanaged, IPixel + where TPixel3 : unmanaged, IPixel + => throw new NotImplementedException(); + /// /// Gets the representation of the pixels as a of contiguous memory /// at row beginning from the first pixel on that row. @@ -242,6 +259,8 @@ namespace SixLabors.ImageSharp return false; } + public bool DangerousTryGetSinglePixelMemory(out Memory memory) => throw new NotImplementedException(); + /// /// Clones the current image /// diff --git a/src/ImageSharp/PixelAccessor{TPixel}.cs b/src/ImageSharp/PixelAccessor{TPixel}.cs new file mode 100644 index 000000000..0a7f408af --- /dev/null +++ b/src/ImageSharp/PixelAccessor{TPixel}.cs @@ -0,0 +1,62 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp +{ + /// + /// A delegate to be executed on a . + /// + /// The pixel type. + public delegate void PixelAccessorAction(PixelAccessor pixelAccessor) + where TPixel : unmanaged, IPixel; + + /// + /// A delegate to be executed on two instances of . + /// + /// The first pixel type. + /// The second pixel type. + public delegate void PixelAccessorAction( + PixelAccessor pixelAccessor1, + PixelAccessor pixelAccessor2) + where TPixel1 : unmanaged, IPixel + where TPixel2 : unmanaged, IPixel; + + /// + /// A delegate to be executed on three instances of . + /// + /// The first pixel type. + /// The second pixel type. + /// The third pixel type. + public delegate void PixelAccessorAction( + PixelAccessor pixelAccessor1, + PixelAccessor pixelAccessor2, + PixelAccessor pixelAccessor3) + where TPixel1 : unmanaged, IPixel + where TPixel2 : unmanaged, IPixel + where TPixel3 : unmanaged, IPixel; + + /// + /// Provides efficient access the pixel buffers of an . + /// + /// The pixel type. + public ref struct PixelAccessor + where TPixel : unmanaged, IPixel + { + /// + /// Gets the height of the backing . + /// + public int Height { get; } + + /// + /// Gets the representation of the pixels as a of contiguous memory + /// at row beginning from the first pixel on that row. + /// + /// The row. + /// The . + /// Thrown when row index is out of range. + public Span GetRowSpan(int rowIndex) => throw new NotImplementedException(); + } +} diff --git a/tests/ImageSharp.Tests.ProfilingSandbox/LoadResizeSaveParallelMemoryStress.cs b/tests/ImageSharp.Tests.ProfilingSandbox/LoadResizeSaveParallelMemoryStress.cs index 0c0691059..38dd9f812 100644 --- a/tests/ImageSharp.Tests.ProfilingSandbox/LoadResizeSaveParallelMemoryStress.cs +++ b/tests/ImageSharp.Tests.ProfilingSandbox/LoadResizeSaveParallelMemoryStress.cs @@ -31,6 +31,8 @@ namespace SixLabors.ImageSharp.Tests.ProfilingSandbox public static void Run(string[] args) { + Console.WriteLine($"Running: {typeof(LoadResizeSaveParallelMemoryStress).Assembly.Location}"); + Console.WriteLine($"64 bit: {Environment.Is64BitProcess}"); var options = args.Length > 0 ? CommandLineOptions.Parse(args) : null; var lrs = new LoadResizeSaveParallelMemoryStress(); @@ -80,6 +82,7 @@ namespace SixLabors.ImageSharp.Tests.ProfilingSandbox } var stats = new Stats(timer, lrs.Benchmarks.TotalProcessedMegapixels); + Console.WriteLine("Total Megapixels: " + stats.TotalMegapixels); Console.WriteLine(stats.GetMarkdown()); if (options?.FileOutput != null) { diff --git a/tests/ImageSharp.Tests.ProfilingSandbox/Program.cs b/tests/ImageSharp.Tests.ProfilingSandbox/Program.cs index 87d6a363b..2e0d8d97c 100644 --- a/tests/ImageSharp.Tests.ProfilingSandbox/Program.cs +++ b/tests/ImageSharp.Tests.ProfilingSandbox/Program.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Reflection; using System.Threading; using SixLabors.ImageSharp.Memory.Internals; using SixLabors.ImageSharp.Tests.Formats.Jpg; @@ -33,7 +34,16 @@ namespace SixLabors.ImageSharp.Tests.ProfilingSandbox /// public static void Main(string[] args) { - LoadResizeSaveParallelMemoryStress.Run(args); + try + { + Console.WriteLine("WUT: " + GetNetCoreVersion()); + LoadResizeSaveParallelMemoryStress.Run(args); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + // RunJpegEncoderProfilingTests(); // RunJpegColorProfilingTests(); // RunDecodeJpegProfilingTests(); @@ -43,6 +53,20 @@ namespace SixLabors.ImageSharp.Tests.ProfilingSandbox // Console.ReadLine(); } + private static Version GetNetCoreVersion() + { + Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly; + Console.WriteLine(assembly.Location); + string[] assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); + int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App"); + if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2) + { + return Version.Parse(assemblyPath[netCoreAppIndex + 1]); + } + + return null; + } + private static void RunJpegEncoderProfilingTests() { var benchmarks = new JpegProfilingBenchmarks(new ConsoleOutput()); diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs index 00633b959..00d8a5c1c 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs @@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.Tests /// private static void PrepareRemoteExecutor() { - if (!IsFramework) + if (!IsFramework || !Environment.Is64BitProcess) { return; }