mirror of
https://github.com/soukoku/ntwain.git
synced 2025-09-18 17:47:57 +08:00
Added custom cap value container types.
This commit is contained in:
122
src/NTwain/Data/Containers.cs
Normal file
122
src/NTwain/Data/Containers.cs
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
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>
|
||||||
|
/// The value.
|
||||||
|
/// </summary>
|
||||||
|
public T Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stores a group of associated individual values for a capability.
|
||||||
|
/// The values need have no relationship to one another aside from
|
||||||
|
/// being used to describe the same "value" of the capability
|
||||||
|
/// </summary>
|
||||||
|
public struct ArrayValue<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The type of items in the array.
|
||||||
|
/// </summary>
|
||||||
|
public ItemType Type;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Array of values.
|
||||||
|
/// </summary>
|
||||||
|
public T[] ItemList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An enumeration stores a list of individual values, with one of the items designated as the current
|
||||||
|
/// value. There is no required order to the values in the list.
|
||||||
|
/// </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>
|
||||||
|
public ItemType Type;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The item number, or index (zero-based) into
|
||||||
|
/// <see cref="ItemList"/>, of the "current"
|
||||||
|
/// value for the capability.
|
||||||
|
/// </summary>
|
||||||
|
public int CurrentIndex;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The item number, or index (zero-based) into
|
||||||
|
/// <see cref="ItemList"/>, of the "power-on"
|
||||||
|
/// value for the capability.
|
||||||
|
/// </summary>
|
||||||
|
public int DefaultIndex;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The enumerated value list.
|
||||||
|
/// </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;
|
||||||
|
}
|
||||||
|
}
|
@@ -74,9 +74,9 @@ namespace NTwain.Data
|
|||||||
partial class TW_ARRAY
|
partial class TW_ARRAY
|
||||||
{
|
{
|
||||||
// TODO: _itemType in mac is TW_UINT32?
|
// TODO: _itemType in mac is TW_UINT32?
|
||||||
TW_UINT16 _itemType;
|
public TW_UINT16 ItemType;
|
||||||
TW_UINT32 _numItems;
|
public TW_UINT32 NumItems;
|
||||||
object[] _itemList;
|
public IntPtr ItemList;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 2),
|
[StructLayout(LayoutKind.Sequential, Pack = 2),
|
||||||
@@ -181,12 +181,12 @@ namespace NTwain.Data
|
|||||||
partial class TW_ENUMERATION
|
partial class TW_ENUMERATION
|
||||||
{
|
{
|
||||||
// TODO: _itemType in mac is TW_UINT32?
|
// TODO: _itemType in mac is TW_UINT32?
|
||||||
TW_UINT16 _itemType;
|
public TW_UINT16 ItemType;
|
||||||
// TODO: these are UInt64 in linux 64 bit?
|
// TODO: these are UInt64 in linux 64 bit?
|
||||||
TW_UINT32 _numItems;
|
public TW_UINT32 NumItems;
|
||||||
TW_UINT32 _currentIndex;
|
public TW_UINT32 CurrentIndex;
|
||||||
TW_UINT32 _defaultIndex;
|
public TW_UINT32 DefaultIndex;
|
||||||
object[] _itemList;
|
public IntPtr ItemList;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
@@ -431,8 +431,8 @@ namespace NTwain.Data
|
|||||||
partial class TW_ONEVALUE
|
partial class TW_ONEVALUE
|
||||||
{
|
{
|
||||||
// TODO: mac is different?
|
// TODO: mac is different?
|
||||||
TW_UINT16 _itemType;
|
public TW_UINT16 ItemType;
|
||||||
TW_UINT32 _item;
|
public TW_UINT32 Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
@@ -468,12 +468,12 @@ namespace NTwain.Data
|
|||||||
partial class TW_RANGE
|
partial class TW_RANGE
|
||||||
{
|
{
|
||||||
// TODO: mac & linux are different?
|
// TODO: mac & linux are different?
|
||||||
TW_UINT16 _itemType;
|
public TW_UINT16 ItemType;
|
||||||
TW_UINT32 _minValue;
|
public TW_UINT32 MinValue;
|
||||||
TW_UINT32 _maxValue;
|
public TW_UINT32 MaxValue;
|
||||||
TW_UINT32 _stepSize;
|
public TW_UINT32 StepSize;
|
||||||
TW_UINT32 _defaultValue;
|
public TW_UINT32 DefaultValue;
|
||||||
TW_UINT32 _currentValue;
|
public TW_UINT32 CurrentValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
//[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
|
@@ -526,39 +526,6 @@ namespace NTwain.Data
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// <summary>
|
|
||||||
// /// Stores a group of associated individual values for a capability.
|
|
||||||
// /// The values need have no relationship to one another aside from
|
|
||||||
// /// being used to describe the same "value" of the capability
|
|
||||||
// /// </summary>
|
|
||||||
// public partial class TW_ARRAY
|
|
||||||
// {
|
|
||||||
// /// <summary>
|
|
||||||
// /// The type of items in the array. All items in the array have the same size.
|
|
||||||
// /// </summary>
|
|
||||||
// public ItemType ItemType { get { return (ItemType)_itemType; } set { _itemType = (ushort)value; } }
|
|
||||||
|
|
||||||
// ///// <summary>
|
|
||||||
// ///// How many items are in the array.
|
|
||||||
// ///// </summary>
|
|
||||||
// //public int Count { get { return (int)_numItems; } set { _numItems = (uint)value; } }
|
|
||||||
|
|
||||||
// /// <summary>
|
|
||||||
// /// Array of ItemType values starts here.
|
|
||||||
// /// </summary>
|
|
||||||
|
|
||||||
// public object[] ItemList
|
|
||||||
// {
|
|
||||||
// get { return _itemList; }
|
|
||||||
// set
|
|
||||||
// {
|
|
||||||
// _itemList = value;
|
|
||||||
// if (value != null) { _numItems = (uint)value.Length; }
|
|
||||||
// else { _numItems = 0; }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to get audio info.
|
/// Used to get audio info.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1120,52 +1087,6 @@ namespace NTwain.Data
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// <summary>
|
|
||||||
// /// An enumeration stores a list of individual values, with one of the items designated as the current
|
|
||||||
// /// value. There is no required order to the values in the list.
|
|
||||||
// /// </summary>
|
|
||||||
// public partial class TW_ENUMERATION
|
|
||||||
// {
|
|
||||||
// /// <summary>
|
|
||||||
// /// The type of items in the enumerated list. All items in the array have the same size.
|
|
||||||
// /// </summary>
|
|
||||||
// public ItemType ItemType { get { return (ItemType)_itemType; } set { _itemType = (ushort)value; } }
|
|
||||||
// ///// <summary>
|
|
||||||
// ///// How many items are in the enumeration.
|
|
||||||
// ///// </summary>
|
|
||||||
// //public int Count { get { return (int)_numItems; } set { _numItems = (uint)value; } }
|
|
||||||
// /// <summary>
|
|
||||||
// /// The item number, or index (zero-based) into <see cref="ItemList"/>, of the "current"
|
|
||||||
// /// value for the capability.
|
|
||||||
// /// </summary>
|
|
||||||
// public int CurrentIndex { get { return (int)_currentIndex; } set { _currentIndex = (uint)value; } }
|
|
||||||
// /// <summary>
|
|
||||||
// /// The item number, or index (zero-based) into <see cref="ItemList"/>, of the "power-on"
|
|
||||||
// /// value for the capability.
|
|
||||||
// /// </summary>
|
|
||||||
// public int DefaultIndex { get { return (int)_defaultIndex; } set { _defaultIndex = (uint)value; } }
|
|
||||||
// /// <summary>
|
|
||||||
// /// The enumerated list: one value resides within each array element.
|
|
||||||
// /// </summary>
|
|
||||||
|
|
||||||
// public object[] ItemList
|
|
||||||
// {
|
|
||||||
// get { return _itemList; }
|
|
||||||
// set
|
|
||||||
// {
|
|
||||||
// _itemList = value;
|
|
||||||
// if (value != null) { _numItems = (uint)value.Length; }
|
|
||||||
// else { _numItems = 0; }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /// <summary>
|
|
||||||
// /// Gets the byte offset of the item list from a Ptr to the first item.
|
|
||||||
// /// </summary>
|
|
||||||
// internal const int ItemOffset = 14;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// /// <summary>
|
// /// <summary>
|
||||||
// /// This structure is used to pass specific information between the data source and the application
|
// /// This structure is used to pass specific information between the data source and the application
|
||||||
// /// through <see cref="TW_EXTIMAGEINFO"/>.
|
// /// through <see cref="TW_EXTIMAGEINFO"/>.
|
||||||
@@ -1954,21 +1875,6 @@ namespace NTwain.Data
|
|||||||
public uint SheetCount => _sheetCount;
|
public uint SheetCount => _sheetCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// <summary>
|
|
||||||
// /// Container for one value.
|
|
||||||
// /// </summary>
|
|
||||||
// public partial class TW_ONEVALUE
|
|
||||||
// {
|
|
||||||
// /// <summary>
|
|
||||||
// /// The type of the item.
|
|
||||||
// /// </summary>
|
|
||||||
// public ItemType ItemType { get { return (ItemType)_itemType; } set { _itemType = (ushort)value; } }
|
|
||||||
// /// <summary>
|
|
||||||
// /// The value.
|
|
||||||
// /// </summary>
|
|
||||||
// public uint Item { get { return _item; } set { _item = value; } }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This structure holds the color palette information for buffered memory transfers of type
|
/// This structure holds the color palette information for buffered memory transfers of type
|
||||||
@@ -2053,41 +1959,6 @@ namespace NTwain.Data
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// /// <summary>
|
|
||||||
// /// Container for a range of values.
|
|
||||||
// /// </summary>
|
|
||||||
// public partial class 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
|
||||||
// ///// color data. Use this structure for RGB data whose bit depth is up to, and including, 8-bits.
|
// ///// color data. Use this structure for RGB data whose bit depth is up to, and including, 8-bits.
|
||||||
|
@@ -297,7 +297,7 @@ namespace NTwain
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return State.ToString()
|
return State.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user