mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
5 changed files with 95 additions and 134 deletions
@ -1,112 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace SixLabors.ImageSharp.Tuples |
|||
{ |
|||
/// <summary>
|
|||
/// Contains 8 element value tuples of various types.
|
|||
/// </summary>
|
|||
internal static class Octet |
|||
{ |
|||
/// <summary>
|
|||
/// Value tuple of <see cref="uint"/>-s.
|
|||
/// </summary>
|
|||
[StructLayout(LayoutKind.Explicit, Size = 8 * sizeof(uint))] |
|||
public struct OfUInt32 |
|||
{ |
|||
[FieldOffset(0 * sizeof(uint))] |
|||
public uint V0; |
|||
|
|||
[FieldOffset(1 * sizeof(uint))] |
|||
public uint V1; |
|||
|
|||
[FieldOffset(2 * sizeof(uint))] |
|||
public uint V2; |
|||
|
|||
[FieldOffset(3 * sizeof(uint))] |
|||
public uint V3; |
|||
|
|||
[FieldOffset(4 * sizeof(uint))] |
|||
public uint V4; |
|||
|
|||
[FieldOffset(5 * sizeof(uint))] |
|||
public uint V5; |
|||
|
|||
[FieldOffset(6 * sizeof(uint))] |
|||
public uint V6; |
|||
|
|||
[FieldOffset(7 * sizeof(uint))] |
|||
public uint V7; |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"{nameof(Octet)}.{nameof(OfUInt32)}({this.V0},{this.V1},{this.V2},{this.V3},{this.V4},{this.V5},{this.V6},{this.V7})"; |
|||
} |
|||
|
|||
[MethodImpl(InliningOptions.ShortMethod)] |
|||
public void LoadFrom(ref OfByte src) |
|||
{ |
|||
this.V0 = src.V0; |
|||
this.V1 = src.V1; |
|||
this.V2 = src.V2; |
|||
this.V3 = src.V3; |
|||
this.V4 = src.V4; |
|||
this.V5 = src.V5; |
|||
this.V6 = src.V6; |
|||
this.V7 = src.V7; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Value tuple of <see cref="byte"/>-s
|
|||
/// </summary>
|
|||
[StructLayout(LayoutKind.Explicit, Size = 8)] |
|||
public struct OfByte |
|||
{ |
|||
[FieldOffset(0)] |
|||
public byte V0; |
|||
|
|||
[FieldOffset(1)] |
|||
public byte V1; |
|||
|
|||
[FieldOffset(2)] |
|||
public byte V2; |
|||
|
|||
[FieldOffset(3)] |
|||
public byte V3; |
|||
|
|||
[FieldOffset(4)] |
|||
public byte V4; |
|||
|
|||
[FieldOffset(5)] |
|||
public byte V5; |
|||
|
|||
[FieldOffset(6)] |
|||
public byte V6; |
|||
|
|||
[FieldOffset(7)] |
|||
public byte V7; |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return $"{nameof(Octet)}.{nameof(OfByte)}({this.V0},{this.V1},{this.V2},{this.V3},{this.V4},{this.V5},{this.V6},{this.V7})"; |
|||
} |
|||
|
|||
[MethodImpl(InliningOptions.ShortMethod)] |
|||
public void LoadFrom(ref OfUInt32 src) |
|||
{ |
|||
this.V0 = (byte)src.V0; |
|||
this.V1 = (byte)src.V1; |
|||
this.V2 = (byte)src.V2; |
|||
this.V3 = (byte)src.V3; |
|||
this.V4 = (byte)src.V4; |
|||
this.V5 = (byte)src.V5; |
|||
this.V6 = (byte)src.V6; |
|||
this.V7 = (byte)src.V7; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace SixLabors.ImageSharp.Tuples |
|||
{ |
|||
/// <summary>
|
|||
/// Contains 8 element value tuples of various types.
|
|||
/// </summary>
|
|||
[StructLayout(LayoutKind.Sequential)] |
|||
internal struct Octet<T> |
|||
where T : unmanaged |
|||
{ |
|||
public T V0; |
|||
public T V1; |
|||
public T V2; |
|||
public T V3; |
|||
public T V4; |
|||
public T V5; |
|||
public T V6; |
|||
public T V7; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override readonly string ToString() |
|||
{ |
|||
return $"Octet<{typeof(T)}>({this.V0},{this.V1},{this.V2},{this.V3},{this.V4},{this.V5},{this.V6},{this.V7})"; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Octet{T}"/> type.
|
|||
/// </summary>
|
|||
internal static class OctetExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Loads the fields in a target <see cref="Octet{T}"/> of <see cref="uint"/> from one of <see cref="byte"/> type.
|
|||
/// </summary>
|
|||
/// <param name="destination">The target <see cref="Octet{T}"/> of <see cref="uint"/> instance.</param>
|
|||
/// <param name="source">The source <see cref="Octet{T}"/> of <see cref="byte"/> instance.</param>
|
|||
[MethodImpl(InliningOptions.ShortMethod)] |
|||
public static void LoadFrom(ref this Octet<uint> destination, ref Octet<byte> source) |
|||
{ |
|||
destination.V0 = source.V0; |
|||
destination.V1 = source.V1; |
|||
destination.V2 = source.V2; |
|||
destination.V3 = source.V3; |
|||
destination.V4 = source.V4; |
|||
destination.V5 = source.V5; |
|||
destination.V6 = source.V6; |
|||
destination.V7 = source.V7; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loads the fields in a target <see cref="Octet{T}"/> of <see cref="byte"/> from one of <see cref="uint"/> type.
|
|||
/// </summary>
|
|||
/// <param name="destination">The target <see cref="Octet{T}"/> of <see cref="byte"/> instance.</param>
|
|||
/// <param name="source">The source <see cref="Octet{T}"/> of <see cref="uint"/> instance.</param>
|
|||
[MethodImpl(InliningOptions.ShortMethod)] |
|||
public static void LoadFrom(ref this Octet<byte> destination, ref Octet<uint> source) |
|||
{ |
|||
destination.V0 = (byte)source.V0; |
|||
destination.V1 = (byte)source.V1; |
|||
destination.V2 = (byte)source.V2; |
|||
destination.V3 = (byte)source.V3; |
|||
destination.V4 = (byte)source.V4; |
|||
destination.V5 = (byte)source.V5; |
|||
destination.V6 = (byte)source.V6; |
|||
destination.V7 = (byte)source.V7; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue