2002-03-21 03:58:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2000 Corel Corporation
|
2006-02-21 15:41:07 +01:00
|
|
|
* Copyright 2006 CodeWeavers, Aric Stewart
|
2002-03-21 03:58:39 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-21 03:58:39 +01:00
|
|
|
*/
|
|
|
|
|
2003-08-22 07:05:56 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2011-09-05 17:22:50 +02:00
|
|
|
#include "sane_i.h"
|
2002-03-21 03:58:39 +01:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(twain);
|
|
|
|
|
|
|
|
/* DG_IMAGE/DAT_IMAGEINFO/MSG_GET */
|
2006-05-08 20:05:42 +02:00
|
|
|
TW_UINT16 SANE_ImageInfoGet (pTW_IDENTITY pOrigin,
|
2002-03-21 03:58:39 +01:00
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS;
|
|
|
|
pTW_IMAGEINFO pImageInfo = (pTW_IMAGEINFO) pData;
|
2021-10-25 17:32:04 +02:00
|
|
|
int resolution;
|
2002-03-21 03:58:39 +01:00
|
|
|
|
|
|
|
TRACE("DG_IMAGE/DAT_IMAGEINFO/MSG_GET\n");
|
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
if (activeDS.currentState != 6 && activeDS.currentState != 7)
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
|
|
|
twRC = TWRC_FAILURE;
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_SEQERROR;
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-08 20:05:42 +02:00
|
|
|
if (activeDS.currentState == 6)
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
2004-09-14 21:31:22 +02:00
|
|
|
/* return general image description information about the image about to be transferred */
|
2006-02-21 15:41:07 +01:00
|
|
|
TRACE("Getting parameters\n");
|
2021-10-27 15:27:52 +02:00
|
|
|
if (SANE_CALL( get_params, &activeDS.frame_params ))
|
2008-11-19 21:29:53 +01:00
|
|
|
{
|
2021-10-27 13:25:00 +02:00
|
|
|
WARN("sane_get_parameters failed\n");
|
2021-10-27 15:27:52 +02:00
|
|
|
SANE_CALL( cancel_device, NULL );
|
2008-11-19 21:29:53 +01:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
|
|
|
|
2021-10-25 17:32:04 +02:00
|
|
|
if (sane_option_get_int("resolution", &resolution) == TWCC_SUCCESS)
|
2009-02-13 20:14:30 +01:00
|
|
|
pImageInfo->XResolution.Whole = pImageInfo->YResolution.Whole = resolution;
|
|
|
|
else
|
|
|
|
pImageInfo->XResolution.Whole = pImageInfo->YResolution.Whole = -1;
|
2002-03-21 03:58:39 +01:00
|
|
|
pImageInfo->XResolution.Frac = 0;
|
|
|
|
pImageInfo->YResolution.Frac = 0;
|
2021-10-27 13:25:00 +02:00
|
|
|
pImageInfo->ImageWidth = activeDS.frame_params.pixels_per_line;
|
|
|
|
pImageInfo->ImageLength = activeDS.frame_params.lines;
|
2006-02-21 15:41:07 +01:00
|
|
|
|
2021-10-27 13:25:00 +02:00
|
|
|
TRACE("Bits per Sample %i\n",activeDS.frame_params.depth);
|
|
|
|
TRACE("Frame Format %i\n",activeDS.frame_params.format);
|
2006-02-21 15:41:07 +01:00
|
|
|
|
2021-10-27 13:25:00 +02:00
|
|
|
switch (activeDS.frame_params.format)
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
2021-10-27 13:25:00 +02:00
|
|
|
case FMT_RGB:
|
|
|
|
pImageInfo->BitsPerPixel = activeDS.frame_params.depth * 3;
|
2006-02-21 15:41:07 +01:00
|
|
|
pImageInfo->Compression = TWCP_NONE;
|
2002-03-21 03:58:39 +01:00
|
|
|
pImageInfo->Planar = TRUE;
|
2006-02-21 15:41:07 +01:00
|
|
|
pImageInfo->SamplesPerPixel = 3;
|
2021-10-27 13:25:00 +02:00
|
|
|
pImageInfo->BitsPerSample[0] = activeDS.frame_params.depth;
|
|
|
|
pImageInfo->BitsPerSample[1] = activeDS.frame_params.depth;
|
|
|
|
pImageInfo->BitsPerSample[2] = activeDS.frame_params.depth;
|
2002-03-21 03:58:39 +01:00
|
|
|
pImageInfo->PixelType = TWPT_RGB;
|
2021-10-27 13:25:00 +02:00
|
|
|
break;
|
|
|
|
case FMT_GRAY:
|
|
|
|
pImageInfo->BitsPerPixel = activeDS.frame_params.depth;
|
2006-03-22 20:34:44 +01:00
|
|
|
pImageInfo->Compression = TWCP_NONE;
|
|
|
|
pImageInfo->Planar = TRUE;
|
|
|
|
pImageInfo->SamplesPerPixel = 1;
|
2021-10-27 13:25:00 +02:00
|
|
|
pImageInfo->BitsPerSample[0] = activeDS.frame_params.depth;
|
|
|
|
if (activeDS.frame_params.depth == 1)
|
2009-03-03 00:08:11 +01:00
|
|
|
pImageInfo->PixelType = TWPT_BW;
|
|
|
|
else
|
|
|
|
pImageInfo->PixelType = TWPT_GRAY;
|
2021-10-27 13:25:00 +02:00
|
|
|
break;
|
|
|
|
case FMT_OTHER:
|
2006-02-21 15:41:07 +01:00
|
|
|
twRC = TWRC_FAILURE;
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_SEQERROR;
|
2021-10-27 13:25:00 +02:00
|
|
|
break;
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return twRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DG_IMAGE/DAT_IMAGELAYOUT/MSG_GET */
|
2009-03-11 16:28:13 +01:00
|
|
|
TW_UINT16 SANE_ImageLayoutGet (pTW_IDENTITY pOrigin,
|
2002-03-21 03:58:39 +01:00
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
2009-03-11 16:28:13 +01:00
|
|
|
TW_IMAGELAYOUT *img = (TW_IMAGELAYOUT *) pData;
|
2021-10-25 18:34:53 +02:00
|
|
|
int tlx, tly, brx, bry;
|
2021-10-25 17:32:04 +02:00
|
|
|
TW_UINT16 rc;
|
2009-03-11 16:28:13 +01:00
|
|
|
|
|
|
|
TRACE("DG_IMAGE/DAT_IMAGELAYOUT/MSG_GET\n");
|
|
|
|
|
2021-10-25 18:34:53 +02:00
|
|
|
rc = sane_option_get_scan_area( &tlx, &tly, &brx, &bry );
|
2021-10-25 17:32:04 +02:00
|
|
|
if (rc != TWCC_SUCCESS)
|
2009-03-11 16:28:13 +01:00
|
|
|
{
|
2021-10-25 17:32:04 +02:00
|
|
|
activeDS.twCC = rc;
|
2009-03-11 16:28:13 +01:00
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
2021-10-25 18:34:53 +02:00
|
|
|
img->Frame.Left = convert_sane_res_to_twain( tlx );
|
|
|
|
img->Frame.Top = convert_sane_res_to_twain( tly );
|
|
|
|
img->Frame.Right = convert_sane_res_to_twain( brx );
|
|
|
|
img->Frame.Bottom = convert_sane_res_to_twain( bry );
|
2009-03-11 16:28:13 +01:00
|
|
|
img->DocumentNumber = 1;
|
|
|
|
img->PageNumber = 1;
|
|
|
|
img->FrameNumber = 1;
|
|
|
|
|
|
|
|
activeDS.twCC = TWCC_SUCCESS;
|
|
|
|
return TWRC_SUCCESS;
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DG_IMAGE/DAT_IMAGELAYOUT/MSG_GETDEFAULT */
|
2006-05-08 20:05:42 +02:00
|
|
|
TW_UINT16 SANE_ImageLayoutGetDefault (pTW_IDENTITY pOrigin,
|
2002-03-21 03:58:39 +01:00
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
|
|
|
FIXME ("stub!\n");
|
|
|
|
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DG_IMAGE/DAT_IMAGELAYOUT/MSG_RESET */
|
2006-05-08 20:05:42 +02:00
|
|
|
TW_UINT16 SANE_ImageLayoutReset (pTW_IDENTITY pOrigin,
|
2002-03-21 03:58:39 +01:00
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
|
|
|
FIXME ("stub!\n");
|
|
|
|
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DG_IMAGE/DAT_IMAGELAYOUT/MSG_SET */
|
2009-03-11 16:28:13 +01:00
|
|
|
TW_UINT16 SANE_ImageLayoutSet (pTW_IDENTITY pOrigin,
|
2002-03-21 03:58:39 +01:00
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
2009-03-11 16:28:13 +01:00
|
|
|
TW_IMAGELAYOUT *img = (TW_IMAGELAYOUT *) pData;
|
|
|
|
BOOL changed = FALSE;
|
|
|
|
TW_UINT16 twrc;
|
2021-10-25 18:34:53 +02:00
|
|
|
int tlx, tly, brx, bry;
|
2009-03-11 16:28:13 +01:00
|
|
|
|
|
|
|
TRACE("DG_IMAGE/DAT_IMAGELAYOUT/MSG_SET\n");
|
|
|
|
TRACE("Frame: [Left %x.%x|Top %x.%x|Right %x.%x|Bottom %x.%x]\n",
|
|
|
|
img->Frame.Left.Whole, img->Frame.Left.Frac,
|
|
|
|
img->Frame.Top.Whole, img->Frame.Top.Frac,
|
|
|
|
img->Frame.Right.Whole, img->Frame.Right.Frac,
|
|
|
|
img->Frame.Bottom.Whole, img->Frame.Bottom.Frac);
|
|
|
|
|
2021-10-25 18:34:53 +02:00
|
|
|
tlx = img->Frame.Left.Whole * 65536 + img->Frame.Left.Frac;
|
|
|
|
tly = img->Frame.Top.Whole * 65536 + img->Frame.Top.Frac;
|
|
|
|
brx = img->Frame.Right.Whole * 65536 + img->Frame.Right.Frac;
|
|
|
|
bry = img->Frame.Bottom.Whole * 65536 + img->Frame.Bottom.Frac;
|
2009-03-11 16:28:13 +01:00
|
|
|
|
2021-10-25 18:34:53 +02:00
|
|
|
twrc = sane_option_set_scan_area( tlx, tly, brx, bry, &changed );
|
2009-03-11 16:28:13 +01:00
|
|
|
if (twrc != TWRC_SUCCESS)
|
|
|
|
return (twrc);
|
|
|
|
|
|
|
|
activeDS.twCC = TWCC_SUCCESS;
|
|
|
|
return changed ? TWRC_CHECKSTATUS : TWRC_SUCCESS;
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DG_IMAGE/DAT_IMAGEMEMXFER/MSG_GET */
|
2006-05-08 20:05:42 +02:00
|
|
|
TW_UINT16 SANE_ImageMemXferGet (pTW_IDENTITY pOrigin,
|
2002-03-21 03:58:39 +01:00
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
2006-02-21 15:41:07 +01:00
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS;
|
|
|
|
pTW_IMAGEMEMXFER pImageMemXfer = (pTW_IMAGEMEMXFER) pData;
|
|
|
|
|
|
|
|
TRACE ("DG_IMAGE/DAT_IMAGEMEMXFER/MSG_GET\n");
|
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
if (activeDS.currentState < 6 || activeDS.currentState > 7)
|
2006-02-21 15:41:07 +01:00
|
|
|
{
|
|
|
|
twRC = TWRC_FAILURE;
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_SEQERROR;
|
2006-02-21 15:41:07 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
struct read_data_params params;
|
2006-02-21 15:41:07 +01:00
|
|
|
LPBYTE buffer;
|
2021-10-27 15:27:52 +02:00
|
|
|
int retlen;
|
2006-02-21 15:41:07 +01:00
|
|
|
int rows;
|
|
|
|
|
|
|
|
/* Transfer an image from the source to the application */
|
2006-05-08 20:05:42 +02:00
|
|
|
if (activeDS.currentState == 6)
|
2006-02-21 15:41:07 +01:00
|
|
|
{
|
2006-03-22 20:34:22 +01:00
|
|
|
|
|
|
|
/* trigger scanning dialog */
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.progressWnd = ScanningDialogBox(NULL,0);
|
2006-03-22 20:34:22 +01:00
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
ScanningDialogBox(activeDS.progressWnd,0);
|
2006-03-22 20:34:22 +01:00
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
if (SANE_CALL( start_device, NULL ))
|
2006-02-21 15:41:07 +01:00
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
|
|
|
return TWRC_FAILURE;
|
2006-02-21 15:41:07 +01:00
|
|
|
}
|
|
|
|
|
2021-10-27 13:25:00 +02:00
|
|
|
if (get_sane_params( &activeDS.frame_params ))
|
2006-02-21 15:41:07 +01:00
|
|
|
{
|
2021-10-27 13:25:00 +02:00
|
|
|
WARN("sane_get_parameters failed\n");
|
2021-10-27 15:27:52 +02:00
|
|
|
SANE_CALL( cancel_device, NULL );
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
2006-02-21 15:41:07 +01:00
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Acquiring image %dx%dx%d bits (format=%d last=%d) from sane...\n"
|
2021-10-27 13:25:00 +02:00
|
|
|
, activeDS.frame_params.pixels_per_line, activeDS.frame_params.lines,
|
|
|
|
activeDS.frame_params.depth, activeDS.frame_params.format,
|
|
|
|
activeDS.frame_params.last_frame);
|
2006-02-21 15:41:07 +01:00
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.currentState = 7;
|
2006-02-21 15:41:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* access memory buffer */
|
2021-10-27 13:25:00 +02:00
|
|
|
if (pImageMemXfer->Memory.Length < activeDS.frame_params.bytes_per_line)
|
2006-02-21 15:41:07 +01:00
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
SANE_CALL( cancel_device, NULL );
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_BADVALUE;
|
2006-02-21 15:41:07 +01:00
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pImageMemXfer->Memory.Flags & TWMF_HANDLE)
|
|
|
|
{
|
|
|
|
FIXME("Memory Handle, may not be locked correctly\n");
|
|
|
|
buffer = LocalLock(pImageMemXfer->Memory.TheMem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
buffer = pImageMemXfer->Memory.TheMem;
|
|
|
|
|
|
|
|
memset(buffer,0,pImageMemXfer->Memory.Length);
|
|
|
|
|
|
|
|
/* must fill full lines */
|
2021-10-27 15:27:52 +02:00
|
|
|
rows = pImageMemXfer->Memory.Length / activeDS.frame_params.bytes_per_line;
|
|
|
|
params.buffer = buffer;
|
|
|
|
params.len = activeDS.frame_params.bytes_per_line * rows;
|
|
|
|
params.retlen = &retlen;
|
2006-02-21 15:41:07 +01:00
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
twRC = SANE_CALL( read_data, ¶ms );
|
|
|
|
if (twRC == TWCC_SUCCESS)
|
2006-02-21 15:41:07 +01:00
|
|
|
{
|
|
|
|
pImageMemXfer->Compression = TWCP_NONE;
|
2021-10-27 13:25:00 +02:00
|
|
|
pImageMemXfer->BytesPerRow = activeDS.frame_params.bytes_per_line;
|
|
|
|
pImageMemXfer->Columns = activeDS.frame_params.pixels_per_line;
|
2006-02-21 15:41:07 +01:00
|
|
|
pImageMemXfer->Rows = rows;
|
|
|
|
pImageMemXfer->XOffset = 0;
|
|
|
|
pImageMemXfer->YOffset = 0;
|
2021-10-27 15:27:52 +02:00
|
|
|
pImageMemXfer->BytesWritten = retlen;
|
2006-02-21 15:41:07 +01:00
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
ScanningDialogBox(activeDS.progressWnd, retlen);
|
2006-03-22 20:34:22 +01:00
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
if (retlen < activeDS.frame_params.bytes_per_line * rows)
|
2006-02-21 15:41:07 +01:00
|
|
|
{
|
2006-05-08 20:05:42 +02:00
|
|
|
ScanningDialogBox(activeDS.progressWnd, -1);
|
2021-10-27 15:27:52 +02:00
|
|
|
TRACE("sane_read: %u / %u\n", retlen, activeDS.frame_params.bytes_per_line * rows);
|
|
|
|
SANE_CALL( cancel_device, NULL );
|
2006-02-21 15:41:07 +01:00
|
|
|
twRC = TWRC_XFERDONE;
|
|
|
|
}
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWRC_SUCCESS;
|
2006-02-21 15:41:07 +01:00
|
|
|
}
|
2021-10-27 15:27:52 +02:00
|
|
|
else
|
2006-02-21 15:41:07 +01:00
|
|
|
{
|
2006-05-08 20:05:42 +02:00
|
|
|
ScanningDialogBox(activeDS.progressWnd, -1);
|
2021-10-27 15:27:52 +02:00
|
|
|
WARN("sane_read: %u\n", twRC);
|
|
|
|
SANE_CALL( cancel_device, NULL );
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
2006-02-21 15:41:07 +01:00
|
|
|
twRC = TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pImageMemXfer->Memory.Flags & TWMF_HANDLE)
|
|
|
|
LocalUnlock(pImageMemXfer->Memory.TheMem);
|
|
|
|
|
|
|
|
return twRC;
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET */
|
2006-05-08 20:05:42 +02:00
|
|
|
TW_UINT16 SANE_ImageNativeXferGet (pTW_IDENTITY pOrigin,
|
2002-03-21 03:58:39 +01:00
|
|
|
TW_MEMREF pData)
|
|
|
|
{
|
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS;
|
|
|
|
pTW_UINT32 pHandle = (pTW_UINT32) pData;
|
2009-02-13 20:14:58 +01:00
|
|
|
HANDLE hDIB;
|
|
|
|
BITMAPINFOHEADER *header = NULL;
|
|
|
|
int dib_bytes;
|
|
|
|
int dib_bytes_per_line;
|
|
|
|
BYTE *line;
|
2009-03-03 00:08:11 +01:00
|
|
|
RGBQUAD *colors;
|
|
|
|
int color_size = 0;
|
2009-02-13 20:14:58 +01:00
|
|
|
int i;
|
2009-03-03 00:08:11 +01:00
|
|
|
BYTE *p;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-03-21 03:58:39 +01:00
|
|
|
TRACE("DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET\n");
|
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
if (activeDS.currentState != 6)
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
|
|
|
twRC = TWRC_FAILURE;
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_SEQERROR;
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Transfer an image from the source to the application */
|
2021-10-27 15:27:52 +02:00
|
|
|
if (SANE_CALL( start_device, NULL ))
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
|
|
|
return TWRC_FAILURE;
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
if (SANE_CALL( get_params, &activeDS.frame_params ))
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
2021-10-27 13:25:00 +02:00
|
|
|
WARN("sane_get_parameters failed\n");
|
2021-10-27 15:27:52 +02:00
|
|
|
SANE_CALL( cancel_device, NULL );
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
2002-03-21 03:58:39 +01:00
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
2021-10-27 13:25:00 +02:00
|
|
|
switch (activeDS.frame_params.format)
|
2009-02-13 20:14:58 +01:00
|
|
|
{
|
2021-10-27 13:25:00 +02:00
|
|
|
case FMT_GRAY:
|
|
|
|
if (activeDS.frame_params.depth == 8)
|
2009-03-03 00:08:11 +01:00
|
|
|
color_size = (1 << 8) * sizeof(*colors);
|
2021-10-27 13:25:00 +02:00
|
|
|
else if (activeDS.frame_params.depth == 1)
|
2009-03-03 00:08:11 +01:00
|
|
|
;
|
|
|
|
else
|
|
|
|
{
|
2021-10-27 13:25:00 +02:00
|
|
|
FIXME("For NATIVE, we support only 1 bit monochrome and 8 bit Grayscale, not %d\n", activeDS.frame_params.depth);
|
2021-10-27 15:27:52 +02:00
|
|
|
SANE_CALL( cancel_device, NULL );
|
2009-03-03 00:08:11 +01:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
2021-10-27 13:25:00 +02:00
|
|
|
break;
|
|
|
|
case FMT_RGB:
|
|
|
|
break;
|
2021-10-27 15:27:52 +02:00
|
|
|
case FMT_OTHER:
|
|
|
|
FIXME("For NATIVE, we support only GRAY and RGB\n");
|
|
|
|
SANE_CALL( cancel_device, NULL );
|
2009-02-13 20:14:58 +01:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Acquiring image %dx%dx%d bits (format=%d last=%d bpl=%d) from sane...\n"
|
2021-10-27 13:25:00 +02:00
|
|
|
, activeDS.frame_params.pixels_per_line, activeDS.frame_params.lines,
|
|
|
|
activeDS.frame_params.depth, activeDS.frame_params.format,
|
|
|
|
activeDS.frame_params.last_frame, activeDS.frame_params.bytes_per_line);
|
2002-03-21 03:58:39 +01:00
|
|
|
|
2021-10-27 13:25:00 +02:00
|
|
|
dib_bytes_per_line = ((activeDS.frame_params.bytes_per_line + 3) / 4) * 4;
|
|
|
|
dib_bytes = activeDS.frame_params.lines * dib_bytes_per_line;
|
2009-02-13 20:14:58 +01:00
|
|
|
|
2009-03-03 00:08:11 +01:00
|
|
|
hDIB = GlobalAlloc(GMEM_ZEROINIT, dib_bytes + sizeof(*header) + color_size);
|
2009-02-13 20:14:58 +01:00
|
|
|
if (hDIB)
|
|
|
|
header = GlobalLock(hDIB);
|
|
|
|
|
|
|
|
if (!header)
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
SANE_CALL( cancel_device, NULL );
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_LOWMEMORY;
|
2009-02-13 20:14:58 +01:00
|
|
|
if (hDIB)
|
|
|
|
GlobalFree(hDIB);
|
2002-03-21 03:58:39 +01:00
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-02-13 20:14:58 +01:00
|
|
|
header->biSize = sizeof (*header);
|
2021-10-27 13:25:00 +02:00
|
|
|
header->biWidth = activeDS.frame_params.pixels_per_line;
|
|
|
|
header->biHeight = activeDS.frame_params.lines;
|
2009-02-13 20:14:58 +01:00
|
|
|
header->biPlanes = 1;
|
|
|
|
header->biCompression = BI_RGB;
|
2021-10-27 13:25:00 +02:00
|
|
|
switch (activeDS.frame_params.format)
|
|
|
|
{
|
|
|
|
case FMT_RGB:
|
|
|
|
header->biBitCount = activeDS.frame_params.depth * 3;
|
|
|
|
break;
|
|
|
|
case FMT_GRAY:
|
|
|
|
header->biBitCount = activeDS.frame_params.depth;
|
|
|
|
break;
|
|
|
|
case FMT_OTHER:
|
|
|
|
break;
|
|
|
|
}
|
2009-02-13 20:14:58 +01:00
|
|
|
header->biSizeImage = dib_bytes;
|
|
|
|
header->biXPelsPerMeter = 0;
|
|
|
|
header->biYPelsPerMeter = 0;
|
|
|
|
header->biClrUsed = 0;
|
|
|
|
header->biClrImportant = 0;
|
|
|
|
|
2009-03-03 00:08:11 +01:00
|
|
|
p = (BYTE *)(header + 1);
|
|
|
|
|
|
|
|
if (color_size > 0)
|
|
|
|
{
|
|
|
|
colors = (RGBQUAD *) p;
|
|
|
|
p += color_size;
|
|
|
|
for (i = 0; i < (color_size / sizeof(*colors)); i++)
|
|
|
|
colors[i].rgbBlue = colors[i].rgbRed = colors[i].rgbGreen = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-13 20:14:58 +01:00
|
|
|
/* Sane returns data in top down order. Acrobat does best with
|
|
|
|
a bottom up DIB being returned. */
|
2021-10-27 13:25:00 +02:00
|
|
|
line = p + (activeDS.frame_params.lines - 1) * dib_bytes_per_line;
|
|
|
|
for (i = activeDS.frame_params.lines - 1; i >= 0; i--)
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
int retlen;
|
|
|
|
struct read_data_params params = { line, activeDS.frame_params.bytes_per_line, &retlen };
|
|
|
|
|
2009-02-13 20:14:58 +01:00
|
|
|
activeDS.progressWnd = ScanningDialogBox(activeDS.progressWnd,
|
2021-10-27 13:25:00 +02:00
|
|
|
((activeDS.frame_params.lines - 1 - i) * 100)
|
2009-02-13 20:14:58 +01:00
|
|
|
/
|
2021-10-27 13:25:00 +02:00
|
|
|
(activeDS.frame_params.lines - 1));
|
2002-03-21 03:58:39 +01:00
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
twRC = SANE_CALL( read_data, ¶ms );
|
|
|
|
if (twRC != TWCC_SUCCESS) break;
|
|
|
|
if (retlen < activeDS.frame_params.bytes_per_line) break;
|
2009-02-13 20:14:58 +01:00
|
|
|
line -= dib_bytes_per_line;
|
|
|
|
}
|
|
|
|
activeDS.progressWnd = ScanningDialogBox(activeDS.progressWnd, -1);
|
|
|
|
|
|
|
|
GlobalUnlock(hDIB);
|
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
if (twRC != TWCC_SUCCESS)
|
2009-02-13 20:14:58 +01:00
|
|
|
{
|
2021-10-27 15:27:52 +02:00
|
|
|
WARN("sane_read: %u, reading line %d\n", twRC, i);
|
|
|
|
SANE_CALL( cancel_device, NULL );
|
2009-02-13 20:14:58 +01:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
|
|
|
GlobalFree(hDIB);
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2021-10-27 15:27:52 +02:00
|
|
|
SANE_CALL( cancel_device, NULL );
|
2009-05-28 15:24:58 +02:00
|
|
|
*pHandle = (UINT_PTR)hDIB;
|
2002-06-01 01:06:46 +02:00
|
|
|
twRC = TWRC_XFERDONE;
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_SUCCESS;
|
|
|
|
activeDS.currentState = 7;
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
|
|
|
return twRC;
|
|
|
|
}
|