mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-04-05 20:55:01 +08:00
Merge pull request #326 from kasperdaff/ccitt-fax-filter-fixes
Fixes for recent CCITT Fax Filter implementation
This commit is contained in:
commit
636936330a
@ -6,16 +6,20 @@
|
||||
internal enum CcittFaxCompressionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Modified Huffman - Group 3 (T4)
|
||||
/// Modified Huffman (MH) - Group 3 variation (T2)
|
||||
/// </summary>
|
||||
ModifiedHuffman,
|
||||
/// <summary>
|
||||
/// Modified Read - Group 3 (optional T4)
|
||||
/// Modified Huffman (MH) - Group 3 (T4)
|
||||
/// </summary>
|
||||
T4,
|
||||
Group3_1D,
|
||||
/// <summary>
|
||||
/// Modified Modified Read - Group 4 (T6)
|
||||
/// Modified Read (MR) - Group 3 (T4)
|
||||
/// </summary>
|
||||
T6
|
||||
Group3_2D,
|
||||
/// <summary>
|
||||
/// Modified Modified Read (MMR) - Group 4 (T6)
|
||||
/// </summary>
|
||||
Group4_2D
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@
|
||||
{
|
||||
if (k == 0)
|
||||
{
|
||||
var compressionType = CcittFaxCompressionType.T4; // Group 3 1D
|
||||
var compressionType = CcittFaxCompressionType.Group3_1D; // Group 3 1D
|
||||
|
||||
if (input.Count < 20)
|
||||
{
|
||||
@ -78,7 +78,7 @@
|
||||
b = (short)((b << 1) + ((input[(i / 8)] >> (7 - (i % 8))) & 0x01));
|
||||
if ((b & 0xFFF) == 1)
|
||||
{
|
||||
return CcittFaxCompressionType.T4;
|
||||
return CcittFaxCompressionType.Group3_1D;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,11 +88,11 @@
|
||||
else if (k > 0)
|
||||
{
|
||||
// Group 3 2D
|
||||
return CcittFaxCompressionType.T4;
|
||||
return CcittFaxCompressionType.Group3_2D;
|
||||
}
|
||||
else
|
||||
{
|
||||
return CcittFaxCompressionType.T6;
|
||||
return CcittFaxCompressionType.Group4_2D;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
private readonly int columns;
|
||||
private readonly byte[] decodedRow;
|
||||
|
||||
private readonly bool optionG32D;
|
||||
private readonly bool optionByteAligned;
|
||||
|
||||
private readonly CcittFaxCompressionType type;
|
||||
@ -52,20 +51,6 @@
|
||||
changesCurrentRow = new int[columns + 2];
|
||||
|
||||
optionByteAligned = byteAligned;
|
||||
switch (type)
|
||||
{
|
||||
case CcittFaxCompressionType.ModifiedHuffman:
|
||||
optionG32D = false;
|
||||
break;
|
||||
case CcittFaxCompressionType.T4:
|
||||
optionG32D = true;
|
||||
break;
|
||||
case CcittFaxCompressionType.T6:
|
||||
optionG32D = false;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, "Illegal parameter");
|
||||
}
|
||||
}
|
||||
|
||||
private void Fetch()
|
||||
@ -252,7 +237,7 @@
|
||||
}
|
||||
|
||||
done:
|
||||
if (!optionG32D || ReadBit())
|
||||
if (type == CcittFaxCompressionType.Group3_1D || ReadBit())
|
||||
{
|
||||
Decode1D();
|
||||
}
|
||||
@ -279,10 +264,11 @@
|
||||
case CcittFaxCompressionType.ModifiedHuffman:
|
||||
DecodeRowType2();
|
||||
break;
|
||||
case CcittFaxCompressionType.T4:
|
||||
case CcittFaxCompressionType.Group3_1D:
|
||||
case CcittFaxCompressionType.Group3_2D:
|
||||
DecodeRowType4();
|
||||
break;
|
||||
case CcittFaxCompressionType.T6:
|
||||
case CcittFaxCompressionType.Group4_2D:
|
||||
DecodeRowType6();
|
||||
break;
|
||||
default:
|
||||
|
@ -10,7 +10,8 @@
|
||||
using Graphics.Colors;
|
||||
using Graphics.Core;
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
using Tokens;
|
||||
using UglyToad.PdfPig.Parser.Parts;
|
||||
using Util;
|
||||
|
||||
internal static class XObjectFactory
|
||||
@ -99,7 +100,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
var decodedBytes = supportsFilters ? new Lazy<IReadOnlyList<byte>>(() => xObject.Stream.Decode(filterProvider, pdfScanner))
|
||||
var decodeParams = dictionary.GetObjectOrDefault(NameToken.DecodeParms, NameToken.Dp);
|
||||
if (decodeParams is IndirectReferenceToken refToken)
|
||||
{
|
||||
dictionary = dictionary.With(NameToken.DecodeParms, pdfScanner.Get(refToken.Data).Data);
|
||||
}
|
||||
|
||||
var streamToken = new StreamToken(dictionary, xObject.Stream.Data);
|
||||
|
||||
var decodedBytes = supportsFilters ? new Lazy<IReadOnlyList<byte>>(() => streamToken.Decode(filterProvider, pdfScanner))
|
||||
: null;
|
||||
|
||||
var decode = EmptyArray<decimal>.Instance;
|
||||
|
Loading…
Reference in New Issue
Block a user