More cap wrapper.

This commit is contained in:
soukoku
2014-11-08 08:58:27 -05:00
parent 88a54c95d9
commit b4c3ebd549
4 changed files with 370 additions and 122 deletions

View File

@@ -24,9 +24,9 @@ namespace NTwain
ICapControl _source; ICapControl _source;
Func<object, TValue> _convertRoutine; Func<object, TValue> _getConvertRoutine;
Func<TValue, ReturnCode> _setCustomRoutine; Func<TValue, ReturnCode> _setCustomRoutine;
Func<TValue, TWCapability> _setProvider; // an simplified way to set() that only needs on cap value Func<TValue, TWOneValue> _setOneValueFunc;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="CapWrapper{TValue}" /> class. /// Initializes a new instance of the <see cref="CapWrapper{TValue}" /> class.
@@ -46,7 +46,7 @@ namespace NTwain
if (getConversionRoutine == null) { throw new ArgumentNullException("valueConversionRoutine"); } if (getConversionRoutine == null) { throw new ArgumentNullException("valueConversionRoutine"); }
_source = source; _source = source;
_convertRoutine = getConversionRoutine; _getConvertRoutine = getConversionRoutine;
Capability = capability; Capability = capability;
SupportedActions = source.CapQuerySupport(capability); SupportedActions = source.CapQuerySupport(capability);
} }
@@ -68,15 +68,15 @@ namespace NTwain
/// </exception> /// </exception>
public CapWrapper(ICapControl source, CapabilityId capability, public CapWrapper(ICapControl source, CapabilityId capability,
Func<object, TValue> getConversionRoutine, Func<object, TValue> getConversionRoutine,
Func<TValue, TWCapability> setValueProvider) Func<TValue, TWOneValue> setValueProvider)
{ {
if (source == null) { throw new ArgumentNullException("source"); } if (source == null) { throw new ArgumentNullException("source"); }
if (getConversionRoutine == null) { throw new ArgumentNullException("valueConversionRoutine"); } if (getConversionRoutine == null) { throw new ArgumentNullException("valueConversionRoutine"); }
if (setValueProvider == null) { throw new ArgumentNullException("setValueProvider"); } if (setValueProvider == null) { throw new ArgumentNullException("setValueProvider"); }
_source = source; _source = source;
_convertRoutine = getConversionRoutine; _getConvertRoutine = getConversionRoutine;
_setProvider = setValueProvider; _setOneValueFunc = setValueProvider;
Capability = capability; Capability = capability;
SupportedActions = source.CapQuerySupport(capability); SupportedActions = source.CapQuerySupport(capability);
} }
@@ -104,7 +104,7 @@ namespace NTwain
if (setValueRoutine == null) { throw new ArgumentNullException("setValueRoutine"); } if (setValueRoutine == null) { throw new ArgumentNullException("setValueRoutine"); }
_source = source; _source = source;
_convertRoutine = getConversionRoutine; _getConvertRoutine = getConversionRoutine;
_setCustomRoutine = setValueRoutine; _setCustomRoutine = setValueRoutine;
Capability = capability; Capability = capability;
SupportedActions = source.CapQuerySupport(capability); SupportedActions = source.CapQuerySupport(capability);
@@ -206,13 +206,13 @@ namespace NTwain
/// </value> /// </value>
public bool CanSet { get { return Supports(QuerySupports.Set); } } public bool CanSet { get { return Supports(QuerySupports.Set); } }
///// <summary> /// <summary>
///// Gets a value indicating whether <see cref="SetConstraint"/> is supported. /// Gets a value indicating whether <see cref="SetConstraint"/> is supported.
///// </summary> /// </summary>
///// <value> /// <value>
///// <c>true</c> if this capability can set constraint; otherwise, <c>false</c>. /// <c>true</c> if this capability can set constraint; otherwise, <c>false</c>.
///// </value> /// </value>
//public bool CanSetConstraint { get { return Supports(QuerySupports.SetConstraint); } } public bool CanSetConstraint { get { return Supports(QuerySupports.SetConstraint); } }
#endregion #endregion
@@ -226,7 +226,7 @@ namespace NTwain
{ {
if (CanGetDefault) if (CanGetDefault)
{ {
return _convertRoutine(_source.CapGetDefault(Capability)); return _getConvertRoutine(_source.CapGetDefault(Capability));
} }
return default(TValue); return default(TValue);
} }
@@ -239,7 +239,7 @@ namespace NTwain
{ {
if (CanGetCurrent) if (CanGetCurrent)
{ {
return _convertRoutine(_source.CapGetCurrent(Capability)); return _getConvertRoutine(_source.CapGetCurrent(Capability));
} }
return default(TValue); return default(TValue);
} }
@@ -252,7 +252,7 @@ namespace NTwain
{ {
if (CanGet) if (CanGet)
{ {
return _source.CapGet(Capability).Select(o => _convertRoutine(o)).ToList(); return _source.CapGet(Capability).Select(o => _getConvertRoutine(o)).ToList();
} }
return new List<TValue>(); return new List<TValue>();
} }
@@ -350,7 +350,7 @@ namespace NTwain
} }
/// <summary> /// <summary>
/// Sets the current value of this capability. /// Simplified version that sets the current value of this capability.
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <returns></returns> /// <returns></returns>
@@ -363,9 +363,9 @@ namespace NTwain
{ {
rc = _setCustomRoutine(value); rc = _setCustomRoutine(value);
} }
else if (_setProvider != null) else if (_setOneValueFunc != null)
{ {
using (var cap = _setProvider(value)) using (var cap = new TWCapability(Capability, _setOneValueFunc(value)))
{ {
rc = _source.DGControl.Capability.Set(cap); rc = _source.DGControl.Capability.Set(cap);
} }
@@ -374,6 +374,59 @@ namespace NTwain
return rc; return rc;
} }
/// <summary>
/// Sets the constraint value of this capability.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public ReturnCode SetConstraint(TWOneValue value)
{
ReturnCode rc = ReturnCode.Failure;
if (CanSetConstraint)
{
using (var cap = new TWCapability(Capability, value))
{
rc = _source.DGControl.Capability.SetConstraint(cap);
}
}
return rc;
}
/// <summary>
/// Sets the constraint value of this capability.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public ReturnCode SetConstraint(TWEnumeration value)
{
ReturnCode rc = ReturnCode.Failure;
if (CanSetConstraint)
{
using (var cap = new TWCapability(Capability, value))
{
rc = _source.DGControl.Capability.SetConstraint(cap);
}
}
return rc;
}
/// <summary>
/// Sets the constraint value of this capability.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public ReturnCode SetConstraint(TWRange value)
{
ReturnCode rc = ReturnCode.Failure;
if (CanSetConstraint)
{
using (var cap = new TWCapability(Capability, value))
{
rc = _source.DGControl.Capability.SetConstraint(cap);
}
}
return rc;
}
#endregion #endregion
} }

View File

@@ -183,11 +183,11 @@ namespace NTwain
get get
{ {
return _audXferMech ?? (_audXferMech = new CapWrapper<XferMech>(this, CapabilityId.ACapXferMech, ValueExtensions.ConvertToEnum<XferMech>, return _audXferMech ?? (_audXferMech = new CapWrapper<XferMech>(this, CapabilityId.ACapXferMech, ValueExtensions.ConvertToEnum<XferMech>,
value => new TWCapability(CapabilityId.ACapXferMech, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
@@ -210,11 +210,11 @@ namespace NTwain
get get
{ {
return _compression ?? (_compression = new CapWrapper<CompressionType>(this, CapabilityId.ICapCompression, ValueExtensions.ConvertToEnum<CompressionType>, return _compression ?? (_compression = new CapWrapper<CompressionType>(this, CapabilityId.ICapCompression, ValueExtensions.ConvertToEnum<CompressionType>,
value => new TWCapability(CapabilityId.ICapCompression, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
@@ -232,11 +232,11 @@ namespace NTwain
get get
{ {
return _pixelType ?? (_pixelType = new CapWrapper<PixelType>(this, CapabilityId.ICapPixelType, ValueExtensions.ConvertToEnum<PixelType>, return _pixelType ?? (_pixelType = new CapWrapper<PixelType>(this, CapabilityId.ICapPixelType, ValueExtensions.ConvertToEnum<PixelType>,
value => new TWCapability(CapabilityId.ICapPixelType, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
@@ -253,11 +253,11 @@ namespace NTwain
get get
{ {
return _imgUnits ?? (_imgUnits = new CapWrapper<Unit>(this, CapabilityId.ICapUnits, ValueExtensions.ConvertToEnum<Unit>, return _imgUnits ?? (_imgUnits = new CapWrapper<Unit>(this, CapabilityId.ICapUnits, ValueExtensions.ConvertToEnum<Unit>,
value => new TWCapability(CapabilityId.ICapUnits, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
@@ -274,17 +274,16 @@ namespace NTwain
get get
{ {
return _imgXferMech ?? (_imgXferMech = new CapWrapper<XferMech>(this, CapabilityId.ICapXferMech, ValueExtensions.ConvertToEnum<XferMech>, return _imgXferMech ?? (_imgXferMech = new CapWrapper<XferMech>(this, CapabilityId.ICapXferMech, ValueExtensions.ConvertToEnum<XferMech>,
value => new TWCapability(CapabilityId.ICapXferMech, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
#endregion #endregion
private CapWrapper<BoolType> _autoBright; private CapWrapper<BoolType> _autoBright;
/// <summary> /// <summary>
@@ -297,12 +296,12 @@ namespace NTwain
{ {
get get
{ {
return _autoBright ?? (_autoBright = new CapWrapper<BoolType>(this, CapabilityId.ICapAutoBright, ValueExtensions.ConvertToEnum<BoolType>, value => return _autoBright ?? (_autoBright = new CapWrapper<BoolType>(this, CapabilityId.ICapAutoBright, ValueExtensions.ConvertToEnum<BoolType>,
new TWCapability(CapabilityId.ICapAutoBright, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Bool ItemType = ItemType.Bool
}))); }));
} }
} }
@@ -319,11 +318,11 @@ namespace NTwain
get get
{ {
return _brightness ?? (_brightness = new CapWrapper<TWFix32>(this, CapabilityId.ICapBrightness, ValueExtensions.ConvertToFix32, return _brightness ?? (_brightness = new CapWrapper<TWFix32>(this, CapabilityId.ICapBrightness, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapBrightness, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value,// ((uint)dpi) << 16; Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32 ItemType = ItemType.Fix32
}))); }));
} }
} }
@@ -340,11 +339,11 @@ namespace NTwain
get get
{ {
return _contrast ?? (_contrast = new CapWrapper<TWFix32>(this, CapabilityId.ICapContrast, ValueExtensions.ConvertToFix32, return _contrast ?? (_contrast = new CapWrapper<TWFix32>(this, CapabilityId.ICapContrast, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapContrast, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value,// ((uint)dpi) << 16; Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32 ItemType = ItemType.Fix32
}))); }));
} }
} }
@@ -363,15 +362,14 @@ namespace NTwain
get get
{ {
return _exposureTime ?? (_exposureTime = new CapWrapper<TWFix32>(this, CapabilityId.ICapExposureTime, ValueExtensions.ConvertToFix32, return _exposureTime ?? (_exposureTime = new CapWrapper<TWFix32>(this, CapabilityId.ICapExposureTime, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapExposureTime, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value,// ((uint)dpi) << 16; Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32 ItemType = ItemType.Fix32
}))); }));
} }
} }
private CapWrapper<ImageFilter> _imgFilter; private CapWrapper<ImageFilter> _imgFilter;
/// <summary> /// <summary>
@@ -385,11 +383,11 @@ namespace NTwain
get get
{ {
return _imgFilter ?? (_imgFilter = new CapWrapper<ImageFilter>(this, CapabilityId.ICapFilter, ValueExtensions.ConvertToEnum<ImageFilter>, return _imgFilter ?? (_imgFilter = new CapWrapper<ImageFilter>(this, CapabilityId.ICapFilter, ValueExtensions.ConvertToEnum<ImageFilter>,
value => new TWCapability(CapabilityId.ICapFilter, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
@@ -406,11 +404,11 @@ namespace NTwain
get get
{ {
return _gamma ?? (_gamma = new CapWrapper<TWFix32>(this, CapabilityId.ICapGamma, ValueExtensions.ConvertToFix32, return _gamma ?? (_gamma = new CapWrapper<TWFix32>(this, CapabilityId.ICapGamma, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapGamma, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value,// ((uint)dpi) << 16; Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32 ItemType = ItemType.Fix32
}))); }));
} }
} }
@@ -429,15 +427,14 @@ namespace NTwain
get get
{ {
return _highlight ?? (_highlight = new CapWrapper<TWFix32>(this, CapabilityId.ICapHighlight, ValueExtensions.ConvertToFix32, return _highlight ?? (_highlight = new CapWrapper<TWFix32>(this, CapabilityId.ICapHighlight, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapHighlight, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value,// ((uint)dpi) << 16; Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32 ItemType = ItemType.Fix32
}))); }));
} }
} }
private CapWrapper<FileFormat> _fileFormat; private CapWrapper<FileFormat> _fileFormat;
/// <summary> /// <summary>
@@ -451,11 +448,11 @@ namespace NTwain
get get
{ {
return _fileFormat ?? (_fileFormat = new CapWrapper<FileFormat>(this, CapabilityId.ICapImageFileFormat, ValueExtensions.ConvertToEnum<FileFormat>, return _fileFormat ?? (_fileFormat = new CapWrapper<FileFormat>(this, CapabilityId.ICapImageFileFormat, ValueExtensions.ConvertToEnum<FileFormat>,
value => new TWCapability(CapabilityId.ICapImageFileFormat, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
@@ -472,16 +469,15 @@ namespace NTwain
{ {
get get
{ {
return _lampState ?? (_lampState = new CapWrapper<BoolType>(this, CapabilityId.ICapLampState, ValueExtensions.ConvertToEnum<BoolType>, value => return _lampState ?? (_lampState = new CapWrapper<BoolType>(this, CapabilityId.ICapLampState, ValueExtensions.ConvertToEnum<BoolType>,
new TWCapability(CapabilityId.ICapLampState, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Bool ItemType = ItemType.Bool
}))); }));
} }
} }
private CapWrapper<LightSource> _lightSource; private CapWrapper<LightSource> _lightSource;
/// <summary> /// <summary>
@@ -494,16 +490,15 @@ namespace NTwain
{ {
get get
{ {
return _lightSource ?? (_lightSource = new CapWrapper<LightSource>(this, CapabilityId.ICapLightSource, ValueExtensions.ConvertToEnum<LightSource>, value => return _lightSource ?? (_lightSource = new CapWrapper<LightSource>(this, CapabilityId.ICapLightSource, ValueExtensions.ConvertToEnum<LightSource>,
new TWCapability(CapabilityId.ICapLightSource, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
private CapWrapper<OrientationType> _orientation; private CapWrapper<OrientationType> _orientation;
/// <summary> /// <summary>
@@ -516,12 +511,12 @@ namespace NTwain
{ {
get get
{ {
return _orientation ?? (_orientation = new CapWrapper<OrientationType>(this, CapabilityId.ICapOrientation, ValueExtensions.ConvertToEnum<OrientationType>, value => return _orientation ?? (_orientation = new CapWrapper<OrientationType>(this, CapabilityId.ICapOrientation, ValueExtensions.ConvertToEnum<OrientationType>,
new TWCapability(CapabilityId.ICapOrientation, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
@@ -570,11 +565,11 @@ namespace NTwain
get get
{ {
return _shadow ?? (_shadow = new CapWrapper<TWFix32>(this, CapabilityId.ICapShadow, ValueExtensions.ConvertToFix32, return _shadow ?? (_shadow = new CapWrapper<TWFix32>(this, CapabilityId.ICapShadow, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapShadow, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value,// ((uint)dpi) << 16; Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32 ItemType = ItemType.Fix32
}))); }));
} }
} }
@@ -611,8 +606,7 @@ namespace NTwain
return _nativeYRes ?? (_nativeYRes = new CapWrapper<TWFix32>(this, CapabilityId.ICapYNativeResolution, ValueExtensions.ConvertToFix32)); return _nativeYRes ?? (_nativeYRes = new CapWrapper<TWFix32>(this, CapabilityId.ICapYNativeResolution, ValueExtensions.ConvertToFix32));
} }
} }
private CapWrapper<TWFix32> _xResolution; private CapWrapper<TWFix32> _xResolution;
/// <summary> /// <summary>
@@ -626,11 +620,11 @@ namespace NTwain
get get
{ {
return _xResolution ?? (_xResolution = new CapWrapper<TWFix32>(this, CapabilityId.ICapXResolution, ValueExtensions.ConvertToFix32, return _xResolution ?? (_xResolution = new CapWrapper<TWFix32>(this, CapabilityId.ICapXResolution, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapXResolution, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value,// ((uint)dpi) << 16; Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32 ItemType = ItemType.Fix32
}))); }));
} }
} }
@@ -648,13 +642,182 @@ namespace NTwain
get get
{ {
return _yResolution ?? (_yResolution = new CapWrapper<TWFix32>(this, CapabilityId.ICapYResolution, ValueExtensions.ConvertToFix32, return _yResolution ?? (_yResolution = new CapWrapper<TWFix32>(this, CapabilityId.ICapYResolution, ValueExtensions.ConvertToFix32,
value => new TWCapability(CapabilityId.ICapYResolution, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value,// ((uint)dpi) << 16; Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32 ItemType = ItemType.Fix32
}))); }));
} }
} }
private CapWrapper<int> _maxFrames;
/// <summary>
/// Gets the property to work with image max frames for the current source.
/// </summary>
/// <value>
/// The image max frames.
/// </value>
public ICapWrapper<int> CapImageMaxFrames
{
get
{
return _maxFrames ?? (_maxFrames = new CapWrapper<int>(this, CapabilityId.ICapMaxFrames, ValueExtensions.ConvertToEnum<int>,
value => new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
}));
}
}
private CapWrapper<BoolType> _tiles;
/// <summary>
/// Gets the property to work with image tiles flag for the current source.
/// </summary>
/// <value>
/// The image tiles flag.
/// </value>
public ICapWrapper<BoolType> CapImageTiles
{
get
{
return _tiles ?? (_tiles = new CapWrapper<BoolType>(this, CapabilityId.ICapTiles, ValueExtensions.ConvertToEnum<BoolType>,
value => new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.Bool
}));
}
}
private CapWrapper<BitOrder> _bitOrder;
/// <summary>
/// Gets the property to work with image <see cref="BitOrder"/> for the current source.
/// </summary>
/// <value>
/// The image bit order.
/// </value>
public ICapWrapper<BitOrder> CapImageBitOrder
{
get
{
return _bitOrder ?? (_bitOrder = new CapWrapper<BitOrder>(this, CapabilityId.ICapBitOrder, ValueExtensions.ConvertToEnum<BitOrder>,
value => new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
}));
}
}
private CapWrapper<int> _ccittKFactor;
/// <summary>
/// Gets the property to work with image CCITT K factor for the current source.
/// </summary>
/// <value>
/// The image CCITT K factor.
/// </value>
public ICapWrapper<int> CapImageCCITTKFactor
{
get
{
return _ccittKFactor ?? (_ccittKFactor = new CapWrapper<int>(this, CapabilityId.ICapCCITTKFactor, ValueExtensions.ConvertToEnum<int>,
value => new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
}));
}
}
private CapWrapper<LightPath> _lightPath;
/// <summary>
/// Gets the property to work with image light path for the current source.
/// </summary>
/// <value>
/// The image light path.
/// </value>
public ICapWrapper<LightPath> CapImageLightPath
{
get
{
return _lightPath ?? (_lightPath = new CapWrapper<LightPath>(this, CapabilityId.ICapLightPath, ValueExtensions.ConvertToEnum<LightPath>,
value => new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
}));
}
}
private CapWrapper<PixelFlavor> _pixelFlavor;
/// <summary>
/// Gets the property to work with image pixel flavor for the current source.
/// </summary>
/// <value>
/// The image pixel flavor.
/// </value>
public ICapWrapper<PixelFlavor> CapImagePixelFlavor
{
get
{
return _pixelFlavor ?? (_pixelFlavor = new CapWrapper<PixelFlavor>(this, CapabilityId.ICapPixelFlavor, ValueExtensions.ConvertToEnum<PixelFlavor>,
value => new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
}));
}
}
private CapWrapper<PlanarChunky> _planarChunky;
/// <summary>
/// Gets the property to work with image color format for the current source.
/// </summary>
/// <value>
/// The image color format.
/// </value>
public ICapWrapper<PlanarChunky> CapImagePlanarChunky
{
get
{
return _planarChunky ?? (_planarChunky = new CapWrapper<PlanarChunky>(this, CapabilityId.ICapPlanarChunky, ValueExtensions.ConvertToEnum<PlanarChunky>,
value => new TWOneValue
{
Item = (uint)value,
ItemType = ItemType.UInt16
}));
}
}
private CapWrapper<TWFix32> _rotation;
/// <summary>
/// Gets the property to work with image rotation for the current source.
/// </summary>
/// <value>
/// The image rotation.
/// </value>
public ICapWrapper<TWFix32> CapImageRotation
{
get
{
return _rotation ?? (_rotation = new CapWrapper<TWFix32>(this, CapabilityId.ICapRotation, ValueExtensions.ConvertToFix32,
value => new TWOneValue
{
Item = (uint)value,// ((uint)dpi) << 16;
ItemType = ItemType.Fix32
}));
}
}
private CapWrapper<SupportedSize> _supportSize; private CapWrapper<SupportedSize> _supportSize;
@@ -669,11 +832,11 @@ namespace NTwain
get get
{ {
return _supportSize ?? (_supportSize = new CapWrapper<SupportedSize>(this, CapabilityId.ICapSupportedSizes, ValueExtensions.ConvertToEnum<SupportedSize>, return _supportSize ?? (_supportSize = new CapWrapper<SupportedSize>(this, CapabilityId.ICapSupportedSizes, ValueExtensions.ConvertToEnum<SupportedSize>,
value => new TWCapability(CapabilityId.ICapSupportedSizes, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
@@ -690,12 +853,12 @@ namespace NTwain
{ {
get get
{ {
return _autoDeskew ?? (_autoDeskew = new CapWrapper<BoolType>(this, CapabilityId.ICapAutomaticDeskew, ValueExtensions.ConvertToEnum<BoolType>, value => return _autoDeskew ?? (_autoDeskew = new CapWrapper<BoolType>(this, CapabilityId.ICapAutomaticDeskew, ValueExtensions.ConvertToEnum<BoolType>,
new TWCapability(CapabilityId.ICapAutomaticDeskew, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Bool ItemType = ItemType.Bool
}))); }));
} }
} }
@@ -712,12 +875,12 @@ namespace NTwain
{ {
get get
{ {
return _autoRotate ?? (_autoRotate = new CapWrapper<BoolType>(this, CapabilityId.ICapAutomaticRotate, ValueExtensions.ConvertToEnum<BoolType>, value => return _autoRotate ?? (_autoRotate = new CapWrapper<BoolType>(this, CapabilityId.ICapAutomaticRotate, ValueExtensions.ConvertToEnum<BoolType>,
new TWCapability(CapabilityId.ICapAutomaticRotate, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Bool ItemType = ItemType.Bool
}))); }));
} }
} }
@@ -734,7 +897,8 @@ namespace NTwain
{ {
get get
{ {
return _borderDetect ?? (_borderDetect = new CapWrapper<BoolType>(this, CapabilityId.ICapAutomaticBorderDetection, ValueExtensions.ConvertToEnum<BoolType>, value => return _borderDetect ?? (_borderDetect = new CapWrapper<BoolType>(this, CapabilityId.ICapAutomaticBorderDetection, ValueExtensions.ConvertToEnum<BoolType>,
value =>
{ {
var rc = ReturnCode.Failure; var rc = ReturnCode.Failure;
@@ -776,12 +940,12 @@ namespace NTwain
{ {
get get
{ {
return _xferCount ?? (_xferCount = new CapWrapper<int>(this, CapabilityId.CapXferCount, ValueExtensions.ConvertToEnum<int>, value => return _xferCount ?? (_xferCount = new CapWrapper<int>(this, CapabilityId.CapXferCount, ValueExtensions.ConvertToEnum<int>,
new TWCapability(CapabilityId.CapXferCount, new TWOneValue value => new TWOneValue
{ {
Item = value > 0 ? (uint)value : uint.MaxValue, Item = value > 0 ? (uint)value : uint.MaxValue,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
@@ -816,12 +980,12 @@ namespace NTwain
{ {
get get
{ {
return _duplexEnabled ?? (_duplexEnabled = new CapWrapper<BoolType>(this, CapabilityId.CapDuplexEnabled, ValueExtensions.ConvertToEnum<BoolType>, value => return _duplexEnabled ?? (_duplexEnabled = new CapWrapper<BoolType>(this, CapabilityId.CapDuplexEnabled, ValueExtensions.ConvertToEnum<BoolType>,
new TWCapability(CapabilityId.CapDuplexEnabled, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Bool ItemType = ItemType.Bool
}))); }));
} }
} }
@@ -853,7 +1017,8 @@ namespace NTwain
{ {
get get
{ {
return _feederEnabled ?? (_feederEnabled = new CapWrapper<BoolType>(this, CapabilityId.CapFeederEnabled, ValueExtensions.ConvertToEnum<BoolType>, value => return _feederEnabled ?? (_feederEnabled = new CapWrapper<BoolType>(this, CapabilityId.CapFeederEnabled, ValueExtensions.ConvertToEnum<BoolType>,
value =>
{ {
var rc = ReturnCode.Failure; var rc = ReturnCode.Failure;
@@ -906,12 +1071,12 @@ namespace NTwain
{ {
get get
{ {
return _clearPage ?? (_clearPage = new CapWrapper<BoolType>(this, CapabilityId.CapClearPage, ValueExtensions.ConvertToEnum<BoolType>, value => return _clearPage ?? (_clearPage = new CapWrapper<BoolType>(this, CapabilityId.CapClearPage, ValueExtensions.ConvertToEnum<BoolType>,
new TWCapability(CapabilityId.CapClearPage, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Bool ItemType = ItemType.Bool
}))); }));
} }
} }
@@ -927,12 +1092,12 @@ namespace NTwain
{ {
get get
{ {
return _feedPage ?? (_feedPage = new CapWrapper<BoolType>(this, CapabilityId.CapFeedPage, ValueExtensions.ConvertToEnum<BoolType>, value => return _feedPage ?? (_feedPage = new CapWrapper<BoolType>(this, CapabilityId.CapFeedPage, ValueExtensions.ConvertToEnum<BoolType>,
new TWCapability(CapabilityId.CapFeedPage, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Bool ItemType = ItemType.Bool
}))); }));
} }
} }
@@ -948,12 +1113,12 @@ namespace NTwain
{ {
get get
{ {
return _rewindPage ?? (_rewindPage = new CapWrapper<BoolType>(this, CapabilityId.CapRewindPage, ValueExtensions.ConvertToEnum<BoolType>, value => return _rewindPage ?? (_rewindPage = new CapWrapper<BoolType>(this, CapabilityId.CapRewindPage, ValueExtensions.ConvertToEnum<BoolType>,
new TWCapability(CapabilityId.CapRewindPage, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Bool ItemType = ItemType.Bool
}))); }));
} }
} }
@@ -969,12 +1134,12 @@ namespace NTwain
{ {
get get
{ {
return _indicators ?? (_indicators = new CapWrapper<BoolType>(this, CapabilityId.CapIndicators, ValueExtensions.ConvertToEnum<BoolType>, value => return _indicators ?? (_indicators = new CapWrapper<BoolType>(this, CapabilityId.CapIndicators, ValueExtensions.ConvertToEnum<BoolType>,
new TWCapability(CapabilityId.CapIndicators, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Bool ItemType = ItemType.Bool
}))); }));
} }
} }
@@ -1038,12 +1203,12 @@ namespace NTwain
{ {
get get
{ {
return _thumbsEnabled ?? (_thumbsEnabled = new CapWrapper<BoolType>(this, CapabilityId.CapThumbnailsEnabled, ValueExtensions.ConvertToEnum<BoolType>, value => return _thumbsEnabled ?? (_thumbsEnabled = new CapWrapper<BoolType>(this, CapabilityId.CapThumbnailsEnabled, ValueExtensions.ConvertToEnum<BoolType>,
new TWCapability(CapabilityId.CapThumbnailsEnabled, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Bool ItemType = ItemType.Bool
}))); }));
} }
} }
@@ -1091,12 +1256,12 @@ namespace NTwain
{ {
get get
{ {
return _jobControl ?? (_jobControl = new CapWrapper<JobControl>(this, CapabilityId.CapJobControl, ValueExtensions.ConvertToEnum<JobControl>, value => return _jobControl ?? (_jobControl = new CapWrapper<JobControl>(this, CapabilityId.CapJobControl, ValueExtensions.ConvertToEnum<JobControl>,
new TWCapability(CapabilityId.CapJobControl, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.UInt16 ItemType = ItemType.UInt16
}))); }));
} }
} }
@@ -1112,12 +1277,12 @@ namespace NTwain
{ {
get get
{ {
return _alarmVolume ?? (_alarmVolume = new CapWrapper<int>(this, CapabilityId.CapAlarmVolume, ValueExtensions.ConvertToEnum<int>, value => return _alarmVolume ?? (_alarmVolume = new CapWrapper<int>(this, CapabilityId.CapAlarmVolume, ValueExtensions.ConvertToEnum<int>,
new TWCapability(CapabilityId.CapAlarmVolume, new TWOneValue value => new TWOneValue
{ {
Item = (uint)value, Item = (uint)value,
ItemType = ItemType.Int32 ItemType = ItemType.Int32
}))); }));
} }
} }
@@ -1133,12 +1298,12 @@ namespace NTwain
//{ //{
// get // get
// { // {
// return _autoCapture ?? (_autoCapture = new CapWrapper<int>(this, CapabilityId.CapAutomaticCapture, ValueExtensions.ConvertToEnum<int>, value => // return _autoCapture ?? (_autoCapture = new CapWrapper<int>(this, CapabilityId.CapAutomaticCapture, ValueExtensions.ConvertToEnum<int>,
// new TWCapability(CapabilityId.CapAutomaticCapture, new TWOneValue // new TWCapability(CapabilityId.CapAutomaticCapture, new TWOneValue
// { // {
// Item = (uint)value, // Item = (uint)value,
// ItemType = ItemType.Int32 // ItemType = ItemType.Int32
// }))); // }));
// } // }
//} //}

View File

@@ -1,4 +1,5 @@
using System; using NTwain.Data;
using System;
namespace NTwain namespace NTwain
{ {
@@ -139,6 +140,14 @@ namespace NTwain
/// </value> /// </value>
bool CanSet { get; } bool CanSet { get; }
/// <summary>
/// Gets a value indicating whether <see cref="SetConstraint"/> is supported.
/// </summary>
/// <value>
/// <c>true</c> if this capability can set constraint; otherwise, <c>false</c>.
/// </value>
bool CanSetConstraint { get; }
/// <summary> /// <summary>
/// Resets the current value to power-on default. /// Resets the current value to power-on default.
/// </summary> /// </summary>
@@ -146,10 +155,31 @@ namespace NTwain
NTwain.Data.ReturnCode Reset(); NTwain.Data.ReturnCode Reset();
/// <summary> /// <summary>
/// Sets the current value of this capability. /// Simplified version that sets the current value of this capability.
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <returns></returns> /// <returns></returns>
NTwain.Data.ReturnCode Set(TValue value); NTwain.Data.ReturnCode Set(TValue value);
/// <summary>
/// Sets the constraint value of this capability.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
ReturnCode SetConstraint(TWOneValue value);
/// <summary>
/// Sets the constraint value of this capability.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
ReturnCode SetConstraint(TWEnumeration value);
/// <summary>
/// Sets the constraint value of this capability.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
ReturnCode SetConstraint(TWRange value);
} }
} }

View File

@@ -411,7 +411,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<BitDepthReduction>(); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<BitDepthReduction>();
break; break;
case CapabilityId.ICapBitOrder: case CapabilityId.ICapBitOrder:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<BitOrder>(); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageBitOrder.Get();
break; break;
case CapabilityId.ICapBitOrderCodes: case CapabilityId.ICapBitOrderCodes:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
@@ -420,7 +420,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageBrightness.Get(); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageBrightness.Get();
break; break;
case CapabilityId.ICapCCITTKFactor: case CapabilityId.ICapCCITTKFactor:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageCCITTKFactor.Get();
break; break;
case CapabilityId.ICapColorManagementEnabled: case CapabilityId.ICapColorManagementEnabled:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
@@ -501,13 +501,13 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageLameState.Get(); 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.CapImageLightPath.Get();
break; break;
case CapabilityId.ICapLightSource: case CapabilityId.ICapLightSource:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageLightSource.Get(); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageLightSource.Get();
break; break;
case CapabilityId.ICapMaxFrames: case CapabilityId.ICapMaxFrames:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageMaxFrames.Get();
break; break;
case CapabilityId.ICapMinimumHeight: case CapabilityId.ICapMinimumHeight:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
@@ -553,7 +553,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImagePhysicalWidth.Get(); 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.CapImagePixelFlavor.Get();
break; break;
case CapabilityId.ICapPixelFlavorCodes: case CapabilityId.ICapPixelFlavorCodes:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
@@ -562,10 +562,10 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImagePixelType.Get(); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImagePixelType.Get();
break; break;
case CapabilityId.ICapPlanarChunky: case CapabilityId.ICapPlanarChunky:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<PlanarChunky>(); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImagePlanarChunky.Get();
break; break;
case CapabilityId.ICapRotation: case CapabilityId.ICapRotation:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap).CastToEnum<Rotation>(); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageRotation.Get();
break; break;
case CapabilityId.ICapShadow: case CapabilityId.ICapShadow:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageShadow.Get(); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageShadow.Get();
@@ -586,7 +586,7 @@ namespace Tester.WPF
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);
break; break;
case CapabilityId.ICapTiles: case CapabilityId.ICapTiles:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapImageTiles.Get();
break; break;
case CapabilityId.ICapTimeFill: case CapabilityId.ICapTimeFill:
CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap); CapDetailList.ItemsSource = _twainVM.CurrentSource.CapGet(cap);