mirror of
https://github.com/soukoku/ntwain.git
synced 2025-09-19 10:08:00 +08:00
Added TW_RANGE to cap writer.
This commit is contained in:
@@ -112,16 +112,20 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
config.MemoryManager.Unlock(container.ItemList);
|
config.MemoryManager.Unlock(container.ItemList);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IntPtr baseAddr = config.MemoryManager.Lock(twCap.hContainer);
|
baseAddr = config.MemoryManager.Lock(twCap.hContainer);
|
||||||
Marshal.StructureToPtr(container, baseAddr, false);
|
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;
|
return twCap;
|
||||||
@@ -169,12 +173,46 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
config.MemoryManager.Unlock(container.ItemList);
|
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
|
try
|
||||||
{
|
{
|
||||||
IntPtr baseAddr = config.MemoryManager.Lock(twCap.hContainer);
|
IntPtr baseAddr = config.MemoryManager.Lock(twCap.hContainer);
|
||||||
Marshal.StructureToPtr(container, baseAddr, false);
|
Marshal.StructureToPtr(value, baseAddr, false);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -183,39 +221,5 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
return twCap;
|
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
|
// use custom containers for twain container types to not have to worry about memory mgmt
|
||||||
// after giving it to consumers
|
// after giving it to consumers
|
||||||
|
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/// Container for one value.
|
///// Container for one value.
|
||||||
/// </summary>
|
///// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
///// <typeparam name="T"></typeparam>
|
||||||
public struct OneValue<T>
|
//public struct OneValue<T>
|
||||||
{
|
//{
|
||||||
/// <summary>
|
// /// <summary>
|
||||||
/// The type of the item.
|
// /// The type of the item.
|
||||||
/// </summary>
|
// /// </summary>
|
||||||
public ItemType Type;
|
// public ItemType Type;
|
||||||
|
|
||||||
/// <summary>
|
// /// <summary>
|
||||||
/// The value.
|
// /// The value.
|
||||||
/// </summary>
|
// /// </summary>
|
||||||
public T Value;
|
// public T Value;
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stores a group of associated individual values for a capability.
|
/// Stores a group of associated individual values for a capability.
|
||||||
@@ -50,11 +50,6 @@ namespace NTwain.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public struct EnumValue<T>
|
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>
|
/// <summary>
|
||||||
/// The type of items in the enumerated list.
|
/// The type of items in the enumerated list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -79,44 +74,5 @@ namespace NTwain.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public T[] ItemList;
|
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)]
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
partial class TW_RANGE
|
partial struct TW_RANGE
|
||||||
{
|
{
|
||||||
// TODO: mac & linux are different?
|
// TODO: mac & linux are different?
|
||||||
public TW_UINT16 ItemType;
|
TW_UINT16 _itemType;
|
||||||
public TW_UINT32 MinValue;
|
TW_UINT32 _minValue;
|
||||||
public TW_UINT32 MaxValue;
|
TW_UINT32 _maxValue;
|
||||||
public TW_UINT32 StepSize;
|
TW_UINT32 _stepSize;
|
||||||
public TW_UINT32 DefaultValue;
|
TW_UINT32 _defaultValue;
|
||||||
public TW_UINT32 CurrentValue;
|
TW_UINT32 _currentValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
//[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>
|
/// <summary>
|
||||||
/// Returns a <see cref="System.String"/> that represents this instance.
|
/// Returns a <see cref="System.String"/> that represents this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1928,7 +1945,42 @@ namespace NTwain.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public EndXferJob EndOfJob { get { return (EndXferJob)_eOJ; } }
|
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>
|
// ///// <summary>
|
||||||
// ///// This structure is used by the application to specify a set of mapping values to be applied to RGB
|
// ///// This structure is used by the application to specify a set of mapping values to be applied to RGB
|
||||||
|
Reference in New Issue
Block a user