mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Added TW_RANGE to cap writer.
This commit is contained in:
parent
122a3354c4
commit
5e4fd5f7c8
@ -112,16 +112,20 @@ namespace NTwain
|
||||
{
|
||||
config.MemoryManager.Unlock(container.ItemList);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr baseAddr = config.MemoryManager.Lock(twCap.hContainer);
|
||||
Marshal.StructureToPtr(container, baseAddr, false);
|
||||
try
|
||||
{
|
||||
baseAddr = config.MemoryManager.Lock(twCap.hContainer);
|
||||
Marshal.StructureToPtr(container, baseAddr, false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
config.MemoryManager.Unlock(twCap.hContainer);
|
||||
}
|
||||
}
|
||||
finally
|
||||
else
|
||||
{
|
||||
config.MemoryManager.Unlock(twCap.hContainer);
|
||||
config.MemoryManager.Free(twCap.hContainer);
|
||||
}
|
||||
}
|
||||
return twCap;
|
||||
@ -169,12 +173,46 @@ namespace NTwain
|
||||
{
|
||||
config.MemoryManager.Unlock(container.ItemList);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
baseAddr = config.MemoryManager.Lock(twCap.hContainer);
|
||||
Marshal.StructureToPtr(container, baseAddr, false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
config.MemoryManager.Unlock(twCap.hContainer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
config.MemoryManager.Free(twCap.hContainer);
|
||||
}
|
||||
}
|
||||
return twCap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a <see cref="TW_CAPABILITY"/> for use in capability negotiation
|
||||
/// using TWAIN's range value.
|
||||
/// </summary>
|
||||
/// <param name="cap"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public TW_CAPABILITY Generate(CapabilityId cap, TW_RANGE value)
|
||||
{
|
||||
var twCap = new TW_CAPABILITY
|
||||
{
|
||||
Capability = cap,
|
||||
ContainerType = ContainerType.Range,
|
||||
hContainer = config.MemoryManager.Allocate((uint)Marshal.SizeOf(typeof(TW_RANGE)))
|
||||
};
|
||||
if (twCap.hContainer != IntPtr.Zero)
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr baseAddr = config.MemoryManager.Lock(twCap.hContainer);
|
||||
Marshal.StructureToPtr(container, baseAddr, false);
|
||||
Marshal.StructureToPtr(value, baseAddr, false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -183,39 +221,5 @@ namespace NTwain
|
||||
}
|
||||
return twCap;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Generates a <see cref="TW_CAPABILITY"/> for use in capability negotiation
|
||||
///// using TWAIN's range value.
|
||||
///// </summary>
|
||||
///// <param name="cap"></param>
|
||||
///// <param name="value"></param>
|
||||
///// <returns></returns>
|
||||
//public TW_CAPABILITY Generate(CapabilityId cap, RangeValue value)
|
||||
//{
|
||||
// var twCap = new TW_CAPABILITY
|
||||
// {
|
||||
// Capability = cap,
|
||||
// ContainerType = ContainerType.Range
|
||||
// };
|
||||
|
||||
// return twCap;
|
||||
//}
|
||||
|
||||
|
||||
//void SetRangeValue(TW_RANGE value, IMemoryManager memoryManager)
|
||||
//{
|
||||
// if (value == null) { throw new ArgumentNullException("value"); }
|
||||
// ContainerType = ContainerType.Range;
|
||||
|
||||
// // since range value can only house UInt32 we will not allow type size > 4
|
||||
// if (TypeExtensions.GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.BadValueType, "TW_RANGE")); }
|
||||
|
||||
// _hContainer = memoryManager.Allocate((uint)Marshal.SizeOf(value));
|
||||
// if (_hContainer != IntPtr.Zero)
|
||||
// {
|
||||
// Marshal.StructureToPtr(value, _hContainer, false);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -9,22 +9,22 @@ namespace NTwain.Data
|
||||
// use custom containers for twain container types to not have to worry about memory mgmt
|
||||
// after giving it to consumers
|
||||
|
||||
/// <summary>
|
||||
/// Container for one value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public struct OneValue<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of the item.
|
||||
/// </summary>
|
||||
public ItemType Type;
|
||||
///// <summary>
|
||||
///// Container for one value.
|
||||
///// </summary>
|
||||
///// <typeparam name="T"></typeparam>
|
||||
//public struct OneValue<T>
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// The type of the item.
|
||||
// /// </summary>
|
||||
// public ItemType Type;
|
||||
|
||||
/// <summary>
|
||||
/// The value.
|
||||
/// </summary>
|
||||
public T Value;
|
||||
}
|
||||
// /// <summary>
|
||||
// /// The value.
|
||||
// /// </summary>
|
||||
// public T Value;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Stores a group of associated individual values for a capability.
|
||||
@ -50,11 +50,6 @@ namespace NTwain.Data
|
||||
/// </summary>
|
||||
public struct EnumValue<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the byte offset of the item list from a Ptr to the first item.
|
||||
/// </summary>
|
||||
internal const int ValuesOffset = 14;
|
||||
|
||||
/// <summary>
|
||||
/// The type of items in the enumerated list.
|
||||
/// </summary>
|
||||
@ -79,44 +74,5 @@ namespace NTwain.Data
|
||||
/// </summary>
|
||||
public T[] ItemList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Container for a range of values.
|
||||
/// </summary>
|
||||
public struct RangeValue
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of items in the container.
|
||||
/// </summary>
|
||||
public ItemType Type;
|
||||
|
||||
/// <summary>
|
||||
/// The least positive/most negative value of the range.
|
||||
/// </summary>
|
||||
public int Min;
|
||||
|
||||
/// <summary>
|
||||
/// The most positive/least negative value of the range.
|
||||
/// </summary>
|
||||
public int Max;
|
||||
|
||||
/// <summary>
|
||||
/// The delta between two adjacent values of the range.
|
||||
/// e.g. Item2 - Item1 = StepSize;
|
||||
/// </summary>
|
||||
public int StepSize;
|
||||
|
||||
/// <summary>
|
||||
/// The device’s "power-on" value for the capability. If the application is
|
||||
/// performing a MSG_SET operation and isn’t sure what the default
|
||||
/// value is, set this field to <see cref="TwainConst.DontCare32"/>.
|
||||
/// </summary>
|
||||
public int DefaultValue;
|
||||
|
||||
/// <summary>
|
||||
/// The value to which the device (or its user interface) is currently set to
|
||||
/// for the capability.
|
||||
/// </summary>
|
||||
public int CurrentValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -465,15 +465,15 @@ namespace NTwain.Data
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
partial class TW_RANGE
|
||||
partial struct TW_RANGE
|
||||
{
|
||||
// TODO: mac & linux are different?
|
||||
public TW_UINT16 ItemType;
|
||||
public TW_UINT32 MinValue;
|
||||
public TW_UINT32 MaxValue;
|
||||
public TW_UINT32 StepSize;
|
||||
public TW_UINT32 DefaultValue;
|
||||
public TW_UINT32 CurrentValue;
|
||||
TW_UINT16 _itemType;
|
||||
TW_UINT32 _minValue;
|
||||
TW_UINT32 _maxValue;
|
||||
TW_UINT32 _stepSize;
|
||||
TW_UINT32 _defaultValue;
|
||||
TW_UINT32 _currentValue;
|
||||
}
|
||||
|
||||
//[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
|
@ -48,6 +48,23 @@ namespace NTwain.Data
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts this value to a value for communicating with twain data source.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public uint ToTransferValue()
|
||||
{
|
||||
// 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);
|
||||
|
||||
return BitConverter.ToUInt32(array, 0);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a <see cref="System.String"/> that represents this instance.
|
||||
/// </summary>
|
||||
@ -1928,7 +1945,42 @@ namespace NTwain.Data
|
||||
/// </summary>
|
||||
public EndXferJob EndOfJob { get { return (EndXferJob)_eOJ; } }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Container for a range of values.
|
||||
/// </summary>
|
||||
public partial struct TW_RANGE
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of items in the list.
|
||||
/// </summary>
|
||||
public ItemType ItemType { get { return (ItemType)_itemType; } set { _itemType = (ushort)value; } }
|
||||
/// <summary>
|
||||
/// The least positive/most negative value of the range.
|
||||
/// </summary>
|
||||
public uint MinValue { get { return _minValue; } set { _minValue = value; } }
|
||||
/// <summary>
|
||||
/// The most positive/least negative value of the range.
|
||||
/// </summary>
|
||||
public uint MaxValue { get { return _maxValue; } set { _maxValue = value; } }
|
||||
/// <summary>
|
||||
/// The delta between two adjacent values of the range.
|
||||
/// e.g. Item2 - Item1 = StepSize;
|
||||
/// </summary>
|
||||
public uint StepSize { get { return _stepSize; } set { _stepSize = value; } }
|
||||
/// <summary>
|
||||
/// The device’s "power-on" value for the capability. If the application is
|
||||
/// performing a MSG_SET operation and isn’t sure what the default
|
||||
/// value is, set this field to <see cref="TwainConst.DontCare32"/>.
|
||||
/// </summary>
|
||||
public uint DefaultValue { get { return _defaultValue; } set { _defaultValue = value; } }
|
||||
/// <summary>
|
||||
/// The value to which the device (or its user interface) is currently set to
|
||||
/// for the capability.
|
||||
/// </summary>
|
||||
public uint CurrentValue { get { return _currentValue; } set { _currentValue = value; } }
|
||||
}
|
||||
|
||||
// ///// <summary>
|
||||
// ///// This structure is used by the application to specify a set of mapping values to be applied to RGB
|
||||
|
Loading…
Reference in New Issue
Block a user