using NTwain.Internals;
using NTwain.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
namespace NTwain.Data
{
//// This file contains custom logic added to the twain types.
//// Separating the raw field definitions out makes finding all the
//// custom code logic easier. Mostly this just makes the fields
//// into .net friendly properties.
//// potentially unit tests for the twain types only need to target
//// code in this file since everything else is just interop and
//// field definitions.
//// most of the doc text are copied from the twain spec pdf.
///
/// Stores a fixed point number. This can be implicitly converted
/// to a float in dotnet.
///
public partial struct TWFix32 : IEquatable, IConvertible
{
// the conversion logic is found in the spec.
float ToFloat()
{
return (float)_whole + _frac / 65536f;
}
TWFix32(float value)
{
//int temp = (int)(value * 65536.0 + 0.5);
//_whole = (short)(temp >> 16);
//_frac = (ushort)(temp & 0x0000ffff);
// different version from twain faq
bool sign = value < 0;
int temp = (int)(value * 65536.0 + (sign ? (-0.5) : 0.5));
_whole = (short)(temp >> 16);
_frac = (ushort)(temp & 0x0000ffff);
}
///
/// The Whole part of the floating point number. This number is signed.
///
public short Whole { get { return _whole; } set { _whole = value; } }
///
/// The Fractional part of the floating point number. This number is unsigned.
///
public ushort Fraction { get { return _frac; } set { _frac = value; } }
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
return ToFloat().ToString(CultureInfo.InvariantCulture);
}
#region equals
///
/// Determines whether the specified is equal to this instance.
///
/// The to compare with this instance.
///
/// true if the specified is equal to this instance; otherwise, false.
///
public override bool Equals(object obj)
{
if (!(obj is TWFix32))
return false;
return Equals((TWFix32)obj);
}
///
/// Indicates whether the current object is equal to another object of the same type.
///
/// An object to compare with this object.
///
public bool Equals(TWFix32 other)
{
return _whole == other._whole && _frac == other._frac;
}
///
/// Returns a hash code for this instance.
///
///
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
public override int GetHashCode()
{
return _whole ^ _frac;
}
#endregion
#region static stuff
///
/// Performs an implicit conversion from to .
///
/// The value.
/// The result of the conversion.
public static implicit operator float(TWFix32 value)
{
return value.ToFloat();
}
///
/// Performs an implicit conversion from to .
///
/// The value.
/// The result of the conversion.
public static implicit operator TWFix32(float value)
{
return new TWFix32(value);
}
///
/// Performs an implicit conversion from to .
///
/// The value.
/// The result of the conversion.
public static implicit operator double(TWFix32 value)
{
return value.ToFloat();
}
///
/// Performs an implicit conversion from to .
///
/// The value.
/// The result of the conversion.
public static implicit operator TWFix32(double value)
{
return new TWFix32((float)value);
}
///
/// Implements the operator ==.
///
/// The value1.
/// The value2.
/// The result of the operator.
public static bool operator ==(TWFix32 value1, TWFix32 value2)
{
return value1.Equals(value2);
}
///
/// Implements the operator !=.
///
/// The value1.
/// The value2.
/// The result of the operator.
public static bool operator !=(TWFix32 value1, TWFix32 value2)
{
return !value1.Equals(value2);
}
#endregion
#region IConvertable
TypeCode IConvertible.GetTypeCode()
{
return TypeCode.Single;
}
bool IConvertible.ToBoolean(IFormatProvider provider)
{
return this != 0;
}
byte IConvertible.ToByte(IFormatProvider provider)
{
return Convert.ToByte((float)this);
}
char IConvertible.ToChar(IFormatProvider provider)
{
return Convert.ToChar((float)this);
}
DateTime IConvertible.ToDateTime(IFormatProvider provider)
{
return Convert.ToDateTime((float)this);
}
decimal IConvertible.ToDecimal(IFormatProvider provider)
{
return Convert.ToDecimal((float)this);
}
double IConvertible.ToDouble(IFormatProvider provider)
{
return Convert.ToDouble((float)this);
}
short IConvertible.ToInt16(IFormatProvider provider)
{
return Convert.ToInt16((float)this);
}
int IConvertible.ToInt32(IFormatProvider provider)
{
return Convert.ToInt32((float)this);
}
long IConvertible.ToInt64(IFormatProvider provider)
{
return Convert.ToInt64((float)this);
}
sbyte IConvertible.ToSByte(IFormatProvider provider)
{
return Convert.ToSByte((float)this);
}
float IConvertible.ToSingle(IFormatProvider provider)
{
return Convert.ToSingle((float)this);
}
string IConvertible.ToString(IFormatProvider provider)
{
return this.ToString();
}
object IConvertible.ToType(Type conversionType, IFormatProvider provider)
{
return Convert.ChangeType((float)this, conversionType, CultureInfo.InvariantCulture);
}
ushort IConvertible.ToUInt16(IFormatProvider provider)
{
return Convert.ToUInt16((float)this);
}
uint IConvertible.ToUInt32(IFormatProvider provider)
{
return Convert.ToUInt32((float)this);
}
ulong IConvertible.ToUInt64(IFormatProvider provider)
{
return Convert.ToUInt64((float)this);
}
#endregion
}
///
/// Embedded in the structure.
/// Defines a frame rectangle in ICapUnits coordinates.
///
public partial struct TWFrame : IEquatable
{
#region properties
///
/// Value of the left-most edge of the rectangle.
///
public float Left { get { return _left; } set { _left = value; } }
///
/// Value of the top-most edge of the rectangle.
///
public float Top { get { return _top; } set { _top = value; } }
///
/// Value of the right-most edge of the rectangle.
///
public float Right { get { return _right; } set { _right = value; } }
///
/// Value of the bottom-most edge of the rectangle.
///
public float Bottom { get { return _bottom; } set { _bottom = value; } }
#endregion
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "L={0}, T={1}, R={2}, B={3}", Left, Top, Right, Bottom);
}
#region equals
///
/// Determines whether the specified is equal to this instance.
///
/// The to compare with this instance.
///
/// true if the specified is equal to this instance; otherwise, false.
///
public override bool Equals(object obj)
{
if (!(obj is TWFrame))
return false;
return Equals((TWFrame)obj);
}
///
/// Indicates whether the current object is equal to another object of the same type.
///
/// An object to compare with this object.
///
public bool Equals(TWFrame other)
{
return _left == other._left && _top == other._top &&
_right == other._right && _bottom == other._bottom;
}
///
/// Returns a hash code for this instance.
///
///
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
public override int GetHashCode()
{
return _left.GetHashCode() ^ _top.GetHashCode() ^
_right.GetHashCode() ^ _bottom.GetHashCode();
}
#endregion
#region static stuff
///
/// Implements the operator ==.
///
/// The value1.
/// The value2.
/// The result of the operator.
public static bool operator ==(TWFrame value1, TWFrame value2)
{
return value1.Equals(value2);
}
///
/// Implements the operator !=.
///
/// The value1.
/// The value2.
/// The result of the operator.
public static bool operator !=(TWFrame value1, TWFrame value2)
{
return !value1.Equals(value2);
}
#endregion
}
///
/// Embedded in the structure that is embedded in the
/// structure. Defines the parameters used for channel-specific transformation. The transform can be
/// described either as an extended form of the gamma function or as a table look-up with linear
/// interpolation.
///
public partial struct TWDecodeFunction : IEquatable
{
#region properties
///
/// Starting input value of the extended gamma function. Defines the
/// minimum input value of channel data.
///
public float StartIn { get { return _startIn; } }//set { _startIn = value; } }
///
/// Ending input value of the extended gamma function. Defines the maximum
/// input value of channel data.
///
public float BreakIn { get { return _breakIn; } }//set { _breakIn = value; } }
///
/// The input value at which the transform switches from linear
/// transformation/interpolation to gamma transformation.
///
public float EndIn { get { return _endIn; } }//set { _endIn = value; } }
///
/// Starting output value of the extended gamma function. Defines the
/// minimum output value of channel data.
///
public float StartOut { get { return _startOut; } }//set { _startOut = value; } }
///
/// Ending output value of the extended gamma function. Defines the
/// maximum output value of channel data.
///
public float BreakOut { get { return _breakOut; } }//set { _breakOut = value; } }
///
/// The output value at which the transform switches from linear
/// transformation/interpolation to gamma transformation.
///
public float EndOut { get { return _endOut; } }//set { _endOut = value; } }
///
/// Constant value. The exponential used in the gamma function.
///
public float Gamma { get { return _gamma; } }//set { _gamma = value; } }
///
/// The number of samples in the look-up table. Includes the values of StartIn
/// and EndIn. Zero-based index (actually, number of samples - 1). If zero, use
/// extended gamma, otherwise use table look-up.
///
public float SampleCount { get { return _sampleCount; } }//set { _sampleCount = value; } }
#endregion
#region equals
///
/// Determines whether the specified is equal to this instance.
///
/// The to compare with this instance.
///
/// true if the specified is equal to this instance; otherwise, false.
///
public override bool Equals(object obj)
{
if (!(obj is TWDecodeFunction))
return false;
return Equals((TWDecodeFunction)obj);
}
///
/// Indicates whether the current object is equal to another object of the same type.
///
/// An object to compare with this object.
///
public bool Equals(TWDecodeFunction other)
{
return _startIn == other._startIn && _startOut == other._startOut &&
_breakIn == other._breakIn && _breakOut == other._breakOut &&
_endIn == other._endIn && _endOut == other._endOut &&
_gamma == other._gamma && _sampleCount == other._sampleCount;
}
///
/// Returns a hash code for this instance.
///
///
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
public override int GetHashCode()
{
return _startIn.GetHashCode() ^ _startOut.GetHashCode() ^
_breakIn.GetHashCode() ^ _breakOut.GetHashCode() ^
_endIn.GetHashCode() ^ _endOut.GetHashCode() ^
_gamma.GetHashCode() ^ _sampleCount.GetHashCode();
}
#endregion
#region static stuff
///
/// Implements the operator ==.
///
/// The value1.
/// The value2.
/// The result of the operator.
public static bool operator ==(TWDecodeFunction value1, TWDecodeFunction value2)
{
return value1.Equals(value2);
}
///
/// Implements the operator !=.
///
/// The value1.
/// The value2.
/// The result of the operator.
public static bool operator !=(TWDecodeFunction value1, TWDecodeFunction value2)
{
return !value1.Equals(value2);
}
#endregion
}
///
/// Specifies the parametrics used for either the ABC or LMN transform stages.
///
public partial struct TWTransformStage
{
///
/// Channel-specific transform parameters.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public TWDecodeFunction[] Decode { get { return _decode; } }//set { _decode = value; } }
///
/// Flattened 3x3 matrix that specifies how channels are mixed in.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public TWFix32[] Mix { get { return _mix; } }//set { _mix = value; } }
///
/// Gets the value as matrix.
///
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1814:PreferJaggedArraysOverMultidimensional", MessageId = "Body"),
System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1814:PreferJaggedArraysOverMultidimensional", MessageId = "Return")]
public TWFix32[,] GetMixMatrix()
{
// from http://stackoverflow.com/questions/3845235/convert-array-to-matrix, haven't tested it
TWFix32[,] mat = new TWFix32[3, 3];
Buffer.BlockCopy(_mix, 0, mat, 0, _mix.Length * 4);
return mat;
}
}
///
/// 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
///
public partial class TWArray
{
///
/// The type of items in the array. All items in the array have the same size.
///
public ItemType ItemType { get { return (ItemType)_itemType; } set { _itemType = (ushort)value; } }
/////
///// How many items are in the array.
/////
//public int Count { get { return (int)_numItems; } set { _numItems = (uint)value; } }
///
/// Array of ItemType values starts here.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public object[] ItemList
{
get { return _itemList; }
set
{
_itemList = value;
if (value != null) { _numItems = (uint)value.Length; }
else { _numItems = 0; }
}
}
}
///
/// Used to get audio info.
///
public partial class TWAudioInfo
{
internal TWAudioInfo() { }
///
/// Name of audio data.
///
public string Name { get { return _name; } }
}
///
/// Used in Callback mechanism for sending messages from the Source to the Application.
/// Applications version 2.2 or higher must use .
///
partial class TWCallback
{
///
/// Initializes a new instance of the class.
///
/// The callback function’s entry point.
public TWCallback(CallbackDelegate callback)
{
_callBackProc = callback;
}
/////
///// An application defined reference constant.
/////
/////
///// The reference constant.
/////
//public uint RefCon { get { return _refCon; } set { _refCon = value; } }
/////
///// Initialized to any valid DG_CONTROL / DAT_NULL message.
/////
/////
///// The message.
/////
//public short Message { get { return _message; } set { _message = value; } }
}
///
/// Used in the Callback mechanism for sending messages from the Source to the Application.
///
partial class TWCallback2
{
///
/// Initializes a new instance of the class.
///
/// The callback function’s entry point.
public TWCallback2(CallbackDelegate callback)
{
_callBackProc = callback;
}
/////
///// An application defined reference constant. It has a different size on different
///// platforms.
/////
/////
///// The reference constant.
/////
//public UIntPtr RefCon { get { return _refCon; } set { _refCon = value; } }
/////
///// Initialized to any valid DG_CONTROL / DAT_NULL message.
/////
/////
///// The message.
/////
//public short Message { get { return _message; } set { _message = value; } }
}
///
/// Used by an application either to get information about, or control the setting of a capability.
///
public sealed partial class TWCapability : IDisposable
{
#region ctors
///
/// Initializes a new instance of the class.
///
/// The capability.
public TWCapability(CapabilityId capability)
{
Capability = capability;
ContainerType = ContainerType.DoNotCare;
}
///
/// Initializes a new instance of the class.
///
/// The capability.
/// The value.
public TWCapability(CapabilityId capability, TWOneValue value)
: this(capability, value, PlatformInfo.Current.MemoryManager) { }
///
/// Initializes a new instance of the class.
///
/// The capability.
/// The value.
/// The memory manager.
public TWCapability(CapabilityId capability, TWOneValue value, IMemoryManager memoryManager)
{
Capability = capability;
SetOneValue(value, memoryManager);
}
///
/// Initializes a new instance of the class.
///
/// The capability.
/// The value.
public TWCapability(CapabilityId capability, TWEnumeration value)
: this(capability, value, PlatformInfo.Current.MemoryManager) { }
///
/// Initializes a new instance of the class.
///
/// The capability.
/// The value.
/// The memory manager.
public TWCapability(CapabilityId capability, TWEnumeration value, IMemoryManager memoryManager)
{
Capability = capability;
SetEnumValue(value, memoryManager);
}
///
/// Initializes a new instance of the class.
///
/// The capability.
/// The value.
public TWCapability(CapabilityId capability, TWRange value)
: this(capability, value, PlatformInfo.Current.MemoryManager) { }
///
/// Initializes a new instance of the class.
///
/// The capability.
/// The value.
/// The memory manager.
public TWCapability(CapabilityId capability, TWRange value, IMemoryManager memoryManager)
{
Capability = capability;
SetRangeValue(value, memoryManager);
}
///
/// Initializes a new instance of the class.
///
/// The capability.
/// The value.
public TWCapability(CapabilityId capability, TWArray value)
: this(capability, value, PlatformInfo.Current.MemoryManager) { }
///
/// Initializes a new instance of the class.
///
/// The capability.
/// The value.
/// The memory manager.
public TWCapability(CapabilityId capability, TWArray value, IMemoryManager memoryManager)
{
Capability = capability;
SetArrayValue(value, memoryManager);
}
#endregion
#region properties
///
/// Id of capability to set or get.
///
public CapabilityId Capability { get { return (CapabilityId)_cap; } set { _cap = (ushort)value; } }
///
/// The type of the container structure referenced by the pointer internally. The container
/// will be one of four types: , ,
/// , or .
///
public ContainerType ContainerType { get { return (ContainerType)_conType; } set { _conType = (ushort)value; } }
internal IntPtr Container { get { return _hContainer; } }
#endregion
#region value functions
void SetOneValue(TWOneValue value, IMemoryManager memoryManager)
{
if (value == null) { throw new ArgumentNullException("value"); }
ContainerType = ContainerType.OneValue;
// since one 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, "TWOneValue")); }
_hContainer = memoryManager.Allocate((uint)Marshal.SizeOf(value));
if (_hContainer != IntPtr.Zero)
{
Marshal.StructureToPtr(value, _hContainer, false);
}
}
void SetEnumValue(TWEnumeration value, IMemoryManager memoryManager)
{
if (value == null) { throw new ArgumentNullException("value"); }
ContainerType = ContainerType.Enum;
Int32 valueSize = TWEnumeration.ItemOffset + value.ItemList.Length * TypeExtensions.GetItemTypeSize(value.ItemType);
int offset = 0;
_hContainer = memoryManager.Allocate((uint)valueSize);
IntPtr baseAddr = memoryManager.Lock(_hContainer);
// can't safely use StructureToPtr here so write it our own
baseAddr.WriteValue(ref offset, ItemType.UInt16, value.ItemType);
baseAddr.WriteValue(ref offset, ItemType.UInt32, (uint)value.ItemList.Length);
baseAddr.WriteValue(ref offset, ItemType.UInt32, value.CurrentIndex);
baseAddr.WriteValue(ref offset, ItemType.UInt32, value.DefaultIndex);
foreach (var item in value.ItemList)
{
baseAddr.WriteValue(ref offset, value.ItemType, item);
}
//memoryManager.Unlock(baseAddr);
memoryManager.Unlock(_hContainer);
}
void SetRangeValue(TWRange 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, "TWRange")); }
_hContainer = memoryManager.Allocate((uint)Marshal.SizeOf(value));
if (_hContainer != IntPtr.Zero)
{
Marshal.StructureToPtr(value, _hContainer, false);
}
}
void SetArrayValue(TWArray value, IMemoryManager memoryManager)
{
if (value == null) { throw new ArgumentNullException("value"); }
ContainerType = ContainerType.Array;
Int32 valueSize = 6 + value.ItemList.Length * TypeExtensions.GetItemTypeSize(value.ItemType);
int offset = 0;
_hContainer = memoryManager.Allocate((uint)valueSize);
IntPtr baseAddr = memoryManager.Lock(_hContainer);
// can't safely use StructureToPtr here so write it our own
baseAddr.WriteValue(ref offset, ItemType.UInt16, value.ItemType);
baseAddr.WriteValue(ref offset, ItemType.UInt32, (uint)value.ItemList.Length);
foreach (var item in value.ItemList)
{
baseAddr.WriteValue(ref offset, value.ItemType, item);
}
memoryManager.Unlock(_hContainer);
//memoryManager.Unlock(baseAddr);
}
#endregion
#region IDisposable Members
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
void Dispose(bool disposing)
{
if (disposing) { }
if (_hContainer != IntPtr.Zero)
{
PlatformInfo.Current.MemoryManager.Free(_hContainer);
_hContainer = IntPtr.Zero;
}
}
///
/// Finalizes an instance of the class.
///
~TWCapability()
{
Dispose(false);
}
#endregion
}
///
/// Embedded in the structure;
/// defines a CIE XYZ space tri-stimulus value.
///
public partial struct TWCiePoint : IEquatable
{
#region properties
///
/// First tri-stimulus value of the CIE space representation.
///
public float X { get { return _z; } }
///
/// Second tri-stimulus value of the CIE space representation.
///
public float Y { get { return _z; } }
///
/// Third tri-stimulus value of the CIE space representation.
///
public float Z { get { return _z; } }
#endregion
#region equals
///
/// Determines whether the specified is equal to this instance.
///
/// The to compare with this instance.
///
/// true if the specified is equal to this instance; otherwise, false.
///
public override bool Equals(object obj)
{
if (!(obj is TWCiePoint))
return false;
return Equals((TWCiePoint)obj);
}
///
/// Indicates whether the current object is equal to another object of the same type.
///
/// An object to compare with this object.
///
public bool Equals(TWCiePoint other)
{
return _x == other._x && _y == other._y &&
_z == other._z;
}
///
/// Returns a hash code for this instance.
///
///
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
public override int GetHashCode()
{
return _x.GetHashCode() ^ _y.GetHashCode() ^
_z.GetHashCode();
}
#endregion
#region static stuff
///
/// Implements the operator ==.
///
/// The value1.
/// The value2.
/// The result of the operator.
public static bool operator ==(TWCiePoint value1, TWCiePoint value2)
{
return value1.Equals(value2);
}
///
/// Implements the operator !=.
///
/// The value1.
/// The value2.
/// The result of the operator.
public static bool operator !=(TWCiePoint value1, TWCiePoint value2)
{
return !value1.Equals(value2);
}
#endregion
}
///
/// Defines the mapping from an RGB color space device into CIE 1931 (XYZ) color space.
///
public partial class TWCieColor
{
internal TWCieColor() { }
///
/// Defines the original color space that was transformed into CIE XYZ.
/// This value is not set-able by the application.
///
public ushort ColorSpace { get { return _colorSpace; } }
///
/// Used to indicate which data byte is taken first. If zero, then high byte is
/// first. If non-zero, then low byte is first.
///
public short LowEndian { get { return _lowEndian; } }
///
/// If non-zero then color data is device-dependent and only ColorSpace is
/// valid in this structure.
///
public short DeviceDependent { get { return _deviceDependent; } }
///
/// Version of the color space descriptor specification used to define the
/// transform data. The current version is zero.
///
public int VersionNumber { get { return _versionNumber; } }
///
/// Describes parametrics for the first stage transformation of the Postscript
/// Level 2 CIE color space transform process.
///
public TWTransformStage StageABC { get { return _stageABC; } }
///
/// Describes parametrics for the first stage transformation of the Postscript
/// Level 2 CIE color space transform process.
///
public TWTransformStage StageLMN { get { return _stageLMN; } }
///
/// Values that specify the CIE 1931 (XYZ space) tri-stimulus value of the
/// diffused white point.
///
public TWCiePoint WhitePoint { get { return _whitePoint; } }
///
/// Values that specify the CIE 1931 (XYZ space) tri-stimulus value of the
/// diffused black point.
///
public TWCiePoint BlackPoint { get { return _blackPoint; } }
///
/// Values that specify the CIE 1931 (XYZ space) tri-stimulus value of inkless
/// "paper" from which the image was acquired.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "WhitePaper")]
public TWCiePoint WhitePaper { get { return _whitePaper; } }
///
/// Values that specify the CIE 1931 (XYZ space) tri-stimulus value of solid
/// black ink on the "paper" from which the image was acquired.
///
public TWCiePoint BlackInk { get { return _blackInk; } }
///
/// Optional table look-up values used by the decode function. Samples
/// are ordered sequentially and end-to-end as A, B, C, L, M, and N.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public TWFix32[] Samples { get { return _samples; } }
}
///
/// Allows for a data source and application to pass custom data to each other.
///
public partial class TWCustomDSData
{
///
/// Length, in bytes, of data.
///
public uint InfoLength { get { return _infoLength; } set { _infoLength = value; } }
///
/// Handle to memory containing InfoLength bytes of data.
///
public IntPtr hData { get { return _hData; } set { _hData = value; } }
}
///
/// Provides information about the Event that was raised by the Source. The Source should only fill
/// in those fields applicable to the Event. The Application must only read those fields applicable to
/// the Event.
///
public partial class TWDeviceEvent
{
internal TWDeviceEvent() { }
///
/// Defines event that has taken place.
///
public DeviceEvent Event { get { return (DeviceEvent)_event; } }
///
/// The name of the device that generated the event.
///
public string DeviceName { get { return _deviceName; } }
///
/// Battery minutes remaining. Valid for BatteryCheck event only.
///
public int BatteryMinutes { get { return (int)_batteryMinutes; } }
///
/// Battery percentage remaining. Valid for BatteryCheck event only.
///
public int BatteryPercentage { get { return (int)_batteryPercentage; } }
///
/// Current power supply in use. Valid for PowerSupply event only.
///
public int PowerSupply { get { return (int)_powerSupply; } }
///
/// Current X Resolution. Valid for Resolution event only.
///
public float XResolution { get { return _xResolution; } }
///
/// Current Y Resolution. Valid for Resolution event only.
///
public float YResolution { get { return _yResolution; } }
///
/// Current flash setting. Valid for BatteryCheck event only.
///
public FlashedUsed FlashUsed2 { get { return (FlashedUsed)_flashUsed2; } }
///
/// Number of images camera will capture. Valid for AutomaticCapture event only.
///
public int AutomaticCapture { get { return (int)_automaticCapture; } }
///
/// Number of seconds before first capture. Valid for AutomaticCapture event only.
///
public int TimeBeforeFirstCapture { get { return (int)_timeBeforeFirstCapture; } }
///
/// Hundredths of a second between captures. Valid for AutomaticCapture event only.
///
public int TimeBetweenCaptures { get { return (int)_timeBetweenCaptures; } }
}
///
/// Embedded in the , , and structures.
/// This structure holds the tri-stimulus color palette information for structures.
/// The order of the channels shall match their alphabetic representation. That is, for RGB data, R
/// shall be channel 1. For CMY data, C shall be channel 1. This allows the application and Source
/// to maintain consistency. Grayscale data will have the same values entered in all three channels.
///
public partial struct TWElement8 : IEquatable
{
///
/// Value used to index into the color table.
///
public byte Index { get { return _index; } set { _index = value; } }
///
/// First tri-stimulus value (e.g. Red).
///
public byte Channel1 { get { return _channel1; } set { _channel1 = value; } }
///
/// Second tri-stimulus value (e.g Green).
///
public byte Channel2 { get { return _channel2; } set { _channel2 = value; } }
///
/// Third tri-stimulus value (e.g Blue).
///
public byte Channel3 { get { return _channel3; } set { _channel3 = value; } }
#region equals
///
/// Determines whether the specified is equal to this instance.
///
/// The to compare with this instance.
///
/// true if the specified is equal to this instance; otherwise, false.
///
public override bool Equals(object obj)
{
if (!(obj is TWElement8))
return false;
return Equals((TWElement8)obj);
}
///
/// Indicates whether the current object is equal to another object of the same type.
///
/// An object to compare with this object.
///
public bool Equals(TWElement8 other)
{
return _channel1 == other._channel1 && _channel2 == other._channel2 &&
_channel3 == other._channel3 && _index == other._index;
}
///
/// Returns a hash code for this instance.
///
///
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
public override int GetHashCode()
{
return _channel1.GetHashCode() ^ _channel2.GetHashCode() ^
_channel3.GetHashCode() ^ _index.GetHashCode();
}
///
/// Check for value equality.
///
/// The v1.
/// The v2.
///
public static bool operator ==(TWElement8 v1, TWElement8 v2)
{
return v1.Equals(v2);
}
///
/// Check for value inequality.
///
/// The v1.
/// The v2.
///
public static bool operator !=(TWElement8 v1, TWElement8 v2)
{
return !(v1 == v2);
}
#endregion
}
///
/// 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.
///
public partial class TWEnumeration
{
///
/// The type of items in the enumerated list. All items in the array have the same size.
///
public ItemType ItemType { get { return (ItemType)_itemType; } set { _itemType = (ushort)value; } }
/////
///// How many items are in the enumeration.
/////
//public int Count { get { return (int)_numItems; } set { _numItems = (uint)value; } }
///
/// The item number, or index (zero-based) into , of the "current"
/// value for the capability.
///
public int CurrentIndex { get { return (int)_currentIndex; } set { _currentIndex = (uint)value; } }
///
/// The item number, or index (zero-based) into , of the "power-on"
/// value for the capability.
///
public int DefaultIndex { get { return (int)_defaultIndex; } set { _defaultIndex = (uint)value; } }
///
/// The enumerated list: one value resides within each array element.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public object[] ItemList
{
get { return _itemList; }
set
{
_itemList = value;
if (value != null) { _numItems = (uint)value.Length; }
else { _numItems = 0; }
}
}
///
/// Gets the byte offset of the item list from a Ptr to the first item.
///
internal const int ItemOffset = 14;
}
///
/// Used on Windows and Macintosh pre OS X to pass application events/messages from the
/// application to the Source.
///
public partial class TWEvent
{
///
/// A pointer to the event/message to be examined by the Source.
/// Under Microsoft Windows, pEvent is a pMSG (pointer to a Microsoft
/// Windows MSG struct). That is, the message the application received from
/// GetMessage(). On the Macintosh, pEvent is a pointer to an EventRecord.
///
public IntPtr pEvent { get { return _pEvent; } set { _pEvent = value; } }
///
/// Any message the Source needs to send to the application in
/// response to processing the event/message. The messages currently defined for
/// this purpose are ,
/// and .
///
public Message TWMessage { get { return (Message)_tWMessage; } }
}
///
/// This structure is used to pass specific information between the data source and the application
/// through .
///
[DebuggerDisplay("ID = {InfoID}, Type = {ItemType}")]
public partial struct TWInfo
{
///
/// Tag identifying an information.
///
public ExtendedImageInfo InfoID { get { return (ExtendedImageInfo)_infoID; } set { _infoID = (ushort)value; } }
///
/// Item data type.
///
public ItemType ItemType { get { return (ItemType)_itemType; } set { _itemType = (ushort)value; } }
///
/// Number of items.
///
public ushort NumItems { get { return _numItems; } }
///
/// This is the return code of availability of data for extended image attribute requested.
///
///
/// The return code.
///
public ReturnCode ReturnCode { get { return (ReturnCode)_returnCode; } }
///
/// Contains either data or a handle to data. The field
/// contains data if the total amount of data is less than or equal to four bytes. The
/// field contains a handle if the total amount of data is more than four bytes.
/// The amount of data is determined by multiplying NumItems times
/// the byte size of the data type specified by ItemType.
/// If the Item field contains a handle to data, then the Application is
/// responsible for freeing that memory.
///
public IntPtr Item { get { return _item; } internal set { _item = value; } }
bool ItemIsPointer
{
get
{
return ItemType == Data.ItemType.Handle ||
(TypeExtensions.GetItemTypeSize(ItemType) * NumItems) > 4;// IntPtr.Size
}
}
///
/// Try to reads the values from the property.
///
///
public IList