Cleared some todos.

This commit is contained in:
soukoku 2014-04-06 16:25:48 -04:00
parent 006d33b451
commit 7e8d8f24b0
9 changed files with 55 additions and 46 deletions

View File

@ -83,10 +83,8 @@ namespace NTwain.Data
{ {
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
TWDecodeFunction[] _decode; TWDecodeFunction[] _decode;
// TODO: research jagged aray mapping (3x3).
// maybe can only have 1-D
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)]
TWFix32[][] _mix; TWFix32[] _mix;
} }
[StructLayout(LayoutKind.Sequential, Pack = 2)] [StructLayout(LayoutKind.Sequential, Pack = 2)]
@ -230,61 +228,58 @@ namespace NTwain.Data
TWInfo[] _info; TWInfo[] _info;
} }
[StructLayout(LayoutKind.Explicit, Pack = 2), [StructLayout(LayoutKind.Sequential, Pack = 2),
BestFitMapping(false, ThrowOnUnmappableChar = true)] BestFitMapping(false, ThrowOnUnmappableChar = true)]
partial class TWFileSystem partial class TWFileSystem
{ {
// TODO: verify all field offset #s //[FieldOffset(0)]
[FieldOffset(0)]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String255)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String255)]
string _inputName; string _inputName;
[FieldOffset(TwainConst.String255)] //[FieldOffset(TwainConst.String255)]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String255)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String255)]
string _outputName; string _outputName;
[FieldOffset(512)] //[FieldOffset(512)]
TW_MEMREF _context; TW_MEMREF _context;
//TODO: verify this field offset in 64bit due to previous pointer //[FieldOffset(520)]
[FieldOffset(520)] //short _recursive;
short _recursive; //[FieldOffset(520)]
[FieldOffset(520)]
TW_BOOL _subdirectories; TW_BOOL _subdirectories;
[FieldOffset(524)] //[FieldOffset(524)]
TW_INT32 _fileType; TW_INT32 _fileType;
[FieldOffset(524)] //[FieldOffset(524)]
TW_UINT32 _fileSystemType; //TW_UINT32 _fileSystemType;
[FieldOffset(528)] //[FieldOffset(528)]
TW_UINT32 _size; TW_UINT32 _size;
[FieldOffset(532)] //[FieldOffset(532)]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String32)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String32)]
string _createTimeDate; string _createTimeDate;
[FieldOffset(566)] //[FieldOffset(566)]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String32)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TwainConst.String32)]
string _modifiedTimeDate; string _modifiedTimeDate;
[FieldOffset(600)] //[FieldOffset(600)]
TW_UINT32 _freeSpace; TW_UINT32 _freeSpace;
[FieldOffset(604)] //[FieldOffset(604)]
TW_INT32 _newImageSize; TW_INT32 _newImageSize;
[FieldOffset(608)] //[FieldOffset(608)]
TW_UINT32 _numberOfFiles; TW_UINT32 _numberOfFiles;
[FieldOffset(612)] //[FieldOffset(612)]
TW_UINT32 _numberOfSnippets; TW_UINT32 _numberOfSnippets;
[FieldOffset(616)] //[FieldOffset(616)]
TW_UINT32 _deviceGroupMask; TW_UINT32 _deviceGroupMask;
[FieldOffset(620)] //[FieldOffset(620)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 508)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 508)]
TW_INT8[] _reserved; TW_INT8[] _reserved;
} }

View File

@ -470,9 +470,21 @@ namespace NTwain.Data
/// </summary> /// </summary>
public TWDecodeFunction[] Decode { get { return _decode; } set { _decode = value; } } public TWDecodeFunction[] Decode { get { return _decode; } set { _decode = value; } }
/// <summary> /// <summary>
/// 3x3 matrix that specifies how channels are mixed in. /// Flattened 3x3 matrix that specifies how channels are mixed in.
/// </summary> /// </summary>
public TWFix32[][] Mix { get { return _mix; } set { _mix = value; } } public TWFix32[] Mix { get { return _mix; } set { _mix = value; } }
/// <summary>
/// Gets the <see cref="Mix"/> value as matrix.
/// </summary>
/// <returns></returns>
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;
}
} }
/// <summary> /// <summary>
@ -1606,9 +1618,8 @@ namespace NTwain.Data
/// all subdirectories in the directory being deleted; or copies all /// all subdirectories in the directory being deleted; or copies all
/// sub-directories in the directory being copied. /// sub-directories in the directory being copied.
/// </summary> /// </summary>
public short Recursive { get { return _recursive; } set { _recursive = value; } } public bool Recursive { get { return _subdirectories == TwainConst.True; } set { _subdirectories = value ? TwainConst.True : TwainConst.False; } }
public bool Subdirectories { get { return _subdirectories == TwainConst.True; } }
/// <summary> /// <summary>
/// Gets the type of the file. /// Gets the type of the file.
/// </summary> /// </summary>
@ -1616,8 +1627,7 @@ namespace NTwain.Data
/// The type of the file. /// The type of the file.
/// </value> /// </value>
public FileType FileType { get { return (FileType)_fileType; } set { _fileType = (int)value; } } public FileType FileType { get { return (FileType)_fileType; } set { _fileType = (int)value; } }
public uint FileSystemType { get { return _fileSystemType; } set { _fileSystemType = value; } }
/// <summary> /// <summary>
/// If <see cref="NTwain.Values.FileType.Directory"/>, total size of media in bytes. /// If <see cref="NTwain.Values.FileType.Directory"/>, total size of media in bytes.
/// If <see cref="NTwain.Values.FileType.Image"/>, size of image in bytes. /// If <see cref="NTwain.Values.FileType.Image"/>, size of image in bytes.

View File

@ -17,7 +17,7 @@ namespace NTwain.Triplets
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <returns></returns> /// <returns></returns>
public ReturnCode Get(ref uint value) public ReturnCode Get(ref DataGroups value)
{ {
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.XferGroup, Message.Get); Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.XferGroup, Message.Get);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value); return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
@ -30,7 +30,7 @@ namespace NTwain.Triplets
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
/// <returns></returns> /// <returns></returns>
public ReturnCode Set(uint value) public ReturnCode Set(DataGroups value)
{ {
Session.VerifyState(6, 6, DataGroups.Control, DataArgumentType.XferGroup, Message.Set); Session.VerifyState(6, 6, DataGroups.Control, DataArgumentType.XferGroup, Message.Set);
return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value); return PInvoke.DsmEntry(Session.GetAppId(), Session.SourceId, DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);

View File

@ -28,7 +28,7 @@ namespace NTwain.Triplets
// DataGroups dg, // DataGroups dg,
// DataArgumentType dat, // DataArgumentType dat,
// Message msg, // Message msg,
// ref uint data); // ref DataGroups data);
// [DllImport("/usr/local/lib/libtwaindsm.so", EntryPoint = "#1")] // [DllImport("/usr/local/lib/libtwaindsm.so", EntryPoint = "#1")]
// public static extern ReturnCode DsmEntryLinux( // public static extern ReturnCode DsmEntryLinux(

View File

@ -25,7 +25,7 @@ namespace NTwain.Triplets
DataGroups dg, DataGroups dg,
DataArgumentType dat, DataArgumentType dat,
Message msg, Message msg,
ref uint data); ref DataGroups data);
[DllImport("twain_32", EntryPoint = "#1")] [DllImport("twain_32", EntryPoint = "#1")]
public static extern ReturnCode DsmEntry32( public static extern ReturnCode DsmEntry32(

View File

@ -25,7 +25,7 @@ namespace NTwain.Triplets
DataGroups dg, DataGroups dg,
DataArgumentType dat, DataArgumentType dat,
Message msg, Message msg,
ref uint data); ref DataGroups data);
[DllImport("twaindsm", EntryPoint = "#1")] [DllImport("twaindsm", EntryPoint = "#1")]
public static extern ReturnCode DsmEntry64( public static extern ReturnCode DsmEntry64(

View File

@ -53,7 +53,7 @@ namespace NTwain.Triplets
DataGroups dg, DataGroups dg,
DataArgumentType dat, DataArgumentType dat,
Message msg, Message msg,
ref uint data) ref DataGroups data)
{ {
if (CanUseTwainDSM) { return NativeMethods.DsmEntry64(origin, destination, dg, dat, msg, ref data); } if (CanUseTwainDSM) { return NativeMethods.DsmEntry64(origin, destination, dg, dat, msg, ref data); }
else { return NativeMethods.DsmEntry32(origin, destination, dg, dat, msg, ref data); } else { return NativeMethods.DsmEntry32(origin, destination, dg, dat, msg, ref data); }

View File

@ -603,7 +603,7 @@ namespace NTwain
// My guess is the DS needs to see the Success return code first before letting transfer happen // My guess is the DS needs to see the Success return code first before letting transfer happen
// so this is an hack to make it happen. // so this is an hack to make it happen.
// TODO: find a better method. // TODO: find a better method without needing a SynchronizationContext.
ThreadPool.QueueUserWorkItem(o => ThreadPool.QueueUserWorkItem(o =>
{ {
var ctx = o as SynchronizationContext; var ctx = o as SynchronizationContext;
@ -669,12 +669,19 @@ namespace NTwain
/// </summary> /// </summary>
protected virtual void DoTransferRoutine() protected virtual void DoTransferRoutine()
{ {
// TODO: better way to determine what's being xfered? DataGroups xferGroup = DataGroups.None;
if ((SourceId.DataGroup & DataGroups.Image) == DataGroups.Image)
if (DGControl.XferGroup.Get(ref xferGroup) != ReturnCode.Success)
{
xferGroup = DataGroups.None;
}
// support one or the other or both?
if ((xferGroup & DataGroups.Image) == DataGroups.Image)
{ {
DoImageXfer(); DoImageXfer();
} }
else if ((SourceId.DataGroup & DataGroups.Audio) == DataGroups.Audio) else if ((xferGroup & DataGroups.Audio) == DataGroups.Audio)
{ {
DoAudioXfer(); DoAudioXfer();
} }
@ -725,8 +732,7 @@ namespace NTwain
rc = DGControl.PendingXfers.Reset(pending); rc = DGControl.PendingXfers.Reset(pending);
if (rc == ReturnCode.Success) if (rc == ReturnCode.Success)
{ {
// TODO: verify if audio exit directly? break;
return;
} }
} }
else if (!preXferArgs.CancelCurrent) else if (!preXferArgs.CancelCurrent)

View File

@ -97,8 +97,6 @@ namespace NTwain
#region do xfer #region do xfer
// TODO: expose all swallowed exceptions somehow later
IntPtr dataPtr = IntPtr.Zero; IntPtr dataPtr = IntPtr.Zero;
IntPtr lockedPtr = IntPtr.Zero; IntPtr lockedPtr = IntPtr.Zero;
string file = null; string file = null;