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"> <Compile Include="..\NTwain\ICapControl.cs">
<Link>ICapControl.cs</Link> <Link>ICapControl.cs</Link>
</Compile> </Compile>
<Compile Include="..\NTwain\ICapWrapper.cs">
<Link>ICapWrapper.cs</Link>
</Compile>
<Compile Include="..\NTwain\IDataSource.cs"> <Compile Include="..\NTwain\IDataSource.cs">
<Link>IDataSource.cs</Link> <Link>IDataSource.cs</Link>
</Compile> </Compile>

View File

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

View File

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

View File

@@ -140,14 +140,10 @@ namespace NTwain
/// <summary> /// <summary>
/// Resets all values and constraint to power-on defaults. /// Resets all values and constraint to power-on defaults.
/// </summary> /// </summary>
/// <param name="capabilityId">The capability identifier.</param>
/// <returns></returns> /// <returns></returns>
public ReturnCode CapResetAll(CapabilityId capabilityId) public ReturnCode CapResetAll()
{ {
using (TWCapability cap = new TWCapability(capabilityId) using (TWCapability cap = new TWCapability(CapabilityId.CapSupportedCaps))
{
ContainerType = ContainerType.DoNotCare
})
{ {
var rc = DGControl.Capability.ResetAll(cap); var rc = DGControl.Capability.ResetAll(cap);
return rc; return rc;
@@ -161,10 +157,7 @@ namespace NTwain
/// <returns></returns> /// <returns></returns>
public ReturnCode CapReset(CapabilityId capabilityId) public ReturnCode CapReset(CapabilityId capabilityId)
{ {
using (TWCapability cap = new TWCapability(capabilityId) using (TWCapability cap = new TWCapability(capabilityId))
{
ContainerType = ContainerType.DoNotCare
})
{ {
var rc = DGControl.Capability.Reset(cap); var rc = DGControl.Capability.Reset(cap);
return rc; return rc;
@@ -185,7 +178,7 @@ namespace NTwain
/// <value> /// <value>
/// The audio xfer mech. /// The audio xfer mech.
/// </value> /// </value>
public CapWrapper<XferMech> CapAudioXferMech public ICapWrapper<XferMech> CapAudioXferMech
{ {
get get
{ {
@@ -202,6 +195,51 @@ namespace NTwain
#region img caps #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; private CapWrapper<Unit> _imgUnits;
/// <summary> /// <summary>
@@ -210,7 +248,7 @@ namespace NTwain
/// <value> /// <value>
/// The image unit of measure. /// The image unit of measure.
/// </value> /// </value>
public CapWrapper<Unit> CapImageUnits public ICapWrapper<Unit> CapImageUnits
{ {
get get
{ {
@@ -231,7 +269,7 @@ namespace NTwain
/// <value> /// <value>
/// The image xfer mech. /// The image xfer mech.
/// </value> /// </value>
public CapWrapper<XferMech> CapImageXferMech public ICapWrapper<XferMech> CapImageXferMech
{ {
get get
{ {
@@ -244,21 +282,110 @@ namespace NTwain
} }
} }
#endregion
private CapWrapper<CompressionType> _compression;
private CapWrapper<BoolType> _autoBright;
/// <summary> /// <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> /// </summary>
/// <value> /// <value>
/// The image compression. /// The image auto brightness flag.
/// </value> /// </value>
public CapWrapper<CompressionType> CapImageCompression public ICapWrapper<BoolType> CapImageAutoBright
{ {
get get
{ {
return _compression ?? (_compression = new CapWrapper<CompressionType>(this, CapabilityId.ICapCompression, ValueExtensions.ConvertToEnum<CompressionType>, return _autoBright ?? (_autoBright = new CapWrapper<BoolType>(this, CapabilityId.ICapAutoBright, ValueExtensions.ConvertToEnum<BoolType>, value =>
value => new TWCapability(CapabilityId.ICapCompression, new TWOneValue 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, Item = (uint)value,
ItemType = ItemType.UInt16 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; private CapWrapper<FileFormat> _fileFormat;
@@ -275,7 +446,7 @@ namespace NTwain
/// <value> /// <value>
/// The image file format. /// The image file format.
/// </value> /// </value>
public CapWrapper<FileFormat> CapImageFileFormat public ICapWrapper<FileFormat> CapImageFileFormat
{ {
get get
{ {
@@ -289,20 +460,42 @@ namespace NTwain
} }
private CapWrapper<PixelType> _pixelType; private CapWrapper<BoolType> _lampState;
/// <summary> /// <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> /// </summary>
/// <value> /// <value>
/// The image pixel type. /// The image lamp state flag.
/// </value> /// </value>
public CapWrapper<PixelType> CapImagePixelType public ICapWrapper<BoolType> CapImageLameState
{ {
get get
{ {
return _pixelType ?? (_pixelType = new CapWrapper<PixelType>(this, CapabilityId.ICapPixelType, ValueExtensions.ConvertToEnum<PixelType>, return _lampState ?? (_lampState = new CapWrapper<BoolType>(this, CapabilityId.ICapLampState, ValueExtensions.ConvertToEnum<BoolType>, value =>
value => new TWCapability(CapabilityId.ICapPixelType, new TWOneValue 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, Item = (uint)value,
ItemType = ItemType.UInt16 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; private CapWrapper<SupportedSize> _supportSize;
/// <summary> /// <summary>
@@ -319,7 +664,7 @@ namespace NTwain
/// <value> /// <value>
/// The image supported size. /// The image supported size.
/// </value> /// </value>
public CapWrapper<SupportedSize> CapImageSupportedSize public ICapWrapper<SupportedSize> CapImageSupportedSize
{ {
get get
{ {
@@ -341,7 +686,7 @@ namespace NTwain
/// <value> /// <value>
/// The image auto deskew flag. /// The image auto deskew flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapImageAutoDeskew public ICapWrapper<BoolType> CapImageAutoDeskew
{ {
get get
{ {
@@ -363,7 +708,7 @@ namespace NTwain
/// <value> /// <value>
/// The image auto rotate flag. /// The image auto rotate flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapImageAutoRotate public ICapWrapper<BoolType> CapImageAutoRotate
{ {
get 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; private CapWrapper<BoolType> _borderDetect;
/// <summary> /// <summary>
@@ -429,7 +730,7 @@ namespace NTwain
/// <value> /// <value>
/// The auto border detection flag. /// The auto border detection flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapImageAutomaticBorderDetection public ICapWrapper<BoolType> CapImageAutomaticBorderDetection
{ {
get get
{ {
@@ -459,7 +760,33 @@ namespace NTwain
#endregion #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; private CapWrapper<Duplex> _duplex;
@@ -469,7 +796,7 @@ namespace NTwain
/// <value> /// <value>
/// The duplex mode. /// The duplex mode.
/// </value> /// </value>
public CapWrapper<Duplex> CapDuplex public IReadOnlyCapWrapper<Duplex> CapDuplex
{ {
get get
{ {
@@ -485,7 +812,7 @@ namespace NTwain
/// <value> /// <value>
/// The duplex enabled flag. /// The duplex enabled flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapDuplexEnabled public ICapWrapper<BoolType> CapDuplexEnabled
{ {
get 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; private CapWrapper<BoolType> _feederLoaded;
/// <summary> /// <summary>
@@ -528,7 +833,7 @@ namespace NTwain
/// <value> /// <value>
/// The feeder loaded flag. /// The feeder loaded flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapFeederLoaded public IReadOnlyCapWrapper<BoolType> CapFeederLoaded
{ {
get get
{ {
@@ -544,7 +849,7 @@ namespace NTwain
/// <value> /// <value>
/// The feeder enabled flag. /// The feeder enabled flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapFeederEnabled public ICapWrapper<BoolType> CapFeederEnabled
{ {
get get
{ {
@@ -597,7 +902,7 @@ namespace NTwain
/// <value> /// <value>
/// The clear page flag. /// The clear page flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapClearPage public ICapWrapper<BoolType> CapClearPage
{ {
get get
{ {
@@ -618,7 +923,7 @@ namespace NTwain
/// <value> /// <value>
/// The feed page flag. /// The feed page flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapFeedPage public ICapWrapper<BoolType> CapFeedPage
{ {
get get
{ {
@@ -639,7 +944,7 @@ namespace NTwain
/// <value> /// <value>
/// The rewind page flag. /// The rewind page flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapRewindPage public ICapWrapper<BoolType> CapRewindPage
{ {
get get
{ {
@@ -660,7 +965,7 @@ namespace NTwain
/// <value> /// <value>
/// The indicators flag. /// The indicators flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapIndicators public ICapWrapper<BoolType> CapIndicators
{ {
get get
{ {
@@ -681,7 +986,7 @@ namespace NTwain
/// <value> /// <value>
/// The paper sensor flag. /// The paper sensor flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapPaperDetectable public IReadOnlyCapWrapper<BoolType> CapPaperDetectable
{ {
get get
{ {
@@ -697,7 +1002,7 @@ namespace NTwain
/// <value> /// <value>
/// The UI controllable flag. /// The UI controllable flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapUIControllable public IReadOnlyCapWrapper<BoolType> CapUIControllable
{ {
get get
{ {
@@ -713,7 +1018,7 @@ namespace NTwain
/// <value> /// <value>
/// The devince online flag. /// The devince online flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapDeviceOnline public IReadOnlyCapWrapper<BoolType> CapDeviceOnline
{ {
get get
{ {
@@ -729,7 +1034,7 @@ namespace NTwain
/// <value> /// <value>
/// The thumbnails enabled flag. /// The thumbnails enabled flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapThumbnailsEnabled public ICapWrapper<BoolType> CapThumbnailsEnabled
{ {
get get
{ {
@@ -750,7 +1055,7 @@ namespace NTwain
/// <value> /// <value>
/// The UI only flag. /// The UI only flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapEnableDSUIOnly public IReadOnlyCapWrapper<BoolType> CapEnableDSUIOnly
{ {
get get
{ {
@@ -766,7 +1071,7 @@ namespace NTwain
/// <value> /// <value>
/// The custom data flag. /// The custom data flag.
/// </value> /// </value>
public CapWrapper<BoolType> CapCustomDSData public IReadOnlyCapWrapper<BoolType> CapCustomDSData
{ {
get get
{ {
@@ -782,7 +1087,7 @@ namespace NTwain
/// <value> /// <value>
/// The job control option. /// The job control option.
/// </value> /// </value>
public CapWrapper<JobControl> CapJobControl public ICapWrapper<JobControl> CapJobControl
{ {
get get
{ {
@@ -803,7 +1108,7 @@ namespace NTwain
/// <value> /// <value>
/// The alarm volume. /// The alarm volume.
/// </value> /// </value>
public CapWrapper<int> CapAlarmVolume public ICapWrapper<int> CapAlarmVolume
{ {
get get
{ {
@@ -824,7 +1129,7 @@ namespace NTwain
///// <value> ///// <value>
///// The auto capture count. ///// The auto capture count.
///// </value> ///// </value>
//public CapWrapper<int> CapAutomaticCapture //public ICapWrapper<int> CapAutomaticCapture
//{ //{
// get // get
// { // {

View File

@@ -47,24 +47,8 @@ namespace NTwain
/// <summary> /// <summary>
/// Resets all values and constraints to power-on defaults. /// Resets all values and constraints to power-on defaults.
/// </summary> /// </summary>
/// <param name="capabilityId">The capability identifier.</param>
/// <returns></returns> /// <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\WinMemoryManager.cs" />
<Compile Include="Internals\UnsafeNativeMethods.cs" /> <Compile Include="Internals\UnsafeNativeMethods.cs" />
<Compile Include="Internals\IWinMessageFilter.cs" /> <Compile Include="Internals\IWinMessageFilter.cs" />
<Compile Include="ICapWrapper.cs" />
<Compile Include="MessageLoopHooks.cs" /> <Compile Include="MessageLoopHooks.cs" />
<Compile Include="PlatformInfo.cs" /> <Compile Include="PlatformInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs"> <Compile Include="Properties\Resources.Designer.cs">

View File

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

View File

@@ -307,7 +307,7 @@ namespace Tester.Winform
_loadingCaps = false; _loadingCaps = false;
} }
private void LoadPaperSize(CapWrapper<SupportedSize> cap) private void LoadPaperSize(ICapWrapper<SupportedSize> cap)
{ {
var list = cap.Get(); var list = cap.Get();
comboSize.DataSource = list; 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; 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 // only allow dpi of certain values for those source that lists everything
var list = cap.Get().Where(dpi => (dpi % 50) == 0).ToList(); 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(); var list = cap.Get();
comboDepth.DataSource = list; comboDepth.DataSource = list;