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/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.
//
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/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/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs
index 33b73cdd11..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;
}
///
@@ -381,7 +399,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/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..77ee17fc20 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;
///
@@ -15,27 +14,51 @@ 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
{
+ ///
+ /// 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/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 66882e4927..3991c4e0e9 100644
--- a/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs
@@ -31,21 +31,6 @@ namespace ImageSharp.Formats
///
internal const int LutSize = 8;
- ///
- /// The byte buffer.
- ///
- internal Bytes Bytes;
-
- ///
- /// 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 +101,21 @@ namespace ImageSharp.Formats
///
private readonly byte[] temp;
+ ///
+ /// The byte buffer.
+ ///
+ 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,8 +205,8 @@ 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.Bytes = Bytes.Create();
+ this.bits = default(Bits);
+ this.bytes = Bytes.Create();
// TODO: This looks like it could be static.
for (int i = 0; i < MaxTc + 1; i++)
@@ -224,10 +224,44 @@ namespace ImageSharp.Formats
///
internal enum ErrorCodes
{
+ ///
+ /// NoError
+ ///
NoError,
+
+ ///
+ /// MissingFF00
+ ///
MissingFF00
}
+ ///
+ /// Gets or sets the byte buffer.
+ ///
+ public Bytes Bytes
+ {
+ get
+ {
+ return this.bytes;
+ }
+
+ set
+ {
+ this.bytes = value;
+ }
+ }
+
+ ///
+ /// 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.
@@ -241,7 +275,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);
@@ -381,7 +415,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);
@@ -449,6 +483,9 @@ namespace ImageSharp.Formats
}
}
+ ///
+ /// Dispose
+ ///
public void Dispose()
{
for (int i = 0; i < this.huffmanTrees.Length; i++)
@@ -456,7 +493,7 @@ namespace ImageSharp.Formats
this.huffmanTrees[i].Dispose();
}
- this.Bytes.Dispose();
+ this.bytes.Dispose();
}
///
@@ -466,7 +503,7 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal byte ReadByte()
{
- return this.Bytes.ReadByte(this.InputStream);
+ return this.bytes.ReadByte(this.inputStream);
}
///
@@ -627,19 +664,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);
}
}
@@ -652,22 +689,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])
{
@@ -686,18 +723,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;
}
@@ -708,19 +745,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;
}
@@ -733,13 +770,13 @@ namespace ImageSharp.Formats
///
private void UnreadByteStuffedByte()
{
- this.Bytes.I -= this.Bytes.UnreadableBytes;
- this.Bytes.UnreadableBytes = 0;
- if (this.Bits.UnreadBits >= 8)
+ this.bytes.I -= this.bytes.UnreadableBytes;
+ this.bytes.UnreadableBytes = 0;
+ 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;
}
}
@@ -752,32 +789,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)
+ 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);
}
}
}
@@ -789,32 +826,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)
+ 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);
}
}
@@ -1478,7 +1515,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");
}
@@ -1520,7 +1557,7 @@ namespace ImageSharp.Formats
}
}
- this.Bits = default(Bits);
+ this.bits = default(Bits);
int mcu = 0;
byte expectedRst = JpegConstants.Markers.RST0;
@@ -1533,12 +1570,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);
@@ -1673,7 +1710,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];
@@ -1728,7 +1765,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;
@@ -1756,7 +1793,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);
diff --git a/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpg/JpegEncoderCore.cs
index 2ec65bc5b5..55901033c2 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.
@@ -960,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.
///
@@ -999,6 +1002,11 @@ namespace ImageSharp.Formats
code <<= 1;
}
}
+
+ ///
+ /// Gets the collection of huffman values.
+ ///
+ public uint[] Values { get; }
}
}
}
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;