diff --git a/contributing.md b/.github/CONTRIBUTING.md similarity index 100% rename from contributing.md rename to .github/CONTRIBUTING.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000000..e2c1276eb8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,23 @@ +### Prerequisites + +- [ ] I have written a descriptive issue title +- [ ] I have verified that I am running the latest version of ImageSharp +- [ ] I have verified if the problem exist in both `DEBUG` and `RELEASE` mode +- [ ] I have searched [open](https://github.com/JimBobSquarePants/ImageSharp/issuess) and [closed](https://github.com/JimBobSquarePants/ImageSharp/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported + +### Description + + +### Steps to Reproduce + + +### System Configuration + + +- ImageSharp version: +- Other ImageSharp packages and versions: +- Environment (Operating system, version and so on): +- .NET Framework version: +- Additional information: + + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000000..4f87647ffc --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,11 @@ +### Prerequisites + +- [ ] I have written a descriptive pull-request title +- [ ] I have verified that there are no overlapping [pull-requests](https://github.com/JimBobSquarePants/ImageSharp/pulls) open +- [ ] I have verified that I am following matches the existing coding patterns and practise as demonstrated in the repository. These follow strict Stylecop rules :cop:. +- [ ] I have provided test coverage for my change (where applicable) + +### Description + + + diff --git a/src/ImageSharp.Drawing/project.json b/src/ImageSharp.Drawing/project.json index a73dee21b5..04a5601706 100644 --- a/src/ImageSharp.Drawing/project.json +++ b/src/ImageSharp.Drawing/project.json @@ -80,7 +80,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.0.0" + "System.Runtime": { "type": "build" } } }, "net461": { @@ -88,7 +88,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.20.0", + "System.Runtime": { "type": "build" }, "System.Numerics": "4.0.0.0", "System.Numerics.Vectors": "4.0.0.0" } diff --git a/src/ImageSharp.Formats.Bmp/project.json b/src/ImageSharp.Formats.Bmp/project.json index fe7f487e95..575e414aa1 100644 --- a/src/ImageSharp.Formats.Bmp/project.json +++ b/src/ImageSharp.Formats.Bmp/project.json @@ -76,7 +76,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.0.0" + "System.Runtime": { "type": "build" } } }, "net461": { @@ -84,7 +84,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.20.0", + "System.Runtime": { "type": "build" }, "System.Numerics": "4.0.0.0", "System.Numerics.Vectors": "4.0.0.0" } diff --git a/src/ImageSharp.Formats.Gif/project.json b/src/ImageSharp.Formats.Gif/project.json index 395ea77b8d..e12d3c733f 100644 --- a/src/ImageSharp.Formats.Gif/project.json +++ b/src/ImageSharp.Formats.Gif/project.json @@ -76,7 +76,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.0.0" + "System.Runtime": { "type": "build" } } }, "net461": { @@ -84,7 +84,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.20.0", + "System.Runtime": { "type": "build" }, "System.Numerics": "4.0.0.0", "System.Numerics.Vectors": "4.0.0.0" } diff --git a/src/ImageSharp.Formats.Jpeg/project.json b/src/ImageSharp.Formats.Jpeg/project.json index e0fdeeef25..de16f6c1ce 100644 --- a/src/ImageSharp.Formats.Jpeg/project.json +++ b/src/ImageSharp.Formats.Jpeg/project.json @@ -76,7 +76,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.0.0" + "System.Runtime": { "type": "build" } } }, "net461": { @@ -84,7 +84,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.20.0", + "System.Runtime": { "type": "build" }, "System.Numerics": "4.0.0.0", "System.Numerics.Vectors": "4.0.0.0" } diff --git a/src/ImageSharp.Formats.Png/project.json b/src/ImageSharp.Formats.Png/project.json index 17dac21713..d029f1d2f0 100644 --- a/src/ImageSharp.Formats.Png/project.json +++ b/src/ImageSharp.Formats.Png/project.json @@ -76,7 +76,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.0.0" + "System.Runtime": { "type": "build" } } }, "net461": { @@ -84,7 +84,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.20.0", + "System.Runtime": { "type": "build" }, "System.Numerics": "4.0.0.0", "System.Numerics.Vectors": "4.0.0.0" } diff --git a/src/ImageSharp.Processing/project.json b/src/ImageSharp.Processing/project.json index 9b96b53121..2ff224fa4a 100644 --- a/src/ImageSharp.Processing/project.json +++ b/src/ImageSharp.Processing/project.json @@ -76,7 +76,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.0.0" + "System.Runtime": { "type": "build" } } }, "net461": { @@ -84,7 +84,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.20.0", + "System.Runtime": { "type": "build" }, "System.Numerics": "4.0.0.0", "System.Numerics.Vectors": "4.0.0.0" } diff --git a/src/ImageSharp/project.json b/src/ImageSharp/project.json index 28cb7b4099..117d320900 100644 --- a/src/ImageSharp/project.json +++ b/src/ImageSharp/project.json @@ -72,7 +72,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.0.0" + "System.Runtime": { "type": "build" } } }, "net461": { @@ -80,7 +80,7 @@ "System.Threading.Tasks.Parallel": "4.0.0" }, "frameworkAssemblies": { - "System.Runtime": "4.0.20.0", + "System.Runtime": { "type": "build" }, "System.Numerics": "4.0.0.0", "System.Numerics.Vectors": "4.0.0.0" } diff --git a/tests/ImageSharp.Benchmarks/General/Clamp.cs b/tests/ImageSharp.Benchmarks/General/Clamp.cs index abbcb4bf1c..ae53de9d3a 100644 --- a/tests/ImageSharp.Benchmarks/General/Clamp.cs +++ b/tests/ImageSharp.Benchmarks/General/Clamp.cs @@ -6,6 +6,7 @@ namespace ImageSharp.Benchmarks.General { using System; + using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; @@ -17,24 +18,24 @@ namespace ImageSharp.Benchmarks.General [Benchmark(Baseline = true, Description = "Maths Clamp")] public byte ClampMaths() { - int value = this.Value; - return (byte)Math.Min(Math.Max(0, value), 255); + int value = this.Value; + return (byte)Math.Min(Math.Max(byte.MinValue, value), byte.MaxValue); } [Benchmark(Description = "No Maths Clamp")] public byte ClampNoMaths() { - int value = this.Value; - value = value >= 255 ? 255 : value; - return (byte)(value <= 0 ? 0 : value); + int value = this.Value; + value = value >= byte.MaxValue ? byte.MaxValue : value; + return (byte)(value <= byte.MinValue ? byte.MinValue : value); } [Benchmark(Description = "No Maths No Equals Clamp")] public byte ClampNoMathsNoEquals() { - int value = this.Value; - value = value > 255 ? 255 : value; - return (byte)(value < 0 ? 0 : value); + int value = this.Value; + value = value > byte.MaxValue ? byte.MaxValue : value; + return (byte)(value < byte.MinValue ? byte.MinValue : value); } [Benchmark(Description = "No Maths Clamp No Ternary")] @@ -42,14 +43,14 @@ namespace ImageSharp.Benchmarks.General { int value = this.Value; - if (value >= 255) + if (value >= byte.MaxValue) { - return 255; + return byte.MaxValue; } - if (value <= 0) + if (value <= byte.MinValue) { - return 0; + return byte.MinValue; } return (byte)value; @@ -58,19 +59,37 @@ namespace ImageSharp.Benchmarks.General [Benchmark(Description = "No Maths No Equals Clamp No Ternary")] public byte ClampNoMathsEqualsNoTernary() { - int value = this.Value; + int value = this.Value; - if (value > 255) - { - return 255; - } + if (value > byte.MaxValue) + { + return byte.MaxValue; + } - if (value < 0) - { - return 0; - } + if (value < byte.MinValue) + { + return byte.MinValue; + } - return (byte)value; + return (byte)value; + } + + [Benchmark(Description = "Clamp using Bitwise Abs")] + public byte ClampBitwise() + { + int x = this.Value; + int absmax = byte.MaxValue - x; + x = (x + byte.MaxValue - AbsBitwiseVer(ref absmax)) >> 1; + x = (x + byte.MinValue + AbsBitwiseVer(ref x)) >> 1; + + return (byte)x; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int AbsBitwiseVer(ref int x) + { + int y = x >> 31; + return (x ^ y) - y; } } } diff --git a/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs b/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs index 867583c7f5..b5a44d9196 100644 --- a/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs +++ b/tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs @@ -22,7 +22,7 @@ namespace ImageSharp.Benchmarks.Image { if (this.jpegBytes == null) { - this.jpegBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Jpg/Calliphora.jpg"); + this.jpegBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Jpg/Baseline/Calliphora.jpg"); } }