1
0
mirror of https://github.com/soukoku/ntwain.git synced 2025-04-05 20:59:23 +08:00

Added more wrapped caps.

This commit is contained in:
soukoku 2014-11-07 20:22:58 -05:00
parent 56115b619d
commit 88a54c95d9
10 changed files with 602 additions and 162 deletions

View File

@ -81,6 +81,9 @@
<Compile Include="..\NTwain\ICapControl.cs">
<Link>ICapControl.cs</Link>
</Compile>
<Compile Include="..\NTwain\ICapWrapper.cs">
<Link>ICapWrapper.cs</Link>
</Compile>
<Compile Include="..\NTwain\IDataSource.cs">
<Link>IDataSource.cs</Link>
</Compile>

View File

@ -13,7 +13,7 @@ namespace NTwain
/// Wrapped class for reading/writing a TWAIN capability associated with a <see cref="DataSource"/>.
/// </summary>
/// <typeparam name="TValue">The TWAIN type of the value.</typeparam>
public class CapWrapper<TValue>
public class CapWrapper<TValue> : NTwain.ICapWrapper<TValue>
{
/// <summary>
/// Routine that does nothing.
@ -340,15 +340,6 @@ namespace NTwain
#region set methods
/// <summary>
/// Resets all values and constraints to power-on defaults.
/// </summary>
/// <returns></returns>
public ReturnCode ResetAll()
{
return _source.CapResetAll(Capability);
}
/// <summary>
/// Resets the current value to power-on default.
/// </summary>

View File

@ -1792,6 +1792,7 @@ namespace NTwain.Data
ICapCustHalftone = 0x1104,
ICapExposureTime = 0x1105,
ICapFilter = 0x1106,
[Obsolete("Use ICapFlashUsed2 instead.")]
ICapFlashUsed = 0x1107,
ICapGamma = 0x1108,
ICapHalftones = 0x1109,

View File

@ -140,14 +140,10 @@ namespace NTwain
/// <summary>
/// Resets all values and constraint to power-on defaults.
/// </summary>
/// <param name="capabilityId">The capability identifier.</param>
/// <returns></returns>
public ReturnCode CapResetAll(CapabilityId capabilityId)
public ReturnCode CapResetAll()
{
using (TWCapability cap = new TWCapability(capabilityId)
{
ContainerType = ContainerType.DoNotCare
})
using (TWCapability cap = new TWCapability(CapabilityId.CapSupportedCaps))
{
var rc = DGControl.Capability.ResetAll(cap);
return rc;
@ -161,10 +157,7 @@ namespace NTwain
/// <returns></returns>
public ReturnCode CapReset(CapabilityId capabilityId)
{
using (TWCapability cap = new TWCapability(capabilityId)
{
ContainerType = ContainerType.DoNotCare
})
using (TWCapability cap = new TWCapability(capabilityId))
{
var rc = DGControl.Capability.Reset(cap);
return rc;
@ -185,7 +178,7 @@ namespace NTwain
/// <value>
/// The audio xfer mech.
/// </value>
public CapWrapper<XferMech> CapAudioXferMech
public ICapWrapper<XferMech> CapAudioXferMech
{
get
{
@ -202,6 +195,51 @@ namespace NTwain
#region img caps
#region mandatory
private CapWrapper<CompressionType> _compression;
/// <summary>
/// Gets the property to work with image <see cref="CompressionType"/> for the current source.
/// </summary>
/// <value>
/// The image compression.
/// </value>
public ICapWrapper<CompressionType> CapImageCompression
{
get
{
return _compression ?? (_compression = new CapWrapper<CompressionType>(this, CapabilityId.ICapCompression, ValueExtensions.ConvertToEnum<CompressionType>,
value => new TWCapability(CapabilityId.ICapCompression, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
})));
}
}
private CapWrapper<PixelType> _pixelType;
/// <summary>
/// Gets the property to work with image <see cref="PixelType"/> for the current source.
/// </summary>
/// <value>
/// The image pixel type.
/// </value>
public ICapWrapper<PixelType> CapImagePixelType
{
get
{
return _pixelType ?? (_pixelType = new CapWrapper<PixelType>(this, CapabilityId.ICapPixelType, ValueExtensions.ConvertToEnum<PixelType>,
value => new TWCapability(CapabilityId.ICapPixelType, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
})));
}
}
private CapWrapper<Unit> _imgUnits;
/// <summary>
@ -210,7 +248,7 @@ namespace NTwain
/// <value>
/// The image unit of measure.
/// </value>
public CapWrapper<Unit> CapImageUnits
public ICapWrapper<Unit> CapImageUnits
{
get
{
@ -231,7 +269,7 @@ namespace NTwain
/// <value>
/// The image xfer mech.
/// </value>
public CapWrapper<XferMech> CapImageXferMech
public ICapWrapper<XferMech> CapImageXferMech
{
get
{
@ -244,21 +282,110 @@ namespace NTwain
}
}
#endregion
private CapWrapper<CompressionType> _compression;
private CapWrapper<BoolType> _autoBright;
/// <summary>
/// Gets the property to work with image <see cref="CompressionType"/> for the current source.
/// Gets the property to work with image auto brightness flag for the current source.
/// </summary>
/// <value>
/// The image compression.
/// The image auto brightness flag.
/// </value>
public CapWrapper<CompressionType> CapImageCompression
public ICapWrapper<BoolType> CapImageAutoBright
{
get
{
return _compression ?? (_compression = new CapWrapper<CompressionType>(this, CapabilityId.ICapCompression, ValueExtensions.ConvertToEnum<CompressionType>,
value => new TWCapability(CapabilityId.ICapCompression, new TWOneValue
return _autoBright ?? (_autoBright = new CapWrapper<BoolType>(this, CapabilityId.ICapAutoBright, ValueExtensions.ConvertToEnum<BoolType>, value =>
new TWCapability(CapabilityId.ICapAutoBright, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Bool
})));
}
}
private CapWrapper<TWFix32> _brightness;
/// <summary>
/// Gets the property to work with image brightness for the current source.
/// </summary>
/// <value>
/// The image brightness.
/// </value>
public ICapWrapper<TWFix32> CapImageBrightness
{
get
{
return _brightness ?? (_brightness = new CapWrapper<TWFix32>(this, CapabilityId.ICapBrightness, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapBrightness, new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
})));
}
}
private CapWrapper<TWFix32> _contrast;
/// <summary>
/// Gets the property to work with image contrast for the current source.
/// </summary>
/// <value>
/// The image contrast.
/// </value>
public ICapWrapper<TWFix32> CapImageContrast
{
get
{
return _contrast ?? (_contrast = new CapWrapper<TWFix32>(this, CapabilityId.ICapContrast, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapContrast, new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
})));
}
}
// TODO: add ICapCustHalftone
private CapWrapper<TWFix32> _exposureTime;
/// <summary>
/// Gets the property to work with image exposure time (in seconds) for the current source.
/// </summary>
/// <value>
/// The image exposure time.
/// </value>
public ICapWrapper<TWFix32> CapImageExposureTime
{
get
{
return _exposureTime ?? (_exposureTime = new CapWrapper<TWFix32>(this, CapabilityId.ICapExposureTime, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapExposureTime, new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
})));
}
}
private CapWrapper<ImageFilter> _imgFilter;
/// <summary>
/// Gets the property to work with image <see cref="FilterType"/> for the current source.
/// </summary>
/// <value>
/// The image filter type.
/// </value>
public ICapWrapper<ImageFilter> CapImageFilter
{
get
{
return _imgFilter ?? (_imgFilter = new CapWrapper<ImageFilter>(this, CapabilityId.ICapFilter, ValueExtensions.ConvertToEnum<ImageFilter>,
value => new TWCapability(CapabilityId.ICapFilter, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
@ -266,6 +393,50 @@ namespace NTwain
}
}
private CapWrapper<TWFix32> _gamma;
/// <summary>
/// Gets the property to work with image gamma value for the current source.
/// </summary>
/// <value>
/// The image gamma.
/// </value>
public ICapWrapper<TWFix32> CapImageGamma
{
get
{
return _gamma ?? (_gamma = new CapWrapper<TWFix32>(this, CapabilityId.ICapGamma, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapGamma, new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
})));
}
}
// TODO: add ICapHalftones
private CapWrapper<TWFix32> _highlight;
/// <summary>
/// Gets the property to work with image highlight value for the current source.
/// </summary>
/// <value>
/// The image highlight.
/// </value>
public ICapWrapper<TWFix32> CapImageHighlight
{
get
{
return _highlight ?? (_highlight = new CapWrapper<TWFix32>(this, CapabilityId.ICapHighlight, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapHighlight, new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
})));
}
}
private CapWrapper<FileFormat> _fileFormat;
@ -275,7 +446,7 @@ namespace NTwain
/// <value>
/// The image file format.
/// </value>
public CapWrapper<FileFormat> CapImageFileFormat
public ICapWrapper<FileFormat> CapImageFileFormat
{
get
{
@ -289,20 +460,42 @@ namespace NTwain
}
private CapWrapper<PixelType> _pixelType;
private CapWrapper<BoolType> _lampState;
/// <summary>
/// Gets the property to work with image <see cref="PixelType"/> for the current source.
/// Gets the property to work with image lamp state flag for the current source.
/// </summary>
/// <value>
/// The image pixel type.
/// The image lamp state flag.
/// </value>
public CapWrapper<PixelType> CapImagePixelType
public ICapWrapper<BoolType> CapImageLameState
{
get
{
return _pixelType ?? (_pixelType = new CapWrapper<PixelType>(this, CapabilityId.ICapPixelType, ValueExtensions.ConvertToEnum<PixelType>,
value => new TWCapability(CapabilityId.ICapPixelType, new TWOneValue
return _lampState ?? (_lampState = new CapWrapper<BoolType>(this, CapabilityId.ICapLampState, ValueExtensions.ConvertToEnum<BoolType>, value =>
new TWCapability(CapabilityId.ICapLampState, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Bool
})));
}
}
private CapWrapper<LightSource> _lightSource;
/// <summary>
/// Gets the property to work with image light source for the current source.
/// </summary>
/// <value>
/// The image light source.
/// </value>
public ICapWrapper<LightSource> CapImageLightSource
{
get
{
return _lightSource ?? (_lightSource = new CapWrapper<LightSource>(this, CapabilityId.ICapLightSource, ValueExtensions.ConvertToEnum<LightSource>, value =>
new TWCapability(CapabilityId.ICapLightSource, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
@ -311,6 +504,158 @@ namespace NTwain
}
private CapWrapper<OrientationType> _orientation;
/// <summary>
/// Gets the property to work with image orientation for the current source.
/// </summary>
/// <value>
/// The image orientation.
/// </value>
public ICapWrapper<OrientationType> CapImageOrientation
{
get
{
return _orientation ?? (_orientation = new CapWrapper<OrientationType>(this, CapabilityId.ICapOrientation, ValueExtensions.ConvertToEnum<OrientationType>, value =>
new TWCapability(CapabilityId.ICapOrientation, new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
})));
}
}
private CapWrapper<TWFix32> _physicalWidth;
/// <summary>
/// Gets the property to work with image physical width for the current source.
/// </summary>
/// <value>
/// The image physical width.
/// </value>
public IReadOnlyCapWrapper<TWFix32> CapImagePhysicalWidth
{
get
{
return _physicalWidth ?? (_physicalWidth = new CapWrapper<TWFix32>(this, CapabilityId.ICapPhysicalWidth, ValueExtensions.ConvertToFix32));
}
}
private CapWrapper<TWFix32> _physicalHeight;
/// <summary>
/// Gets the property to work with image physical height for the current source.
/// </summary>
/// <value>
/// The image physical height.
/// </value>
public IReadOnlyCapWrapper<TWFix32> CapImagePhysicalHeight
{
get
{
return _physicalHeight ?? (_physicalHeight = new CapWrapper<TWFix32>(this, CapabilityId.ICapPhysicalHeight, ValueExtensions.ConvertToFix32));
}
}
private CapWrapper<TWFix32> _shadow;
/// <summary>
/// Gets the property to work with image shadow value for the current source.
/// </summary>
/// <value>
/// The image shadow.
/// </value>
public ICapWrapper<TWFix32> CapImageShadow
{
get
{
return _shadow ?? (_shadow = new CapWrapper<TWFix32>(this, CapabilityId.ICapShadow, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapShadow, new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
})));
}
}
// TODO: add ICapFrames
private CapWrapper<TWFix32> _nativeXRes;
/// <summary>
/// Gets the property to work with image's native x-axis resolution for the current source.
/// </summary>
/// <value>
/// The image's native x-axis resolution.
/// </value>
public IReadOnlyCapWrapper<TWFix32> CapImageXNativeResolution
{
get
{
return _nativeXRes ?? (_nativeXRes = new CapWrapper<TWFix32>(this, CapabilityId.ICapXNativeResolution, ValueExtensions.ConvertToFix32));
}
}
private CapWrapper<TWFix32> _nativeYRes;
/// <summary>
/// Gets the property to work with image's native y-axis resolution for the current source.
/// </summary>
/// <value>
/// The image's native y-axis resolution.
/// </value>
public IReadOnlyCapWrapper<TWFix32> CapImageYNativeResolution
{
get
{
return _nativeYRes ?? (_nativeYRes = new CapWrapper<TWFix32>(this, CapabilityId.ICapYNativeResolution, ValueExtensions.ConvertToFix32));
}
}
private CapWrapper<TWFix32> _xResolution;
/// <summary>
/// Gets the property to work with image x-axis resolution for the current source.
/// </summary>
/// <value>
/// The image x-axis resolution.
/// </value>
public ICapWrapper<TWFix32> CapImageXResolution
{
get
{
return _xResolution ?? (_xResolution = new CapWrapper<TWFix32>(this, CapabilityId.ICapXResolution, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapXResolution, new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
})));
}
}
private CapWrapper<TWFix32> _yResolution;
/// <summary>
/// Gets the property to work with image y-axis resolution for the current source.
/// </summary>
/// <value>
/// The image y-axis resolution.
/// </value>
public ICapWrapper<TWFix32> CapImageYResolution
{
get
{
return _yResolution ?? (_yResolution = new CapWrapper<TWFix32>(this, CapabilityId.ICapYResolution, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapYResolution, new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
})));
}
}
private CapWrapper<SupportedSize> _supportSize;
/// <summary>
@ -319,7 +664,7 @@ namespace NTwain
/// <value>
/// The image supported size.
/// </value>
public CapWrapper<SupportedSize> CapImageSupportedSize
public ICapWrapper<SupportedSize> CapImageSupportedSize
{
get
{
@ -341,7 +686,7 @@ namespace NTwain
/// <value>
/// The image auto deskew flag.
/// </value>
public CapWrapper<BoolType> CapImageAutoDeskew
public ICapWrapper<BoolType> CapImageAutoDeskew
{
get
{
@ -363,7 +708,7 @@ namespace NTwain
/// <value>
/// The image auto rotate flag.
/// </value>
public CapWrapper<BoolType> CapImageAutoRotate
public ICapWrapper<BoolType> CapImageAutoRotate
{
get
{
@ -377,50 +722,6 @@ namespace NTwain
}
private CapWrapper<TWFix32> _xResolution;
/// <summary>
/// Gets the property to work with image horizontal resolution for the current source.
/// </summary>
/// <value>
/// The image horizontal resolution.
/// </value>
public CapWrapper<TWFix32> CapImageXResolution
{
get
{
return _xResolution ?? (_xResolution = new CapWrapper<TWFix32>(this, CapabilityId.ICapXResolution, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapXResolution, new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
})));
}
}
private CapWrapper<TWFix32> _yResolution;
/// <summary>
/// Gets the property to work with image vertical resolution for the current source.
/// </summary>
/// <value>
/// The image vertical resolution.
/// </value>
public CapWrapper<TWFix32> CapImageYResolution
{
get
{
return _yResolution ?? (_yResolution = new CapWrapper<TWFix32>(this, CapabilityId.ICapYResolution, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapYResolution, new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
})));
}
}
private CapWrapper<BoolType> _borderDetect;
/// <summary>
@ -429,7 +730,7 @@ namespace NTwain
/// <value>
/// The auto border detection flag.
/// </value>
public CapWrapper<BoolType> CapImageAutomaticBorderDetection
public ICapWrapper<BoolType> CapImageAutomaticBorderDetection
{
get
{
@ -459,7 +760,33 @@ namespace NTwain
#endregion
#region other caps
#region general caps
#region mandatory
private CapWrapper<int> _xferCount;
/// <summary>
/// Gets the property to work with xfer count for the current source.
/// </summary>
/// <value>
/// The xfer count.
/// </value>
public ICapWrapper<int> CapXferCount
{
get
{
return _xferCount ?? (_xferCount = new CapWrapper<int>(this, CapabilityId.CapXferCount, ValueExtensions.ConvertToEnum<int>, value =>
new TWCapability(CapabilityId.CapXferCount, new TWOneValue
{
Item = value > 0 ? (uint)value : uint.MaxValue,
ItemType = ItemType.UInt16
})));
}
}
#endregion
private CapWrapper<Duplex> _duplex;
@ -469,7 +796,7 @@ namespace NTwain
/// <value>
/// The duplex mode.
/// </value>
public CapWrapper<Duplex> CapDuplex
public IReadOnlyCapWrapper<Duplex> CapDuplex
{
get
{
@ -485,7 +812,7 @@ namespace NTwain
/// <value>
/// The duplex enabled flag.
/// </value>
public CapWrapper<BoolType> CapDuplexEnabled
public ICapWrapper<BoolType> CapDuplexEnabled
{
get
{
@ -498,28 +825,6 @@ namespace NTwain
}
}
private CapWrapper<int> _xferCount;
/// <summary>
/// Gets the property to work with xfer count for the current source.
/// </summary>
/// <value>
/// The xfer count.
/// </value>
public CapWrapper<int> CapXferCount
{
get
{
return _xferCount ?? (_xferCount = new CapWrapper<int>(this, CapabilityId.CapXferCount, ValueExtensions.ConvertToEnum<int>, value =>
new TWCapability(CapabilityId.CapXferCount, new TWOneValue
{
Item = value > 0 ? (uint)value : uint.MaxValue,
ItemType = ItemType.UInt16
})));
}
}
private CapWrapper<BoolType> _feederLoaded;
/// <summary>
@ -528,7 +833,7 @@ namespace NTwain
/// <value>
/// The feeder loaded flag.
/// </value>
public CapWrapper<BoolType> CapFeederLoaded
public IReadOnlyCapWrapper<BoolType> CapFeederLoaded
{
get
{
@ -544,7 +849,7 @@ namespace NTwain
/// <value>
/// The feeder enabled flag.
/// </value>
public CapWrapper<BoolType> CapFeederEnabled
public ICapWrapper<BoolType> CapFeederEnabled
{
get
{
@ -597,7 +902,7 @@ namespace NTwain
/// <value>
/// The clear page flag.
/// </value>
public CapWrapper<BoolType> CapClearPage
public ICapWrapper<BoolType> CapClearPage
{
get
{
@ -618,7 +923,7 @@ namespace NTwain
/// <value>
/// The feed page flag.
/// </value>
public CapWrapper<BoolType> CapFeedPage
public ICapWrapper<BoolType> CapFeedPage
{
get
{
@ -639,7 +944,7 @@ namespace NTwain
/// <value>
/// The rewind page flag.
/// </value>
public CapWrapper<BoolType> CapRewindPage
public ICapWrapper<BoolType> CapRewindPage
{
get
{
@ -660,7 +965,7 @@ namespace NTwain
/// <value>
/// The indicators flag.
/// </value>
public CapWrapper<BoolType> CapIndicators
public ICapWrapper<BoolType> CapIndicators
{
get
{
@ -681,7 +986,7 @@ namespace NTwain
/// <value>
/// The paper sensor flag.
/// </value>
public CapWrapper<BoolType> CapPaperDetectable
public IReadOnlyCapWrapper<BoolType> CapPaperDetectable
{
get
{
@ -697,7 +1002,7 @@ namespace NTwain
/// <value>
/// The UI controllable flag.
/// </value>
public CapWrapper<BoolType> CapUIControllable
public IReadOnlyCapWrapper<BoolType> CapUIControllable
{
get
{
@ -713,7 +1018,7 @@ namespace NTwain
/// <value>
/// The devince online flag.
/// </value>
public CapWrapper<BoolType> CapDeviceOnline
public IReadOnlyCapWrapper<BoolType> CapDeviceOnline
{
get
{
@ -729,7 +1034,7 @@ namespace NTwain
/// <value>
/// The thumbnails enabled flag.
/// </value>
public CapWrapper<BoolType> CapThumbnailsEnabled
public ICapWrapper<BoolType> CapThumbnailsEnabled
{
get
{
@ -750,7 +1055,7 @@ namespace NTwain
/// <value>
/// The UI only flag.
/// </value>
public CapWrapper<BoolType> CapEnableDSUIOnly
public IReadOnlyCapWrapper<BoolType> CapEnableDSUIOnly
{
get
{
@ -766,7 +1071,7 @@ namespace NTwain
/// <value>
/// The custom data flag.
/// </value>
public CapWrapper<BoolType> CapCustomDSData
public IReadOnlyCapWrapper<BoolType> CapCustomDSData
{
get
{
@ -782,7 +1087,7 @@ namespace NTwain
/// <value>
/// The job control option.
/// </value>
public CapWrapper<JobControl> CapJobControl
public ICapWrapper<JobControl> CapJobControl
{
get
{
@ -803,7 +1108,7 @@ namespace NTwain
/// <value>
/// The alarm volume.
/// </value>
public CapWrapper<int> CapAlarmVolume
public ICapWrapper<int> CapAlarmVolume
{
get
{
@ -824,7 +1129,7 @@ namespace NTwain
///// <value>
///// The auto capture count.
///// </value>
//public CapWrapper<int> CapAutomaticCapture
//public ICapWrapper<int> CapAutomaticCapture
//{
// get
// {

View File

@ -47,24 +47,8 @@ namespace NTwain
/// <summary>
/// Resets all values and constraints to power-on defaults.
/// </summary>
/// <param name="capabilityId">The capability identifier.</param>
/// <returns></returns>
ReturnCode CapResetAll(CapabilityId capabilityId);
ReturnCode CapResetAll();
//CapabilityControl<XferMech> CapAudioXferMech { get; }
//CapabilityControl<BoolType> CapDuplexEnabled { get; }
//CapabilityControl<BoolType> CapFeederEnabled { get; }
//CapabilityControl<BoolType> CapImageAutoDeskew { get; }
//CapabilityControl<BoolType> CapImageAutomaticBorderDetection { get; }
//CapabilityControl<BoolType> CapImageAutoRotate { get; }
//CapabilityControl<CompressionType> CapImageCompression { get; }
//CapabilityControl<FileFormat> CapImageFileFormat { get; }
//CapabilityControl<PixelType> CapImagePixelType { get; }
//CapabilityControl<SupportedSize> CapImageSupportedSize { get; }
//CapabilityControl<XferMech> CapImageXferMech { get; }
//CapabilityControl<TWFix32> CapImageXResolution { get; }
//CapabilityControl<TWFix32> CapImageYResolution { get; }
//CapabilityControl<int> CapXferCount { get; }
}
}

155
NTwain/ICapWrapper.cs Normal file
View File

@ -0,0 +1,155 @@
using System;
namespace NTwain
{
/// <summary>
/// Interface for reading a TWAIN capability associated with a <see cref="DataSource"/>.
/// </summary>
/// <typeparam name="TValue">The TWAIN type of the value.</typeparam>
public interface IReadOnlyCapWrapper<TValue>
{
/// <summary>
/// Gets a value indicating whether <see cref="Get"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can get values; otherwise, <c>false</c>.
/// </value>
bool CanGet { get; }
/// <summary>
/// Gets a value indicating whether <see cref="GetDefault"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can get default value; otherwise, <c>false</c>.
/// </value>
bool CanGetCurrent { get; }
/// <summary>
/// Gets a value indicating whether <see cref="GetCurrent"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can get current value; otherwise, <c>false</c>.
/// </value>
bool CanGetDefault { get; }
/// <summary>
/// Gets a value indicating whether <see cref="GetHelp"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can get help; otherwise, <c>false</c>.
/// </value>
bool CanGetHelp { get; }
/// <summary>
/// Gets a value indicating whether <see cref="GetLabel"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can get label; otherwise, <c>false</c>.
/// </value>
bool CanGetLabel { get; }
/// <summary>
/// Gets a value indicating whether <see cref="GetLabelEnum"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can get label enum; otherwise, <c>false</c>.
/// </value>
bool CanGetLabelEnum { get; }
/// <summary>
/// Gets the capability.
/// </summary>
/// <value>
/// The capability.
/// </value>
NTwain.Data.CapabilityId Capability { get; }
/// <summary>
/// Gets all the possible values of this capability.
/// </summary>
/// <returns></returns>
System.Collections.Generic.IList<TValue> Get();
/// <summary>
/// Gets the current value of this capability.
/// </summary>
/// <returns></returns>
TValue GetCurrent();
/// <summary>
/// Gets the default value of this capability.
/// </summary>
/// <returns></returns>
TValue GetDefault();
/// <summary>
/// [Experimental] Gets the help value of this capability.
/// </summary>
/// <returns></returns>
string GetHelp();
/// <summary>
/// [Experimental] Gets the label value of this capability.
/// </summary>
/// <returns></returns>
string GetLabel();
/// <summary>
/// [Experimental] Gets the display names for possible values of this capability.
/// </summary>
/// <returns></returns>
System.Collections.Generic.IList<string> GetLabelEnum();
/// <summary>
/// Gets a value indicating whether this capability is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability is supported; otherwise, <c>false</c>.
/// </value>
bool IsSupported { get; }
/// <summary>
/// Gets the supported actions.
/// </summary>
/// <value>
/// The supported actions.
/// </value>
NTwain.Data.QuerySupports SupportedActions { get; }
}
/// <summary>
/// Interface for reading/writing a TWAIN capability associated with a <see cref="DataSource"/>.
/// </summary>
/// <typeparam name="TValue">The TWAIN type of the value.</typeparam>
public interface ICapWrapper<TValue> : IReadOnlyCapWrapper<TValue>
{
/// <summary>
/// Gets a value indicating whether <see cref="Reset"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can reset; otherwise, <c>false</c>.
/// </value>
bool CanReset { get; }
/// <summary>
/// Gets a value indicating whether <see cref="Set"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can set; otherwise, <c>false</c>.
/// </value>
bool CanSet { get; }
/// <summary>
/// Resets the current value to power-on default.
/// </summary>
/// <returns></returns>
NTwain.Data.ReturnCode Reset();
/// <summary>
/// Sets the current value of this capability.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
NTwain.Data.ReturnCode Set(TValue value);
}
}

View File

@ -78,6 +78,7 @@
<Compile Include="Internals\WinMemoryManager.cs" />
<Compile Include="Internals\UnsafeNativeMethods.cs" />
<Compile Include="Internals\IWinMessageFilter.cs" />
<Compile Include="ICapWrapper.cs" />
<Compile Include="MessageLoopHooks.cs" />
<Compile Include="PlatformInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">

View File

@ -23,7 +23,7 @@ namespace NTwain
/// <summary>
/// The build release version number.
/// </summary>
public const string Build = "3.1.0"; // change this for each nuget release
public const string Build = "3.1.1"; // change this for each nuget release
}

View File

@ -357,7 +357,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
break;
case CapabilityId.ICapAutoBright:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageAutoBright.Get();
break;
case CapabilityId.ICapAutoDiscardBlankPages:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
@ -417,7 +417,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
break;
case CapabilityId.ICapBrightness:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageBrightness.Get();
break;
case CapabilityId.ICapCCITTKFactor:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
@ -429,13 +429,13 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageCompression.Get();
break;
case CapabilityId.ICapContrast:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageContrast.Get();
break;
case CapabilityId.ICapCustHalftone:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
break;
case CapabilityId.ICapExposureTime:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageExposureTime.Get();
break;
case CapabilityId.ICapExtImageInfo:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
@ -453,7 +453,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
break;
case CapabilityId.ICapFlashUsed2:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<FlashedUsed>();
break;
case CapabilityId.ICapFlipRotation:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<FlipRotation>();
@ -462,13 +462,13 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
break;
case CapabilityId.ICapGamma:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageGamma.Get();
break;
case CapabilityId.ICapHalftones:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
break;
case CapabilityId.ICapHighlight:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageHighlight.Get();
break;
case CapabilityId.ICapICCProfile:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<IccProfile>();
@ -480,7 +480,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageFileFormat.Get();
break;
case CapabilityId.ICapImageFilter:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<ImageFilter>();
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageFilter.Get();
break;
case CapabilityId.ICapImageMerge:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<ImageMerge>();
@ -498,13 +498,13 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<JpegSubsampling>();
break;
case CapabilityId.ICapLampState:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageLameState.Get();
break;
case CapabilityId.ICapLightPath:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<LightPath>();
break;
case CapabilityId.ICapLightSource:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<LightSource>();
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageLightSource.Get();
break;
case CapabilityId.ICapMaxFrames:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
@ -522,7 +522,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<NoiseFilter>();
break;
case CapabilityId.ICapOrientation:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<OrientationType>();
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageOrientation.Get();
break;
case CapabilityId.ICapOverScan:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<OverScan>();
@ -547,10 +547,10 @@ namespace Tester.WPF
break;
// TODO phys size are twfix32
case CapabilityId.ICapPhysicalHeight:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImagePhysicalHeight.Get();
break;
case CapabilityId.ICapPhysicalWidth:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImagePhysicalWidth.Get();
break;
case CapabilityId.ICapPixelFlavor:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<PixelFlavor>();
@ -568,7 +568,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<Rotation>();
break;
case CapabilityId.ICapShadow:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageShadow.Get();
break;
case CapabilityId.ICapSupportedBarcodeTypes:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<BarcodeType>();
@ -601,7 +601,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageXferMech.Get();
break;
case CapabilityId.ICapXNativeResolution:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageXNativeResolution.Get();
break;
case CapabilityId.ICapXResolution:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageXResolution.Get();
@ -610,7 +610,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
break;
case CapabilityId.ICapYNativeResolution:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageYNativeResolution.Get();
break;
case CapabilityId.ICapYResolution:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageYResolution.Get();

View File

@ -307,7 +307,7 @@ namespace Tester.Winform
_loadingCaps = false;
}
private void LoadPaperSize(CapWrapper<SupportedSize> cap)
private void LoadPaperSize(ICapWrapper<SupportedSize> cap)
{
var list = cap.Get();
comboSize.DataSource = list;
@ -324,13 +324,13 @@ namespace Tester.Winform
}
private void LoadDuplex(CapWrapper<BoolType> cap)
private void LoadDuplex(ICapWrapper<BoolType> cap)
{
ckDuplex.Checked = cap.GetCurrent() == BoolType.True;
}
private void LoadDPI(CapWrapper<TWFix32> cap)
private void LoadDPI(ICapWrapper<TWFix32> cap)
{
// only allow dpi of certain values for those source that lists everything
var list = cap.Get().Where(dpi => (dpi % 50) == 0).ToList();
@ -342,7 +342,7 @@ namespace Tester.Winform
}
}
private void LoadDepth(CapWrapper<PixelType> cap)
private void LoadDepth(ICapWrapper<PixelType> cap)
{
var list = cap.Get();
comboDepth.DataSource = list;