diff --git a/src/ImageSharp.Formats.Jpeg/Components/Decoder/Bits.cs b/src/ImageSharp.Formats.Jpeg/Components/Decoder/Bits.cs index 80787101b0..05b49f57ca 100644 --- a/src/ImageSharp.Formats.Jpeg/Components/Decoder/Bits.cs +++ b/src/ImageSharp.Formats.Jpeg/Components/Decoder/Bits.cs @@ -54,7 +54,6 @@ namespace ImageSharp.Formats.Jpg /// The number of bits to ensure. /// Jpeg decoder /// Error code - //[MethodImpl(MethodImplOptions.AggressiveInlining)] public DecoderErrorCode EnsureNBitsUnsafe(int n, JpegDecoderCore decoder) { while (true) @@ -70,8 +69,8 @@ namespace ImageSharp.Formats.Jpg /// /// Unrolled version of for n==8 /// - /// - /// + /// The + /// A public DecoderErrorCode Ensure8BitsUnsafe(JpegDecoderCore decoder) { return this.EnsureBitsStepImpl(decoder); @@ -80,36 +79,13 @@ namespace ImageSharp.Formats.Jpg /// /// Unrolled version of for n==1 /// - /// - /// + /// The + /// A public DecoderErrorCode Ensure1BitUnsafe(JpegDecoderCore decoder) { return this.EnsureBitsStepImpl(decoder); } - private DecoderErrorCode EnsureBitsStepImpl(JpegDecoderCore decoder) - { - int c; - DecoderErrorCode errorCode = decoder.Bytes.ReadByteStuffedByteUnsafe(decoder.InputStream, out c); - - if (errorCode != DecoderErrorCode.NoError) - { - return errorCode; - } - - this.Accumulator = (this.Accumulator << 8) | c; - this.UnreadBits += 8; - if (this.Mask == 0) - { - this.Mask = 1 << 7; - } - else - { - this.Mask <<= 8; - } - return errorCode; - } - /// /// Receive extend /// @@ -156,5 +132,29 @@ namespace ImageSharp.Formats.Jpg return DecoderErrorCode.NoError; } + + private DecoderErrorCode EnsureBitsStepImpl(JpegDecoderCore decoder) + { + int c; + DecoderErrorCode errorCode = decoder.Bytes.ReadByteStuffedByteUnsafe(decoder.InputStream, out c); + + if (errorCode != DecoderErrorCode.NoError) + { + return errorCode; + } + + this.Accumulator = (this.Accumulator << 8) | c; + this.UnreadBits += 8; + if (this.Mask == 0) + { + this.Mask = 1 << 7; + } + else + { + this.Mask <<= 8; + } + + return errorCode; + } } } \ No newline at end of file diff --git a/src/ImageSharp.Formats.Jpeg/Components/Decoder/Bytes.cs b/src/ImageSharp.Formats.Jpeg/Components/Decoder/Bytes.cs index 50f8fd7f02..0e57e98d89 100644 --- a/src/ImageSharp.Formats.Jpeg/Components/Decoder/Bytes.cs +++ b/src/ImageSharp.Formats.Jpeg/Components/Decoder/Bytes.cs @@ -162,7 +162,6 @@ namespace ImageSharp.Formats.Jpg /// Input stream /// The result as out parameter /// The - //[MethodImpl(MethodImplOptions.AggressiveInlining)] public DecoderErrorCode ReadByteUnsafe(Stream inputStream, out byte result) { DecoderErrorCode errorCode = DecoderErrorCode.NoError; @@ -182,6 +181,12 @@ namespace ImageSharp.Formats.Jpg return errorCode; } + /// + /// Same as but the result is an + /// + /// The input stream + /// The result + /// A [MethodImpl(MethodImplOptions.AggressiveInlining)] public DecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int result) { @@ -222,7 +227,6 @@ namespace ImageSharp.Formats.Jpg /// /// Input stream /// The - //[MethodImpl(MethodImplOptions.AggressiveInlining)] public DecoderErrorCode FillUnsafe(Stream inputStream) { if (this.I != this.J) diff --git a/src/ImageSharp.Formats.Jpeg/Components/Decoder/HuffmanTree.cs b/src/ImageSharp.Formats.Jpeg/Components/Decoder/HuffmanTree.cs index 55cf8c77f6..b563d26528 100644 --- a/src/ImageSharp.Formats.Jpeg/Components/Decoder/HuffmanTree.cs +++ b/src/ImageSharp.Formats.Jpeg/Components/Decoder/HuffmanTree.cs @@ -189,7 +189,7 @@ namespace ImageSharp.Formats.Jpg // whose codeLength's high bits matches code. // The high 8 bits of lutValue are the encoded value. // The low 8 bits are 1 plus the codeLength. - int base2 = (code << (7 - i)); + int base2 = code << (7 - i); int lutValue = (this.ValuesAsInt[x] << 8) | (2 + i); for (int k = 0; k < 1 << (7 - i); k++) @@ -226,6 +226,12 @@ namespace ImageSharp.Formats.Jpg } } + /// + /// Gets the value for the given code and index. + /// + /// The code + /// The index + /// The value public int GetValue(int code, int i) { return this.ValuesAsInt[this.Indices[i] + code - this.MinCodes[i]]; diff --git a/src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs b/src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs index cf39ad0e6e..d4cb6ffaf1 100644 --- a/src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs @@ -230,7 +230,6 @@ namespace ImageSharp.Formats { if (this.Bits.UnreadBits == 0) { - //DecoderErrorCode errorCode = this.Bits.EnsureNBitsUnsafe(1, this); DecoderErrorCode errorCode = this.Bits.Ensure1BitUnsafe(this); if (errorCode != DecoderErrorCode.NoError) { @@ -339,7 +338,6 @@ namespace ImageSharp.Formats if (this.Bits.UnreadBits < 8) { - //DecoderErrorCode errorCode = this.Bits.EnsureNBitsUnsafe(8, this); DecoderErrorCode errorCode = this.Bits.Ensure8BitsUnsafe(this); if (errorCode == DecoderErrorCode.NoError) diff --git a/src/ImageSharp.Formats.Jpeg/project.json b/src/ImageSharp.Formats.Jpeg/project.json index 9a704b4b4f..e0fdeeef25 100644 --- a/src/ImageSharp.Formats.Jpeg/project.json +++ b/src/ImageSharp.Formats.Jpeg/project.json @@ -42,10 +42,10 @@ "target": "project", "version": "1.0.0-*" }, - //"StyleCop.Analyzers": { - // "version": "1.1.0-beta001", - // "type": "build" - //}, + "StyleCop.Analyzers": { + "version": "1.1.0-beta001", + "type": "build" + }, "System.Buffers": "4.0.0", "System.Runtime.CompilerServices.Unsafe": "4.0.0" },