Creating a new Image<TPixel> by Wrapping IMemoryOwner<byte> #1580
-
What are your thoughts on adding a WrapMemory overload that takes in // showing usings of third-party libs
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using Microsoft.Toolkit.HighPerformance;
using Microsoft.Toolkit.HighPerformance.Buffers;
private static IMemoryOwner<byte> ZlibDecompress(ReadOnlyMemory<byte> data)
{
using (var ss = data.AsStream())
using (var iis = new InflaterInputStream(ss))
{
var bufferWriter = new ArrayPoolBufferWriter<byte>(data.Length);
// Inflate
iis.CopyTo(bufferWriter.AsStream());
return bufferWriter;
}
}
// showing usage code
var compressedData = ...;
IMemoryOwner<byte> decompressedMemoryOwner = ZlibDecompress(compressedData);
// This does not work, expects IMemoryOwner<TPixel>
var image = Image.WrapMemory<TPixel>(decompressedMemoryOwner, width, height); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This would be essentially a convenience extension accompanying an existing ImageSharp/src/ImageSharp/Image.WrapMemory.cs Lines 140 to 147 in 08b0320 Since /cc @Sergio0694 |
Beta Was this translation helpful? Give feedback.
This would be essentially a convenience extension accompanying an existing
IMemoryOwner<TPixel>
method:ImageSharp/src/ImageSharp/Image.WrapMemory.cs
Lines 140 to 147 in 08b0320
Since
Memory<byte>
overloads already exist, it makes sense to also haveIMemoryOwner<byte>
overloads for API symmetry. The easiest implementation would be to create aWrapperMemoryOwner<TPixel>
that adaptsIMemoryOwner<byte>
. Interested in PR-ing it?/cc @Serg…