mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-08-20 09:21:57 +08:00
normalize line endings in ccitt file
This commit is contained in:
parent
1b472f6992
commit
53471207df
@ -1,24 +1,24 @@
|
||||
namespace UglyToad.PdfPig.Filters
|
||||
{
|
||||
using System;
|
||||
namespace UglyToad.PdfPig.Filters
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Tokens;
|
||||
using UglyToad.PdfPig.Util;
|
||||
using Util;
|
||||
|
||||
/// <summary>
|
||||
/// Decodes image data that has been encoded using either Group 3 or Group 4.
|
||||
///
|
||||
/// Ported from https://github.com/apache/pdfbox/blob/714156a15ea6fcfe44ac09345b01e192cbd74450/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java
|
||||
/// </summary>
|
||||
/// Decodes image data that has been encoded using either Group 3 or Group 4.
|
||||
///
|
||||
/// Ported from https://github.com/apache/pdfbox/blob/714156a15ea6fcfe44ac09345b01e192cbd74450/pdfbox/src/main/java/org/apache/pdfbox/filter/CCITTFaxFilter.java
|
||||
/// </summary>
|
||||
internal class CcittFaxDecodeFilter : IFilter
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <inheritdoc />
|
||||
public bool IsSupported { get; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
|
||||
/// <inheritdoc />
|
||||
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
|
||||
{
|
||||
var decodeParms = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex);
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
}
|
||||
|
||||
var k = decodeParms.GetIntOrDefault(NameToken.K, 0);
|
||||
var encodedByteAlign = decodeParms.GetBooleanOrDefault(NameToken.EncodedByteAlign, false);
|
||||
var encodedByteAlign = decodeParms.GetBooleanOrDefault(NameToken.EncodedByteAlign, false);
|
||||
var compressionType = DetermineCompressionType(input, k);
|
||||
using (var stream = new CcittFaxDecoderStream(new MemoryStream(input.ToArray()), cols, compressionType, encodedByteAlign))
|
||||
{
|
||||
@ -59,7 +59,7 @@
|
||||
private static CcittFaxCompressionType DetermineCompressionType(IReadOnlyList<byte> input, int k)
|
||||
{
|
||||
if (k == 0)
|
||||
{
|
||||
{
|
||||
var compressionType = CcittFaxCompressionType.Group3_1D; // Group 3 1D
|
||||
|
||||
if (input.Count < 20)
|
||||
@ -85,20 +85,19 @@
|
||||
|
||||
return compressionType;
|
||||
}
|
||||
else if (k > 0)
|
||||
|
||||
if (k > 0)
|
||||
{
|
||||
// Group 3 2D
|
||||
return CcittFaxCompressionType.Group3_2D;
|
||||
}
|
||||
else
|
||||
{
|
||||
return CcittFaxCompressionType.Group4_2D;
|
||||
}
|
||||
|
||||
return CcittFaxCompressionType.Group4_2D;
|
||||
}
|
||||
|
||||
private static void ReadFromDecoderStream(CcittFaxDecoderStream decoderStream, byte[] result)
|
||||
{
|
||||
int pos = 0;
|
||||
var pos = 0;
|
||||
int read;
|
||||
while ((read = decoderStream.Read(result, pos, result.Length - pos)) > -1)
|
||||
{
|
||||
@ -118,5 +117,5 @@
|
||||
bufferData[i] = (byte)(~bufferData[i] & 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user