Use ScanningContext to create images in PdfSharpImporter

This commit is contained in:
Ben Olden-Cooligan 2022-07-23 09:36:06 -07:00
parent 862c6662f9
commit d6440ba747
6 changed files with 12 additions and 13 deletions

View File

@ -83,8 +83,7 @@ public class RecoveryStorageManagerTests : ContextualTests
new GdiImage(new Bitmap(100, 100)),
BitDepth.Grayscale,
true,
-1,
Enumerable.Empty<Transform>()));
-1));
_recoveryStorageManager.WriteIndex(new[] {image1});
var indexFileContent = File.ReadAllText(Path.Combine(_recoveryFolder, "index.xml"));

View File

@ -127,7 +127,7 @@ internal static class TwainApi
// TODO: Clean this up a bit
using Bitmap bmp = DibUtils.BitmapFromDib(img, out bitcount);
Bitmaps.Add(_scanningContext.CreateProcessedImage(new GdiImage(bmp), bitcount == 1 ? BitDepth.BlackAndWhite : BitDepth.Color, _settings.MaxQuality, _settings.Quality, Enumerable.Empty<Transform>()));
Bitmaps.Add(_scanningContext.CreateProcessedImage(new GdiImage(bmp), bitcount == 1 ? BitDepth.BlackAndWhite : BitDepth.Color, _settings.MaxQuality, _settings.Quality));
}
_form.Close();
break;

View File

@ -60,8 +60,7 @@ public class ImageImporter : IImageImporter
frame,
BitDepth.Color,
lossless,
-1,
Enumerable.Empty<Transform>());
-1);
image = _importPostProcessor.AddPostProcessingData(
image,
frame,

View File

@ -11,6 +11,7 @@ using PdfSharp.Pdf.IO;
namespace NAPS2.ImportExport.Pdf;
// TODO: We should have a "nicer" name (PdfImporter) for SDK users, or maybe have this be internal and have the public ScannedImageImporter (which should also maybe be renamed...)
// TODO: Add tests
public class PdfSharpImporter : IPdfImporter
{
static PdfSharpImporter()
@ -228,11 +229,7 @@ public class PdfSharpImporter : IPdfImporter
using var memoryStream = new MemoryStream(imageBytes);
using var storage = _scanningContext.ImageContext.Load(memoryStream);
storage.SetResolution(storage.Width / (float) page.Width.Inch, storage.Height / (float) page.Height.Inch);
var image = new ProcessedImage(
storage,
new ImageMetadata(BitDepth.Color, false),
new PostProcessingData(),
TransformState.Empty);
var image = _scanningContext.CreateProcessedImage(storage, BitDepth.Color, false, -1);
return _importPostProcessor.AddPostProcessingData(
image,
storage,
@ -270,8 +267,7 @@ public class PdfSharpImporter : IPdfImporter
using (storage)
{
storage.SetResolution(storage.Width / (float) page.Width.Inch, storage.Height / (float) page.Height.Inch);
// TODO: This should probably use CreateProcessedImage to convert the storage? And also make a copy/clone if needed
var image = new ProcessedImage(storage, new ImageMetadata(bitDepth, true), new PostProcessingData(), TransformState.Empty);
var image = _scanningContext.CreateProcessedImage(storage, bitDepth, true, -1);
return _importPostProcessor.AddPostProcessingData(
image,
storage,

View File

@ -41,7 +41,7 @@ internal class RemotePostProcessor : IRemotePostProcessor
var bitDepth = options.UseNativeUI ? BitDepth.Color : options.BitDepth;
var scannedImage = _scanningContext.CreateProcessedImage(image, bitDepth, options.MaxQuality,
options.Quality, Enumerable.Empty<Transform>());
options.Quality);
DoRevertibleTransforms(ref scannedImage, ref image, options, postProcessingContext);
postProcessingContext.TempPath = SaveForBackgroundOcr(image, options);
// TODO: We need to attach the thumbnail to the scanned image

View File

@ -54,6 +54,11 @@ public class ScanningContext : IDisposable
return CreateProcessedImage(storage, BitDepth.Color, false, -1, transforms);
}
public ProcessedImage CreateProcessedImage(IImageStorage storage, BitDepth bitDepth, bool lossless, int quality)
{
return CreateProcessedImage(storage, bitDepth, lossless, quality, Enumerable.Empty<Transform>());
}
public ProcessedImage CreateProcessedImage(IImageStorage storage, BitDepth bitDepth, bool lossless, int quality,
IEnumerable<Transform> transforms)
{