// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System; using System.Numerics; using System.Runtime.CompilerServices; namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils { /// /// Span Extensions /// internal static class SpanExtensions { /// /// Save to a Vector4 /// /// The data /// The vector to save to [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SaveTo(this Span data, ref Vector4 v) { v.X = data[0]; v.Y = data[1]; v.Z = data[2]; v.W = data[3]; } /// /// Save to a Vector4 /// /// The data /// The vector to save to [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SaveTo(this Span data, ref Vector4 v) { v.X = data[0]; v.Y = data[1]; v.Z = data[2]; v.W = data[3]; } /// /// Load from Vector4 /// /// The data /// The vector to load from [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LoadFrom(this Span data, ref Vector4 v) { data[0] = v.X; data[1] = v.Y; data[2] = v.Z; data[3] = v.W; } /// /// Load from Vector4 /// /// The data /// The vector to load from [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void LoadFrom(this Span data, ref Vector4 v) { data[0] = (int)v.X; data[1] = (int)v.Y; data[2] = (int)v.Z; data[3] = (int)v.W; } /// /// Converts all int values of src to float /// /// Source /// A new with float values public static float[] ConvertAllToFloat(this int[] src) { float[] result = new float[src.Length]; for (int i = 0; i < src.Length; i++) { result[i] = (float)src[i]; } return result; } /// /// Add a scalar to all values of src /// /// The source /// The scalar value to add /// A new instance of public static Span AddScalarToAllValues(this Span src, float scalar) { float[] result = new float[src.Length]; for (int i = 0; i < src.Length; i++) { result[i] = src[i] + scalar; } return result; } /// /// Add a scalar to all values of src /// /// The source /// The scalar value to add /// A new instance of public static Span AddScalarToAllValues(this Span src, int scalar) { int[] result = new int[src.Length]; for (int i = 0; i < src.Length; i++) { result[i] = src[i] + scalar; } return result; } } }