diff --git a/.gitattributes b/.gitattributes
index 435f0bb91b..0f550f4074 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -89,13 +89,22 @@
###############################################################################
*.bmp binary
*.dll binary
+*.eot binary
*.exe binary
*.gif binary
*.jpg binary
+*.pdf binary
*.png binary
-*.tga binary
+*.ppt binary
+*.pptx binary
*.ttf binary
*.snk binary
+*.ttf binary
+*.woff binary
+*.woff2 binary
+*.xls binary
+*.xlsx binary
+
###############################################################################
# Set explicit file behavior to:
@@ -107,3 +116,4 @@
*.pdf diff=astextplain
*.pptx diff=astextplain
*.rtf diff=astextplain
+*.svg diff=astextplain
diff --git a/Directory.Build.props b/Directory.Build.props
index efe4cc9665..9fcdf13961 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -29,10 +29,42 @@
true
+
+
+
+
+ $(DefineConstants);SUPPORTS_MATHF;SUPPORTS_HASHCODE;SUPPORTS_EXTENDED_INTRINSICS;SUPPORTS_SPAN_STREAM;SUPPORTS_ENCODING_STRING
+
+
+ $(DefineConstants);SUPPORTS_MATHF;SUPPORTS_HASHCODE;SUPPORTS_EXTENDED_INTRINSICS;SUPPORTS_SPAN_STREAM;SUPPORTS_ENCODING_STRING
+
+
+ $(DefineConstants);SUPPORTS_MATHF;
+
+
+ $(DefineConstants);SUPPORTS_MATHF;SUPPORTS_SPAN_STREAM;SUPPORTS_ENCODING_STRING
+
+
+ $(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS
+
+
true
-
+
false
diff --git a/shared-infrastructure b/shared-infrastructure
index faf84e44ec..c2e689abe9 160000
--- a/shared-infrastructure
+++ b/shared-infrastructure
@@ -1 +1 @@
-Subproject commit faf84e44ec90e8a42a7271bcd04fea76279efb08
+Subproject commit c2e689abe9227209e6d5bc4bf56255d92b4a5d62
diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
index 5a53d3e78b..c4e3224bbe 100644
--- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
+++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
@@ -8,18 +8,10 @@
SixLabors.ImageSharp.Drawing
Image Draw Shape Path Font
SixLabors.ImageSharp
- netcoreapp2.1;netstandard1.3;netstandard2.0
-
-
-
- $(DefineConstants);SUPPORTS_MATHF
+ netcoreapp2.1;netstandard2.0;netstandard1.3
-
- $(DefineConstants);SUPPORTS_HASHCODE
-
-
diff --git a/src/ImageSharp/Common/Extensions/EncoderExtensions.cs b/src/ImageSharp/Common/Extensions/EncoderExtensions.cs
index 59c878485d..87aaa93a9f 100644
--- a/src/ImageSharp/Common/Extensions/EncoderExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/EncoderExtensions.cs
@@ -1,7 +1,7 @@
-// Copyright (c) Six Labors and contributors.
+// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-#if !NETCOREAPP2_1
+#if !SUPPORTS_ENCODING_STRING
using System;
using System.Text;
@@ -32,4 +32,4 @@ public static string GetString(this Encoding encoding, ReadOnlySpan buffer
}
}
}
-#endif
\ No newline at end of file
+#endif
diff --git a/src/ImageSharp/Common/Extensions/StreamExtensions.cs b/src/ImageSharp/Common/Extensions/StreamExtensions.cs
index 6af09b220a..cee3e24145 100644
--- a/src/ImageSharp/Common/Extensions/StreamExtensions.cs
+++ b/src/ImageSharp/Common/Extensions/StreamExtensions.cs
@@ -4,7 +4,6 @@
using System;
using System.Buffers;
using System.IO;
-
using SixLabors.ImageSharp.Memory;
using SixLabors.Memory;
@@ -15,7 +14,6 @@ namespace SixLabors.ImageSharp
///
internal static class StreamExtensions
{
-#if NETCOREAPP2_1
///
/// Writes data from a stream into the provided buffer.
///
@@ -24,23 +22,18 @@ internal static class StreamExtensions
/// The offset within the buffer to begin writing.
/// The number of bytes to write to the stream.
public static void Write(this Stream stream, Span buffer, int offset, int count)
- {
- stream.Write(buffer.Slice(offset, count));
- }
+ => stream.Write(buffer.Slice(offset, count));
///
/// Reads data from a stream into the provided buffer.
///
/// The stream.
- /// The buffer..
+ /// The buffer.
/// The offset within the buffer where the bytes are read into.
/// The number of bytes, if available, to read.
/// The actual number of bytes read.
public static int Read(this Stream stream, Span buffer, int offset, int count)
- {
- return stream.Read(buffer.Slice(offset, count));
- }
-#endif
+ => stream.Read(buffer.Slice(offset, count));
///
/// Skips the number of bytes in the given stream.
@@ -75,17 +68,39 @@ public static void Skip(this Stream stream, int count)
}
public static void Read(this Stream stream, IManagedByteBuffer buffer)
- {
- stream.Read(buffer.Array, 0, buffer.Length());
- }
+ => stream.Read(buffer.Array, 0, buffer.Length());
public static void Write(this Stream stream, IManagedByteBuffer buffer)
+ => stream.Write(buffer.Array, 0, buffer.Length());
+
+#if !SUPPORTS_SPAN_STREAM
+ // This is a port of the CoreFX implementation and is MIT Licensed:
+ // https://github.com/dotnet/corefx/blob/17300169760c61a90cab8d913636c1058a30a8c1/src/Common/src/CoreLib/System/IO/Stream.cs#L742
+ public static int Read(this Stream stream, Span buffer)
{
- stream.Write(buffer.Array, 0, buffer.Length());
+ // This uses ArrayPool.Shared, rather than taking a MemoryAllocator,
+ // in order to match the signature of the framework method that exists in
+ // .NET Core.
+ byte[] sharedBuffer = ArrayPool.Shared.Rent(buffer.Length);
+ try
+ {
+ int numRead = stream.Read(sharedBuffer, 0, buffer.Length);
+ if ((uint)numRead > (uint)buffer.Length)
+ {
+ throw new IOException("Stream was too long.");
+ }
+
+ new Span(sharedBuffer, 0, numRead).CopyTo(buffer);
+ return numRead;
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(sharedBuffer);
+ }
}
-#if NET472 || NETSTANDARD1_3 || NETSTANDARD2_0
- // This is a port of the CoreFX implementation and is MIT Licensed: https://github.com/dotnet/coreclr/blob/c4dca1072d15bdda64c754ad1ea474b1580fa554/src/System.Private.CoreLib/shared/System/IO/Stream.cs#L770
+ // This is a port of the CoreFX implementation and is MIT Licensed:
+ // https://github.com/dotnet/corefx/blob/17300169760c61a90cab8d913636c1058a30a8c1/src/Common/src/CoreLib/System/IO/Stream.cs#L775
public static void Write(this Stream stream, ReadOnlySpan buffer)
{
// This uses ArrayPool.Shared, rather than taking a MemoryAllocator,
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
index 596710294a..eda5f1f784 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
@@ -445,11 +445,7 @@ private void ReadRle24(Buffer2D pixels, int width, int height, b
/// Keeps track of rows, which have undefined pixels.
private void UncompressRle4(int w, Span buffer, Span undefinedPixels, Span rowsWithUndefinedPixels)
{
-#if NETCOREAPP2_1
Span cmd = stackalloc byte[2];
-#else
- var cmd = new byte[2];
-#endif
int count = 0;
while (count < buffer.Length)
@@ -556,11 +552,7 @@ private void UncompressRle4(int w, Span buffer, Span undefinedPixels
/// Keeps track of rows, which have undefined pixels.
private void UncompressRle8(int w, Span buffer, Span undefinedPixels, Span rowsWithUndefinedPixels)
{
-#if NETCOREAPP2_1
Span cmd = stackalloc byte[2];
-#else
- var cmd = new byte[2];
-#endif
int count = 0;
while (count < buffer.Length)
@@ -639,11 +631,7 @@ private void UncompressRle8(int w, Span buffer, Span undefinedPixels
/// Keeps track of rows, which have undefined pixels.
private void UncompressRle24(int w, Span buffer, Span undefinedPixels, Span rowsWithUndefinedPixels)
{
-#if NETCOREAPP2_1
Span cmd = stackalloc byte[2];
-#else
- var cmd = new byte[2];
-#endif
int uncompressedPixels = 0;
while (uncompressedPixels < buffer.Length)
@@ -1213,11 +1201,7 @@ private static int CountBits(uint n)
///
private void ReadInfoHeader()
{
-#if NETCOREAPP2_1
Span buffer = stackalloc byte[BmpInfoHeader.MaxHeaderSize];
-#else
- var buffer = new byte[BmpInfoHeader.MaxHeaderSize];
-#endif
// Read the header size.
this.stream.Read(buffer, 0, BmpInfoHeader.HeaderSizeSize);
@@ -1339,11 +1323,7 @@ private void ReadInfoHeader()
///
private void ReadFileHeader()
{
-#if NETCOREAPP2_1
Span buffer = stackalloc byte[BmpFileHeader.Size];
-#else
- var buffer = new byte[BmpFileHeader.Size];
-#endif
this.stream.Read(buffer, 0, BmpFileHeader.Size);
short fileTypeMarker = BinaryPrimitives.ReadInt16LittleEndian(buffer);
diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
index f7576bacbd..41be71d2b3 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
@@ -173,11 +173,7 @@ public void Encode(Image image, Stream stream)
reserved: 0,
offset: BmpFileHeader.Size + infoHeaderSize + colorPaletteSize);
-#if NETCOREAPP2_1
Span buffer = stackalloc byte[infoHeaderSize];
-#else
- var buffer = new byte[infoHeaderSize];
-#endif
fileHeader.WriteTo(buffer);
stream.Write(buffer, 0, BmpFileHeader.Size);
diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs
index af390e9545..2ae8a834ef 100644
--- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs
+++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs
@@ -113,11 +113,7 @@ public void DecodePixels(int width, int height, int dataSize, Span pixels)
Unsafe.Add(ref suffixRef, code) = (byte)code;
}
-#if NETCOREAPP2_1
Span buffer = stackalloc byte[255];
-#else
- var buffer = new byte[255];
-#endif
while (xyz < length)
{
@@ -227,11 +223,7 @@ public void DecodePixels(int width, int height, int dataSize, Span pixels)
/// The .
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
-#if NETCOREAPP2_1
private int ReadBlock(Span buffer)
-#else
- private int ReadBlock(byte[] buffer)
-#endif
{
int bufferSize = this.stream.ReadByte();
diff --git a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
index 1ff3bb5999..d4f42a6c36 100644
--- a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
+++ b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
@@ -565,11 +565,8 @@ private bool ReadFileHeader(Stream stream)
{
this.currentStream = stream;
-#if NETCOREAPP2_1
Span buffer = stackalloc byte[TgaFileHeader.Size];
-#else
- var buffer = new byte[TgaFileHeader.Size];
-#endif
+
this.currentStream.Read(buffer, 0, TgaFileHeader.Size);
this.fileHeader = TgaFileHeader.Parse(buffer);
this.metadata = new ImageMetadata();
diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
index 3f4fb8f934..9dcea142f5 100644
--- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
+++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
@@ -97,11 +97,7 @@ public void Encode(Image image, Stream stream)
pixelDepth: (byte)this.bitsPerPixel.Value,
imageDescriptor: imageDescriptor);
-#if NETCOREAPP2_1
Span buffer = stackalloc byte[TgaFileHeader.Size];
-#else
- byte[] buffer = new byte[TgaFileHeader.Size];
-#endif
fileHeader.WriteTo(buffer);
stream.Write(buffer, 0, TgaFileHeader.Size);
diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj
index c59f883964..d86da5dcdf 100644
--- a/src/ImageSharp/ImageSharp.csproj
+++ b/src/ImageSharp/ImageSharp.csproj
@@ -10,7 +10,7 @@
$(packageversion)
0.0.1
- netcoreapp2.1;netstandard1.3;netstandard2.0;net472
+ netcoreapp2.1;netstandard2.0;netstandard1.3;net472
true
true
@@ -19,23 +19,6 @@
SixLabors.ImageSharp
-
-
- $(DefineConstants);SUPPORTS_MATHF
-
-
-
- $(DefineConstants);SUPPORTS_HASHCODE
-
-
-
- $(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS
-
-
-
-
-
-