Browse Source

renaming is hard

af/merge-core
Anton Firszov 9 years ago
parent
commit
4f97c8302a
  1. 36
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs
  2. 54
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs
  3. 28
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs
  4. 78
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs
  5. 16
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegBlockProcessor.cs
  6. 2
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldDecoderErrorCode.cs
  7. 10
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldHuffmanTree.cs
  8. 14
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegPixelArea.cs
  9. 4
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.ComputationData.cs
  10. 60
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.cs
  11. 6
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrImage.cs
  12. 44
      src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegDecoderCore.cs
  13. 2
      tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs
  14. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  15. 2
      tests/ImageSharp.Tests/Formats/Jpg/YCbCrImageTests.cs

36
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bits.cs

@ -40,7 +40,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void EnsureNBits(int n, ref InputProcessor inputProcessor)
{
DecoderErrorCode errorCode = this.EnsureNBitsUnsafe(n, ref inputProcessor);
OldDecoderErrorCode errorCode = this.EnsureNBitsUnsafe(n, ref inputProcessor);
errorCode.EnsureNoError();
}
@ -48,17 +48,17 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// Reads bytes from the byte buffer to ensure that bits.UnreadBits is at
/// least n. For best performance (avoiding function calls inside hot loops),
/// the caller is the one responsible for first checking that bits.UnreadBits < n.
/// This method does not throw. Returns <see cref="DecoderErrorCode"/> instead.
/// This method does not throw. Returns <see cref="OldDecoderErrorCode"/> instead.
/// </summary>
/// <param name="n">The number of bits to ensure.</param>
/// <param name="inputProcessor">The <see cref="InputProcessor"/></param>
/// <returns>Error code</returns>
public DecoderErrorCode EnsureNBitsUnsafe(int n, ref InputProcessor inputProcessor)
public OldDecoderErrorCode EnsureNBitsUnsafe(int n, ref InputProcessor inputProcessor)
{
while (true)
{
DecoderErrorCode errorCode = this.EnsureBitsStepImpl(ref inputProcessor);
if (errorCode != DecoderErrorCode.NoError || this.UnreadBits >= n)
OldDecoderErrorCode errorCode = this.EnsureBitsStepImpl(ref inputProcessor);
if (errorCode != OldDecoderErrorCode.NoError || this.UnreadBits >= n)
{
return errorCode;
}
@ -69,8 +69,8 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// Unrolled version of <see cref="EnsureNBitsUnsafe"/> for n==8
/// </summary>
/// <param name="inputProcessor">The <see cref="InputProcessor"/></param>
/// <returns>A <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode Ensure8BitsUnsafe(ref InputProcessor inputProcessor)
/// <returns>A <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode Ensure8BitsUnsafe(ref InputProcessor inputProcessor)
{
return this.EnsureBitsStepImpl(ref inputProcessor);
}
@ -79,8 +79,8 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// Unrolled version of <see cref="EnsureNBitsUnsafe"/> for n==1
/// </summary>
/// <param name="inputProcessor">The <see cref="InputProcessor"/></param>
/// <returns>A <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode Ensure1BitUnsafe(ref InputProcessor inputProcessor)
/// <returns>A <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode Ensure1BitUnsafe(ref InputProcessor inputProcessor)
{
return this.EnsureBitsStepImpl(ref inputProcessor);
}
@ -95,7 +95,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
public int ReceiveExtend(int t, ref InputProcessor inputProcessor)
{
int x;
DecoderErrorCode errorCode = this.ReceiveExtendUnsafe(t, ref inputProcessor, out x);
OldDecoderErrorCode errorCode = this.ReceiveExtendUnsafe(t, ref inputProcessor, out x);
errorCode.EnsureNoError();
return x;
}
@ -106,13 +106,13 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// <param name="t">Byte</param>
/// <param name="inputProcessor">The <see cref="InputProcessor"/></param>
/// <param name="x">Read bits value</param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode ReceiveExtendUnsafe(int t, ref InputProcessor inputProcessor, out int x)
/// <returns>The <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode ReceiveExtendUnsafe(int t, ref InputProcessor inputProcessor, out int x)
{
if (this.UnreadBits < t)
{
DecoderErrorCode errorCode = this.EnsureNBitsUnsafe(t, ref inputProcessor);
if (errorCode != DecoderErrorCode.NoError)
OldDecoderErrorCode errorCode = this.EnsureNBitsUnsafe(t, ref inputProcessor);
if (errorCode != OldDecoderErrorCode.NoError)
{
x = int.MaxValue;
return errorCode;
@ -129,15 +129,15 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
x += ((-1) << t) + 1;
}
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
private DecoderErrorCode EnsureBitsStepImpl(ref InputProcessor inputProcessor)
private OldDecoderErrorCode EnsureBitsStepImpl(ref InputProcessor inputProcessor)
{
int c;
DecoderErrorCode errorCode = inputProcessor.Bytes.ReadByteStuffedByteUnsafe(inputProcessor.InputStream, out c);
OldDecoderErrorCode errorCode = inputProcessor.Bytes.ReadByteStuffedByteUnsafe(inputProcessor.InputStream, out c);
if (errorCode != DecoderErrorCode.NoError)
if (errorCode != OldDecoderErrorCode.NoError)
{
return errorCode;
}

54
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/Bytes.cs

@ -86,8 +86,8 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// </summary>
/// <param name="inputStream">Input stream</param>
/// <param name="x">The result byte as <see cref="int"/></param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode ReadByteStuffedByteUnsafe(Stream inputStream, out int x)
/// <returns>The <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode ReadByteStuffedByteUnsafe(Stream inputStream, out int x)
{
// Take the fast path if bytes.buf contains at least two bytes.
if (this.I + 2 <= this.J)
@ -97,48 +97,48 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
this.UnreadableBytes = 1;
if (x != OldJpegConstants.Markers.XFFInt)
{
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
if (this.BufferAsInt[this.I] != 0x00)
{
return DecoderErrorCode.MissingFF00;
return OldDecoderErrorCode.MissingFF00;
}
this.I++;
this.UnreadableBytes = 2;
x = OldJpegConstants.Markers.XFF;
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
this.UnreadableBytes = 0;
DecoderErrorCode errorCode = this.ReadByteAsIntUnsafe(inputStream, out x);
OldDecoderErrorCode errorCode = this.ReadByteAsIntUnsafe(inputStream, out x);
this.UnreadableBytes = 1;
if (errorCode != DecoderErrorCode.NoError)
if (errorCode != OldDecoderErrorCode.NoError)
{
return errorCode;
}
if (x != OldJpegConstants.Markers.XFF)
{
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
errorCode = this.ReadByteAsIntUnsafe(inputStream, out x);
this.UnreadableBytes = 2;
if (errorCode != DecoderErrorCode.NoError)
if (errorCode != OldDecoderErrorCode.NoError)
{
return errorCode;
}
if (x != 0x00)
{
return DecoderErrorCode.MissingFF00;
return OldDecoderErrorCode.MissingFF00;
}
x = OldJpegConstants.Markers.XFF;
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
/// <summary>
@ -150,25 +150,25 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
public byte ReadByte(Stream inputStream)
{
byte result;
DecoderErrorCode errorCode = this.ReadByteUnsafe(inputStream, out result);
OldDecoderErrorCode errorCode = this.ReadByteUnsafe(inputStream, out result);
errorCode.EnsureNoError();
return result;
}
/// <summary>
/// Extracts the next byte, whether buffered or not buffered into the result out parameter. It does not care about byte stuffing.
/// This method does not throw on format error, it returns a <see cref="DecoderErrorCode"/> instead.
/// This method does not throw on format error, it returns a <see cref="OldDecoderErrorCode"/> instead.
/// </summary>
/// <param name="inputStream">Input stream</param>
/// <param name="result">The result <see cref="byte"/> as out parameter</param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode ReadByteUnsafe(Stream inputStream, out byte result)
/// <returns>The <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode ReadByteUnsafe(Stream inputStream, out byte result)
{
DecoderErrorCode errorCode = DecoderErrorCode.NoError;
OldDecoderErrorCode errorCode = OldDecoderErrorCode.NoError;
while (this.I == this.J)
{
errorCode = this.FillUnsafe(inputStream);
if (errorCode != DecoderErrorCode.NoError)
if (errorCode != OldDecoderErrorCode.NoError)
{
result = 0;
return errorCode;
@ -186,15 +186,15 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// </summary>
/// <param name="inputStream">The input stream</param>
/// <param name="result">The result <see cref="int"/></param>
/// <returns>A <see cref="DecoderErrorCode"/></returns>
/// <returns>A <see cref="OldDecoderErrorCode"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public DecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int result)
public OldDecoderErrorCode ReadByteAsIntUnsafe(Stream inputStream, out int result)
{
DecoderErrorCode errorCode = DecoderErrorCode.NoError;
OldDecoderErrorCode errorCode = OldDecoderErrorCode.NoError;
while (this.I == this.J)
{
errorCode = this.FillUnsafe(inputStream);
if (errorCode != DecoderErrorCode.NoError)
if (errorCode != OldDecoderErrorCode.NoError)
{
result = 0;
return errorCode;
@ -216,18 +216,18 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Fill(Stream inputStream)
{
DecoderErrorCode errorCode = this.FillUnsafe(inputStream);
OldDecoderErrorCode errorCode = this.FillUnsafe(inputStream);
errorCode.EnsureNoError();
}
/// <summary>
/// Fills up the bytes buffer from the underlying stream.
/// It should only be called when there are no unread bytes in bytes.
/// This method does not throw <see cref="EOFException"/>, returns a <see cref="DecoderErrorCode"/> instead!
/// This method does not throw <see cref="EOFException"/>, returns a <see cref="OldDecoderErrorCode"/> instead!
/// </summary>
/// <param name="inputStream">Input stream</param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode FillUnsafe(Stream inputStream)
/// <returns>The <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode FillUnsafe(Stream inputStream)
{
if (this.I != this.J)
{
@ -249,7 +249,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
int n = inputStream.Read(this.Buffer, this.J, this.Buffer.Length - this.J);
if (n == 0)
{
return DecoderErrorCode.UnexpectedEndOfStream;
return OldDecoderErrorCode.UnexpectedEndOfStream;
}
this.J += n;
@ -259,7 +259,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
this.BufferAsInt[i] = this.Buffer[i];
}
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
}
}

28
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderThrowHelper.cs

@ -14,19 +14,19 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
internal static class DecoderThrowHelper
{
/// <summary>
/// Throws an exception that belongs to the given <see cref="DecoderErrorCode"/>
/// Throws an exception that belongs to the given <see cref="OldDecoderErrorCode"/>
/// </summary>
/// <param name="errorCode">The <see cref="DecoderErrorCode"/></param>
/// <param name="errorCode">The <see cref="OldDecoderErrorCode"/></param>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowExceptionForErrorCode(this DecoderErrorCode errorCode)
public static void ThrowExceptionForErrorCode(this OldDecoderErrorCode errorCode)
{
switch (errorCode)
{
case DecoderErrorCode.NoError:
case OldDecoderErrorCode.NoError:
throw new ArgumentException("ThrowExceptionForErrorCode() called with NoError!", nameof(errorCode));
case DecoderErrorCode.MissingFF00:
case OldDecoderErrorCode.MissingFF00:
throw new MissingFF00Exception();
case DecoderErrorCode.UnexpectedEndOfStream:
case OldDecoderErrorCode.UnexpectedEndOfStream:
throw new EOFException();
default:
throw new ArgumentOutOfRangeException(nameof(errorCode), errorCode, null);
@ -34,26 +34,26 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
/// <summary>
/// Throws an exception if the given <see cref="DecoderErrorCode"/> defines an error.
/// Throws an exception if the given <see cref="OldDecoderErrorCode"/> defines an error.
/// </summary>
/// <param name="errorCode">The <see cref="DecoderErrorCode"/></param>
/// <param name="errorCode">The <see cref="OldDecoderErrorCode"/></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void EnsureNoError(this DecoderErrorCode errorCode)
public static void EnsureNoError(this OldDecoderErrorCode errorCode)
{
if (errorCode != DecoderErrorCode.NoError)
if (errorCode != OldDecoderErrorCode.NoError)
{
ThrowExceptionForErrorCode(errorCode);
}
}
/// <summary>
/// Throws an exception if the given <see cref="DecoderErrorCode"/> is <see cref="DecoderErrorCode.UnexpectedEndOfStream"/>.
/// Throws an exception if the given <see cref="OldDecoderErrorCode"/> is <see cref="OldDecoderErrorCode.UnexpectedEndOfStream"/>.
/// </summary>
/// <param name="errorCode">The <see cref="DecoderErrorCode"/></param>
/// <param name="errorCode">The <see cref="OldDecoderErrorCode"/></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void EnsureNoEOF(this DecoderErrorCode errorCode)
public static void EnsureNoEOF(this OldDecoderErrorCode errorCode)
{
if (errorCode == DecoderErrorCode.UnexpectedEndOfStream)
if (errorCode == OldDecoderErrorCode.UnexpectedEndOfStream)
{
errorCode.ThrowExceptionForErrorCode();
}

78
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/InputProcessor.cs

@ -10,7 +10,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
using System.Runtime.CompilerServices;
/// <summary>
/// Encapsulates stream reading and processing data and operations for <see cref="JpegDecoderCore"/>.
/// Encapsulates stream reading and processing data and operations for <see cref="OldJpegDecoderCore"/>.
/// It's a value type for imporved data locality, and reduced number of CALLVIRT-s
/// </summary>
internal struct InputProcessor : IDisposable
@ -29,7 +29,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// Initializes a new instance of the <see cref="InputProcessor"/> struct.
/// </summary>
/// <param name="inputStream">The input <see cref="Stream"/></param>
/// <param name="temp">Temporal buffer, same as <see cref="JpegDecoderCore.Temp"/></param>
/// <param name="temp">Temporal buffer, same as <see cref="OldJpegDecoderCore.Temp"/></param>
public InputProcessor(Stream inputStream, byte[] temp)
{
this.Bits = default(Bits);
@ -45,7 +45,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
public Stream InputStream { get; }
/// <summary>
/// Gets the temporal buffer, same instance as <see cref="JpegDecoderCore.Temp"/>
/// Gets the temporal buffer, same instance as <see cref="OldJpegDecoderCore.Temp"/>
/// </summary>
public byte[] Temp { get; }
@ -58,11 +58,11 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// If errorCode indicates unexpected EOF, sets <see cref="UnexpectedEndOfStreamReached"/> to true and returns false.
/// Calls <see cref="DecoderThrowHelper.EnsureNoError"/> and returns true otherwise.
/// </summary>
/// <param name="errorCode">The <see cref="DecoderErrorCode"/></param>
/// <param name="errorCode">The <see cref="OldDecoderErrorCode"/></param>
/// <returns><see cref="bool"/> indicating whether everything is OK</returns>
public bool CheckEOFEnsureNoError(DecoderErrorCode errorCode)
public bool CheckEOFEnsureNoError(OldDecoderErrorCode errorCode)
{
if (errorCode == DecoderErrorCode.UnexpectedEndOfStream)
if (errorCode == OldDecoderErrorCode.UnexpectedEndOfStream)
{
this.UnexpectedEndOfStreamReached = true;
return false;
@ -76,11 +76,11 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// If errorCode indicates unexpected EOF, sets <see cref="UnexpectedEndOfStreamReached"/> to true and returns false.
/// Returns true otherwise.
/// </summary>
/// <param name="errorCode">The <see cref="DecoderErrorCode"/></param>
/// <param name="errorCode">The <see cref="OldDecoderErrorCode"/></param>
/// <returns><see cref="bool"/> indicating whether everything is OK</returns>
public bool CheckEOF(DecoderErrorCode errorCode)
public bool CheckEOF(OldDecoderErrorCode errorCode)
{
if (errorCode == DecoderErrorCode.UnexpectedEndOfStream)
if (errorCode == OldDecoderErrorCode.UnexpectedEndOfStream)
{
this.UnexpectedEndOfStreamReached = true;
return false;
@ -112,13 +112,13 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// TODO: This method (and also the usages) could be optimized by batching!
/// </summary>
/// <param name="result">The decoded bit as a <see cref="bool"/></param>
/// <returns>The <see cref="DecoderErrorCode" /></returns>
public DecoderErrorCode DecodeBitUnsafe(out bool result)
/// <returns>The <see cref="OldDecoderErrorCode" /></returns>
public OldDecoderErrorCode DecodeBitUnsafe(out bool result)
{
if (this.Bits.UnreadBits == 0)
{
DecoderErrorCode errorCode = this.Bits.Ensure1BitUnsafe(ref this);
if (errorCode != DecoderErrorCode.NoError)
OldDecoderErrorCode errorCode = this.Bits.Ensure1BitUnsafe(ref this);
if (errorCode != OldDecoderErrorCode.NoError)
{
result = false;
return errorCode;
@ -128,18 +128,18 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
result = (this.Bits.Accumulator & this.Bits.Mask) != 0;
this.Bits.UnreadBits--;
this.Bits.Mask >>= 1;
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
/// <summary>
/// Reads exactly length bytes into data. It does not care about byte stuffing.
/// Does not throw on errors, returns <see cref="JpegDecoderCore"/> instead!
/// Does not throw on errors, returns <see cref="OldJpegDecoderCore"/> instead!
/// </summary>
/// <param name="data">The data to write to.</param>
/// <param name="offset">The offset in the source buffer</param>
/// <param name="length">The number of bytes to read</param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length)
/// <returns>The <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode ReadFullUnsafe(byte[] data, int offset, int length)
{
// Unread the overshot bytes, if any.
if (this.Bytes.UnreadableBytes != 0)
@ -152,7 +152,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
this.Bytes.UnreadableBytes = 0;
}
DecoderErrorCode errorCode = DecoderErrorCode.NoError;
OldDecoderErrorCode errorCode = OldDecoderErrorCode.NoError;
while (length > 0)
{
if (this.Bytes.J - this.Bytes.I >= length)
@ -180,8 +180,8 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// </summary>
/// <param name="count">The number of bits to decode.</param>
/// <param name="result">The <see cref="uint" /> result</param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode DecodeBitsUnsafe(int count, out int result)
/// <returns>The <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode DecodeBitsUnsafe(int count, out int result)
{
if (this.Bits.UnreadBits < count)
{
@ -192,7 +192,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
result = result & ((1 << count) - 1);
this.Bits.UnreadBits -= count;
this.Bits.Mask >>= count;
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
/// <summary>
@ -200,8 +200,8 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// </summary>
/// <param name="huffmanTree">The huffman value</param>
/// <param name="result">The decoded <see cref="byte" /></param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode DecodeHuffmanUnsafe(ref HuffmanTree huffmanTree, out int result)
/// <returns>The <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode DecodeHuffmanUnsafe(ref OldHuffmanTree huffmanTree, out int result)
{
result = 0;
@ -212,11 +212,11 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
if (this.Bits.UnreadBits < 8)
{
DecoderErrorCode errorCode = this.Bits.Ensure8BitsUnsafe(ref this);
OldDecoderErrorCode errorCode = this.Bits.Ensure8BitsUnsafe(ref this);
if (errorCode == DecoderErrorCode.NoError)
if (errorCode == OldDecoderErrorCode.NoError)
{
int lutIndex = (this.Bits.Accumulator >> (this.Bits.UnreadBits - HuffmanTree.LutSizeLog2)) & 0xFF;
int lutIndex = (this.Bits.Accumulator >> (this.Bits.UnreadBits - OldHuffmanTree.LutSizeLog2)) & 0xFF;
int v = huffmanTree.Lut[lutIndex];
if (v != 0)
@ -236,7 +236,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
int code = 0;
for (int i = 0; i < HuffmanTree.MaxCodeLength; i++)
for (int i = 0; i < OldHuffmanTree.MaxCodeLength; i++)
{
if (this.Bits.UnreadBits == 0)
{
@ -254,7 +254,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
if (code <= huffmanTree.MaxCodes[i])
{
result = huffmanTree.GetValue(code, i);
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
code <<= 1;
@ -264,7 +264,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
DecoderThrowHelper.ThrowImageFormatException.BadHuffmanCode();
// DUMMY RETURN! C# doesn't know we have thrown an exception!
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
/// <summary>
@ -274,17 +274,17 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Skip(int count)
{
DecoderErrorCode errorCode = this.SkipUnsafe(count);
OldDecoderErrorCode errorCode = this.SkipUnsafe(count);
errorCode.EnsureNoError();
}
/// <summary>
/// Skips the next n bytes.
/// Does not throw, returns <see cref="DecoderErrorCode"/> instead!
/// Does not throw, returns <see cref="OldDecoderErrorCode"/> instead!
/// </summary>
/// <param name="count">The number of bytes to ignore.</param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode SkipUnsafe(int count)
/// <returns>The <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode SkipUnsafe(int count)
{
// Unread the overshot bytes, if any.
if (this.Bytes.UnreadableBytes != 0)
@ -312,14 +312,14 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
break;
}
DecoderErrorCode errorCode = this.Bytes.FillUnsafe(this.InputStream);
if (errorCode != DecoderErrorCode.NoError)
OldDecoderErrorCode errorCode = this.Bytes.FillUnsafe(this.InputStream);
if (errorCode != OldDecoderErrorCode.NoError)
{
return errorCode;
}
}
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
/// <summary>
@ -331,7 +331,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReadFull(byte[] data, int offset, int length)
{
DecoderErrorCode errorCode = this.ReadFullUnsafe(data, offset, length);
OldDecoderErrorCode errorCode = this.ReadFullUnsafe(data, offset, length);
errorCode.EnsureNoError();
}
@ -359,8 +359,8 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// </summary>
/// <param name="t">Byte</param>
/// <param name="x">Read bits value</param>
/// <returns>The <see cref="DecoderErrorCode"/></returns>
public DecoderErrorCode ReceiveExtendUnsafe(int t, out int x)
/// <returns>The <see cref="OldDecoderErrorCode"/></returns>
public OldDecoderErrorCode ReceiveExtendUnsafe(int t, out int x)
{
return this.Bits.ReceiveExtendUnsafe(t, ref this, out x);
}

16
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegBlockProcessor.cs

@ -44,10 +44,10 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
/// <summary>
/// Dequantize, perform the inverse DCT and store the blocks to the into the corresponding <see cref="JpegPixelArea"/> instances.
/// Dequantize, perform the inverse DCT and store the blocks to the into the corresponding <see cref="OldJpegPixelArea"/> instances.
/// </summary>
/// <param name="decoder">The <see cref="JpegDecoderCore"/> instance</param>
public void ProcessAllBlocks(JpegDecoderCore decoder)
/// <param name="decoder">The <see cref="OldJpegDecoderCore"/> instance</param>
public void ProcessAllBlocks(OldJpegDecoderCore decoder)
{
Buffer<DecodedBlock> blockArray = decoder.DecodedBlocks[this.componentIndex];
for (int i = 0; i < blockArray.Length; i++)
@ -57,11 +57,11 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
/// <summary>
/// Dequantize, perform the inverse DCT and store decodedBlock.Block to the into the corresponding <see cref="JpegPixelArea"/> instance.
/// Dequantize, perform the inverse DCT and store decodedBlock.Block to the into the corresponding <see cref="OldJpegPixelArea"/> instance.
/// </summary>
/// <param name="decoder">The <see cref="JpegDecoderCore"/></param>
/// <param name="decoder">The <see cref="OldJpegDecoderCore"/></param>
/// <param name="decodedBlock">The <see cref="DecodedBlock"/></param>
private void ProcessBlockColors(JpegDecoderCore decoder, ref DecodedBlock decodedBlock)
private void ProcessBlockColors(OldJpegDecoderCore decoder, ref DecodedBlock decodedBlock)
{
this.data.Block = decodedBlock.Block;
int qtIndex = decoder.ComponentArray[this.componentIndex].Selector;
@ -73,8 +73,8 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
DCT.TransformIDCT(ref *b, ref *this.pointers.Temp1, ref *this.pointers.Temp2);
JpegPixelArea destChannel = decoder.GetDestinationChannel(this.componentIndex);
JpegPixelArea destArea = destChannel.GetOffsetedSubAreaForBlock(decodedBlock.Bx, decodedBlock.By);
OldJpegPixelArea destChannel = decoder.GetDestinationChannel(this.componentIndex);
OldJpegPixelArea destArea = destChannel.GetOffsetedSubAreaForBlock(decodedBlock.Bx, decodedBlock.By);
destArea.LoadColorsFrom(this.pointers.Temp1, this.pointers.Temp2);
}

2
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/DecoderErrorCode.cs → src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldDecoderErrorCode.cs

@ -8,7 +8,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// <summary>
/// Represents "recoverable" decoder errors.
/// </summary>
internal enum DecoderErrorCode
internal enum OldDecoderErrorCode
{
/// <summary>
/// NoError

10
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/HuffmanTree.cs → src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldHuffmanTree.cs

@ -10,7 +10,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// <summary>
/// Represents a Huffman tree
/// </summary>
internal struct HuffmanTree : IDisposable
internal struct OldHuffmanTree : IDisposable
{
/// <summary>
/// The index of the AC table row
@ -99,12 +99,12 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
private static readonly ArrayPool<int> CodesPool16 = ArrayPool<int>.Create(MaxCodeLength, 50);
/// <summary>
/// Creates and initializes an array of <see cref="HuffmanTree" /> instances of size <see cref="NumberOfTrees" />
/// Creates and initializes an array of <see cref="OldHuffmanTree" /> instances of size <see cref="NumberOfTrees" />
/// </summary>
/// <returns>An array of <see cref="HuffmanTree" /> instances representing the Huffman tables</returns>
public static HuffmanTree[] CreateHuffmanTrees()
/// <returns>An array of <see cref="OldHuffmanTree" /> instances representing the Huffman tables</returns>
public static OldHuffmanTree[] CreateHuffmanTrees()
{
HuffmanTree[] result = new HuffmanTree[NumberOfTrees];
OldHuffmanTree[] result = new OldHuffmanTree[NumberOfTrees];
for (int i = 0; i < MaxTc + 1; i++)
{
for (int j = 0; j < MaxTh + 1; j++)

14
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/JpegPixelArea.cs → src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegPixelArea.cs

@ -14,15 +14,15 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// <summary>
/// Represents an area of a Jpeg subimage (channel)
/// </summary>
internal struct JpegPixelArea
internal struct OldJpegPixelArea
{
/// <summary>
/// Initializes a new instance of the <see cref="JpegPixelArea" /> struct from existing data.
/// Initializes a new instance of the <see cref="OldJpegPixelArea" /> struct from existing data.
/// </summary>
/// <param name="pixels">The pixel buffer</param>
/// <param name="stride">The stride</param>
/// <param name="offset">The offset</param>
public JpegPixelArea(Buffer2D<byte> pixels, int stride, int offset)
public OldJpegPixelArea(Buffer2D<byte> pixels, int stride, int offset)
{
this.Stride = stride;
this.Pixels = pixels;
@ -30,11 +30,11 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
/// <summary>
/// Initializes a new instance of the <see cref="JpegPixelArea" /> struct from existing buffer.
/// Initializes a new instance of the <see cref="OldJpegPixelArea" /> struct from existing buffer.
/// <see cref="Stride"/> will be set to <see cref="Buffer2D{T}.Width"/> of <paramref name="pixels"/> and <see cref="Offset"/> will be set to 0.
/// </summary>
/// <param name="pixels">The pixel buffer</param>
public JpegPixelArea(Buffer2D<byte> pixels)
public OldJpegPixelArea(Buffer2D<byte> pixels)
: this(pixels, pixels.Width, 0)
{
}
@ -85,10 +85,10 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// <param name="bx">The block X index</param>
/// <param name="by">The block Y index</param>
/// <returns>The subarea offseted by block indices</returns>
public JpegPixelArea GetOffsetedSubAreaForBlock(int bx, int by)
public OldJpegPixelArea GetOffsetedSubAreaForBlock(int bx, int by)
{
int offset = this.Offset + (8 * ((by * this.Stride) + bx));
return new JpegPixelArea(this.Pixels, this.Stride, offset);
return new OldJpegPixelArea(this.Pixels, this.Stride, offset);
}
/// <summary>

4
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.ComputationData.cs

@ -32,12 +32,12 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// <summary>
/// The buffer storing the <see cref="OldComponentScan"/>-s for each component
/// </summary>
public fixed byte ScanData[3 * JpegDecoderCore.MaxComponents];
public fixed byte ScanData[3 * OldJpegDecoderCore.MaxComponents];
/// <summary>
/// The DC values for each component
/// </summary>
public fixed int Dc[JpegDecoderCore.MaxComponents];
public fixed int Dc[OldJpegDecoderCore.MaxComponents];
/// <summary>
/// Creates and initializes a new <see cref="ComputationData"/> instance

60
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OldJpegScanDecoder.cs

@ -96,12 +96,12 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
private int eobRun;
/// <summary>
/// Initializes a default-constructed <see cref="OldJpegScanDecoder"/> instance for reading data from <see cref="JpegDecoderCore"/>-s stream.
/// Initializes a default-constructed <see cref="OldJpegScanDecoder"/> instance for reading data from <see cref="OldJpegDecoderCore"/>-s stream.
/// </summary>
/// <param name="p">Pointer to <see cref="OldJpegScanDecoder"/> on the stack</param>
/// <param name="decoder">The <see cref="JpegDecoderCore"/> instance</param>
/// <param name="decoder">The <see cref="OldJpegDecoderCore"/> instance</param>
/// <param name="remaining">The remaining bytes in the segment block.</param>
public static void InitStreamReading(OldJpegScanDecoder* p, JpegDecoderCore decoder, int remaining)
public static void InitStreamReading(OldJpegScanDecoder* p, OldJpegDecoderCore decoder, int remaining)
{
p->data = ComputationData.Create();
p->pointers = new DataPointers(&p->data);
@ -109,8 +109,8 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
/// <summary>
/// Read Huffman data from Jpeg scans in <see cref="JpegDecoderCore.InputStream"/>,
/// and decode it as <see cref="Block8x8F"/> into <see cref="JpegDecoderCore.DecodedBlocks"/>.
/// Read Huffman data from Jpeg scans in <see cref="OldJpegDecoderCore.InputStream"/>,
/// and decode it as <see cref="Block8x8F"/> into <see cref="OldJpegDecoderCore.DecodedBlocks"/>.
///
/// The blocks are traversed one MCU at a time. For 4:2:0 chroma
/// subsampling, there are four Y 8x8 blocks in every 16x16 MCU.
@ -135,8 +135,8 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// 0 1 2
/// 3 4 5
/// </summary>
/// <param name="decoder">The <see cref="JpegDecoderCore"/> instance</param>
public void DecodeBlocks(JpegDecoderCore decoder)
/// <param name="decoder">The <see cref="OldJpegDecoderCore"/> instance</param>
public void DecodeBlocks(OldJpegDecoderCore decoder)
{
int blockCount = 0;
int mcu = 0;
@ -197,7 +197,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
// but this one assumes well-formed input, and hence the restart marker follows immediately.
if (!decoder.InputProcessor.UnexpectedEndOfStreamReached)
{
DecoderErrorCode errorCode = decoder.InputProcessor.ReadFullUnsafe(decoder.Temp, 0, 2);
OldDecoderErrorCode errorCode = decoder.InputProcessor.ReadFullUnsafe(decoder.Temp, 0, 2);
if (decoder.InputProcessor.CheckEOFEnsureNoError(errorCode))
{
if (decoder.Temp[0] != 0xff || decoder.Temp[1] != expectedRst)
@ -230,15 +230,15 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
private void ResetDc()
{
Unsafe.InitBlock(this.pointers.Dc, default(byte), sizeof(int) * JpegDecoderCore.MaxComponents);
Unsafe.InitBlock(this.pointers.Dc, default(byte), sizeof(int) * OldJpegDecoderCore.MaxComponents);
}
/// <summary>
/// The implementation part of <see cref="InitStreamReading"/> as an instance method.
/// </summary>
/// <param name="decoder">The <see cref="JpegDecoderCore"/></param>
/// <param name="decoder">The <see cref="OldJpegDecoderCore"/></param>
/// <param name="remaining">The remaining bytes</param>
private void InitStreamReadingImpl(JpegDecoderCore decoder, int remaining)
private void InitStreamReadingImpl(OldJpegDecoderCore decoder, int remaining)
{
if (decoder.ComponentCount == 0)
{
@ -305,10 +305,10 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// </summary>
/// <param name="decoder">The decoder</param>
/// <param name="scanIndex">The index of the scan</param>
private void DecodeBlock(JpegDecoderCore decoder, int scanIndex)
private void DecodeBlock(OldJpegDecoderCore decoder, int scanIndex)
{
Block8x8F* b = this.pointers.Block;
int huffmannIdx = (HuffmanTree.AcTableIndex * HuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].AcTableSelector;
int huffmannIdx = (OldHuffmanTree.AcTableIndex * OldHuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].AcTableSelector;
if (this.ah != 0)
{
this.Refine(ref decoder.InputProcessor, ref decoder.HuffmanTrees[huffmannIdx], 1 << this.al);
@ -316,14 +316,14 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
else
{
int zig = this.zigStart;
DecoderErrorCode errorCode;
OldDecoderErrorCode errorCode;
if (zig == 0)
{
zig++;
// Decode the DC coefficient, as specified in section F.2.2.1.
int value;
int huffmanIndex = (HuffmanTree.DcTableIndex * HuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].DcTableSelector;
int huffmanIndex = (OldHuffmanTree.DcTableIndex * OldHuffmanTree.ThRowSize) + this.pointers.ComponentScan[scanIndex].DcTableSelector;
errorCode = decoder.InputProcessor.DecodeHuffmanUnsafe(
ref decoder.HuffmanTrees[huffmanIndex],
out value);
@ -411,30 +411,30 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
}
private DecoderErrorCode DecodeEobRun(int count, ref InputProcessor decoder)
private OldDecoderErrorCode DecodeEobRun(int count, ref InputProcessor decoder)
{
int bitsResult;
DecoderErrorCode errorCode = decoder.DecodeBitsUnsafe(count, out bitsResult);
if (errorCode != DecoderErrorCode.NoError)
OldDecoderErrorCode errorCode = decoder.DecodeBitsUnsafe(count, out bitsResult);
if (errorCode != OldDecoderErrorCode.NoError)
{
return errorCode;
}
this.eobRun |= bitsResult;
return DecoderErrorCode.NoError;
return OldDecoderErrorCode.NoError;
}
/// <summary>
/// Gets the block index used to retieve blocks from in <see cref="JpegDecoderCore.DecodedBlocks"/>
/// Gets the block index used to retieve blocks from in <see cref="OldJpegDecoderCore.DecodedBlocks"/>
/// </summary>
/// <param name="decoder">The <see cref="JpegDecoderCore"/> instance</param>
/// <param name="decoder">The <see cref="OldJpegDecoderCore"/> instance</param>
/// <returns>The index</returns>
private int GetBlockIndex(JpegDecoderCore decoder)
private int GetBlockIndex(OldJpegDecoderCore decoder)
{
return ((this.by * decoder.MCUCountX) * this.hi) + this.bx;
}
private void InitComponentScan(JpegDecoderCore decoder, int i, ref OldComponentScan currentComponentScan, ref int totalHv)
private void InitComponentScan(OldJpegDecoderCore decoder, int i, ref OldComponentScan currentComponentScan, ref int totalHv)
{
// Component selector.
int cs = decoder.Temp[1 + (2 * i)];
@ -459,7 +459,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
private void ProcessComponentImpl(
JpegDecoderCore decoder,
OldJpegDecoderCore decoder,
int i,
ref OldComponentScan currentComponentScan,
ref int totalHv,
@ -481,13 +481,13 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
totalHv += currentComponent.HorizontalFactor * currentComponent.VerticalFactor;
currentComponentScan.DcTableSelector = (byte)(decoder.Temp[2 + (2 * i)] >> 4);
if (currentComponentScan.DcTableSelector > HuffmanTree.MaxTh)
if (currentComponentScan.DcTableSelector > OldHuffmanTree.MaxTh)
{
throw new ImageFormatException("Bad DC table selector value");
}
currentComponentScan.AcTableSelector = (byte)(decoder.Temp[2 + (2 * i)] & 0x0f);
if (currentComponentScan.AcTableSelector > HuffmanTree.MaxTh)
if (currentComponentScan.AcTableSelector > OldHuffmanTree.MaxTh)
{
throw new ImageFormatException("Bad AC table selector value");
}
@ -499,7 +499,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
/// <param name="bp">The <see cref="InputProcessor"/> instance</param>
/// <param name="h">The Huffman tree</param>
/// <param name="delta">The low transform offset</param>
private void Refine(ref InputProcessor bp, ref HuffmanTree h, int delta)
private void Refine(ref InputProcessor bp, ref OldHuffmanTree h, int delta)
{
Block8x8F* b = this.pointers.Block;
@ -512,7 +512,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
bool bit;
DecoderErrorCode errorCode = bp.DecodeBitUnsafe(out bit);
OldDecoderErrorCode errorCode = bp.DecodeBitUnsafe(out bit);
if (!bp.CheckEOFEnsureNoError(errorCode))
{
return;
@ -542,7 +542,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
int z = 0;
int val;
DecoderErrorCode errorCode = bp.DecodeHuffmanUnsafe(ref h, out val);
OldDecoderErrorCode errorCode = bp.DecodeHuffmanUnsafe(ref h, out val);
if (!bp.CheckEOF(errorCode))
{
return;
@ -651,7 +651,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
}
bool bit;
DecoderErrorCode errorCode = bp.DecodeBitUnsafe(out bit);
OldDecoderErrorCode errorCode = bp.DecodeBitUnsafe(out bit);
if (!bp.CheckEOFEnsureNoError(errorCode))
{
return int.MinValue;

6
src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/YCbCrImage.cs

@ -18,17 +18,17 @@ namespace ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder
// Complex value type field + mutable + available to other classes = the field MUST NOT be private :P
#pragma warning disable SA1401 // FieldsMustBePrivate
/// <summary>
/// Gets the luminance components channel as <see cref="JpegPixelArea" />.
/// Gets the luminance components channel as <see cref="OldJpegPixelArea" />.
/// </summary>
public Buffer2D<byte> YChannel;
/// <summary>
/// Gets the blue chroma components channel as <see cref="JpegPixelArea" />.
/// Gets the blue chroma components channel as <see cref="OldJpegPixelArea" />.
/// </summary>
public Buffer2D<byte> CbChannel;
/// <summary>
/// Gets an offseted <see cref="JpegPixelArea" /> to the Cr channel
/// Gets an offseted <see cref="OldJpegPixelArea" /> to the Cr channel
/// </summary>
public Buffer2D<byte> CrChannel;
#pragma warning restore SA1401

44
src/ImageSharp/Formats/Jpeg/GolangPort/JpegDecoderCore.cs → src/ImageSharp/Formats/Jpeg/GolangPort/OldJpegDecoderCore.cs

@ -19,7 +19,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
/// <summary>
/// Performs the jpeg decoding operation.
/// </summary>
internal sealed unsafe class JpegDecoderCore : IDisposable
internal sealed unsafe class OldJpegDecoderCore : IDisposable
{
/// <summary>
/// The maximum number of color components
@ -35,7 +35,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
#pragma warning disable SA1401 // FieldsMustBePrivate
/// <summary>
/// Encapsulates stream reading and processing data and operations for <see cref="JpegDecoderCore"/>.
/// Encapsulates stream reading and processing data and operations for <see cref="OldJpegDecoderCore"/>.
/// It's a value type for imporved data locality, and reduced number of CALLVIRT-s
/// </summary>
public InputProcessor InputProcessor;
@ -64,12 +64,12 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
/// <summary>
/// The black image to decode to.
/// </summary>
private JpegPixelArea blackImage;
private OldJpegPixelArea blackImage;
/// <summary>
/// A grayscale image to decode to.
/// </summary>
private JpegPixelArea grayImage;
private OldJpegPixelArea grayImage;
/// <summary>
/// The horizontal resolution. Calculated if the image has a JFIF header.
@ -97,15 +97,15 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
private YCbCrImage ycbcrImage;
/// <summary>
/// Initializes a new instance of the <see cref="JpegDecoderCore" /> class.
/// Initializes a new instance of the <see cref="OldJpegDecoderCore" /> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="options">The options.</param>
public JpegDecoderCore(Configuration configuration, IJpegDecoderOptions options)
public OldJpegDecoderCore(Configuration configuration, IJpegDecoderOptions options)
{
this.IgnoreMetadata = options.IgnoreMetadata;
this.configuration = configuration ?? Configuration.Default;
this.HuffmanTrees = HuffmanTree.CreateHuffmanTrees();
this.HuffmanTrees = OldHuffmanTree.CreateHuffmanTrees();
this.QuantizationTables = new Block8x8F[MaxTq + 1];
this.Temp = new byte[2 * Block8x8F.ScalarCount];
this.ComponentArray = new OldComponent[MaxComponents];
@ -120,7 +120,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
/// <summary>
/// Gets the huffman trees
/// </summary>
public HuffmanTree[] HuffmanTrees { get; }
public OldHuffmanTree[] HuffmanTrees { get; }
/// <summary>
/// Gets the array of <see cref="Buffer{T}"/>-s storing the "raw" frequency-domain decoded blocks.
@ -231,11 +231,11 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
}
/// <summary>
/// Gets the <see cref="JpegPixelArea"/> representing the channel at a given component index
/// Gets the <see cref="OldJpegPixelArea"/> representing the channel at a given component index
/// </summary>
/// <param name="compIndex">The component index</param>
/// <returns>The <see cref="JpegPixelArea"/> of the channel</returns>
public JpegPixelArea GetDestinationChannel(int compIndex)
/// <returns>The <see cref="OldJpegPixelArea"/> of the channel</returns>
public OldJpegPixelArea GetDestinationChannel(int compIndex)
{
if (this.ComponentCount == 1)
{
@ -246,11 +246,11 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
switch (compIndex)
{
case 0:
return new JpegPixelArea(this.ycbcrImage.YChannel);
return new OldJpegPixelArea(this.ycbcrImage.YChannel);
case 1:
return new JpegPixelArea(this.ycbcrImage.CbChannel);
return new OldJpegPixelArea(this.ycbcrImage.CbChannel);
case 2:
return new JpegPixelArea(this.ycbcrImage.CrChannel);
return new OldJpegPixelArea(this.ycbcrImage.CrChannel);
case 3:
return this.blackImage;
default:
@ -460,9 +460,9 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
}
/// <summary>
/// Process the blocks in <see cref="DecodedBlocks"/> into Jpeg image channels (<see cref="YCbCrImage"/> and <see cref="JpegPixelArea"/>)
/// Process the blocks in <see cref="DecodedBlocks"/> into Jpeg image channels (<see cref="YCbCrImage"/> and <see cref="OldJpegPixelArea"/>)
/// <see cref="DecodedBlocks"/> are in a "raw" frequency-domain form. We need to apply IDCT, dequantization and unzigging to transform them into color-space blocks.
/// We can copy these blocks into <see cref="JpegPixelArea"/>-s afterwards.
/// We can copy these blocks into <see cref="OldJpegPixelArea"/>-s afterwards.
/// </summary>
/// <typeparam name="TPixel">The pixel type</typeparam>
private void ProcessBlocksIntoJpegImageChannels<TPixel>()
@ -480,7 +480,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
}
/// <summary>
/// Convert the pixel data in <see cref="YCbCrImage"/> and/or <see cref="JpegPixelArea"/> into pixels of <see cref="Image{TPixel}"/>
/// Convert the pixel data in <see cref="YCbCrImage"/> and/or <see cref="OldJpegPixelArea"/> into pixels of <see cref="Image{TPixel}"/>
/// </summary>
/// <typeparam name="TPixel">The pixel type</typeparam>
/// <param name="metadata">The metadata for the image.</param>
@ -788,7 +788,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
if (this.ComponentCount == 1)
{
Buffer2D<byte> buffer = Buffer2D<byte>.CreateClean(8 * this.MCUCountX, 8 * this.MCUCountY);
this.grayImage = new JpegPixelArea(buffer);
this.grayImage = new OldJpegPixelArea(buffer);
}
else
{
@ -828,7 +828,7 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
int v3 = this.ComponentArray[3].VerticalFactor;
Buffer2D<byte> buffer = Buffer2D<byte>.CreateClean(8 * h3 * this.MCUCountX, 8 * v3 * this.MCUCountY);
this.blackImage = new JpegPixelArea(buffer);
this.blackImage = new OldJpegPixelArea(buffer);
}
}
}
@ -1062,18 +1062,18 @@ namespace ImageSharp.Formats.Jpeg.GolangPort
this.InputProcessor.ReadFull(this.Temp, 0, 17);
int tc = this.Temp[0] >> 4;
if (tc > HuffmanTree.MaxTc)
if (tc > OldHuffmanTree.MaxTc)
{
throw new ImageFormatException("Bad Tc value");
}
int th = this.Temp[0] & 0x0f;
if (th > HuffmanTree.MaxTh || (!this.IsProgressive && (th > 1)))
if (th > OldHuffmanTree.MaxTh || (!this.IsProgressive && (th > 1)))
{
throw new ImageFormatException("Bad Th value");
}
int huffTreeIndex = (tc * HuffmanTree.ThRowSize) + th;
int huffTreeIndex = (tc * OldHuffmanTree.ThRowSize) + th;
this.HuffmanTrees[huffTreeIndex].ProcessDefineHuffmanTablesMarkerLoop(
ref this.InputProcessor,
this.Temp,

2
tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs

@ -65,7 +65,7 @@ namespace ImageSharp.Benchmarks.Image
{
Guard.NotNull(stream, "stream");
using (var decoder = new JpegDecoderCore(configuration, this))
using (var decoder = new OldJpegDecoderCore(configuration, this))
{
return decoder.Decode<TPixel>(stream);
}

2
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -174,7 +174,7 @@ namespace ImageSharp.Tests
image.Save(ms, new JpegEncoder());
ms.Seek(0, SeekOrigin.Begin);
using (var decoder = new JpegDecoderCore(null, new JpegDecoder()))
using (var decoder = new OldJpegDecoderCore(null, new JpegDecoder()))
{
decoder.Decode<TPixel>(ms);

2
tests/ImageSharp.Tests/Formats/Jpg/YCbCrImageTests.cs

@ -64,7 +64,7 @@ namespace ImageSharp.Tests
Assert.Equal(img.CrChannel.Width, 400 / expectedCStrideDiv);
}
private void PrintChannel(string name, JpegPixelArea channel)
private void PrintChannel(string name, OldJpegPixelArea channel)
{
this.Output.WriteLine($"{name}: Stride={channel.Stride}");
}

Loading…
Cancel
Save