public static void LoadPixels <TPixelFrom, TPixelTo>(
            IReadOnlyPixelRows pixels, IPixelBuffer <TPixelTo> destination, Rectangle?sourceRectangle = null)
            where TPixelFrom : unmanaged, IPixel
            where TPixelTo : unmanaged, IPixel <TPixelTo>
        {
            if (pixels == null)
            {
                throw new ArgumentNullException(nameof(pixels));
            }
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            var rect = sourceRectangle ?? pixels.GetBounds();

            ImagingArgumentGuard.AssertNonEmptyRectangle(rect, nameof(sourceRectangle));

            Span <byte> rowByteBuffer = stackalloc byte[4096];
            var         rowBuffer     = MemoryMarshal.Cast <byte, TPixelFrom>(rowByteBuffer);

            for (int y = 0; y < rect.Height; y++)
            {
                var dstRow = destination.GetPixelRowSpan(y);

                int offsetX = 0;
                do
                {
                    int left  = rect.Width - offsetX;
                    int count = Math.Min(rowBuffer.Length, left);
                    var slice = rowBuffer.Slice(0, count);

                    pixels.GetPixelByteRow(rect.X + offsetX, rect.Y + y, MemoryMarshal.AsBytes(slice));

                    ConvertPixels(slice, dstRow);
                    dstRow   = dstRow[count..];
Exemple #2
0
 public static TPixel GetPixel <TPixel>(this IPixelBuffer <TPixel> buffer, int x, int y)
     where TPixel : unmanaged, IPixel
 {
     return(buffer.GetPixelRowSpan(y)[x]);
 }
Exemple #3
0
 public static Span <TPixel> GetPixelRow <TPixel>(this IPixelBuffer <TPixel> buffer, int y)
     where TPixel : unmanaged, IPixel
 {
     return(buffer.GetPixelRowSpan(y));
 }
Exemple #4
0
 public static void SetPixel <TPixel>(this IPixelBuffer <TPixel> buffer, int x, int y, TPixel value)
     where TPixel : unmanaged, IPixel
 {
     buffer.GetPixelRowSpan(y)[x] = value;
 }