diff --git a/NAPS2.Lib/Automation/AutomatedScanning.cs b/NAPS2.Lib/Automation/AutomatedScanning.cs index 56035b5c0..f9f7c389f 100644 --- a/NAPS2.Lib/Automation/AutomatedScanning.cs +++ b/NAPS2.Lib/Automation/AutomatedScanning.cs @@ -19,7 +19,7 @@ public class AutomatedScanning private readonly IEmailProviderFactory _emailProviderFactory; private readonly IScanPerformer _scanPerformer; private readonly ErrorOutput _errorOutput; - private readonly IScannedImageImporter _scannedImageImporter; + private readonly IFileImporter _fileImporter; private readonly IOperationFactory _operationFactory; private readonly TesseractLanguageManager _tesseractLanguageManager; private readonly IFormFactory _formFactory; @@ -40,7 +40,7 @@ public class AutomatedScanning public AutomatedScanning(ConsoleOutput output, AutomatedScanningOptions options, ImageContext imageContext, IScanPerformer scanPerformer, ErrorOutput errorOutput, IEmailProviderFactory emailProviderFactory, - IScannedImageImporter scannedImageImporter, IOperationFactory operationFactory, + IFileImporter fileImporter, IOperationFactory operationFactory, TesseractLanguageManager tesseractLanguageManager, IFormFactory formFactory, Naps2Config config, IProfileManager profileManager, RecoveryStorageManager recoveryStorageManager, ScanningContext scanningContext) { @@ -50,7 +50,7 @@ public class AutomatedScanning _scanPerformer = scanPerformer; _errorOutput = errorOutput; _emailProviderFactory = emailProviderFactory; - _scannedImageImporter = scannedImageImporter; + _fileImporter = fileImporter; _operationFactory = operationFactory; _tesseractLanguageManager = tesseractLanguageManager; _formFactory = formFactory; @@ -284,7 +284,7 @@ public class AutomatedScanning PatchTOnly = true } }; - await foreach (var image in _scannedImageImporter.Import(actualPath, importParams)) + await foreach (var image in _fileImporter.Import(actualPath, importParams)) { scan.Add(image); } diff --git a/NAPS2.Sdk/ImportExport/Email/EmailSettings.cs b/NAPS2.Lib/ImportExport/Email/EmailSettings.cs similarity index 100% rename from NAPS2.Sdk/ImportExport/Email/EmailSettings.cs rename to NAPS2.Lib/ImportExport/Email/EmailSettings.cs diff --git a/NAPS2.Lib/ImportExport/Images/SaveImagesOperation.cs b/NAPS2.Lib/ImportExport/Images/SaveImagesOperation.cs index 66e324f3a..4f5675799 100644 --- a/NAPS2.Lib/ImportExport/Images/SaveImagesOperation.cs +++ b/NAPS2.Lib/ImportExport/Images/SaveImagesOperation.cs @@ -1,6 +1,6 @@ namespace NAPS2.ImportExport.Images; -public class SaveImagesOperation : OperationBase +internal class SaveImagesOperation : OperationBase { private readonly IOverwritePrompt _overwritePrompt; private readonly ImageContext _imageContext; diff --git a/NAPS2.Lib/ImportExport/ImportOperation.cs b/NAPS2.Lib/ImportExport/ImportOperation.cs index 12976acd6..6f5b494a5 100644 --- a/NAPS2.Lib/ImportExport/ImportOperation.cs +++ b/NAPS2.Lib/ImportExport/ImportOperation.cs @@ -2,11 +2,11 @@ public class ImportOperation : OperationBase { - private readonly IScannedImageImporter _scannedImageImporter; + private readonly IFileImporter _fileImporter; - public ImportOperation(IScannedImageImporter scannedImageImporter) + public ImportOperation(IFileImporter fileImporter) { - _scannedImageImporter = scannedImageImporter; + _fileImporter = fileImporter; ProgressTitle = MiscResources.ImportProgress; AllowCancel = true; @@ -31,7 +31,7 @@ public class ImportOperation : OperationBase { Status.StatusText = string.Format(MiscResources.ImportingFormat, Path.GetFileName(fileName)); InvokeStatusChanged(); - var images = _scannedImageImporter.Import(fileName, importParams, oneFile ? ProgressHandler : CancelToken); + var images = _fileImporter.Import(fileName, importParams, oneFile ? ProgressHandler : CancelToken); await foreach (var image in images) { imageCallback(image); diff --git a/NAPS2.Sdk/ImportExport/SaveSeparator.cs b/NAPS2.Lib/ImportExport/SaveSeparator.cs similarity index 100% rename from NAPS2.Sdk/ImportExport/SaveSeparator.cs rename to NAPS2.Lib/ImportExport/SaveSeparator.cs diff --git a/NAPS2.Sdk/ImportExport/SaveSeparatorHelper.cs b/NAPS2.Lib/ImportExport/SaveSeparatorHelper.cs similarity index 98% rename from NAPS2.Sdk/ImportExport/SaveSeparatorHelper.cs rename to NAPS2.Lib/ImportExport/SaveSeparatorHelper.cs index 719602eb5..301336b40 100644 --- a/NAPS2.Sdk/ImportExport/SaveSeparatorHelper.cs +++ b/NAPS2.Lib/ImportExport/SaveSeparatorHelper.cs @@ -1,6 +1,6 @@ namespace NAPS2.ImportExport; -public static class SaveSeparatorHelper +internal static class SaveSeparatorHelper { /// /// Given a list of scans (each of which is a list of 1 or more images), diff --git a/NAPS2.Lib/Modules/CommonModule.cs b/NAPS2.Lib/Modules/CommonModule.cs index 4477970f1..d3ae098b4 100644 --- a/NAPS2.Lib/Modules/CommonModule.cs +++ b/NAPS2.Lib/Modules/CommonModule.cs @@ -21,7 +21,7 @@ public class CommonModule : Module protected override void Load(ContainerBuilder builder) { // Import - builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().AsSelf(); diff --git a/NAPS2.Lib/Pdf/SavePdfOperation.cs b/NAPS2.Lib/Pdf/SavePdfOperation.cs index 0217e1ffb..e149b1c3d 100644 --- a/NAPS2.Lib/Pdf/SavePdfOperation.cs +++ b/NAPS2.Lib/Pdf/SavePdfOperation.cs @@ -4,7 +4,7 @@ using NAPS2.Ocr; namespace NAPS2.Pdf; -public class SavePdfOperation : OperationBase +internal class SavePdfOperation : OperationBase { private readonly IPdfExporter _pdfExporter; private readonly IOverwritePrompt _overwritePrompt; diff --git a/NAPS2.Lib/Recovery/RecoverableFolder.cs b/NAPS2.Lib/Recovery/RecoverableFolder.cs index 8f4c208ac..f9d529faa 100644 --- a/NAPS2.Lib/Recovery/RecoverableFolder.cs +++ b/NAPS2.Lib/Recovery/RecoverableFolder.cs @@ -1,4 +1,5 @@ using System.Collections.Immutable; +using NAPS2.ImportExport; using NAPS2.ImportExport.Images; using NAPS2.Scan; using NAPS2.Serialization; @@ -8,14 +9,12 @@ namespace NAPS2.Recovery; public class RecoverableFolder : IDisposable { private readonly ScanningContext _scanningContext; - private readonly ImportPostProcessor _importPostProcessor; private readonly DirectoryInfo _directory; private readonly FileStream _lockFile; private readonly RecoveryIndex _recoveryIndex; private bool _disposed; - public static RecoverableFolder? TryCreate(ScanningContext scanningContext, ImportPostProcessor importPostProcessor, - DirectoryInfo directory) + public static RecoverableFolder? TryCreate(ScanningContext scanningContext, DirectoryInfo directory) { string indexFilePath = Path.Combine(directory.FullName, "index.xml"); string lockFilePath = Path.Combine(directory.FullName, RecoveryStorageManager.LOCK_FILE_NAME); @@ -33,7 +32,7 @@ public class RecoverableFolder : IDisposable // TODO: Consider auto-delete in this case // TODO: Also in the case where you have a lock file but no index is written (especially if no images are present) if (imageCount == 0) return null; - return new RecoverableFolder(scanningContext, importPostProcessor, directory, lockFile, recoveryIndex, + return new RecoverableFolder(scanningContext, directory, lockFile, recoveryIndex, imageCount, scannedDateTime); } catch (Exception) @@ -43,12 +42,10 @@ public class RecoverableFolder : IDisposable } } - public RecoverableFolder(ScanningContext scanningContext, ImportPostProcessor importPostProcessor, - DirectoryInfo directory, FileStream lockFile, RecoveryIndex recoveryIndex, int imageCount, - DateTime scannedDateTime) + public RecoverableFolder(ScanningContext scanningContext, DirectoryInfo directory, FileStream lockFile, + RecoveryIndex recoveryIndex, int imageCount, DateTime scannedDateTime) { _scanningContext = scanningContext; - _importPostProcessor = importPostProcessor; _directory = directory; _lockFile = lockFile; _recoveryIndex = recoveryIndex; @@ -133,7 +130,7 @@ public class RecoverableFolder : IDisposable indexImage.TransformList!.ToImmutableList()); // TODO: Make this take a lazy rendered image or something - processedImage = _importPostProcessor.AddPostProcessingData(processedImage, + processedImage = ImportPostProcessor.AddPostProcessingData(processedImage, null, recoveryParams.ThumbnailSize, new BarcodeDetectionOptions(), diff --git a/NAPS2.Lib/Recovery/RecoveryManager.cs b/NAPS2.Lib/Recovery/RecoveryManager.cs index 3d6f9ea21..a3b4f68f5 100644 --- a/NAPS2.Lib/Recovery/RecoveryManager.cs +++ b/NAPS2.Lib/Recovery/RecoveryManager.cs @@ -6,17 +6,10 @@ namespace NAPS2.Recovery; public class RecoveryManager { private readonly ScanningContext _scanningContext; - private readonly ImportPostProcessor _importPostProcessor; public RecoveryManager(ScanningContext scanningContext) - : this(scanningContext, new ImportPostProcessor()) - { - } - - public RecoveryManager(ScanningContext scanningContext, ImportPostProcessor importPostProcessor) { _scanningContext = scanningContext; - _importPostProcessor = importPostProcessor; } public RecoverableFolder? GetLatestRecoverableFolder() @@ -43,7 +36,7 @@ public class RecoveryManager { try { - return RecoverableFolder.TryCreate(_scanningContext, _importPostProcessor, directory); + return RecoverableFolder.TryCreate(_scanningContext, directory); } catch (Exception) { diff --git a/NAPS2.Sdk.Tests/ImportExport/ImageImporterTests.cs b/NAPS2.Sdk.Tests/ImportExport/ImageImporterTests.cs index 3c98965fd..3ab667be6 100644 --- a/NAPS2.Sdk.Tests/ImportExport/ImageImporterTests.cs +++ b/NAPS2.Sdk.Tests/ImportExport/ImageImporterTests.cs @@ -15,7 +15,7 @@ public class ImageImporterTests : ContextualTests public ImageImporterTests() { - _imageImporter = new ImageImporter(ScanningContext, ImageContext, new ImportPostProcessor()); + _imageImporter = new ImageImporter(ScanningContext); ScanningContext.FileStorageManager = FileStorageManager.CreateFolder(Path.Combine(FolderPath, "recovery")); } diff --git a/NAPS2.Sdk.Tests/ImportExport/ImportPostProcessorTests.cs b/NAPS2.Sdk.Tests/ImportExport/ImportPostProcessorTests.cs index a5afcbe79..2483c5718 100644 --- a/NAPS2.Sdk.Tests/ImportExport/ImportPostProcessorTests.cs +++ b/NAPS2.Sdk.Tests/ImportExport/ImportPostProcessorTests.cs @@ -1,3 +1,4 @@ +using NAPS2.ImportExport; using NAPS2.ImportExport.Images; using NAPS2.Scan; using NAPS2.Sdk.Tests.Asserts; @@ -7,19 +8,12 @@ namespace NAPS2.Sdk.Tests.ImportExport; public class ImportPostProcessorTests : ContextualTests { - private readonly ImportPostProcessor _importPostProcessor; - - public ImportPostProcessorTests() - { - _importPostProcessor = new ImportPostProcessor(); - } - [Fact] public void NoPostProcessing() { using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog)); using var image2 = - _importPostProcessor.AddPostProcessingData(image, null, null, new BarcodeDetectionOptions(), false); + ImportPostProcessor.AddPostProcessingData(image, null, null, new BarcodeDetectionOptions(), false); Assert.Null(image2.PostProcessingData.Thumbnail); Assert.Null(image2.PostProcessingData.ThumbnailTransformState); @@ -34,7 +28,7 @@ public class ImportPostProcessorTests : ContextualTests { using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog)); using var image2 = - _importPostProcessor.AddPostProcessingData(image, null, null, new BarcodeDetectionOptions(), true); + ImportPostProcessor.AddPostProcessingData(image, null, null, new BarcodeDetectionOptions(), true); Assert.False(IsDisposed(image2)); image2.Dispose(); @@ -46,7 +40,7 @@ public class ImportPostProcessorTests : ContextualTests { using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog)); using var image2 = - _importPostProcessor.AddPostProcessingData(image, null, 256, new BarcodeDetectionOptions(), false); + ImportPostProcessor.AddPostProcessingData(image, null, 256, new BarcodeDetectionOptions(), false); var actual = image2.PostProcessingData.Thumbnail; @@ -63,7 +57,7 @@ public class ImportPostProcessorTests : ContextualTests using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.dog)); using var image2 = image.WithTransform(new BrightnessTransform(300)); using var image3 = - _importPostProcessor.AddPostProcessingData(image2, null, 256, new BarcodeDetectionOptions(), false); + ImportPostProcessor.AddPostProcessingData(image2, null, 256, new BarcodeDetectionOptions(), false); var actual = image3.PostProcessingData.Thumbnail; @@ -83,7 +77,7 @@ public class ImportPostProcessorTests : ContextualTests using var rendered = LoadImage(ImageResources.dog); using var image = ScanningContext.CreateProcessedImage(rendered); using var image2 = - _importPostProcessor.AddPostProcessingData(image, rendered, 256, new BarcodeDetectionOptions(), true); + ImportPostProcessor.AddPostProcessingData(image, rendered, 256, new BarcodeDetectionOptions(), true); var actual = image2.PostProcessingData.Thumbnail; @@ -103,7 +97,7 @@ public class ImportPostProcessorTests : ContextualTests { using var image = ScanningContext.CreateProcessedImage(LoadImage(ImageResources.patcht)); var barcodeOptions = new BarcodeDetectionOptions { DetectBarcodes = true }; - using var image2 = _importPostProcessor.AddPostProcessingData(image, null, null, barcodeOptions, false); + using var image2 = ImportPostProcessor.AddPostProcessingData(image, null, null, barcodeOptions, false); Assert.True(image2.PostProcessingData.Barcode.IsPatchT); } @@ -114,7 +108,7 @@ public class ImportPostProcessorTests : ContextualTests using var rendered = LoadImage(ImageResources.patcht); using var image = ScanningContext.CreateProcessedImage(rendered); var barcodeOptions = new BarcodeDetectionOptions { DetectBarcodes = true }; - using var image2 = _importPostProcessor.AddPostProcessingData(image, rendered, null, barcodeOptions, false); + using var image2 = ImportPostProcessor.AddPostProcessingData(image, rendered, null, barcodeOptions, false); Assert.True(image2.PostProcessingData.Barcode.IsPatchT); } diff --git a/NAPS2.Sdk.Tests/Worker/WorkerChannelTests.cs b/NAPS2.Sdk.Tests/Worker/WorkerChannelTests.cs index 3916e9e7f..06b44d1ef 100644 --- a/NAPS2.Sdk.Tests/Worker/WorkerChannelTests.cs +++ b/NAPS2.Sdk.Tests/Worker/WorkerChannelTests.cs @@ -21,7 +21,7 @@ public class WorkerChannelTests : ContextualTests NamedPipeServer server = new NamedPipeServer(pipeName); WorkerService.BindService(server.ServiceBinder, new WorkerServiceImpl(ScanningContext, remoteScanController, thumbnailRenderer, mapiWrapper, - twainSessionController, new ImportPostProcessor())); + twainSessionController)); server.Start(); var client = new WorkerServiceAdapter(new NamedPipeChannel(".", pipeName)); return new Channel diff --git a/NAPS2.Sdk/ImportExport/ScannedImageImporter.cs b/NAPS2.Sdk/ImportExport/FileImporter.cs similarity index 85% rename from NAPS2.Sdk/ImportExport/ScannedImageImporter.cs rename to NAPS2.Sdk/ImportExport/FileImporter.cs index 1825fe943..d4abd819e 100644 --- a/NAPS2.Sdk/ImportExport/ScannedImageImporter.cs +++ b/NAPS2.Sdk/ImportExport/FileImporter.cs @@ -3,12 +3,12 @@ using NAPS2.Pdf; namespace NAPS2.ImportExport; -public class ScannedImageImporter : IScannedImageImporter +public class FileImporter : IFileImporter { - private readonly IScannedImageImporter _pdfImporter; - private readonly IScannedImageImporter _imageImporter; + private readonly IFileImporter _pdfImporter; + private readonly IFileImporter _imageImporter; - public ScannedImageImporter(IPdfImporter pdfImporter, IImageImporter imageImporter) + public FileImporter(IPdfImporter pdfImporter, IImageImporter imageImporter) { _pdfImporter = pdfImporter; _imageImporter = imageImporter; diff --git a/NAPS2.Sdk/ImportExport/IScannedImageImporter.cs b/NAPS2.Sdk/ImportExport/IFileImporter.cs similarity index 80% rename from NAPS2.Sdk/ImportExport/IScannedImageImporter.cs rename to NAPS2.Sdk/ImportExport/IFileImporter.cs index 09da6aff8..7a3aacf56 100644 --- a/NAPS2.Sdk/ImportExport/IScannedImageImporter.cs +++ b/NAPS2.Sdk/ImportExport/IFileImporter.cs @@ -1,6 +1,6 @@ namespace NAPS2.ImportExport; -public interface IScannedImageImporter +public interface IFileImporter { IAsyncEnumerable Import(string filePath, ImportParams importParams, ProgressHandler progress = default); } \ No newline at end of file diff --git a/NAPS2.Sdk/ImportExport/IImageImporter.cs b/NAPS2.Sdk/ImportExport/IImageImporter.cs new file mode 100644 index 000000000..f20097c5c --- /dev/null +++ b/NAPS2.Sdk/ImportExport/IImageImporter.cs @@ -0,0 +1,5 @@ +namespace NAPS2.ImportExport; + +public interface IImageImporter : IFileImporter +{ +} \ No newline at end of file diff --git a/NAPS2.Sdk/ImportExport/Images/ImageImporter.cs b/NAPS2.Sdk/ImportExport/ImageImporter.cs similarity index 83% rename from NAPS2.Sdk/ImportExport/Images/ImageImporter.cs rename to NAPS2.Sdk/ImportExport/ImageImporter.cs index 7365a591a..33454b998 100644 --- a/NAPS2.Sdk/ImportExport/Images/ImageImporter.cs +++ b/NAPS2.Sdk/ImportExport/ImageImporter.cs @@ -1,20 +1,15 @@ using Microsoft.Extensions.Logging; using NAPS2.Scan; -namespace NAPS2.ImportExport.Images; +namespace NAPS2.ImportExport; public class ImageImporter : IImageImporter { private readonly ScanningContext _scanningContext; - private readonly ImageContext _imageContext; - private readonly ImportPostProcessor _importPostProcessor; - public ImageImporter(ScanningContext scanningContext, ImageContext imageContext, - ImportPostProcessor importPostProcessor) + public ImageImporter(ScanningContext scanningContext) { _scanningContext = scanningContext; - _imageContext = imageContext; - _importPostProcessor = importPostProcessor; } public IAsyncEnumerable Import(string filePath, ImportParams importParams, @@ -28,7 +23,7 @@ public class ImageImporter : IImageImporter try { var toImport = - _imageContext.LoadFrames(filePath, new ProgressCallback((current, max) => + _scanningContext.ImageContext.LoadFrames(filePath, new ProgressCallback((current, max) => { frameCount = max; if (current == 0) @@ -53,7 +48,7 @@ public class ImageImporter : IImageImporter lossless, -1, null); - image = _importPostProcessor.AddPostProcessingData( + image = ImportPostProcessor.AddPostProcessingData( image, frame, importParams.ThumbnailSize, diff --git a/NAPS2.Sdk/ImportExport/Images/IImageImporter.cs b/NAPS2.Sdk/ImportExport/Images/IImageImporter.cs deleted file mode 100644 index 7312be179..000000000 --- a/NAPS2.Sdk/ImportExport/Images/IImageImporter.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace NAPS2.ImportExport.Images; - -public interface IImageImporter : IScannedImageImporter -{ -} \ No newline at end of file diff --git a/NAPS2.Sdk/ImportExport/Images/ImportPostProcessor.cs b/NAPS2.Sdk/ImportExport/ImportPostProcessor.cs similarity index 78% rename from NAPS2.Sdk/ImportExport/Images/ImportPostProcessor.cs rename to NAPS2.Sdk/ImportExport/ImportPostProcessor.cs index 6519f664e..fee9c7293 100644 --- a/NAPS2.Sdk/ImportExport/Images/ImportPostProcessor.cs +++ b/NAPS2.Sdk/ImportExport/ImportPostProcessor.cs @@ -1,11 +1,10 @@ using NAPS2.Scan; -namespace NAPS2.ImportExport.Images; +namespace NAPS2.ImportExport; -// TODO: Maybe make this static (and ImportExportHelper, ImageClipboard, etc.) now that ImageContext is on the image -public class ImportPostProcessor +internal static class ImportPostProcessor { - public ProcessedImage AddPostProcessingData(ProcessedImage image, IMemoryImage? rendered, int? thumbnailSize, + public static ProcessedImage AddPostProcessingData(ProcessedImage image, IMemoryImage? rendered, int? thumbnailSize, BarcodeDetectionOptions barcodeDetectionOptions, bool disposeOriginalImage) { if (!thumbnailSize.HasValue && !barcodeDetectionOptions.DetectBarcodes) diff --git a/NAPS2.Sdk/ImportExport/Placeholders.cs b/NAPS2.Sdk/ImportExport/Placeholders.cs index e9b8177d9..b0f82bf2a 100644 --- a/NAPS2.Sdk/ImportExport/Placeholders.cs +++ b/NAPS2.Sdk/ImportExport/Placeholders.cs @@ -7,7 +7,7 @@ namespace NAPS2.ImportExport; /// Class for handling substitution of special values in file paths. For example, "$(YYYY)" can be substituted with the current year. /// Use Placeholders.All for recommended substitutions. Alternatively, you can use Placeholders.Env or Placeholders.None if you prefer. /// -public abstract class Placeholders +internal abstract class Placeholders { public const string YEAR_4_DIGITS = "$(YYYY)"; public const string YEAR_2_DIGITS = "$(YY)"; diff --git a/NAPS2.Sdk/Pdf/IPdfImporter.cs b/NAPS2.Sdk/Pdf/IPdfImporter.cs index 2df426d2f..f00067805 100644 --- a/NAPS2.Sdk/Pdf/IPdfImporter.cs +++ b/NAPS2.Sdk/Pdf/IPdfImporter.cs @@ -2,6 +2,6 @@ namespace NAPS2.Pdf; -public interface IPdfImporter : IScannedImageImporter +public interface IPdfImporter : IFileImporter { } \ No newline at end of file diff --git a/NAPS2.Sdk/Pdf/PdfImporter.cs b/NAPS2.Sdk/Pdf/PdfImporter.cs index 1efef787e..ea8e40a78 100644 --- a/NAPS2.Sdk/Pdf/PdfImporter.cs +++ b/NAPS2.Sdk/Pdf/PdfImporter.cs @@ -11,24 +11,11 @@ public class PdfImporter : IPdfImporter private readonly ScanningContext _scanningContext; private readonly IPdfPasswordProvider? _pdfPasswordProvider; - private readonly ImportPostProcessor _importPostProcessor; - public PdfImporter(ScanningContext scanningContext) - : this(scanningContext, null) - { - } - - public PdfImporter(ScanningContext scanningContext, IPdfPasswordProvider? pdfPasswordProvider) - : this(scanningContext, pdfPasswordProvider, new ImportPostProcessor()) - { - } - - internal PdfImporter(ScanningContext scanningContext, IPdfPasswordProvider? pdfPasswordProvider, - ImportPostProcessor importPostProcessor) + public PdfImporter(ScanningContext scanningContext, IPdfPasswordProvider? pdfPasswordProvider = null) { _scanningContext = scanningContext; _pdfPasswordProvider = pdfPasswordProvider; - _importPostProcessor = importPostProcessor; } public IAsyncEnumerable Import(string filePath, ImportParams? importParams = null, @@ -113,7 +100,7 @@ public class PdfImporter : IPdfImporter { var pageSize = new PageSize((decimal) page.Width * 72, (decimal) page.Height * 72, PageSizeUnit.Inch); var image = _scanningContext.CreateProcessedImage(storage, BitDepth.Color, false, -1, pageSize); - return _importPostProcessor.AddPostProcessingData( + return ImportPostProcessor.AddPostProcessingData( image, storage, importParams.ThumbnailSize, @@ -143,7 +130,7 @@ public class PdfImporter : IPdfImporter } var image = _scanningContext.CreateProcessedImage(storage); - return _importPostProcessor.AddPostProcessingData( + return ImportPostProcessor.AddPostProcessingData( image, null, importParams.ThumbnailSize, diff --git a/NAPS2.Sdk/Remoting/Worker/WorkerServiceImpl.cs b/NAPS2.Sdk/Remoting/Worker/WorkerServiceImpl.cs index 7eb2cc1aa..efcc548a0 100644 --- a/NAPS2.Sdk/Remoting/Worker/WorkerServiceImpl.cs +++ b/NAPS2.Sdk/Remoting/Worker/WorkerServiceImpl.cs @@ -1,6 +1,7 @@ using System.Threading; using Google.Protobuf; using Grpc.Core; +using NAPS2.ImportExport; using NAPS2.ImportExport.Email; using NAPS2.ImportExport.Email.Mapi; using NAPS2.ImportExport.Images; @@ -23,7 +24,6 @@ internal class WorkerServiceImpl : WorkerService.WorkerServiceBase private readonly ThumbnailRenderer _thumbnailRenderer; private readonly IMapiWrapper _mapiWrapper; private readonly ITwainSessionController _twainSessionController; - private readonly ImportPostProcessor _importPostProcessor; private readonly AutoResetEvent _ongoingCallFinished = new(false); private int _ongoingCallCount; @@ -31,22 +31,19 @@ internal class WorkerServiceImpl : WorkerService.WorkerServiceBase public WorkerServiceImpl(ScanningContext scanningContext, ThumbnailRenderer thumbnailRenderer, IMapiWrapper mapiWrapper, ITwainSessionController twainSessionController) : this(scanningContext, new RemoteScanController(scanningContext), - thumbnailRenderer, mapiWrapper, twainSessionController, - new ImportPostProcessor()) + thumbnailRenderer, mapiWrapper, twainSessionController) { } internal WorkerServiceImpl(ScanningContext scanningContext, IRemoteScanController remoteScanController, ThumbnailRenderer thumbnailRenderer, - IMapiWrapper mapiWrapper, ITwainSessionController twainSessionController, - ImportPostProcessor importPostProcessor) + IMapiWrapper mapiWrapper, ITwainSessionController twainSessionController) { _scanningContext = scanningContext; _remoteScanController = remoteScanController; _thumbnailRenderer = thumbnailRenderer; _mapiWrapper = mapiWrapper; _twainSessionController = twainSessionController; - _importPostProcessor = importPostProcessor; } public override Task Init(InitRequest request, ServerCallContext context) @@ -268,7 +265,7 @@ internal class WorkerServiceImpl : WorkerService.WorkerServiceBase int? thumbnailSize = request.ThumbnailSize == 0 ? null : request.ThumbnailSize; var barcodeOptions = request.BarcodeDetectionOptionsXml.FromXml(); using var newImage = - _importPostProcessor.AddPostProcessingData(image, null, thumbnailSize, barcodeOptions, true); + ImportPostProcessor.AddPostProcessingData(image, null, thumbnailSize, barcodeOptions, true); return Task.FromResult(new ImportPostProcessResponse { Image = ImageSerializer.Serialize(newImage,