mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
First attempt on #76 TWFix32 onevalue being wrong.
This commit is contained in:
parent
8f6e661a61
commit
a11add856d
@ -326,10 +326,10 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
return _autoBright ?? (_autoBright = new CapWrapper<BoolType>(_source, CapabilityId.ICapAutoBright, ValueExtensions.ConvertToEnum<BoolType>,
|
return _autoBright ?? (_autoBright = new CapWrapper<BoolType>(_source, CapabilityId.ICapAutoBright, ValueExtensions.ConvertToEnum<BoolType>,
|
||||||
value => new TWOneValue
|
value => new TWOneValue
|
||||||
{
|
{
|
||||||
Item = (uint)value,
|
Item = (uint)value,
|
||||||
ItemType = ItemType.Bool
|
ItemType = ItemType.Bool
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,12 +345,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _brightness ?? (_brightness = new CapWrapper<TWFix32>(_source, CapabilityId.ICapBrightness, ValueExtensions.ConvertToFix32,
|
return _brightness ?? (_brightness = new CapWrapper<TWFix32>(_source, CapabilityId.ICapBrightness, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,12 +361,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _contrast ?? (_contrast = new CapWrapper<TWFix32>(_source, CapabilityId.ICapContrast, ValueExtensions.ConvertToFix32,
|
return _contrast ?? (_contrast = new CapWrapper<TWFix32>(_source, CapabilityId.ICapContrast, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,12 +398,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _exposureTime ?? (_exposureTime = new CapWrapper<TWFix32>(_source, CapabilityId.ICapExposureTime, ValueExtensions.ConvertToFix32,
|
return _exposureTime ?? (_exposureTime = new CapWrapper<TWFix32>(_source, CapabilityId.ICapExposureTime, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,12 +435,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _gamma ?? (_gamma = new CapWrapper<TWFix32>(_source, CapabilityId.ICapGamma, ValueExtensions.ConvertToFix32,
|
return _gamma ?? (_gamma = new CapWrapper<TWFix32>(_source, CapabilityId.ICapGamma, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,12 +467,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _highlight ?? (_highlight = new CapWrapper<TWFix32>(_source, CapabilityId.ICapHighlight, ValueExtensions.ConvertToFix32,
|
return _highlight ?? (_highlight = new CapWrapper<TWFix32>(_source, CapabilityId.ICapHighlight, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,12 +600,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _shadow ?? (_shadow = new CapWrapper<TWFix32>(_source, CapabilityId.ICapShadow, ValueExtensions.ConvertToFix32,
|
return _shadow ?? (_shadow = new CapWrapper<TWFix32>(_source, CapabilityId.ICapShadow, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -701,12 +671,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _xResolution ?? (_xResolution = new CapWrapper<TWFix32>(_source, CapabilityId.ICapXResolution, ValueExtensions.ConvertToFix32,
|
return _xResolution ?? (_xResolution = new CapWrapper<TWFix32>(_source, CapabilityId.ICapXResolution, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,12 +688,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _yResolution ?? (_yResolution = new CapWrapper<TWFix32>(_source, CapabilityId.ICapYResolution, ValueExtensions.ConvertToFix32,
|
return _yResolution ?? (_yResolution = new CapWrapper<TWFix32>(_source, CapabilityId.ICapYResolution, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,12 +851,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _rotation ?? (_rotation = new CapWrapper<TWFix32>(_source, CapabilityId.ICapRotation, ValueExtensions.ConvertToFix32,
|
return _rotation ?? (_rotation = new CapWrapper<TWFix32>(_source, CapabilityId.ICapRotation, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -933,12 +888,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _threshold ?? (_threshold = new CapWrapper<TWFix32>(_source, CapabilityId.ICapThreshold, ValueExtensions.ConvertToFix32,
|
return _threshold ?? (_threshold = new CapWrapper<TWFix32>(_source, CapabilityId.ICapThreshold, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -954,12 +904,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _xscaling ?? (_xscaling = new CapWrapper<TWFix32>(_source, CapabilityId.ICapXScaling, ValueExtensions.ConvertToFix32,
|
return _xscaling ?? (_xscaling = new CapWrapper<TWFix32>(_source, CapabilityId.ICapXScaling, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -975,12 +920,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _yscaling ?? (_yscaling = new CapWrapper<TWFix32>(_source, CapabilityId.ICapYScaling, ValueExtensions.ConvertToFix32,
|
return _yscaling ?? (_yscaling = new CapWrapper<TWFix32>(_source, CapabilityId.ICapYScaling, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1932,12 +1872,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _mergeHeight ?? (_mergeHeight = new CapWrapper<TWFix32>(_source, CapabilityId.ICapImageMergeHeightThreshold, ValueExtensions.ConvertToFix32,
|
return _mergeHeight ?? (_mergeHeight = new CapWrapper<TWFix32>(_source, CapabilityId.ICapImageMergeHeightThreshold, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3250,12 +3185,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _dblFeedLength ?? (_dblFeedLength = new CapWrapper<TWFix32>(_source, CapabilityId.CapDoubleFeedDetectionLength, ValueExtensions.ConvertToFix32,
|
return _dblFeedLength ?? (_dblFeedLength = new CapWrapper<TWFix32>(_source, CapabilityId.CapDoubleFeedDetectionLength, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3355,12 +3285,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _printVOffset ?? (_printVOffset = new CapWrapper<TWFix32>(_source, CapabilityId.CapPrinterVerticalOffset, ValueExtensions.ConvertToFix32,
|
return _printVOffset ?? (_printVOffset = new CapWrapper<TWFix32>(_source, CapabilityId.CapPrinterVerticalOffset, ValueExtensions.ConvertToFix32, value => value.ToOneValue()));
|
||||||
value => new TWOneValue
|
|
||||||
{
|
|
||||||
Item = (uint)value,// ((uint)dpi) << 16;
|
|
||||||
ItemType = ItemType.Fix32
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,33 @@ namespace NTwain.Data
|
|||||||
return ToFloat().ToString(CultureInfo.InvariantCulture);
|
return ToFloat().ToString(CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts this to <see cref="TWOneValue"/> for capability set methods.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public TWOneValue ToOneValue()
|
||||||
|
{
|
||||||
|
// copy struct parts as-is.
|
||||||
|
// probably has a faster way but can't think now
|
||||||
|
|
||||||
|
byte[] array = new byte[4];
|
||||||
|
var part = BitConverter.GetBytes(Whole);
|
||||||
|
Buffer.BlockCopy(part, 0, array, 0, 2);
|
||||||
|
|
||||||
|
part = BitConverter.GetBytes(Fraction);
|
||||||
|
Buffer.BlockCopy(part, 0, array, 2, 2);
|
||||||
|
|
||||||
|
var converted = BitConverter.ToUInt32(array, 0);
|
||||||
|
|
||||||
|
return new TWOneValue
|
||||||
|
{
|
||||||
|
ItemType = ItemType.Fix32,
|
||||||
|
Item = converted
|
||||||
|
// old wrong conversion
|
||||||
|
// (uint)this,// ((uint)dpi) << 16;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#region equals
|
#region equals
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -16,7 +16,7 @@ namespace NTwain.Data
|
|||||||
/// <typeparam name="TEnum">The type of the enum.</typeparam>
|
/// <typeparam name="TEnum">The type of the enum.</typeparam>
|
||||||
/// <param name="list">The list.</param>
|
/// <param name="list">The list.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IList<TEnum> CastToEnum<TEnum>(this IEnumerable<object> list) where TEnum : struct,IConvertible
|
public static IList<TEnum> CastToEnum<TEnum>(this IEnumerable<object> list) where TEnum : struct, IConvertible
|
||||||
{
|
{
|
||||||
return list.CastToEnum<TEnum>(true);
|
return list.CastToEnum<TEnum>(true);
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ namespace NTwain.Data
|
|||||||
/// <param name="list">The list.</param>
|
/// <param name="list">The list.</param>
|
||||||
/// <param name="tryUpperWord">set to <c>true</c> for working with bad values.</param>
|
/// <param name="tryUpperWord">set to <c>true</c> for working with bad values.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IList<TEnum> CastToEnum<TEnum>(this IEnumerable<object> list, bool tryUpperWord) where TEnum : struct,IConvertible
|
public static IList<TEnum> CastToEnum<TEnum>(this IEnumerable<object> list, bool tryUpperWord) where TEnum : struct, IConvertible
|
||||||
{
|
{
|
||||||
return list.Select(o => o.ConvertToEnum<TEnum>(tryUpperWord)).ToList();
|
return list.Select(o => o.ConvertToEnum<TEnum>(tryUpperWord)).ToList();
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ namespace NTwain.Data
|
|||||||
/// <typeparam name="TEnum">The type of the enum.</typeparam>
|
/// <typeparam name="TEnum">The type of the enum.</typeparam>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TEnum ConvertToEnum<TEnum>(this object value) where TEnum : struct,IConvertible
|
public static TEnum ConvertToEnum<TEnum>(this object value) where TEnum : struct, IConvertible
|
||||||
{
|
{
|
||||||
return ConvertToEnum<TEnum>(value, true);
|
return ConvertToEnum<TEnum>(value, true);
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ namespace NTwain.Data
|
|||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
/// <param name="tryUpperWord">if set to <c>true</c> [try upper word].</param>
|
/// <param name="tryUpperWord">if set to <c>true</c> [try upper word].</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TEnum ConvertToEnum<TEnum>(this object value, bool tryUpperWord) where TEnum : struct,IConvertible
|
public static TEnum ConvertToEnum<TEnum>(this object value, bool tryUpperWord) where TEnum : struct, IConvertible
|
||||||
{
|
{
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
@ -59,7 +59,7 @@ namespace NTwain.Data
|
|||||||
if (returnType.IsEnum)
|
if (returnType.IsEnum)
|
||||||
{
|
{
|
||||||
var rawType = Enum.GetUnderlyingType(returnType);
|
var rawType = Enum.GetUnderlyingType(returnType);
|
||||||
|
|
||||||
if (tryUpperWord)
|
if (tryUpperWord)
|
||||||
{
|
{
|
||||||
// small routine to work with bad sources that may put
|
// small routine to work with bad sources that may put
|
||||||
@ -76,7 +76,7 @@ namespace NTwain.Data
|
|||||||
}
|
}
|
||||||
// old method:
|
// old method:
|
||||||
// return (TEnum)Enum.ToObject(returnType, value);
|
// return (TEnum)Enum.ToObject(returnType, value);
|
||||||
|
|
||||||
// new method:
|
// new method:
|
||||||
// try to convert to enum's underlying type first then cast to the enum
|
// try to convert to enum's underlying type first then cast to the enum
|
||||||
return (TEnum)Convert.ChangeType(value, rawType, CultureInfo.InvariantCulture);
|
return (TEnum)Convert.ChangeType(value, rawType, CultureInfo.InvariantCulture);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
[assembly: AssemblyCopyright("Copyright \x00a9 Yin-Chun Wang 2012-2016")]
|
[assembly: AssemblyCopyright("Copyright \x00a9 Yin-Chun Wang 2012-2017")]
|
||||||
[assembly: AssemblyCompany("Yin-Chun Wang")]
|
[assembly: AssemblyCompany("Yin-Chun Wang")]
|
||||||
|
|
||||||
[assembly: AssemblyVersion(NTwain.VersionInfo.Release)]
|
[assembly: AssemblyVersion(NTwain.VersionInfo.Release)]
|
||||||
@ -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.4.0"; // change this for each nuget release
|
public const string Build = "3.4.1"; // change this for each nuget release
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user