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
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-08-22 07:05:56 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
2002-03-21 03:58:39 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "twain.h"
|
2006-05-08 20:05:42 +02:00
|
|
|
#include "sane_i.h"
|
2002-03-21 03:58:39 +01:00
|
|
|
#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)
|
|
|
|
{
|
2007-07-02 19:42:13 +02:00
|
|
|
#ifndef SONAME_LIBSANE
|
2002-03-21 03:58:39 +01:00
|
|
|
return TWRC_FAILURE;
|
|
|
|
#else
|
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS;
|
|
|
|
pTW_IMAGEINFO pImageInfo = (pTW_IMAGEINFO) pData;
|
|
|
|
SANE_Status status;
|
2009-02-13 20:14:30 +01:00
|
|
|
SANE_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 */
|
2007-03-14 19:10:03 +01:00
|
|
|
status = psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param);
|
2006-02-21 15:41:07 +01:00
|
|
|
TRACE("Getting parameters\n");
|
2008-11-19 21:29:53 +01:00
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
{
|
|
|
|
WARN("psane_get_parameters: %s\n", psane_strstatus (status));
|
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
2008-11-19 21:29:53 +01:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
activeDS.sane_param_valid = TRUE;
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
|
|
|
|
2009-02-13 20:14:30 +01:00
|
|
|
if (sane_option_get_int(activeDS.deviceHandle, "resolution", &resolution) == SANE_STATUS_GOOD)
|
|
|
|
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;
|
2006-05-08 20:05:42 +02:00
|
|
|
pImageInfo->ImageWidth = activeDS.sane_param.pixels_per_line;
|
|
|
|
pImageInfo->ImageLength = activeDS.sane_param.lines;
|
2006-02-21 15:41:07 +01:00
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
TRACE("Bits per Sample %i\n",activeDS.sane_param.depth);
|
|
|
|
TRACE("Frame Format %i\n",activeDS.sane_param.format);
|
2006-02-21 15:41:07 +01:00
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
if (activeDS.sane_param.format == SANE_FRAME_RGB )
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
2006-05-08 20:05:42 +02:00
|
|
|
pImageInfo->BitsPerPixel = activeDS.sane_param.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;
|
2006-05-08 20:05:42 +02:00
|
|
|
pImageInfo->BitsPerSample[0] = activeDS.sane_param.depth;
|
|
|
|
pImageInfo->BitsPerSample[1] = activeDS.sane_param.depth;
|
|
|
|
pImageInfo->BitsPerSample[2] = activeDS.sane_param.depth;
|
2002-03-21 03:58:39 +01:00
|
|
|
pImageInfo->PixelType = TWPT_RGB;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2006-05-08 20:05:42 +02:00
|
|
|
else if (activeDS.sane_param.format == SANE_FRAME_GRAY)
|
2006-03-22 20:34:44 +01:00
|
|
|
{
|
2006-05-08 20:05:42 +02:00
|
|
|
pImageInfo->BitsPerPixel = activeDS.sane_param.depth;
|
2006-03-22 20:34:44 +01:00
|
|
|
pImageInfo->Compression = TWCP_NONE;
|
|
|
|
pImageInfo->Planar = TRUE;
|
|
|
|
pImageInfo->SamplesPerPixel = 1;
|
2006-05-08 20:05:42 +02:00
|
|
|
pImageInfo->BitsPerSample[0] = activeDS.sane_param.depth;
|
2009-03-03 00:08:11 +01:00
|
|
|
if (activeDS.sane_param.depth == 1)
|
|
|
|
pImageInfo->PixelType = TWPT_BW;
|
|
|
|
else
|
|
|
|
pImageInfo->PixelType = TWPT_GRAY;
|
2006-03-22 20:34:44 +01:00
|
|
|
}
|
2006-02-21 15:41:07 +01:00
|
|
|
else
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
2006-05-08 20:05:42 +02:00
|
|
|
ERR("Unhandled source frame type %i\n",activeDS.sane_param.format);
|
2006-02-21 15:41:07 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return twRC;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
#ifndef SONAME_LIBSANE
|
2002-03-21 03:58:39 +01:00
|
|
|
return TWRC_FAILURE;
|
2009-03-11 16:28:13 +01:00
|
|
|
#else
|
|
|
|
TW_IMAGELAYOUT *img = (TW_IMAGELAYOUT *) pData;
|
|
|
|
SANE_Fixed tlx_current;
|
|
|
|
SANE_Fixed tly_current;
|
|
|
|
SANE_Fixed brx_current;
|
|
|
|
SANE_Fixed bry_current;
|
|
|
|
SANE_Status status;
|
|
|
|
|
|
|
|
TRACE("DG_IMAGE/DAT_IMAGELAYOUT/MSG_GET\n");
|
|
|
|
|
|
|
|
status = sane_option_probe_scan_area(activeDS.deviceHandle, "tl-x", &tlx_current, NULL, NULL, NULL, NULL);
|
|
|
|
if (status == SANE_STATUS_GOOD)
|
|
|
|
status = sane_option_probe_scan_area(activeDS.deviceHandle, "tl-y", &tly_current, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (status == SANE_STATUS_GOOD)
|
|
|
|
status = sane_option_probe_scan_area(activeDS.deviceHandle, "br-x", &brx_current, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (status == SANE_STATUS_GOOD)
|
|
|
|
status = sane_option_probe_scan_area(activeDS.deviceHandle, "br-y", &bry_current, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
{
|
|
|
|
activeDS.twCC = sane_status_to_twcc(status);
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_sane_res_to_twain(SANE_UNFIX(tlx_current), SANE_UNIT_MM, &img->Frame.Left, TWUN_INCHES);
|
|
|
|
convert_sane_res_to_twain(SANE_UNFIX(tly_current), SANE_UNIT_MM, &img->Frame.Top, TWUN_INCHES);
|
|
|
|
convert_sane_res_to_twain(SANE_UNFIX(brx_current), SANE_UNIT_MM, &img->Frame.Right, TWUN_INCHES);
|
|
|
|
convert_sane_res_to_twain(SANE_UNFIX(bry_current), SANE_UNIT_MM, &img->Frame.Bottom, TWUN_INCHES);
|
|
|
|
|
|
|
|
img->DocumentNumber = 1;
|
|
|
|
img->PageNumber = 1;
|
|
|
|
img->FrameNumber = 1;
|
|
|
|
|
|
|
|
activeDS.twCC = TWCC_SUCCESS;
|
|
|
|
return TWRC_SUCCESS;
|
|
|
|
#endif
|
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;
|
|
|
|
}
|
|
|
|
|
2009-03-11 16:28:13 +01:00
|
|
|
#ifdef SONAME_LIBSANE
|
|
|
|
static TW_UINT16 set_one_imagecoord(const char *option_name, TW_FIX32 val, BOOL *changed)
|
|
|
|
{
|
|
|
|
double d = val.Whole + ((double) val.Frac / 65536.0);
|
|
|
|
int set_status = 0;
|
|
|
|
SANE_Status status;
|
|
|
|
status = sane_option_set_fixed(activeDS.deviceHandle, option_name,
|
|
|
|
SANE_FIX((d * 254) / 10), &set_status);
|
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
{
|
|
|
|
activeDS.twCC = sane_status_to_twcc(status);
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
if (set_status & SANE_INFO_INEXACT)
|
|
|
|
*changed = TRUE;
|
|
|
|
return TWRC_SUCCESS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-03-21 03:58:39 +01:00
|
|
|
/* 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
|
|
|
#ifndef SONAME_LIBSANE
|
2002-03-21 03:58:39 +01:00
|
|
|
return TWRC_FAILURE;
|
2009-03-11 16:28:13 +01:00
|
|
|
#else
|
|
|
|
TW_IMAGELAYOUT *img = (TW_IMAGELAYOUT *) pData;
|
|
|
|
BOOL changed = FALSE;
|
|
|
|
TW_UINT16 twrc;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
twrc = set_one_imagecoord("tl-x", img->Frame.Left, &changed);
|
|
|
|
if (twrc != TWRC_SUCCESS)
|
|
|
|
return (twrc);
|
|
|
|
|
|
|
|
twrc = set_one_imagecoord("tl-y", img->Frame.Top, &changed);
|
|
|
|
if (twrc != TWRC_SUCCESS)
|
|
|
|
return (twrc);
|
|
|
|
|
|
|
|
twrc = set_one_imagecoord("br-x", img->Frame.Right, &changed);
|
|
|
|
if (twrc != TWRC_SUCCESS)
|
|
|
|
return (twrc);
|
|
|
|
|
|
|
|
twrc = set_one_imagecoord("br-y", img->Frame.Bottom, &changed);
|
|
|
|
if (twrc != TWRC_SUCCESS)
|
|
|
|
return (twrc);
|
|
|
|
|
|
|
|
activeDS.twCC = TWCC_SUCCESS;
|
|
|
|
return changed ? TWRC_CHECKSTATUS : TWRC_SUCCESS;
|
|
|
|
#endif
|
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)
|
|
|
|
{
|
2007-07-02 19:42:13 +02:00
|
|
|
#ifndef SONAME_LIBSANE
|
2002-03-21 03:58:39 +01:00
|
|
|
return TWRC_FAILURE;
|
2006-02-21 15:41:07 +01:00
|
|
|
#else
|
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS;
|
|
|
|
pTW_IMAGEMEMXFER pImageMemXfer = (pTW_IMAGEMEMXFER) pData;
|
|
|
|
SANE_Status status = SANE_STATUS_GOOD;
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
LPBYTE buffer;
|
|
|
|
int buff_len = 0;
|
|
|
|
int consumed_len = 0;
|
|
|
|
LPBYTE ptr;
|
|
|
|
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
|
|
|
|
2009-03-05 20:25:58 +01:00
|
|
|
if (! activeDS.sane_started)
|
2006-02-21 15:41:07 +01:00
|
|
|
{
|
2009-03-05 20:25:58 +01:00
|
|
|
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;
|
2006-02-21 15:41:07 +01:00
|
|
|
}
|
|
|
|
|
2007-03-14 19:10:03 +01:00
|
|
|
status = psane_get_parameters (activeDS.deviceHandle,
|
2006-05-08 20:05:42 +02:00
|
|
|
&activeDS.sane_param);
|
|
|
|
activeDS.sane_param_valid = TRUE;
|
2006-02-21 15:41:07 +01:00
|
|
|
|
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
{
|
2007-03-14 19:10:03 +01:00
|
|
|
WARN("psane_get_parameters: %s\n", psane_strstatus (status));
|
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
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"
|
2006-05-08 20:05:42 +02:00
|
|
|
, activeDS.sane_param.pixels_per_line, activeDS.sane_param.lines,
|
|
|
|
activeDS.sane_param.depth, activeDS.sane_param.format,
|
|
|
|
activeDS.sane_param.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 */
|
2006-05-08 20:05:42 +02:00
|
|
|
if (pImageMemXfer->Memory.Length < activeDS.sane_param.bytes_per_line)
|
2006-02-21 15:41:07 +01:00
|
|
|
{
|
2007-03-14 19:10:03 +01:00
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
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);
|
|
|
|
|
|
|
|
ptr = buffer;
|
|
|
|
consumed_len = 0;
|
2006-05-08 20:05:42 +02:00
|
|
|
rows = pImageMemXfer->Memory.Length / activeDS.sane_param.bytes_per_line;
|
2006-02-21 15:41:07 +01:00
|
|
|
|
|
|
|
/* must fill full lines */
|
2006-05-08 20:05:42 +02:00
|
|
|
while (consumed_len < (activeDS.sane_param.bytes_per_line*rows) &&
|
2006-02-21 15:41:07 +01:00
|
|
|
status == SANE_STATUS_GOOD)
|
|
|
|
{
|
2007-03-14 19:10:03 +01:00
|
|
|
status = psane_read (activeDS.deviceHandle, ptr,
|
2006-05-08 20:05:42 +02:00
|
|
|
(activeDS.sane_param.bytes_per_line*rows) - consumed_len ,
|
2006-02-21 15:41:07 +01:00
|
|
|
&buff_len);
|
|
|
|
consumed_len += buff_len;
|
|
|
|
ptr += buff_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == SANE_STATUS_GOOD || status == SANE_STATUS_EOF)
|
|
|
|
{
|
|
|
|
pImageMemXfer->Compression = TWCP_NONE;
|
2006-05-08 20:05:42 +02:00
|
|
|
pImageMemXfer->BytesPerRow = activeDS.sane_param.bytes_per_line;
|
|
|
|
pImageMemXfer->Columns = activeDS.sane_param.pixels_per_line;
|
2006-02-21 15:41:07 +01:00
|
|
|
pImageMemXfer->Rows = rows;
|
|
|
|
pImageMemXfer->XOffset = 0;
|
|
|
|
pImageMemXfer->YOffset = 0;
|
|
|
|
pImageMemXfer->BytesWritten = consumed_len;
|
|
|
|
|
2006-05-08 20:05:42 +02:00
|
|
|
ScanningDialogBox(activeDS.progressWnd, consumed_len);
|
2006-03-22 20:34:22 +01:00
|
|
|
|
2006-02-21 15:41:07 +01:00
|
|
|
if (status == SANE_STATUS_EOF)
|
|
|
|
{
|
2006-05-08 20:05:42 +02:00
|
|
|
ScanningDialogBox(activeDS.progressWnd, -1);
|
2007-03-14 19:10:03 +01:00
|
|
|
TRACE("psane_read: %s\n", psane_strstatus (status));
|
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
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
|
|
|
}
|
|
|
|
else if (status != SANE_STATUS_EOF)
|
|
|
|
{
|
2006-05-08 20:05:42 +02:00
|
|
|
ScanningDialogBox(activeDS.progressWnd, -1);
|
2007-03-14 19:10:03 +01:00
|
|
|
WARN("psane_read: %s\n", psane_strstatus (status));
|
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
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;
|
|
|
|
#endif
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
|
|
|
|
2009-02-13 20:14:58 +01:00
|
|
|
#ifdef SONAME_LIBSANE
|
|
|
|
static SANE_Status read_one_line(SANE_Handle h, BYTE *line, int len)
|
|
|
|
{
|
|
|
|
int read_len;
|
|
|
|
SANE_Status status;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
read_len = 0;
|
|
|
|
status = psane_read (activeDS.deviceHandle, line, len, &read_len);
|
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (read_len == len)
|
|
|
|
break;
|
|
|
|
|
|
|
|
line += read_len;
|
|
|
|
len -= read_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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)
|
|
|
|
{
|
2007-07-02 19:42:13 +02:00
|
|
|
#ifndef SONAME_LIBSANE
|
2002-03-21 03:58:39 +01:00
|
|
|
return TWRC_FAILURE;
|
|
|
|
#else
|
|
|
|
TW_UINT16 twRC = TWRC_SUCCESS;
|
|
|
|
pTW_UINT32 pHandle = (pTW_UINT32) pData;
|
|
|
|
SANE_Status status;
|
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 */
|
2009-03-05 20:25:58 +01:00
|
|
|
if (! activeDS.sane_started)
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
2009-03-05 20:25:58 +01:00
|
|
|
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;
|
2002-03-21 03:58:39 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-03-14 19:10:03 +01:00
|
|
|
status = psane_get_parameters (activeDS.deviceHandle, &activeDS.sane_param);
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.sane_param_valid = TRUE;
|
2002-03-21 03:58:39 +01:00
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
{
|
2007-03-14 19:10:03 +01:00
|
|
|
WARN("psane_get_parameters: %s\n", psane_strstatus (status));
|
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
2006-05-08 20:05:42 +02:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
2002-03-21 03:58:39 +01:00
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-03-03 00:08:11 +01:00
|
|
|
if (activeDS.sane_param.format == SANE_FRAME_GRAY)
|
2009-02-13 20:14:58 +01:00
|
|
|
{
|
2009-03-03 00:08:11 +01:00
|
|
|
if (activeDS.sane_param.depth == 8)
|
|
|
|
color_size = (1 << 8) * sizeof(*colors);
|
|
|
|
else if (activeDS.sane_param.depth == 1)
|
|
|
|
;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("For NATIVE, we support only 1 bit monochrome and 8 bit Grayscale, not %d\n", activeDS.sane_param.depth);
|
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
2009-03-03 00:08:11 +01:00
|
|
|
activeDS.twCC = TWCC_OPERATIONERROR;
|
|
|
|
return TWRC_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (activeDS.sane_param.format != SANE_FRAME_RGB)
|
|
|
|
{
|
|
|
|
FIXME("For NATIVE, we support only GRAY and RGB, not %d\n", activeDS.sane_param.format);
|
2009-02-13 20:14:58 +01:00
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
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"
|
2006-05-08 20:05:42 +02:00
|
|
|
, activeDS.sane_param.pixels_per_line, activeDS.sane_param.lines,
|
|
|
|
activeDS.sane_param.depth, activeDS.sane_param.format,
|
2009-02-13 20:14:58 +01:00
|
|
|
activeDS.sane_param.last_frame, activeDS.sane_param.bytes_per_line);
|
2002-03-21 03:58:39 +01:00
|
|
|
|
2009-02-13 20:14:58 +01:00
|
|
|
dib_bytes_per_line = ((activeDS.sane_param.bytes_per_line + 3) / 4) * 4;
|
|
|
|
dib_bytes = activeDS.sane_param.lines * dib_bytes_per_line;
|
|
|
|
|
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
|
|
|
{
|
2007-03-14 19:10:03 +01:00
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
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);
|
|
|
|
header->biWidth = activeDS.sane_param.pixels_per_line;
|
|
|
|
header->biHeight = activeDS.sane_param.lines;
|
|
|
|
header->biPlanes = 1;
|
|
|
|
header->biCompression = BI_RGB;
|
2009-03-03 00:08:11 +01:00
|
|
|
if (activeDS.sane_param.format == SANE_FRAME_RGB)
|
|
|
|
header->biBitCount = activeDS.sane_param.depth * 3;
|
|
|
|
if (activeDS.sane_param.format == SANE_FRAME_GRAY)
|
|
|
|
header->biBitCount = activeDS.sane_param.depth;
|
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. */
|
2009-03-03 00:08:11 +01:00
|
|
|
line = p + (activeDS.sane_param.lines - 1) * dib_bytes_per_line;
|
2009-02-13 20:14:58 +01:00
|
|
|
for (i = activeDS.sane_param.lines - 1; i >= 0; i--)
|
2002-03-21 03:58:39 +01:00
|
|
|
{
|
2009-02-13 20:14:58 +01:00
|
|
|
activeDS.progressWnd = ScanningDialogBox(activeDS.progressWnd,
|
|
|
|
((activeDS.sane_param.lines - 1 - i) * 100)
|
|
|
|
/
|
|
|
|
(activeDS.sane_param.lines - 1));
|
2002-03-21 03:58:39 +01:00
|
|
|
|
2009-02-13 20:14:58 +01:00
|
|
|
status = read_one_line(activeDS.deviceHandle, line,
|
|
|
|
activeDS.sane_param.bytes_per_line);
|
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
break;
|
|
|
|
|
|
|
|
line -= dib_bytes_per_line;
|
|
|
|
}
|
|
|
|
activeDS.progressWnd = ScanningDialogBox(activeDS.progressWnd, -1);
|
|
|
|
|
|
|
|
GlobalUnlock(hDIB);
|
|
|
|
|
|
|
|
if (status != SANE_STATUS_GOOD && status != SANE_STATUS_EOF)
|
|
|
|
{
|
|
|
|
WARN("psane_read: %s, reading line %d\n", psane_strstatus(status), i);
|
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
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
|
|
|
|
2007-03-14 19:10:03 +01:00
|
|
|
psane_cancel (activeDS.deviceHandle);
|
2009-03-05 20:25:58 +01:00
|
|
|
activeDS.sane_started = FALSE;
|
2002-10-25 05:50:14 +02:00
|
|
|
*pHandle = (TW_UINT32)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;
|
|
|
|
#endif
|
|
|
|
}
|