Moved DetermineBufferSize() to TW_SETUPMEMXFER

This commit is contained in:
Eugene Wang 2023-04-08 12:18:01 -04:00
parent 830dc8cd9b
commit 633e8b1236
3 changed files with 19 additions and 16 deletions

View File

@ -2507,7 +2507,7 @@ namespace NTwain.Data
/// Provides the application information about the Sources 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;

View File

@ -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; } }

View File

@ -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)
{