mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-11 15:26:55 +03:00
Add PageNumber and PageSide to PostProcessingData
This commit is contained in:
parent
4a5efc6599
commit
e6318000b8
@ -160,4 +160,55 @@ public class RemotePostProcessorTests : ContextualTests
|
||||
Assert.Equal(297m, result.Metadata.PageSize.Height);
|
||||
Assert.Equal(PageSizeUnit.Millimetre, result.Metadata.PageSize.Unit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoFlipDuplexed()
|
||||
{
|
||||
var image1 = LoadImage(ImageResources.dog);
|
||||
var image2 = LoadImage(ImageResources.dog);
|
||||
var options = new ScanOptions
|
||||
{
|
||||
PaperSource = PaperSource.Duplex
|
||||
};
|
||||
var result1 = _remotePostProcessor.PostProcess(image1, options, new PostProcessingContext
|
||||
{
|
||||
PageNumber = 1
|
||||
})!;
|
||||
var result2 = _remotePostProcessor.PostProcess(image2, options, new PostProcessingContext
|
||||
{
|
||||
PageNumber = 2
|
||||
})!;
|
||||
Assert.Equal(1, result1.PostProcessingData.PageNumber);
|
||||
Assert.Equal(PageSide.Front, result1.PostProcessingData.PageSide);
|
||||
ImageAsserts.Similar(ImageResources.dog, result1);
|
||||
Assert.Equal(2, result2.PostProcessingData.PageNumber);
|
||||
Assert.Equal(PageSide.Back, result2.PostProcessingData.PageSide);
|
||||
ImageAsserts.Similar(ImageResources.dog, result2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FlipDuplexed()
|
||||
{
|
||||
var image1 = LoadImage(ImageResources.dog);
|
||||
var image2 = LoadImage(ImageResources.dog);
|
||||
var options = new ScanOptions
|
||||
{
|
||||
PaperSource = PaperSource.Duplex,
|
||||
FlipDuplexedPages = true
|
||||
};
|
||||
var result1 = _remotePostProcessor.PostProcess(image1, options, new PostProcessingContext
|
||||
{
|
||||
PageNumber = 1
|
||||
})!;
|
||||
var result2 = _remotePostProcessor.PostProcess(image2, options, new PostProcessingContext
|
||||
{
|
||||
PageNumber = 2
|
||||
})!;
|
||||
Assert.Equal(1, result1.PostProcessingData.PageNumber);
|
||||
Assert.Equal(PageSide.Front, result1.PostProcessingData.PageSide);
|
||||
ImageAsserts.Similar(ImageResources.dog, result1);
|
||||
Assert.Equal(2, result2.PostProcessingData.PageNumber);
|
||||
Assert.Equal(PageSide.Back, result2.PostProcessingData.PageSide);
|
||||
ImageAsserts.Similar(ImageResources.dog, result2.WithTransform(new RotationTransform(180)));
|
||||
}
|
||||
}
|
8
NAPS2.Sdk/Images/PageSide.cs
Normal file
8
NAPS2.Sdk/Images/PageSide.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace NAPS2.Images;
|
||||
|
||||
public enum PageSide
|
||||
{
|
||||
Unknown,
|
||||
Front,
|
||||
Back
|
||||
}
|
@ -5,10 +5,15 @@ namespace NAPS2.Images;
|
||||
/// <summary>
|
||||
/// Represents information about an image obtained during post-processing (e.g. thumbnail image, barcode).
|
||||
/// </summary>
|
||||
public record PostProcessingData(IMemoryImage? Thumbnail, TransformState? ThumbnailTransformState,
|
||||
Barcode Barcode, CancellationTokenSource? OcrCts)
|
||||
public record PostProcessingData(
|
||||
IMemoryImage? Thumbnail,
|
||||
TransformState? ThumbnailTransformState,
|
||||
int PageNumber,
|
||||
PageSide PageSide,
|
||||
Barcode Barcode,
|
||||
CancellationTokenSource? OcrCts)
|
||||
{
|
||||
public PostProcessingData() : this(null, null, Barcode.NoDetection, null)
|
||||
public PostProcessingData() : this(null, null, 0, PageSide.Unknown, Barcode.NoDetection, null)
|
||||
{
|
||||
}
|
||||
}
|
@ -137,7 +137,10 @@ internal class RemotePostProcessor : IRemotePostProcessor
|
||||
private void DoRevertibleTransforms(ref ProcessedImage processedImage, ref IMemoryImage image, ScanOptions options,
|
||||
PostProcessingContext postProcessingContext)
|
||||
{
|
||||
var data = processedImage.PostProcessingData;
|
||||
var data = processedImage.PostProcessingData with
|
||||
{
|
||||
PageNumber = postProcessingContext.PageNumber
|
||||
};
|
||||
|
||||
if ((!options.UseNativeUI && options.BrightnessContrastAfterScan) ||
|
||||
options.Driver is not (Driver.Wia or Driver.Twain))
|
||||
@ -146,10 +149,16 @@ internal class RemotePostProcessor : IRemotePostProcessor
|
||||
processedImage = processedImage.WithTransform(new TrueContrastTransform(options.Contrast), true);
|
||||
}
|
||||
|
||||
if (options.FlipDuplexedPages && options.PaperSource == PaperSource.Duplex &&
|
||||
postProcessingContext.PageNumber % 2 == 0)
|
||||
if (options.PaperSource == PaperSource.Duplex)
|
||||
{
|
||||
processedImage = processedImage.WithTransform(new RotationTransform(180), true);
|
||||
data = data with
|
||||
{
|
||||
PageSide = postProcessingContext.PageNumber % 2 == 0 ? PageSide.Back : PageSide.Front
|
||||
};
|
||||
if (options.FlipDuplexedPages && data.PageSide == PageSide.Back)
|
||||
{
|
||||
processedImage = processedImage.WithTransform(new RotationTransform(180), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.RotateDegrees != 0)
|
||||
|
Loading…
Reference in New Issue
Block a user