Browse Source

fix remaining single-buffer specific code

pull/1109/head
Anton Firszov 6 years ago
parent
commit
ccdda970b5
  1. 1
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
  2. 7
      src/ImageSharp/Image.LoadPixelData.cs
  3. 4
      src/ImageSharp/ImageFrame.LoadPixelData.cs
  4. 3
      src/ImageSharp/ImageFrame.cs
  5. 2
      src/ImageSharp/ImageFrameCollection{TPixel}.cs
  6. 15
      src/ImageSharp/ImageFrame{TPixel}.cs
  7. 19
      src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs
  8. 2
      src/ImageSharp/Memory/TransformItemsDelegate{T}.cs

1
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs

@ -38,7 +38,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
this.blockAreaSize.Height);
this.BlockRowsPerStep = JpegImagePostProcessor.BlockRowsPerStep / this.Component.SubSamplingDivisors.Height;
}
/// <summary>

7
src/ImageSharp/Image.LoadPixelData.cs

@ -4,6 +4,7 @@
using System;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
@ -118,10 +119,10 @@ namespace SixLabors.ImageSharp
Guard.MustBeGreaterThanOrEqualTo(data.Length, count, nameof(data));
var image = new Image<TPixel>(config, width, height);
data.Slice(0, count).CopyTo(image.Frames.RootFrame.GetPixelSpan());
data = data.Slice(0, count);
data.CopyTo(image.Frames.RootFrame.PixelBuffer.MemoryGroup);
return image;
}
}
}
}

4
src/ImageSharp/ImageFrame.LoadPixelData.cs

@ -4,6 +4,7 @@
using System;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
@ -43,7 +44,8 @@ namespace SixLabors.ImageSharp
var image = new ImageFrame<TPixel>(configuration, width, height);
data.Slice(0, count).CopyTo(image.GetPixelSpan());
data = data.Slice(0, count);
data.CopyTo(image.PixelBuffer.MemoryGroup);
return image;
}

3
src/ImageSharp/ImageFrame.cs

@ -3,6 +3,7 @@
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
@ -78,7 +79,7 @@ namespace SixLabors.ImageSharp
/// <param name="disposing">Whether to dispose of managed and unmanaged objects.</param>
protected abstract void Dispose(bool disposing);
internal abstract void CopyPixelsTo<TDestinationPixel>(Span<TDestinationPixel> destination)
internal abstract void CopyPixelsTo<TDestinationPixel>(MemoryGroup<TDestinationPixel> destination)
where TDestinationPixel : struct, IPixel<TDestinationPixel>;
/// <summary>

2
src/ImageSharp/ImageFrameCollection{TPixel}.cs

@ -351,7 +351,7 @@ namespace SixLabors.ImageSharp
this.parent.GetConfiguration(),
source.Size(),
source.Metadata.DeepClone());
source.CopyPixelsTo(result.PixelBuffer.GetSingleSpan());
source.CopyPixelsTo(result.PixelBuffer.MemoryGroup);
return result;
}
}

15
src/ImageSharp/ImageFrame{TPixel}.cs

@ -218,15 +218,22 @@ namespace SixLabors.ImageSharp
this.isDisposed = true;
}
internal override void CopyPixelsTo<TDestinationPixel>(Span<TDestinationPixel> destination)
internal override void CopyPixelsTo<TDestinationPixel>(MemoryGroup<TDestinationPixel> destination)
{
if (typeof(TPixel) == typeof(TDestinationPixel))
{
Span<TPixel> dest1 = MemoryMarshal.Cast<TDestinationPixel, TPixel>(destination);
this.PixelBuffer.GetSingleSpan().CopyTo(dest1);
this.PixelBuffer.MemoryGroup.TransformTo(destination, (s, d) =>
{
Span<TPixel> d1 = MemoryMarshal.Cast<TDestinationPixel, TPixel>(d);
s.CopyTo(d1);
});
return;
}
PixelOperations<TPixel>.Instance.To(this.GetConfiguration(), this.PixelBuffer.GetSingleSpan(), destination);
this.PixelBuffer.MemoryGroup.TransformTo(destination, (s, d) =>
{
PixelOperations<TPixel>.Instance.To(this.GetConfiguration(), s, d);
});
}
/// <inheritdoc/>

19
src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs

@ -126,11 +126,12 @@ namespace SixLabors.ImageSharp.Memory
}
}
internal static void TransformTo<T>(
this IMemoryGroup<T> source,
IMemoryGroup<T> target,
TransformItemsDelegate<T> transform)
where T : struct
internal static void TransformTo<TSource, TTarget>(
this IMemoryGroup<TSource> source,
IMemoryGroup<TTarget> target,
TransformItemsDelegate<TSource, TTarget> transform)
where TSource : struct
where TTarget : struct
{
Guard.NotNull(source, nameof(source));
Guard.NotNull(target, nameof(target));
@ -145,14 +146,14 @@ namespace SixLabors.ImageSharp.Memory
}
long position = 0;
var srcCur = new MemoryGroupCursor<T>(source);
var trgCur = new MemoryGroupCursor<T>(target);
var srcCur = new MemoryGroupCursor<TSource>(source);
var trgCur = new MemoryGroupCursor<TTarget>(target);
while (position < source.TotalLength)
{
int fwd = Math.Min(srcCur.LookAhead(), trgCur.LookAhead());
Span<T> srcSpan = srcCur.GetSpan(fwd);
Span<T> trgSpan = trgCur.GetSpan(fwd);
Span<TSource> srcSpan = srcCur.GetSpan(fwd);
Span<TTarget> trgSpan = trgCur.GetSpan(fwd);
transform(srcSpan, trgSpan);
srcCur.Forward(fwd);

2
src/ImageSharp/Memory/TransformItemsDelegate{T}.cs

@ -5,5 +5,5 @@ using System;
namespace SixLabors.ImageSharp.Memory
{
internal delegate void TransformItemsDelegate<T>(ReadOnlySpan<T> source, Span<T> target);
internal delegate void TransformItemsDelegate<TSource, TTarget>(ReadOnlySpan<TSource> source, Span<TTarget> target);
}

Loading…
Cancel
Save