Browse Source

Added docs to the color sonverters

pull/2120/head
Dmitry Pentin 4 years ago
parent
commit
dd0327ac50
  1. 9
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs
  2. 8
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykScalar.cs
  3. 14
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs
  4. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs
  5. 8
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs
  6. 14
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs
  7. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs
  8. 18
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbScalar.cs
  9. 16
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs
  10. 4
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs
  11. 12
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrScalar.cs
  12. 16
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs
  13. 6
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs
  14. 10
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKScalar.cs
  15. 16
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs
  16. 1
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterAvx.cs
  17. 9
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs
  18. 1
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterScalar.cs
  19. 48
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterVector.cs
  20. 2
      src/ImageSharp/Formats/Jpeg/Components/Encoder/SpectralConverter{TPixel}.cs

9
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykAvx.cs

@ -19,6 +19,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override void ConvertToRgbInplace(in ComponentValues values)
{
ref Vector256<float> c0Base =
@ -48,10 +49,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
=> ConvertFromRgbInplace(in values, this.MaximumValue, rLane, gLane, bLane);
/// <inheritdoc/>
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
=> ConvertFromRgb(in values, this.MaximumValue, rLane, gLane, bLane);
public static void ConvertFromRgbInplace(in ComponentValues values, float maxValue, Span<float> rLane, Span<float> gLane, Span<float> bLane)
public static void ConvertFromRgb(in ComponentValues values, float maxValue, Span<float> rLane, Span<float> gLane, Span<float> bLane)
{
ref Vector256<float> destC =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component0));
@ -69,7 +71,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
ref Vector256<float> srcB =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(bLane));
// Used for the color conversion
var scale = Vector256.Create(maxValue);
nint n = values.Component0.Length / Vector256<float>.Count;

8
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykScalar.cs

@ -14,11 +14,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override void ConvertToRgbInplace(in ComponentValues values) =>
ConvertToRgbInplace(values, this.MaximumValue);
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertFromRgbInplace(values, this.MaximumValue, r, g, b);
/// <inheritdoc/>
public override void ConvertFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertFromRgb(values, this.MaximumValue, r, g, b);
public static void ConvertToRgbInplace(in ComponentValues values, float maxValue)
{
@ -42,7 +44,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
public static void ConvertFromRgbInplace(in ComponentValues values, float maxValue, Span<float> r, Span<float> g, Span<float> b)
public static void ConvertFromRgb(in ComponentValues values, float maxValue, Span<float> r, Span<float> g, Span<float> b)
{
Span<float> c = values.Component0;
Span<float> m = values.Component1;

14
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector.cs

@ -17,7 +17,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
protected override void ConvertCoreVectorizedInplaceToRgb(in ComponentValues values)
/// <inheritdoc/>
protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
{
ref Vector<float> cBase =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0));
@ -45,13 +46,16 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
protected override void ConvertCoreInplaceToRgb(in ComponentValues values)
/// <inheritdoc/>
protected override void ConvertToRgbInplaceScalarRemainder(in ComponentValues values)
=> CmykScalar.ConvertToRgbInplace(values, this.MaximumValue);
protected override void ConvertCoreVectorizedInplaceFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
/// <inheritdoc/>
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertFromRgbInplaceVectorized(in values, this.MaximumValue, r, g, b);
protected override void ConvertCoreInplaceFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
/// <inheritdoc/>
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertFromRgbInplaceRemainder(values, this.MaximumValue, r, g, b);
public static void ConvertFromRgbInplaceVectorized(in ComponentValues values, float maxValue, Span<float> r, Span<float> g, Span<float> b)
@ -96,7 +100,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
public static void ConvertFromRgbInplaceRemainder(in ComponentValues values, float maxValue, Span<float> r, Span<float> g, Span<float> b)
=> CmykScalar.ConvertFromRgbInplace(values, maxValue, r, g, b);
=> CmykScalar.ConvertFromRgb(values, maxValue, r, g, b);
}
}
}

4
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleAvx.cs

@ -20,6 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override void ConvertToRgbInplace(in ComponentValues values)
{
ref Vector256<float> c0Base =
@ -36,7 +37,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
/// <inheritdoc/>
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
{
ref Vector256<float> destLuminance =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component0));

8
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs

@ -16,13 +16,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override void ConvertToRgbInplace(in ComponentValues values)
=> ConvertCoreInplaceToRgb(values.Component0, this.MaximumValue);
=> ConvertToRgbInplace(values.Component0, this.MaximumValue);
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
/// <inheritdoc/>
public override void ConvertFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertCoreInplaceFromRgb(values, r, g, b);
internal static void ConvertCoreInplaceToRgb(Span<float> values, float maxValue)
internal static void ConvertToRgbInplace(Span<float> values, float maxValue)
{
ref float valuesRef = ref MemoryMarshal.GetReference(values);
float scale = 1 / maxValue;

14
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector.cs

@ -17,7 +17,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
protected override void ConvertCoreVectorizedInplaceToRgb(in ComponentValues values)
/// <inheritdoc/>
protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
{
ref Vector<float> cBase =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0));
@ -32,10 +33,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
protected override void ConvertCoreInplaceToRgb(in ComponentValues values)
=> GrayscaleScalar.ConvertCoreInplaceToRgb(values.Component0, this.MaximumValue);
/// <inheritdoc/>
protected override void ConvertToRgbInplaceScalarRemainder(in ComponentValues values)
=> GrayscaleScalar.ConvertToRgbInplace(values.Component0, this.MaximumValue);
protected override void ConvertCoreVectorizedInplaceFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
/// <inheritdoc/>
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
{
ref Vector<float> destLuma =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0));
@ -63,7 +66,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
protected override void ConvertCoreInplaceFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
/// <inheritdoc/>
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> GrayscaleScalar.ConvertCoreInplaceFromRgb(values, r, g, b);
}
}

4
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbAvx.cs

@ -19,6 +19,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override void ConvertToRgbInplace(in ComponentValues values)
{
ref Vector256<float> rBase =
@ -42,7 +43,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
/// <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);

18
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbScalar.cs

@ -14,20 +14,22 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override void ConvertToRgbInplace(in ComponentValues values)
=> ConvertCoreInplaceToRgb(values, this.MaximumValue);
=> ConvertToRgbInplace(values, this.MaximumValue);
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertCoreInplaceFromRgb(values, r, g, b);
/// <inheritdoc/>
public override void ConvertFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertFromRgb(values, r, g, b);
internal static void ConvertCoreInplaceToRgb(ComponentValues values, float maxValue)
internal static void ConvertToRgbInplace(ComponentValues values, float maxValue)
{
GrayscaleScalar.ConvertCoreInplaceToRgb(values.Component0, maxValue);
GrayscaleScalar.ConvertCoreInplaceToRgb(values.Component1, maxValue);
GrayscaleScalar.ConvertCoreInplaceToRgb(values.Component2, maxValue);
GrayscaleScalar.ConvertToRgbInplace(values.Component0, maxValue);
GrayscaleScalar.ConvertToRgbInplace(values.Component1, maxValue);
GrayscaleScalar.ConvertToRgbInplace(values.Component2, maxValue);
}
internal static void ConvertCoreInplaceFromRgb(ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
internal static void ConvertFromRgb(ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
{
r.CopyTo(values.Component0);
g.CopyTo(values.Component1);

16
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbVector.cs

@ -17,7 +17,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
protected override void ConvertCoreVectorizedInplaceToRgb(in ComponentValues values)
/// <inheritdoc/>
protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
{
ref Vector<float> rBase =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0));
@ -40,18 +41,21 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
protected override void ConvertCoreInplaceToRgb(in ComponentValues values)
=> RgbScalar.ConvertCoreInplaceToRgb(values, this.MaximumValue);
/// <inheritdoc/>
protected override void ConvertToRgbInplaceScalarRemainder(in ComponentValues values)
=> RgbScalar.ConvertToRgbInplace(values, this.MaximumValue);
protected override void ConvertCoreVectorizedInplaceFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
/// <inheritdoc/>
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
{
r.CopyTo(values.Component0);
g.CopyTo(values.Component1);
b.CopyTo(values.Component2);
}
protected override void ConvertCoreInplaceFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> RgbScalar.ConvertCoreInplaceFromRgb(values, r, g, b);
/// <inheritdoc/>
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> RgbScalar.ConvertFromRgb(values, r, g, b);
}
}
}

4
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrAvx.cs

@ -21,6 +21,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override void ConvertToRgbInplace(in ComponentValues values)
{
ref Vector256<float> c0Base =
@ -70,7 +71,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
/// <inheritdoc/>
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
{
ref Vector256<float> destY =
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component0));

12
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrScalar.cs

@ -20,13 +20,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override void ConvertToRgbInplace(in ComponentValues values)
=> ConvertCoreInplaceToRgb(values, this.MaximumValue, this.HalfValue);
=> ConvertToRgbInplace(values, this.MaximumValue, this.HalfValue);
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertCoreInplaceFromRgb(values, this.HalfValue, r, g, b);
/// <inheritdoc/>
public override void ConvertFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertFromRgb(values, this.HalfValue, r, g, b);
public static void ConvertCoreInplaceToRgb(in ComponentValues values, float maxValue, float halfValue)
public static void ConvertToRgbInplace(in ComponentValues values, float maxValue, float halfValue)
{
Span<float> c0 = values.Component0;
Span<float> c1 = values.Component1;
@ -49,7 +51,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
public static void ConvertCoreInplaceFromRgb(in ComponentValues values, float halfValue, Span<float> rLane, Span<float> gLane, Span<float> bLane)
public static void ConvertFromRgb(in ComponentValues values, float halfValue, Span<float> rLane, Span<float> gLane, Span<float> bLane)
{
Span<float> y = values.Component0;
Span<float> cb = values.Component1;

16
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector.cs

@ -18,7 +18,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
protected override void ConvertCoreVectorizedInplaceToRgb(in ComponentValues values)
/// <inheritdoc/>
protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
{
ref Vector<float> c0Base =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0));
@ -68,10 +69,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
protected override void ConvertCoreInplaceToRgb(in ComponentValues values)
=> YCbCrScalar.ConvertCoreInplaceToRgb(values, this.MaximumValue, this.HalfValue);
/// <inheritdoc/>
protected override void ConvertToRgbInplaceScalarRemainder(in ComponentValues values)
=> YCbCrScalar.ConvertToRgbInplace(values, this.MaximumValue, this.HalfValue);
protected override void ConvertCoreVectorizedInplaceFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
/// <inheritdoc/>
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
{
ref Vector<float> destY =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0));
@ -117,8 +120,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
protected override void ConvertCoreInplaceFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> YCbCrScalar.ConvertCoreInplaceFromRgb(values, this.HalfValue, r, g, b);
/// <inheritdoc/>
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> YCbCrScalar.ConvertFromRgb(values, this.HalfValue, r, g, b);
}
}
}

6
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKAvx.cs

@ -20,6 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override void ConvertToRgbInplace(in ComponentValues values)
{
ref Vector256<float> c0Base =
@ -78,10 +79,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
/// <inheritdoc/>
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
{
// rgb -> cmyk
CmykAvx.ConvertFromRgbInplace(in values, this.MaximumValue, rLane, gLane, bLane);
CmykAvx.ConvertFromRgb(in values, this.MaximumValue, rLane, gLane, bLane);
// cmyk -> ycck
ref Vector256<float> destY =

10
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKScalar.cs

@ -20,11 +20,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override void ConvertToRgbInplace(in ComponentValues values)
=> ConvertToRgpInplace(values, this.MaximumValue, this.HalfValue);
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertCoreInplaceFromRgb(values, this.HalfValue, this.MaximumValue, r, g, b);
/// <inheritdoc/>
public override void ConvertFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
=> ConvertFromRgb(values, this.HalfValue, this.MaximumValue, r, g, b);
public static void ConvertToRgpInplace(in ComponentValues values, float maxValue, float halfValue)
{
@ -51,10 +53,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
public static void ConvertCoreInplaceFromRgb(in ComponentValues values, float halfValue, float maxValue, Span<float> rLane, Span<float> gLane, Span<float> bLane)
public static void ConvertFromRgb(in ComponentValues values, float halfValue, float maxValue, Span<float> rLane, Span<float> gLane, Span<float> bLane)
{
// rgb -> cmyk
CmykScalar.ConvertFromRgbInplace(in values, maxValue, rLane, gLane, bLane);
CmykScalar.ConvertFromRgb(in values, maxValue, rLane, gLane, bLane);
// cmyk -> ycck
Span<float> c = values.Component0;

16
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs

@ -17,7 +17,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
protected override void ConvertCoreVectorizedInplaceToRgb(in ComponentValues values)
/// <inheritdoc/>
protected override void ConvertToRgbInplaceVectorized(in ComponentValues values)
{
ref Vector<float> c0Base =
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0));
@ -69,10 +70,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
protected override void ConvertCoreInplaceToRgb(in ComponentValues values) =>
/// <inheritdoc/>
protected override void ConvertToRgbInplaceScalarRemainder(in ComponentValues values) =>
YccKScalar.ConvertToRgpInplace(values, this.MaximumValue, this.HalfValue);
protected override void ConvertCoreVectorizedInplaceFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
/// <inheritdoc/>
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
{
// rgb -> cmyk
CmykVector.ConvertFromRgbInplaceVectorized(in values, this.MaximumValue, rLane, gLane, bLane);
@ -121,13 +124,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
protected override void ConvertCoreInplaceFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
/// <inheritdoc/>
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
{
// rgb -> cmyk
CmykScalar.ConvertFromRgbInplace(in values, this.MaximumValue, r, g, b);
CmykScalar.ConvertFromRgb(in values, this.MaximumValue, r, g, b);
// cmyk -> ycck
YccKScalar.ConvertCoreInplaceFromRgb(in values, this.HalfValue, this.MaximumValue, r, g, b);
YccKScalar.ConvertFromRgb(in values, this.HalfValue, this.MaximumValue, r, g, b);
}
}
}

1
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterAvx.cs

@ -25,6 +25,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override bool IsAvailable => Avx.IsSupported;
}
}

9
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs

@ -79,7 +79,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <param name="values">The input/ouptut as a stack-only <see cref="ComponentValues"/> struct</param>
public abstract void ConvertToRgbInplace(in ComponentValues values);
public abstract void ConvertFromRgbInplace(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b);
/// <summary>
/// Converts RGB lanes to jpeg component values.
/// </summary>
/// <param name="values">Jpeg component values.</param>
/// <param name="rLane">Red colors lane.</param>
/// <param name="gLane">Green colors lane.</param>
/// <param name="bLane">Blue colors lane.</param>
public abstract void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane);
/// <summary>
/// Returns the <see cref="JpegColorConverterBase"/>s for all supported colorspaces and precisions.

1
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterScalar.cs

@ -16,6 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public override bool IsAvailable => true;
}
}

48
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterVector.cs

@ -26,9 +26,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
}
/// <inheritdoc/>
public sealed override bool IsAvailable => Vector.IsHardwareAccelerated && Vector<float>.Count % 4 == 0;
public override void ConvertToRgbInplace(in ComponentValues values)
/// <inheritdoc/>
public sealed override void ConvertToRgbInplace(in ComponentValues values)
{
DebugGuard.IsTrue(this.IsAvailable, $"{this.GetType().Name} converter is not supported on current hardware.");
@ -38,7 +40,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
int simdCount = length - remainder;
if (simdCount > 0)
{
this.ConvertCoreVectorizedInplaceToRgb(values.Slice(0, simdCount));
this.ConvertToRgbInplaceVectorized(values.Slice(0, simdCount));
}
// Jpeg images width is always divisible by 8 without a remainder
@ -48,11 +50,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
// remainder pixels
if (remainder > 0)
{
this.ConvertCoreInplaceToRgb(values.Slice(simdCount, remainder));
this.ConvertToRgbInplaceScalarRemainder(values.Slice(simdCount, remainder));
}
}
public override void ConvertFromRgbInplace(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
/// <inheritdoc/>
public sealed override void ConvertFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
{
DebugGuard.IsTrue(this.IsAvailable, $"{this.GetType().Name} converter is not supported on current hardware.");
@ -62,7 +65,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
int simdCount = length - remainder;
if (simdCount > 0)
{
this.ConvertCoreVectorizedInplaceFromRgb(
this.ConvertFromRgbVectorized(
values.Slice(0, simdCount),
r.Slice(0, simdCount),
g.Slice(0, simdCount),
@ -76,7 +79,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
// remainder pixels
if (remainder > 0)
{
this.ConvertCoreInplaceFromRgb(
this.ConvertFromRgbScalarRemainder(
values.Slice(simdCount, remainder),
r.Slice(simdCount, remainder),
g.Slice(simdCount, remainder),
@ -84,13 +87,38 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
}
}
protected abstract void ConvertCoreVectorizedInplaceToRgb(in ComponentValues values);
/// <summary>
/// Converts planar jpeg component values in <paramref name="values"/>
/// to RGB color space inplace using <see cref="Vector"/> API.
/// </summary>
/// <param name="values">The input/ouptut as a stack-only <see cref="ComponentValues"/> struct</param>
protected abstract void ConvertToRgbInplaceVectorized(in ComponentValues values);
protected abstract void ConvertCoreInplaceToRgb(in ComponentValues values);
/// <summary>
/// Converts remainder of the planar jpeg component values after
/// conversion in <see cref="ConvertToRgbInplaceVectorized(in ComponentValues)"/>.
/// </summary>
/// <param name="values">The input/ouptut as a stack-only <see cref="ComponentValues"/> struct</param>
protected abstract void ConvertToRgbInplaceScalarRemainder(in ComponentValues values);
protected abstract void ConvertCoreVectorizedInplaceFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b);
/// <summary>
/// Converts RGB lanes to jpeg component values using <see cref="Vector"/> API.
/// </summary>
/// <param name="values">Jpeg component values.</param>
/// <param name="rLane">Red colors lane.</param>
/// <param name="gLane">Green colors lane.</param>
/// <param name="bLane">Blue colors lane.</param>
protected abstract void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane);
protected abstract void ConvertCoreInplaceFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b);
/// <summary>
/// Converts remainder of RGB lanes to jpeg component values after
/// conversion in <see cref="ConvertFromRgbVectorized(in ComponentValues, Span{float}, Span{float}, Span{float})"/>.
/// </summary>
/// <param name="values">Jpeg component values.</param>
/// <param name="rLane">Red colors lane.</param>
/// <param name="gLane">Green colors lane.</param>
/// <param name="bLane">Blue colors lane.</param>
protected abstract void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane);
}
}
}

2
src/ImageSharp/Formats/Jpeg/Components/Encoder/SpectralConverter{TPixel}.cs

@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
// Convert from rgb24 to target pixel type
var values = new JpegColorConverterBase.ComponentValues(this.componentProcessors, y);
this.colorConverter.ConvertFromRgbInplace(values, rLane, gLane, bLane);
this.colorConverter.ConvertFromRgb(values, rLane, gLane, bLane);
}
// Convert pixels to spectral

Loading…
Cancel
Save