Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / twain / ds_image.c
blobc9fc1b04ca0cb2cf2763bab50745dc68216877dc
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "twain.h"
28 #include "twain_i.h"
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,
35 TW_MEMREF pData)
37 FIXME ("stub!\n");
39 return TWRC_FAILURE;
42 /* DG_IMAGE/DAT_EXTIMAGEINFO/MSG_GET */
43 TW_UINT16 TWAIN_ExtImageInfoGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
44 TW_MEMREF pData)
46 FIXME ("stub!\n");
48 return TWRC_FAILURE;
51 /* DG_IMAGE/DAT_GRAYRESPONSE/MSG_RESET */
52 TW_UINT16 TWAIN_GrayResponseReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
53 TW_MEMREF pData)
55 FIXME ("stub!\n");
57 return TWRC_FAILURE;
60 /* DG_IMAGE/DAT_GRAYRESPONSE/MSG_SET */
61 TW_UINT16 TWAIN_GrayResponseSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
62 TW_MEMREF pData)
64 FIXME ("stub!\n");
66 return TWRC_FAILURE;
69 /* DG_IMAGE/DAT_IMAGEFILEXFER/MSG_GET */
70 TW_UINT16 TWAIN_ImageFileXferGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
71 TW_MEMREF pData)
73 FIXME ("stub!\n");
75 return TWRC_FAILURE;
78 /* DG_IMAGE/DAT_IMAGEINFO/MSG_GET */
79 TW_UINT16 TWAIN_ImageInfoGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
80 TW_MEMREF pData)
82 #ifndef HAVE_SANE
83 return TWRC_FAILURE;
84 #else
85 TW_UINT16 twRC = TWRC_SUCCESS;
86 pTW_IMAGEINFO pImageInfo = (pTW_IMAGEINFO) pData;
87 activeDS *pSource = TWAIN_LookupSource (pDest);
88 SANE_Status status;
90 TRACE("DG_IMAGE/DAT_IMAGEINFO/MSG_GET\n");
92 if (!pSource)
94 twRC = TWRC_FAILURE;
95 DSM_twCC = TWCC_BADDEST;
97 else if (pSource->currentState != 6 && pSource->currentState != 7)
99 twRC = TWRC_FAILURE;
100 pSource->twCC = TWCC_SEQERROR;
102 else
104 if (pSource->currentState == 6)
106 /* return general image description information about the image about to be transferred */
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 */
133 return twRC;
134 #endif
137 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_GET */
138 TW_UINT16 TWAIN_ImageLayoutGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
139 TW_MEMREF pData)
141 FIXME ("stub!\n");
143 return TWRC_FAILURE;
146 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_GETDEFAULT */
147 TW_UINT16 TWAIN_ImageLayoutGetDefault (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
148 TW_MEMREF pData)
150 FIXME ("stub!\n");
152 return TWRC_FAILURE;
155 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_RESET */
156 TW_UINT16 TWAIN_ImageLayoutReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
157 TW_MEMREF pData)
159 FIXME ("stub!\n");
161 return TWRC_FAILURE;
164 /* DG_IMAGE/DAT_IMAGELAYOUT/MSG_SET */
165 TW_UINT16 TWAIN_ImageLayoutSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
166 TW_MEMREF pData)
168 FIXME ("stub!\n");
170 return TWRC_FAILURE;
173 /* DG_IMAGE/DAT_IMAGEMEMXFER/MSG_GET */
174 TW_UINT16 TWAIN_ImageMemXferGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
175 TW_MEMREF pData)
177 FIXME ("stub!\n");
179 return TWRC_FAILURE;
182 /* DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET */
183 TW_UINT16 TWAIN_ImageNativeXferGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
184 TW_MEMREF pData)
186 #ifndef HAVE_SANE
187 return TWRC_FAILURE;
188 #else
189 TW_UINT16 twRC = TWRC_SUCCESS;
190 pTW_UINT32 pHandle = (pTW_UINT32) pData;
191 activeDS *pSource = TWAIN_LookupSource (pDest);
192 SANE_Status status;
193 SANE_Byte buffer[32*1024];
194 int buff_len;
195 HBITMAP hDIB;
196 BITMAPINFO bmpInfo;
197 VOID *pBits;
198 HDC dc;
200 TRACE("DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET\n");
202 if (!pSource)
204 twRC = TWRC_FAILURE;
205 DSM_twCC = TWCC_NODS;
207 else if (pSource->currentState != 6)
209 twRC = TWRC_FAILURE;
210 pSource->twCC = TWCC_SEQERROR;
212 else
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;
221 return TWRC_FAILURE;
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;
230 return TWRC_FAILURE;
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);
255 if (!hDIB)
257 sane_cancel (pSource->deviceHandle);
258 pSource->twCC = TWCC_LOWMEMORY;
259 return TWRC_FAILURE;
264 status = sane_read (pSource->deviceHandle, buffer,
265 sizeof (buffer), &buff_len);
266 if (status == SANE_STATUS_GOOD)
268 /* FIXME: put code for converting 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;
276 return TWRC_FAILURE;
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;
287 return twRC;
288 #endif
291 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_GET */
292 TW_UINT16 TWAIN_JPEGCompressionGet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
293 TW_MEMREF pData)
295 FIXME ("stub!\n");
297 return TWRC_FAILURE;
300 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_GETDEFAULT */
301 TW_UINT16 TWAIN_JPEGCompressionGetDefault (pTW_IDENTITY pOrigin,
302 pTW_IDENTITY pDest,
303 TW_MEMREF pData)
305 FIXME ("stub!\n");
307 return TWRC_FAILURE;
310 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_RESET */
311 TW_UINT16 TWAIN_JPEGCompressionReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
312 TW_MEMREF pData)
314 FIXME ("stub!\n");
316 return TWRC_FAILURE;
319 /* DG_IMAGE/DAT_JPEGCOMPRESSION/MSG_SET */
320 TW_UINT16 TWAIN_JPEGCompressionSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
321 TW_MEMREF pData)
323 FIXME ("stub!\n");
325 return TWRC_FAILURE;
328 /* DG_IMAGE/DAT_PALETTE8/MSG_GET */
329 TW_UINT16 TWAIN_Palette8Get (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
330 TW_MEMREF pData)
332 FIXME ("stub!\n");
334 return TWRC_FAILURE;
337 /* DG_IMAGE/DAT_PALETTE8/MSG_GETDEFAULT */
338 TW_UINT16 TWAIN_Palette8GetDefault (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
339 TW_MEMREF pData)
341 FIXME ("stub!\n");
343 return TWRC_FAILURE;
346 /* DG_IMAGE/DAT_PALETTE8/MSG_RESET */
347 TW_UINT16 TWAIN_Palette8Reset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
348 TW_MEMREF pData)
350 FIXME ("stub!\n");
352 return TWRC_FAILURE;
355 /* DG_IMAGE/DAT_PALETTE8/MSG_SET */
356 TW_UINT16 TWAIN_Palette8Set (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
357 TW_MEMREF pData)
359 FIXME ("stub!\n");
361 return TWRC_FAILURE;
364 /* DG_IMAGE/DAT_RGBRESPONSE/MSG_RESET */
365 TW_UINT16 TWAIN_RGBResponseReset (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
366 TW_MEMREF pData)
368 FIXME ("stub!\n");
370 return TWRC_FAILURE;
373 /* DG_IMAGE/DAT_RGBRESPONSE/MSG_SET */
374 TW_UINT16 TWAIN_RGBResponseSet (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
375 TW_MEMREF pData)
377 FIXME ("stub!\n");
379 return TWRC_FAILURE;