Some text and eximageinfo correctness update.

This commit is contained in:
soukoku 2014-05-23 18:41:18 -04:00
parent 3b31c465e6
commit b0142127d7
12 changed files with 155 additions and 61 deletions

View File

@ -499,12 +499,12 @@ namespace NTwain.Data
/// Gets the <see cref="Mix"/> value as matrix.
/// </summary>
/// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1814:PreferJaggedArraysOverMultidimensional", MessageId = "Body"),
[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];
TWFix32[,] mat = new TWFix32[3, 3];
Buffer.BlockCopy(_mix, 0, mat, 0, _mix.Length * 4);
return mat;
}
@ -1348,11 +1348,11 @@ namespace NTwain.Data
/// <summary>
/// Tag identifying an information.
/// </summary>
public ExtendedImageInfo InfoID { get { return (ExtendedImageInfo)_infoID; } }
public ExtendedImageInfo InfoID { get { return (ExtendedImageInfo)_infoID; } set { _infoID = (ushort)value; } }
/// <summary>
/// Item data type.
/// </summary>
public ItemType ItemType { get { return (ItemType)_itemType; } }
public ItemType ItemType { get { return (ItemType)_itemType; } set { _itemType = (ushort)value; } }
/// <summary>
/// Number of items.
/// </summary>
@ -1388,7 +1388,10 @@ namespace NTwain.Data
/// </summary>
public sealed partial class TWExtImageInfo : IDisposable
{
internal TWExtImageInfo() { }
internal TWExtImageInfo()
{
_info = new TWInfo[200];
}
/// <summary>
/// Number of information that application is requesting. This is filled by the
@ -1396,7 +1399,7 @@ namespace NTwain.Data
/// image information. The application should allocate memory and fill in the
/// attribute tag for image information.
/// </summary>
public uint NumInfos { get { return _numInfos; } }
public uint NumInfos { get { return _numInfos; } set { _numInfos = value; } }
/// <summary>
/// Array of information.
/// </summary>

View File

@ -17,6 +17,9 @@ namespace NTwain.Data
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1028:EnumStorageShouldBeInt32")]
public enum ContainerType : ushort
{
/// <summary>
/// The default value for this enum.
/// </summary>
Invalid = 0,
/// <summary>
/// The container is <see cref="TWArray"/>.
@ -34,6 +37,9 @@ namespace NTwain.Data
/// The container is <see cref="TWRange"/>.
/// </summary>
Range = 6,
/// <summary>
/// The don't care value.
/// </summary>
DontCare = TwainConst.DontCare16,
}

View File

@ -45,12 +45,12 @@ namespace NTwain
/// </value>
public TWImageInfo ImageInfo { get; internal set; }
/// <summary>
/// Gets the extended image information if applicable.
/// </summary>
/// <value>
/// The extended image information.
/// </value>
public TWExtImageInfo ExImageInfo { get; internal set; }
///// <summary>
///// Gets the extended image information if applicable.
///// </summary>
///// <value>
///// The extended image information.
///// </value>
//public TWExtImageInfo ExImageInfo { get; internal set; }
}
}

View File

@ -414,14 +414,14 @@ namespace NTwain.Internals
static void DoImageXferredEventRoutine(ITwainSessionInternal session, IntPtr dataPtr, byte[] dataArray, string filePath)
{
TWImageInfo imgInfo;
TWExtImageInfo extInfo = null;
if (session.CurrentSource.SupportedCaps.Contains(CapabilityId.ICapExtImageInfo))
{
if (session.DGImage.ExtImageInfo.Get(out extInfo) != ReturnCode.Success)
{
extInfo = null;
}
}
//TWExtImageInfo extInfo = null;
//if (session.CurrentSource.SupportedCaps.Contains(CapabilityId.ICapExtImageInfo))
//{
// if (session.DGImage.ExtImageInfo.Get(out extInfo) != ReturnCode.Success)
// {
// extInfo = null;
// }
//}
if (session.DGImage.ImageInfo.Get(out imgInfo) != ReturnCode.Success)
{
imgInfo = null;
@ -432,9 +432,9 @@ namespace NTwain.Internals
MemData = dataArray,
FileDataPath = filePath,
ImageInfo = imgInfo,
ExImageInfo = extInfo
//ExImageInfo = extInfo
});
if (extInfo != null) { extInfo.Dispose(); }
//if (extInfo != null) { extInfo.Dispose(); }
}
#endregion

View File

@ -6,15 +6,15 @@ namespace NTwain.Triplets
/// <summary>
/// Represents <see cref="DataArgumentType.AudioInfo"/>.
/// </summary>
public sealed class AudioInfo : OpBase
sealed class AudioInfo : OpBase
{
internal AudioInfo(ITwainSessionInternal session) : base(session) { }
/// <summary>
/// <summary>
/// Used to get the information of the current audio data ready to transfer.
/// </summary>
/// <param name="info">The info.</param>
/// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode Get(out TWAudioInfo info)
{
Session.VerifyState(6, 7, DataGroups.Audio, DataArgumentType.AudioInfo, Message.Get);

View File

@ -27,7 +27,7 @@ namespace NTwain.Triplets
}
AudioInfo _audioInfo;
public AudioInfo AudioInfo
internal AudioInfo AudioInfo
{
get
{

View File

@ -34,7 +34,10 @@ namespace NTwain.Triplets
return _callback2;
}
}
Capability _capability;
Capability _capability;
/// <summary>
/// Gets the operations defined for DAT_CAPABILITY.
/// </summary>
public Capability Capability
{
get
@ -44,6 +47,9 @@ namespace NTwain.Triplets
}
}
CapabilityCustom _capabilityCust;
/// <summary>
/// Gets the operations defined for a custom DAT_* value with capability data.
/// </summary>
public CapabilityCustom CapabilityCustom
{
get
@ -52,7 +58,10 @@ namespace NTwain.Triplets
return _capabilityCust;
}
}
CustomDSData _customDSData;
CustomDSData _customDSData;
/// <summary>
/// Gets the operations defined for DAT_CUSTOMDSDATA.
/// </summary>
public CustomDSData CustomDSData
{
get
@ -88,7 +97,10 @@ namespace NTwain.Triplets
return _event;
}
}
FileSystem _fileSys;
FileSystem _fileSys;
/// <summary>
/// Gets the operations defined for DAT_FILESYSTEM.
/// </summary>
public FileSystem FileSystem
{
get
@ -115,7 +127,10 @@ namespace NTwain.Triplets
return _parent;
}
}
PassThru _passThru;
PassThru _passThru;
/// <summary>
/// Gets the operations defined for DAT_PASSTHRU.
/// </summary>
public PassThru PassThru
{
get
@ -133,7 +148,10 @@ namespace NTwain.Triplets
return _pendingXfers;
}
}
SetupFileXfer _setupFileXfer;
SetupFileXfer _setupFileXfer;
/// <summary>
/// Gets the operations defined for DAT_SETUPFILEXFER.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xfer")]
public SetupFileXfer SetupFileXfer
{
@ -143,7 +161,10 @@ namespace NTwain.Triplets
return _setupFileXfer;
}
}
SetupMemXfer _setupMemXfer;
SetupMemXfer _setupMemXfer;
/// <summary>
/// Gets the operations defined for DAT_SETUPMEMXFER.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xfer"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Mem")]
public SetupMemXfer SetupMemXfer
{
@ -180,7 +201,10 @@ namespace NTwain.Triplets
return _userInterface;
}
}
XferGroup _xferGroup;
XferGroup _xferGroup;
/// <summary>
/// Gets the operations defined for DAT_XFERGROUP.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xfer")]
public XferGroup XferGroup
{

View File

@ -6,16 +6,20 @@ namespace NTwain.Triplets
/// <summary>
/// Represents <see cref="DataArgumentType.ExtImageInfo"/>.
/// </summary>
public sealed class ExtImageInfo : OpBase
{
internal ExtImageInfo(ITwainSessionInternal session) : base(session) { }
public sealed class ExtImageInfo : OpBase
{
internal ExtImageInfo(ITwainSessionInternal session) : base(session) { }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode Get(out TWExtImageInfo info)
{
Session.VerifyState(7, 7, DataGroups.Image, DataArgumentType.ExtImageInfo, Message.Get);
info = new TWExtImageInfo();
/// <summary>
/// This operation is used by the application to query the data source for extended image attributes.
/// The application is responsible for creating and disiposing the info object.
/// </summary>
/// <param name="info">The information.</param>
/// <returns></returns>
public ReturnCode Get(TWExtImageInfo info)
{
Session.VerifyState(7, 7, DataGroups.Image, DataArgumentType.ExtImageInfo, Message.Get);
return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, Message.Get, info);
}
}
}
}
}

View File

@ -10,6 +10,13 @@ namespace NTwain.Triplets
{
internal ImageLayout(ITwainSessionInternal session) : base(session) { }
/// <summary>
/// Gets both the size and placement of the image on the scanner. The
/// coordinates on the scanner and the extents of the image are expressed in the unit of measure
/// currently negotiated for ICAP_UNITS (default is inches).
/// </summary>
/// <param name="layout">The layout.</param>
/// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode Get(out TWImageLayout layout)
{
@ -18,6 +25,14 @@ namespace NTwain.Triplets
return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, Message.Get, layout);
}
/// <summary>
/// returns the default information on the layout of an image. This is the size and
/// position of the image that will be acquired from the Source if the acquisition is started with the
/// Source (and the device it is controlling) in its power-on state (for instance, most flatbed scanners
/// will capture the entire bed).
/// </summary>
/// <param name="layout">The layout.</param>
/// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode GetDefault(out TWImageLayout layout)
{
@ -26,6 +41,11 @@ namespace NTwain.Triplets
return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, Message.GetDefault, layout);
}
/// <summary>
/// This operation sets the image layout information for the next transfer to its default settings.
/// </summary>
/// <param name="layout">The layout.</param>
/// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode Reset(out TWImageLayout layout)
{
@ -34,6 +54,15 @@ namespace NTwain.Triplets
return Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, Message.Reset, layout);
}
/// <summary>
/// This operation sets the layout for the next image transfer. This allows the application to specify
/// the physical area to be acquired during the next image transfer (for instance, a frame-based
/// application would pass to the Source the size of the frame the user selected within the
/// application—the helpful Source would present a selection region already sized to match the
/// layout frame size).
/// </summary>
/// <param name="layout">The layout.</param>
/// <returns></returns>
public ReturnCode Set(TWImageLayout layout)
{
Session.VerifyState(4, 4, DataGroups.Image, DataArgumentType.ImageLayout, Message.Set);

View File

@ -16,6 +16,9 @@ namespace NTwain.Triplets
}
CieColor _cieColor;
/// <summary>
/// Gets the operations defined for DAT_CIECOLOR.
/// </summary>
public CieColor CieColor
{
get
@ -27,6 +30,9 @@ namespace NTwain.Triplets
ExtImageInfo _extImgInfo;
/// <summary>
/// Gets the operations defined for DAT_EXTIMAGEINFO.
/// </summary>
public ExtImageInfo ExtImageInfo
{
get
@ -38,6 +44,9 @@ namespace NTwain.Triplets
Filter _filter;
/// <summary>
/// Gets the operations defined for DAT_FILTER.
/// </summary>
public Filter Filter
{
get
@ -48,6 +57,9 @@ namespace NTwain.Triplets
}
GrayResponse _grayResponse;
/// <summary>
/// Gets the operations defined for DAT_GRAYRESPONSE.
/// </summary>
public GrayResponse GrayResponse
{
get
@ -58,6 +70,9 @@ namespace NTwain.Triplets
}
IccProfile _iccProfile;
/// <summary>
/// Gets the operations defined for DAT_ICCPROFILE.
/// </summary>
public IccProfile IccProfile
{
get
@ -88,6 +103,9 @@ namespace NTwain.Triplets
}
ImageLayout _imgLayout;
/// <summary>
/// Gets the operations defined for DAT_IMAGELAYOUT.
/// </summary>
public ImageLayout ImageLayout
{
get
@ -128,6 +146,9 @@ namespace NTwain.Triplets
}
JpegCompression _jpegComp;
/// <summary>
/// Gets the operations defined for DAT_JPEGCOMPRESSION.
/// </summary>
public JpegCompression JpegCompression
{
get
@ -138,6 +159,9 @@ namespace NTwain.Triplets
}
Palette8 _palette8;
/// <summary>
/// Gets the operations defined for DAT_PALETTE8.
/// </summary>
public Palette8 Palette8
{
get
@ -148,6 +172,9 @@ namespace NTwain.Triplets
}
RgbResponse _rgbResp;
/// <summary>
/// Gets the operations defined for DAT_RGBRESPONSE.
/// </summary>
public RgbResponse RgbResponse
{
get

View File

@ -50,6 +50,20 @@ namespace NTwain
TWIdentity _appId;
TWUserInterface _twui;
static readonly Dictionary<string, TwainSource> __ownedSources = new Dictionary<string, TwainSource>();
internal static TwainSource GetSourceInstance(ITwainSessionInternal session, TWIdentity sourceId)
{
var key = string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}", sourceId.Manufacturer, sourceId.ProductFamily, sourceId.ProductName);
if (__ownedSources.ContainsKey(key))
{
return __ownedSources[key];
}
return __ownedSources[key] = new TwainSource(session, sourceId);
}
/// <summary>
/// Gets or sets the optional synchronization context.
/// This allows events to be raised on the thread
@ -139,7 +153,7 @@ namespace NTwain
TWIdentity id;
if (DGControl.Identity.GetDefault(out id) == ReturnCode.Success)
{
return TwainSource.GetInstance(this, id);
return GetSourceInstance(this, id);
}
return null;
}
@ -162,7 +176,7 @@ namespace NTwain
TWIdentity id;
if (DGControl.Identity.UserSelect(out id) == ReturnCode.Success)
{
return TwainSource.GetInstance(this, id);
return GetSourceInstance(this, id);
}
return null;
}
@ -303,7 +317,6 @@ namespace NTwain
/// Gets list of sources available in the system.
/// Only call this at state 2 or higher.
/// </summary>
/// <param name="session">The session.</param>
/// <returns></returns>
public IEnumerable<TwainSource> GetSources()
{
@ -311,7 +324,7 @@ namespace NTwain
var rc = DGControl.Identity.GetFirst(out srcId);
while (rc == ReturnCode.Success)
{
yield return TwainSource.GetInstance(this, srcId);
yield return GetSourceInstance(this, srcId);
rc = DGControl.Identity.GetNext(out srcId);
}
}

View File

@ -16,21 +16,9 @@ namespace NTwain
/// </summary>
public partial class TwainSource : INotifyPropertyChanged
{
static readonly Dictionary<string, TwainSource> __globalInstances = new Dictionary<string, TwainSource>();
internal static TwainSource GetInstance(ITwainSessionInternal session, TWIdentity sourceId)
{
var key = string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}", sourceId.Manufacturer, sourceId.ProductFamily, sourceId.ProductName);
if (__globalInstances.ContainsKey(key))
{
return __globalInstances[key];
}
return __globalInstances[key] = new TwainSource(session, sourceId);
}
ITwainSessionInternal _session;
private TwainSource(ITwainSessionInternal session, TWIdentity sourceId)
internal TwainSource(ITwainSessionInternal session, TWIdentity sourceId)
{
_session = session;
Identity = sourceId;