mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Moved DetermineBufferSize() to TW_SETUPMEMXFER
This commit is contained in:
parent
830dc8cd9b
commit
633e8b1236
@ -2507,7 +2507,7 @@ namespace NTwain.Data
|
||||
/// Provides the application information about the Source’s requirements and preferences regarding allocation of transfer buffer(s).
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
public struct TW_SETUPMEMXFER
|
||||
public partial struct TW_SETUPMEMXFER
|
||||
{
|
||||
public uint MinBufSize;
|
||||
public uint MaxBufSize;
|
||||
|
@ -762,6 +762,23 @@ namespace NTwain.Data
|
||||
}
|
||||
}
|
||||
|
||||
partial struct TW_SETUPMEMXFER
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines the best buffer size from values
|
||||
/// specified by source
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public uint DetermineBufferSize()
|
||||
{
|
||||
if (Preferred != TwainConst.TWON_DONTCARE32) return Preferred;
|
||||
if (MaxBufSize != TwainConst.TWON_DONTCARE32) return MaxBufSize;
|
||||
if (MinBufSize != TwainConst.TWON_DONTCARE32) return MinBufSize;
|
||||
// default to 16 kb if source doesn't really want to say what it needs
|
||||
return 1024 * 16;
|
||||
}
|
||||
}
|
||||
|
||||
//partial struct TW_DEVICEEVENT
|
||||
//{
|
||||
// public TWDE Event { get { return (TWDE)_event; } }
|
||||
|
@ -275,7 +275,7 @@ namespace NTwain
|
||||
rc = DGControl.SetupMemXfer.Get(ref _appIdentity, ref _currentDS, out TW_SETUPMEMXFER memSetup);
|
||||
if (rc == TWRC.SUCCESS)
|
||||
{
|
||||
uint buffSize = DetermineBufferSize(memSetup);
|
||||
uint buffSize = memSetup.DetermineBufferSize();
|
||||
var memPtr = Alloc(buffSize);
|
||||
|
||||
TW_IMAGEMEMXFER memXfer = new()
|
||||
@ -357,20 +357,6 @@ namespace NTwain
|
||||
return WrapInSTS(rc);
|
||||
}
|
||||
|
||||
private static uint DetermineBufferSize(TW_SETUPMEMXFER memSetup)
|
||||
{
|
||||
// default to 16 kb if source doesn't really want to say what it needs
|
||||
var buffSize = memSetup.Preferred;
|
||||
if (buffSize != TwainConst.TWON_DONTCARE32) return buffSize;
|
||||
|
||||
buffSize = memSetup.MaxBufSize;
|
||||
if (buffSize != TwainConst.TWON_DONTCARE32) return buffSize;
|
||||
|
||||
buffSize = memSetup.MinBufSize;
|
||||
if (buffSize != TwainConst.TWON_DONTCARE32) return buffSize;
|
||||
|
||||
return 1024 * 16;
|
||||
}
|
||||
|
||||
private STS TransferFileImage(ref TW_PENDINGXFERS pending)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user