2016-02-10 06:10:08 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NAPS2.Scan;
|
2018-11-29 21:46:31 +03:00
|
|
|
|
using NAPS2.Images;
|
2016-02-10 06:10:08 +03:00
|
|
|
|
|
|
|
|
|
namespace NAPS2.ImportExport
|
|
|
|
|
{
|
|
|
|
|
public static class SaveSeparatorHelper
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Given a list of scans (each of which is a list of 1 or more images),
|
|
|
|
|
/// split up the images into multiple lists as described by the SaveSeparator parameter.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="scans"></param>
|
|
|
|
|
/// <param name="separator"></param>
|
2018-03-02 03:32:54 +03:00
|
|
|
|
/// <param name="splitSize"></param>
|
2016-02-10 06:10:08 +03:00
|
|
|
|
/// <returns></returns>
|
2018-03-02 03:32:54 +03:00
|
|
|
|
public static IEnumerable<List<ScannedImage>> SeparateScans(IEnumerable<IEnumerable<ScannedImage>> scans, SaveSeparator separator, int splitSize = 1)
|
2016-02-10 06:10:08 +03:00
|
|
|
|
{
|
|
|
|
|
if (separator == SaveSeparator.FilePerScan)
|
|
|
|
|
{
|
|
|
|
|
foreach (var scan in scans)
|
|
|
|
|
{
|
|
|
|
|
yield return scan.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (separator == SaveSeparator.FilePerPage)
|
|
|
|
|
{
|
2018-03-02 03:32:54 +03:00
|
|
|
|
splitSize = Math.Max(splitSize, 1);
|
|
|
|
|
foreach (var scan in scans.Select(x => x.ToList()))
|
2016-02-10 06:10:08 +03:00
|
|
|
|
{
|
2018-03-02 03:32:54 +03:00
|
|
|
|
for (int i = 0; i < scan.Count; i += splitSize)
|
2016-02-10 06:10:08 +03:00
|
|
|
|
{
|
2018-03-02 03:32:54 +03:00
|
|
|
|
yield return scan.Skip(i).Take(splitSize).ToList();
|
2016-02-10 06:10:08 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (separator == SaveSeparator.PatchT)
|
|
|
|
|
{
|
|
|
|
|
var images = new List<ScannedImage>();
|
|
|
|
|
foreach (var scan in scans)
|
|
|
|
|
{
|
|
|
|
|
foreach (var image in scan)
|
|
|
|
|
{
|
|
|
|
|
if (image.PatchCode == PatchCode.PatchT)
|
|
|
|
|
{
|
2016-07-03 05:12:30 +03:00
|
|
|
|
image.Dispose();
|
2016-02-10 06:10:08 +03:00
|
|
|
|
if (images.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
yield return images;
|
|
|
|
|
images = new List<ScannedImage>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
images.Add(image);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-03 05:12:30 +03:00
|
|
|
|
}
|
|
|
|
|
if (images.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
yield return images;
|
2016-02-10 06:10:08 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
yield return scans.SelectMany(x => x.ToList()).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|