mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
parallel process images in color space
This commit is contained in:
@@ -334,11 +334,12 @@
|
||||
for (int p = 0; p < document.NumberOfPages; p++)
|
||||
{
|
||||
var page = document.GetPage(p + 1);
|
||||
foreach (var image in page.GetImages())
|
||||
var images = page.GetImages().ToArray();
|
||||
for (int i = 0; i < images.Length; i++)
|
||||
{
|
||||
if (image.TryGetPng(out var png))
|
||||
if (images[i].TryGetPng(out var png))
|
||||
{
|
||||
// TODO
|
||||
File.WriteAllBytes(Path.Combine(OutputFolder, $"Pig Production Handbook_{p + 1}_{i}.png"), png);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Tokens;
|
||||
using UglyToad.PdfPig.Content;
|
||||
using UglyToad.PdfPig.Functions;
|
||||
@@ -535,6 +536,89 @@
|
||||
/// <inheritdoc/>
|
||||
internal override IReadOnlyList<byte> Transform(IReadOnlyList<byte> decoded)
|
||||
{
|
||||
int outputCount = Process(Enumerable.Repeat(1.0, NumberOfColorComponents).ToArray()).Length;
|
||||
int outputSize = (int)(decoded.Count * outputCount / (double)NumberOfColorComponents);
|
||||
var transformed = new byte[outputSize];
|
||||
|
||||
Parallel.For(0, decoded.Count / NumberOfColorComponents, i =>
|
||||
{
|
||||
double[] comps = new double[NumberOfColorComponents];
|
||||
for (int n = 0; n < NumberOfColorComponents; n++)
|
||||
{
|
||||
comps[n] = decoded[i * NumberOfColorComponents + n] / 255.0;
|
||||
}
|
||||
|
||||
var colors = Process(comps);
|
||||
for (int c = 0; c < outputCount; c++)
|
||||
{
|
||||
transformed[i * outputCount + c] = ConvertToByte(colors[c]);
|
||||
}
|
||||
});
|
||||
return transformed;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/// <inheritdoc/>
|
||||
internal override IReadOnlyList<byte> Transform(IReadOnlyList<byte> decoded)
|
||||
{
|
||||
int outputCount = Process(Enumerable.Repeat(1.0, NumberOfColorComponents).ToArray()).Length;
|
||||
int outputSize = (int)(decoded.Count * outputCount / (double)NumberOfColorComponents);
|
||||
var transformed = new byte[outputSize];
|
||||
|
||||
//Parallel.For(0, )
|
||||
for (var i = 0; i < decoded.Count / NumberOfColorComponents; i++)
|
||||
{
|
||||
double[] comps = new double[NumberOfColorComponents];
|
||||
for (int n = 0; n < NumberOfColorComponents; n++)
|
||||
{
|
||||
comps[n] = decoded[i* NumberOfColorComponents + n] / 255.0;
|
||||
}
|
||||
|
||||
var colors = Process(comps);
|
||||
for (int c = 0; c < outputCount; c++)
|
||||
{
|
||||
transformed[i * outputCount + c] = ConvertToByte(colors[c]);
|
||||
}
|
||||
}
|
||||
|
||||
return transformed;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
/// <inheritdoc/>
|
||||
internal override IReadOnlyList<byte> Transform(IReadOnlyList<byte> decoded)
|
||||
{
|
||||
int outputCount = Process(Enumerable.Repeat(1.0, NumberOfColorComponents).ToArray()).Length;
|
||||
int outputSize = (int)(decoded.Count * outputCount / (double)NumberOfColorComponents);
|
||||
|
||||
var transformed = new byte[outputSize];
|
||||
for (var i = 0; i < decoded.Count; i += NumberOfColorComponents)
|
||||
{
|
||||
double[] comps = new double[NumberOfColorComponents];
|
||||
for (int n = 0; n < NumberOfColorComponents; n++)
|
||||
{
|
||||
comps[n] = decoded[i + n] / 255.0;
|
||||
}
|
||||
|
||||
var colors = Process(comps);
|
||||
for (int c = 0; c < outputCount; c++)
|
||||
{
|
||||
transformed[(i / NumberOfColorComponents) * outputCount + c] = ConvertToByte(colors[c]);
|
||||
}
|
||||
}
|
||||
|
||||
return transformed;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
/// <inheritdoc/>
|
||||
internal override IReadOnlyList<byte> Transform(IReadOnlyList<byte> decoded)
|
||||
{
|
||||
int outputCount = Process(Enumerable.Repeat(1.0, NumberOfColorComponents).ToArray()).Length;
|
||||
|
||||
var transformed = new List<byte>();
|
||||
for (var i = 0; i < decoded.Count; i += NumberOfColorComponents)
|
||||
{
|
||||
@@ -545,7 +629,7 @@
|
||||
}
|
||||
|
||||
var colors = Process(comps);
|
||||
for (int c = 0; c < colors.Length; c++)
|
||||
for (int c = 0; c < outputCount; c++)
|
||||
{
|
||||
transformed.Add(ConvertToByte(colors[c]));
|
||||
}
|
||||
@@ -553,6 +637,7 @@
|
||||
|
||||
return transformed;
|
||||
}
|
||||
*/
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IColor GetInitializeColor()
|
||||
@@ -1348,22 +1433,24 @@
|
||||
{
|
||||
if (Profile != null)
|
||||
{
|
||||
var transformed = new List<byte>();
|
||||
for (var i = 0; i < decoded.Count; i += NumberOfColorComponents)
|
||||
int outputCount = Process(Enumerable.Repeat(1.0, NumberOfColorComponents).ToArray()).Length;
|
||||
int outputSize = (int)(decoded.Count * outputCount / (double)NumberOfColorComponents);
|
||||
var transformed = new byte[outputSize];
|
||||
|
||||
Parallel.For(0, decoded.Count / NumberOfColorComponents, i =>
|
||||
{
|
||||
double[] comps = new double[NumberOfColorComponents];
|
||||
for (int n = 0; n < NumberOfColorComponents; n++)
|
||||
{
|
||||
comps[n] = decoded[i + n] / 255.0;
|
||||
comps[n] = decoded[i * NumberOfColorComponents + n] / 255.0;
|
||||
}
|
||||
|
||||
var colors = Process(comps);
|
||||
for (int c = 0; c < colors.Length; c++)
|
||||
for (int c = 0; c < outputCount; c++)
|
||||
{
|
||||
transformed.Add(ConvertToByte(colors[c]));
|
||||
transformed[i * outputCount + c] = ConvertToByte(colors[c]);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
return transformed;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user