Pass IFilterProvider to IFilter.Decode() and handle null in PdfExtensions.Resolve()
Some checks failed
Build and test / build (push) Has been cancelled
Run Integration Tests / build (push) Has been cancelled

This commit is contained in:
BobLd 2025-02-23 09:19:15 +00:00
parent d973e03206
commit f26e7d90a3
23 changed files with 56 additions and 60 deletions

View File

@ -20,7 +20,7 @@ O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF""AGXBPCsi + DGm >@3BB / F * &OCAfu2
l(DId<j@<? 3r@:F % a + D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G l(DId<j@<? 3r@:F % a + D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G
> uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c~>"); > uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c~>");
var result = filter.Decode(bytes, dictionary, 0); var result = filter.Decode(bytes, dictionary, TestFilterProvider.Instance, 0);
#if !NET #if !NET
string text = Encoding.ASCII.GetString(result.ToArray()); string text = Encoding.ASCII.GetString(result.ToArray());
@ -39,7 +39,7 @@ O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF""AGXBPCsi + DGm >@3BB / F * &OCAfu2
{ {
var bytes = Encoding.ASCII.GetBytes("9jqo^zBlbD-"); var bytes = Encoding.ASCII.GetBytes("9jqo^zBlbD-");
var result = filter.Decode(bytes, dictionary, 1); var result = filter.Decode(bytes, dictionary, TestFilterProvider.Instance, 1);
#if !NET #if !NET
string text = Encoding.ASCII.GetString(result.ToArray()); string text = Encoding.ASCII.GetString(result.ToArray());
@ -55,7 +55,7 @@ O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF""AGXBPCsi + DGm >@3BB / F * &OCAfu2
{ {
var bytes = Encoding.ASCII.GetBytes("qjzqo^"); var bytes = Encoding.ASCII.GetBytes("qjzqo^");
Action action = () => filter.Decode(bytes, dictionary, 0); Action action = () => filter.Decode(bytes, dictionary, TestFilterProvider.Instance, 0);
Assert.Throws<InvalidOperationException>(action); Assert.Throws<InvalidOperationException>(action);
} }
@ -65,7 +65,7 @@ O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF""AGXBPCsi + DGm >@3BB / F * &OCAfu2
{ {
var bytes = Encoding.ASCII.GetBytes("9jqo^B"); var bytes = Encoding.ASCII.GetBytes("9jqo^B");
Action action = () => filter.Decode(bytes, dictionary, 1); Action action = () => filter.Decode(bytes, dictionary, TestFilterProvider.Instance, 1);
Assert.Throws<ArgumentOutOfRangeException>(action); Assert.Throws<ArgumentOutOfRangeException>(action);
} }
@ -110,7 +110,7 @@ T()<(%'A;f?Ma+CT;%+E_a:A0>K&EZek1D/aN,F)u&6DBNA*A0>f4BOu4*+EM76E,9eK+B3(_<%9""p.
F*22=@:F%a+=SF4C'moi+=Li?EZeh0FD)e-@<>p#@;]TuBl.9kATKCFGA(],AKYo5BOu4*+CT;%+C#7pF_Pr+@VfTuDf0B:+=SF4C'moi+= F*22=@:F%a+=SF4C'moi+=Li?EZeh0FD)e-@<>p#@;]TuBl.9kATKCFGA(],AKYo5BOu4*+CT;%+C#7pF_Pr+@VfTuDf0B:+=SF4C'moi+=
Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&~>"; Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&~>";
var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, 0); var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, TestFilterProvider.Instance, 0);
#if !NET #if !NET
string text = Encoding.ASCII.GetString(result.ToArray()); string text = Encoding.ASCII.GetString(result.ToArray());
@ -134,7 +134,7 @@ T()<(%'A;f?Ma+CT;%+E_a:A0>K&EZek1D/aN,F)u&6DBNA*A0>f4BOu4*+EM76E,9eK+B3(_<%9""p.
F*22=@:F%a+=SF4C'moi+=Li?EZeh0FD)e-@<>p#@;]TuBl.9kATKCFGA(],AKYo5BOu4*+CT;%+C#7pF_Pr+@VfTuDf0B:+=SF4C'moi+= F*22=@:F%a+=SF4C'moi+=Li?EZeh0FD)e-@<>p#@;]TuBl.9kATKCFGA(],AKYo5BOu4*+CT;%+C#7pF_Pr+@VfTuDf0B:+=SF4C'moi+=
Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&"; Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&";
var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, 0); var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, TestFilterProvider.Instance, 0);
#if !NET #if !NET
string text = Encoding.ASCII.GetString(result.ToArray()); string text = Encoding.ASCII.GetString(result.ToArray());
@ -154,7 +154,7 @@ Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&";
{ {
var bytes = Encoding.ASCII.GetBytes("9jqo^zBlbD-"); var bytes = Encoding.ASCII.GetBytes("9jqo^zBlbD-");
var result = filter.Decode(bytes, dictionary, 1); var result = filter.Decode(bytes, dictionary, TestFilterProvider.Instance, 1);
#if !NET #if !NET
string text = Encoding.ASCII.GetString(result.ToArray()); string text = Encoding.ASCII.GetString(result.ToArray());
@ -176,7 +176,7 @@ T()<(%'A;f?Ma+CT;%+E_a:A0>K&EZek1D/aN,F)u&6DBNA*A0>f4BOu4*+EM76E,9eK+B3(_<%9""p.
F*22=@:F%a+=SF4C'moi+=Li?EZeh0FD)e-@<>p#@;]TuBl.9kATKCFGA(],AKYo5BOu4*+CT;%+C#7pF_Pr+@VfTuDf0B:+=SF4C'moi+= F*22=@:F%a+=SF4C'moi+=Li?EZeh0FD)e-@<>p#@;]TuBl.9kATKCFGA(],AKYo5BOu4*+CT;%+C#7pF_Pr+@VfTuDf0B:+=SF4C'moi+=
Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&~>"; Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&~>";
var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, 0); var result = filter.Decode(Encoding.ASCII.GetBytes(input), dictionary, TestFilterProvider.Instance, 0);
#if !NET #if !NET
string text = Encoding.ASCII.GetString(result.ToArray()); string text = Encoding.ASCII.GetString(result.ToArray());

View File

@ -16,7 +16,7 @@
var input = Encoding.ASCII.GetBytes( var input = Encoding.ASCII.GetBytes(
"7368652073656C6C73207365617368656C6C73206F6E20746865207365612073686F7265"); "7368652073656C6C73207365617368656C6C73206F6E20746865207365612073686F7265");
var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1);
var decodedText = Encoding.ASCII.GetString(decoded.ToArray()); var decodedText = Encoding.ASCII.GetString(decoded.ToArray());
@ -31,7 +31,7 @@
var input = Encoding.ASCII.GetBytes( var input = Encoding.ASCII.GetBytes(
"<7368652073656C6C73207365617368656C6C73206F6E20746865207365612073686F7265>"); "<7368652073656C6C73207365617368656C6C73206F6E20746865207365612073686F7265>");
var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1);
var decodedText = Encoding.ASCII.GetString(decoded.ToArray()); var decodedText = Encoding.ASCII.GetString(decoded.ToArray());
@ -47,7 +47,7 @@
@"6F6E6365207 5706F6E206120 74696D6520696E @"6F6E6365207 5706F6E206120 74696D6520696E
20612067616C6178792046617220466172204177 6179"); 20612067616C6178792046617220466172204177 6179");
var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1);
var decodedText = Encoding.ASCII.GetString(decoded.ToArray()); var decodedText = Encoding.ASCII.GetString(decoded.ToArray());
@ -61,7 +61,7 @@
var input = Encoding.ASCII.GetBytes("6f6e63652075706f6e20612074696d6520696e20612067616c61787920466172204661722041776179"); var input = Encoding.ASCII.GetBytes("6f6e63652075706f6e20612074696d6520696e20612067616c61787920466172204661722041776179");
var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1);
var decodedText = Encoding.ASCII.GetString(decoded.ToArray()); var decodedText = Encoding.ASCII.GetString(decoded.ToArray());
@ -75,7 +75,7 @@
{ {
var input = Encoding.ASCII.GetBytes(inputString); var input = Encoding.ASCII.GetBytes(inputString);
Action action = () => new AsciiHexDecodeFilter().Decode(input, dictionary, 1); Action action = () => new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1);
Assert.Throws<InvalidOperationException>(action); Assert.Throws<InvalidOperationException>(action);
} }
@ -85,7 +85,7 @@
{ {
var input = Encoding.ASCII.GetBytes("AE5>"); var input = Encoding.ASCII.GetBytes("AE5>");
var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1);
#pragma warning disable SYSLIB0001 #pragma warning disable SYSLIB0001
var decodedText = Encoding.UTF7.GetString(decoded.ToArray()); var decodedText = Encoding.UTF7.GetString(decoded.ToArray());
@ -101,7 +101,7 @@
var input = Encoding.ASCII.GetBytes("6f6e63652075706f6e20612074696d6520696e20612067616c61787920466172204661722041776179> There is stuff following the EOD."); var input = Encoding.ASCII.GetBytes("6f6e63652075706f6e20612074696d6520696e20612067616c61787920466172204661722041776179> There is stuff following the EOD.");
var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, 1); var decoded = new AsciiHexDecodeFilter().Decode(input, dictionary, TestFilterProvider.Instance, 1);
var decodedText = Encoding.ASCII.GetString(decoded.ToArray()); var decodedText = Encoding.ASCII.GetString(decoded.ToArray());

View File

@ -31,7 +31,7 @@
}; };
var expectedBytes = ImageHelpers.LoadFileBytes("ccittfax-decoded.bin"); var expectedBytes = ImageHelpers.LoadFileBytes("ccittfax-decoded.bin");
var decodedBytes = filter.Decode(encodedBytes, new DictionaryToken(dictionary), 0); var decodedBytes = filter.Decode(encodedBytes, new DictionaryToken(dictionary), TestFilterProvider.Instance, 0);
Assert.Equal(expectedBytes, decodedBytes.ToArray()); Assert.Equal(expectedBytes, decodedBytes.ToArray());
} }
} }

View File

@ -17,7 +17,7 @@
{ {
inputStream.Seek(0, SeekOrigin.Begin); inputStream.Seek(0, SeekOrigin.Begin);
var result = filter.Encode(inputStream, parameters, 0); var result = filter.Encode(inputStream, parameters, 0);
var decoded = filter.Decode(result, parameters, 0); var decoded = filter.Decode(result, parameters, TestFilterProvider.Instance, 0);
Assert.Equal(input, decoded.ToArray()); Assert.Equal(input, decoded.ToArray());
} }
} }

View File

@ -24,7 +24,7 @@
1, 10, 19 1, 10, 19
}; };
var decoded = filter.Decode(data, new DictionaryToken(new Dictionary<NameToken, IToken>()), 1); var decoded = filter.Decode(data, new DictionaryToken(new Dictionary<NameToken, IToken>()), TestFilterProvider.Instance, 1);
var expectedResult = new byte[] var expectedResult = new byte[]
{ {
@ -53,7 +53,7 @@
90, 6, 7 90, 6, 7
}; };
var decoded = filter.Decode(data, new DictionaryToken(new Dictionary<NameToken, IToken>()), 0); var decoded = filter.Decode(data, new DictionaryToken(new Dictionary<NameToken, IToken>()), TestFilterProvider.Instance, 0);
var expectedResult = new byte[] var expectedResult = new byte[]
{ {

View File

@ -62,7 +62,7 @@
{ {
public bool IsSupported => false; public bool IsSupported => false;
public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex) public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -96,7 +96,7 @@
}); });
var filter = new FlateFilter(); var filter = new FlateFilter();
var filtered = filter.Decode(streamBytes, dictionary, 0).ToArray(); var filtered = filter.Decode(streamBytes, dictionary, TestFilterProvider.Instance, 0).ToArray();
var expected = var expected =
"1 0 15 0 1 0 216 0 1 2 160 0 1 2 210 0 1 3 84 0 1 4 46 0 1 7 165 0 1 70 229 0 1 72 84 0 1 96 235 0 1 98 18 0 2 0 12 0 2 0 12 1 2 0 12 2 2 0 12 3 2 0 12 4 2 0 12 5 2 0 12 6 2 0 12 7 2 0 12 8" "1 0 15 0 1 0 216 0 1 2 160 0 1 2 210 0 1 3 84 0 1 4 46 0 1 7 165 0 1 70 229 0 1 72 84 0 1 96 235 0 1 98 18 0 2 0 12 0 2 0 12 1 2 0 12 2 2 0 12 3 2 0 12 4 2 0 12 5 2 0 12 6 2 0 12 7 2 0 12 8"

View File

@ -6,6 +6,8 @@
internal class TestFilterProvider : ILookupFilterProvider internal class TestFilterProvider : ILookupFilterProvider
{ {
public static readonly TestFilterProvider Instance = new TestFilterProvider();
public IReadOnlyList<IFilter> GetFilters(DictionaryToken dictionary) public IReadOnlyList<IFilter> GetFilters(DictionaryToken dictionary)
{ {
return new List<IFilter>(); return new List<IFilter>();

View File

@ -64,8 +64,9 @@
RenderingIntent renderingIntent, RenderingIntent renderingIntent,
bool interpolate, bool interpolate,
IReadOnlyList<double> decode, IReadOnlyList<double> decode,
ReadOnlyMemory<byte> rawMemory, ReadOnlyMemory<byte> rawMemory,
IReadOnlyList<IFilter> filters, ILookupFilterProvider filterProvider,
IReadOnlyList<NameToken> filterNames,
DictionaryToken streamDictionary, DictionaryToken streamDictionary,
ColorSpaceDetails colorSpaceDetails) ColorSpaceDetails colorSpaceDetails)
{ {
@ -79,8 +80,10 @@
Interpolate = interpolate; Interpolate = interpolate;
ImageDictionary = streamDictionary; ImageDictionary = streamDictionary;
RawMemory = rawMemory; RawMemory = rawMemory;
ColorSpaceDetails = colorSpaceDetails; ColorSpaceDetails = colorSpaceDetails;
var filters = filterProvider.GetNamedFilters(filterNames);
var supportsFilters = true; var supportsFilters = true;
foreach (var filter in filters) foreach (var filter in filters)
{ {
@ -97,7 +100,7 @@
for (var i = 0; i < filters.Count; i++) for (var i = 0; i < filters.Count; i++)
{ {
var filter = filters[i]; var filter = filters[i];
b = filter.Decode(b.Span, streamDictionary, i); b = filter.Decode(b.Span, streamDictionary, filterProvider, i);
} }
return b; return b;

View File

@ -27,7 +27,7 @@
public bool IsSupported { get; } = true; public bool IsSupported { get; } = true;
/// <inheritdoc /> /// <inheritdoc />
public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex) public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex)
{ {
Span<byte> asciiBuffer = stackalloc byte[5]; Span<byte> asciiBuffer = stackalloc byte[5];

View File

@ -28,7 +28,7 @@
public bool IsSupported { get; } = true; public bool IsSupported { get; } = true;
/// <inheritdoc /> /// <inheritdoc />
public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex) public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex)
{ {
Span<byte> pair = stackalloc byte[2]; Span<byte> pair = stackalloc byte[2];
var index = 0; var index = 0;

View File

@ -20,7 +20,7 @@
public bool IsSupported { get; } = true; public bool IsSupported { get; } = true;
/// <inheritdoc /> /// <inheritdoc />
public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex) public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex)
{ {
var decodeParms = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex); var decodeParms = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex);

View File

@ -13,7 +13,7 @@
public bool IsSupported { get; } = false; public bool IsSupported { get; } = false;
/// <inheritdoc /> /// <inheritdoc />
public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex) public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex)
{ {
throw new NotSupportedException("The DST (Discrete Cosine Transform) Filter indicates data is encoded in JPEG format. " + throw new NotSupportedException("The DST (Discrete Cosine Transform) Filter indicates data is encoded in JPEG format. " +
"This filter is not currently supported but the raw data can be supplied to JPEG supporting libraries."); "This filter is not currently supported but the raw data can be supplied to JPEG supporting libraries.");

View File

@ -31,7 +31,7 @@
public bool IsSupported { get; } = true; public bool IsSupported { get; } = true;
/// <inheritdoc /> /// <inheritdoc />
public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex) public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex)
{ {
var parameters = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex); var parameters = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex);

View File

@ -18,8 +18,9 @@
/// </summary> /// </summary>
/// <param name="input">The encoded bytes which were encoded using this filter.</param> /// <param name="input">The encoded bytes which were encoded using this filter.</param>
/// <param name="streamDictionary">The dictionary of the <see cref="StreamToken"/> (or other dictionary types, e.g. inline images) containing these bytes.</param> /// <param name="streamDictionary">The dictionary of the <see cref="StreamToken"/> (or other dictionary types, e.g. inline images) containing these bytes.</param>
/// <param name="filterProvider">The filter provider.</param>
/// <param name="filterIndex">The position of this filter in the pipeline used to encode data.</param> /// <param name="filterIndex">The position of this filter in the pipeline used to encode data.</param>
/// <returns>The decoded bytes.</returns> /// <returns>The decoded bytes.</returns>
ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex); ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex);
} }
} }

View File

@ -13,7 +13,7 @@
public bool IsSupported { get; } = false; public bool IsSupported { get; } = false;
/// <inheritdoc /> /// <inheritdoc />
public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex) public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex)
{ {
throw new NotSupportedException("The JBIG2 Filter for monochrome image data is not currently supported. " + throw new NotSupportedException("The JBIG2 Filter for monochrome image data is not currently supported. " +
"Try accessing the raw compressed data directly."); "Try accessing the raw compressed data directly.");

View File

@ -13,7 +13,7 @@
public bool IsSupported { get; } = false; public bool IsSupported { get; } = false;
/// <inheritdoc /> /// <inheritdoc />
public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex) public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex)
{ {
throw new NotSupportedException("The JPX Filter (JPEG2000) for image data is not currently supported. " + throw new NotSupportedException("The JPX Filter (JPEG2000) for image data is not currently supported. " +
"Try accessing the raw compressed data directly."); "Try accessing the raw compressed data directly.");

View File

@ -29,7 +29,7 @@ namespace UglyToad.PdfPig.Filters
public bool IsSupported { get; } = true; public bool IsSupported { get; } = true;
/// <inheritdoc /> /// <inheritdoc />
public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex) public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex)
{ {
var parameters = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex); var parameters = DecodeParameterResolver.GetFilterParameters(streamDictionary, filterIndex);

View File

@ -16,7 +16,7 @@
public bool IsSupported { get; } = true; public bool IsSupported { get; } = true;
/// <inheritdoc /> /// <inheritdoc />
public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, int filterIndex) public ReadOnlyMemory<byte> Decode(ReadOnlySpan<byte> input, DictionaryToken streamDictionary, IFilterProvider filterProvider, int filterIndex)
{ {
using var output = new ArrayPoolBufferWriter<byte>(input.Length); using var output = new ArrayPoolBufferWriter<byte>(input.Length);

View File

@ -98,18 +98,15 @@
filterNames.Add(filterName); filterNames.Add(filterName);
} }
var filters = filterProvider.GetNamedFilters(filterNames);
var decodeRaw = GetByKeys<ArrayToken>(NameToken.Decode, NameToken.D, false) ?? new ArrayToken(Array.Empty<IToken>()); var decodeRaw = GetByKeys<ArrayToken>(NameToken.Decode, NameToken.D, false) ?? new ArrayToken(Array.Empty<IToken>());
var decode = decodeRaw.Data.OfType<NumericToken>().Select(x => x.Double).ToArray(); var decode = decodeRaw.Data.OfType<NumericToken>().Select(x => x.Double).ToArray();
var interpolate = GetByKeys<BooleanToken>(NameToken.Interpolate, NameToken.I, false)?.Data ?? false; var interpolate = GetByKeys<BooleanToken>(NameToken.Interpolate, NameToken.I, false)?.Data ?? false;
return new InlineImage(bounds, width, height, bitsPerComponent, isMask, renderingIntent, interpolate, decode, Bytes, return new InlineImage(bounds, width, height, bitsPerComponent,
filters, isMask, renderingIntent, interpolate, decode, Bytes,
imgDic, filterProvider, filterNames, imgDic, details);
details);
} }
#nullable disable #nullable disable

View File

@ -62,7 +62,7 @@
var transform = stream.Data; var transform = stream.Data;
for (var i = 0; i < filters.Count; i++) for (var i = 0; i < filters.Count; i++)
{ {
transform = filters[i].Decode(transform.Span, stream.StreamDictionary, i); transform = filters[i].Decode(transform.Span, stream.StreamDictionary, filterProvider, i);
} }
return transform; return transform;
@ -78,7 +78,7 @@
var transform = stream.Data; var transform = stream.Data;
for (var i = 0; i < filters.Count; i++) for (var i = 0; i < filters.Count; i++)
{ {
transform = filters[i].Decode(transform.Span, stream.StreamDictionary, i); transform = filters[i].Decode(transform.Span, stream.StreamDictionary, filterProvider, i);
} }
return transform; return transform;
@ -88,12 +88,12 @@
/// Returns an equivalent token where any indirect references of child objects are /// Returns an equivalent token where any indirect references of child objects are
/// recursively traversed and resolved. /// recursively traversed and resolved.
/// </summary> /// </summary>
internal static T Resolve<T>(this T token, IPdfTokenScanner scanner) where T : IToken internal static T? Resolve<T>(this T? token, IPdfTokenScanner scanner) where T : IToken
{ {
return (T)ResolveInternal(token, scanner); return (T?)ResolveInternal(token, scanner);
} }
private static IToken ResolveInternal(this IToken token, IPdfTokenScanner scanner) private static IToken? ResolveInternal(this IToken? token, IPdfTokenScanner scanner)
{ {
if (token is StreamToken stream) if (token is StreamToken stream)
{ {
@ -105,7 +105,7 @@
var resolvedItems = new Dictionary<NameToken, IToken>(); var resolvedItems = new Dictionary<NameToken, IToken>();
foreach (var kvp in dict.Data) foreach (var kvp in dict.Data)
{ {
var value = kvp.Value is IndirectReferenceToken reference ? scanner.Get(reference.Data).Data : kvp.Value; var value = kvp.Value is IndirectReferenceToken reference ? scanner.Get(reference.Data)?.Data : kvp.Value;
resolvedItems[NameToken.Create(kvp.Key)] = ResolveInternal(value, scanner); resolvedItems[NameToken.Create(kvp.Key)] = ResolveInternal(value, scanner);
} }
@ -117,14 +117,13 @@
var resolvedItems = new List<IToken>(); var resolvedItems = new List<IToken>();
for (int i = 0; i < arr.Length; i++) for (int i = 0; i < arr.Length; i++)
{ {
var value = arr.Data[i] is IndirectReferenceToken reference ? scanner.Get(reference.Data).Data : arr.Data[i]; var value = arr.Data[i] is IndirectReferenceToken reference ? scanner.Get(reference.Data)?.Data : arr.Data[i];
resolvedItems.Add(ResolveInternal(value, scanner)); resolvedItems.Add(ResolveInternal(value, scanner));
} }
return new ArrayToken(resolvedItems); return new ArrayToken(resolvedItems);
} }
var val = token is IndirectReferenceToken tokenReference ? scanner.Get(tokenReference.Data).Data : token; return token is IndirectReferenceToken tokenReference ? scanner.Get(tokenReference.Data)?.Data : token;
return val;
} }
} }
} }

View File

@ -15,7 +15,7 @@
/// </summary> /// </summary>
/// <param name="reference">The object number for the object to tokenize.</param> /// <param name="reference">The object number for the object to tokenize.</param>
/// <returns>The tokenized object.</returns> /// <returns>The tokenized object.</returns>
ObjectToken Get(IndirectReference reference); ObjectToken? Get(IndirectReference reference);
/// <summary> /// <summary>
/// Adds the token to an internal cache that will be returned instead of /// Adds the token to an internal cache that will be returned instead of

View File

@ -5,9 +5,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Core; using Core;
using Encryption; using Encryption;
@ -714,10 +712,8 @@
coreTokenScanner.DeregisterCustomTokenizer(tokenizer); coreTokenScanner.DeregisterCustomTokenizer(tokenizer);
} }
#nullable disable public ObjectToken? Get(IndirectReference reference)
public ObjectToken Get(IndirectReference reference)
{ {
if (isDisposed) if (isDisposed)
{ {
@ -769,8 +765,6 @@
return BruteForceFileToFindReference(reference); return BruteForceFileToFindReference(reference);
} }
#nullable enable
public void ReplaceToken(IndirectReference reference, IToken token) public void ReplaceToken(IndirectReference reference, IToken token)
{ {
// Using 0 position as it isn't written to stream and this value doesn't // Using 0 position as it isn't written to stream and this value doesn't