From a32b676962be502464e7977f82831ff3985a3363 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 15 Oct 2018 08:52:01 -0700 Subject: [PATCH 01/10] Drop netstandard1.1 support --- .../Common/Extensions/EncoderExtensions.cs | 4 --- src/ImageSharp/Common/Helpers/TestHelpers.cs | 4 +-- src/ImageSharp/Configuration.cs | 8 ------ src/ImageSharp/IO/IFileSystem.cs | 2 -- src/ImageSharp/IO/LocalFileSystem.cs | 17 +++--------- src/ImageSharp/Image.FromBytes.cs | 3 --- src/ImageSharp/Image.FromFile.cs | 4 +-- src/ImageSharp/ImageExtensions.cs | 3 --- src/ImageSharp/ImageSharp.csproj | 4 +-- .../MetaData/Profiles/ICC/IccProfile.cs | 9 +------ .../MetaData/Profiles/ICC/IccWriter.cs | 5 ---- .../MetaData/Profiles/ICC/IccProfileTests.cs | 5 ---- .../TestDataIcc/IccTestDataProfiles.cs | 26 +++---------------- 13 files changed, 12 insertions(+), 82 deletions(-) diff --git a/src/ImageSharp/Common/Extensions/EncoderExtensions.cs b/src/ImageSharp/Common/Extensions/EncoderExtensions.cs index e6b800e86..82899863c 100644 --- a/src/ImageSharp/Common/Extensions/EncoderExtensions.cs +++ b/src/ImageSharp/Common/Extensions/EncoderExtensions.cs @@ -20,14 +20,10 @@ namespace SixLabors.ImageSharp /// The string. public static string GetString(this Encoding encoding, ReadOnlySpan buffer) { -#if NETSTANDARD1_1 - return encoding.GetString(buffer.ToArray()); -#else fixed (byte* bytes = buffer) { return encoding.GetString(bytes, buffer.Length); } -#endif } } } diff --git a/src/ImageSharp/Common/Helpers/TestHelpers.cs b/src/ImageSharp/Common/Helpers/TestHelpers.cs index 14e5835b4..45ef7706d 100644 --- a/src/ImageSharp/Common/Helpers/TestHelpers.cs +++ b/src/ImageSharp/Common/Helpers/TestHelpers.cs @@ -13,9 +13,7 @@ namespace SixLabors.ImageSharp.Common.Helpers /// Only intended to be used in tests! /// internal const string ImageSharpBuiltAgainst = -#if NETSTANDARD1_1 - "netstandard1.1"; -#elif NETCOREAPP2_1 +#if NETCOREAPP2_1 "netcoreapp2.1"; #else "netstandard2.0"; diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 576f7bf3d..c0064d187 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -3,15 +3,12 @@ using System; using System.Collections.Generic; -using System.Threading.Tasks; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Png; -#if !NETSTANDARD1_1 using SixLabors.ImageSharp.IO; -#endif using SixLabors.ImageSharp.Processing; using SixLabors.Memory; @@ -100,12 +97,10 @@ namespace SixLabors.ImageSharp /// internal int MaxHeaderSize => this.ImageFormatsManager.MaxHeaderSize; -#if !NETSTANDARD1_1 /// /// Gets or sets the filesystem helper for accessing the local file system. /// internal IFileSystem FileSystem { get; set; } = new LocalFileSystem(); -#endif /// /// Gets or sets the image operations provider factory. @@ -135,10 +130,7 @@ namespace SixLabors.ImageSharp MemoryAllocator = this.MemoryAllocator, ImageOperationsProvider = this.ImageOperationsProvider, ReadOrigin = this.ReadOrigin, - -#if !NETSTANDARD1_1 FileSystem = this.FileSystem -#endif }; } diff --git a/src/ImageSharp/IO/IFileSystem.cs b/src/ImageSharp/IO/IFileSystem.cs index 088d4abb8..593c760fc 100644 --- a/src/ImageSharp/IO/IFileSystem.cs +++ b/src/ImageSharp/IO/IFileSystem.cs @@ -5,7 +5,6 @@ using System.IO; namespace SixLabors.ImageSharp.IO { - #if !NETSTANDARD1_1 /// /// A simple interface representing the filesystem. /// @@ -25,5 +24,4 @@ namespace SixLabors.ImageSharp.IO /// A stream representing the file to open. Stream Create(string path); } -#endif } diff --git a/src/ImageSharp/IO/LocalFileSystem.cs b/src/ImageSharp/IO/LocalFileSystem.cs index 204f5f4e1..dc5901ff9 100644 --- a/src/ImageSharp/IO/LocalFileSystem.cs +++ b/src/ImageSharp/IO/LocalFileSystem.cs @@ -1,30 +1,19 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.Collections.Generic; using System.IO; -using System.Text; namespace SixLabors.ImageSharp.IO { - #if !NETSTANDARD1_1 /// /// A wrapper around the local File apis. /// internal class LocalFileSystem : IFileSystem { /// - public Stream OpenRead(string path) - { - return File.OpenRead(path); - } + public Stream OpenRead(string path) => File.OpenRead(path); /// - public Stream Create(string path) - { - return File.Create(path); - } + public Stream Create(string path) => File.Create(path); } -#endif -} +} \ No newline at end of file diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs index 12abf720b..07adc03ff 100644 --- a/src/ImageSharp/Image.FromBytes.cs +++ b/src/ImageSharp/Image.FromBytes.cs @@ -174,8 +174,6 @@ namespace SixLabors.ImageSharp } } -#if !NETSTANDARD1_1 - /// /// By reading the header on the provided byte array this calculates the images format. /// @@ -303,6 +301,5 @@ namespace SixLabors.ImageSharp } } } -#endif } } \ No newline at end of file diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index ad8f3426f..b13cef482 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -#if !NETSTANDARD1_1 using System; using System.IO; using SixLabors.ImageSharp.Formats; @@ -212,5 +211,4 @@ namespace SixLabors.ImageSharp } } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ImageSharp/ImageExtensions.cs b/src/ImageSharp/ImageExtensions.cs index bf312cb6f..e579bec1a 100644 --- a/src/ImageSharp/ImageExtensions.cs +++ b/src/ImageSharp/ImageExtensions.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.InteropServices; using System.Text; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Formats; @@ -17,7 +16,6 @@ namespace SixLabors.ImageSharp /// public static partial class ImageExtensions { -#if !NETSTANDARD1_1 /// /// Writes the image to the given stream using the currently loaded image format. /// @@ -78,7 +76,6 @@ namespace SixLabors.ImageSharp source.Save(fs, encoder); } } -#endif /// /// Writes the image to the given stream using the currently loaded image format. diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index a7ca0a014..83b2b1260 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -5,7 +5,7 @@ $(packageversion) 0.0.1 Six Labors and contributors - netstandard1.1;netstandard1.3;netstandard2.0;netcoreapp2.1 + netstandard1.3;netstandard2.0;netcoreapp2.1 true true SixLabors.ImageSharp @@ -47,7 +47,7 @@ - + diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs index 44990b7ec..72665bc69 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs @@ -3,10 +3,7 @@ using System; using System.Collections.Generic; - -#if !NETSTANDARD1_1 using System.Security.Cryptography; -#endif namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -100,8 +97,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public IccProfile DeepClone() => new IccProfile(this); -#if !NETSTANDARD1_1 - /// /// Calculates the MD5 hash value of an ICC profile /// @@ -147,8 +142,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } } -#endif - /// /// Checks for signs of a corrupt profile. /// @@ -227,4 +220,4 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc this.entries = new List(reader.ReadTagData(this.data)); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs index c42e32d55..b476e3195 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; using System.Collections.Generic; using System.Linq; @@ -51,12 +50,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc writer.WriteXyzNumber(header.PcsIlluminant); writer.WriteAsciiString(header.CreatorSignature, 4, false); -#if !NETSTANDARD1_1 IccProfileId id = IccProfile.CalculateHash(writer.GetData()); writer.WriteProfileId(id); -#else - writer.WriteProfileId(IccProfileId.Zero); -#endif } private void WriteTagTable(IccDataWriter writer, IccTagTableEntry[] table) diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccProfileTests.cs index 2e2c92182..17b5dacc4 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccProfileTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccProfileTests.cs @@ -9,9 +9,6 @@ namespace SixLabors.ImageSharp.Tests.Icc { public class IccProfileTests { - -#if !NETSTANDARD1_1 - [Theory] [MemberData(nameof(IccTestDataProfiles.ProfileIdTestData), MemberType = typeof(IccTestDataProfiles))] public void CalculateHash_WithByteArray_CalculatesProfileHash(byte[] data, IccProfileId expected) @@ -33,8 +30,6 @@ namespace SixLabors.ImageSharp.Tests.Icc Assert.Equal(data, copy); } -#endif - [Theory] [MemberData(nameof(IccTestDataProfiles.ProfileValidityTestData), MemberType = typeof(IccTestDataProfiles))] public void CheckIsValid_WithProfiles_ReturnsValidity(byte[] data, bool expected) diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs index 35ffa2bbb..b037a7a9a 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs @@ -14,20 +14,12 @@ namespace SixLabors.ImageSharp.Tests public static readonly byte[] Header_Random_Id_Array = { -#if !NETSTANDARD1_1 - 0x84, 0xA8, 0xD4, 0x60, 0xC7, 0x16, 0xB6, 0xF3, 0x9B, 0x0E, 0x4C, 0x3D, 0xAB, 0x95, 0xF8, 0x38, -#else - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -#endif + 0x84, 0xA8, 0xD4, 0x60, 0xC7, 0x16, 0xB6, 0xF3, 0x9B, 0x0E, 0x4C, 0x3D, 0xAB, 0x95, 0xF8, 0x38, }; public static readonly byte[] Profile_Random_Id_Array = { -#if !NETSTANDARD1_1 - 0x91, 0x7D, 0x6D, 0xE6, 0x84, 0xC9, 0x58, 0xD1, 0x3B, 0xB0, 0xF5, 0xBB, 0xAD, 0xD1, 0x13, 0x4F, -#else - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -#endif + 0x91, 0x7D, 0x6D, 0xE6, 0x84, 0xC9, 0x58, 0xD1, 0x3B, 0xB0, 0xF5, 0xBB, 0xAD, 0xD1, 0x13, 0x4F, }; public static readonly IccProfileHeader Header_Random_Write = CreateHeaderRandomValue( @@ -35,13 +27,7 @@ namespace SixLabors.ImageSharp.Tests new IccProfileId(1, 2, 3, 4), // should be overwritten "ijkl"); // should be overwritten to "acsp" - public static readonly IccProfileHeader Header_Random_Read = CreateHeaderRandomValue(132, -#if !NETSTANDARD1_1 - Header_Random_Id_Value, -#else - IccProfileId.Zero, -#endif - "acsp"); + public static readonly IccProfileHeader Header_Random_Read = CreateHeaderRandomValue(132, Header_Random_Id_Value, "acsp"); public static readonly byte[] Header_Random_Array = CreateHeaderRandomArray(132, 0, Header_Random_Id_Array); @@ -120,11 +106,7 @@ namespace SixLabors.ImageSharp.Tests ); public static readonly IccProfile Profile_Random_Val = new IccProfile(CreateHeaderRandomValue(168, -#if !NETSTANDARD1_1 Profile_Random_Id_Value, -#else - IccProfileId.Zero, -#endif "acsp"), new IccTagDataEntry[] { @@ -239,4 +221,4 @@ namespace SixLabors.ImageSharp.Tests new object[] { Header_Random_Array, true }, }; } -} +} \ No newline at end of file From 9b27fd2fe54cd2a386b1b267ca50c4c4572645e4 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 15 Oct 2018 08:54:58 -0700 Subject: [PATCH 02/10] Use static Encoding.ASCII property --- src/ImageSharp/Formats/Gif/GifConstants.cs | 2 +- src/ImageSharp/Formats/Png/PngConstants.cs | 2 +- .../MetaData/Profiles/ICC/DataReader/IccDataReader.cs | 2 +- .../MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs | 2 +- .../MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs | 2 +- tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Formats/Gif/GifConstants.cs b/src/ImageSharp/Formats/Gif/GifConstants.cs index 8167d0d2e..f8942cc3b 100644 --- a/src/ImageSharp/Formats/Gif/GifConstants.cs +++ b/src/ImageSharp/Formats/Gif/GifConstants.cs @@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// Gets the default encoding to use when reading comments. /// - public static readonly Encoding DefaultEncoding = Encoding.GetEncoding("ASCII"); + public static readonly Encoding DefaultEncoding = Encoding.ASCII; /// /// The list of mimetypes that equate to a gif. diff --git a/src/ImageSharp/Formats/Png/PngConstants.cs b/src/ImageSharp/Formats/Png/PngConstants.cs index 48c866f67..62a7b74ab 100644 --- a/src/ImageSharp/Formats/Png/PngConstants.cs +++ b/src/ImageSharp/Formats/Png/PngConstants.cs @@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Formats.Png /// /// The default encoding for text metadata. /// - public static readonly Encoding DefaultEncoding = Encoding.GetEncoding("ASCII"); + public static readonly Encoding DefaultEncoding = Encoding.ASCII; /// /// The list of mimetypes that equate to a png. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs index cc0f8f34d..f75b09ad0 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// internal sealed partial class IccDataReader { - private static readonly Encoding AsciiEncoding = Encoding.GetEncoding("ASCII"); + private static readonly Encoding AsciiEncoding = Encoding.ASCII; /// /// The data that is read diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs index cfcc66c8e..f6ce40826 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc internal sealed partial class IccDataWriter : IDisposable { private static readonly bool IsLittleEndian = BitConverter.IsLittleEndian; - private static readonly Encoding AsciiEncoding = Encoding.GetEncoding("ASCII"); + private static readonly Encoding AsciiEncoding = Encoding.ASCII; /// /// The underlying stream where the data is written to diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs index 9b24bffe8..f4704680e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// internal sealed class IccDataTagDataEntry : IccTagDataEntry, IEquatable { - private static readonly Encoding AsciiEncoding = Encoding.GetEncoding("ASCII"); + private static readonly Encoding AsciiEncoding = Encoding.ASCII; /// /// Initializes a new instance of the class. diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs index dc29b1949..2a7d69616 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png { // Needs a minimum length of 9 for pHYs chunk. memStream.Write(new byte[] { 0, 0, 0, 9 }, 0, 4); - memStream.Write(Encoding.GetEncoding("ASCII").GetBytes(chunkName), 0, 4); // 4 bytes chunk header + memStream.Write(Encoding.ASCII.GetBytes(chunkName), 0, 4); // 4 bytes chunk header memStream.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 9); // 9 bytes of chunk data memStream.Write(new byte[] { 0, 0, 0, 0 }, 0, 4); // Junk Crc } From 607d421de759ce6f9f9152c153c78f14e6b824c2 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 15 Oct 2018 09:22:27 -0700 Subject: [PATCH 03/10] Update SixLabors.Drawing minimium netststandard support to v1.3 --- src/ImageSharp.Drawing/ImageSharp.Drawing.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj index 42ef080e5..1cb3f444f 100644 --- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj +++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj @@ -5,8 +5,8 @@ $(packageversion) 0.0.1 SixLabors and contributors - netstandard1.1;netstandard2.0 - 7.2 + netstandard1.3;netstandard2.0 + 7.3 true true SixLabors.ImageSharp.Drawing From 473a7f40ab0daf27bd2da323660e5cff107e76a5 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 15 Oct 2018 09:25:11 -0700 Subject: [PATCH 04/10] Use ASCII Encoding when known to be ASCII --- src/ImageSharp/Formats/Gif/GifConstants.cs | 4 ++-- .../Formats/Jpeg/Components/Decoder/ProfileResolver.cs | 8 ++++---- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 2 +- tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ImageSharp/Formats/Gif/GifConstants.cs b/src/ImageSharp/Formats/Gif/GifConstants.cs index f8942cc3b..288c3dfa1 100644 --- a/src/ImageSharp/Formats/Gif/GifConstants.cs +++ b/src/ImageSharp/Formats/Gif/GifConstants.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// The ASCII encoded bytes used to identify the GIF file. /// - internal static readonly byte[] MagicNumber = Encoding.UTF8.GetBytes(FileType + FileVersion); + internal static readonly byte[] MagicNumber = Encoding.ASCII.GetBytes(FileType + FileVersion); /// /// The extension block introducer !. @@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Formats.Gif /// /// The ASCII encoded application identification bytes. /// - internal static readonly byte[] NetscapeApplicationIdentificationBytes = Encoding.UTF8.GetBytes(NetscapeApplicationIdentification); + internal static readonly byte[] NetscapeApplicationIdentificationBytes = Encoding.ASCII.GetBytes(NetscapeApplicationIdentification); /// /// The Netscape looping application sub block size. diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs index a6d5faaea..3e7108b15 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ProfileResolver.cs @@ -14,22 +14,22 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// /// Describes the EXIF specific markers /// - public static readonly byte[] JFifMarker = Encoding.UTF8.GetBytes("JFIF\0"); + public static readonly byte[] JFifMarker = Encoding.ASCII.GetBytes("JFIF\0"); /// /// Describes the EXIF specific markers /// - public static readonly byte[] IccMarker = Encoding.UTF8.GetBytes("ICC_PROFILE\0"); + public static readonly byte[] IccMarker = Encoding.ASCII.GetBytes("ICC_PROFILE\0"); /// /// Describes the ICC specific markers /// - public static readonly byte[] ExifMarker = Encoding.UTF8.GetBytes("Exif\0\0"); + public static readonly byte[] ExifMarker = Encoding.ASCII.GetBytes("Exif\0\0"); /// /// Describes Adobe specific markers /// - public static readonly byte[] AdobeMarker = Encoding.UTF8.GetBytes("Adobe"); + public static readonly byte[] AdobeMarker = Encoding.ASCII.GetBytes("Adobe"); /// /// Returns a value indicating whether the passed bytes are a match to the profile identifier diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 8401f4e98..d66ac6c0d 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -1005,7 +1005,7 @@ namespace SixLabors.ImageSharp.Formats.Png if (this.crc.Value != chunk.Crc) { - string chunkTypeName = Encoding.UTF8.GetString(chunkType); + string chunkTypeName = Encoding.ASCII.GetString(chunkType); throw new ImageFormatException($"CRC Error. PNG {chunkTypeName} chunk is corrupt!"); } diff --git a/tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs index 35652dd6b..e4cd06ab1 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png private static PngChunkType GetType(string text) { - return (PngChunkType)BinaryPrimitives.ReadInt32BigEndian(Encoding.UTF8.GetBytes(text)); + return (PngChunkType)BinaryPrimitives.ReadInt32BigEndian(Encoding.ASCII.GetBytes(text)); } } } \ No newline at end of file From 1e38917560d8dfd375559e5ab6eb78e98d636d16 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 15 Oct 2018 09:30:56 -0700 Subject: [PATCH 05/10] Update benchmarks to target netcoreapp2.1 --- tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index 36b7d4db4..a705c9bac 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -1,11 +1,11 @@  - netcoreapp2.0;net461 + netcoreapp2.1;net461 Exe True SixLabors.ImageSharp.Benchmarks ImageSharp.Benchmarks - 7.2 + 7.3 win7-x64 From 348229b4f2bad76a1d4fa70dbc7579d82f967d15 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 15 Oct 2018 10:10:35 -0700 Subject: [PATCH 06/10] Remove AsciiEncoding field --- .../Profiles/ICC/DataReader/IccDataReader.Primitives.cs | 2 +- .../MetaData/Profiles/ICC/DataReader/IccDataReader.cs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs index 5be0060f6..bb85a5ca3 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Primitives.cs @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc } Guard.MustBeGreaterThan(length, 0, nameof(length)); - string value = AsciiEncoding.GetString(this.data, this.AddIndex(length), length); + string value = Encoding.ASCII.GetString(this.data, this.AddIndex(length), length); // remove data after (potential) null terminator int pos = value.IndexOf('\0'); diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs index f75b09ad0..91a28fd74 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs @@ -11,8 +11,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// internal sealed partial class IccDataReader { - private static readonly Encoding AsciiEncoding = Encoding.ASCII; - /// /// The data that is read /// From 23982e896f679b24a993c972083af70618c18274 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 15 Oct 2018 16:01:51 -0700 Subject: [PATCH 07/10] Remove remaining AsciiEncoding fields --- .../Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs | 4 ++-- .../MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs | 2 -- .../Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs index a58f62519..404285b50 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs @@ -178,7 +178,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return 0; } - byte[] data = AsciiEncoding.GetBytes(value); + byte[] data = Encoding.ASCII.GetBytes(value); this.dataStream.Write(data, 0, data.Length); return data.Length; } @@ -215,7 +215,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc value = value.Substring(0, Math.Min(length - lengthAdjust, value.Length)); - byte[] textData = AsciiEncoding.GetBytes(value); + byte[] textData = Encoding.ASCII.GetBytes(value); int actualLength = Math.Min(length - lengthAdjust, textData.Length); this.dataStream.Write(textData, 0, actualLength); for (int i = 0; i < length - actualLength; i++) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs index f6ce40826..e509f67d7 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs @@ -3,7 +3,6 @@ using System; using System.IO; -using System.Text; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { @@ -13,7 +12,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc internal sealed partial class IccDataWriter : IDisposable { private static readonly bool IsLittleEndian = BitConverter.IsLittleEndian; - private static readonly Encoding AsciiEncoding = Encoding.ASCII; /// /// The underlying stream where the data is written to diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs index f4704680e..451088290 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs @@ -12,8 +12,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// internal sealed class IccDataTagDataEntry : IccTagDataEntry, IEquatable { - private static readonly Encoding AsciiEncoding = Encoding.ASCII; - /// /// Initializes a new instance of the class. /// @@ -60,7 +58,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// Gets the decoded as 7bit ASCII. /// If is false, returns null /// - public string AsciiString => this.IsAscii ? AsciiEncoding.GetString(this.Data, 0, this.Data.Length) : null; + public string AsciiString => this.IsAscii ? Encoding.ASCII.GetString(this.Data, 0, this.Data.Length) : null; /// public override bool Equals(IccTagDataEntry other) From 8eebfd1b2aa085ba5c10d2e8f1a97474353f6bcf Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 15 Oct 2018 16:04:19 -0700 Subject: [PATCH 08/10] Update README --- README.md | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/README.md b/README.md index 66dc0dcf4..3ec925b94 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Designed to democratize image processing, ImageSharp brings you an incredibly po Compared to `System.Drawing` we have been able to develop something much more flexible, easier to code against, and much, much less prone to memory leaks. Gone are system-wide process-locks; ImageSharp images are thread-safe and fully supported in web environments. -Built against .Net Standard 1.1 ImageSharp can be used in device, cloud, and embedded/IoT scenarios. +Built against .Net Standard 1.3 ImageSharp can be used in device, cloud, and embedded/IoT scenarios. ### Documentation For all SixLabors projects, including ImageSharp: @@ -83,24 +83,6 @@ using (Image image = Image.Load("foo.jpg")) image.Save("bar.jpg"); // Automatic encoder selected based on extension. } ``` -On netstandard 1.1 - 1.2 - -```csharp -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.Processing; - -// Image.Load(Stream stream) is a shortcut for our default type. -// Other pixel formats use Image.Load(Stream stream)) -using (FileStream stream = File.OpenRead("foo.jpg")) -using (FileStream output = File.OpenWrite("bar.jpg")) -using (Image image = Image.Load(stream)) -{ - image.Mutate(x => x - .Resize(image.Width / 2, image.Height / 2) - .Grayscale()); - image.Save(output); -} -``` Setting individual pixel values can be performed as follows: From 4b617ac52d2caed43b00e29f0e7ff935dafa826d Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 15 Oct 2018 16:06:41 -0700 Subject: [PATCH 09/10] Fix .NET casing --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ec925b94..a72074f8f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Designed to democratize image processing, ImageSharp brings you an incredibly po Compared to `System.Drawing` we have been able to develop something much more flexible, easier to code against, and much, much less prone to memory leaks. Gone are system-wide process-locks; ImageSharp images are thread-safe and fully supported in web environments. -Built against .Net Standard 1.3 ImageSharp can be used in device, cloud, and embedded/IoT scenarios. +Built against .NET Standard 1.3 ImageSharp can be used in device, cloud, and embedded/IoT scenarios. ### Documentation For all SixLabors projects, including ImageSharp: @@ -115,7 +115,7 @@ If you prefer, you can compile ImageSharp yourself (please do and help!) Alternatively, you can work from command line and/or with a lightweight editor on **both Linux/Unix and Windows**: - [Visual Studio Code](https://code.visualstudio.com/) with [C# Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp) -- [.Net Core](https://www.microsoft.com/net/core#linuxubuntu) +- [.NET Core](https://www.microsoft.com/net/core#linuxubuntu) To clone ImageSharp locally click the "Clone in Windows" button above or run the following git commands. From 97323c9070a70640d7a8e5acb558bca32bde591f Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 15 Oct 2018 16:07:07 -0700 Subject: [PATCH 10/10] Use BitConverter.IsLittleEndian directly This allows the JIT can optimize away the unused branch --- .../MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs index e509f67d7..21b7b6421 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs @@ -11,8 +11,6 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// internal sealed partial class IccDataWriter : IDisposable { - private static readonly bool IsLittleEndian = BitConverter.IsLittleEndian; - /// /// The underlying stream where the data is written to /// @@ -179,7 +177,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// The number of bytes written private unsafe int WriteBytes(byte* data, int length) { - if (IsLittleEndian) + if (BitConverter.IsLittleEndian) { for (int i = length - 1; i >= 0; i--) {