-
-
Notifications
You must be signed in to change notification settings - Fork 855
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 #1864 from br3aker/dp/jpeg-decoder-color-converters
Automatic SSE color converters based on Vector API
- Loading branch information
Showing
42 changed files
with
822 additions
and
1,074 deletions.
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
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
...mats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.Avx2JpegColorConverter.cs
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
...ats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.BasicJpegColorConverter.cs
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
...geSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmykAvx.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,52 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
#if SUPPORTS_RUNTIME_INTRINSICS | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Intrinsics; | ||
using System.Runtime.Intrinsics.X86; | ||
|
||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters | ||
{ | ||
internal abstract partial class JpegColorConverterBase | ||
{ | ||
internal sealed class FromCmykAvx : JpegColorConverterAvx | ||
{ | ||
public FromCmykAvx(int precision) | ||
: base(JpegColorSpace.Cmyk, precision) | ||
{ | ||
} | ||
|
||
public override void ConvertToRgbInplace(in ComponentValues values) | ||
{ | ||
ref Vector256<float> c0Base = | ||
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component0)); | ||
ref Vector256<float> c1Base = | ||
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component1)); | ||
ref Vector256<float> c2Base = | ||
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component2)); | ||
ref Vector256<float> c3Base = | ||
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component3)); | ||
|
||
// Used for the color conversion | ||
var scale = Vector256.Create(1 / (this.MaximumValue * this.MaximumValue)); | ||
|
||
nint n = values.Component0.Length / Vector256<float>.Count; | ||
for (nint i = 0; i < n; i++) | ||
{ | ||
ref Vector256<float> c = ref Unsafe.Add(ref c0Base, i); | ||
ref Vector256<float> m = ref Unsafe.Add(ref c1Base, i); | ||
ref Vector256<float> y = ref Unsafe.Add(ref c2Base, i); | ||
Vector256<float> k = Unsafe.Add(ref c3Base, i); | ||
|
||
k = Avx.Multiply(k, scale); | ||
c = Avx.Multiply(c, k); | ||
m = Avx.Multiply(m, k); | ||
y = Avx.Multiply(y, k); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
#endif |
60 changes: 0 additions & 60 deletions
60
...eSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmykAvx2.cs
This file was deleted.
Oops, something went wrong.
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
51 changes: 51 additions & 0 deletions
51
...harp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.FromCmykVector.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,51 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System.Numerics; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters | ||
{ | ||
internal abstract partial class JpegColorConverterBase | ||
{ | ||
internal sealed class FromCmykVector : JpegColorConverterVector | ||
{ | ||
public FromCmykVector(int precision) | ||
: base(JpegColorSpace.Cmyk, precision) | ||
{ | ||
} | ||
|
||
protected override void ConvertCoreVectorizedInplace(in ComponentValues values) | ||
{ | ||
ref Vector<float> cBase = | ||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0)); | ||
ref Vector<float> mBase = | ||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component1)); | ||
ref Vector<float> yBase = | ||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2)); | ||
ref Vector<float> kBase = | ||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component3)); | ||
|
||
var scale = new Vector<float>(1 / (this.MaximumValue * this.MaximumValue)); | ||
|
||
nint n = values.Component0.Length / Vector<float>.Count; | ||
for (nint i = 0; i < n; i++) | ||
{ | ||
ref Vector<float> c = ref Unsafe.Add(ref cBase, i); | ||
ref Vector<float> m = ref Unsafe.Add(ref mBase, i); | ||
ref Vector<float> y = ref Unsafe.Add(ref yBase, i); | ||
Vector<float> k = Unsafe.Add(ref kBase, i); | ||
|
||
k *= scale; | ||
c *= k; | ||
m *= k; | ||
y *= k; | ||
} | ||
} | ||
|
||
protected override void ConvertCoreInplace(in ComponentValues values) => | ||
FromCmykScalar.ConvertCoreInplace(values, this.MaximumValue); | ||
} | ||
} | ||
} |
Oops, something went wrong.