Browse Source

Merge branch 'master' into js/fix-481

af/merge-core
James Jackson-South 8 years ago
committed by GitHub
parent
commit
1949122df4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/ImageSharp/Advanced/AdvancedImageExtensions.cs
  2. 2
      src/ImageSharp/ColorSpaces/CieLab.cs
  3. 2
      src/ImageSharp/ColorSpaces/CieLch.cs
  4. 2
      src/ImageSharp/ColorSpaces/CieLchuv.cs
  5. 2
      src/ImageSharp/ColorSpaces/CieLuv.cs
  6. 2
      src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs
  7. 2
      src/ImageSharp/ColorSpaces/CieXyy.cs
  8. 2
      src/ImageSharp/ColorSpaces/CieXyz.cs
  9. 2
      src/ImageSharp/ColorSpaces/Cmyk.cs
  10. 2
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs
  11. 2
      src/ImageSharp/ColorSpaces/Hsl.cs
  12. 2
      src/ImageSharp/ColorSpaces/Hsv.cs
  13. 2
      src/ImageSharp/ColorSpaces/HunterLab.cs
  14. 2
      src/ImageSharp/ColorSpaces/LinearRgb.cs
  15. 2
      src/ImageSharp/ColorSpaces/Lms.cs
  16. 2
      src/ImageSharp/ColorSpaces/Rgb.cs
  17. 2
      src/ImageSharp/ColorSpaces/YCbCr.cs
  18. 8
      src/ImageSharp/Common/Extensions/SimdUtils.cs
  19. 2
      src/ImageSharp/Formats/Gif/PackedField.cs
  20. 5
      src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs
  21. 4
      src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs
  22. 2
      src/ImageSharp/Formats/Jpeg/Common/Decoder/AdobeMarker.cs
  23. 9
      src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs
  24. 9
      src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs
  25. 4
      src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs
  26. 2
      src/ImageSharp/Formats/Jpeg/Common/Decoder/JFifMarker.cs
  27. 2
      src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.cs
  28. 2
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs
  29. 2
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs
  30. 2
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs
  31. 2
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsYCbCrToRgbTables.cs
  32. 11
      src/ImageSharp/Formats/Png/Filters/AverageFilter.cs
  33. 11
      src/ImageSharp/Formats/Png/Filters/PaethFilter.cs
  34. 7
      src/ImageSharp/Formats/Png/Filters/SubFilter.cs
  35. 11
      src/ImageSharp/Formats/Png/Filters/UpFilter.cs
  36. 4
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  37. 6
      src/ImageSharp/ImageSharp.csproj
  38. 2
      src/ImageSharp/Memory/BufferArea{T}.cs
  39. 3
      src/ImageSharp/Memory/BufferExtensions.cs
  40. 7
      src/ImageSharp/Memory/SpanHelper.cs
  41. 2
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs
  42. 2
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs
  43. 2
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs
  44. 2
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs
  45. 2
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs
  46. 2
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs
  47. 2
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs
  48. 2
      src/ImageSharp/Numerics/ValueSize.cs
  49. 35
      src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs
  50. 12
      src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.tt
  51. 28
      src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs
  52. 12
      src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt
  53. 9
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
  54. 4
      src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
  55. 2
      src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs
  56. 6
      src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs
  57. 6
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs
  58. 8
      tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
  59. 3
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  60. 2
      tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs
  61. 4
      tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
  62. 7
      tests/ImageSharp.Tests/Memory/BufferTestSuite.cs
  63. 20
      tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs

3
src/ImageSharp/Advanced/AdvancedImageExtensions.cs

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
@ -148,6 +149,6 @@ namespace SixLabors.ImageSharp.Advanced
/// <returns>A reference to the element.</returns>
private static ref TPixel DangerousGetPinnableReferenceToPixelBuffer<TPixel>(IPixelSource<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> ref source.PixelBuffer.Span.DangerousGetPinnableReference();
=> ref MemoryMarshal.GetReference(source.PixelBuffer.Span);
}
}

2
src/ImageSharp/ColorSpaces/CieLab.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents a CIE L*a*b* 1976 color.
/// <see href="https://en.wikipedia.org/wiki/Lab_color_space"/>
/// </summary>
internal struct CieLab : IColorVector, IEquatable<CieLab>, IAlmostEquatable<CieLab, float>
internal readonly struct CieLab : IColorVector, IEquatable<CieLab>, IAlmostEquatable<CieLab, float>
{
/// <summary>
/// D50 standard illuminant.

2
src/ImageSharp/ColorSpaces/CieLch.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents the CIE L*C*h°, cylindrical form of the CIE L*a*b* 1976 color.
/// <see href="https://en.wikipedia.org/wiki/Lab_color_space#Cylindrical_representation:_CIELCh_or_CIEHLC"/>
/// </summary>
internal struct CieLch : IColorVector, IEquatable<CieLch>, IAlmostEquatable<CieLch, float>
internal readonly struct CieLch : IColorVector, IEquatable<CieLch>, IAlmostEquatable<CieLch, float>
{
/// <summary>
/// D50 standard illuminant.

2
src/ImageSharp/ColorSpaces/CieLchuv.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents the CIE L*C*h°, cylindrical form of the CIE L*u*v* 1976 color.
/// <see href="https://en.wikipedia.org/wiki/Lab_color_space#Cylindrical_representation:_CieLchuv_or_CIEHLC"/>
/// </summary>
internal struct CieLchuv : IColorVector, IEquatable<CieLchuv>, IAlmostEquatable<CieLchuv, float>
internal readonly struct CieLchuv : IColorVector, IEquatable<CieLchuv>, IAlmostEquatable<CieLchuv, float>
{
/// <summary>
/// D50 standard illuminant.

2
src/ImageSharp/ColorSpaces/CieLuv.cs

@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// attempted perceptual uniformity
/// <see href="https://en.wikipedia.org/wiki/CIELUV"/>
/// </summary>
internal struct CieLuv : IColorVector, IEquatable<CieLuv>, IAlmostEquatable<CieLuv, float>
internal readonly struct CieLuv : IColorVector, IEquatable<CieLuv>, IAlmostEquatable<CieLuv, float>
{
/// <summary>
/// D65 standard illuminant.

2
src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Represents the coordinates of CIEXY chromaticity space
/// </summary>
internal struct CieXyChromaticityCoordinates : IEquatable<CieXyChromaticityCoordinates>, IAlmostEquatable<CieXyChromaticityCoordinates, float>
internal readonly struct CieXyChromaticityCoordinates : IEquatable<CieXyChromaticityCoordinates>, IAlmostEquatable<CieXyChromaticityCoordinates, float>
{
/// <summary>
/// Represents a <see cref="CieXyChromaticityCoordinates"/> that has X, Y values set to zero.

2
src/ImageSharp/ColorSpaces/CieXyy.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents an CIE xyY 1931 color
/// <see href="https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space"/>
/// </summary>
internal struct CieXyy : IColorVector, IEquatable<CieXyy>, IAlmostEquatable<CieXyy, float>
internal readonly struct CieXyy : IColorVector, IEquatable<CieXyy>, IAlmostEquatable<CieXyy, float>
{
/// <summary>
/// Represents a <see cref="CieXyy"/> that has X, Y, and Y values set to zero.

2
src/ImageSharp/ColorSpaces/CieXyz.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents an CIE XYZ 1931 color
/// <see href="https://en.wikipedia.org/wiki/CIE_1931_color_space#Definition_of_the_CIE_XYZ_color_space"/>
/// </summary>
internal struct CieXyz : IColorVector, IEquatable<CieXyz>, IAlmostEquatable<CieXyz, float>
internal readonly struct CieXyz : IColorVector, IEquatable<CieXyz>, IAlmostEquatable<CieXyz, float>
{
/// <summary>
/// Represents a <see cref="CieXyz"/> that has X, Y, and Z values set to zero.

2
src/ImageSharp/ColorSpaces/Cmyk.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Represents an CMYK (cyan, magenta, yellow, keyline) color.
/// </summary>
internal struct Cmyk : IEquatable<Cmyk>, IAlmostEquatable<Cmyk, float>
internal readonly struct Cmyk : IEquatable<Cmyk>, IAlmostEquatable<Cmyk, float>
{
/// <summary>
/// Represents a <see cref="Cmyk"/> that has C, M, Y, and K values set to zero.

2
src/ImageSharp/ColorSpaces/Conversion/Implementation/Rgb/RgbWorkingSpace.cs

@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSap
/// <summary>
/// Trivial implementation of <see cref="IRgbWorkingSpace"/>
/// </summary>
internal struct RgbWorkingSpace : IRgbWorkingSpace
internal readonly struct RgbWorkingSpace : IRgbWorkingSpace
{
/// <summary>
/// Initializes a new instance of the <see cref="RgbWorkingSpace"/> struct.

2
src/ImageSharp/ColorSpaces/Hsl.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Represents a Hsl (hue, saturation, lightness) color.
/// </summary>
internal struct Hsl : IColorVector, IEquatable<Hsl>, IAlmostEquatable<Hsl, float>
internal readonly struct Hsl : IColorVector, IEquatable<Hsl>, IAlmostEquatable<Hsl, float>
{
/// <summary>
/// Represents a <see cref="Hsl"/> that has H, S, and L values set to zero.

2
src/ImageSharp/ColorSpaces/Hsv.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Represents a HSV (hue, saturation, value) color. Also known as HSB (hue, saturation, brightness).
/// </summary>
internal struct Hsv : IColorVector, IEquatable<Hsv>, IAlmostEquatable<Hsv, float>
internal readonly struct Hsv : IColorVector, IEquatable<Hsv>, IAlmostEquatable<Hsv, float>
{
/// <summary>
/// Represents a <see cref="Hsv"/> that has H, S, and V values set to zero.

2
src/ImageSharp/ColorSpaces/HunterLab.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Represents an Hunter LAB color.
/// <see href="https://en.wikipedia.org/wiki/Lab_color_space"/>
/// </summary>
internal struct HunterLab : IColorVector, IEquatable<HunterLab>, IAlmostEquatable<HunterLab, float>
internal readonly struct HunterLab : IColorVector, IEquatable<HunterLab>, IAlmostEquatable<HunterLab, float>
{
/// <summary>
/// D50 standard illuminant.

2
src/ImageSharp/ColorSpaces/LinearRgb.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Represents an linear Rgb color with specified <see cref="IRgbWorkingSpace"/> working space
/// </summary>
internal struct LinearRgb : IColorVector, IEquatable<LinearRgb>, IAlmostEquatable<LinearRgb, float>
internal readonly struct LinearRgb : IColorVector, IEquatable<LinearRgb>, IAlmostEquatable<LinearRgb, float>
{
/// <summary>
/// Represents a <see cref="LinearRgb"/> that has R, G, and B values set to zero.

2
src/ImageSharp/ColorSpaces/Lms.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// named after their responsivity (sensitivity) at long, medium and short wavelengths.
/// <see href="https://en.wikipedia.org/wiki/LMS_color_space"/>
/// </summary>
internal struct Lms : IColorVector, IEquatable<Lms>, IAlmostEquatable<Lms, float>
internal readonly struct Lms : IColorVector, IEquatable<Lms>, IAlmostEquatable<Lms, float>
{
/// <summary>
/// Represents a <see cref="Lms"/> that has L, M, and S values set to zero.

2
src/ImageSharp/ColorSpaces/Rgb.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Represents an RGB color with specified <see cref="IRgbWorkingSpace"/> working space
/// </summary>
internal struct Rgb : IColorVector, IEquatable<Rgb>, IAlmostEquatable<Rgb, float>
internal readonly struct Rgb : IColorVector, IEquatable<Rgb>, IAlmostEquatable<Rgb, float>
{
/// <summary>
/// Represents a <see cref="Rgb"/> that has R, G, and B values set to zero.

2
src/ImageSharp/ColorSpaces/YCbCr.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <see href="http://en.wikipedia.org/wiki/YCbCr"/>
/// <see href="http://www.ijg.org/files/T-REC-T.871-201105-I!!PDF-E.pdf"/>
/// </summary>
internal struct YCbCr : IColorVector, IEquatable<YCbCr>, IAlmostEquatable<YCbCr, float>
internal readonly struct YCbCr : IColorVector, IEquatable<YCbCr>, IAlmostEquatable<YCbCr, float>
{
/// <summary>
/// Represents a <see cref="YCbCr"/> that has Y, Cb, and Cr values set to zero.

8
src/ImageSharp/Common/Extensions/SimdUtils.cs

@ -76,8 +76,8 @@ namespace SixLabors.ImageSharp
return;
}
ref Vector<float> srcBase = ref Unsafe.As<float, Vector<float>>(ref source.DangerousGetPinnableReference());
ref Octet.OfByte destBase = ref Unsafe.As<byte, Octet.OfByte>(ref dest.DangerousGetPinnableReference());
ref Vector<float> srcBase = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(source));
ref Octet.OfByte destBase = ref Unsafe.As<byte, Octet.OfByte>(ref MemoryMarshal.GetReference(dest));
int n = source.Length / 8;
Vector<float> magick = new Vector<float>(32768.0f);
@ -117,8 +117,8 @@ namespace SixLabors.ImageSharp
return;
}
ref Vector<float> srcBase = ref Unsafe.As<float, Vector<float>>(ref source.DangerousGetPinnableReference());
ref Octet.OfByte destBase = ref Unsafe.As<byte, Octet.OfByte>(ref dest.DangerousGetPinnableReference());
ref Vector<float> srcBase = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(source));
ref Octet.OfByte destBase = ref Unsafe.As<byte, Octet.OfByte>(ref MemoryMarshal.GetReference(dest));
int n = source.Length / 8;
Vector<float> magick = new Vector<float>(32768.0f);

2
src/ImageSharp/Formats/Gif/PackedField.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Represents a byte of data in a GIF data stream which contains a number
/// of data items.
/// </summary>
internal struct PackedField : IEquatable<PackedField>
internal readonly struct PackedField : IEquatable<PackedField>
{
/// <summary>
/// The individual bits representing the packed byte.

5
src/ImageSharp/Formats/Jpeg/Common/Block8x8.cs

@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace SixLabors.ImageSharp.Formats.Jpeg.Common
@ -34,7 +35,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
public Block8x8(Span<short> coefficients)
{
ref byte selfRef = ref Unsafe.As<Block8x8, byte>(ref this);
ref byte sourceRef = ref coefficients.NonPortableCast<short, byte>().DangerousGetPinnableReference();
ref byte sourceRef = ref MemoryMarshal.GetReference(coefficients.NonPortableCast<short, byte>());
Unsafe.CopyBlock(ref selfRef, ref sourceRef, Size * sizeof(short));
}
@ -204,7 +205,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
public void CopyTo(Span<short> destination)
{
ref byte selfRef = ref Unsafe.As<Block8x8, byte>(ref this);
ref byte destRef = ref destination.NonPortableCast<short, byte>().DangerousGetPinnableReference();
ref byte destRef = ref MemoryMarshal.GetReference(destination.NonPortableCast<short, byte>());
Unsafe.CopyBlock(ref destRef, ref selfRef, Size * sizeof(short));
}

4
src/ImageSharp/Formats/Jpeg/Common/Block8x8F.cs

@ -163,7 +163,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void LoadFrom(Span<float> source)
{
ref byte s = ref Unsafe.As<float, byte>(ref source.DangerousGetPinnableReference());
ref byte s = ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(source));
ref byte d = ref Unsafe.As<Block8x8F, byte>(ref this);
Unsafe.CopyBlock(ref d, ref s, Size * sizeof(float));
@ -203,7 +203,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CopyTo(Span<float> dest)
{
ref byte d = ref Unsafe.As<float, byte>(ref dest.DangerousGetPinnableReference());
ref byte d = ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(dest));
ref byte s = ref Unsafe.As<Block8x8F, byte>(ref this);
Unsafe.CopyBlock(ref d, ref s, Size * sizeof(float));

2
src/ImageSharp/Formats/Jpeg/Common/Decoder/AdobeMarker.cs

@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
/// Provides information about the Adobe marker segment.
/// </summary>
/// <remarks>See the included 5116.DCT.pdf file in the source for more information.</remarks>
internal struct AdobeMarker : IEquatable<AdobeMarker>
internal readonly struct AdobeMarker : IEquatable<AdobeMarker>
{
/// <summary>
/// Gets the length of an adobe marker segment.

9
src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimd.cs

@ -4,6 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Common.Tuples;
namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
@ -37,14 +38,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
DebugGuard.IsTrue(result.Length % 8 == 0, nameof(result), "result.Length should be divisable by 8!");
ref Vector4Pair yBase =
ref Unsafe.As<float, Vector4Pair>(ref values.Component0.DangerousGetPinnableReference());
ref Unsafe.As<float, Vector4Pair>(ref MemoryMarshal.GetReference(values.Component0));
ref Vector4Pair cbBase =
ref Unsafe.As<float, Vector4Pair>(ref values.Component1.DangerousGetPinnableReference());
ref Unsafe.As<float, Vector4Pair>(ref MemoryMarshal.GetReference(values.Component1));
ref Vector4Pair crBase =
ref Unsafe.As<float, Vector4Pair>(ref values.Component2.DangerousGetPinnableReference());
ref Unsafe.As<float, Vector4Pair>(ref MemoryMarshal.GetReference(values.Component2));
ref Vector4Octet resultBase =
ref Unsafe.As<Vector4, Vector4Octet>(ref result.DangerousGetPinnableReference());
ref Unsafe.As<Vector4, Vector4Octet>(ref MemoryMarshal.GetReference(result));
var chromaOffset = new Vector4(-128f);

9
src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromYCbCrSimdAvx2.cs

@ -4,6 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Common.Tuples;
// ReSharper disable ImpureMethodCallOnReadonlyValueField
@ -46,14 +47,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
}
ref Vector<float> yBase =
ref Unsafe.As<float, Vector<float>>(ref values.Component0.DangerousGetPinnableReference());
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0));
ref Vector<float> cbBase =
ref Unsafe.As<float, Vector<float>>(ref values.Component1.DangerousGetPinnableReference());
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component1));
ref Vector<float> crBase =
ref Unsafe.As<float, Vector<float>>(ref values.Component2.DangerousGetPinnableReference());
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2));
ref Vector4Octet resultBase =
ref Unsafe.As<Vector4, Vector4Octet>(ref result.DangerousGetPinnableReference());
ref Unsafe.As<Vector4, Vector4Octet>(ref MemoryMarshal.GetReference(result));
var chromaOffset = new Vector<float>(-128f);

4
src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs

@ -66,7 +66,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
/// <summary>
/// A stack-only struct to reference the input buffers using <see cref="ReadOnlySpan{T}"/>-s.
/// </summary>
public struct ComponentValues
#pragma warning disable SA1206 // Declaration keywords should follow order
public readonly ref struct ComponentValues
#pragma warning restore SA1206 // Declaration keywords should follow order
{
/// <summary>
/// The component count

2
src/ImageSharp/Formats/Jpeg/Common/Decoder/JFifMarker.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
/// Provides information about the JFIF marker segment
/// TODO: Thumbnail?
/// </summary>
internal struct JFifMarker : IEquatable<JFifMarker>
internal readonly struct JFifMarker : IEquatable<JFifMarker>
{
/// <summary>
/// Gets the length of an JFIF marker segment.

2
src/ImageSharp/Formats/Jpeg/Common/GenericBlock8x8.cs

@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common
ref byte blockStart = ref Unsafe.As<GenericBlock8x8<T>, byte>(ref this);
ref byte imageStart = ref Unsafe.As<T, byte>(
ref Unsafe.Add(ref source.GetRowSpan(sourceY).DangerousGetPinnableReference(), sourceX));
ref Unsafe.Add(ref MemoryMarshal.GetReference(source.GetRowSpan(sourceY)), sourceX));
int blockRowSizeInBytes = 8 * Unsafe.SizeOf<T>();
int imageRowSizeInBytes = source.Width * Unsafe.SizeOf<T>();

2
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs

@ -5,8 +5,6 @@ using System;
using System.IO;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
{
/// <summary>

2
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanLut.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder
/// codeword size in bits and the 24 least significant bits hold the codeword.
/// The maximum codeword size is 16 bits.
/// </summary>
internal struct HuffmanLut
internal readonly struct HuffmanLut
{
/// <summary>
/// The compiled representations of theHuffmanSpec.

2
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Encoder/HuffmanSpec.cs

@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Encoder
/// <summary>
/// The Huffman encoding specifications.
/// </summary>
internal struct HuffmanSpec
internal readonly struct HuffmanSpec
{
#pragma warning disable SA1118 // ParameterMustNotSpanMultipleLines

2
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsYCbCrToRgbTables.cs

@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// Provides 8-bit lookup tables for converting from YCbCr to Rgb colorspace.
/// Methods to build the tables are based on libjpeg implementation.
/// </summary>
internal struct PdfJsYCbCrToRgbTables
internal readonly struct PdfJsYCbCrToRgbTables
{
/// <summary>
/// The red red-chrominance table

11
src/ImageSharp/Formats/Png/Filters/AverageFilter.cs

@ -3,6 +3,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
@ -24,8 +25,8 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
// Average(x) + floor((Raw(x-bpp)+Prior(x))/2)
for (int x = 1; x < scanline.Length; x++)
@ -60,9 +61,9 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
ref byte resultBaseRef = ref MemoryMarshal.GetReference(result);
sum = 0;
// Average(x) = Raw(x) - floor((Raw(x-bpp)+Prior(x))/2)

11
src/ImageSharp/Formats/Png/Filters/PaethFilter.cs

@ -3,6 +3,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
@ -25,8 +26,8 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
// Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp))
int offset = bytesPerPixel + 1;
@ -61,9 +62,9 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
ref byte resultBaseRef = ref MemoryMarshal.GetReference(result);
sum = 0;
// Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp), Prior(x), Prior(x - bpp))

7
src/ImageSharp/Formats/Png/Filters/SubFilter.cs

@ -3,6 +3,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
@ -21,7 +22,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Decode(Span<byte> scanline, int bytesPerPixel)
{
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
// Sub(x) + Raw(x-bpp)
for (int x = 1; x < scanline.Length; x++)
@ -52,8 +53,8 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
{
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
ref byte resultBaseRef = ref MemoryMarshal.GetReference(result);
sum = 0;
// Sub(x) = Raw(x) - Raw(x-bpp)

11
src/ImageSharp/Formats/Png/Filters/UpFilter.cs

@ -3,6 +3,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.Png.Filters
{
@ -23,8 +24,8 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
{
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
// Up(x) + Prior(x)
for (int x = 1; x < scanline.Length; x++)
@ -48,9 +49,9 @@ namespace SixLabors.ImageSharp.Formats.Png.Filters
DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline));
DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result));
ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference();
ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();
ref byte resultBaseRef = ref result.DangerousGetPinnableReference();
ref byte scanBaseRef = ref MemoryMarshal.GetReference(scanline);
ref byte prevBaseRef = ref MemoryMarshal.GetReference(previousScanline);
ref byte resultBaseRef = ref MemoryMarshal.GetReference(result);
sum = 0;
// Up(x) = Raw(x) - Prior(x)

4
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -701,7 +701,7 @@ namespace SixLabors.ImageSharp.Formats.Png
Span<TPixel> rowSpan = pixels.GetPixelRowSpan(this.currentRow);
// Trim the first marker byte from the buffer
var scanlineBuffer = new Span<byte>(defilteredScanline, 1);
var scanlineBuffer = new Span<byte>(defilteredScanline, 1, defilteredScanline.Length - 1);
switch (this.pngColorType)
{
@ -932,7 +932,7 @@ namespace SixLabors.ImageSharp.Formats.Png
var color = default(TPixel);
// Trim the first marker byte from the buffer
var scanlineBuffer = new Span<byte>(defilteredScanline, 1);
var scanlineBuffer = new Span<byte>(defilteredScanline, 1, defilteredScanline.Length - 1);
switch (this.pngColorType)
{

6
src/ImageSharp/ImageSharp.csproj

@ -29,6 +29,7 @@
<DebugType Condition="$(codecov) == ''">portable</DebugType>
<DebugSymbols>True</DebugSymbols>
<Features>IOperation</Features>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Shared\*.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
@ -40,12 +41,11 @@
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Buffers" Version="4.4.0" />
<PackageReference Include="System.Memory" Version="4.4.0-preview2-25405-01" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.4.0" />
<PackageReference Include="System.Memory" Version="4.5.0-preview1-26216-02" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.0-preview1-26216-02" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' OR '$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.4.0" />
<PackageReference Include="System.Threading.Tasks.Parallel" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
</ItemGroup>

2
src/ImageSharp/Memory/BufferArea{T}.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Memory
/// This type is kind-of 2D Span, but it can live on heap.
/// </summary>
/// <typeparam name="T">The element type</typeparam>
internal struct BufferArea<T>
internal readonly struct BufferArea<T>
where T : struct
{
/// <summary>

3
src/ImageSharp/Memory/BufferExtensions.cs

@ -4,6 +4,7 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Memory
{
@ -53,7 +54,7 @@ namespace SixLabors.ImageSharp.Memory
public static ref T DangerousGetPinnableReference<T>(this IBuffer<T> buffer)
where T : struct =>
ref buffer.Span.DangerousGetPinnableReference();
ref MemoryMarshal.GetReference(buffer.Span);
public static void Read(this Stream stream, IManagedByteBuffer buffer)
{

7
src/ImageSharp/Memory/SpanHelper.cs

@ -4,6 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Memory
{
@ -22,7 +23,7 @@ namespace SixLabors.ImageSharp.Memory
public static ref Vector<T> FetchVector<T>(this Span<T> span)
where T : struct
{
return ref Unsafe.As<T, Vector<T>>(ref span.DangerousGetPinnableReference());
return ref Unsafe.As<T, Vector<T>>(ref MemoryMarshal.GetReference(span));
}
/// <summary>
@ -39,8 +40,8 @@ namespace SixLabors.ImageSharp.Memory
DebugGuard.MustBeLessThanOrEqualTo(count, source.Length, nameof(count));
DebugGuard.MustBeLessThanOrEqualTo(count, destination.Length, nameof(count));
ref byte srcRef = ref Unsafe.As<T, byte>(ref source.DangerousGetPinnableReference());
ref byte destRef = ref Unsafe.As<T, byte>(ref destination.DangerousGetPinnableReference());
ref byte srcRef = ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(source));
ref byte destRef = ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(destination));
int byteCount = Unsafe.SizeOf<T>() * count;

2
src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// Entry of ICC colorant table
/// </summary>
internal struct IccColorantTableEntry : IEquatable<IccColorantTableEntry>
internal readonly struct IccColorantTableEntry : IEquatable<IccColorantTableEntry>
{
/// <summary>
/// Initializes a new instance of the <see cref="IccColorantTableEntry"/> struct.

2
src/ImageSharp/MetaData/Profiles/ICC/Various/IccNamedColor.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// A specific color with a name
/// </summary>
internal struct IccNamedColor : IEquatable<IccNamedColor>
internal readonly struct IccNamedColor : IEquatable<IccNamedColor>
{
/// <summary>
/// Initializes a new instance of the <see cref="IccNamedColor"/> struct.

2
src/ImageSharp/MetaData/Profiles/ICC/Various/IccPositionNumber.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// Position of an object within an ICC profile
/// </summary>
internal struct IccPositionNumber : IEquatable<IccPositionNumber>
internal readonly struct IccPositionNumber : IEquatable<IccPositionNumber>
{
/// <summary>
/// Initializes a new instance of the <see cref="IccPositionNumber"/> struct.

2
src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// ICC Profile ID
/// </summary>
public struct IccProfileId : IEquatable<IccProfileId>
public readonly struct IccProfileId : IEquatable<IccProfileId>
{
/// <summary>
/// A profile ID with all values set to zero

2
src/ImageSharp/MetaData/Profiles/ICC/Various/IccResponseNumber.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// Associates a normalized device code with a measurement value
/// </summary>
internal struct IccResponseNumber : IEquatable<IccResponseNumber>
internal readonly struct IccResponseNumber : IEquatable<IccResponseNumber>
{
/// <summary>
/// Initializes a new instance of the <see cref="IccResponseNumber"/> struct.

2
src/ImageSharp/MetaData/Profiles/ICC/Various/IccScreeningChannel.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// A single channel of a <see cref="IccScreeningTagDataEntry"/>
/// </summary>
internal struct IccScreeningChannel : IEquatable<IccScreeningChannel>
internal readonly struct IccScreeningChannel : IEquatable<IccScreeningChannel>
{
/// <summary>
/// Initializes a new instance of the <see cref="IccScreeningChannel"/> struct.

2
src/ImageSharp/MetaData/Profiles/ICC/Various/IccTagTableEntry.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// Entry of ICC tag table
/// </summary>
internal struct IccTagTableEntry : IEquatable<IccTagTableEntry>
internal readonly struct IccTagTableEntry : IEquatable<IccTagTableEntry>
{
/// <summary>
/// Initializes a new instance of the <see cref="IccTagTableEntry"/> struct.

2
src/ImageSharp/Numerics/ValueSize.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp
/// <summary>
/// Represents a value in relation to a value on the image
/// </summary>
internal struct ValueSize : IEquatable<ValueSize>
internal readonly struct ValueSize : IEquatable<ValueSize>
{
/// <summary>
/// Initializes a new instance of the <see cref="ValueSize"/> struct.

35
src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.cs

@ -6,7 +6,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public partial class PixelOperations<TPixel>
{
@ -20,8 +21,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
ref Rgba32 sourceRef = ref source.DangerousGetPinnableReference();
ref TPixel destRef = ref destPixels.DangerousGetPinnableReference();
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(source);
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
Rgba32 rgba = new Rgba32(0, 0, 0, 255);
@ -57,8 +58,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
ref TPixel sourceBaseRef = ref sourcePixels.DangerousGetPinnableReference();
ref Rgba32 destBaseRef = ref dest.DangerousGetPinnableReference();
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destBaseRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@ -91,8 +92,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
ref Bgra32 sourceRef = ref source.DangerousGetPinnableReference();
ref TPixel destRef = ref destPixels.DangerousGetPinnableReference();
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(source);
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
Rgba32 rgba = new Rgba32(0, 0, 0, 255);
@ -128,8 +129,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
ref TPixel sourceBaseRef = ref sourcePixels.DangerousGetPinnableReference();
ref Bgra32 destBaseRef = ref dest.DangerousGetPinnableReference();
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destBaseRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@ -162,8 +163,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
ref Rgb24 sourceRef = ref source.DangerousGetPinnableReference();
ref TPixel destRef = ref destPixels.DangerousGetPinnableReference();
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(source);
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
Rgba32 rgba = new Rgba32(0, 0, 0, 255);
@ -199,8 +200,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
ref TPixel sourceBaseRef = ref sourcePixels.DangerousGetPinnableReference();
ref Rgb24 destBaseRef = ref dest.DangerousGetPinnableReference();
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destBaseRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@ -233,8 +234,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
ref Bgr24 sourceRef = ref source.DangerousGetPinnableReference();
ref TPixel destRef = ref destPixels.DangerousGetPinnableReference();
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(source);
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
Rgba32 rgba = new Rgba32(0, 0, 0, 255);
@ -270,8 +271,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
ref TPixel sourceBaseRef = ref sourcePixels.DangerousGetPinnableReference();
ref Bgr24 destBaseRef = ref dest.DangerousGetPinnableReference();
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destBaseRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{

12
src/ImageSharp/PixelFormats/Generated/PixelOperations{TPixel}.Generated.tt

@ -7,6 +7,7 @@
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Runtime.InteropServices" #>
<#@ output extension=".cs" #>
<#
void GenerateToDestFormatMethods(string pixelType)
@ -24,8 +25,8 @@
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
ref TPixel sourceBaseRef = ref sourcePixels.DangerousGetPinnableReference();
ref <#=pixelType#> destBaseRef = ref dest.DangerousGetPinnableReference();
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref <#=pixelType#> destBaseRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@ -64,8 +65,8 @@
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
ref <#=pixelType#> sourceRef = ref source.DangerousGetPinnableReference();
ref TPixel destRef = ref destPixels.DangerousGetPinnableReference();
ref <#=pixelType#> sourceRef = ref MemoryMarshal.GetReference(source);
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels);
Rgba32 rgba = new Rgba32(0, 0, 0, 255);
@ -101,7 +102,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
public partial class PixelOperations<TPixel>
{
<#

28
src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs

@ -6,9 +6,9 @@ namespace SixLabors.ImageSharp
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats;
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
@ -22,8 +22,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
ref Rgb24 sourceRef = ref source.DangerousGetPinnableReference();
ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference();
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels);
for (int i = 0; i < count; i++)
{
@ -38,8 +38,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference();
ref Rgb24 destRef = ref dest.DangerousGetPinnableReference();
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@ -54,8 +54,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
ref Bgr24 sourceRef = ref source.DangerousGetPinnableReference();
ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference();
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels);
for (int i = 0; i < count; i++)
{
@ -70,8 +70,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference();
ref Bgr24 destRef = ref dest.DangerousGetPinnableReference();
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@ -86,8 +86,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
ref Bgra32 sourceRef = ref source.DangerousGetPinnableReference();
ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference();
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels);
for (int i = 0; i < count; i++)
{
@ -102,8 +102,8 @@ namespace SixLabors.ImageSharp
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference();
ref Bgra32 destRef = ref dest.DangerousGetPinnableReference();
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{

12
src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt

@ -18,8 +18,8 @@
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
ref <#=pixelType#> sourceRef = ref source.DangerousGetPinnableReference();
ref Rgba32 destRef = ref destPixels.DangerousGetPinnableReference();
ref <#=pixelType#> sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels);
for (int i = 0; i < count; i++)
{
@ -40,8 +40,8 @@
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
ref Rgba32 sourceRef = ref sourcePixels.DangerousGetPinnableReference();
ref <#=pixelType#> destRef = ref dest.DangerousGetPinnableReference();
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref <#=pixelType#> destRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
@ -61,9 +61,9 @@ namespace SixLabors.ImageSharp
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats;
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>

9
src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs

@ -4,6 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats
{
@ -30,8 +31,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourceVectors, nameof(sourceVectors), destColors, nameof(destColors), count);
ref Vector4 sourceRef = ref sourceVectors.DangerousGetPinnableReference();
ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
ref Vector4 sourceRef = ref MemoryMarshal.GetReference(sourceVectors);
ref TPixel destRef = ref MemoryMarshal.GetReference(destColors);
for (int i = 0; i < count; i++)
{
@ -51,8 +52,8 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourceColors, nameof(sourceColors), destVectors, nameof(destVectors), count);
ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference();
ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference();
ref TPixel sourceRef = ref MemoryMarshal.GetReference(sourceColors);
ref Vector4 destRef = ref MemoryMarshal.GetReference(destVectors);
for (int i = 0; i < count; i++)
{

4
src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs

@ -57,8 +57,8 @@ namespace SixLabors.ImageSharp
int unpackedRawCount = count * 4;
ref uint sourceBase = ref Unsafe.As<Rgba32, uint>(ref sourceColors.DangerousGetPinnableReference());
ref UnpackedRGBA destBaseAsUnpacked = ref Unsafe.As<Vector4, UnpackedRGBA>(ref destVectors.DangerousGetPinnableReference());
ref uint sourceBase = ref Unsafe.As<Rgba32, uint>(ref MemoryMarshal.GetReference(sourceColors));
ref UnpackedRGBA destBaseAsUnpacked = ref Unsafe.As<Vector4, UnpackedRGBA>(ref MemoryMarshal.GetReference(destVectors));
ref Vector<uint> destBaseAsUInt = ref Unsafe.As<UnpackedRGBA, Vector<uint>>(ref destBaseAsUnpacked);
ref Vector<float> destBaseAsFloat = ref Unsafe.As<UnpackedRGBA, Vector<float>>(ref destBaseAsUnpacked);

2
src/ImageSharp/Processing/Processors/Dithering/PixelPair.cs

@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
/// Represents a composite pair of pixels. Used for caching color distance lookups.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal struct PixelPair<TPixel> : IEquatable<PixelPair<TPixel>>
internal readonly struct PixelPair<TPixel> : IEquatable<PixelPair<TPixel>>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>

6
src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs

@ -4,7 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Processing.Processors
@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
{
ref float horizontalValues = ref this.GetStartReference();
int left = this.Left;
ref Vector4 vecPtr = ref Unsafe.Add(ref rowSpan.DangerousGetPinnableReference(), left + sourceX);
ref Vector4 vecPtr = ref Unsafe.Add(ref MemoryMarshal.GetReference(rowSpan), left + sourceX);
// Destination color components
Vector4 result = Vector4.Zero;
@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.Processing.Processors
{
ref float horizontalValues = ref this.GetStartReference();
int left = this.Left;
ref Vector4 vecPtr = ref Unsafe.Add(ref rowSpan.DangerousGetPinnableReference(), left + sourceX);
ref Vector4 vecPtr = ref Unsafe.Add(ref MemoryMarshal.GetReference(rowSpan), left + sourceX);
// Destination color components
Vector4 result = Vector4.Zero;

6
tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs

@ -3,7 +3,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
{
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Memory;
@ -37,8 +37,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Color.Bulk
[Benchmark(Baseline = true)]
public void PerElement()
{
ref Vector4 s = ref this.source.Span.DangerousGetPinnableReference();
ref TPixel d = ref this.destination.Span.DangerousGetPinnableReference();
ref Vector4 s = ref MemoryMarshal.GetReference(this.source.Span);
ref TPixel d = ref MemoryMarshal.GetReference(this.destination.Span);
for (int i = 0; i < this.Count; i++)
{

8
tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj

@ -17,11 +17,11 @@
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.10.12" />
<PackageReference Include="Colourful" Version="1.1.2" />
<PackageReference Include="System.Drawing.Common" Version="4.5.0-preview2-26202-05" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net461'">
<PackageReference Include="System.Numerics.Vectors" Version="4.4.0" />
<PackageReference Include="System.Drawing.Common" Version="4.5.0-preview1-26216-02" />
<PackageReference Include="System.Memory" Version="4.5.0-preview1-26216-02" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0-preview1-26216-02" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ImageSharp.Drawing\ImageSharp.Drawing.csproj" />
<ProjectReference Include="..\..\src\ImageSharp\ImageSharp.csproj" />

3
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -16,7 +16,8 @@
<None Include="PixelFormats\PixelOperationsTests.Blender.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="4.5.0-preview2-26202-05" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0-preview1-26216-02" />
<PackageReference Include="System.Drawing.Common" Version="4.5.0-preview1-26216-02" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Moq" Version="4.7.145" />

2
tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs

@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
public void ReleaseRetainedResources_ReplacesInnerArrayPool(bool keepBufferAlive)
{
IBuffer<int> buffer = this.MemoryManager.Allocate<int>(32);
ref int ptrToPrev0 = ref buffer.Span.DangerousGetPinnableReference();
ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.Span);
if (!keepBufferAlive)
{

4
tests/ImageSharp.Tests/Memory/Buffer2DTests.cs

@ -5,7 +5,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Tests.Common;
using SixLabors.Primitives;
@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
public static void SpanPointsTo<T>(Span<T> span, IBuffer<T> buffer, int bufferOffset = 0)
where T : struct
{
ref T actual = ref span.DangerousGetPinnableReference();
ref T actual = ref MemoryMarshal.GetReference(span);
ref T expected = ref Unsafe.Add(ref buffer.DangerousGetPinnableReference(), bufferOffset);
Assert.True(Unsafe.AreSame(ref expected, ref actual), "span does not point to the expected position");

7
tests/ImageSharp.Tests/Memory/BufferTestSuite.cs

@ -3,6 +3,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
using Xunit;
// ReSharper disable InconsistentNaming
@ -165,9 +166,9 @@ namespace SixLabors.ImageSharp.Tests.Memory
{
using (IBuffer<T> buffer = this.Allocate<T>(desiredLength, false, testManagedByteBuffer))
{
ref T a = ref buffer.Span.DangerousGetPinnableReference();
ref T b = ref buffer.Span.DangerousGetPinnableReference();
ref T c = ref buffer.Span.DangerousGetPinnableReference();
ref T a = ref MemoryMarshal.GetReference(buffer.Span);
ref T b = ref MemoryMarshal.GetReference(buffer.Span);
ref T c = ref MemoryMarshal.GetReference(buffer.Span);
Assert.True(Unsafe.AreSame(ref a, ref b));
Assert.True(Unsafe.AreSame(ref b, ref c));

20
tests/ImageSharp.Tests/Memory/SpanUtilityTests.cs

@ -78,8 +78,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
TestStructs.Foo[] source = TestStructs.Foo.CreateArray(count + 2);
TestStructs.Foo[] dest = new TestStructs.Foo[count + 5];
var apSource = new Span<TestStructs.Foo>(source, 1);
var apDest = new Span<TestStructs.Foo>(dest, 1);
var apSource = new Span<TestStructs.Foo>(source, 1, source.Length - 1);
var apDest = new Span<TestStructs.Foo>(dest, 1, dest.Length - 1);
SpanHelper.Copy(apSource, apDest, count - 1);
@ -101,8 +101,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
TestStructs.AlignedFoo[] source = TestStructs.AlignedFoo.CreateArray(count + 2);
TestStructs.AlignedFoo[] dest = new TestStructs.AlignedFoo[count + 5];
var apSource = new Span<TestStructs.AlignedFoo>(source, 1);
var apDest = new Span<TestStructs.AlignedFoo>(dest, 1);
var apSource = new Span<TestStructs.AlignedFoo>(source, 1, source.Length - 1);
var apDest = new Span<TestStructs.AlignedFoo>(dest, 1, dest.Length - 1);
SpanHelper.Copy(apSource, apDest, count - 1);
@ -124,8 +124,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
int[] source = CreateTestInts(count + 2);
int[] dest = new int[count + 5];
var apSource = new Span<int>(source, 1);
var apDest = new Span<int>(dest, 1);
var apSource = new Span<int>(source, 1, source.Length - 1);
var apDest = new Span<int>(dest, 1, dest.Length - 1);
SpanHelper.Copy(apSource, apDest, count - 1);
@ -148,8 +148,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
TestStructs.Foo[] source = TestStructs.Foo.CreateArray(count + 2);
byte[] dest = new byte[destCount + sizeof(TestStructs.Foo) * 2];
var apSource = new Span<TestStructs.Foo>(source, 1);
var apDest = new Span<byte>(dest, sizeof(TestStructs.Foo));
var apSource = new Span<TestStructs.Foo>(source, 1, source.Length - 1);
var apDest = new Span<byte>(dest, sizeof(TestStructs.Foo), dest.Length - sizeof(TestStructs.Foo));
SpanHelper.Copy(apSource.AsBytes(), apDest, (count - 1) * sizeof(TestStructs.Foo));
@ -171,8 +171,8 @@ namespace SixLabors.ImageSharp.Tests.Memory
TestStructs.AlignedFoo[] source = TestStructs.AlignedFoo.CreateArray(count + 2);
byte[] dest = new byte[destCount + sizeof(TestStructs.AlignedFoo) * 2];
var apSource = new Span<TestStructs.AlignedFoo>(source, 1);
var apDest = new Span<byte>(dest, sizeof(TestStructs.AlignedFoo));
var apSource = new Span<TestStructs.AlignedFoo>(source, 1, source.Length - 1);
var apDest = new Span<byte>(dest, sizeof(TestStructs.AlignedFoo), dest.Length - sizeof(TestStructs.AlignedFoo));
SpanHelper.Copy(apSource.AsBytes(), apDest, (count - 1) * sizeof(TestStructs.AlignedFoo));

Loading…
Cancel
Save