Add PatchCode property to IScannedImage and TWAIN impl

This commit is contained in:
Ben Olden-Cooligan 2015-08-17 19:01:47 -04:00
parent 9b76dbd407
commit 0250277120
7 changed files with 69 additions and 1 deletions

View File

@ -82,6 +82,7 @@
<DependentUpon>Icons.resx</DependentUpon>
</Compile>
<Compile Include="ImportExport\Pdf\PdfSaver.cs" />
<Compile Include="Scan\PatchCode.cs" />
<Compile Include="Util\ChangeTracker.cs" />
<Compile Include="Util\CollectionExtensions.cs" />
<Compile Include="Config\AppConfig.cs" />

View File

@ -62,6 +62,8 @@ namespace NAPS2.Scan
public ScanDpi Resolution { get; set; }
public ScanSource PaperSource { get; set; }
public bool DetectPatchCodes { get; set; }
}
public enum ScanSource

View File

@ -214,5 +214,7 @@ namespace NAPS2.Scan.Images
_recoveryIndexManager.Index.Images.Insert(index, indexImage);
_recoveryIndexManager.Save();
}
public PatchCode PatchCode { get; set; }
}
}

View File

@ -77,5 +77,10 @@ namespace NAPS2.Scan.Images
/// </summary>
/// <param name="index">The index at which the image was inserted after being removed.</param>
void MovedTo(int index);
/// <summary>
/// Gets or sets the patch code associated with the scanned page.
/// </summary>
PatchCode PatchCode { get; set; }
}
}

View File

@ -126,5 +126,7 @@ namespace NAPS2.Scan.Images
{
// Do nothing, this is only important for FileBasedScannedImage
}
public PatchCode PatchCode { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NAPS2.Scan
{
public enum PatchCode
{
None,
Patch1,
Patch2,
Patch3,
Patch4,
Patch6,
PatchT
}
}

View File

@ -108,7 +108,18 @@ namespace NAPS2.Scan.Twain
var bitDepth = output.PixelFormat == PixelFormat.Format1bppIndexed
? ScanBitDepth.BlackWhite
: ScanBitDepth.C24Bit;
images.Add(scannedImageFactory.Create(result, bitDepth, ScanSettings.MaxQuality));
var img = scannedImageFactory.Create(result, bitDepth, ScanSettings.MaxQuality);
if (ScanSettings.DetectPatchCodes)
{
foreach (var patchCodeInfo in eventArgs.GetExtImageInfo(ExtendedImageInfo.PatchCode))
{
if (patchCodeInfo.ReturnCode == ReturnCode.Success)
{
img.PatchCode = GetPatchCode(patchCodeInfo);
}
}
}
images.Add(img);
}
}
};
@ -179,6 +190,27 @@ namespace NAPS2.Scan.Twain
return images;
}
private static PatchCode GetPatchCode(TWInfo patchCodeInfo)
{
switch ((NTwain.Data.PatchCode)patchCodeInfo.Item)
{
case NTwain.Data.PatchCode.Patch1:
return PatchCode.Patch1;
case NTwain.Data.PatchCode.Patch2:
return PatchCode.Patch2;
case NTwain.Data.PatchCode.Patch3:
return PatchCode.Patch3;
case NTwain.Data.PatchCode.Patch4:
return PatchCode.Patch4;
case NTwain.Data.PatchCode.Patch6:
return PatchCode.Patch6;
case NTwain.Data.PatchCode.PatchT:
return PatchCode.PatchT;
default:
throw new ArgumentException();
}
}
private void ConfigureDS(DataSource ds)
{
if (ScanSettings.UseNativeUI)
@ -255,6 +287,12 @@ namespace NAPS2.Scan.Twain
int dpi = ScanSettings.Resolution.ToIntDpi();
ds.Capabilities.ICapXResolution.SetValue(dpi);
ds.Capabilities.ICapYResolution.SetValue(dpi);
// Patch codes
if (ScanSettings.DetectPatchCodes)
{
ds.Capabilities.ICapPatchCodeDetectionEnabled.SetValue(BoolType.True);
}
}
}
}