Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
eee64f2
Remove SUPPORTS conditions
JimBobSquarePants Jul 23, 2022
6fc84a8
Remove other obsolete conditions and warnings
JimBobSquarePants Jul 23, 2022
ca0b284
Remove obsolete OSX transform methods
JimBobSquarePants Jul 23, 2022
3fb4787
Normalize some reference swapping
JimBobSquarePants Jul 26, 2022
3c40500
Clean up pixel blender defaults
JimBobSquarePants Jul 27, 2022
3d837b1
Update PixelBlender{TPixel}.cs
JimBobSquarePants Jul 27, 2022
606e64a
Merge branch 'main' into js/remove-obsolete-code
JimBobSquarePants Sep 2, 2022
89faddf
Fix build
JimBobSquarePants Sep 2, 2022
61299f9
PR feedback
JimBobSquarePants Sep 2, 2022
65a2ea3
Merge branch 'main' into js/remove-obsolete-code
JimBobSquarePants Sep 2, 2022
ba1adc3
Use BitOperations directly.
dlemstra Sep 3, 2022
3031400
Did not push all files....
dlemstra Sep 3, 2022
f9c9a01
Removed unused argument.
dlemstra Sep 3, 2022
1c5a78c
Removed unit tests.
dlemstra Sep 3, 2022
3a6f26d
Removed unused class.
dlemstra Sep 3, 2022
b22785e
Update editorconfig and fix all new warnings.
JimBobSquarePants Sep 6, 2022
ac84e49
Fix CA1854 for NET 7
JimBobSquarePants Sep 6, 2022
90c85c0
Cleanup and remove unused index
JimBobSquarePants Sep 6, 2022
0e46510
Use culture for NET 7
JimBobSquarePants Sep 6, 2022
e25734a
Reverse unsealing
JimBobSquarePants Sep 6, 2022
9b29319
Reverse breaking change.
JimBobSquarePants Sep 6, 2022
145dc9e
Merge branch 'main' into js/remove-obsolete-code
JimBobSquarePants Sep 9, 2022
e9049e2
Throw for unsupported App0 markers.
JimBobSquarePants Sep 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>..\ImageSharp.ruleset</CodeAnalysisRuleSet>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to only use forward slashes now because Windows now also supports that.

</PropertyGroup>

<ItemGroup>
<!-- DynamicProxyGenAssembly2 is needed so Moq can use our internals -->
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" Key="0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7" />
Expand Down
7 changes: 7 additions & 0 deletions src/ImageSharp.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="ImageSharp" ToolsVersion="17.0">
<Include Path="..\shared-infrastructure\sixlabors.ruleset" Action="Default" />
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1011" Action="None" />
</Rules>
</RuleSet>
21 changes: 6 additions & 15 deletions src/ImageSharp/ColorSpaces/Companding/SRgbCompanding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if SUPPORTS_RUNTIME_INTRINSICS
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
#endif

namespace SixLabors.ImageSharp.ColorSpaces.Companding
{
Expand All @@ -25,10 +23,10 @@ public static class SRgbCompanding
private const int Length = Scale + 2; // 256kb @ 16bit precision.
private const int Scale = (1 << 16) - 1;

private static readonly Lazy<float[]> LazyCompressTable = new Lazy<float[]>(
private static readonly Lazy<float[]> LazyCompressTable = new(
() =>
{
var result = new float[Length];
float[] result = new float[Length];

for (int i = 0; i < result.Length; i++)
{
Expand All @@ -49,10 +47,10 @@ public static class SRgbCompanding
},
true);

private static readonly Lazy<float[]> LazyExpandTable = new Lazy<float[]>(
private static readonly Lazy<float[]> LazyExpandTable = new(
() =>
{
var result = new float[Length];
float[] result = new float[Length];

for (int i = 0; i < result.Length; i++)
{
Expand Down Expand Up @@ -84,19 +82,17 @@ public static class SRgbCompanding
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Expand(Span<Vector4> vectors)
{
#if SUPPORTS_RUNTIME_INTRINSICS
if (Avx2.IsSupported && vectors.Length >= 2)
{
CompandAvx2(vectors, ExpandTable);

if (Numerics.Modulo2(vectors.Length) != 0)
{
// Vector4 fits neatly in pairs. Any overlap has to be equal to 1.
Expand(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1)));
Expand(ref MemoryMarshal.GetReference(vectors[^1..]));
Copy link
Contributor

@gfoidl gfoidl Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old version may be more performant, unfortunately. This is tracked in dotnet/roslyn#43598, and you can see the difference in this sharplab.

If it's not perf-sensitive, then got with the new code, as it's cleaner to read.
Edit: this goes through that whole PR, there are definitely some hot places where this will have negative impact.
If Roslyn tackles that issue, perf will increase "for free".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ This is so frustrating. Why introduce an analyser that promotes worse behaviour?

}
}
else
#endif
{
CompandScalar(vectors, ExpandTable);
}
Expand All @@ -109,19 +105,17 @@ public static void Expand(Span<Vector4> vectors)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void Compress(Span<Vector4> vectors)
{
#if SUPPORTS_RUNTIME_INTRINSICS
if (Avx2.IsSupported && vectors.Length >= 2)
{
CompandAvx2(vectors, CompressTable);

if (Numerics.Modulo2(vectors.Length) != 0)
{
// Vector4 fits neatly in pairs. Any overlap has to be equal to 1.
Compress(ref MemoryMarshal.GetReference(vectors.Slice(vectors.Length - 1)));
Compress(ref MemoryMarshal.GetReference(vectors[^1..]));
}
}
else
#endif
{
CompandScalar(vectors, CompressTable);
}
Expand Down Expand Up @@ -171,8 +165,6 @@ public static float Expand(float channel)
public static float Compress(float channel)
=> channel <= 0.0031308F ? 12.92F * channel : (1.055F * MathF.Pow(channel, 0.416666666666667F)) - 0.055F;

#if SUPPORTS_RUNTIME_INTRINSICS

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe void CompandAvx2(Span<Vector4> vectors, float[] table)
{
Expand Down Expand Up @@ -204,7 +196,6 @@ private static unsafe void CompandAvx2(Span<Vector4> vectors, float[] table)
}
}
}
#endif

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe void CompandScalar(Span<Vector4> vectors, float[] table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void Transform(

if (sourceWhitePoint.Equals(destinationWhitePoint))
{
source.CopyTo(destination.Slice(0, count));
source.CopyTo(destination[..count]);
return;
}

Expand Down
35 changes: 0 additions & 35 deletions src/ImageSharp/Common/Extensions/EncoderExtensions.cs

This file was deleted.

46 changes: 0 additions & 46 deletions src/ImageSharp/Common/Extensions/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,51 +70,5 @@ public static void Skip(this Stream stream, int count)
ArrayPool<byte>.Shared.Return(buffer);
}
}

#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<byte> buffer)
{
// This uses ArrayPool<byte>.Shared, rather than taking a MemoryAllocator,
// in order to match the signature of the framework method that exists in
// .NET Core.
byte[] sharedBuffer = ArrayPool<byte>.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<byte>(sharedBuffer, 0, numRead).CopyTo(buffer);
return numRead;
}
finally
{
ArrayPool<byte>.Shared.Return(sharedBuffer);
}
}

// 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<byte> buffer)
{
// This uses ArrayPool<byte>.Shared, rather than taking a MemoryAllocator,
// in order to match the signature of the framework method that exists in
// .NET Core.
byte[] sharedBuffer = ArrayPool<byte>.Shared.Rent(buffer.Length);
try
{
buffer.CopyTo(sharedBuffer);
stream.Write(sharedBuffer, 0, buffer.Length);
}
finally
{
ArrayPool<byte>.Shared.Return(sharedBuffer);
}
}
#endif
}
}
2 changes: 1 addition & 1 deletion src/ImageSharp/Common/Helpers/HexConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static int HexStringToBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
{
// Slightly better performance in the loop below, allows us to skip a bounds check
// while still supporting output buffers that are larger than necessary
bytes = bytes.Slice(0, chars.Length / 2);
bytes = bytes[..(chars.Length / 2)];
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
6 changes: 2 additions & 4 deletions src/ImageSharp/Common/Helpers/InliningOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ internal static class InliningOptions
public const MethodImplOptions AlwaysInline = MethodImplOptions.AggressiveInlining;
#if PROFILING
public const MethodImplOptions HotPath = MethodImplOptions.NoInlining;

public const MethodImplOptions ShortMethod = MethodImplOptions.NoInlining;
#else
#if SUPPORTS_HOTPATH
public const MethodImplOptions HotPath = MethodImplOptions.AggressiveOptimization;
#else
public const MethodImplOptions HotPath = MethodImplOptions.AggressiveInlining;
#endif

public const MethodImplOptions ShortMethod = MethodImplOptions.AggressiveInlining;
#endif
public const MethodImplOptions ColdPath = MethodImplOptions.NoInlining;
Expand Down
Loading