mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-08-20 09:37:44 +08:00
Fix Separation color space and add tests
This commit is contained in:
parent
b4649758c6
commit
3191cdc446
@ -101,7 +101,7 @@
|
||||
{
|
||||
var page1 = document.GetPage(1);
|
||||
var images = page1.GetImages().ToArray();
|
||||
var image1page1 = images.ElementAt(0);
|
||||
var image1page1 = images[0];
|
||||
var separationCs = image1page1.ColorSpaceDetails as SeparationColorSpaceDetails;
|
||||
Assert.NotNull(separationCs);
|
||||
Assert.True(separationCs.AlternateColorSpace is DeviceCmykColorSpaceDetails);
|
||||
@ -116,6 +116,39 @@
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SeparationColorSpace()
|
||||
{
|
||||
var path = IntegrationHelpers.GetDocumentPath("MOZILLA-3136-0.pdf");
|
||||
|
||||
using (var document = PdfDocument.Open(path))
|
||||
{
|
||||
var page = document.GetPage(4);
|
||||
var images = page.GetImages().ToArray();
|
||||
|
||||
var image4 = images[4];
|
||||
|
||||
var separation = image4.ColorSpaceDetails as SeparationColorSpaceDetails;
|
||||
Assert.NotNull(separation);
|
||||
|
||||
Assert.True(image4.TryGetPng(out var png4));
|
||||
|
||||
File.WriteAllBytes(Path.Combine(OutputFolder, "MOZILLA-3136-0_4_separation.png"), png4);
|
||||
|
||||
// Green dolphin image
|
||||
// "Colorized TIFF (should appear only in GWG Green separation)"
|
||||
var image9 = images[9];
|
||||
|
||||
var indexedCs = image9.ColorSpaceDetails as IndexedColorSpaceDetails;
|
||||
Assert.NotNull(indexedCs);
|
||||
Assert.Equal(ColorSpace.Separation, indexedCs.BaseColorSpace.Type);
|
||||
|
||||
Assert.True(image9.TryGetPng(out var png9));
|
||||
|
||||
File.WriteAllBytes(Path.Combine(OutputFolder, "MOZILLA-3136-0_9_separation.png"), png9);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IndexedCalRgbColorSpaceImages()
|
||||
{
|
||||
@ -217,7 +250,7 @@
|
||||
File.WriteAllBytes(Path.Combine(OutputFolder, "MOZILLA-10225-0_341_0.png"), bytes341_0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void SeparationLabColorSpace()
|
||||
{
|
||||
|
||||
@ -728,18 +728,19 @@
|
||||
/// <inheritdoc/>
|
||||
internal override ReadOnlySpan<byte> Transform(ReadOnlySpan<byte> values)
|
||||
{
|
||||
var cache = new Dictionary<int, double[]>(values.Length * 3);
|
||||
var transformed = new List<byte>(values.Length * 3);
|
||||
for (var i = 0; i < values.Length; i += 3)
|
||||
var colorCache = new Dictionary<int, double[]>(values.Length);
|
||||
var transformed = new List<byte>(values.Length);
|
||||
|
||||
for (var i = 0; i < values.Length; ++i)
|
||||
{
|
||||
byte b = values[i++];
|
||||
if (!cache.TryGetValue(b, out double[]? colors))
|
||||
byte b = values[i];
|
||||
if (!colorCache.TryGetValue(b, out double[]? colors))
|
||||
{
|
||||
colors = Process(b / 255.0);
|
||||
cache[b] = colors;
|
||||
colorCache[b] = colors;
|
||||
}
|
||||
|
||||
for (int c = 0; c < colors.Length; c++)
|
||||
for (int c = 0; c < colors.Length; ++c)
|
||||
{
|
||||
transformed.Add(ConvertToByte(colors[c]));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user