-
-
Notifications
You must be signed in to change notification settings - Fork 852
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2409 from stefannikolei/stefannikolei/arm/colorco…
…nvertergrayscale Port GrayscalConverter to Arm
- Loading branch information
Showing
5 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleArm.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// 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 static SixLabors.ImageSharp.SimdUtils; | ||
|
||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; | ||
|
||
internal abstract partial class JpegColorConverterBase | ||
{ | ||
internal sealed class GrayscaleArm : JpegColorConverterArm | ||
{ | ||
public GrayscaleArm(int precision) | ||
: base(JpegColorSpace.Grayscale, precision) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void ConvertToRgbInplace(in ComponentValues values) | ||
{ | ||
ref Vector128<float> c0Base = | ||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); | ||
|
||
// Used for the color conversion | ||
var scale = Vector128.Create(1 / this.MaximumValue); | ||
|
||
nuint n = (uint)values.Component0.Length / (uint)Vector128<float>.Count; | ||
for (nuint i = 0; i < n; i++) | ||
{ | ||
ref Vector128<float> c0 = ref Unsafe.Add(ref c0Base, i); | ||
c0 = AdvSimd.Multiply(c0, scale); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) | ||
{ | ||
ref Vector128<float> destLuminance = | ||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); | ||
|
||
ref Vector128<float> srcRed = | ||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(rLane)); | ||
ref Vector128<float> srcGreen = | ||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(gLane)); | ||
ref Vector128<float> srcBlue = | ||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(bLane)); | ||
|
||
// Used for the color conversion | ||
var f0299 = Vector128.Create(0.299f); | ||
var f0587 = Vector128.Create(0.587f); | ||
var f0114 = Vector128.Create(0.114f); | ||
|
||
nuint n = (uint)values.Component0.Length / (uint)Vector128<float>.Count; | ||
for (nuint i = 0; i < n; i++) | ||
{ | ||
ref Vector128<float> r = ref Unsafe.Add(ref srcRed, i); | ||
ref Vector128<float> g = ref Unsafe.Add(ref srcGreen, i); | ||
ref Vector128<float> b = ref Unsafe.Add(ref srcBlue, i); | ||
|
||
// luminocity = (0.299 * r) + (0.587 * g) + (0.114 * b) | ||
Unsafe.Add(ref destLuminance, i) = HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(f0114, b), f0587, g), f0299, r); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters