sane.ds: More correctly detect an end of scan job from sane; this enables Acrobat to pull multiple pages in one scan.

This commit is contained in:
Jeremy White 2009-03-05 13:25:58 -06:00 committed by Alexandre Julliard
parent 28b708ca9e
commit e472c49a23
4 changed files with 80 additions and 26 deletions

View File

@ -695,6 +695,7 @@ static TW_UINT16 SANE_ICAPResolution (pTW_CAPABILITY pCapability, TW_UINT16 acti
return twCC; return twCC;
} }
#ifdef SONAME_LIBSANE
static void convert_double_fix32(double d, TW_FIX32 *fix32) static void convert_double_fix32(double d, TW_FIX32 *fix32)
{ {
TW_INT32 value = (TW_INT32) (d * 65536.0 + 0.5); TW_INT32 value = (TW_INT32) (d * 65536.0 + 0.5);
@ -702,8 +703,6 @@ static void convert_double_fix32(double d, TW_FIX32 *fix32)
fix32->Frac = value & 0x0000ffffL; fix32->Frac = value & 0x0000ffffL;
} }
#ifdef SONAME_LIBSANE
static BOOL convert_sane_res_to_twain(double sane_res, SANE_Unit unit, TW_FIX32 *twain_res, TW_UINT16 twtype) static BOOL convert_sane_res_to_twain(double sane_res, SANE_Unit unit, TW_FIX32 *twain_res, TW_UINT16 twtype)
{ {
double d; double d;

View File

@ -335,8 +335,12 @@ TW_UINT16 SANE_PassThrough (pTW_IDENTITY pOrigin,
TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin, TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin,
TW_MEMREF pData) TW_MEMREF pData)
{ {
#ifndef SONAME_LIBSANE
return TWRC_FAILURE;
#else
TW_UINT16 twRC = TWRC_SUCCESS; TW_UINT16 twRC = TWRC_SUCCESS;
pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData; pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
SANE_Status status;
TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n"); TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
@ -347,31 +351,41 @@ TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin,
} }
else else
{ {
if (pPendingXfers->Count != 0) pPendingXfers->Count = -1;
{
pPendingXfers->Count --;
activeDS.currentState = 6; activeDS.currentState = 6;
} if (! activeDS.sane_started)
else
{ {
status = psane_start (activeDS.deviceHandle);
if (status != SANE_STATUS_GOOD)
{
TRACE("PENDINGXFERS/MSG_ENDXFER sane_start returns %s\n", psane_strstatus(status));
pPendingXfers->Count = 0;
activeDS.currentState = 5; activeDS.currentState = 5;
/* Notify the application that it can close the data source */ /* Notify the application that it can close the data source */
if (activeDS.windowMessage) if (activeDS.windowMessage)
PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_CLOSEDSREQ, 0); PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_CLOSEDSREQ, 0);
} }
else
activeDS.sane_started = TRUE;
}
twRC = TWRC_SUCCESS; twRC = TWRC_SUCCESS;
activeDS.twCC = TWCC_SUCCESS; activeDS.twCC = TWCC_SUCCESS;
} }
return twRC; return twRC;
#endif
} }
/* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */ /* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin, TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin,
TW_MEMREF pData) TW_MEMREF pData)
{ {
#ifndef SONAME_LIBSANE
return TWRC_FAILURE;
#else
TW_UINT16 twRC = TWRC_SUCCESS; TW_UINT16 twRC = TWRC_SUCCESS;
pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData; pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
SANE_Status status;
TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n"); TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
@ -382,19 +396,33 @@ TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin,
} }
else else
{ {
/* FIXME: we shouldn't return 1 here */ pPendingXfers->Count = -1;
pPendingXfers->Count = 1; if (! activeDS.sane_started)
{
status = psane_start (activeDS.deviceHandle);
if (status != SANE_STATUS_GOOD)
{
TRACE("PENDINGXFERS/MSG_GET sane_start returns %s\n", psane_strstatus(status));
pPendingXfers->Count = 0;
}
else
activeDS.sane_started = TRUE;
}
twRC = TWRC_SUCCESS; twRC = TWRC_SUCCESS;
activeDS.twCC = TWCC_SUCCESS; activeDS.twCC = TWCC_SUCCESS;
} }
return twRC; return twRC;
#endif
} }
/* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */ /* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin, TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin,
TW_MEMREF pData) TW_MEMREF pData)
{ {
#ifndef SONAME_LIBSANE
return TWRC_FAILURE;
#else
TW_UINT16 twRC = TWRC_SUCCESS; TW_UINT16 twRC = TWRC_SUCCESS;
pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData; pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
@ -411,9 +439,16 @@ TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin,
activeDS.currentState = 5; activeDS.currentState = 5;
twRC = TWRC_SUCCESS; twRC = TWRC_SUCCESS;
activeDS.twCC = TWCC_SUCCESS; activeDS.twCC = TWCC_SUCCESS;
if (activeDS.sane_started)
{
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
}
} }
return twRC; return twRC;
#endif
} }
/* DG_CONTROL/DAT_PENDINGXFERS/MSG_STOPFEEDER */ /* DG_CONTROL/DAT_PENDINGXFERS/MSG_STOPFEEDER */

View File

@ -106,6 +106,7 @@ TW_UINT16 SANE_ImageInfoGet (pTW_IDENTITY pOrigin,
{ {
WARN("psane_get_parameters: %s\n", psane_strstatus (status)); WARN("psane_get_parameters: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR; activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -230,6 +231,8 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
ScanningDialogBox(activeDS.progressWnd,0); ScanningDialogBox(activeDS.progressWnd,0);
if (! activeDS.sane_started)
{
status = psane_start (activeDS.deviceHandle); status = psane_start (activeDS.deviceHandle);
if (status != SANE_STATUS_GOOD) if (status != SANE_STATUS_GOOD)
{ {
@ -238,6 +241,8 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
activeDS.twCC = TWCC_OPERATIONERROR; activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE; return TWRC_FAILURE;
} }
activeDS.sane_started = TRUE;
}
status = psane_get_parameters (activeDS.deviceHandle, status = psane_get_parameters (activeDS.deviceHandle,
&activeDS.sane_param); &activeDS.sane_param);
@ -247,6 +252,7 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
{ {
WARN("psane_get_parameters: %s\n", psane_strstatus (status)); WARN("psane_get_parameters: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR; activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -263,6 +269,7 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
if (pImageMemXfer->Memory.Length < activeDS.sane_param.bytes_per_line) if (pImageMemXfer->Memory.Length < activeDS.sane_param.bytes_per_line)
{ {
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_BADVALUE; activeDS.twCC = TWCC_BADVALUE;
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -309,6 +316,7 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
ScanningDialogBox(activeDS.progressWnd, -1); ScanningDialogBox(activeDS.progressWnd, -1);
TRACE("psane_read: %s\n", psane_strstatus (status)); TRACE("psane_read: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
twRC = TWRC_XFERDONE; twRC = TWRC_XFERDONE;
} }
activeDS.twCC = TWRC_SUCCESS; activeDS.twCC = TWRC_SUCCESS;
@ -318,6 +326,7 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
ScanningDialogBox(activeDS.progressWnd, -1); ScanningDialogBox(activeDS.progressWnd, -1);
WARN("psane_read: %s\n", psane_strstatus (status)); WARN("psane_read: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR; activeDS.twCC = TWCC_OPERATIONERROR;
twRC = TWRC_FAILURE; twRC = TWRC_FAILURE;
} }
@ -384,6 +393,8 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
else else
{ {
/* Transfer an image from the source to the application */ /* Transfer an image from the source to the application */
if (! activeDS.sane_started)
{
status = psane_start (activeDS.deviceHandle); status = psane_start (activeDS.deviceHandle);
if (status != SANE_STATUS_GOOD) if (status != SANE_STATUS_GOOD)
{ {
@ -392,6 +403,8 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
activeDS.twCC = TWCC_OPERATIONERROR; activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE; return TWRC_FAILURE;
} }
activeDS.sane_started = TRUE;
}
status = psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param); status = psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param);
activeDS.sane_param_valid = TRUE; activeDS.sane_param_valid = TRUE;
@ -399,6 +412,7 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
{ {
WARN("psane_get_parameters: %s\n", psane_strstatus (status)); WARN("psane_get_parameters: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR; activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -413,6 +427,7 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
{ {
FIXME("For NATIVE, we support only 1 bit monochrome and 8 bit Grayscale, not %d\n", activeDS.sane_param.depth); FIXME("For NATIVE, we support only 1 bit monochrome and 8 bit Grayscale, not %d\n", activeDS.sane_param.depth);
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR; activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -421,6 +436,7 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
{ {
FIXME("For NATIVE, we support only GRAY and RGB, not %d\n", activeDS.sane_param.format); FIXME("For NATIVE, we support only GRAY and RGB, not %d\n", activeDS.sane_param.format);
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR; activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -440,6 +456,7 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
if (!header) if (!header)
{ {
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_LOWMEMORY; activeDS.twCC = TWCC_LOWMEMORY;
if (hDIB) if (hDIB)
GlobalFree(hDIB); GlobalFree(hDIB);
@ -497,12 +514,14 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
{ {
WARN("psane_read: %s, reading line %d\n", psane_strstatus(status), i); WARN("psane_read: %s, reading line %d\n", psane_strstatus(status), i);
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR; activeDS.twCC = TWCC_OPERATIONERROR;
GlobalFree(hDIB); GlobalFree(hDIB);
return TWRC_FAILURE; return TWRC_FAILURE;
} }
psane_cancel (activeDS.deviceHandle); psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
*pHandle = (TW_UINT32)hDIB; *pHandle = (TW_UINT32)hDIB;
twRC = TWRC_XFERDONE; twRC = TWRC_XFERDONE;
activeDS.twCC = TWCC_SUCCESS; activeDS.twCC = TWCC_SUCCESS;

View File

@ -71,6 +71,7 @@ struct tagActiveDS
SANE_Parameters sane_param; /* parameters about the image SANE_Parameters sane_param; /* parameters about the image
transferred */ transferred */
BOOL sane_param_valid; /* true if valid sane_param*/ BOOL sane_param_valid; /* true if valid sane_param*/
BOOL sane_started; /* If sane_start has been called */
INT deviceIndex; /* index of the current device */ INT deviceIndex; /* index of the current device */
#endif #endif
/* Capabilities */ /* Capabilities */