mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
6 changed files with 148 additions and 5 deletions
@ -0,0 +1,53 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
using System.Runtime.Intrinsics; |
|||
using System.Runtime.Intrinsics.Arm; |
|||
using System.Runtime.Intrinsics.X86; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class RgbArm : JpegColorConverterArm |
|||
{ |
|||
public RgbArm(int precision) |
|||
: base(JpegColorSpace.RGB, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void ConvertToRgbInplace(in ComponentValues values) |
|||
{ |
|||
ref Vector128<float> rBase = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector128<float> gBase = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector128<float> bBase = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
// Used for the color conversion
|
|||
var scale = Vector128.Create(1 / this.MaximumValue); |
|||
nint n = (nint)(uint)values.Component0.Length / Vector128<float>.Count; |
|||
for (nint i = 0; i < n; i++) |
|||
{ |
|||
ref Vector128<float> r = ref Unsafe.Add(ref rBase, i); |
|||
ref Vector128<float> g = ref Unsafe.Add(ref gBase, i); |
|||
ref Vector128<float> b = ref Unsafe.Add(ref bBase, i); |
|||
r = AdvSimd.Multiply(r, scale); |
|||
g = AdvSimd.Multiply(g, scale); |
|||
b = AdvSimd.Multiply(b, scale); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
rLane.CopyTo(values.Component0); |
|||
gLane.CopyTo(values.Component1); |
|||
bLane.CopyTo(values.Component2); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
using System.Runtime.Intrinsics; |
|||
using System.Runtime.Intrinsics.Arm; |
|||
using System.Runtime.Intrinsics.X86; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
/// <summary>
|
|||
/// <see cref="JpegColorConverterBase"/> abstract base for implementations
|
|||
/// based on <see cref="Avx"/> instructions.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Converters of this family would expect input buffers lengths to be
|
|||
/// divisible by 8 without a remainder.
|
|||
/// This is guaranteed by real-life data as jpeg stores pixels via 8x8 blocks.
|
|||
/// DO NOT pass test data of invalid size to these converters as they
|
|||
/// potentially won't do a bound check and return a false positive result.
|
|||
/// </remarks>
|
|||
internal abstract class JpegColorConverterArm : JpegColorConverterBase |
|||
{ |
|||
protected JpegColorConverterArm(JpegColorSpace colorSpace, int precision) |
|||
: base(colorSpace, precision) |
|||
{ |
|||
} |
|||
|
|||
public static bool IsSupported => AdvSimd.IsSupported; |
|||
|
|||
public sealed override bool IsAvailable => IsSupported; |
|||
|
|||
public sealed override int ElementsPerBatch => Vector128<float>.Count; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue