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
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(twain);
30 /* DG_IMAGE/DAT_CIECOLOR/MSG_GET */
31 TW_UINT16 TWAIN_CIEColorGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
39 /* DG_IMAGE/DAT_EXTIMAGEINFO/MSG_GET */
40 TW_UINT16 TWAIN_ExtImageInfoGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
48 /* DG_IMAGE/DAT_GRAYRESPONSE/MSG_RESET */
49 TW_UINT16 TWAIN_GrayResponseReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
57 /* DG_IMAGE/DAT_GRAYRESPONSE/MSG_SET */
58 TW_UINT16 TWAIN_GrayResponseSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
66 /* DG_IMAGE/DAT_IMAGEFILEXFER/MSG_GET */
67 TW_UINT16 TWAIN_ImageFileXferGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
75 /* DG_IMAGE/DAT_IMAGEINFO/MSG_GET */
76 TW_UINT16 TWAIN_ImageInfoGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
82 TW_UINT16 twRC = TWRC_SUCCESS;
83 pTW_IMAGEINFO pImageInfo = (pTW_IMAGEINFO) pData;
84 activeDS *pSource = TWAIN_LookupSource (pDest);
87 TRACE("DG_IMAGE/DAT_IMAGEINFO/MSG_GET\n");
92 DSM_twCC = TWCC_BADDEST;
94 else if (pSource->currentState != 6 && pSource->currentState != 7)
97 pSource->twCC = TWCC_SEQERROR;
101 if (pSource->currentState == 6)
103 /* return general image description information about the image about to be transfer */
104 status = sane_get_parameters (pSource->deviceHandle, &pSource->sane_param);
107 pImageInfo->XResolution.Whole = -1;
108 pImageInfo->XResolution.Frac = 0;
109 pImageInfo->YResolution.Whole = -1;
110 pImageInfo->YResolution.Frac = 0;
111 pImageInfo->ImageWidth = pSource->sane_param.pixels_per_line;
112 pImageInfo->ImageLength = pSource->sane_param.lines;
113 if (pSource->sane_param.depth == 24)
115 pImageInfo->SamplesPerPixel = 3;
116 pImageInfo->BitsPerSample[0] = 8;
117 pImageInfo->BitsPerSample[1] = 8;
118 pImageInfo->BitsPerSample[2] = 8;
119 pImageInfo->BitsPerPixel = 24;
120 pImageInfo->Planar = TRUE;
121 pImageInfo->PixelType = TWPT_RGB;
122 pImageInfo->Compression = TWCP_NONE;
124 else if (pSource->sane_param.depth == 8)
126 /* FIXME: fill the image info structure for 8-bit image */
134 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_GET */
135 TW_UINT16 TWAIN_ImageLayoutGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
143 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_GETDEFAULT */
144 TW_UINT16 TWAIN_ImageLayoutGetDefault (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
152 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_RESET */
153 TW_UINT16 TWAIN_ImageLayoutReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
161 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_SET */
162 TW_UINT16 TWAIN_ImageLayoutSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
170 /* DG_IMAGE/DAT_IMAGEMEMXFER/MSG_GET */
171 TW_UINT16 TWAIN_ImageMemXferGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
179 /* DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET */
180 TW_UINT16 TWAIN_ImageNativeXferGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
186 TW_UINT16 twRC = TWRC_SUCCESS;
187 pTW_UINT32 pHandle = (pTW_UINT32) pData;
188 activeDS *pSource = TWAIN_LookupSource (pDest);
190 SANE_Byte buffer[32*1024];
197 TRACE("DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET\n");
202 DSM_twCC = TWCC_NODS;
204 else if (pSource->currentState != 6)
207 pSource->twCC = TWCC_SEQERROR;
211 /* Transfer an image from the source to the application */
212 status = sane_start (pSource->deviceHandle);
213 if (status != SANE_STATUS_GOOD)
215 WARN("sane_start: %s\n", sane_strstatus (status));
216 sane_cancel (pSource->deviceHandle);
217 pSource->twCC = TWCC_OPERATIONERROR;
221 status = sane_get_parameters (pSource->deviceHandle, &pSource->sane_param);
222 if (status != SANE_STATUS_GOOD)
224 WARN("sane_get_parameters: %s\n", sane_strstatus (status));
225 sane_cancel (pSource->deviceHandle);
226 pSource->twCC = TWCC_OPERATIONERROR;
230 TRACE("Acquiring image %dx%dx%d bits (format=%d last=%d) from sane...\n"
231 , pSource->sane_param.pixels_per_line, pSource->sane_param.lines,
232 pSource->sane_param.depth, pSource->sane_param.format,
233 pSource->sane_param.last_frame);
235 ZeroMemory (&bmpInfo, sizeof (BITMAPINFO));
236 bmpInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
237 bmpInfo.bmiHeader.biWidth = pSource->sane_param.pixels_per_line;
238 bmpInfo.bmiHeader.biHeight = pSource->sane_param.lines;
239 bmpInfo.bmiHeader.biPlanes = 1;
240 bmpInfo.bmiHeader.biBitCount = pSource->sane_param.depth;
241 bmpInfo.bmiHeader.biCompression = BI_RGB;
242 bmpInfo.bmiHeader.biSizeImage = 0;
243 bmpInfo.bmiHeader.biXPelsPerMeter = 0;
244 bmpInfo.bmiHeader.biYPelsPerMeter = 0;
245 bmpInfo.bmiHeader.biClrUsed = 1;
246 bmpInfo.bmiHeader.biClrImportant = 0;
247 bmpInfo.bmiColors[0].rgbBlue = 128;
248 bmpInfo.bmiColors[0].rgbGreen = 128;
249 bmpInfo.bmiColors[0].rgbRed = 128;
250 hDIB = CreateDIBSection ((dc = GetDC(pSource->hwndOwner)), &bmpInfo,
251 DIB_RGB_COLORS, &pBits, 0, 0);
254 sane_cancel (pSource->deviceHandle);
255 pSource->twCC = TWCC_LOWMEMORY;
261 status = sane_read (pSource->deviceHandle, buffer,
262 sizeof (buffer), &buff_len);
263 if (status == SANE_STATUS_GOOD)
265 /* FIXME: put code for coverting the image data into DIB here */
268 else if (status != SANE_STATUS_EOF)
270 WARN("sane_read: %s\n", sane_strstatus (status));
271 sane_cancel (pSource->deviceHandle);
272 pSource->twCC = TWCC_OPERATIONERROR;
275 } while (status == SANE_STATUS_GOOD);
277 sane_cancel (pSource->deviceHandle);
278 ReleaseDC (pSource->hwndOwner, dc);
279 *pHandle = (TW_UINT32)hDIB;
280 twRC = TWRC_XFERDONE;
281 pSource->twCC = TWCC_SUCCESS;
282 pSource->currentState = 7;
288 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_GET */
289 TW_UINT16 TWAIN_JPEGCompressionGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
297 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_GETDEFAULT */
298 TW_UINT16 TWAIN_JPEGCompressionGetDefault (pTW_IDENTITY pOrigin,
307 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_RESET */
308 TW_UINT16 TWAIN_JPEGCompressionReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
316 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_SET */
317 TW_UINT16 TWAIN_JPEGCompressionSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
325 /* DG_IMAGE/DAT_PALETTE8/MSG_GET */
326 TW_UINT16 TWAIN_Palette8Get (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
334 /* DG_IMAGE/DAT_PALETTE8/MSG_GETDEFAULT */
335 TW_UINT16 TWAIN_Palette8GetDefault (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
343 /* DG_IMAGE/DAT_PALETTE8/MSG_RESET */
344 TW_UINT16 TWAIN_Palette8Reset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
352 /* DG_IMAGE/DAT_PALETTE8/MSG_SET */
353 TW_UINT16 TWAIN_Palette8Set (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
361 /* DG_IMAGE/DAT_RGBRESPONSE/MSG_RESET */
362 TW_UINT16 TWAIN_RGBResponseReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
370 /* DG_IMAGE/DAT_RGBRESPONSE/MSG_SET */
371 TW_UINT16 TWAIN_RGBResponseSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,