Browse Source

prefixed every ported class with PdfJs... to avoid naming conflicts

af/merge-core
Anton Firszov 9 years ago
parent
commit
1f5543d021
  1. 8
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsAdobe.cs
  2. 4
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsComponent.cs
  3. 4
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsComponentBlocks.cs
  4. 12
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFileMarker.cs
  5. 6
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrame.cs
  6. 4
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs
  7. 8
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs
  8. 8
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs
  9. 10
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsIDCT.cs
  10. 8
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsJFif.cs
  11. 10
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsJpegPixelArea.cs
  12. 4
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsQuantizationTables.cs
  13. 124
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs
  14. 4
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsYCbCrToRgbTables.cs
  15. 4
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegConstants.cs
  16. 215
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
  17. 3
      src/ImageSharp/ImageSharp.csproj

8
src/ImageSharp/Formats/Jpeg/Port/Components/Adobe.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsAdobe.cs

@ -4,14 +4,14 @@
// </copyright>
// ReSharper disable InconsistentNaming
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
/// <summary>
/// Provides information about the Adobe marker segment
/// </summary>
internal struct Adobe : IEquatable<Adobe>
internal struct PdfJsAdobe : IEquatable<PdfJsAdobe>
{
/// <summary>
/// The DCT Encode Version
@ -38,7 +38,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
public byte ColorTransform;
/// <inheritdoc/>
public bool Equals(Adobe other)
public bool Equals(PdfJsAdobe other)
{
return this.DCTEncodeVersion == other.DCTEncodeVersion
&& this.APP14Flags0 == other.APP14Flags0
@ -54,7 +54,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
return false;
}
return obj is Adobe && this.Equals((Adobe)obj);
return obj is PdfJsAdobe && this.Equals((PdfJsAdobe)obj);
}
/// <inheritdoc/>

4
src/ImageSharp/Formats/Jpeg/Port/Components/Component.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsComponent.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
using System.Numerics;
@ -12,7 +12,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// <summary>
/// Represents a component block
/// </summary>
internal struct Component : IDisposable
internal struct PdfJsComponent : IDisposable
{
/// <summary>
/// Gets or sets the output

4
src/ImageSharp/Formats/Jpeg/Port/Components/ComponentBlocks.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsComponentBlocks.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
@ -15,7 +15,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// <summary>
/// Gets or sets the component blocks
/// </summary>
public Component[] Components { get; set; }
public PdfJsComponent[] Components { get; set; }
/// <inheritdoc/>
public void Dispose()

12
src/ImageSharp/Formats/Jpeg/Port/Components/FileMarker.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFileMarker.cs

@ -3,19 +3,19 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
/// <summary>
/// Represents a jpeg file marker
/// </summary>
internal struct FileMarker
internal struct PdfJsFileMarker
{
/// <summary>
/// Initializes a new instance of the <see cref="FileMarker"/> struct.
/// Initializes a new instance of the <see cref="PdfJsFileMarker"/> struct.
/// </summary>
/// <param name="marker">The marker</param>
/// <param name="position">The position within the stream</param>
public FileMarker(ushort marker, long position)
public PdfJsFileMarker(ushort marker, long position)
{
this.Marker = marker;
this.Position = position;
@ -23,12 +23,12 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
/// <summary>
/// Initializes a new instance of the <see cref="FileMarker"/> struct.
/// Initializes a new instance of the <see cref="PdfJsFileMarker"/> struct.
/// </summary>
/// <param name="marker">The marker</param>
/// <param name="position">The position within the stream</param>
/// <param name="invalid">Whether the current marker is invalid</param>
public FileMarker(ushort marker, long position, bool invalid)
public PdfJsFileMarker(ushort marker, long position, bool invalid)
{
this.Marker = marker;
this.Position = position;

6
src/ImageSharp/Formats/Jpeg/Port/Components/Frame.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrame.cs

@ -3,14 +3,14 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
/// <summary>
/// Represent a single jpeg frame
/// </summary>
internal sealed class Frame : IDisposable
internal sealed class PdfJsFrame : IDisposable
{
/// <summary>
/// Gets or sets a value indicating whether the frame uses the extended specification
@ -50,7 +50,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// <summary>
/// Gets or sets the frame component collection
/// </summary>
public FrameComponent[] Components { get; set; }
public PdfJsFrameComponent[] Components { get; set; }
/// <summary>
/// Gets or sets the maximum horizontal sampling factor

4
src/ImageSharp/Formats/Jpeg/Port/Components/FrameComponent.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
@ -12,7 +12,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// <summary>
/// Represents a single frame component
/// </summary>
internal struct FrameComponent : IDisposable
internal struct PdfJsFrameComponent : IDisposable
{
/// <summary>
/// Gets or sets the component Id

8
src/ImageSharp/Formats/Jpeg/Port/Components/HuffmanTable.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
using System.Runtime.CompilerServices;
@ -13,7 +13,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// <summary>
/// Represents a Huffman Table
/// </summary>
internal struct HuffmanTable : IDisposable
internal struct PdfJsHuffmanTable : IDisposable
{
private Buffer<short> lookahead;
private Buffer<short> valOffset;
@ -21,11 +21,11 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
private Buffer<byte> huffval;
/// <summary>
/// Initializes a new instance of the <see cref="HuffmanTable"/> struct.
/// Initializes a new instance of the <see cref="PdfJsHuffmanTable"/> struct.
/// </summary>
/// <param name="lengths">The code lengths</param>
/// <param name="values">The huffman values</param>
public HuffmanTable(byte[] lengths, byte[] values)
public PdfJsHuffmanTable(byte[] lengths, byte[] values)
{
this.lookahead = Buffer<short>.CreateClean(256);
this.valOffset = Buffer<short>.CreateClean(18);

8
src/ImageSharp/Formats/Jpeg/Port/Components/HuffmanTables.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
using System.Collections.Generic;
@ -12,16 +12,16 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// <summary>
/// Defines a pair of huffman tables
/// </summary>
internal sealed class HuffmanTables : IDisposable
internal sealed class PdfJsHuffmanTables : IDisposable
{
private readonly HuffmanTable[] tables = new HuffmanTable[4];
private readonly PdfJsHuffmanTable[] tables = new PdfJsHuffmanTable[4];
/// <summary>
/// Gets or sets the table at the given index.
/// </summary>
/// <param name="index">The index</param>
/// <returns>The <see cref="List{HuffmanBranch}"/></returns>
public ref HuffmanTable this[int index]
public ref PdfJsHuffmanTable this[int index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get

10
src/ImageSharp/Formats/Jpeg/Port/Components/IDCT.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsIDCT.cs

@ -1,4 +1,4 @@
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
using System.Runtime.CompilerServices;
@ -8,7 +8,7 @@
/// <summary>
/// Performs the inverse Descrete Cosine Transform on each frame component.
/// </summary>
internal static class IDCT
internal static class PdfJsIDCT
{
/// <summary>
/// Precomputed values scaled up by 14 bits
@ -61,7 +61,7 @@
private static readonly byte[] Limit = new byte[5 * (MaxJSample + 1)];
static IDCT()
static PdfJsIDCT()
{
// Main part of range limit table: limit[x] = x
int i;
@ -87,7 +87,7 @@
/// <param name="blockBufferOffset">The block buffer offset</param>
/// <param name="computationBuffer">The computational buffer for holding temp values</param>
/// <param name="quantizationTable">The quantization table</param>
public static void QuantizeAndInverse(ref FrameComponent component, int blockBufferOffset, ref Span<short> computationBuffer, ref Span<short> quantizationTable)
public static void QuantizeAndInverse(ref PdfJsFrameComponent component, int blockBufferOffset, ref Span<short> computationBuffer, ref Span<short> quantizationTable)
{
Span<short> blockData = component.BlockData.Slice(blockBufferOffset);
int v0, v1, v2, v3, v4, v5, v6, v7;
@ -306,7 +306,7 @@
/// <param name="blockBufferOffset">The block buffer offset</param>
/// <param name="computationBuffer">The computational buffer for holding temp values</param>
/// <param name="multiplierTable">The multiplier table</param>
public static void QuantizeAndInverseFast(ref FrameComponent component, int blockBufferOffset, ref Span<short> computationBuffer, ref Span<short> multiplierTable)
public static void QuantizeAndInverseFast(ref PdfJsFrameComponent component, int blockBufferOffset, ref Span<short> computationBuffer, ref Span<short> multiplierTable)
{
Span<short> blockData = component.BlockData.Slice(blockBufferOffset);
int p0, p1, p2, p3, p4, p5, p6, p7;

8
src/ImageSharp/Formats/Jpeg/Port/Components/JFif.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsJFif.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
@ -11,7 +11,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// Provides information about the JFIF marker segment
/// TODO: Thumbnail?
/// </summary>
internal struct JFif : IEquatable<JFif>
internal struct PdfJsJFif : IEquatable<PdfJsJFif>
{
/// <summary>
/// The major version
@ -42,7 +42,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
public short YDensity;
/// <inheritdoc/>
public bool Equals(JFif other)
public bool Equals(PdfJsJFif other)
{
return this.MajorVersion == other.MajorVersion
&& this.MinorVersion == other.MinorVersion
@ -59,7 +59,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
return false;
}
return obj is JFif && this.Equals((JFif)obj);
return obj is PdfJsJFif && this.Equals((PdfJsJFif)obj);
}
/// <inheritdoc/>

10
src/ImageSharp/Formats/Jpeg/Port/Components/JpegPixelArea.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsJpegPixelArea.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
using System.Diagnostics;
@ -14,7 +14,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// <summary>
/// Represents a section of the jpeg component data laid out in pixel order.
/// </summary>
internal struct JpegPixelArea : IDisposable
internal struct PdfJsJpegPixelArea : IDisposable
{
private readonly int imageWidth;
@ -25,12 +25,12 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
private int rowStride;
/// <summary>
/// Initializes a new instance of the <see cref="JpegPixelArea"/> struct.
/// Initializes a new instance of the <see cref="PdfJsJpegPixelArea"/> struct.
/// </summary>
/// <param name="imageWidth">The image width</param>
/// <param name="imageHeight">The image height</param>
/// <param name="numberOfComponents">The number of components</param>
public JpegPixelArea(int imageWidth, int imageHeight, int numberOfComponents)
public PdfJsJpegPixelArea(int imageWidth, int imageHeight, int numberOfComponents)
{
this.imageWidth = imageWidth;
this.imageHeight = imageHeight;
@ -80,7 +80,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
Span<int> xScaleBlockOffsetSpan = xScaleBlockOffset;
for (int i = 0; i < numberOfComponents; i++)
{
ref Component component = ref components.Components[i];
ref PdfJsComponent component = ref components.Components[i];
Vector2 componentScale = component.Scale * scale;
int offset = i;
Span<short> output = component.Output;

4
src/ImageSharp/Formats/Jpeg/Port/Components/QuantizationTables.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsQuantizationTables.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
using System.Runtime.CompilerServices;
@ -13,7 +13,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// <summary>
/// Contains the quantization tables.
/// </summary>
internal sealed class QuantizationTables : IDisposable
internal sealed class PdfJsQuantizationTables : IDisposable
{
/// <summary>
/// Gets the ZigZag scan table

124
src/ImageSharp/Formats/Jpeg/Port/Components/ScanDecoder.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsScanDecoder.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System;
#if DEBUG
@ -15,7 +15,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// <summary>
/// Provides the means to decode a spectral scan
/// </summary>
internal struct ScanDecoder
internal struct PdfJsScanDecoder
{
private byte[] markerBuffer;
@ -63,11 +63,11 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
/// <param name="successivePrev">The successive approximation bit high end</param>
/// <param name="successive">The successive approximation bit low end</param>
public void DecodeScan(
Frame frame,
PdfJsFrame frame,
Stream stream,
HuffmanTables dcHuffmanTables,
HuffmanTables acHuffmanTables,
FrameComponent[] components,
PdfJsHuffmanTables dcHuffmanTables,
PdfJsHuffmanTables acHuffmanTables,
PdfJsFrameComponent[] components,
int componentIndex,
int componentsLength,
ushort resetInterval,
@ -98,14 +98,14 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
mcuExpected = mcusPerLine * frame.McusPerColumn;
}
FileMarker fileMarker;
PdfJsFileMarker fileMarker;
while (mcu < mcuExpected)
{
// Reset interval stuff
int mcuToRead = resetInterval != 0 ? Math.Min(mcuExpected - mcu, resetInterval) : mcuExpected;
for (int i = 0; i < components.Length; i++)
{
ref FrameComponent c = ref components[i];
ref PdfJsFrameComponent c = ref components[i];
c.Pred = 0;
}
@ -145,7 +145,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
this.bitsCount = 0;
this.accumulator = 0;
this.bitsUnRead = 0;
fileMarker = JpegDecoderCore.FindNextFileMarker(this.markerBuffer, stream);
fileMarker = PdfJsJpegDecoderCore.FindNextFileMarker(this.markerBuffer, stream);
// Some bad images seem to pad Scan blocks with e.g. zero bytes, skip past
// those to attempt to find a valid marker (fixes issue4090.pdf) in original code.
@ -159,7 +159,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
ushort marker = fileMarker.Marker;
// RSTn - We've alread read the bytes and altered the position so no need to skip
if (marker >= JpegConstants.Markers.RST0 && marker <= JpegConstants.Markers.RST7)
if (marker >= PdfJsJpegConstants.Markers.RST0 && marker <= PdfJsJpegConstants.Markers.RST7)
{
continue;
}
@ -173,7 +173,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
}
fileMarker = JpegDecoderCore.FindNextFileMarker(this.markerBuffer, stream);
fileMarker = PdfJsJpegDecoderCore.FindNextFileMarker(this.markerBuffer, stream);
// Some images include more Scan blocks than expected, skip past those and
// attempt to find the next valid marker (fixes issue8182.pdf) in original code.
@ -192,16 +192,16 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int GetBlockBufferOffset(FrameComponent component, int row, int col)
private static int GetBlockBufferOffset(PdfJsFrameComponent component, int row, int col)
{
return 64 * (((component.BlocksPerLine + 1) * row) + col);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeScanBaseline(
HuffmanTables dcHuffmanTables,
HuffmanTables acHuffmanTables,
FrameComponent[] components,
PdfJsHuffmanTables dcHuffmanTables,
PdfJsHuffmanTables acHuffmanTables,
PdfJsFrameComponent[] components,
int componentsLength,
int mcusPerLine,
int mcuToRead,
@ -210,9 +210,9 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
{
if (componentsLength == 1)
{
ref FrameComponent component = ref components[this.compIndex];
ref HuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId];
ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
ref PdfJsFrameComponent component = ref components[this.compIndex];
ref PdfJsHuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId];
ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
for (int n = 0; n < mcuToRead; n++)
{
@ -231,9 +231,9 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
{
for (int i = 0; i < componentsLength; i++)
{
ref FrameComponent component = ref components[i];
ref HuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId];
ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
ref PdfJsFrameComponent component = ref components[i];
ref PdfJsHuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId];
ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
int h = component.HorizontalFactor;
int v = component.VerticalFactor;
@ -258,8 +258,8 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeScanDCFirst(
HuffmanTables dcHuffmanTables,
FrameComponent[] components,
PdfJsHuffmanTables dcHuffmanTables,
PdfJsFrameComponent[] components,
int componentsLength,
int mcusPerLine,
int mcuToRead,
@ -268,8 +268,8 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
{
if (componentsLength == 1)
{
ref FrameComponent component = ref components[this.compIndex];
ref HuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId];
ref PdfJsFrameComponent component = ref components[this.compIndex];
ref PdfJsHuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId];
for (int n = 0; n < mcuToRead; n++)
{
@ -288,8 +288,8 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
{
for (int i = 0; i < componentsLength; i++)
{
ref FrameComponent component = ref components[i];
ref HuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId];
ref PdfJsFrameComponent component = ref components[i];
ref PdfJsHuffmanTable dcHuffmanTable = ref dcHuffmanTables[component.DCHuffmanTableId];
int h = component.HorizontalFactor;
int v = component.VerticalFactor;
@ -314,7 +314,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeScanDCSuccessive(
FrameComponent[] components,
PdfJsFrameComponent[] components,
int componentsLength,
int mcusPerLine,
int mcuToRead,
@ -323,7 +323,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
{
if (componentsLength == 1)
{
ref FrameComponent component = ref components[this.compIndex];
ref PdfJsFrameComponent component = ref components[this.compIndex];
for (int n = 0; n < mcuToRead; n++)
{
if (this.endOfStreamReached || this.unexpectedMarkerReached)
@ -341,7 +341,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
{
for (int i = 0; i < componentsLength; i++)
{
ref FrameComponent component = ref components[i];
ref PdfJsFrameComponent component = ref components[i];
int h = component.HorizontalFactor;
int v = component.VerticalFactor;
for (int j = 0; j < v; j++)
@ -365,8 +365,8 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeScanACFirst(
HuffmanTables acHuffmanTables,
FrameComponent[] components,
PdfJsHuffmanTables acHuffmanTables,
PdfJsFrameComponent[] components,
int componentsLength,
int mcusPerLine,
int mcuToRead,
@ -375,8 +375,8 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
{
if (componentsLength == 1)
{
ref FrameComponent component = ref components[this.compIndex];
ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
ref PdfJsFrameComponent component = ref components[this.compIndex];
ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
for (int n = 0; n < mcuToRead; n++)
{
@ -395,8 +395,8 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
{
for (int i = 0; i < componentsLength; i++)
{
ref FrameComponent component = ref components[i];
ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
ref PdfJsFrameComponent component = ref components[i];
ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
int h = component.HorizontalFactor;
int v = component.VerticalFactor;
@ -421,8 +421,8 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeScanACSuccessive(
HuffmanTables acHuffmanTables,
FrameComponent[] components,
PdfJsHuffmanTables acHuffmanTables,
PdfJsFrameComponent[] components,
int componentsLength,
int mcusPerLine,
int mcuToRead,
@ -431,8 +431,8 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
{
if (componentsLength == 1)
{
ref FrameComponent component = ref components[this.compIndex];
ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
ref PdfJsFrameComponent component = ref components[this.compIndex];
ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
for (int n = 0; n < mcuToRead; n++)
{
@ -451,8 +451,8 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
{
for (int i = 0; i < componentsLength; i++)
{
ref FrameComponent component = ref components[i];
ref HuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
ref PdfJsFrameComponent component = ref components[i];
ref PdfJsHuffmanTable acHuffmanTable = ref acHuffmanTables[component.ACHuffmanTableId];
int h = component.HorizontalFactor;
int v = component.VerticalFactor;
@ -476,7 +476,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeBlockBaseline(ref HuffmanTable dcHuffmanTable, ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcu, Stream stream)
private void DecodeBlockBaseline(ref PdfJsHuffmanTable dcHuffmanTable, ref PdfJsHuffmanTable acHuffmanTable, ref PdfJsFrameComponent component, int mcu, Stream stream)
{
int blockRow = mcu / component.BlocksPerLine;
int blockCol = mcu % component.BlocksPerLine;
@ -485,7 +485,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeMcuBaseline(ref HuffmanTable dcHuffmanTable, ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream)
private void DecodeMcuBaseline(ref PdfJsHuffmanTable dcHuffmanTable, ref PdfJsHuffmanTable acHuffmanTable, ref PdfJsFrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream)
{
int mcuRow = mcu / mcusPerLine;
int mcuCol = mcu % mcusPerLine;
@ -496,7 +496,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeBlockDCFirst(ref HuffmanTable dcHuffmanTable, ref FrameComponent component, int mcu, Stream stream)
private void DecodeBlockDCFirst(ref PdfJsHuffmanTable dcHuffmanTable, ref PdfJsFrameComponent component, int mcu, Stream stream)
{
int blockRow = mcu / component.BlocksPerLine;
int blockCol = mcu % component.BlocksPerLine;
@ -505,7 +505,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeMcuDCFirst(ref HuffmanTable dcHuffmanTable, ref FrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream)
private void DecodeMcuDCFirst(ref PdfJsHuffmanTable dcHuffmanTable, ref PdfJsFrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream)
{
int mcuRow = mcu / mcusPerLine;
int mcuCol = mcu % mcusPerLine;
@ -516,7 +516,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeBlockDCSuccessive(ref FrameComponent component, int mcu, Stream stream)
private void DecodeBlockDCSuccessive(ref PdfJsFrameComponent component, int mcu, Stream stream)
{
int blockRow = mcu / component.BlocksPerLine;
int blockCol = mcu % component.BlocksPerLine;
@ -525,7 +525,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeMcuDCSuccessive(ref FrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream)
private void DecodeMcuDCSuccessive(ref PdfJsFrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream)
{
int mcuRow = mcu / mcusPerLine;
int mcuCol = mcu % mcusPerLine;
@ -536,7 +536,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeBlockACFirst(ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcu, Stream stream)
private void DecodeBlockACFirst(ref PdfJsHuffmanTable acHuffmanTable, ref PdfJsFrameComponent component, int mcu, Stream stream)
{
int blockRow = mcu / component.BlocksPerLine;
int blockCol = mcu % component.BlocksPerLine;
@ -545,7 +545,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeMcuACFirst(ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream)
private void DecodeMcuACFirst(ref PdfJsHuffmanTable acHuffmanTable, ref PdfJsFrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream)
{
int mcuRow = mcu / mcusPerLine;
int mcuCol = mcu % mcusPerLine;
@ -556,7 +556,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeBlockACSuccessive(ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcu, Stream stream)
private void DecodeBlockACSuccessive(ref PdfJsHuffmanTable acHuffmanTable, ref PdfJsFrameComponent component, int mcu, Stream stream)
{
int blockRow = mcu / component.BlocksPerLine;
int blockCol = mcu % component.BlocksPerLine;
@ -565,7 +565,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeMcuACSuccessive(ref HuffmanTable acHuffmanTable, ref FrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream)
private void DecodeMcuACSuccessive(ref PdfJsHuffmanTable acHuffmanTable, ref PdfJsFrameComponent component, int mcusPerLine, int mcu, int row, int col, Stream stream)
{
int mcuRow = mcu / mcusPerLine;
int mcuCol = mcu % mcusPerLine;
@ -593,7 +593,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
this.endOfStreamReached = true;
}
if (this.bitsData == JpegConstants.Markers.Prefix)
if (this.bitsData == PdfJsJpegConstants.Markers.Prefix)
{
int nextByte = stream.ReadByte();
if (nextByte != 0)
@ -616,7 +616,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private short DecodeHuffman(ref HuffmanTable tree, Stream stream)
private short DecodeHuffman(ref PdfJsHuffmanTable tree, Stream stream)
{
short code = -1;
@ -715,7 +715,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeBaseline(ref FrameComponent component, int offset, ref HuffmanTable dcHuffmanTable, ref HuffmanTable acHuffmanTable, Stream stream)
private void DecodeBaseline(ref PdfJsFrameComponent component, int offset, ref PdfJsHuffmanTable dcHuffmanTable, ref PdfJsHuffmanTable acHuffmanTable, Stream stream)
{
int t = this.DecodeHuffman(ref dcHuffmanTable, stream);
if (this.endOfStreamReached || this.unexpectedMarkerReached)
@ -756,7 +756,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
break;
}
byte z = QuantizationTables.DctZigZag[k];
byte z = PdfJsQuantizationTables.DctZigZag[k];
short re = (short)this.ReceiveAndExtend(s, stream);
component.BlockData[offset + z] = re;
k++;
@ -764,7 +764,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeDCFirst(ref FrameComponent component, int offset, ref HuffmanTable dcHuffmanTable, Stream stream)
private void DecodeDCFirst(ref PdfJsFrameComponent component, int offset, ref PdfJsHuffmanTable dcHuffmanTable, Stream stream)
{
int t = this.DecodeHuffman(ref dcHuffmanTable, stream);
if (this.endOfStreamReached || this.unexpectedMarkerReached)
@ -777,7 +777,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeDCSuccessive(ref FrameComponent component, int offset, Stream stream)
private void DecodeDCSuccessive(ref PdfJsFrameComponent component, int offset, Stream stream)
{
int bit = this.ReadBit(stream);
if (this.endOfStreamReached || this.unexpectedMarkerReached)
@ -789,7 +789,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeACFirst(ref FrameComponent component, int offset, ref HuffmanTable acHuffmanTable, Stream stream)
private void DecodeACFirst(ref PdfJsFrameComponent component, int offset, ref PdfJsHuffmanTable acHuffmanTable, Stream stream)
{
if (this.eobrun > 0)
{
@ -824,14 +824,14 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
}
k += r;
byte z = QuantizationTables.DctZigZag[k];
byte z = PdfJsQuantizationTables.DctZigZag[k];
componentBlockDataSpan[offset + z] = (short)(this.ReceiveAndExtend(s, stream) * (1 << this.successiveState));
k++;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DecodeACSuccessive(ref FrameComponent component, int offset, ref HuffmanTable acHuffmanTable, Stream stream)
private void DecodeACSuccessive(ref PdfJsFrameComponent component, int offset, ref PdfJsHuffmanTable acHuffmanTable, Stream stream)
{
int k = this.specStart;
int e = this.specEnd;
@ -839,7 +839,7 @@ namespace ImageSharp.Formats.Jpeg.Port.Components
Span<short> componentBlockDataSpan = component.BlockData.Span;
while (k <= e)
{
byte z = QuantizationTables.DctZigZag[k];
byte z = PdfJsQuantizationTables.DctZigZag[k];
switch (this.successiveACState)
{
case 0: // Initial state

4
src/ImageSharp/Formats/Jpeg/Port/Components/YCbCrToRgbTables.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsYCbCrToRgbTables.cs

@ -1,4 +1,4 @@
namespace ImageSharp.Formats.Jpeg.Port.Components
namespace ImageSharp.Formats.Jpeg.PdfJsPort.Components
{
using System.Runtime.CompilerServices;
using ImageSharp.PixelFormats;
@ -7,7 +7,7 @@
/// Provides 8-bit lookup tables for converting from YCbCr to Rgb colorspace.
/// Methods to build the tables are based on libjpeg implementation.
/// </summary>
internal struct YCbCrToRgbTables
internal struct PdfJsYCbCrToRgbTables
{
/// <summary>
/// The red red-chrominance table

4
src/ImageSharp/Formats/Jpeg/Port/JpegConstants.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegConstants.cs

@ -4,12 +4,12 @@
// </copyright>
// ReSharper disable InconsistentNaming
namespace ImageSharp.Formats.Jpeg.Port
namespace ImageSharp.Formats.Jpeg.PdfJsPort
{
/// <summary>
/// Contains jpeg constant values
/// </summary>
internal static class JpegConstants
internal static class PdfJsJpegConstants
{
/// <summary>
/// Contains marker specific constants

215
src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs → src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

@ -3,14 +3,15 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Port
namespace ImageSharp.Formats.Jpeg.PdfJsPort
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using ImageSharp.Formats.Jpeg.Port.Components;
using ImageSharp.Formats.Jpeg.PdfJsPort.Components;
using ImageSharp.Memory;
using ImageSharp.PixelFormats;
@ -18,7 +19,7 @@ namespace ImageSharp.Formats.Jpeg.Port
/// Performs the jpeg decoding operation.
/// Ported from <see href="https://github.com/mozilla/pdf.js/blob/master/src/core/jpg.js"/> with additional fixes to handle common encoding errors
/// </summary>
internal sealed class JpegDecoderCore : IDisposable
internal sealed class PdfJsJpegDecoderCore : IDisposable
{
/// <summary>
/// The global configuration
@ -32,17 +33,17 @@ namespace ImageSharp.Formats.Jpeg.Port
private readonly byte[] markerBuffer = new byte[2];
private QuantizationTables quantizationTables;
private PdfJsQuantizationTables quantizationTables;
private HuffmanTables dcHuffmanTables;
private PdfJsHuffmanTables dcHuffmanTables;
private HuffmanTables acHuffmanTables;
private PdfJsHuffmanTables acHuffmanTables;
private Frame frame;
private PdfJsFrame frame;
private ComponentBlocks components;
private JpegPixelArea pixelArea;
private PdfJsJpegPixelArea pixelArea;
private ushort resetInterval;
@ -60,27 +61,27 @@ namespace ImageSharp.Formats.Jpeg.Port
/// <summary>
/// Contains information about the JFIF marker
/// </summary>
private JFif jFif;
private PdfJsJFif jFif;
/// <summary>
/// Contains information about the Adobe marker
/// </summary>
private Adobe adobe;
private PdfJsAdobe adobe;
/// <summary>
/// Initializes static members of the <see cref="JpegDecoderCore"/> class.
/// Initializes static members of the <see cref="PdfJsJpegDecoderCore"/> class.
/// </summary>
static JpegDecoderCore()
static PdfJsJpegDecoderCore()
{
YCbCrToRgbTables.Create();
PdfJsYCbCrToRgbTables.Create();
}
/// <summary>
/// Initializes a new instance of the <see cref="JpegDecoderCore" /> class.
/// Initializes a new instance of the <see cref="PdfJsJpegDecoderCore" /> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="options">The options.</param>
public JpegDecoderCore(Configuration configuration, IJpegDecoderOptions options)
public PdfJsJpegDecoderCore(Configuration configuration, IJpegDecoderOptions options)
{
this.configuration = configuration ?? Configuration.Default;
this.IgnoreMetadata = options.IgnoreMetadata;
@ -101,35 +102,35 @@ namespace ImageSharp.Formats.Jpeg.Port
/// </summary>
/// <param name="marker">The buffer to read file markers to</param>
/// <param name="stream">The input stream</param>
/// <returns>The <see cref="FileMarker"/></returns>
public static FileMarker FindNextFileMarker(byte[] marker, Stream stream)
/// <returns>The <see cref="PdfJsFileMarker"/></returns>
public static PdfJsFileMarker FindNextFileMarker(byte[] marker, Stream stream)
{
int value = stream.Read(marker, 0, 2);
if (value == 0)
{
return new FileMarker(JpegConstants.Markers.EOI, (int)stream.Length - 2);
return new PdfJsFileMarker(PdfJsJpegConstants.Markers.EOI, (int)stream.Length - 2);
}
if (marker[0] == JpegConstants.Markers.Prefix)
if (marker[0] == PdfJsJpegConstants.Markers.Prefix)
{
// According to Section B.1.1.2:
// "Any marker may optionally be preceded by any number of fill bytes, which are bytes assigned code 0xFF."
while (marker[1] == JpegConstants.Markers.Prefix)
while (marker[1] == PdfJsJpegConstants.Markers.Prefix)
{
int suffix = stream.ReadByte();
if (suffix == -1)
{
return new FileMarker(JpegConstants.Markers.EOI, (int)stream.Length - 2);
return new PdfJsFileMarker(PdfJsJpegConstants.Markers.EOI, (int)stream.Length - 2);
}
marker[1] = (byte)value;
}
return new FileMarker((ushort)((marker[0] << 8) | marker[1]), (int)(stream.Position - 2));
return new PdfJsFileMarker((ushort)((marker[0] << 8) | marker[1]), (int)(stream.Position - 2));
}
return new FileMarker((ushort)((marker[0] << 8) | marker[1]), (int)(stream.Position - 2), true);
return new PdfJsFileMarker((ushort)((marker[0] << 8) | marker[1]), (int)(stream.Position - 2), true);
}
/// <summary>
@ -171,7 +172,7 @@ namespace ImageSharp.Formats.Jpeg.Port
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int GetBlockBufferOffset(ref Component component, int row, int col)
private static int GetBlockBufferOffset(ref PdfJsComponent component, int row, int col)
{
return 64 * (((component.BlocksPerLine + 1) * row) + col);
}
@ -185,79 +186,79 @@ namespace ImageSharp.Formats.Jpeg.Port
{
// TODO: metadata only logic
// Check for the Start Of Image marker.
var fileMarker = new FileMarker(this.ReadUint16(), 0);
if (fileMarker.Marker != JpegConstants.Markers.SOI)
var fileMarker = new PdfJsFileMarker(this.ReadUint16(), 0);
if (fileMarker.Marker != PdfJsJpegConstants.Markers.SOI)
{
throw new ImageFormatException("Missing SOI marker.");
}
ushort marker = this.ReadUint16();
fileMarker = new FileMarker(marker, (int)this.InputStream.Position - 2);
fileMarker = new PdfJsFileMarker(marker, (int)this.InputStream.Position - 2);
this.quantizationTables = new QuantizationTables();
this.dcHuffmanTables = new HuffmanTables();
this.acHuffmanTables = new HuffmanTables();
this.quantizationTables = new PdfJsQuantizationTables();
this.dcHuffmanTables = new PdfJsHuffmanTables();
this.acHuffmanTables = new PdfJsHuffmanTables();
while (fileMarker.Marker != JpegConstants.Markers.EOI)
while (fileMarker.Marker != PdfJsJpegConstants.Markers.EOI)
{
// Get the marker length
int remaining = this.ReadUint16() - 2;
switch (fileMarker.Marker)
{
case JpegConstants.Markers.APP0:
case PdfJsJpegConstants.Markers.APP0:
this.ProcessApplicationHeaderMarker(remaining);
break;
case JpegConstants.Markers.APP1:
case PdfJsJpegConstants.Markers.APP1:
this.ProcessApp1Marker(remaining, metaData);
break;
case JpegConstants.Markers.APP2:
case PdfJsJpegConstants.Markers.APP2:
this.ProcessApp2Marker(remaining, metaData);
break;
case JpegConstants.Markers.APP3:
case JpegConstants.Markers.APP4:
case JpegConstants.Markers.APP5:
case JpegConstants.Markers.APP6:
case JpegConstants.Markers.APP7:
case JpegConstants.Markers.APP8:
case JpegConstants.Markers.APP9:
case JpegConstants.Markers.APP10:
case JpegConstants.Markers.APP11:
case JpegConstants.Markers.APP12:
case JpegConstants.Markers.APP13:
case PdfJsJpegConstants.Markers.APP3:
case PdfJsJpegConstants.Markers.APP4:
case PdfJsJpegConstants.Markers.APP5:
case PdfJsJpegConstants.Markers.APP6:
case PdfJsJpegConstants.Markers.APP7:
case PdfJsJpegConstants.Markers.APP8:
case PdfJsJpegConstants.Markers.APP9:
case PdfJsJpegConstants.Markers.APP10:
case PdfJsJpegConstants.Markers.APP11:
case PdfJsJpegConstants.Markers.APP12:
case PdfJsJpegConstants.Markers.APP13:
this.InputStream.Skip(remaining);
break;
case JpegConstants.Markers.APP14:
case PdfJsJpegConstants.Markers.APP14:
this.ProcessApp14Marker(remaining);
break;
case JpegConstants.Markers.APP15:
case JpegConstants.Markers.COM:
case PdfJsJpegConstants.Markers.APP15:
case PdfJsJpegConstants.Markers.COM:
this.InputStream.Skip(remaining);
break;
case JpegConstants.Markers.DQT:
case PdfJsJpegConstants.Markers.DQT:
this.ProcessDefineQuantizationTablesMarker(remaining);
break;
case JpegConstants.Markers.SOF0:
case JpegConstants.Markers.SOF1:
case JpegConstants.Markers.SOF2:
case PdfJsJpegConstants.Markers.SOF0:
case PdfJsJpegConstants.Markers.SOF1:
case PdfJsJpegConstants.Markers.SOF2:
this.ProcessStartOfFrameMarker(remaining, fileMarker);
break;
case JpegConstants.Markers.DHT:
case PdfJsJpegConstants.Markers.DHT:
this.ProcessDefineHuffmanTablesMarker(remaining);
break;
case JpegConstants.Markers.DRI:
case PdfJsJpegConstants.Markers.DRI:
this.ProcessDefineRestartIntervalMarker(remaining);
break;
case JpegConstants.Markers.SOS:
case PdfJsJpegConstants.Markers.SOS:
this.ProcessStartOfScanMarker();
break;
}
@ -268,12 +269,12 @@ namespace ImageSharp.Formats.Jpeg.Port
this.imageWidth = this.frame.SamplesPerLine;
this.imageHeight = this.frame.Scanlines;
this.components = new ComponentBlocks { Components = new Component[this.frame.ComponentCount] };
this.components = new ComponentBlocks { Components = new PdfJsComponent[this.frame.ComponentCount] };
for (int i = 0; i < this.components.Components.Length; i++)
{
ref var frameComponent = ref this.frame.Components[i];
var component = new Component
var component = new PdfJsComponent
{
Scale = new System.Numerics.Vector2(
frameComponent.HorizontalFactor / (float)this.frame.MaxHorizontalFactor,
@ -302,7 +303,7 @@ namespace ImageSharp.Formats.Jpeg.Port
throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.numberOfComponents}");
}
this.pixelArea = new JpegPixelArea(image.Width, image.Height, this.numberOfComponents);
this.pixelArea = new PdfJsJpegPixelArea(image.Width, image.Height, this.numberOfComponents);
this.pixelArea.LinearizeBlockData(this.components, image.Width, image.Height);
if (this.numberOfComponents == 1)
@ -313,11 +314,11 @@ namespace ImageSharp.Formats.Jpeg.Port
if (this.numberOfComponents == 3)
{
if (this.adobe.Equals(default(Adobe)) || this.adobe.ColorTransform == JpegConstants.Markers.Adobe.ColorTransformYCbCr)
if (this.adobe.Equals(default(PdfJsAdobe)) || this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYCbCr)
{
this.FillYCbCrImage(image);
}
else if (this.adobe.ColorTransform == JpegConstants.Markers.Adobe.ColorTransformUnknown)
else if (this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformUnknown)
{
this.FillRgbImage(image);
}
@ -325,7 +326,7 @@ namespace ImageSharp.Formats.Jpeg.Port
if (this.numberOfComponents == 4)
{
if (this.adobe.ColorTransform == JpegConstants.Markers.Adobe.ColorTransformYcck)
if (this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYcck)
{
this.FillYcckImage(image);
}
@ -380,15 +381,15 @@ namespace ImageSharp.Formats.Jpeg.Port
this.InputStream.Read(this.temp, 0, 13);
remaining -= 13;
bool isJfif = this.temp[0] == JpegConstants.Markers.JFif.J &&
this.temp[1] == JpegConstants.Markers.JFif.F &&
this.temp[2] == JpegConstants.Markers.JFif.I &&
this.temp[3] == JpegConstants.Markers.JFif.F &&
this.temp[4] == JpegConstants.Markers.JFif.Null;
bool isJfif = this.temp[0] == PdfJsJpegConstants.Markers.JFif.J &&
this.temp[1] == PdfJsJpegConstants.Markers.JFif.F &&
this.temp[2] == PdfJsJpegConstants.Markers.JFif.I &&
this.temp[3] == PdfJsJpegConstants.Markers.JFif.F &&
this.temp[4] == PdfJsJpegConstants.Markers.JFif.Null;
if (isJfif)
{
this.jFif = new JFif
this.jFif = new PdfJsJFif
{
MajorVersion = this.temp[5],
MinorVersion = this.temp[6],
@ -422,12 +423,12 @@ namespace ImageSharp.Formats.Jpeg.Port
byte[] profile = new byte[remaining];
this.InputStream.Read(profile, 0, remaining);
if (profile[0] == JpegConstants.Markers.Exif.E &&
profile[1] == JpegConstants.Markers.Exif.X &&
profile[2] == JpegConstants.Markers.Exif.I &&
profile[3] == JpegConstants.Markers.Exif.F &&
profile[4] == JpegConstants.Markers.Exif.Null &&
profile[5] == JpegConstants.Markers.Exif.Null)
if (profile[0] == PdfJsJpegConstants.Markers.Exif.E &&
profile[1] == PdfJsJpegConstants.Markers.Exif.X &&
profile[2] == PdfJsJpegConstants.Markers.Exif.I &&
profile[3] == PdfJsJpegConstants.Markers.Exif.F &&
profile[4] == PdfJsJpegConstants.Markers.Exif.Null &&
profile[5] == PdfJsJpegConstants.Markers.Exif.Null)
{
this.isExif = true;
metadata.ExifProfile = new ExifProfile(profile);
@ -453,18 +454,18 @@ namespace ImageSharp.Formats.Jpeg.Port
this.InputStream.Read(identifier, 0, Icclength);
remaining -= Icclength; // We have read it by this point
if (identifier[0] == JpegConstants.Markers.ICC.I &&
identifier[1] == JpegConstants.Markers.ICC.C &&
identifier[2] == JpegConstants.Markers.ICC.C &&
identifier[3] == JpegConstants.Markers.ICC.UnderScore &&
identifier[4] == JpegConstants.Markers.ICC.P &&
identifier[5] == JpegConstants.Markers.ICC.R &&
identifier[6] == JpegConstants.Markers.ICC.O &&
identifier[7] == JpegConstants.Markers.ICC.F &&
identifier[8] == JpegConstants.Markers.ICC.I &&
identifier[9] == JpegConstants.Markers.ICC.L &&
identifier[10] == JpegConstants.Markers.ICC.E &&
identifier[11] == JpegConstants.Markers.ICC.Null)
if (identifier[0] == PdfJsJpegConstants.Markers.ICC.I &&
identifier[1] == PdfJsJpegConstants.Markers.ICC.C &&
identifier[2] == PdfJsJpegConstants.Markers.ICC.C &&
identifier[3] == PdfJsJpegConstants.Markers.ICC.UnderScore &&
identifier[4] == PdfJsJpegConstants.Markers.ICC.P &&
identifier[5] == PdfJsJpegConstants.Markers.ICC.R &&
identifier[6] == PdfJsJpegConstants.Markers.ICC.O &&
identifier[7] == PdfJsJpegConstants.Markers.ICC.F &&
identifier[8] == PdfJsJpegConstants.Markers.ICC.I &&
identifier[9] == PdfJsJpegConstants.Markers.ICC.L &&
identifier[10] == PdfJsJpegConstants.Markers.ICC.E &&
identifier[11] == PdfJsJpegConstants.Markers.ICC.Null)
{
byte[] profile = new byte[remaining];
this.InputStream.Read(profile, 0, remaining);
@ -502,15 +503,15 @@ namespace ImageSharp.Formats.Jpeg.Port
this.InputStream.Read(this.temp, 0, 12);
remaining -= 12;
bool isAdobe = this.temp[0] == JpegConstants.Markers.Adobe.A &&
this.temp[1] == JpegConstants.Markers.Adobe.D &&
this.temp[2] == JpegConstants.Markers.Adobe.O &&
this.temp[3] == JpegConstants.Markers.Adobe.B &&
this.temp[4] == JpegConstants.Markers.Adobe.E;
bool isAdobe = this.temp[0] == PdfJsJpegConstants.Markers.Adobe.A &&
this.temp[1] == PdfJsJpegConstants.Markers.Adobe.D &&
this.temp[2] == PdfJsJpegConstants.Markers.Adobe.O &&
this.temp[3] == PdfJsJpegConstants.Markers.Adobe.B &&
this.temp[4] == PdfJsJpegConstants.Markers.Adobe.E;
if (isAdobe)
{
this.adobe = new Adobe
this.adobe = new PdfJsAdobe
{
DCTEncodeVersion = (short)((this.temp[5] << 8) | this.temp[6]),
APP14Flags0 = (short)((this.temp[7] << 8) | this.temp[8]),
@ -557,7 +558,7 @@ namespace ImageSharp.Formats.Jpeg.Port
Span<short> tableSpan = this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec & 15);
for (int j = 0; j < 64; j++)
{
tableSpan[QuantizationTables.DctZigZag[j]] = this.temp[j];
tableSpan[PdfJsQuantizationTables.DctZigZag[j]] = this.temp[j];
}
}
@ -577,7 +578,7 @@ namespace ImageSharp.Formats.Jpeg.Port
Span<short> tableSpan = this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec & 15);
for (int j = 0; j < 64; j++)
{
tableSpan[QuantizationTables.DctZigZag[j]] = (short)((this.temp[2 * j] << 8) | this.temp[(2 * j) + 1]);
tableSpan[PdfJsQuantizationTables.DctZigZag[j]] = (short)((this.temp[2 * j] << 8) | this.temp[(2 * j) + 1]);
}
}
@ -603,7 +604,7 @@ namespace ImageSharp.Formats.Jpeg.Port
/// </summary>
/// <param name="remaining">The remaining bytes in the segment block.</param>
/// <param name="frameMarker">The current frame marker.</param>
private void ProcessStartOfFrameMarker(int remaining, FileMarker frameMarker)
private void ProcessStartOfFrameMarker(int remaining, PdfJsFileMarker frameMarker)
{
if (this.frame != null)
{
@ -612,10 +613,10 @@ namespace ImageSharp.Formats.Jpeg.Port
this.InputStream.Read(this.temp, 0, remaining);
this.frame = new Frame
this.frame = new PdfJsFrame
{
Extended = frameMarker.Marker == JpegConstants.Markers.SOF1,
Progressive = frameMarker.Marker == JpegConstants.Markers.SOF2,
Extended = frameMarker.Marker == PdfJsJpegConstants.Markers.SOF1,
Progressive = frameMarker.Marker == PdfJsJpegConstants.Markers.SOF2,
Precision = this.temp[0],
Scanlines = (short)((this.temp[1] << 8) | this.temp[2]),
SamplesPerLine = (short)((this.temp[3] << 8) | this.temp[4]),
@ -628,7 +629,7 @@ namespace ImageSharp.Formats.Jpeg.Port
// No need to pool this. They max out at 4
this.frame.ComponentIds = new byte[this.frame.ComponentCount];
this.frame.Components = new FrameComponent[this.frame.ComponentCount];
this.frame.Components = new PdfJsFrameComponent[this.frame.ComponentCount];
for (int i = 0; i < this.frame.Components.Length; i++)
{
@ -747,7 +748,7 @@ namespace ImageSharp.Formats.Jpeg.Port
throw new ImageFormatException("Unknown component selector");
}
ref FrameComponent component = ref this.frame.Components[componentIndex];
ref PdfJsFrameComponent component = ref this.frame.Components[componentIndex];
int tableSpec = this.InputStream.ReadByte();
component.DCHuffmanTableId = tableSpec >> 4;
component.ACHuffmanTableId = tableSpec & 15;
@ -758,7 +759,7 @@ namespace ImageSharp.Formats.Jpeg.Port
int spectralStart = this.temp[0];
int spectralEnd = this.temp[1];
int successiveApproximation = this.temp[2];
var scanDecoder = default(ScanDecoder);
var scanDecoder = default(PdfJsScanDecoder);
scanDecoder.DecodeScan(
this.frame,
@ -780,7 +781,7 @@ namespace ImageSharp.Formats.Jpeg.Port
/// </summary>
/// <param name="component">The component</param>
/// <param name="frameComponent">The frame component</param>
private void BuildComponentData(ref Component component, ref FrameComponent frameComponent)
private void BuildComponentData(ref PdfJsComponent component, ref PdfJsFrameComponent frameComponent)
{
int blocksPerLine = component.BlocksPerLine;
int blocksPerColumn = component.BlocksPerColumn;
@ -798,7 +799,7 @@ namespace ImageSharp.Formats.Jpeg.Port
Span<short> multiplierSpan = multiplicationBuffer;
for (int i = 0; i < 64; i++)
{
multiplierSpan[i] = (short)IDCT.Descale(quantizationTable[i] * IDCT.Aanscales[i], 12);
multiplierSpan[i] = (short)PdfJsIDCT.Descale(quantizationTable[i] * PdfJsIDCT.Aanscales[i], 12);
}
for (int blockRow = 0; blockRow < blocksPerColumn; blockRow++)
@ -806,7 +807,7 @@ namespace ImageSharp.Formats.Jpeg.Port
for (int blockCol = 0; blockCol < blocksPerLine; blockCol++)
{
int offset = GetBlockBufferOffset(ref component, blockRow, blockCol);
IDCT.QuantizeAndInverseFast(ref frameComponent, offset, ref computationBufferSpan, ref multiplierSpan);
PdfJsIDCT.QuantizeAndInverseFast(ref frameComponent, offset, ref computationBufferSpan, ref multiplierSpan);
}
}
}
@ -821,9 +822,9 @@ namespace ImageSharp.Formats.Jpeg.Port
/// <param name="index">The table index</param>
/// <param name="codeLengths">The codelengths</param>
/// <param name="values">The values</param>
private void BuildHuffmanTable(HuffmanTables tables, int index, byte[] codeLengths, byte[] values)
private void BuildHuffmanTable(PdfJsHuffmanTables tables, int index, byte[] codeLengths, byte[] values)
{
tables[index] = new HuffmanTable(codeLengths, values);
tables[index] = new PdfJsHuffmanTable(codeLengths, values);
}
/// <summary>
@ -887,7 +888,7 @@ namespace ImageSharp.Formats.Jpeg.Port
ref byte cb = ref areaRowSpan[o + 1];
ref byte cr = ref areaRowSpan[o + 2];
ref TPixel pixel = ref imageRowSpan[x];
YCbCrToRgbTables.PackYCbCr(ref pixel, yy, cb, cr);
PdfJsYCbCrToRgbTables.PackYCbCr(ref pixel, yy, cb, cr);
}
}
}
@ -908,7 +909,7 @@ namespace ImageSharp.Formats.Jpeg.Port
ref byte k = ref areaRowSpan[o + 3];
ref TPixel pixel = ref imageRowSpan[x];
YCbCrToRgbTables.PackYccK(ref pixel, yy, cb, cr, k);
PdfJsYCbCrToRgbTables.PackYccK(ref pixel, yy, cb, cr, k);
}
}
}

3
src/ImageSharp/ImageSharp.csproj

@ -104,4 +104,7 @@
<DependentUpon>PorterDuffFunctions.Generated.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="PdfJsPort\Jpeg\Formats\" />
</ItemGroup>
</Project>
Loading…
Cancel
Save