Skip to content

Commit

Permalink
API for extracting images (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmester committed Apr 20, 2024
1 parent f8b0b4d commit ad1b1db
Show file tree
Hide file tree
Showing 29 changed files with 1,391 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

<!-- Code -->
<PropertyGroup>
<LangVersion>9.0</LangVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<!-- Feature defines -->
<PropertyGroup>
<DefineConstants Condition="'$(TargetFramework)' != 'net40'">$(DefineConstants);HAVE_ASYNC</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);HAVE_NULLABLE</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);HAVE_NULLABLE;HAVE_ASYNC_ENUMERABLE</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' != 'netstandard1.6'">$(DefineConstants);HAVE_STREAM_BEGINEND</DefineConstants>
</PropertyGroup>

Expand Down
9 changes: 9 additions & 0 deletions src/PdfToSvg/ColorSpaces/CalGrayColorSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace PdfToSvg.ColorSpaces
Expand Down Expand Up @@ -58,5 +59,13 @@ public override void ToRgb(float[] input, ref int inputOffset, out float red, ou
green = a;
blue = a;
}

public override int GetHashCode() =>
1182521745 ^
gamma.GetHashCode();

public override bool Equals(object obj) =>
obj is CalGrayColorSpace colorSpace &&
colorSpace.gamma == gamma;
}
}
9 changes: 9 additions & 0 deletions src/PdfToSvg/ColorSpaces/CalRgbColorSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,14 @@ public override void ToRgb(float[] input, ref int inputOffset, out float red, ou
green = ColorConversion.LinearRgbToSRgb(rgb.M21);
blue = ColorConversion.LinearRgbToSRgb(rgb.M31);
}

public override int GetHashCode() =>
1721897427 ^
transform.GetHashCode();

public override bool Equals(object obj) =>
obj is CalRgbColorSpace colorSpace &&
(colorSpace.gamma ?? ArrayUtils.Empty<double>()).SequenceEqual(gamma ?? ArrayUtils.Empty<double>()) &&
colorSpace.transform == transform;
}
}
2 changes: 1 addition & 1 deletion src/PdfToSvg/ColorSpaces/ColorSpaceParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static ColorSpace ParseIndexed(object[] colorSpaceParams, PdfDictionary?
using var lookupStream = lookupDict.Stream.OpenDecoded(cancellationToken);

var buffer = new byte[maxLookupLength];
var lookupLength = lookupStream.ReadAll(buffer, 0, buffer.Length);
var lookupLength = lookupStream.ReadAll(buffer, 0, buffer.Length, cancellationToken);

lookup = new byte[lookupLength];
Buffer.BlockCopy(buffer, 0, lookup, 0, lookupLength);
Expand Down
13 changes: 13 additions & 0 deletions src/PdfToSvg/ColorSpaces/DeviceNColorSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// https://github.com/dmester/pdftosvg.net
// Licensed under the MIT License.

using PdfToSvg.Common;
using PdfToSvg.Functions;
using PdfToSvg.Imaging;
using System;
Expand Down Expand Up @@ -71,6 +72,18 @@ public override DecodeArray GetDefaultDecodeArray(int bitsPerComponent)

public override float[] DefaultColor => new float[ComponentsPerSample];

public override int GetHashCode() =>
895666034 ^
ComponentsPerSample ^
AlternateSpace.GetHashCode() ^
tintTransform.GetHashCode();

public override bool Equals(object obj) =>
obj is DeviceNColorSpace colorSpace &&
colorSpace.ComponentsPerSample == ComponentsPerSample &&
colorSpace.AlternateSpace.Equals(AlternateSpace) &&
ReferenceEquals(colorSpace.tintTransform, tintTransform);

public override string ToString() => "DeviceN N=" + ComponentsPerSample + " " + AlternateSpace;
}
}
12 changes: 12 additions & 0 deletions src/PdfToSvg/ColorSpaces/LabColorSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,17 @@ private static float g(float x)
? x * x * x
: (108f / 841f) * (x - (4f / 29f));
}

public override int GetHashCode() =>
725317562 ^
transform.GetHashCode();

public override bool Equals(object obj) =>
obj is LabColorSpace colorSpace &&
colorSpace.amin == amin &&
colorSpace.amax == amax &&
colorSpace.bmin == bmin &&
colorSpace.bmax == bmax &&
colorSpace.transform == transform;
}
}
8 changes: 8 additions & 0 deletions src/PdfToSvg/ColorSpaces/PatternColorSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,13 @@ public override void ToRgb(float[] input, ref int inputOffset, out float red, ou
}

public override string ToString() => "Pattern";

public override int GetHashCode() =>
310771017 ^
AlternateSpace.GetHashCode();

public override bool Equals(object obj) =>
obj is PatternColorSpace colorSpace &&
colorSpace.AlternateSpace.Equals(AlternateSpace);
}
}
11 changes: 11 additions & 0 deletions src/PdfToSvg/ColorSpaces/SeparationColorSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -52,5 +53,15 @@ public override DecodeArray GetDefaultDecodeArray(int bitsPerComponent)
public override float[] DefaultColor => new[] { 0f };

public override string ToString() => "Separation " + AlternateSpace;

public override int GetHashCode() =>
1388104043 ^
AlternateSpace.GetHashCode() ^
tintTransform.GetHashCode();

public override bool Equals(object obj) =>
obj is SeparationColorSpace colorSpace &&
colorSpace.AlternateSpace.Equals(AlternateSpace) &&
colorSpace.tintTransform.Equals(tintTransform);
}
}
2 changes: 1 addition & 1 deletion src/PdfToSvg/ColorSpaces/UnsupportedColorSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void ToRgb(float[] input, ref int inputOffset, out float red, ou
public string Name => name.Value;

public override int GetHashCode() => name.GetHashCode();
public bool Equals(UnsupportedColorSpace? other) => other != null;
public bool Equals(UnsupportedColorSpace? other) => name == other?.name;
public override bool Equals(object? obj) => Equals(obj as UnsupportedColorSpace);

public override string ToString() => "Unsupported color space: " + name;
Expand Down

0 comments on commit ad1b1db

Please sign in to comment.