Commit e472c49a authored by Jeremy White's avatar Jeremy White Committed by Alexandre Julliard

sane.ds: More correctly detect an end of scan job from sane; this enables…

sane.ds: More correctly detect an end of scan job from sane; this enables Acrobat to pull multiple pages in one scan.
parent 28b708ca
......@@ -695,6 +695,7 @@ static TW_UINT16 SANE_ICAPResolution (pTW_CAPABILITY pCapability, TW_UINT16 acti
return twCC;
}
#ifdef SONAME_LIBSANE
static void convert_double_fix32(double d, TW_FIX32 *fix32)
{
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;
}
#ifdef SONAME_LIBSANE
static BOOL convert_sane_res_to_twain(double sane_res, SANE_Unit unit, TW_FIX32 *twain_res, TW_UINT16 twtype)
{
double d;
......
......@@ -335,8 +335,12 @@ TW_UINT16 SANE_PassThrough (pTW_IDENTITY pOrigin,
TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin,
TW_MEMREF pData)
{
#ifndef SONAME_LIBSANE
return TWRC_FAILURE;
#else
TW_UINT16 twRC = TWRC_SUCCESS;
pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
SANE_Status status;
TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_ENDXFER\n");
......@@ -347,31 +351,41 @@ TW_UINT16 SANE_PendingXfersEndXfer (pTW_IDENTITY pOrigin,
}
else
{
if (pPendingXfers->Count != 0)
{
pPendingXfers->Count --;
activeDS.currentState = 6;
}
else
pPendingXfers->Count = -1;
activeDS.currentState = 6;
if (! activeDS.sane_started)
{
activeDS.currentState = 5;
/* Notify the application that it can close the data source */
if (activeDS.windowMessage)
PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_CLOSEDSREQ, 0);
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;
/* Notify the application that it can close the data source */
if (activeDS.windowMessage)
PostMessageA(activeDS.hwndOwner, activeDS.windowMessage, MSG_CLOSEDSREQ, 0);
}
else
activeDS.sane_started = TRUE;
}
twRC = TWRC_SUCCESS;
activeDS.twCC = TWCC_SUCCESS;
}
return twRC;
#endif
}
/* DG_CONTROL/DAT_PENDINGXFERS/MSG_GET */
TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin,
TW_MEMREF pData)
{
#ifndef SONAME_LIBSANE
return TWRC_FAILURE;
#else
TW_UINT16 twRC = TWRC_SUCCESS;
pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
SANE_Status status;
TRACE("DG_CONTROL/DAT_PENDINGXFERS/MSG_GET\n");
......@@ -382,19 +396,33 @@ TW_UINT16 SANE_PendingXfersGet (pTW_IDENTITY pOrigin,
}
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;
activeDS.twCC = TWCC_SUCCESS;
}
return twRC;
#endif
}
/* DG_CONTROL/DAT_PENDINGXFERS/MSG_RESET */
TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin,
TW_MEMREF pData)
{
#ifndef SONAME_LIBSANE
return TWRC_FAILURE;
#else
TW_UINT16 twRC = TWRC_SUCCESS;
pTW_PENDINGXFERS pPendingXfers = (pTW_PENDINGXFERS) pData;
......@@ -411,9 +439,16 @@ TW_UINT16 SANE_PendingXfersReset (pTW_IDENTITY pOrigin,
activeDS.currentState = 5;
twRC = TWRC_SUCCESS;
activeDS.twCC = TWCC_SUCCESS;
if (activeDS.sane_started)
{
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
}
}
return twRC;
#endif
}
/* DG_CONTROL/DAT_PENDINGXFERS/MSG_STOPFEEDER */
......
......@@ -106,6 +106,7 @@ TW_UINT16 SANE_ImageInfoGet (pTW_IDENTITY pOrigin,
{
WARN("psane_get_parameters: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE;
}
......@@ -230,13 +231,17 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
ScanningDialogBox(activeDS.progressWnd,0);
status = psane_start (activeDS.deviceHandle);
if (status != SANE_STATUS_GOOD)
if (! activeDS.sane_started)
{
WARN("psane_start: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle);
activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE;
status = psane_start (activeDS.deviceHandle);
if (status != SANE_STATUS_GOOD)
{
WARN("psane_start: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle);
activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE;
}
activeDS.sane_started = TRUE;
}
status = psane_get_parameters (activeDS.deviceHandle,
......@@ -247,6 +252,7 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
{
WARN("psane_get_parameters: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE;
}
......@@ -263,6 +269,7 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
if (pImageMemXfer->Memory.Length < activeDS.sane_param.bytes_per_line)
{
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_BADVALUE;
return TWRC_FAILURE;
}
......@@ -309,6 +316,7 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
ScanningDialogBox(activeDS.progressWnd, -1);
TRACE("psane_read: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
twRC = TWRC_XFERDONE;
}
activeDS.twCC = TWRC_SUCCESS;
......@@ -318,6 +326,7 @@ TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
ScanningDialogBox(activeDS.progressWnd, -1);
WARN("psane_read: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR;
twRC = TWRC_FAILURE;
}
......@@ -384,13 +393,17 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
else
{
/* Transfer an image from the source to the application */
status = psane_start (activeDS.deviceHandle);
if (status != SANE_STATUS_GOOD)
if (! activeDS.sane_started)
{
WARN("psane_start: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle);
activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE;
status = psane_start (activeDS.deviceHandle);
if (status != SANE_STATUS_GOOD)
{
WARN("psane_start: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle);
activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE;
}
activeDS.sane_started = TRUE;
}
status = psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param);
......@@ -399,6 +412,7 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
{
WARN("psane_get_parameters: %s\n", psane_strstatus (status));
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR;
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);
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR;
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);
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE;
}
......@@ -440,6 +456,7 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
if (!header)
{
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_LOWMEMORY;
if (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);
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
activeDS.twCC = TWCC_OPERATIONERROR;
GlobalFree(hDIB);
return TWRC_FAILURE;
}
psane_cancel (activeDS.deviceHandle);
activeDS.sane_started = FALSE;
*pHandle = (TW_UINT32)hDIB;
twRC = TWRC_XFERDONE;
activeDS.twCC = TWCC_SUCCESS;
......
......@@ -71,6 +71,7 @@ struct tagActiveDS
SANE_Parameters sane_param; /* parameters about the image
transferred */
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 */
#endif
/* Capabilities */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment