Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
namespace SharpCorePDF.Infrastructure.Pdf;

/// <summary>
/// Decodes a baseline (SOF0) or extended sequential (SOF1) JPEG to its samples.
/// Decodes a JPEG — baseline, extended sequential or progressive — to its samples.
/// </summary>
/// <remarks>
/// <para>
/// The decoder is a baseline one: one scan, canonical Huffman coding, an 8 x 8 inverse DCT, and the three
/// component layouts a PDF image states — Gray, RGB/YCbCr and CMYK/YCCK. Progressive (SOF2) is refused
/// for now; ADR-005 records it as the next variant.
/// The decoder reads the sequential form (SOF0/SOF1) and the progressive form (SOF2): a sequential scan
/// is decoded in one pass, while a progressive file's scans accumulate quantised coefficients that the
/// inverse DCT reconstructs once at the end. Both forms cover canonical Huffman coding, restart markers,
/// an 8 x 8 inverse DCT and the component layouts a PDF image states — Gray, RGB/YCbCr and CMYK/YCCK.
/// </para>
/// <para>
/// The samples are the values the JPEG stores, interleaved, one byte per component: <c>Gray8</c> for one
Expand Down Expand Up @@ -70,7 +71,7 @@
out int height) =>
new JpegDecoder(data).Run(maxBytes, out pixels, out format, out width, out height);

private bool Run(int maxBytes, out byte[]? pixels, out string? format, out int width, out int height)

Check warning on line 74 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 53 to the 15 allowed.

Check warning on line 74 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 53 to the 15 allowed.

Check warning on line 74 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 53 to the 15 allowed.

Check warning on line 74 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 53 to the 15 allowed.
{
pixels = null;
format = null;
Expand Down Expand Up @@ -450,7 +451,7 @@
public int BlocksY { get; set; }
}

private bool DecodeScan(

Check warning on line 454 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 40 to the 15 allowed.

Check warning on line 454 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 40 to the 15 allowed.

Check warning on line 454 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 40 to the 15 allowed.

Check warning on line 454 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 40 to the 15 allowed.
int scanStart,
int maxBytes,
out byte[]? pixels,
Expand Down Expand Up @@ -529,7 +530,7 @@
return BuildOutput(maxBytes, out pixels, out format);
}

private bool ReconstructProgressive()

Check warning on line 533 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.

Check warning on line 533 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.

Check warning on line 533 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.
{
var mcuWidth = 8 * maxH;
var mcuHeight = 8 * maxV;
Expand Down Expand Up @@ -576,7 +577,7 @@
return true;
}

private bool DecodeProgressiveScan(int dataStart, out int nextOffset)

Check warning on line 580 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 66 to the 15 allowed.

Check warning on line 580 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 66 to the 15 allowed.

Check warning on line 580 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 66 to the 15 allowed.
{
nextOffset = dataStart;
var mcuWidth = 8 * maxH;
Expand Down Expand Up @@ -676,7 +677,7 @@
return true;
}

private bool DecodeProgressiveBlock(ref JpegBits bits, JpegComponent component, int blockY, int blockX)

Check warning on line 680 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 107 to the 15 allowed.

Check warning on line 680 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 107 to the 15 allowed.

Check warning on line 680 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 107 to the 15 allowed.
{
var block = component.Coefficients.AsSpan(((blockY * component.BlocksX) + blockX) * 64, 64);

Expand Down Expand Up @@ -937,7 +938,7 @@
return true;
}

private bool DecodeBlock(ref JpegBits bits, JpegComponent component, int[] coefficients, byte[] samples)

Check warning on line 941 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

Check warning on line 941 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

Check warning on line 941 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.
{
var dcTable = dcTables[component.DcTable];
var acTable = acTables[component.AcTable];
Expand Down Expand Up @@ -1032,7 +1033,7 @@
}
}

private bool BuildOutput(int maxBytes, out byte[]? pixels, out string? format)

Check warning on line 1036 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 26 to the 15 allowed.

Check warning on line 1036 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 26 to the 15 allowed.

Check warning on line 1036 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Refactor this method to reduce its Cognitive Complexity from 26 to the 15 allowed.
{
pixels = null;
format = null;
Expand Down Expand Up @@ -1131,7 +1132,7 @@
/// even output position takes three parts of its sample and one of the neighbour before it, an odd one
/// three parts and one of the neighbour after it, rounded as libjpeg rounds.
/// </summary>
private static int Sample(

Check warning on line 1135 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Method has 9 parameters, which is greater than the 7 authorized.

Check warning on line 1135 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Method has 9 parameters, which is greater than the 7 authorized.

Check warning on line 1135 in src/SharpCorePDF.Infrastructure/Pdf/JpegDecoder.cs

View workflow job for this annotation

GitHub Actions / Build, test and analyse

Method has 9 parameters, which is greater than the 7 authorized.
byte[] plane,
int stride,
int rows,
Expand Down
Loading