2 * Copyright 2000 Corel Corporation
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
33 /* DG_IMAGE/DAT_CIECOLOR/MSG_GET */
34 TW_UINT16
TWAIN_CIEColorGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
42 /* DG_IMAGE/DAT_EXTIMAGEINFO/MSG_GET */
43 TW_UINT16
TWAIN_ExtImageInfoGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
51 /* DG_IMAGE/DAT_GRAYRESPONSE/MSG_RESET */
52 TW_UINT16
TWAIN_GrayResponseReset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
60 /* DG_IMAGE/DAT_GRAYRESPONSE/MSG_SET */
61 TW_UINT16
TWAIN_GrayResponseSet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
69 /* DG_IMAGE/DAT_IMAGEFILEXFER/MSG_GET */
70 TW_UINT16
TWAIN_ImageFileXferGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
78 /* DG_IMAGE/DAT_IMAGEINFO/MSG_GET */
79 TW_UINT16
TWAIN_ImageInfoGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
85 TW_UINT16 twRC
= TWRC_SUCCESS
;
86 pTW_IMAGEINFO pImageInfo
= (pTW_IMAGEINFO
) pData
;
87 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
90 TRACE("DG_IMAGE/DAT_IMAGEINFO/MSG_GET\n");
95 DSM_twCC
= TWCC_BADDEST
;
97 else if (pSource
->currentState
!= 6 && pSource
->currentState
!= 7)
100 pSource
->twCC
= TWCC_SEQERROR
;
104 if (pSource
->currentState
== 6)
106 /* return general image description information about the image about to be transfer */
107 status
= sane_get_parameters (pSource
->deviceHandle
, &pSource
->sane_param
);
110 pImageInfo
->XResolution
.Whole
= -1;
111 pImageInfo
->XResolution
.Frac
= 0;
112 pImageInfo
->YResolution
.Whole
= -1;
113 pImageInfo
->YResolution
.Frac
= 0;
114 pImageInfo
->ImageWidth
= pSource
->sane_param
.pixels_per_line
;
115 pImageInfo
->ImageLength
= pSource
->sane_param
.lines
;
116 if (pSource
->sane_param
.depth
== 24)
118 pImageInfo
->SamplesPerPixel
= 3;
119 pImageInfo
->BitsPerSample
[0] = 8;
120 pImageInfo
->BitsPerSample
[1] = 8;
121 pImageInfo
->BitsPerSample
[2] = 8;
122 pImageInfo
->BitsPerPixel
= 24;
123 pImageInfo
->Planar
= TRUE
;
124 pImageInfo
->PixelType
= TWPT_RGB
;
125 pImageInfo
->Compression
= TWCP_NONE
;
127 else if (pSource
->sane_param
.depth
== 8)
129 /* FIXME: fill the image info structure for 8-bit image */
137 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_GET */
138 TW_UINT16
TWAIN_ImageLayoutGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
146 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_GETDEFAULT */
147 TW_UINT16
TWAIN_ImageLayoutGetDefault (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
155 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_RESET */
156 TW_UINT16
TWAIN_ImageLayoutReset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
164 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_SET */
165 TW_UINT16
TWAIN_ImageLayoutSet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
173 /* DG_IMAGE/DAT_IMAGEMEMXFER/MSG_GET */
174 TW_UINT16
TWAIN_ImageMemXferGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
182 /* DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET */
183 TW_UINT16
TWAIN_ImageNativeXferGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
189 TW_UINT16 twRC
= TWRC_SUCCESS
;
190 pTW_UINT32 pHandle
= (pTW_UINT32
) pData
;
191 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
193 SANE_Byte buffer
[32*1024];
200 TRACE("DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET\n");
205 DSM_twCC
= TWCC_NODS
;
207 else if (pSource
->currentState
!= 6)
210 pSource
->twCC
= TWCC_SEQERROR
;
214 /* Transfer an image from the source to the application */
215 status
= sane_start (pSource
->deviceHandle
);
216 if (status
!= SANE_STATUS_GOOD
)
218 WARN("sane_start: %s\n", sane_strstatus (status
));
219 sane_cancel (pSource
->deviceHandle
);
220 pSource
->twCC
= TWCC_OPERATIONERROR
;
224 status
= sane_get_parameters (pSource
->deviceHandle
, &pSource
->sane_param
);
225 if (status
!= SANE_STATUS_GOOD
)
227 WARN("sane_get_parameters: %s\n", sane_strstatus (status
));
228 sane_cancel (pSource
->deviceHandle
);
229 pSource
->twCC
= TWCC_OPERATIONERROR
;
233 TRACE("Acquiring image %dx%dx%d bits (format=%d last=%d) from sane...\n"
234 , pSource
->sane_param
.pixels_per_line
, pSource
->sane_param
.lines
,
235 pSource
->sane_param
.depth
, pSource
->sane_param
.format
,
236 pSource
->sane_param
.last_frame
);
238 ZeroMemory (&bmpInfo
, sizeof (BITMAPINFO
));
239 bmpInfo
.bmiHeader
.biSize
= sizeof (BITMAPINFOHEADER
);
240 bmpInfo
.bmiHeader
.biWidth
= pSource
->sane_param
.pixels_per_line
;
241 bmpInfo
.bmiHeader
.biHeight
= pSource
->sane_param
.lines
;
242 bmpInfo
.bmiHeader
.biPlanes
= 1;
243 bmpInfo
.bmiHeader
.biBitCount
= pSource
->sane_param
.depth
;
244 bmpInfo
.bmiHeader
.biCompression
= BI_RGB
;
245 bmpInfo
.bmiHeader
.biSizeImage
= 0;
246 bmpInfo
.bmiHeader
.biXPelsPerMeter
= 0;
247 bmpInfo
.bmiHeader
.biYPelsPerMeter
= 0;
248 bmpInfo
.bmiHeader
.biClrUsed
= 1;
249 bmpInfo
.bmiHeader
.biClrImportant
= 0;
250 bmpInfo
.bmiColors
[0].rgbBlue
= 128;
251 bmpInfo
.bmiColors
[0].rgbGreen
= 128;
252 bmpInfo
.bmiColors
[0].rgbRed
= 128;
253 hDIB
= CreateDIBSection ((dc
= GetDC(pSource
->hwndOwner
)), &bmpInfo
,
254 DIB_RGB_COLORS
, &pBits
, 0, 0);
257 sane_cancel (pSource
->deviceHandle
);
258 pSource
->twCC
= TWCC_LOWMEMORY
;
264 status
= sane_read (pSource
->deviceHandle
, buffer
,
265 sizeof (buffer
), &buff_len
);
266 if (status
== SANE_STATUS_GOOD
)
268 /* FIXME: put code for coverting the image data into DIB here */
271 else if (status
!= SANE_STATUS_EOF
)
273 WARN("sane_read: %s\n", sane_strstatus (status
));
274 sane_cancel (pSource
->deviceHandle
);
275 pSource
->twCC
= TWCC_OPERATIONERROR
;
278 } while (status
== SANE_STATUS_GOOD
);
280 sane_cancel (pSource
->deviceHandle
);
281 ReleaseDC (pSource
->hwndOwner
, dc
);
282 *pHandle
= (TW_UINT32
)hDIB
;
283 twRC
= TWRC_XFERDONE
;
284 pSource
->twCC
= TWCC_SUCCESS
;
285 pSource
->currentState
= 7;
291 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_GET */
292 TW_UINT16
TWAIN_JPEGCompressionGet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
300 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_GETDEFAULT */
301 TW_UINT16
TWAIN_JPEGCompressionGetDefault (pTW_IDENTITY pOrigin
,
310 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_RESET */
311 TW_UINT16
TWAIN_JPEGCompressionReset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
319 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_SET */
320 TW_UINT16
TWAIN_JPEGCompressionSet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
328 /* DG_IMAGE/DAT_PALETTE8/MSG_GET */
329 TW_UINT16
TWAIN_Palette8Get (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
337 /* DG_IMAGE/DAT_PALETTE8/MSG_GETDEFAULT */
338 TW_UINT16
TWAIN_Palette8GetDefault (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
346 /* DG_IMAGE/DAT_PALETTE8/MSG_RESET */
347 TW_UINT16
TWAIN_Palette8Reset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
355 /* DG_IMAGE/DAT_PALETTE8/MSG_SET */
356 TW_UINT16
TWAIN_Palette8Set (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
364 /* DG_IMAGE/DAT_RGBRESPONSE/MSG_RESET */
365 TW_UINT16
TWAIN_RGBResponseReset (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,
373 /* DG_IMAGE/DAT_RGBRESPONSE/MSG_SET */
374 TW_UINT16
TWAIN_RGBResponseSet (pTW_IDENTITY pOrigin
, pTW_IDENTITY pDest
,