diff --git a/NAPS2.Images.Gdi/GdiImage.cs b/NAPS2.Images.Gdi/GdiImage.cs index a3cebb55f..114bd2155 100644 --- a/NAPS2.Images.Gdi/GdiImage.cs +++ b/NAPS2.Images.Gdi/GdiImage.cs @@ -12,10 +12,8 @@ namespace NAPS2.Images.Gdi; #endif public class GdiImage : IMemoryImage { - public GdiImage(ImageContext imageContext, Bitmap bitmap) + public GdiImage(Bitmap bitmap) { - if (imageContext is not GdiImageContext) throw new ArgumentException("Expected GdiImageContext"); - ImageContext = imageContext; if (bitmap == null) { throw new ArgumentNullException(nameof(bitmap)); @@ -25,7 +23,7 @@ public class GdiImage : IMemoryImage OriginalFileFormat = bitmap.RawFormat.AsImageFileFormat(); } - public ImageContext ImageContext { get; } + public ImageContext ImageContext { get; } = new GdiImageContext(); /// /// Gets the underlying System.Drawing.Bitmap object for this image. diff --git a/NAPS2.Images.Gdi/GdiImageContext.cs b/NAPS2.Images.Gdi/GdiImageContext.cs index e8585f3a0..4c7b14c50 100644 --- a/NAPS2.Images.Gdi/GdiImageContext.cs +++ b/NAPS2.Images.Gdi/GdiImageContext.cs @@ -28,7 +28,7 @@ public class GdiImageContext : ImageContext { var memoryStream = EnsureMemoryStream(stream); using var bitmap = new Bitmap(memoryStream); - return new GdiImage(this, bitmap).Copy(); + return new GdiImage(bitmap).Copy(); } protected override void LoadFramesCore(Action produceImage, Stream stream, @@ -42,7 +42,7 @@ public class GdiImageContext : ImageContext progress.Report(i, count); if (progress.IsCancellationRequested) break; bitmap.SelectActiveFrame(FrameDimension.Page, i); - produceImage(new GdiImage(this, bitmap).Copy()); + produceImage(new GdiImage(bitmap).Copy()); } progress.Report(count, count); } @@ -85,6 +85,6 @@ public class GdiImageContext : ImageContext } bitmap.Palette = p; } - return new GdiImage(this, bitmap); + return new GdiImage(bitmap); } } \ No newline at end of file diff --git a/NAPS2.Images.Gdi/GdiImageTransformer.cs b/NAPS2.Images.Gdi/GdiImageTransformer.cs index 9987b5231..e678398d6 100644 --- a/NAPS2.Images.Gdi/GdiImageTransformer.cs +++ b/NAPS2.Images.Gdi/GdiImageTransformer.cs @@ -53,7 +53,7 @@ public class GdiImageTransformer : AbstractImageTransformer g.TranslateTransform(-image.Width / 2.0f, -image.Height / 2.0f); g.DrawImage(image.Bitmap, new Rectangle(0, 0, image.Width, image.Height)); } - var resultImage = new GdiImage(ImageContext, result); + var resultImage = new GdiImage(result); OptimizePixelFormat(image, ref resultImage); image.Dispose(); return resultImage; @@ -82,6 +82,6 @@ public class GdiImageTransformer : AbstractImageTransformer image.HorizontalResolution * image.Width / transform.Width, image.VerticalResolution * image.Height / transform.Height); image.Dispose(); - return new GdiImage(ImageContext, result); + return new GdiImage(result); } } \ No newline at end of file diff --git a/NAPS2.Images.Gtk/GtkImage.cs b/NAPS2.Images.Gtk/GtkImage.cs index 2f3518cac..73c9ad785 100644 --- a/NAPS2.Images.Gtk/GtkImage.cs +++ b/NAPS2.Images.Gtk/GtkImage.cs @@ -7,17 +7,15 @@ namespace NAPS2.Images.Gtk; public class GtkImage : IMemoryImage { - public GtkImage(ImageContext imageContext, Pixbuf pixbuf) + public GtkImage(Pixbuf pixbuf) { - if (imageContext is not GtkImageContext) throw new ArgumentException("Expected GtkImageContext"); LeakTracer.StartTracking(this); - ImageContext = imageContext; Pixbuf = pixbuf; HorizontalResolution = float.TryParse(pixbuf.GetOption("x-dpi"), out var xDpi) ? xDpi : 0; VerticalResolution = float.TryParse(pixbuf.GetOption("y-dpi"), out var yDpi) ? yDpi : 0; } - public ImageContext ImageContext { get; } + public ImageContext ImageContext { get; } = new GtkImageContext(); public Pixbuf Pixbuf { get; } @@ -142,7 +140,7 @@ public class GtkImage : IMemoryImage return (keys.ToArray(), values.ToArray()); } - public IMemoryImage Clone() => new GtkImage(ImageContext, (Pixbuf) Pixbuf.Clone()) + public IMemoryImage Clone() => new GtkImage((Pixbuf) Pixbuf.Clone()) { OriginalFileFormat = OriginalFileFormat, LogicalPixelFormat = LogicalPixelFormat, diff --git a/NAPS2.Images.Gtk/GtkImageContext.cs b/NAPS2.Images.Gtk/GtkImageContext.cs index 71b1f0368..102a54aee 100644 --- a/NAPS2.Images.Gtk/GtkImageContext.cs +++ b/NAPS2.Images.Gtk/GtkImageContext.cs @@ -32,7 +32,7 @@ public class GtkImageContext : ImageContext _tiffIo.LoadTiff(img => { image = img; cts.Cancel(); }, stream, cts.Token); return image; } - return new GtkImage(this, new Pixbuf(stream)); + return new GtkImage(new Pixbuf(stream)); } protected override void LoadFramesCore(Action produceImage, Stream stream, @@ -65,6 +65,6 @@ public class GtkImageContext : ImageContext throw new ArgumentException("Unsupported pixel format"); } var pixbuf = new Pixbuf(Colorspace.Rgb, pixelFormat == ImagePixelFormat.ARGB32, 8, width, height); - return new GtkImage(this, pixbuf); + return new GtkImage(pixbuf); } } \ No newline at end of file diff --git a/NAPS2.Images.Gtk/GtkImageTransformer.cs b/NAPS2.Images.Gtk/GtkImageTransformer.cs index 108d95460..b1f226068 100644 --- a/NAPS2.Images.Gtk/GtkImageTransformer.cs +++ b/NAPS2.Images.Gtk/GtkImageTransformer.cs @@ -31,7 +31,7 @@ public class GtkImageTransformer : AbstractImageTransformer context.Translate(-image.Width / 2.0, -image.Height / 2.0); CairoHelper.SetSourcePixbuf(context, image.Pixbuf, 0, 0); context.Paint(); - var newImage = new GtkImage(ImageContext, new Pixbuf(surface, 0, 0, width, height)); + var newImage = new GtkImage(new Pixbuf(surface, 0, 0, width, height)); OptimizePixelFormat(image, ref newImage); newImage.LogicalPixelFormat = image.LogicalPixelFormat; newImage.SetResolution(xres, yres); @@ -49,7 +49,7 @@ public class GtkImageTransformer : AbstractImageTransformer context.Scale(transform.Width / (double) image.Width, transform.Height / (double) image.Height); CairoHelper.SetSourcePixbuf(context, image.Pixbuf, 0, 0); context.Paint(); - var newImage = new GtkImage(ImageContext, new Pixbuf(surface, 0, 0, transform.Width, transform.Height)); + var newImage = new GtkImage(new Pixbuf(surface, 0, 0, transform.Width, transform.Height)); newImage.LogicalPixelFormat = image.LogicalPixelFormat == ImagePixelFormat.BW1 ? ImagePixelFormat.Gray8 : image.LogicalPixelFormat; diff --git a/NAPS2.Images.ImageSharp/ImageSharpImage.cs b/NAPS2.Images.ImageSharp/ImageSharpImage.cs index 5c0948dfe..46d27a7f9 100644 --- a/NAPS2.Images.ImageSharp/ImageSharpImage.cs +++ b/NAPS2.Images.ImageSharp/ImageSharpImage.cs @@ -15,17 +15,15 @@ namespace NAPS2.Images.ImageSharp; public class ImageSharpImage : IMemoryImage { - public ImageSharpImage(ImageContext imageContext, Image image) + public ImageSharpImage(Image image) { - if (imageContext is not ImageSharpImageContext) throw new ArgumentException("Expected ImageSharpImageContext"); LeakTracer.StartTracking(this); - ImageContext = imageContext; // TODO: Something similar to MacImage where if it's not a supported pixel type we convert // TODO: Though we might also want to add support where reasonable, e.g. we can probably support argb or bgr pretty easily? Image = image; } - public ImageContext ImageContext { get; } + public ImageContext ImageContext { get; } = new ImageSharpImageContext(); public Image Image { get; } @@ -156,7 +154,7 @@ public class ImageSharpImage : IMemoryImage return encoder; } - public IMemoryImage Clone() => new ImageSharpImage(ImageContext, Image.Clone(_ => { })) + public IMemoryImage Clone() => new ImageSharpImage(Image.Clone(_ => { })) { OriginalFileFormat = OriginalFileFormat, LogicalPixelFormat = LogicalPixelFormat diff --git a/NAPS2.Images.ImageSharp/ImageSharpImageContext.cs b/NAPS2.Images.ImageSharp/ImageSharpImageContext.cs index 0bd6fead5..31d6d213f 100644 --- a/NAPS2.Images.ImageSharp/ImageSharpImageContext.cs +++ b/NAPS2.Images.ImageSharp/ImageSharpImageContext.cs @@ -36,7 +36,7 @@ public class ImageSharpImageContext : ImageContext protected override IMemoryImage LoadCore(Stream stream, ImageFileFormat format) { - return new ImageSharpImage(this, Image.Load(GetDecoderOptions(), stream)); + return new ImageSharpImage(Image.Load(GetDecoderOptions(), stream)); } protected override void LoadFramesCore(Action produceImage, Stream stream, @@ -66,6 +66,6 @@ public class ImageSharpImageContext : ImageContext ImagePixelFormat.Gray8 or ImagePixelFormat.BW1 => new Image(GetConfiguration(), width, height), _ => throw new InvalidOperationException("Unsupported pixel format") }; - return new ImageSharpImage(this, image); + return new ImageSharpImage(image); } } \ No newline at end of file diff --git a/NAPS2.Images.ImageSharp/ImageSharpImageTransformer.cs b/NAPS2.Images.ImageSharp/ImageSharpImageTransformer.cs index a94013625..a81021dff 100644 --- a/NAPS2.Images.ImageSharp/ImageSharpImageTransformer.cs +++ b/NAPS2.Images.ImageSharp/ImageSharpImageTransformer.cs @@ -33,7 +33,7 @@ public class ImageSharpImageTransformer : AbstractImageTransformer x.Crop(cropRect)); - var newImage = new ImageSharpImage(ImageContext, copy); + var newImage = new ImageSharpImage(copy); // TODO: In Gdi, we convert this back to BW1. Should we do the same? newImage.LogicalPixelFormat = image.LogicalPixelFormat == ImagePixelFormat.BW1 ? ImagePixelFormat.Gray8 diff --git a/NAPS2.Images.Mac/MacImage.cs b/NAPS2.Images.Mac/MacImage.cs index 076618126..dea1ff20d 100644 --- a/NAPS2.Images.Mac/MacImage.cs +++ b/NAPS2.Images.Mac/MacImage.cs @@ -4,10 +4,8 @@ namespace NAPS2.Images.Mac; public class MacImage : IMemoryImage { - public MacImage(ImageContext imageContext, NSImage image) + public MacImage(NSImage image) { - if (imageContext is not MacImageContext) throw new ArgumentException("Expected MacImageContext"); - ImageContext = imageContext; NsImage = image ?? throw new ArgumentNullException(nameof(image)); var reps = NsImage.Representations(); if (reps.Length != 1) @@ -69,7 +67,7 @@ public class MacImage : IMemoryImage }; } - public ImageContext ImageContext { get; } + public ImageContext ImageContext { get; } = new MacImageContext(); public NSImage NsImage { get; } @@ -208,7 +206,7 @@ public class MacImage : IMemoryImage #else var nsImage = (NSImage) NsImage.Copy(); #endif - return new MacImage(ImageContext, nsImage) + return new MacImage(nsImage) { OriginalFileFormat = OriginalFileFormat, LogicalPixelFormat = LogicalPixelFormat diff --git a/NAPS2.Images.Mac/MacImageContext.cs b/NAPS2.Images.Mac/MacImageContext.cs index 53fbee225..583a1ee9a 100644 --- a/NAPS2.Images.Mac/MacImageContext.cs +++ b/NAPS2.Images.Mac/MacImageContext.cs @@ -37,7 +37,7 @@ public class MacImageContext : ImageContext image.Dispose(); return CreateImage(reps[0]); } - return new MacImage(this, image); + return new MacImage(image); } finally { @@ -93,7 +93,7 @@ public class MacImageContext : ImageContext frame = new NSImage(rep.Size); } frame.AddRepresentation(rep); - return new MacImage(this, frame); + return new MacImage(frame); } public override IMemoryImage Create(int width, int height, ImagePixelFormat pixelFormat) @@ -104,7 +104,7 @@ public class MacImageContext : ImageContext var image = new NSImage(rep.Size); image.AddRepresentation(rep); rep.Dispose(); - return new MacImage(this, image); + return new MacImage(image); } } } \ No newline at end of file diff --git a/NAPS2.Images.Wpf/WpfImage.cs b/NAPS2.Images.Wpf/WpfImage.cs index 9187fcb37..1b90395c5 100644 --- a/NAPS2.Images.Wpf/WpfImage.cs +++ b/NAPS2.Images.Wpf/WpfImage.cs @@ -19,18 +19,16 @@ public class WpfImage : IMemoryImage private bool _disposed; - public WpfImage(ImageContext imageContext, WriteableBitmap bitmap) + public WpfImage(WriteableBitmap bitmap) { - if (imageContext is not WpfImageContext) throw new ArgumentException("Expected WpfImageContext"); LeakTracer.StartTracking(this); - ImageContext = imageContext; // TODO: Something similar to MacImage where if it's not a supported pixel type we convert WpfPixelFormatFixer.MaybeFixPixelFormat(ref bitmap); Bitmap = bitmap; DetachFromDispatcher(Bitmap); } - public ImageContext ImageContext { get; } + public ImageContext ImageContext { get; } = new WpfImageContext(); public WriteableBitmap Bitmap { get; private set; } @@ -166,7 +164,7 @@ public class WpfImage : IMemoryImage public IMemoryImage Clone() { if (_disposed) throw new InvalidOperationException(); - return new WpfImage(ImageContext, Bitmap.Clone()) + return new WpfImage(Bitmap.Clone()) { OriginalFileFormat = OriginalFileFormat, LogicalPixelFormat = LogicalPixelFormat diff --git a/NAPS2.Images.Wpf/WpfImageContext.cs b/NAPS2.Images.Wpf/WpfImageContext.cs index 22a0335ae..94b455498 100644 --- a/NAPS2.Images.Wpf/WpfImageContext.cs +++ b/NAPS2.Images.Wpf/WpfImageContext.cs @@ -32,7 +32,7 @@ public class WpfImageContext : ImageContext bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); bitmap.Freeze(); - return new WpfImage(this, new WriteableBitmap(bitmap)); + return new WpfImage(new WriteableBitmap(bitmap)); } protected override void LoadFramesCore(Action produceImage, Stream stream, @@ -46,7 +46,7 @@ public class WpfImageContext : ImageContext foreach (var frame in decoder.Frames) { if (progress.IsCancellationRequested) return; - produceImage(new WpfImage(this, new WriteableBitmap(frame))); + produceImage(new WpfImage(new WriteableBitmap(frame))); progress.Report(++i, decoder.Frames.Count); } return; @@ -77,6 +77,6 @@ public class WpfImageContext : ImageContext _ => throw new InvalidOperationException("Unsupported pixel format") }; var image = new WriteableBitmap(width, height, 0, 0, wpfPixelFormat, null); - return new WpfImage(this, image); + return new WpfImage(image); } } \ No newline at end of file diff --git a/NAPS2.Images.Wpf/WpfImageTransformer.cs b/NAPS2.Images.Wpf/WpfImageTransformer.cs index 00b1c152f..aa8fe41fd 100644 --- a/NAPS2.Images.Wpf/WpfImageTransformer.cs +++ b/NAPS2.Images.Wpf/WpfImageTransformer.cs @@ -34,7 +34,7 @@ public class WpfImageTransformer : AbstractImageTransformer var rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default); rtb.Render(visual); - var newImage = new WpfImage(ImageContext, new WriteableBitmap(rtb)); + var newImage = new WpfImage(new WriteableBitmap(rtb)); // TODO: In Gdi, we convert this back to BW1 (or the original pixel format). Should we do the same? newImage.LogicalPixelFormat = image.LogicalPixelFormat == ImagePixelFormat.BW1 ? ImagePixelFormat.Gray8 @@ -49,7 +49,7 @@ public class WpfImageTransformer : AbstractImageTransformer var copy = new TransformedBitmap(image.Bitmap, new System.Windows.Media.ScaleTransform(transform.Width / (double) image.Width, transform.Height / (double) image.Height)); - var newImage = new WpfImage(ImageContext, new WriteableBitmap(copy)); + var newImage = new WpfImage(new WriteableBitmap(copy)); newImage.LogicalPixelFormat = image.LogicalPixelFormat == ImagePixelFormat.BW1 ? ImagePixelFormat.Gray8 : image.LogicalPixelFormat; diff --git a/NAPS2.Images/IMemoryImage.cs b/NAPS2.Images/IMemoryImage.cs index 2ebf25798..4b4ea01a0 100644 --- a/NAPS2.Images/IMemoryImage.cs +++ b/NAPS2.Images/IMemoryImage.cs @@ -8,8 +8,6 @@ namespace NAPS2.Images; /// public interface IMemoryImage : IImageStorage { - // TODO: Now that ImageContext objects are fully stateless, we can maybe eliminate ImageContext as a parameter - // in IMemoryImage constructors and just create the appropriate ImageContext objects automatically. /// /// Gets the image context used to create this image. /// diff --git a/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkEtoPlatform.cs b/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkEtoPlatform.cs index c8e503333..22dd8ed25 100644 --- a/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkEtoPlatform.cs +++ b/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkEtoPlatform.cs @@ -44,9 +44,9 @@ public class GtkEtoPlatform : EtoPlatform return new Bitmap(new BitmapHandler(pixbuf)); } - public override IMemoryImage FromBitmap(ImageContext imageContext, Bitmap bitmap) + public override IMemoryImage FromBitmap(Bitmap bitmap) { - return new GtkImage(imageContext, bitmap.ToGdk()); + return new GtkImage(bitmap.ToGdk()); } public override void SetClipboardImage(Clipboard clipboard, ProcessedImage processedImage, IMemoryImage memoryImage) @@ -57,7 +57,7 @@ public class GtkEtoPlatform : EtoPlatform clipboard.Image = memoryImage.ToEtoImage(); } - public override IMemoryImage DrawHourglass(ImageContext imageContext, IMemoryImage image) + public override IMemoryImage DrawHourglass(IMemoryImage image) { // TODO return image; diff --git a/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs b/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs index f42064c01..de9f25608 100644 --- a/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs +++ b/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs @@ -59,12 +59,12 @@ public class MacEtoPlatform : EtoPlatform return new Bitmap(new BitmapHandler((NSImage) nsImage.Copy())); } - public override IMemoryImage FromBitmap(ImageContext imageContext, Bitmap bitmap) + public override IMemoryImage FromBitmap(Bitmap bitmap) { - return new MacImage(imageContext, bitmap.ToNS()); + return new MacImage(bitmap.ToNS()); } - public override IMemoryImage DrawHourglass(ImageContext imageContext, IMemoryImage image) + public override IMemoryImage DrawHourglass(IMemoryImage image) { // TODO return image; diff --git a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs index 8d79e9845..91d5e93c7 100644 --- a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs +++ b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs @@ -104,12 +104,12 @@ public class WinFormsEtoPlatform : EtoPlatform return bitmap.ToEto(); } - public override IMemoryImage FromBitmap(ImageContext imageContext, Bitmap bitmap) + public override IMemoryImage FromBitmap(Bitmap bitmap) { - return new GdiImage(imageContext, (SD.Bitmap) bitmap.ToSD()); + return new GdiImage((SD.Bitmap) bitmap.ToSD()); } - public override IMemoryImage DrawHourglass(ImageContext imageContext, IMemoryImage image) + public override IMemoryImage DrawHourglass(IMemoryImage image) { var bitmap = new System.Drawing.Bitmap(image.Width, image.Height); using (var g = SD.Graphics.FromImage(bitmap)) @@ -131,7 +131,7 @@ public class WinFormsEtoPlatform : EtoPlatform g.DrawImage(hourglass, new SD.Rectangle((bitmap.Width - 32) / 2, (bitmap.Height - 32) / 2, 32, 32)); } image.Dispose(); - return new GdiImage(imageContext, bitmap); + return new GdiImage(bitmap); } public override void SetFrame(Control container, Control control, Point location, Size size, bool inOverlay) diff --git a/NAPS2.Lib.WinForms/Modules/GdiModule.cs b/NAPS2.Lib.WinForms/Modules/GdiModule.cs index 93111bebe..7f89f56db 100644 --- a/NAPS2.Lib.WinForms/Modules/GdiModule.cs +++ b/NAPS2.Lib.WinForms/Modules/GdiModule.cs @@ -17,7 +17,7 @@ public class GdiModule : Module builder.RegisterBuildCallback(ctx => { var scanningContext = ctx.Resolve(); - scanningContext.LegacyTwainDriver = new LegacyTwainScanDriver(scanningContext); + scanningContext.LegacyTwainDriver = new LegacyTwainScanDriver(); }); } } \ No newline at end of file diff --git a/NAPS2.Lib.WinForms/Scan/Twain/Legacy/LegacyTwainScanDriver.cs b/NAPS2.Lib.WinForms/Scan/Twain/Legacy/LegacyTwainScanDriver.cs index 79510e508..d5c446825 100644 --- a/NAPS2.Lib.WinForms/Scan/Twain/Legacy/LegacyTwainScanDriver.cs +++ b/NAPS2.Lib.WinForms/Scan/Twain/Legacy/LegacyTwainScanDriver.cs @@ -5,13 +5,6 @@ namespace NAPS2.Scan.Twain.Legacy; internal class LegacyTwainScanDriver : IScanDriver { - private readonly ScanningContext _scanningContext; - - public LegacyTwainScanDriver(ScanningContext scanningContext) - { - _scanningContext = scanningContext; - } - public Task GetDevices(ScanOptions options, CancellationToken cancelToken, Action callback) { Check32Bit(); @@ -28,7 +21,7 @@ internal class LegacyTwainScanDriver : IScanDriver Action callback) { Check32Bit(); - return Task.Run(() => Invoker.Current.Invoke(() => TwainApi.Scan(_scanningContext, options, callback))); + return Task.Run(() => Invoker.Current.Invoke(() => TwainApi.Scan(options, callback))); } private static void Check32Bit() diff --git a/NAPS2.Lib.WinForms/Scan/Twain/Legacy/TwainApi.cs b/NAPS2.Lib.WinForms/Scan/Twain/Legacy/TwainApi.cs index e84c4613a..74b4ca54a 100644 --- a/NAPS2.Lib.WinForms/Scan/Twain/Legacy/TwainApi.cs +++ b/NAPS2.Lib.WinForms/Scan/Twain/Legacy/TwainApi.cs @@ -52,7 +52,7 @@ internal static class TwainApi return result; } - public static void Scan(ScanningContext scanningContext, ScanOptions options, Action produceImage) + public static void Scan(ScanOptions options, Action produceImage) { var tw = new Twain(); if (!tw.Init(options.DialogParent)) @@ -64,7 +64,7 @@ internal static class TwainApi throw new DeviceNotFoundException(); } var form = new FTwainGui(); - var mf = new TwainMessageFilter(scanningContext, options, tw, form); + var mf = new TwainMessageFilter(options, tw, form); form.ShowDialog(new Win32Window(options.DialogParent)); foreach (var b in mf.Bitmaps) { @@ -74,7 +74,6 @@ internal static class TwainApi private class TwainMessageFilter : IMessageFilter { - private readonly ScanningContext _scanningContext; private readonly ScanOptions _settings; private readonly Twain _tw; private readonly FTwainGui _form; @@ -82,9 +81,8 @@ internal static class TwainApi private bool _activated; private bool _msgfilter; - public TwainMessageFilter(ScanningContext scanningContext, ScanOptions settings, Twain tw, FTwainGui form) + public TwainMessageFilter(ScanOptions settings, Twain tw, FTwainGui form) { - _scanningContext = scanningContext; _settings = settings; _tw = tw; _form = form; @@ -129,7 +127,7 @@ internal static class TwainApi int bitcount = 0; Bitmap bmp = DibUtils.BitmapFromDib(img, out bitcount); - Bitmaps.Add(new GdiImage(_scanningContext.ImageContext, bmp)); + Bitmaps.Add(new GdiImage(bmp)); } _form.Close(); break; diff --git a/NAPS2.Lib/EtoForms/Desktop/DesktopController.cs b/NAPS2.Lib/EtoForms/Desktop/DesktopController.cs index e3b412a9a..b882eeea6 100644 --- a/NAPS2.Lib/EtoForms/Desktop/DesktopController.cs +++ b/NAPS2.Lib/EtoForms/Desktop/DesktopController.cs @@ -375,7 +375,7 @@ public class DesktopController var etoBitmap = (Bitmap) Clipboard.Instance.Image; Task.Run(() => { - var image = EtoPlatform.Current.FromBitmap(_scanningContext.ImageContext, etoBitmap); + var image = EtoPlatform.Current.FromBitmap(etoBitmap); var processedImage = _scanningContext.CreateProcessedImage(image); processedImage = ImportPostProcessor.AddPostProcessingData(processedImage, image, _thumbnailController.RenderSize, new BarcodeDetectionOptions(), true); diff --git a/NAPS2.Lib/EtoForms/EtoPlatform.cs b/NAPS2.Lib/EtoForms/EtoPlatform.cs index b232536a3..6f829a4be 100644 --- a/NAPS2.Lib/EtoForms/EtoPlatform.cs +++ b/NAPS2.Lib/EtoForms/EtoPlatform.cs @@ -23,8 +23,8 @@ public abstract class EtoPlatform public abstract IListView CreateListView(ListViewBehavior behavior) where T : notnull; public abstract void ConfigureImageButton(Button button, bool big); public abstract Bitmap ToBitmap(IMemoryImage image); - public abstract IMemoryImage FromBitmap(ImageContext imageContext, Bitmap bitmap); - public abstract IMemoryImage DrawHourglass(ImageContext imageContext, IMemoryImage thumb); + public abstract IMemoryImage FromBitmap(Bitmap bitmap); + public abstract IMemoryImage DrawHourglass(IMemoryImage thumb); public abstract void SetFrame(Control container, Control control, Point location, Size size, bool inOverlay); public abstract Control CreateContainer(); public abstract void AddToContainer(Control container, Control control, bool inOverlay); diff --git a/NAPS2.Lib/Images/UiThumbnailProvider.cs b/NAPS2.Lib/Images/UiThumbnailProvider.cs index 36e2bfba4..bd42a0b4e 100644 --- a/NAPS2.Lib/Images/UiThumbnailProvider.cs +++ b/NAPS2.Lib/Images/UiThumbnailProvider.cs @@ -28,7 +28,7 @@ public class UiThumbnailProvider } if (img.IsThumbnailDirty) { - thumb = EtoPlatform.Current.DrawHourglass(_imageContext, thumb); + thumb = EtoPlatform.Current.DrawHourglass(thumb); } return thumb; } @@ -38,7 +38,7 @@ public class UiThumbnailProvider { var placeholder = _imageContext.Create(thumbnailSize, thumbnailSize, ImagePixelFormat.RGB24); placeholder.Fill(_colorScheme.BackgroundColor); - placeholder = EtoPlatform.Current.DrawHourglass(_imageContext, placeholder); + placeholder = EtoPlatform.Current.DrawHourglass(placeholder); return placeholder; } } \ No newline at end of file diff --git a/NAPS2.Sdk.Tests/Images/GdiImageTests.cs b/NAPS2.Sdk.Tests/Images/GdiImageTests.cs index 352e05776..d928163b9 100644 --- a/NAPS2.Sdk.Tests/Images/GdiImageTests.cs +++ b/NAPS2.Sdk.Tests/Images/GdiImageTests.cs @@ -32,7 +32,7 @@ public class GdiImageTests { var bitmap = new Bitmap(new MemoryStream(ImageResources.dog_bw_invertpal)); - var image = new GdiImage(new GdiImageContext(), bitmap); + var image = new GdiImage(bitmap); Assert.True(image.FixedPixelFormat); Assert.Equal(ImagePixelFormat.BW1, image.PixelFormat); Assert.Equal(Color.Black.ToArgb(), image.Bitmap.Palette.Entries[0].ToArgb()); @@ -49,7 +49,7 @@ public class GdiImageTests p.Entries[128] = Color.Blue; bitmap.Palette = p; - var image = new GdiImage(new GdiImageContext(), bitmap); + var image = new GdiImage(bitmap); Assert.True(image.FixedPixelFormat); Assert.Equal(ImagePixelFormat.RGB24, image.PixelFormat); } @@ -59,7 +59,7 @@ public class GdiImageTests { var bitmap = new Bitmap(1, 1, PixelFormat.Format48bppRgb); - var image = new GdiImage(new GdiImageContext(), bitmap); + var image = new GdiImage(bitmap); Assert.True(image.FixedPixelFormat); Assert.Equal(ImagePixelFormat.RGB24, image.PixelFormat); } @@ -69,7 +69,7 @@ public class GdiImageTests { var bitmap = new Bitmap(1, 1, PixelFormat.Format64bppArgb); - var image = new GdiImage(new GdiImageContext(), bitmap); + var image = new GdiImage(bitmap); Assert.True(image.FixedPixelFormat); Assert.Equal(ImagePixelFormat.ARGB32, image.PixelFormat); } diff --git a/NAPS2.Sdk/Scan/Internal/Apple/DeviceOperator.cs b/NAPS2.Sdk/Scan/Internal/Apple/DeviceOperator.cs index 0edcb1702..53cde8568 100644 --- a/NAPS2.Sdk/Scan/Internal/Apple/DeviceOperator.cs +++ b/NAPS2.Sdk/Scan/Internal/Apple/DeviceOperator.cs @@ -215,7 +215,7 @@ internal class DeviceOperator : ICScannerDeviceDelegate nsImage.AddRepresentation(imageRep); // TODO: Could maybe do this without the NAPS2.Images.Mac reference but that would require duplicating // a bunch of logic to normalize image reps etc. - var macImage = new MacImage(_scanningContext.ImageContext, nsImage); + var macImage = new MacImage(nsImage); _logger.LogDebug("Setting resolution to {Dpi}", _resolution); macImage.SetResolution(_resolution, _resolution); if (_scanningContext.ImageContext is MacImageContext)