Browse Source

stylecopped dah stuff

af/merge-core
Anton Firszov 9 years ago
parent
commit
d049664eb7
  1. 56
      src/ImageSharp.Formats.Jpeg/Components/Decoder/Bits.cs
  2. 8
      src/ImageSharp.Formats.Jpeg/Components/Decoder/Bytes.cs
  3. 8
      src/ImageSharp.Formats.Jpeg/Components/Decoder/HuffmanTree.cs
  4. 2
      src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs
  5. 8
      src/ImageSharp.Formats.Jpeg/project.json

56
src/ImageSharp.Formats.Jpeg/Components/Decoder/Bits.cs

@ -54,7 +54,6 @@ namespace ImageSharp.Formats.Jpg
/// <param name="n">The number of bits to ensure.</param>
/// <param name="decoder">Jpeg decoder</param>
/// <returns>Error code</returns>
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
public DecoderErrorCode EnsureNBitsUnsafe(int n, JpegDecoderCore decoder)
{
while (true)
@ -70,8 +69,8 @@ namespace ImageSharp.Formats.Jpg
/// <summary>
/// Unrolled version of <see cref="EnsureNBitsUnsafe"/> for n==8
/// </summary>
/// <param name="decoder"></param>
/// <returns></returns>
/// <param name="decoder">The <see cref="JpegDecoderCore"/></param>
/// <returns>A <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode Ensure8BitsUnsafe(JpegDecoderCore decoder)
{
return this.EnsureBitsStepImpl(decoder);
@ -80,36 +79,13 @@ namespace ImageSharp.Formats.Jpg
/// <summary>
/// Unrolled version of <see cref="EnsureNBitsUnsafe"/> for n==1
/// </summary>
/// <param name="decoder"></param>
/// <returns></returns>
/// <param name="decoder">The <see cref="JpegDecoderCore"/></param>
/// <returns>A <see cref="DecoderErrorCode"/></returns>
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;
}
/// <summary>
/// Receive extend
/// </summary>
@ -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;
}
}
}

8
src/ImageSharp.Formats.Jpeg/Components/Decoder/Bytes.cs

@ -162,7 +162,6 @@ namespace ImageSharp.Formats.Jpg
/// <param name="inputStream">Input stream</param>
/// <param name="result">The result <see cref="byte"/> as out parameter</param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
//[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;
}
/// <summary>
/// Same as <see cref="ReadByteUnsafe"/> but the result is an <see cref="int"/>
/// </summary>
/// <param name="inputStream">The input stream</param>
/// <param name="result">The result <see cref="int"/></param>
/// <returns>A <see cref="DecoderErrorCode"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public DecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int result)
{
@ -222,7 +227,6 @@ namespace ImageSharp.Formats.Jpg
/// </summary>
/// <param name="inputStream">Input stream</param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
public DecoderErrorCode FillUnsafe(Stream inputStream)
{
if (this.I != this.J)

8
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
}
}
/// <summary>
/// Gets the value for the given code and index.
/// </summary>
/// <param name="code">The code</param>
/// <param name="i">The index</param>
/// <returns>The value</returns>
public int GetValue(int code, int i)
{
return this.ValuesAsInt[this.Indices[i] + code - this.MinCodes[i]];

2
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)

8
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"
},

Loading…
Cancel
Save