Browse Source

Changing decoder bytes to private field.

pull/49/head
Olivia 10 years ago
parent
commit
371780cc08
  1. 61
      src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs

61
src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs

@ -31,11 +31,6 @@ namespace ImageSharp.Formats
/// </summary> /// </summary>
internal const int LutSize = 8; internal const int LutSize = 8;
/// <summary>
/// The byte buffer.
/// </summary>
internal Bytes Bytes;
/// <summary> /// <summary>
/// The input stream. /// The input stream.
/// </summary> /// </summary>
@ -116,6 +111,11 @@ namespace ImageSharp.Formats
/// </summary> /// </summary>
private readonly byte[] temp; private readonly byte[] temp;
/// <summary>
/// The byte buffer.
/// </summary>
private Bytes bytes;
/// <summary> /// <summary>
/// The image width /// The image width
/// </summary> /// </summary>
@ -206,7 +206,7 @@ namespace ImageSharp.Formats
this.componentArray = new Component[MaxComponents]; this.componentArray = new Component[MaxComponents];
this.progCoeffs = new Block8x8F[MaxComponents][]; this.progCoeffs = new Block8x8F[MaxComponents][];
this.Bits = default(Bits); this.Bits = default(Bits);
this.Bytes = Bytes.Create(); this.bytes = Bytes.Create();
// TODO: This looks like it could be static. // TODO: This looks like it could be static.
for (int i = 0; i < MaxTc + 1; i++) for (int i = 0; i < MaxTc + 1; i++)
@ -235,6 +235,17 @@ namespace ImageSharp.Formats
MissingFF00 MissingFF00
} }
/// <summary>
/// Gets the byte buffer.
/// </summary>
public Bytes Bytes
{
get
{
return this.bytes;
}
}
/// <summary> /// <summary>
/// Decodes the image from the specified this._stream and sets /// Decodes the image from the specified this._stream and sets
/// the data to image. /// the data to image.
@ -466,7 +477,7 @@ namespace ImageSharp.Formats
this.huffmanTrees[i].Dispose(); this.huffmanTrees[i].Dispose();
} }
this.Bytes.Dispose(); this.bytes.Dispose();
} }
/// <summary> /// <summary>
@ -476,7 +487,7 @@ namespace ImageSharp.Formats
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal byte ReadByte() internal byte ReadByte()
{ {
return this.Bytes.ReadByte(this.InputStream); return this.bytes.ReadByte(this.InputStream);
} }
/// <summary> /// <summary>
@ -743,8 +754,8 @@ namespace ImageSharp.Formats
/// </summary> /// </summary>
private void UnreadByteStuffedByte() private void UnreadByteStuffedByte()
{ {
this.Bytes.I -= this.Bytes.UnreadableBytes; this.bytes.I -= this.bytes.UnreadableBytes;
this.Bytes.UnreadableBytes = 0; this.bytes.UnreadableBytes = 0;
if (this.Bits.UnreadBits >= 8) if (this.Bits.UnreadBits >= 8)
{ {
this.Bits.Accumulator >>= 8; this.Bits.Accumulator >>= 8;
@ -762,32 +773,32 @@ namespace ImageSharp.Formats
private void ReadFull(byte[] data, int offset, int length) private void ReadFull(byte[] data, int offset, int length)
{ {
// Unread the overshot bytes, if any. // 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.UnreadByteStuffedByte();
} }
this.Bytes.UnreadableBytes = 0; this.bytes.UnreadableBytes = 0;
} }
while (length > 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); Array.Copy(this.bytes.Buffer, this.bytes.I, data, offset, length);
this.Bytes.I += length; this.bytes.I += length;
length -= length; length -= length;
} }
else else
{ {
Array.Copy(this.Bytes.Buffer, this.Bytes.I, data, offset, 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; offset += this.bytes.J - this.bytes.I;
length -= this.Bytes.J - this.Bytes.I; length -= this.bytes.J - this.bytes.I;
this.Bytes.I += 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) private void Skip(int count)
{ {
// Unread the overshot bytes, if any. // 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.UnreadByteStuffedByte();
} }
this.Bytes.UnreadableBytes = 0; this.bytes.UnreadableBytes = 0;
} }
while (true) while (true)
{ {
int m = this.Bytes.J - this.Bytes.I; int m = this.bytes.J - this.bytes.I;
if (m > count) if (m > count)
{ {
m = count; m = count;
} }
this.Bytes.I += m; this.bytes.I += m;
count -= m; count -= m;
if (count == 0) if (count == 0)
{ {
break; break;
} }
this.Bytes.Fill(this.InputStream); this.bytes.Fill(this.InputStream);
} }
} }

Loading…
Cancel
Save