Browse Source

Merge branch 'master' into af/extend-bulk-conversion

pull/751/head
Anton Firszov 7 years ago
parent
commit
ea745d8ee1
  1. 4
      appveyor.yml
  2. 4
      src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs
  3. 4
      src/ImageSharp/Common/Helpers/SimdUtils.cs
  4. 6
      src/ImageSharp/Common/Helpers/TestHelpers.cs
  5. 13
      src/ImageSharp/ImageSharp.csproj
  6. 13
      src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
  7. 20
      src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs
  8. 4
      src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs
  9. 18
      src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs
  10. 3
      src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs
  11. 4
      src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs
  12. 6
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs
  13. 2
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  14. 4
      tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.PrimitivesTests.cs
  15. 4
      tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccReaderTests.cs
  16. 2
      tests/ImageSharp.Tests/RunExtendedTests.cmd

4
appveyor.yml

@ -12,10 +12,10 @@ environment:
- target_framework: netcoreapp2.1 - target_framework: netcoreapp2.1
is_32bit: True is_32bit: True
- target_framework: net471 - target_framework: net472
is_32bit: False is_32bit: False
- target_framework: net471 - target_framework: net472
is_32bit: True is_32bit: True
- target_framework: net462 - target_framework: net462

4
src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs

@ -1,5 +1,4 @@
using System; using System;
using System.Diagnostics;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -20,8 +19,7 @@ namespace SixLabors.ImageSharp
public static class ExtendedIntrinsics public static class ExtendedIntrinsics
{ {
public static bool IsAvailable { get; } = public static bool IsAvailable { get; } =
#if NETCOREAPP2_1 #if SUPPORTS_EXTENDED_INTRINSICS
// TODO: Also available in .NET 4.7.2, we need to add a build target!
Vector.IsHardwareAccelerated; Vector.IsHardwareAccelerated;
#else #else
false; false;

4
src/ImageSharp/Common/Helpers/SimdUtils.cs

@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp
{ {
DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!"); DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!");
#if NETCOREAPP2_1 #if SUPPORTS_EXTENDED_INTRINSICS
ExtendedIntrinsics.BulkConvertByteToNormalizedFloatReduce(ref source, ref dest); ExtendedIntrinsics.BulkConvertByteToNormalizedFloatReduce(ref source, ref dest);
#else #else
BasicIntrinsics256.BulkConvertByteToNormalizedFloatReduce(ref source, ref dest); BasicIntrinsics256.BulkConvertByteToNormalizedFloatReduce(ref source, ref dest);
@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp
{ {
DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!"); DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!");
#if NETCOREAPP2_1 #if SUPPORTS_EXTENDED_INTRINSICS
ExtendedIntrinsics.BulkConvertNormalizedFloatToByteClampOverflowsReduce(ref source, ref dest); ExtendedIntrinsics.BulkConvertNormalizedFloatToByteClampOverflowsReduce(ref source, ref dest);
#else #else
BasicIntrinsics256.BulkConvertNormalizedFloatToByteClampOverflowsReduce(ref source, ref dest); BasicIntrinsics256.BulkConvertNormalizedFloatToByteClampOverflowsReduce(ref source, ref dest);

6
src/ImageSharp/Common/Helpers/TestHelpers.cs

@ -13,8 +13,12 @@ namespace SixLabors.ImageSharp.Common.Helpers
/// Only intended to be used in tests! /// Only intended to be used in tests!
/// </summary> /// </summary>
internal const string ImageSharpBuiltAgainst = internal const string ImageSharpBuiltAgainst =
#if NETCOREAPP2_1 #if NET472
"netfx4.7.2";
#elif NETCOREAPP2_1
"netcoreapp2.1"; "netcoreapp2.1";
#elif NETSTANDARD1_3
"netstandard1.3";
#else #else
"netstandard2.0"; "netstandard2.0";
#endif #endif

13
src/ImageSharp/ImageSharp.csproj

@ -5,7 +5,7 @@
<VersionPrefix Condition="$(packageversion) != ''">$(packageversion)</VersionPrefix> <VersionPrefix Condition="$(packageversion) != ''">$(packageversion)</VersionPrefix>
<VersionPrefix Condition="$(packageversion) == ''">0.0.1</VersionPrefix> <VersionPrefix Condition="$(packageversion) == ''">0.0.1</VersionPrefix>
<Authors>Six Labors and contributors</Authors> <Authors>Six Labors and contributors</Authors>
<TargetFrameworks>netstandard1.3;netstandard2.0;netcoreapp2.1</TargetFrameworks> <TargetFrameworks>netstandard1.3;netstandard2.0;netcoreapp2.1;net472</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>SixLabors.ImageSharp</AssemblyName> <AssemblyName>SixLabors.ImageSharp</AssemblyName>
@ -31,9 +31,15 @@
<Features>IOperation</Features> <Features>IOperation</Features>
<LangVersion>Latest</LangVersion> <LangVersion>Latest</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'net472' ">
<DefineConstants>$(DefineConstants);SUPPORTS_EXTENDED_INTRINSICS</DefineConstants>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\Shared\*.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" /> <Compile Include="..\Shared\*.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.1" /> <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.1" />
<PackageReference Include="SixLabors.Core" Version="1.0.0-beta0006" /> <PackageReference Include="SixLabors.Core" Version="1.0.0-beta0006" />
@ -43,15 +49,14 @@
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.IO.UnmanagedMemoryStream" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3'"> <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.IO.UnmanagedMemoryStream" Version="4.3.0" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" /> <PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="System.Threading.Tasks.Parallel" Version="4.3.0" /> <PackageReference Include="System.Threading.Tasks.Parallel" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" /> <PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>
<CodeAnalysisRuleSet>..\..\ImageSharp.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>..\..\ImageSharp.ruleset</CodeAnalysisRuleSet>
<RootNamespace>SixLabors.ImageSharp</RootNamespace> <RootNamespace>SixLabors.ImageSharp</RootNamespace>

13
src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
{ {
this.Parts = ExifParts.All; this.Parts = ExifParts.All;
this.data = data; this.data = data;
this.InvalidTags = new List<ExifTag>(); this.InvalidTags = Array.Empty<ExifTag>();
} }
/// <summary> /// <summary>
@ -63,7 +63,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
this.Parts = other.Parts; this.Parts = other.Parts;
this.thumbnailLength = other.thumbnailLength; this.thumbnailLength = other.thumbnailLength;
this.thumbnailOffset = other.thumbnailOffset; this.thumbnailOffset = other.thumbnailOffset;
this.InvalidTags = new List<ExifTag>(other.InvalidTags);
this.InvalidTags = other.InvalidTags.Count > 0
? new List<ExifTag>(other.InvalidTags)
: (IReadOnlyList<ExifTag>)Array.Empty<ExifTag>();
if (other.values != null) if (other.values != null)
{ {
this.values = new List<ExifValue>(other.Values.Count); this.values = new List<ExifValue>(other.Values.Count);
@ -289,7 +293,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
this.values = reader.ReadValues(); this.values = reader.ReadValues();
this.InvalidTags = new List<ExifTag>(reader.InvalidTags); this.InvalidTags = reader.InvalidTags.Count > 0
? new List<ExifTag>(reader.InvalidTags)
: (IReadOnlyList<ExifTag>)Array.Empty<ExifTag>();
this.thumbnailOffset = (int)reader.ThumbnailOffset; this.thumbnailOffset = (int)reader.ThumbnailOffset;
this.thumbnailLength = (int)reader.ThumbnailLength; this.thumbnailLength = (int)reader.ThumbnailLength;
} }

20
src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs

@ -7,7 +7,6 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Primitives;
@ -19,7 +18,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
/// </summary> /// </summary>
internal sealed class ExifReader internal sealed class ExifReader
{ {
private readonly List<ExifTag> invalidTags = new List<ExifTag>(); private List<ExifTag> invalidTags;
private readonly byte[] exifData; private readonly byte[] exifData;
private int position; private int position;
private Endianness endianness = Endianness.BigEndian; private Endianness endianness = Endianness.BigEndian;
@ -38,7 +37,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
/// <summary> /// <summary>
/// Gets the invalid tags. /// Gets the invalid tags.
/// </summary> /// </summary>
public IReadOnlyList<ExifTag> InvalidTags => this.invalidTags; public IReadOnlyList<ExifTag> InvalidTags => this.invalidTags ?? (IReadOnlyList<ExifTag>)Array.Empty<ExifTag>();
/// <summary> /// <summary>
/// Gets the thumbnail length in the byte stream /// Gets the thumbnail length in the byte stream
@ -338,7 +337,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
// Ensure that the new index does not overrun the data // Ensure that the new index does not overrun the data
if (newIndex > int.MaxValue) if (newIndex > int.MaxValue)
{ {
this.invalidTags.Add(tag); this.AddInvalidTag(tag);
exifValue = default; exifValue = default;
@ -349,7 +348,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
if (this.RemainingLength < size) if (this.RemainingLength < size)
{ {
this.invalidTags.Add(tag); this.AddInvalidTag(tag);
this.position = oldIndex; this.position = oldIndex;
exifValue = default; exifValue = default;
@ -372,6 +372,16 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
return true; return true;
} }
private void AddInvalidTag(ExifTag tag)
{
if (this.invalidTags == null)
{
this.invalidTags = new List<ExifTag>();
}
this.invalidTags.Add(tag);
}
private TEnum ToEnum<TEnum>(int value, TEnum defaultValue) private TEnum ToEnum<TEnum>(int value, TEnum defaultValue)
where TEnum : struct where TEnum : struct
{ {

4
src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs

@ -17,8 +17,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
/// <summary> /// <summary>
/// Which parts will be written. /// Which parts will be written.
/// </summary> /// </summary>
private ExifParts allowedParts; private readonly ExifParts allowedParts;
private IList<ExifValue> values; private readonly IList<ExifValue> values;
private List<int> dataOffsets; private List<int> dataOffsets;
private readonly List<int> ifdIndexes; private readonly List<int> ifdIndexes;
private readonly List<int> exifIndexes; private readonly List<int> exifIndexes;

18
src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Collections.Generic;
using System.Security.Cryptography; using System.Security.Cryptography;
namespace SixLabors.ImageSharp.MetaData.Profiles.Icc namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
@ -20,7 +19,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary> /// <summary>
/// The backing file for the <see cref="Entries"/> property /// The backing file for the <see cref="Entries"/> property
/// </summary> /// </summary>
private List<IccTagDataEntry> entries; private IccTagDataEntry[] entries;
/// <summary> /// <summary>
/// ICC profile header /// ICC profile header
@ -46,13 +45,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// </summary> /// </summary>
/// <param name="header">The profile header</param> /// <param name="header">The profile header</param>
/// <param name="entries">The actual profile data</param> /// <param name="entries">The actual profile data</param>
internal IccProfile(IccProfileHeader header, IEnumerable<IccTagDataEntry> entries) internal IccProfile(IccProfileHeader header, IccTagDataEntry[] entries)
{ {
Guard.NotNull(header, nameof(header)); this.header = header ?? throw new ArgumentNullException(nameof(header));
Guard.NotNull(entries, nameof(entries)); this.entries = entries ?? throw new ArgumentNullException(nameof(entries));
this.header = header;
this.entries = new List<IccTagDataEntry>(entries);
} }
/// <summary> /// <summary>
@ -85,7 +81,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary> /// <summary>
/// Gets the actual profile data /// Gets the actual profile data
/// </summary> /// </summary>
public List<IccTagDataEntry> Entries public IccTagDataEntry[] Entries
{ {
get get
{ {
@ -212,12 +208,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
if (this.data is null) if (this.data is null)
{ {
this.entries = new List<IccTagDataEntry>(); this.entries = Array.Empty<IccTagDataEntry>();
return; return;
} }
var reader = new IccReader(); var reader = new IccReader();
this.entries = new List<IccTagDataEntry>(reader.ReadTagData(this.data)); this.entries = reader.ReadTagData(this.data);
} }
} }
} }

3
src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SixLabors.ImageSharp.MetaData.Profiles.Icc namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
@ -126,7 +127,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
// A normal profile usually has 5-15 entries // A normal profile usually has 5-15 entries
if (tagCount > 100) if (tagCount > 100)
{ {
return new IccTagTableEntry[0]; return Array.Empty<IccTagTableEntry>();
} }
var table = new List<IccTagTableEntry>((int)tagCount); var table = new List<IccTagTableEntry>((int)tagCount);

4
src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs

@ -68,12 +68,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
} }
} }
private IccTagTableEntry[] WriteTagData(IccDataWriter writer, List<IccTagDataEntry> entries) private IccTagTableEntry[] WriteTagData(IccDataWriter writer, IccTagDataEntry[] entries)
{ {
IEnumerable<IGrouping<IccTagDataEntry, IccTagDataEntry>> grouped = entries.GroupBy(t => t); IEnumerable<IGrouping<IccTagDataEntry, IccTagDataEntry>> grouped = entries.GroupBy(t => t);
// (Header size) + (entry count) + (nr of entries) * (size of table entry) // (Header size) + (entry count) + (nr of entries) * (size of table entry)
writer.SetIndex(128 + 4 + (entries.Count * 12)); writer.SetIndex(128 + 4 + (entries.Length * 12));
var table = new List<IccTagTableEntry>(); var table = new List<IccTagTableEntry>();
foreach (IGrouping<IccTagDataEntry, IccTagDataEntry> group in grouped) foreach (IGrouping<IccTagDataEntry, IccTagDataEntry> group in grouped)

6
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs

@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// Initializes a new instance of the <see cref="IccCurveTagDataEntry"/> class. /// Initializes a new instance of the <see cref="IccCurveTagDataEntry"/> class.
/// </summary> /// </summary>
public IccCurveTagDataEntry() public IccCurveTagDataEntry()
: this(new float[0], IccProfileTag.Unknown) : this(Array.Empty<float>(), IccProfileTag.Unknown)
{ {
} }
@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// </summary> /// </summary>
/// <param name="tagSignature">Tag Signature</param> /// <param name="tagSignature">Tag Signature</param>
public IccCurveTagDataEntry(IccProfileTag tagSignature) public IccCurveTagDataEntry(IccProfileTag tagSignature)
: this(new float[0], tagSignature) : this(Array.Empty<float>(), tagSignature)
{ {
} }
@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
public IccCurveTagDataEntry(float[] curveData, IccProfileTag tagSignature) public IccCurveTagDataEntry(float[] curveData, IccProfileTag tagSignature)
: base(IccTypeSignature.Curve, tagSignature) : base(IccTypeSignature.Curve, tagSignature)
{ {
this.CurveData = curveData ?? new float[0]; this.CurveData = curveData ?? Array.Empty<float>();
} }
/// <summary> /// <summary>

2
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net462;net471;netcoreapp2.1</TargetFrameworks> <TargetFrameworks>net462;net472;netcoreapp2.1</TargetFrameworks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<DebugType Condition="$(codecov) != ''">full</DebugType> <DebugType Condition="$(codecov) != ''">full</DebugType>

4
tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.PrimitivesTests.cs

@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.Tests.Icc
byte[] output = writer.GetData(); byte[] output = writer.GetData();
Assert.Equal(0, count); Assert.Equal(0, count);
Assert.Equal(new byte[0], output); Assert.Equal(Array.Empty<byte>(), output);
} }
[Fact] [Fact]
@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests.Icc
byte[] output = writer.GetData(); byte[] output = writer.GetData();
Assert.Equal(0, count); Assert.Equal(0, count);
Assert.Equal(new byte[0], output); Assert.Equal(Array.Empty<byte>(), output);
} }
[Theory] [Theory]

4
tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccReaderTests.cs

@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Tests.Icc
IccProfile output = reader.Read(IccTestDataProfiles.Header_Random_Array); IccProfile output = reader.Read(IccTestDataProfiles.Header_Random_Array);
Assert.Equal(0, output.Entries.Count); Assert.Equal(0, output.Entries.Length);
Assert.NotNull(output.Header); Assert.NotNull(output.Header);
IccProfileHeader header = output.Header; IccProfileHeader header = output.Header;
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Tests.Icc
IccProfile output = reader.Read(IccTestDataProfiles.Profile_Random_Array); IccProfile output = reader.Read(IccTestDataProfiles.Profile_Random_Array);
Assert.Equal(2, output.Entries.Count); Assert.Equal(2, output.Entries.Length);
Assert.True(ReferenceEquals(output.Entries[0], output.Entries[1])); Assert.True(ReferenceEquals(output.Entries[0], output.Entries[1]));
} }

2
tests/ImageSharp.Tests/RunExtendedTests.cmd

@ -5,3 +5,5 @@ dotnet xunit -nobuild -c Release -f net47
dotnet xunit -nobuild -c Release -f net47 -x86 dotnet xunit -nobuild -c Release -f net47 -x86
dotnet xunit -nobuild -c Release -f net471 dotnet xunit -nobuild -c Release -f net471
dotnet xunit -nobuild -c Release -f net471 -x86 dotnet xunit -nobuild -c Release -f net471 -x86
dotnet xunit -nobuild -c Release -f net472
dotnet xunit -nobuild -c Release -f net472 -x86

Loading…
Cancel
Save