mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
733 lines
42 KiB
733 lines
42 KiB
// Copyright (c) Six Labors and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// <auto-generated />
|
|
|
|
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace SixLabors.ImageSharp.PixelFormats
|
|
{
|
|
public partial class PixelOperations<TPixel>
|
|
{
|
|
/// <summary>
|
|
/// Converts all pixels in 'source` span of <see cref="Argb32"/> into a span of <typeparamref name="TPixel"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Argb32"/> data.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
internal virtual void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> source, Span<TPixel> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
|
|
|
|
ref Argb32 sourceBaseRef = ref MemoryMarshal.GetReference(source);
|
|
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
ref Argb32 sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromArgb32(sp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="FromArgb32(Configuration, ReadOnlySpan{Argb32}, Span{TPixel})"/> that expects a byte span.
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Argb32"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void FromArgb32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count)
|
|
{
|
|
this.FromArgb32(configuration, MemoryMarshal.Cast<byte, Argb32>(sourceBytes).Slice(0, count), destPixels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Argb32"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The span of source pixels</param>
|
|
/// <param name="destPixels">The destination span of <see cref="Argb32"/> data.</param>
|
|
internal virtual void ToArgb32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Argb32> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
|
|
|
|
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
|
|
ref Argb32 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < sourcePixels.Length; i++)
|
|
{
|
|
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref Argb32 dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromScaledVector4(sp.ToScaledVector4());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="ToArgb32(Configuration, ReadOnlySpan{TPixel}, Span{Argb32})"/> that expects a byte span as destination.
|
|
/// The layout of the data in 'destBytes' must be compatible with <see cref="Argb32"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
|
|
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ToArgb32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
|
|
{
|
|
this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Argb32>(destBytes));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels in 'source` span of <see cref="Bgr24"/> into a span of <typeparamref name="TPixel"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Bgr24"/> data.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
internal virtual void FromBgr24(Configuration configuration, ReadOnlySpan<Bgr24> source, Span<TPixel> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
|
|
|
|
ref Bgr24 sourceBaseRef = ref MemoryMarshal.GetReference(source);
|
|
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
ref Bgr24 sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromBgr24(sp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="FromBgr24(Configuration, ReadOnlySpan{Bgr24}, Span{TPixel})"/> that expects a byte span.
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Bgr24"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void FromBgr24Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count)
|
|
{
|
|
this.FromBgr24(configuration, MemoryMarshal.Cast<byte, Bgr24>(sourceBytes).Slice(0, count), destPixels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Bgr24"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The span of source pixels</param>
|
|
/// <param name="destPixels">The destination span of <see cref="Bgr24"/> data.</param>
|
|
internal virtual void ToBgr24(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Bgr24> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
|
|
|
|
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
|
|
ref Bgr24 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < sourcePixels.Length; i++)
|
|
{
|
|
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref Bgr24 dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromScaledVector4(sp.ToScaledVector4());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="ToBgr24(Configuration, ReadOnlySpan{TPixel}, Span{Bgr24})"/> that expects a byte span as destination.
|
|
/// The layout of the data in 'destBytes' must be compatible with <see cref="Bgr24"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
|
|
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ToBgr24Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
|
|
{
|
|
this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Bgr24>(destBytes));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels in 'source` span of <see cref="Bgra32"/> into a span of <typeparamref name="TPixel"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Bgra32"/> data.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
internal virtual void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> source, Span<TPixel> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
|
|
|
|
ref Bgra32 sourceBaseRef = ref MemoryMarshal.GetReference(source);
|
|
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
ref Bgra32 sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromBgra32(sp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="FromBgra32(Configuration, ReadOnlySpan{Bgra32}, Span{TPixel})"/> that expects a byte span.
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Bgra32"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void FromBgra32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count)
|
|
{
|
|
this.FromBgra32(configuration, MemoryMarshal.Cast<byte, Bgra32>(sourceBytes).Slice(0, count), destPixels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Bgra32"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The span of source pixels</param>
|
|
/// <param name="destPixels">The destination span of <see cref="Bgra32"/> data.</param>
|
|
internal virtual void ToBgra32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Bgra32> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
|
|
|
|
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
|
|
ref Bgra32 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < sourcePixels.Length; i++)
|
|
{
|
|
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref Bgra32 dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromScaledVector4(sp.ToScaledVector4());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="ToBgra32(Configuration, ReadOnlySpan{TPixel}, Span{Bgra32})"/> that expects a byte span as destination.
|
|
/// The layout of the data in 'destBytes' must be compatible with <see cref="Bgra32"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
|
|
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ToBgra32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
|
|
{
|
|
this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Bgra32>(destBytes));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels in 'source` span of <see cref="Gray8"/> into a span of <typeparamref name="TPixel"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Gray8"/> data.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
internal virtual void FromGray8(Configuration configuration, ReadOnlySpan<Gray8> source, Span<TPixel> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
|
|
|
|
ref Gray8 sourceBaseRef = ref MemoryMarshal.GetReference(source);
|
|
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
ref Gray8 sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromGray8(sp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="FromGray8(Configuration, ReadOnlySpan{Gray8}, Span{TPixel})"/> that expects a byte span.
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Gray8"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void FromGray8Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count)
|
|
{
|
|
this.FromGray8(configuration, MemoryMarshal.Cast<byte, Gray8>(sourceBytes).Slice(0, count), destPixels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Gray8"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The span of source pixels</param>
|
|
/// <param name="destPixels">The destination span of <see cref="Gray8"/> data.</param>
|
|
internal virtual void ToGray8(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Gray8> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
|
|
|
|
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
|
|
ref Gray8 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < sourcePixels.Length; i++)
|
|
{
|
|
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref Gray8 dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromScaledVector4(sp.ToScaledVector4());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="ToGray8(Configuration, ReadOnlySpan{TPixel}, Span{Gray8})"/> that expects a byte span as destination.
|
|
/// The layout of the data in 'destBytes' must be compatible with <see cref="Gray8"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
|
|
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ToGray8Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
|
|
{
|
|
this.ToGray8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Gray8>(destBytes));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels in 'source` span of <see cref="Gray16"/> into a span of <typeparamref name="TPixel"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Gray16"/> data.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
internal virtual void FromGray16(Configuration configuration, ReadOnlySpan<Gray16> source, Span<TPixel> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
|
|
|
|
ref Gray16 sourceBaseRef = ref MemoryMarshal.GetReference(source);
|
|
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
ref Gray16 sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromGray16(sp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="FromGray16(Configuration, ReadOnlySpan{Gray16}, Span{TPixel})"/> that expects a byte span.
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Gray16"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void FromGray16Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count)
|
|
{
|
|
this.FromGray16(configuration, MemoryMarshal.Cast<byte, Gray16>(sourceBytes).Slice(0, count), destPixels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Gray16"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The span of source pixels</param>
|
|
/// <param name="destPixels">The destination span of <see cref="Gray16"/> data.</param>
|
|
internal virtual void ToGray16(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Gray16> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
|
|
|
|
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
|
|
ref Gray16 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < sourcePixels.Length; i++)
|
|
{
|
|
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref Gray16 dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromScaledVector4(sp.ToScaledVector4());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="ToGray16(Configuration, ReadOnlySpan{TPixel}, Span{Gray16})"/> that expects a byte span as destination.
|
|
/// The layout of the data in 'destBytes' must be compatible with <see cref="Gray16"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
|
|
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ToGray16Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
|
|
{
|
|
this.ToGray16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Gray16>(destBytes));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels in 'source` span of <see cref="Rgb24"/> into a span of <typeparamref name="TPixel"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgb24"/> data.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
internal virtual void FromRgb24(Configuration configuration, ReadOnlySpan<Rgb24> source, Span<TPixel> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
|
|
|
|
ref Rgb24 sourceBaseRef = ref MemoryMarshal.GetReference(source);
|
|
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
ref Rgb24 sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromRgb24(sp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="FromRgb24(Configuration, ReadOnlySpan{Rgb24}, Span{TPixel})"/> that expects a byte span.
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Rgb24"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void FromRgb24Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count)
|
|
{
|
|
this.FromRgb24(configuration, MemoryMarshal.Cast<byte, Rgb24>(sourceBytes).Slice(0, count), destPixels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Rgb24"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The span of source pixels</param>
|
|
/// <param name="destPixels">The destination span of <see cref="Rgb24"/> data.</param>
|
|
internal virtual void ToRgb24(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgb24> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
|
|
|
|
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
|
|
ref Rgb24 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < sourcePixels.Length; i++)
|
|
{
|
|
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref Rgb24 dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromScaledVector4(sp.ToScaledVector4());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="ToRgb24(Configuration, ReadOnlySpan{TPixel}, Span{Rgb24})"/> that expects a byte span as destination.
|
|
/// The layout of the data in 'destBytes' must be compatible with <see cref="Rgb24"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
|
|
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ToRgb24Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
|
|
{
|
|
this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgb24>(destBytes));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels in 'source` span of <see cref="Rgba32"/> into a span of <typeparamref name="TPixel"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgba32"/> data.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
internal virtual void FromRgba32(Configuration configuration, ReadOnlySpan<Rgba32> source, Span<TPixel> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
|
|
|
|
ref Rgba32 sourceBaseRef = ref MemoryMarshal.GetReference(source);
|
|
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
ref Rgba32 sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromRgba32(sp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="FromRgba32(Configuration, ReadOnlySpan{Rgba32}, Span{TPixel})"/> that expects a byte span.
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Rgba32"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void FromRgba32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count)
|
|
{
|
|
this.FromRgba32(configuration, MemoryMarshal.Cast<byte, Rgba32>(sourceBytes).Slice(0, count), destPixels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Rgba32"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The span of source pixels</param>
|
|
/// <param name="destPixels">The destination span of <see cref="Rgba32"/> data.</param>
|
|
internal virtual void ToRgba32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgba32> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
|
|
|
|
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
|
|
ref Rgba32 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < sourcePixels.Length; i++)
|
|
{
|
|
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref Rgba32 dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromScaledVector4(sp.ToScaledVector4());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="ToRgba32(Configuration, ReadOnlySpan{TPixel}, Span{Rgba32})"/> that expects a byte span as destination.
|
|
/// The layout of the data in 'destBytes' must be compatible with <see cref="Rgba32"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
|
|
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ToRgba32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
|
|
{
|
|
this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgba32>(destBytes));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels in 'source` span of <see cref="Rgb48"/> into a span of <typeparamref name="TPixel"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgb48"/> data.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
internal virtual void FromRgb48(Configuration configuration, ReadOnlySpan<Rgb48> source, Span<TPixel> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
|
|
|
|
ref Rgb48 sourceBaseRef = ref MemoryMarshal.GetReference(source);
|
|
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
ref Rgb48 sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromRgb48(sp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="FromRgb48(Configuration, ReadOnlySpan{Rgb48}, Span{TPixel})"/> that expects a byte span.
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Rgb48"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void FromRgb48Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count)
|
|
{
|
|
this.FromRgb48(configuration, MemoryMarshal.Cast<byte, Rgb48>(sourceBytes).Slice(0, count), destPixels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Rgb48"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The span of source pixels</param>
|
|
/// <param name="destPixels">The destination span of <see cref="Rgb48"/> data.</param>
|
|
internal virtual void ToRgb48(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgb48> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
|
|
|
|
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
|
|
ref Rgb48 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < sourcePixels.Length; i++)
|
|
{
|
|
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref Rgb48 dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromScaledVector4(sp.ToScaledVector4());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="ToRgb48(Configuration, ReadOnlySpan{TPixel}, Span{Rgb48})"/> that expects a byte span as destination.
|
|
/// The layout of the data in 'destBytes' must be compatible with <see cref="Rgb48"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
|
|
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ToRgb48Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
|
|
{
|
|
this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgb48>(destBytes));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels in 'source` span of <see cref="Rgba64"/> into a span of <typeparamref name="TPixel"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Rgba64"/> data.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
internal virtual void FromRgba64(Configuration configuration, ReadOnlySpan<Rgba64> source, Span<TPixel> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
|
|
|
|
ref Rgba64 sourceBaseRef = ref MemoryMarshal.GetReference(source);
|
|
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
ref Rgba64 sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromRgba64(sp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="FromRgba64(Configuration, ReadOnlySpan{Rgba64}, Span{TPixel})"/> that expects a byte span.
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Rgba64"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void FromRgba64Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count)
|
|
{
|
|
this.FromRgba64(configuration, MemoryMarshal.Cast<byte, Rgba64>(sourceBytes).Slice(0, count), destPixels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Rgba64"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The span of source pixels</param>
|
|
/// <param name="destPixels">The destination span of <see cref="Rgba64"/> data.</param>
|
|
internal virtual void ToRgba64(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Rgba64> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
|
|
|
|
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
|
|
ref Rgba64 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < sourcePixels.Length; i++)
|
|
{
|
|
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref Rgba64 dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromScaledVector4(sp.ToScaledVector4());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="ToRgba64(Configuration, ReadOnlySpan{TPixel}, Span{Rgba64})"/> that expects a byte span as destination.
|
|
/// The layout of the data in 'destBytes' must be compatible with <see cref="Rgba64"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
|
|
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ToRgba64Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
|
|
{
|
|
this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Rgba64>(destBytes));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels in 'source` span of <see cref="Bgra5551"/> into a span of <typeparamref name="TPixel"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Bgra5551"/> data.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
internal virtual void FromBgra5551(Configuration configuration, ReadOnlySpan<Bgra5551> source, Span<TPixel> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
|
|
|
|
ref Bgra5551 sourceBaseRef = ref MemoryMarshal.GetReference(source);
|
|
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
{
|
|
ref Bgra5551 sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromBgra5551(sp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="FromBgra5551(Configuration, ReadOnlySpan{Bgra5551}, Span{TPixel})"/> that expects a byte span.
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Bgra5551"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void FromBgra5551Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count)
|
|
{
|
|
this.FromBgra5551(configuration, MemoryMarshal.Cast<byte, Bgra5551>(sourceBytes).Slice(0, count), destPixels);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Bgra5551"/>-s.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The span of source pixels</param>
|
|
/// <param name="destPixels">The destination span of <see cref="Bgra5551"/> data.</param>
|
|
internal virtual void ToBgra5551(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Bgra5551> destPixels)
|
|
{
|
|
Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
|
|
|
|
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
|
|
ref Bgra5551 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
|
|
|
|
for (int i = 0; i < sourcePixels.Length; i++)
|
|
{
|
|
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
|
|
ref Bgra5551 dp = ref Unsafe.Add(ref destBaseRef, i);
|
|
|
|
dp.FromScaledVector4(sp.ToScaledVector4());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A helper for <see cref="ToBgra5551(Configuration, ReadOnlySpan{TPixel}, Span{Bgra5551})"/> that expects a byte span as destination.
|
|
/// The layout of the data in 'destBytes' must be compatible with <see cref="Bgra5551"/> layout.
|
|
/// </summary>
|
|
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
|
|
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
|
|
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
|
|
/// <param name="count">The number of pixels to convert.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal void ToBgra5551Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
|
|
{
|
|
this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Bgra5551>(destBytes));
|
|
}
|
|
}
|
|
}
|