From 09f75f4ac20ddbf1da8ccbc1db93be2101931949 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 10:05:54 +0100 Subject: [PATCH 01/16] Fixing default value type constructor warnings. --- src/ImageSharp/Bootstrapper.cs | 2 +- src/ImageSharp/Common/Helpers/Guard.cs | 1 + src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs | 2 +- src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 8 ++++---- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Bootstrapper.cs b/src/ImageSharp/Bootstrapper.cs index de4bcc9389..b29c66c58b 100644 --- a/src/ImageSharp/Bootstrapper.cs +++ b/src/ImageSharp/Bootstrapper.cs @@ -71,7 +71,7 @@ namespace ImageSharp Guard.NotNullOrEmpty(format.Extension, nameof(format), "The extension should not be null or empty."); Guard.NotNullOrEmpty(format.SupportedExtensions, nameof(format), "The supported extensions not be null or empty."); - GuardDuplicate(format); + this.GuardDuplicate(format); this.imageFormats.Add(format); } diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index b67512525a..cf307e9365 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -65,6 +65,7 @@ namespace ImageSharp /// /// Verifies, that the enumeration is not null and not empty. /// + /// The type of objects in the /// The target enumeration, which should be checked against being null or empty. /// Name of the parameter. /// The error message, if any to add to the exception. diff --git a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs index 33b73cdd11..b1f0fb4581 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs @@ -381,7 +381,7 @@ namespace ImageSharp.Formats internal void Clear() { // The cheapest way to do this in C#: - this = new Block8x8F(); + this = default(Block8x8F); } /// diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index c209cde3fe..71cb4c0f68 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -1533,12 +1533,12 @@ namespace ImageSharp.Formats // blocks: the third block in the first row has (bx, by) = (2, 0). int bx, by, blockCount = 0; - Block8x8F b = new Block8x8F(); - Block8x8F temp1 = new Block8x8F(); - Block8x8F temp2 = new Block8x8F(); + Block8x8F b = default(Block8x8F); + Block8x8F temp1 = default(Block8x8F); + Block8x8F temp2 = default(Block8x8F); // Tricky way to copy contents of the Unzig static variable to the stack: - StackallocUnzigData unzigOnStack = new StackallocUnzigData(); + StackallocUnzigData unzigOnStack = default(StackallocUnzigData); int* unzigPtr = unzigOnStack.Data; Marshal.Copy(Unzig, 0, (IntPtr)unzigPtr, 64); From a13b865f6acb610e1ba9c369e7837405e3446562 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 10:44:48 +0100 Subject: [PATCH 02/16] Fixing documentation warnings. Moving MutableSpanExtensions into ints own file. --- .../Drawing/Processors/FillShapeProcessor.cs | 2 +- .../Formats/Jpg/Components/Block8x8F.cs | 52 ++++++++---- .../Formats/Jpg/Components/Bytes.cs | 9 +++ .../Formats/Jpg/Components/Huffman.cs | 9 +++ .../Formats/Jpg/Components/MutableSpan.cs | 75 ++++++++--------- .../Jpg/Components/MutableSpanExtensions.cs | 81 +++++++++++++++++++ src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 3 + 7 files changed, 171 insertions(+), 60 deletions(-) create mode 100644 src/ImageSharp/Formats/Jpg/Components/MutableSpanExtensions.cs diff --git a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs b/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs index 3209ce9c51..a1678010fc 100644 --- a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs +++ b/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs @@ -87,7 +87,7 @@ namespace ImageSharp.Drawing.Processors int offsetY = y - polyStartY; Vector2 currentPoint = default(Vector2); - Vector2 currentPointOffset = default(Vector2); + for (int x = minX; x < maxX; x++) { int offsetX = x - startX; diff --git a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs index b1f0fb4581..8b86e3bd5d 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs @@ -15,9 +15,17 @@ namespace ImageSharp.Formats /// internal partial struct Block8x8F { + /// + /// Vector count + /// public const int VectorCount = 16; + + /// + /// Scalar count + /// public const int ScalarCount = VectorCount * 4; +#pragma warning disable SA1600 // ElementsMustBeDocumented public Vector4 V0L; public Vector4 V0R; @@ -41,6 +49,7 @@ namespace ImageSharp.Formats public Vector4 V7L; public Vector4 V7R; +#pragma warning restore SA1600 // ElementsMustBeDocumented #pragma warning disable SA1310 // FieldNamesMustNotContainUnderscore private static readonly Vector4 C_1_175876 = new Vector4(1.175876f); @@ -59,6 +68,11 @@ namespace ImageSharp.Formats private static readonly Vector4 C_0_125 = new Vector4(0.1250f); #pragma warning restore SA1310 // FieldNamesMustNotContainUnderscore + /// + /// Index into the block + /// + /// The index + /// The float value at the specified index public unsafe float this[int idx] { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -143,25 +157,29 @@ namespace ImageSharp.Formats } } + /// + /// Multiply in place + /// + /// Scalar to multiply by [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void MultiplyAllInplace(Vector4 s) + public void MultiplyAllInplace(Vector4 scalar) { - this.V0L *= s; - this.V0R *= s; - this.V1L *= s; - this.V1R *= s; - this.V2L *= s; - this.V2R *= s; - this.V3L *= s; - this.V3R *= s; - this.V4L *= s; - this.V4R *= s; - this.V5L *= s; - this.V5R *= s; - this.V6L *= s; - this.V6R *= s; - this.V7L *= s; - this.V7R *= s; + this.V0L *= scalar; + this.V0R *= scalar; + this.V1L *= scalar; + this.V1R *= scalar; + this.V2L *= scalar; + this.V2R *= scalar; + this.V3L *= scalar; + this.V3R *= scalar; + this.V4L *= scalar; + this.V4R *= scalar; + this.V5L *= scalar; + this.V5R *= scalar; + this.V6L *= scalar; + this.V6R *= scalar; + this.V7L *= scalar; + this.V7R *= scalar; } /// diff --git a/src/ImageSharp/Formats/Jpg/Components/Bytes.cs b/src/ImageSharp/Formats/Jpg/Components/Bytes.cs index f848439a03..127ba478bb 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Bytes.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Bytes.cs @@ -23,8 +23,14 @@ namespace ImageSharp.Formats /// public byte[] Buffer; + /// + /// Start of bytes read + /// public int I; + /// + /// End of bytes read + /// public int J; /// @@ -44,6 +50,9 @@ namespace ImageSharp.Formats return new Bytes { Buffer = ArrayPool.Rent(4096) }; } + /// + /// Disposes of the underlying buffer + /// public void Dispose() { if (this.Buffer != null) diff --git a/src/ImageSharp/Formats/Jpg/Components/Huffman.cs b/src/ImageSharp/Formats/Jpg/Components/Huffman.cs index 74f77f3033..c0d5a5caad 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Huffman.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Huffman.cs @@ -53,6 +53,12 @@ namespace ImageSharp.Formats private static readonly ArrayPool IntBuffer = ArrayPool.Create(JpegDecoderCore.MaxCodeLength, 50); + /// + /// Initializes the Huffman tree + /// + /// Lut size + /// Max N codes + /// Max code length public void Init(int lutSize, int maxNCodes, int maxCodeLength) { this.Lut = UshortBuffer.Rent(1 << lutSize); @@ -62,6 +68,9 @@ namespace ImageSharp.Formats this.Indices = IntBuffer.Rent(maxCodeLength); } + /// + /// Disposes the underlying buffers + /// public void Dispose() { UshortBuffer.Return(this.Lut, true); diff --git a/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs b/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs index 4b48998495..c43e73614d 100644 --- a/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs +++ b/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs @@ -5,7 +5,6 @@ namespace ImageSharp.Formats { - using System.Numerics; using System.Runtime.CompilerServices; /// @@ -18,24 +17,48 @@ namespace ImageSharp.Formats /// internal struct MutableSpan { + /// + /// Data + /// public T[] Data; + /// + /// Offset + /// public int Offset; + /// + /// Initializes a new instance of the struct. + /// + /// The size of the span + /// The offset (defaults to 0) public MutableSpan(int size, int offset = 0) { this.Data = new T[size]; this.Offset = offset; } + /// + /// Initializes a new instance of the struct. + /// + /// The data + /// The offset (defaults to 0) public MutableSpan(T[] data, int offset = 0) { this.Data = data; this.Offset = offset; } + /// + /// Gets the total count of data + /// public int TotalCount => this.Data.Length - this.Offset; + /// + /// Index into the data + /// + /// The data + /// The value at the specified index public T this[int idx] { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -53,57 +76,25 @@ namespace ImageSharp.Formats public static implicit operator MutableSpan(T[] data) => new MutableSpan(data, 0); + /// + /// Slice the data + /// + /// The offset + /// The new [MethodImpl(MethodImplOptions.AggressiveInlining)] public MutableSpan Slice(int offset) { return new MutableSpan(this.Data, this.Offset + offset); } + /// + /// Add to the offset + /// + /// The additional offset [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddOffset(int offset) { this.Offset += offset; } } - - internal static class MutableSpanExtensions - { - public static MutableSpan Slice(this T[] array, int offset) => new MutableSpan(array, offset); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void SaveTo(this MutableSpan data, ref Vector4 v) - { - v.X = data[0]; - v.Y = data[1]; - v.Z = data[2]; - v.W = data[3]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void SaveTo(this MutableSpan data, ref Vector4 v) - { - v.X = data[0]; - v.Y = data[1]; - v.Z = data[2]; - v.W = data[3]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void LoadFrom(this MutableSpan data, ref Vector4 v) - { - data[0] = v.X; - data[1] = v.Y; - data[2] = v.Z; - data[3] = v.W; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void LoadFrom(this MutableSpan data, ref Vector4 v) - { - data[0] = (int)v.X; - data[1] = (int)v.Y; - data[2] = (int)v.Z; - data[3] = (int)v.W; - } - } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpg/Components/MutableSpanExtensions.cs b/src/ImageSharp/Formats/Jpg/Components/MutableSpanExtensions.cs new file mode 100644 index 0000000000..42edcd3c4a --- /dev/null +++ b/src/ImageSharp/Formats/Jpg/Components/MutableSpanExtensions.cs @@ -0,0 +1,81 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Formats.Jpg.Components +{ + using System.Numerics; + using System.Runtime.CompilerServices; + + /// + /// MutableSpan Extensions + /// + internal static class MutableSpanExtensions + { + /// + /// Slice + /// + /// The type of the data in the span + /// The data array + /// The offset + /// The new + public static MutableSpan Slice(this T[] array, int offset) => new MutableSpan(array, offset); + + /// + /// Save to a Vector4 + /// + /// The data + /// The vector to save to + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void SaveTo(this MutableSpan data, ref Vector4 v) + { + v.X = data[0]; + v.Y = data[1]; + v.Z = data[2]; + v.W = data[3]; + } + + /// + /// Save to a Vector4 + /// + /// The data + /// The vector to save to + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void SaveTo(this MutableSpan data, ref Vector4 v) + { + v.X = data[0]; + v.Y = data[1]; + v.Z = data[2]; + v.W = data[3]; + } + + /// + /// Load from Vector4 + /// + /// The data + /// The vector to load from + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void LoadFrom(this MutableSpan data, ref Vector4 v) + { + data[0] = v.X; + data[1] = v.Y; + data[2] = v.Z; + data[3] = v.W; + } + + /// + /// Load from Vector4 + /// + /// The data + /// The vector to load from + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void LoadFrom(this MutableSpan data, ref Vector4 v) + { + data[0] = (int)v.X; + data[1] = (int)v.Y; + data[2] = (int)v.Z; + data[3] = (int)v.W; + } + } +} diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 71cb4c0f68..8ce3e1be7d 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -449,6 +449,9 @@ namespace ImageSharp.Formats } } + /// + /// Dispose + /// public void Dispose() { for (int i = 0; i < this.huffmanTrees.Length; i++) From 330de98c264faf328002ba85286c70e4bd1a6a1b Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 10:49:15 +0100 Subject: [PATCH 03/16] Adding documentation to enums. --- .../Formats/Jpg/Components/MutableSpan.cs | 2 +- .../Formats/Jpg/Components/YCbCrImage.cs | 18 ++++++++++++++++++ src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs b/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs index c43e73614d..77ee17fc20 100644 --- a/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs +++ b/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs @@ -14,7 +14,7 @@ namespace ImageSharp.Formats /// /// https://github.com/dotnet/corefxlab/blob/master/src/System.Slices/System/Span.cs /// - /// + /// The type of the data in the span internal struct MutableSpan { /// diff --git a/src/ImageSharp/Formats/Jpg/Components/YCbCrImage.cs b/src/ImageSharp/Formats/Jpg/Components/YCbCrImage.cs index 564da379b2..603324bcc7 100644 --- a/src/ImageSharp/Formats/Jpg/Components/YCbCrImage.cs +++ b/src/ImageSharp/Formats/Jpg/Components/YCbCrImage.cs @@ -44,16 +44,34 @@ namespace ImageSharp.Formats /// public enum YCbCrSubsampleRatio { + /// + /// YCbCrSubsampleRatio444 + /// YCbCrSubsampleRatio444, + /// + /// YCbCrSubsampleRatio422 + /// YCbCrSubsampleRatio422, + /// + /// YCbCrSubsampleRatio420 + /// YCbCrSubsampleRatio420, + /// + /// YCbCrSubsampleRatio440 + /// YCbCrSubsampleRatio440, + /// + /// YCbCrSubsampleRatio411 + /// YCbCrSubsampleRatio411, + /// + /// YCbCrSubsampleRatio410 + /// YCbCrSubsampleRatio410, } diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 8ce3e1be7d..28bec0d926 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -224,7 +224,14 @@ namespace ImageSharp.Formats /// internal enum ErrorCodes { + /// + /// NoError + /// NoError, + + /// + /// MissingFF00 + /// MissingFF00 } From de43c8be39db0cd763efa8bfbd559cef321f88a5 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 11:02:22 +0100 Subject: [PATCH 04/16] Fixing multiple lines warnings. --- src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 4 ++-- src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 28bec0d926..2d6e3ee7c7 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -388,7 +388,7 @@ namespace ImageSharp.Formats this.ProcessApp14Marker(remaining); break; default: - if ((JpegConstants.Markers.APP0 <= marker && marker <= JpegConstants.Markers.APP15) + if ((marker >= JpegConstants.Markers.APP0 && marker <= JpegConstants.Markers.APP15) || marker == JpegConstants.Markers.COM) { this.Skip(remaining); @@ -1488,7 +1488,7 @@ namespace ImageSharp.Formats ah = this.temp[3 + scanComponentCountX2] >> 4; al = this.temp[3 + scanComponentCountX2] & 0x0f; - if ((zigStart == 0 && zigEnd != 0) || zigStart > zigEnd || BlockF.BlockSize <= zigEnd) + if ((zigStart == 0 && zigEnd != 0) || zigStart > zigEnd || zigEnd >= BlockF.BlockSize) { throw new ImageFormatException("Bad spectral selection bounds"); } diff --git a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs index 2ec65bc5b5..3144fdbd34 100644 --- a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs @@ -31,6 +31,7 @@ namespace ImageSharp.Formats 39, 46, 53, 60, 61, 54, 47, 55, 62, 63, }; +#pragma warning disable SA1118 // ParameterMustNotSpanMultipleLines /// /// The Huffman encoding specifications. /// This encoder uses the same Huffman encoding for all images. @@ -43,7 +44,10 @@ namespace ImageSharp.Formats { 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }), + new byte[] + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + }), new HuffmanSpec( new byte[] { @@ -75,7 +79,10 @@ namespace ImageSharp.Formats { 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }, - new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }), + new byte[] + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + }), // Chrominance AC. new HuffmanSpec( @@ -105,6 +112,7 @@ namespace ImageSharp.Formats 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa }) }; +#pragma warning restore SA1118 // ParameterMustNotSpanMultipleLines /// /// The compiled representations of theHuffmanSpec. From c074b63a49737ee905619cc58543ff53fdde2747 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 14:32:26 +0100 Subject: [PATCH 05/16] Renaming files with generic types to match {T} pattern. --- .../Brushes/{Brushes`2.cs => Brushes{TColor,TPacked}.cs} | 2 +- .../Brushes/{ImageBrush`2.cs => ImageBrush{TColor,TPacked}.cs} | 2 +- .../{PatternBrush`2.cs => PatternBrush{TColor,TPacked}.cs} | 2 +- .../Brushes/{SolidBrush`2.cs => SolidBrush{TColor,TPacked}.cs} | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/ImageSharp/Drawing/Brushes/{Brushes`2.cs => Brushes{TColor,TPacked}.cs} (98%) rename src/ImageSharp/Drawing/Brushes/{ImageBrush`2.cs => ImageBrush{TColor,TPacked}.cs} (97%) rename src/ImageSharp/Drawing/Brushes/{PatternBrush`2.cs => PatternBrush{TColor,TPacked}.cs} (98%) rename src/ImageSharp/Drawing/Brushes/{SolidBrush`2.cs => SolidBrush{TColor,TPacked}.cs} (96%) diff --git a/src/ImageSharp/Drawing/Brushes/Brushes`2.cs b/src/ImageSharp/Drawing/Brushes/Brushes{TColor,TPacked}.cs similarity index 98% rename from src/ImageSharp/Drawing/Brushes/Brushes`2.cs rename to src/ImageSharp/Drawing/Brushes/Brushes{TColor,TPacked}.cs index 2e2eb5ad30..8bb2c698b7 100644 --- a/src/ImageSharp/Drawing/Brushes/Brushes`2.cs +++ b/src/ImageSharp/Drawing/Brushes/Brushes{TColor,TPacked}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageSharp/Drawing/Brushes/ImageBrush`2.cs b/src/ImageSharp/Drawing/Brushes/ImageBrush{TColor,TPacked}.cs similarity index 97% rename from src/ImageSharp/Drawing/Brushes/ImageBrush`2.cs rename to src/ImageSharp/Drawing/Brushes/ImageBrush{TColor,TPacked}.cs index 19e0591a90..9fcb11038b 100644 --- a/src/ImageSharp/Drawing/Brushes/ImageBrush`2.cs +++ b/src/ImageSharp/Drawing/Brushes/ImageBrush{TColor,TPacked}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageSharp/Drawing/Brushes/PatternBrush`2.cs b/src/ImageSharp/Drawing/Brushes/PatternBrush{TColor,TPacked}.cs similarity index 98% rename from src/ImageSharp/Drawing/Brushes/PatternBrush`2.cs rename to src/ImageSharp/Drawing/Brushes/PatternBrush{TColor,TPacked}.cs index cdbdf23ad2..9d18342d98 100644 --- a/src/ImageSharp/Drawing/Brushes/PatternBrush`2.cs +++ b/src/ImageSharp/Drawing/Brushes/PatternBrush{TColor,TPacked}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageSharp/Drawing/Brushes/SolidBrush`2.cs b/src/ImageSharp/Drawing/Brushes/SolidBrush{TColor,TPacked}.cs similarity index 96% rename from src/ImageSharp/Drawing/Brushes/SolidBrush`2.cs rename to src/ImageSharp/Drawing/Brushes/SolidBrush{TColor,TPacked}.cs index f882d59b35..351373b232 100644 --- a/src/ImageSharp/Drawing/Brushes/SolidBrush`2.cs +++ b/src/ImageSharp/Drawing/Brushes/SolidBrush{TColor,TPacked}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // From c07cd223de33508d231f448b0a75b16ce527bacd Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 14:33:18 +0100 Subject: [PATCH 06/16] Removing unused variables in test. --- tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs index b620c1d19f..cee236adfa 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs @@ -56,11 +56,9 @@ namespace ImageSharp.Tests.Formats.Jpg float a0, a1, a2, a3, b0, b1, b2, b3; float z0, z1, z2, z3, z4; - float r0 = 1.414214f; float r1 = 1.387040f; float r2 = 1.306563f; float r3 = 1.175876f; - float r4 = 1.000000f; float r5 = 0.785695f; float r6 = 0.541196f; float r7 = 0.275899f; From 895437db3571c121f49cbdcf44e858b9dbc6be13 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 10:05:54 +0100 Subject: [PATCH 07/16] Fixing default value type constructor warnings. --- src/ImageSharp/Common/Helpers/Guard.cs | 1 + src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs | 2 +- src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index b67512525a..cf307e9365 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -65,6 +65,7 @@ namespace ImageSharp /// /// Verifies, that the enumeration is not null and not empty. /// + /// The type of objects in the /// The target enumeration, which should be checked against being null or empty. /// Name of the parameter. /// The error message, if any to add to the exception. diff --git a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs index 33b73cdd11..b1f0fb4581 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs @@ -381,7 +381,7 @@ namespace ImageSharp.Formats internal void Clear() { // The cheapest way to do this in C#: - this = new Block8x8F(); + this = default(Block8x8F); } /// diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 66882e4927..d93a12464d 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -1533,12 +1533,12 @@ namespace ImageSharp.Formats // blocks: the third block in the first row has (bx, by) = (2, 0). int bx, by, blockCount = 0; - Block8x8F b = new Block8x8F(); - Block8x8F temp1 = new Block8x8F(); - Block8x8F temp2 = new Block8x8F(); + Block8x8F b = default(Block8x8F); + Block8x8F temp1 = default(Block8x8F); + Block8x8F temp2 = default(Block8x8F); // Tricky way to copy contents of the Unzig static variable to the stack: - StackallocUnzigData unzigOnStack = new StackallocUnzigData(); + StackallocUnzigData unzigOnStack = default(StackallocUnzigData); int* unzigPtr = unzigOnStack.Data; Marshal.Copy(Unzig, 0, (IntPtr)unzigPtr, 64); From 229954a641ec4a5951bb5cd1441ff0c65d03f0c0 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 10:44:48 +0100 Subject: [PATCH 08/16] Fixing documentation warnings. Moving MutableSpanExtensions into ints own file. --- .../Drawing/Processors/FillShapeProcessor.cs | 2 +- .../Formats/Jpg/Components/Block8x8F.cs | 52 ++++++++---- .../Formats/Jpg/Components/Bytes.cs | 9 +++ .../Formats/Jpg/Components/Huffman.cs | 9 +++ .../Formats/Jpg/Components/MutableSpan.cs | 75 ++++++++--------- .../Jpg/Components/MutableSpanExtensions.cs | 81 +++++++++++++++++++ src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 3 + 7 files changed, 171 insertions(+), 60 deletions(-) create mode 100644 src/ImageSharp/Formats/Jpg/Components/MutableSpanExtensions.cs diff --git a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs b/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs index 62f0481d43..f44ec56f7d 100644 --- a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs +++ b/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs @@ -88,7 +88,7 @@ namespace ImageSharp.Drawing.Processors int offsetY = y - polyStartY; Vector2 currentPoint = default(Vector2); - Vector2 currentPointOffset = default(Vector2); + for (int x = minX; x < maxX; x++) { int offsetX = x - startX; diff --git a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs index b1f0fb4581..8b86e3bd5d 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs @@ -15,9 +15,17 @@ namespace ImageSharp.Formats /// internal partial struct Block8x8F { + /// + /// Vector count + /// public const int VectorCount = 16; + + /// + /// Scalar count + /// public const int ScalarCount = VectorCount * 4; +#pragma warning disable SA1600 // ElementsMustBeDocumented public Vector4 V0L; public Vector4 V0R; @@ -41,6 +49,7 @@ namespace ImageSharp.Formats public Vector4 V7L; public Vector4 V7R; +#pragma warning restore SA1600 // ElementsMustBeDocumented #pragma warning disable SA1310 // FieldNamesMustNotContainUnderscore private static readonly Vector4 C_1_175876 = new Vector4(1.175876f); @@ -59,6 +68,11 @@ namespace ImageSharp.Formats private static readonly Vector4 C_0_125 = new Vector4(0.1250f); #pragma warning restore SA1310 // FieldNamesMustNotContainUnderscore + /// + /// Index into the block + /// + /// The index + /// The float value at the specified index public unsafe float this[int idx] { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -143,25 +157,29 @@ namespace ImageSharp.Formats } } + /// + /// Multiply in place + /// + /// Scalar to multiply by [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void MultiplyAllInplace(Vector4 s) + public void MultiplyAllInplace(Vector4 scalar) { - this.V0L *= s; - this.V0R *= s; - this.V1L *= s; - this.V1R *= s; - this.V2L *= s; - this.V2R *= s; - this.V3L *= s; - this.V3R *= s; - this.V4L *= s; - this.V4R *= s; - this.V5L *= s; - this.V5R *= s; - this.V6L *= s; - this.V6R *= s; - this.V7L *= s; - this.V7R *= s; + this.V0L *= scalar; + this.V0R *= scalar; + this.V1L *= scalar; + this.V1R *= scalar; + this.V2L *= scalar; + this.V2R *= scalar; + this.V3L *= scalar; + this.V3R *= scalar; + this.V4L *= scalar; + this.V4R *= scalar; + this.V5L *= scalar; + this.V5R *= scalar; + this.V6L *= scalar; + this.V6R *= scalar; + this.V7L *= scalar; + this.V7R *= scalar; } /// diff --git a/src/ImageSharp/Formats/Jpg/Components/Bytes.cs b/src/ImageSharp/Formats/Jpg/Components/Bytes.cs index f848439a03..127ba478bb 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Bytes.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Bytes.cs @@ -23,8 +23,14 @@ namespace ImageSharp.Formats /// public byte[] Buffer; + /// + /// Start of bytes read + /// public int I; + /// + /// End of bytes read + /// public int J; /// @@ -44,6 +50,9 @@ namespace ImageSharp.Formats return new Bytes { Buffer = ArrayPool.Rent(4096) }; } + /// + /// Disposes of the underlying buffer + /// public void Dispose() { if (this.Buffer != null) diff --git a/src/ImageSharp/Formats/Jpg/Components/Huffman.cs b/src/ImageSharp/Formats/Jpg/Components/Huffman.cs index 74f77f3033..c0d5a5caad 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Huffman.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Huffman.cs @@ -53,6 +53,12 @@ namespace ImageSharp.Formats private static readonly ArrayPool IntBuffer = ArrayPool.Create(JpegDecoderCore.MaxCodeLength, 50); + /// + /// Initializes the Huffman tree + /// + /// Lut size + /// Max N codes + /// Max code length public void Init(int lutSize, int maxNCodes, int maxCodeLength) { this.Lut = UshortBuffer.Rent(1 << lutSize); @@ -62,6 +68,9 @@ namespace ImageSharp.Formats this.Indices = IntBuffer.Rent(maxCodeLength); } + /// + /// Disposes the underlying buffers + /// public void Dispose() { UshortBuffer.Return(this.Lut, true); diff --git a/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs b/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs index 4b48998495..c43e73614d 100644 --- a/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs +++ b/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs @@ -5,7 +5,6 @@ namespace ImageSharp.Formats { - using System.Numerics; using System.Runtime.CompilerServices; /// @@ -18,24 +17,48 @@ namespace ImageSharp.Formats /// internal struct MutableSpan { + /// + /// Data + /// public T[] Data; + /// + /// Offset + /// public int Offset; + /// + /// Initializes a new instance of the struct. + /// + /// The size of the span + /// The offset (defaults to 0) public MutableSpan(int size, int offset = 0) { this.Data = new T[size]; this.Offset = offset; } + /// + /// Initializes a new instance of the struct. + /// + /// The data + /// The offset (defaults to 0) public MutableSpan(T[] data, int offset = 0) { this.Data = data; this.Offset = offset; } + /// + /// Gets the total count of data + /// public int TotalCount => this.Data.Length - this.Offset; + /// + /// Index into the data + /// + /// The data + /// The value at the specified index public T this[int idx] { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -53,57 +76,25 @@ namespace ImageSharp.Formats public static implicit operator MutableSpan(T[] data) => new MutableSpan(data, 0); + /// + /// Slice the data + /// + /// The offset + /// The new [MethodImpl(MethodImplOptions.AggressiveInlining)] public MutableSpan Slice(int offset) { return new MutableSpan(this.Data, this.Offset + offset); } + /// + /// Add to the offset + /// + /// The additional offset [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddOffset(int offset) { this.Offset += offset; } } - - internal static class MutableSpanExtensions - { - public static MutableSpan Slice(this T[] array, int offset) => new MutableSpan(array, offset); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void SaveTo(this MutableSpan data, ref Vector4 v) - { - v.X = data[0]; - v.Y = data[1]; - v.Z = data[2]; - v.W = data[3]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void SaveTo(this MutableSpan data, ref Vector4 v) - { - v.X = data[0]; - v.Y = data[1]; - v.Z = data[2]; - v.W = data[3]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void LoadFrom(this MutableSpan data, ref Vector4 v) - { - data[0] = v.X; - data[1] = v.Y; - data[2] = v.Z; - data[3] = v.W; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void LoadFrom(this MutableSpan data, ref Vector4 v) - { - data[0] = (int)v.X; - data[1] = (int)v.Y; - data[2] = (int)v.Z; - data[3] = (int)v.W; - } - } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpg/Components/MutableSpanExtensions.cs b/src/ImageSharp/Formats/Jpg/Components/MutableSpanExtensions.cs new file mode 100644 index 0000000000..42edcd3c4a --- /dev/null +++ b/src/ImageSharp/Formats/Jpg/Components/MutableSpanExtensions.cs @@ -0,0 +1,81 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Formats.Jpg.Components +{ + using System.Numerics; + using System.Runtime.CompilerServices; + + /// + /// MutableSpan Extensions + /// + internal static class MutableSpanExtensions + { + /// + /// Slice + /// + /// The type of the data in the span + /// The data array + /// The offset + /// The new + public static MutableSpan Slice(this T[] array, int offset) => new MutableSpan(array, offset); + + /// + /// Save to a Vector4 + /// + /// The data + /// The vector to save to + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void SaveTo(this MutableSpan data, ref Vector4 v) + { + v.X = data[0]; + v.Y = data[1]; + v.Z = data[2]; + v.W = data[3]; + } + + /// + /// Save to a Vector4 + /// + /// The data + /// The vector to save to + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void SaveTo(this MutableSpan data, ref Vector4 v) + { + v.X = data[0]; + v.Y = data[1]; + v.Z = data[2]; + v.W = data[3]; + } + + /// + /// Load from Vector4 + /// + /// The data + /// The vector to load from + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void LoadFrom(this MutableSpan data, ref Vector4 v) + { + data[0] = v.X; + data[1] = v.Y; + data[2] = v.Z; + data[3] = v.W; + } + + /// + /// Load from Vector4 + /// + /// The data + /// The vector to load from + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void LoadFrom(this MutableSpan data, ref Vector4 v) + { + data[0] = (int)v.X; + data[1] = (int)v.Y; + data[2] = (int)v.Z; + data[3] = (int)v.W; + } + } +} diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index d93a12464d..1fe2225304 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -449,6 +449,9 @@ namespace ImageSharp.Formats } } + /// + /// Dispose + /// public void Dispose() { for (int i = 0; i < this.huffmanTrees.Length; i++) From 4ba2adfdfb2bcf1e9534d2e6a0d65fe92903350c Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 10:49:15 +0100 Subject: [PATCH 09/16] Adding documentation to enums. --- .../Formats/Jpg/Components/MutableSpan.cs | 2 +- .../Formats/Jpg/Components/YCbCrImage.cs | 18 ++++++++++++++++++ src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs b/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs index c43e73614d..77ee17fc20 100644 --- a/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs +++ b/src/ImageSharp/Formats/Jpg/Components/MutableSpan.cs @@ -14,7 +14,7 @@ namespace ImageSharp.Formats /// /// https://github.com/dotnet/corefxlab/blob/master/src/System.Slices/System/Span.cs /// - /// + /// The type of the data in the span internal struct MutableSpan { /// diff --git a/src/ImageSharp/Formats/Jpg/Components/YCbCrImage.cs b/src/ImageSharp/Formats/Jpg/Components/YCbCrImage.cs index 564da379b2..603324bcc7 100644 --- a/src/ImageSharp/Formats/Jpg/Components/YCbCrImage.cs +++ b/src/ImageSharp/Formats/Jpg/Components/YCbCrImage.cs @@ -44,16 +44,34 @@ namespace ImageSharp.Formats /// public enum YCbCrSubsampleRatio { + /// + /// YCbCrSubsampleRatio444 + /// YCbCrSubsampleRatio444, + /// + /// YCbCrSubsampleRatio422 + /// YCbCrSubsampleRatio422, + /// + /// YCbCrSubsampleRatio420 + /// YCbCrSubsampleRatio420, + /// + /// YCbCrSubsampleRatio440 + /// YCbCrSubsampleRatio440, + /// + /// YCbCrSubsampleRatio411 + /// YCbCrSubsampleRatio411, + /// + /// YCbCrSubsampleRatio410 + /// YCbCrSubsampleRatio410, } diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 1fe2225304..fe606bbb48 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -224,7 +224,14 @@ namespace ImageSharp.Formats /// internal enum ErrorCodes { + /// + /// NoError + /// NoError, + + /// + /// MissingFF00 + /// MissingFF00 } From bdab0fbf4619da18108a61ed1a8dc0dace4f0b5b Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 11:02:22 +0100 Subject: [PATCH 10/16] Fixing multiple lines warnings. --- src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 4 ++-- src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index fe606bbb48..1a36923e59 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -388,7 +388,7 @@ namespace ImageSharp.Formats this.ProcessApp14Marker(remaining); break; default: - if ((JpegConstants.Markers.APP0 <= marker && marker <= JpegConstants.Markers.APP15) + if ((marker >= JpegConstants.Markers.APP0 && marker <= JpegConstants.Markers.APP15) || marker == JpegConstants.Markers.COM) { this.Skip(remaining); @@ -1488,7 +1488,7 @@ namespace ImageSharp.Formats ah = this.temp[3 + scanComponentCountX2] >> 4; al = this.temp[3 + scanComponentCountX2] & 0x0f; - if ((zigStart == 0 && zigEnd != 0) || zigStart > zigEnd || BlockF.BlockSize <= zigEnd) + if ((zigStart == 0 && zigEnd != 0) || zigStart > zigEnd || zigEnd >= BlockF.BlockSize) { throw new ImageFormatException("Bad spectral selection bounds"); } diff --git a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs index 2ec65bc5b5..3144fdbd34 100644 --- a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs @@ -31,6 +31,7 @@ namespace ImageSharp.Formats 39, 46, 53, 60, 61, 54, 47, 55, 62, 63, }; +#pragma warning disable SA1118 // ParameterMustNotSpanMultipleLines /// /// The Huffman encoding specifications. /// This encoder uses the same Huffman encoding for all images. @@ -43,7 +44,10 @@ namespace ImageSharp.Formats { 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }, - new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }), + new byte[] + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + }), new HuffmanSpec( new byte[] { @@ -75,7 +79,10 @@ namespace ImageSharp.Formats { 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }, - new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }), + new byte[] + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + }), // Chrominance AC. new HuffmanSpec( @@ -105,6 +112,7 @@ namespace ImageSharp.Formats 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa }) }; +#pragma warning restore SA1118 // ParameterMustNotSpanMultipleLines /// /// The compiled representations of theHuffmanSpec. From c6ad2bcdbf11afb61d726d7b1639bd2a662fecb7 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 14:32:26 +0100 Subject: [PATCH 11/16] Renaming files with generic types to match {T} pattern. --- .../Brushes/{Brushes`2.cs => Brushes{TColor,TPacked}.cs} | 2 +- .../Brushes/{ImageBrush`2.cs => ImageBrush{TColor,TPacked}.cs} | 2 +- .../{PatternBrush`2.cs => PatternBrush{TColor,TPacked}.cs} | 2 +- .../Brushes/{SolidBrush`2.cs => SolidBrush{TColor,TPacked}.cs} | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/ImageSharp/Drawing/Brushes/{Brushes`2.cs => Brushes{TColor,TPacked}.cs} (98%) rename src/ImageSharp/Drawing/Brushes/{ImageBrush`2.cs => ImageBrush{TColor,TPacked}.cs} (97%) rename src/ImageSharp/Drawing/Brushes/{PatternBrush`2.cs => PatternBrush{TColor,TPacked}.cs} (98%) rename src/ImageSharp/Drawing/Brushes/{SolidBrush`2.cs => SolidBrush{TColor,TPacked}.cs} (96%) diff --git a/src/ImageSharp/Drawing/Brushes/Brushes`2.cs b/src/ImageSharp/Drawing/Brushes/Brushes{TColor,TPacked}.cs similarity index 98% rename from src/ImageSharp/Drawing/Brushes/Brushes`2.cs rename to src/ImageSharp/Drawing/Brushes/Brushes{TColor,TPacked}.cs index 2e2eb5ad30..8bb2c698b7 100644 --- a/src/ImageSharp/Drawing/Brushes/Brushes`2.cs +++ b/src/ImageSharp/Drawing/Brushes/Brushes{TColor,TPacked}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageSharp/Drawing/Brushes/ImageBrush`2.cs b/src/ImageSharp/Drawing/Brushes/ImageBrush{TColor,TPacked}.cs similarity index 97% rename from src/ImageSharp/Drawing/Brushes/ImageBrush`2.cs rename to src/ImageSharp/Drawing/Brushes/ImageBrush{TColor,TPacked}.cs index 19e0591a90..9fcb11038b 100644 --- a/src/ImageSharp/Drawing/Brushes/ImageBrush`2.cs +++ b/src/ImageSharp/Drawing/Brushes/ImageBrush{TColor,TPacked}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageSharp/Drawing/Brushes/PatternBrush`2.cs b/src/ImageSharp/Drawing/Brushes/PatternBrush{TColor,TPacked}.cs similarity index 98% rename from src/ImageSharp/Drawing/Brushes/PatternBrush`2.cs rename to src/ImageSharp/Drawing/Brushes/PatternBrush{TColor,TPacked}.cs index cdbdf23ad2..9d18342d98 100644 --- a/src/ImageSharp/Drawing/Brushes/PatternBrush`2.cs +++ b/src/ImageSharp/Drawing/Brushes/PatternBrush{TColor,TPacked}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageSharp/Drawing/Brushes/SolidBrush`2.cs b/src/ImageSharp/Drawing/Brushes/SolidBrush{TColor,TPacked}.cs similarity index 96% rename from src/ImageSharp/Drawing/Brushes/SolidBrush`2.cs rename to src/ImageSharp/Drawing/Brushes/SolidBrush{TColor,TPacked}.cs index f882d59b35..351373b232 100644 --- a/src/ImageSharp/Drawing/Brushes/SolidBrush`2.cs +++ b/src/ImageSharp/Drawing/Brushes/SolidBrush{TColor,TPacked}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // From e905ed6ce731a79710ddc7917cbd24b93adf74c4 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 14:33:18 +0100 Subject: [PATCH 12/16] Removing unused variables in test. --- tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs index b620c1d19f..cee236adfa 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs @@ -56,11 +56,9 @@ namespace ImageSharp.Tests.Formats.Jpg float a0, a1, a2, a3, b0, b1, b2, b3; float z0, z1, z2, z3, z4; - float r0 = 1.414214f; float r1 = 1.387040f; float r2 = 1.306563f; float r3 = 1.175876f; - float r4 = 1.000000f; float r5 = 0.785695f; float r6 = 0.541196f; float r7 = 0.275899f; From 371780cc082b79998df7b557fc3e892f82eb2e64 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 15:01:23 +0100 Subject: [PATCH 13/16] Changing decoder bytes to private field. --- src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 1a36923e59..6ac586e2e4 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -31,11 +31,6 @@ namespace ImageSharp.Formats /// internal const int LutSize = 8; - /// - /// The byte buffer. - /// - internal Bytes Bytes; - /// /// The input stream. /// @@ -116,6 +111,11 @@ namespace ImageSharp.Formats /// private readonly byte[] temp; + /// + /// The byte buffer. + /// + private Bytes bytes; + /// /// The image width /// @@ -206,7 +206,7 @@ namespace ImageSharp.Formats this.componentArray = new Component[MaxComponents]; this.progCoeffs = new Block8x8F[MaxComponents][]; this.Bits = default(Bits); - this.Bytes = Bytes.Create(); + this.bytes = Bytes.Create(); // TODO: This looks like it could be static. for (int i = 0; i < MaxTc + 1; i++) @@ -235,6 +235,17 @@ namespace ImageSharp.Formats MissingFF00 } + /// + /// Gets the byte buffer. + /// + public Bytes Bytes + { + get + { + return this.bytes; + } + } + /// /// Decodes the image from the specified this._stream and sets /// the data to image. @@ -466,7 +477,7 @@ namespace ImageSharp.Formats this.huffmanTrees[i].Dispose(); } - this.Bytes.Dispose(); + this.bytes.Dispose(); } /// @@ -476,7 +487,7 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] internal byte ReadByte() { - return this.Bytes.ReadByte(this.InputStream); + return this.bytes.ReadByte(this.InputStream); } /// @@ -743,8 +754,8 @@ namespace ImageSharp.Formats /// private void UnreadByteStuffedByte() { - this.Bytes.I -= this.Bytes.UnreadableBytes; - this.Bytes.UnreadableBytes = 0; + this.bytes.I -= this.bytes.UnreadableBytes; + this.bytes.UnreadableBytes = 0; if (this.Bits.UnreadBits >= 8) { this.Bits.Accumulator >>= 8; @@ -762,32 +773,32 @@ namespace ImageSharp.Formats private void ReadFull(byte[] data, int offset, int length) { // Unread the overshot bytes, if any. - if (this.Bytes.UnreadableBytes != 0) + if (this.bytes.UnreadableBytes != 0) { if (this.Bits.UnreadBits >= 8) { this.UnreadByteStuffedByte(); } - this.Bytes.UnreadableBytes = 0; + this.bytes.UnreadableBytes = 0; } while (length > 0) { - if (this.Bytes.J - this.Bytes.I >= length) + if (this.bytes.J - this.bytes.I >= length) { - Array.Copy(this.Bytes.Buffer, this.Bytes.I, data, offset, length); - this.Bytes.I += length; + Array.Copy(this.bytes.Buffer, this.bytes.I, data, offset, length); + this.bytes.I += length; length -= length; } else { - Array.Copy(this.Bytes.Buffer, this.Bytes.I, data, offset, this.Bytes.J - this.Bytes.I); - offset += this.Bytes.J - this.Bytes.I; - length -= this.Bytes.J - this.Bytes.I; - this.Bytes.I += this.Bytes.J - this.Bytes.I; + Array.Copy(this.bytes.Buffer, this.bytes.I, data, offset, this.bytes.J - this.bytes.I); + offset += this.bytes.J - this.bytes.I; + length -= this.bytes.J - this.bytes.I; + this.bytes.I += this.bytes.J - this.bytes.I; - this.Bytes.Fill(this.InputStream); + this.bytes.Fill(this.InputStream); } } } @@ -799,32 +810,32 @@ namespace ImageSharp.Formats private void Skip(int count) { // Unread the overshot bytes, if any. - if (this.Bytes.UnreadableBytes != 0) + if (this.bytes.UnreadableBytes != 0) { if (this.Bits.UnreadBits >= 8) { this.UnreadByteStuffedByte(); } - this.Bytes.UnreadableBytes = 0; + this.bytes.UnreadableBytes = 0; } while (true) { - int m = this.Bytes.J - this.Bytes.I; + int m = this.bytes.J - this.bytes.I; if (m > count) { m = count; } - this.Bytes.I += m; + this.bytes.I += m; count -= m; if (count == 0) { break; } - this.Bytes.Fill(this.InputStream); + this.bytes.Fill(this.InputStream); } } From f510331bd730b9f22be57d505b9e58323e26fb58 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 15:06:55 +0100 Subject: [PATCH 14/16] Changing InputStream and Bits to private fields. --- src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 101 ++++++++++-------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 6ac586e2e4..90c0050960 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -31,16 +31,6 @@ namespace ImageSharp.Formats /// internal const int LutSize = 8; - /// - /// The input stream. - /// - internal Stream InputStream; - - /// - /// Holds the unprocessed bits that have been taken from the byte-stream. - /// - internal Bits Bits; - /// /// The maximum number of color components /// @@ -116,6 +106,16 @@ namespace ImageSharp.Formats /// private Bytes bytes; + /// + /// The byte buffer. + /// + private Stream inputStream; + + /// + /// Holds the unprocessed bits that have been taken from the byte-stream. + /// + private Bits bits; + /// /// The image width /// @@ -205,7 +205,7 @@ namespace ImageSharp.Formats this.temp = new byte[2 * BlockF.BlockSize]; this.componentArray = new Component[MaxComponents]; this.progCoeffs = new Block8x8F[MaxComponents][]; - this.Bits = default(Bits); + this.bits = default(Bits); this.bytes = Bytes.Create(); // TODO: This looks like it could be static. @@ -246,6 +246,17 @@ namespace ImageSharp.Formats } } + /// + /// Gets the input stream. + /// + public Stream InputStream + { + get + { + return this.inputStream; + } + } + /// /// Decodes the image from the specified this._stream and sets /// the data to image. @@ -259,7 +270,7 @@ namespace ImageSharp.Formats where TColor : struct, IPackedPixel where TPacked : struct, IEquatable { - this.InputStream = stream; + this.inputStream = stream; // Check for the Start Of Image marker. this.ReadFull(this.temp, 0, 2); @@ -487,7 +498,7 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] internal byte ReadByte() { - return this.bytes.ReadByte(this.InputStream); + return this.bytes.ReadByte(this.inputStream); } /// @@ -648,19 +659,19 @@ namespace ImageSharp.Formats throw new ImageFormatException("Uninitialized Huffman table"); } - if (this.Bits.UnreadBits < 8) + if (this.bits.UnreadBits < 8) { - var errorCode = this.Bits.EnsureNBits(8, this); + var errorCode = this.bits.EnsureNBits(8, this); if (errorCode == ErrorCodes.NoError) { - ushort v = huffman.Lut[(this.Bits.Accumulator >> (this.Bits.UnreadBits - LutSize)) & 0xff]; + ushort v = huffman.Lut[(this.bits.Accumulator >> (this.bits.UnreadBits - LutSize)) & 0xff]; if (v != 0) { byte n = (byte)((v & 0xff) - 1); - this.Bits.UnreadBits -= n; - this.Bits.Mask >>= n; + this.bits.UnreadBits -= n; + this.bits.Mask >>= n; return (byte)(v >> 8); } } @@ -673,22 +684,22 @@ namespace ImageSharp.Formats int code = 0; for (int i = 0; i < MaxCodeLength; i++) { - if (this.Bits.UnreadBits == 0) + if (this.bits.UnreadBits == 0) { - var errorCode = this.Bits.EnsureNBits(1, this); + var errorCode = this.bits.EnsureNBits(1, this); if (errorCode != ErrorCodes.NoError) { throw new MissingFF00Exception(); } } - if ((this.Bits.Accumulator & this.Bits.Mask) != 0) + if ((this.bits.Accumulator & this.bits.Mask) != 0) { code |= 1; } - this.Bits.UnreadBits--; - this.Bits.Mask >>= 1; + this.bits.UnreadBits--; + this.bits.Mask >>= 1; if (code <= huffman.MaxCodes[i]) { @@ -707,18 +718,18 @@ namespace ImageSharp.Formats /// The private bool DecodeBit() { - if (this.Bits.UnreadBits == 0) + if (this.bits.UnreadBits == 0) { - var errorCode = this.Bits.EnsureNBits(1, this); + var errorCode = this.bits.EnsureNBits(1, this); if (errorCode != ErrorCodes.NoError) { throw new MissingFF00Exception(); } } - bool ret = (this.Bits.Accumulator & this.Bits.Mask) != 0; - this.Bits.UnreadBits--; - this.Bits.Mask >>= 1; + bool ret = (this.bits.Accumulator & this.bits.Mask) != 0; + this.bits.UnreadBits--; + this.bits.Mask >>= 1; return ret; } @@ -729,19 +740,19 @@ namespace ImageSharp.Formats /// The private uint DecodeBits(int count) { - if (this.Bits.UnreadBits < count) + if (this.bits.UnreadBits < count) { - var errorCode = this.Bits.EnsureNBits(count, this); + var errorCode = this.bits.EnsureNBits(count, this); if (errorCode != ErrorCodes.NoError) { throw new MissingFF00Exception(); } } - uint ret = this.Bits.Accumulator >> (this.Bits.UnreadBits - count); + uint ret = this.bits.Accumulator >> (this.bits.UnreadBits - count); ret = (uint)(ret & ((1 << count) - 1)); - this.Bits.UnreadBits -= count; - this.Bits.Mask >>= count; + this.bits.UnreadBits -= count; + this.bits.Mask >>= count; return ret; } @@ -756,11 +767,11 @@ namespace ImageSharp.Formats { this.bytes.I -= this.bytes.UnreadableBytes; this.bytes.UnreadableBytes = 0; - if (this.Bits.UnreadBits >= 8) + if (this.bits.UnreadBits >= 8) { - this.Bits.Accumulator >>= 8; - this.Bits.UnreadBits -= 8; - this.Bits.Mask >>= 8; + this.bits.Accumulator >>= 8; + this.bits.UnreadBits -= 8; + this.bits.Mask >>= 8; } } @@ -775,7 +786,7 @@ namespace ImageSharp.Formats // Unread the overshot bytes, if any. if (this.bytes.UnreadableBytes != 0) { - if (this.Bits.UnreadBits >= 8) + if (this.bits.UnreadBits >= 8) { this.UnreadByteStuffedByte(); } @@ -798,7 +809,7 @@ namespace ImageSharp.Formats length -= this.bytes.J - this.bytes.I; this.bytes.I += this.bytes.J - this.bytes.I; - this.bytes.Fill(this.InputStream); + this.bytes.Fill(this.inputStream); } } } @@ -812,7 +823,7 @@ namespace ImageSharp.Formats // Unread the overshot bytes, if any. if (this.bytes.UnreadableBytes != 0) { - if (this.Bits.UnreadBits >= 8) + if (this.bits.UnreadBits >= 8) { this.UnreadByteStuffedByte(); } @@ -835,7 +846,7 @@ namespace ImageSharp.Formats break; } - this.bytes.Fill(this.InputStream); + this.bytes.Fill(this.inputStream); } } @@ -1541,7 +1552,7 @@ namespace ImageSharp.Formats } } - this.Bits = default(Bits); + this.bits = default(Bits); int mcu = 0; byte expectedRst = JpegConstants.Markers.RST0; @@ -1694,7 +1705,7 @@ namespace ImageSharp.Formats } // Reset the Huffman decoder. - this.Bits = default(Bits); + this.bits = default(Bits); // Reset the DC components, as per section F.2.1.3.1. dc = new int[MaxComponents]; @@ -1749,7 +1760,7 @@ namespace ImageSharp.Formats throw new ImageFormatException("Excessive DC component"); } - int deltaDC = this.Bits.ReceiveExtend(value, this); + int deltaDC = this.bits.ReceiveExtend(value, this); dc[compIndex] += deltaDC; // b[0] = dc[compIndex] << al; @@ -1777,7 +1788,7 @@ namespace ImageSharp.Formats break; } - int ac = this.Bits.ReceiveExtend(val1, this); + int ac = this.bits.ReceiveExtend(val1, this); // b[Unzig[zig]] = ac << al; Block8x8F.SetScalarAt(b, unzigPtr[zig], ac << al); From 467f3f34079c885c90a59402faa6cd3797ef46e4 Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 15:11:53 +0100 Subject: [PATCH 15/16] Fixing Values inside HuffmanLut. --- src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs index 3144fdbd34..55901033c2 100644 --- a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs @@ -968,11 +968,6 @@ namespace ImageSharp.Formats /// private class HuffmanLut { - /// - /// The collection of huffman values. - /// - public readonly uint[] Values; - /// /// Initializes a new instance of the class. /// @@ -1007,6 +1002,11 @@ namespace ImageSharp.Formats code <<= 1; } } + + /// + /// Gets the collection of huffman values. + /// + public uint[] Values { get; } } } } From fb9103aeafc27d56ded7049842dabdb220fc3bdb Mon Sep 17 00:00:00 2001 From: Olivia Date: Mon, 19 Dec 2016 16:23:42 +0100 Subject: [PATCH 16/16] Fixing bytes struct reference issue. --- src/ImageSharp/Formats/Jpg/Components/Bits.cs | 6 +++++- src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Formats/Jpg/Components/Bits.cs b/src/ImageSharp/Formats/Jpg/Components/Bits.cs index 0eebef1321..d7449f4a3b 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Bits.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Bits.cs @@ -45,7 +45,11 @@ namespace ImageSharp.Formats { JpegDecoderCore.ErrorCodes errorCode; - byte c = decoder.Bytes.ReadByteStuffedByte(decoder.InputStream, out errorCode); + // Grab the decode bytes, use them and then set them + // back on the decoder. + var decoderBytes = decoder.Bytes; + byte c = decoderBytes.ReadByteStuffedByte(decoder.InputStream, out errorCode); + decoder.Bytes = decoderBytes; if (errorCode != JpegDecoderCore.ErrorCodes.NoError) { diff --git a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs index 90c0050960..3991c4e0e9 100644 --- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs @@ -236,7 +236,7 @@ namespace ImageSharp.Formats } /// - /// Gets the byte buffer. + /// Gets or sets the byte buffer. /// public Bytes Bytes { @@ -244,6 +244,11 @@ namespace ImageSharp.Formats { return this.bytes; } + + set + { + this.bytes = value; + } } ///