ScanProfile -> ScanOptions property mappings

This commit is contained in:
Ben Olden-Cooligan 2019-07-13 21:50:53 -04:00
parent 79c2f24f71
commit 6e2148f9f4
4 changed files with 91 additions and 6 deletions

View File

@ -24,7 +24,7 @@ namespace NAPS2.Scan.Experimental.Internal
public IScanBridge Create(ScanOptions options)
{
if (!string.IsNullOrEmpty(options.NetworkOptions?.Ip))
if (!string.IsNullOrEmpty(options.NetworkOptions?.Ip) && options.NetworkOptions?.Port != null)
{
// The physical scanner is connected to a different computer, so we connect to a NAPS2 server process over the network
return networkScanBridge;

View File

@ -8,6 +8,6 @@ namespace NAPS2.Scan.Experimental
{
public string Ip { get; set; }
public int Port { get; set; }
public int? Port { get; set; }
}
}

View File

@ -89,16 +89,71 @@ namespace NAPS2.Scan.Experimental
{
var options = new ScanOptions
{
// TODO: Lots more
Driver = scanProfile.DriverName == "wia" ? Driver.Wia
: scanProfile.DriverName == "sane" ? Driver.Sane
: Driver.Twain,
: scanProfile.DriverName == "twain" ? Driver.Twain
: Driver.Default,
WiaOptions =
{
WiaVersion = scanProfile.WiaVersion
}
WiaVersion = scanProfile.WiaVersion,
OffsetWidth = scanProfile.WiaOffsetWidth
},
TwainOptions =
{
Adapter = scanProfile.TwainImpl == TwainImpl.Legacy ? TwainAdapter.Legacy : TwainAdapter.NTwain,
Dsm = scanProfile.TwainImpl == TwainImpl.X64 ? TwainDsm.NewX64
: scanProfile.TwainImpl == TwainImpl.OldDsm || scanProfile.TwainImpl == TwainImpl.Legacy ? TwainDsm.Old
: TwainDsm.New,
TransferMode = scanProfile.TwainImpl == TwainImpl.MemXfer ? TwainTransferMode.Memory : TwainTransferMode.Native,
IncludeWiaDevices = false
},
SaneOptions =
{
KeyValueOptions = new KeyValueScanOptions(scanProfile.KeyValueOptions)
},
NetworkOptions =
{
Ip = scanProfile.ProxyConfig.Ip,
Port = scanProfile.ProxyConfig.Port
},
Brightness = scanProfile.Brightness,
Contrast = scanProfile.Contrast,
Dpi = scanProfile.Resolution.ToIntDpi(),
Modal = scanParams.Modal,
Quality = scanProfile.Quality,
AutoDeskew = scanProfile.AutoDeskew,
BitDepth = scanProfile.BitDepth.ToBitDepth(),
DialogParent = dialogParent,
DoOcr = scanParams.DoOcr,
MaxQuality = scanProfile.MaxQuality,
OcrParams = scanParams.OcrParams,
PageAlign = scanProfile.PageAlign.ToHorizontalAlign(),
PaperSource = scanProfile.PaperSource.ToPaperSource(),
ScaleRatio = scanProfile.AfterScanScale.ToIntScaleFactor(),
ThumbnailSize = scanParams.ThumbnailSize,
DetectPatchCodes = scanParams.DetectPatchCodes,
ExcludeBlankPages = scanProfile.ExcludeBlankPages,
FlipDuplexedPages = scanProfile.FlipDuplexedPages,
NoUI = scanParams.NoUI,
OcrCancelToken = scanParams.OcrCancelToken,
OcrInBackground = true, // TODO
BlankPageCoverageThreshold = scanProfile.BlankPageCoverageThreshold,
BlankPageWhiteThreshold = scanProfile.BlankPageWhiteThreshold,
BrightnessContrastAfterScan = scanProfile.BrightnessContrastAfterScan,
CropToPageSize = scanProfile.ForcePageSizeCrop,
StretchToPageSize = scanProfile.ForcePageSize,
UseNativeUI = scanProfile.UseNativeUI,
Device = null, // Set after
PageSize = null, // Set after
};
PageDimensions pageDimensions = scanProfile.PageSize.PageDimensions() ?? scanProfile.CustomPageSize;
if (pageDimensions == null)
{
throw new ArgumentException("No page size specified");
}
options.PageSize = new PageSize(pageDimensions.Width, pageDimensions.Height, pageDimensions.Unit);
// If a device wasn't specified, prompt the user to pick one
if (string.IsNullOrEmpty(scanProfile.Device?.ID))
{

View File

@ -518,5 +518,35 @@ namespace NAPS2.Scan
throw new ArgumentException();
}
}
public static HorizontalAlign ToHorizontalAlign(this ScanHorizontalAlign horizontalAlign)
{
switch (horizontalAlign)
{
case ScanHorizontalAlign.Left:
return HorizontalAlign.Left;
case ScanHorizontalAlign.Right:
return HorizontalAlign.Right;
case ScanHorizontalAlign.Center:
return HorizontalAlign.Center;
default:
throw new ArgumentException();
}
}
public static PaperSource ToPaperSource(this ScanSource scanSource)
{
switch (scanSource)
{
case ScanSource.Glass:
return PaperSource.Flatbed;
case ScanSource.Feeder:
return PaperSource.Feeder;
case ScanSource.Duplex:
return PaperSource.Duplex;
default:
throw new ArgumentException();
}
}
}
}