From: Bernd Herd codeberg@herdsoft.com
Makes sure SANE transistions to the next frame on some backends. --- dlls/sane.ds/ds_image.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/dlls/sane.ds/ds_image.c b/dlls/sane.ds/ds_image.c index a1e7d91553b..fa39de85277 100644 --- a/dlls/sane.ds/ds_image.c +++ b/dlls/sane.ds/ds_image.c @@ -465,7 +465,11 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
twRC = SANE_CALL( read_data, ¶ms ); if (twRC != TWCC_SUCCESS) break; - if (retlen < activeDS.frame_params.bytes_per_line) break; + if (retlen < activeDS.frame_params.bytes_per_line) + { /* EOF reached */ + i = -2; + break; + } /* TWAIN: for 24 bit color DIBs, the pixels are stored in BGR order */ if (activeDS.frame_params.format == FMT_RGB && activeDS.frame_params.depth == 8) { @@ -489,6 +493,29 @@ TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin, return TWRC_FAILURE; }
+ while (i>=-1) + { + /* Some backends can deliver more data than requestes, especially + * in ADF-Mode. + * Dummy-Read until EOF, else the rest of the image might be read + * as another (nearly empty) frame. Observed with brscan4 driver */ + BYTE *line = (BYTE *) malloc(activeDS.frame_params.bytes_per_line); + if (line) + { + int retlen; + struct read_data_params params = { line, activeDS.frame_params.bytes_per_line, &retlen }; + if (SANE_CALL( read_data, ¶ms ) != TWCC_SUCCESS || + retlen != activeDS.frame_params.bytes_per_line) + { + // EOF reached + i = -2; + } + free(line); + } + } + + activeDS.progressWnd = ScanningDialogBox(activeDS.progressWnd, -1); + GlobalUnlock(hDIB);
*pHandle = (TW_HANDLE)hDIB;