Browse Source

API chunks

af/UniformUnmanagedMemoryPoolMemoryAllocator-02-MemoryGuards
Anton Firszov 5 years ago
parent
commit
32ae7cff83
  1. 18
      src/ImageSharp/ImageFrame{TPixel}.cs
  2. 19
      src/ImageSharp/Image{TPixel}.cs
  3. 62
      src/ImageSharp/PixelAccessor{TPixel}.cs
  4. 3
      tests/ImageSharp.Tests.ProfilingSandbox/LoadResizeSaveParallelMemoryStress.cs
  5. 26
      tests/ImageSharp.Tests.ProfilingSandbox/Program.cs
  6. 2
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

18
src/ImageSharp/ImageFrame{TPixel}.cs

@ -12,6 +12,8 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp
{ {
/// <summary> /// <summary>
/// Represents a pixel-specific image frame containing all pixel data and <see cref="ImageFrameMetadata"/>. /// Represents a pixel-specific image frame containing all pixel data and <see cref="ImageFrameMetadata"/>.
/// In case of animated formats like gif, it contains the single frame in a animation. /// 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); return this.PixelBuffer.GetRowSpan(rowIndex);
} }
public void ProcessPixelRows(PixelAccessorAction<TPixel> processPixels) => throw new NotImplementedException();
public void ProcessPixelRows<TPixel2>(
Image<TPixel2> image2,
PixelAccessorAction<TPixel, TPixel2> processPixels)
where TPixel2 : unmanaged, IPixel<TPixel2>
=> throw new NotImplementedException();
public void ProcessPixelRows<TPixel2, TPixel3>(
Image<TPixel2> image2,
Image<TPixel3> image3,
PixelAccessorAction<TPixel, TPixel2, TPixel3> processPixels)
where TPixel2 : unmanaged, IPixel<TPixel2>
where TPixel3 : unmanaged, IPixel<TPixel3>
=> throw new NotImplementedException();
/// <summary> /// <summary>
/// Gets the representation of the pixels as a <see cref="Span{T}"/> in the source image's pixel format /// Gets the representation of the pixels as a <see cref="Span{T}"/> in the source image's pixel format
/// stored in row major order, if the backing buffer is contiguous. /// stored in row major order, if the backing buffer is contiguous.

19
src/ImageSharp/Image{TPixel}.cs

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -203,6 +204,22 @@ namespace SixLabors.ImageSharp
} }
} }
public void ProcessPixelRows(PixelAccessorAction<TPixel> processPixels) => throw new NotImplementedException();
public void ProcessPixelRows<TPixel2>(
Image<TPixel2> image2,
PixelAccessorAction<TPixel, TPixel2> processPixels)
where TPixel2 : unmanaged, IPixel<TPixel2>
=> throw new NotImplementedException();
public void ProcessPixelRows<TPixel2, TPixel3>(
Image<TPixel2> image2,
Image<TPixel3> image3,
PixelAccessorAction<TPixel, TPixel2, TPixel3> processPixels)
where TPixel2 : unmanaged, IPixel<TPixel2>
where TPixel3 : unmanaged, IPixel<TPixel3>
=> throw new NotImplementedException();
/// <summary> /// <summary>
/// Gets the representation of the pixels as a <see cref="Span{T}"/> of contiguous memory /// Gets the representation of the pixels as a <see cref="Span{T}"/> of contiguous memory
/// at row <paramref name="rowIndex"/> beginning from the first pixel on that row. /// at row <paramref name="rowIndex"/> beginning from the first pixel on that row.
@ -242,6 +259,8 @@ namespace SixLabors.ImageSharp
return false; return false;
} }
public bool DangerousTryGetSinglePixelMemory(out Memory<TPixel> memory) => throw new NotImplementedException();
/// <summary> /// <summary>
/// Clones the current image /// Clones the current image
/// </summary> /// </summary>

62
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
{
/// <summary>
/// A delegate to be executed on a <see cref="PixelAccessor{TPixel}"/>.
/// </summary>
/// <typeparam name="TPixel">The pixel type.</typeparam>
public delegate void PixelAccessorAction<TPixel>(PixelAccessor<TPixel> pixelAccessor)
where TPixel : unmanaged, IPixel<TPixel>;
/// <summary>
/// A delegate to be executed on two instances of <see cref="PixelAccessor{TPixel}"/>.
/// </summary>
/// <typeparam name="TPixel1">The first pixel type.</typeparam>
/// <typeparam name="TPixel2">The second pixel type.</typeparam>
public delegate void PixelAccessorAction<TPixel1, TPixel2>(
PixelAccessor<TPixel1> pixelAccessor1,
PixelAccessor<TPixel2> pixelAccessor2)
where TPixel1 : unmanaged, IPixel<TPixel1>
where TPixel2 : unmanaged, IPixel<TPixel2>;
/// <summary>
/// A delegate to be executed on three instances of <see cref="PixelAccessor{TPixel}"/>.
/// </summary>
/// <typeparam name="TPixel1">The first pixel type.</typeparam>
/// <typeparam name="TPixel2">The second pixel type.</typeparam>
/// <typeparam name="TPixel3">The third pixel type.</typeparam>
public delegate void PixelAccessorAction<TPixel1, TPixel2, TPixel3>(
PixelAccessor<TPixel1> pixelAccessor1,
PixelAccessor<TPixel2> pixelAccessor2,
PixelAccessor<TPixel2> pixelAccessor3)
where TPixel1 : unmanaged, IPixel<TPixel1>
where TPixel2 : unmanaged, IPixel<TPixel2>
where TPixel3 : unmanaged, IPixel<TPixel3>;
/// <summary>
/// Provides efficient access the pixel buffers of an <see cref="Image{TPixel}"/>.
/// </summary>
/// <typeparam name="TPixel">The pixel type.</typeparam>
public ref struct PixelAccessor<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
/// <summary>
/// Gets the height of the backing <see cref="Image{TPixel}"/>.
/// </summary>
public int Height { get; }
/// <summary>
/// Gets the representation of the pixels as a <see cref="Span{T}"/> of contiguous memory
/// at row <paramref name="rowIndex"/> beginning from the first pixel on that row.
/// </summary>
/// <param name="rowIndex">The row.</param>
/// <returns>The <see cref="Span{TPixel}"/>.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when row index is out of range.</exception>
public Span<TPixel> GetRowSpan(int rowIndex) => throw new NotImplementedException();
}
}

3
tests/ImageSharp.Tests.ProfilingSandbox/LoadResizeSaveParallelMemoryStress.cs

@ -31,6 +31,8 @@ namespace SixLabors.ImageSharp.Tests.ProfilingSandbox
public static void Run(string[] args) 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 options = args.Length > 0 ? CommandLineOptions.Parse(args) : null;
var lrs = new LoadResizeSaveParallelMemoryStress(); var lrs = new LoadResizeSaveParallelMemoryStress();
@ -80,6 +82,7 @@ namespace SixLabors.ImageSharp.Tests.ProfilingSandbox
} }
var stats = new Stats(timer, lrs.Benchmarks.TotalProcessedMegapixels); var stats = new Stats(timer, lrs.Benchmarks.TotalProcessedMegapixels);
Console.WriteLine("Total Megapixels: " + stats.TotalMegapixels);
Console.WriteLine(stats.GetMarkdown()); Console.WriteLine(stats.GetMarkdown());
if (options?.FileOutput != null) if (options?.FileOutput != null)
{ {

26
tests/ImageSharp.Tests.ProfilingSandbox/Program.cs

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Reflection;
using System.Threading; using System.Threading;
using SixLabors.ImageSharp.Memory.Internals; using SixLabors.ImageSharp.Memory.Internals;
using SixLabors.ImageSharp.Tests.Formats.Jpg; using SixLabors.ImageSharp.Tests.Formats.Jpg;
@ -33,7 +34,16 @@ namespace SixLabors.ImageSharp.Tests.ProfilingSandbox
/// </param> /// </param>
public static void Main(string[] args) public static void Main(string[] args)
{ {
LoadResizeSaveParallelMemoryStress.Run(args); try
{
Console.WriteLine("WUT: " + GetNetCoreVersion());
LoadResizeSaveParallelMemoryStress.Run(args);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
// RunJpegEncoderProfilingTests(); // RunJpegEncoderProfilingTests();
// RunJpegColorProfilingTests(); // RunJpegColorProfilingTests();
// RunDecodeJpegProfilingTests(); // RunDecodeJpegProfilingTests();
@ -43,6 +53,20 @@ namespace SixLabors.ImageSharp.Tests.ProfilingSandbox
// Console.ReadLine(); // 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() private static void RunJpegEncoderProfilingTests()
{ {
var benchmarks = new JpegProfilingBenchmarks(new ConsoleOutput()); var benchmarks = new JpegProfilingBenchmarks(new ConsoleOutput());

2
tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.Tests
/// </summary> /// </summary>
private static void PrepareRemoteExecutor() private static void PrepareRemoteExecutor()
{ {
if (!IsFramework) if (!IsFramework || !Environment.Is64BitProcess)
{ {
return; return;
} }

Loading…
Cancel
Save