dplayx: Code to forward player creation
[wine/gsoc_dplay.git] / dlls / msvfw32 / msvideo_main.c
blob6196fac7433644b97011534afb62a123cc968e25
1 /*
2 * Copyright 1998 Marcus Meissner
3 * Copyright 2000 Bradley Baetz
4 * Copyright 2003 Michael Günnewig
5 * Copyright 2005 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * FIXME: This all assumes 32 bit codecs
22 * Win95 appears to prefer 32 bit codecs, even from 16 bit code.
23 * There is the ICOpenFunction16 to worry about still, though.
25 * TODO
26 * - no thread safety
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <string.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winreg.h"
36 #include "winnls.h"
37 #include "wingdi.h"
38 #include "winuser.h"
39 #include "commdlg.h"
40 #include "vfw.h"
41 #include "msvideo_private.h"
42 #include "wine/debug.h"
44 /* Drivers32 settings */
45 #define HKLM_DRIVERS32 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32"
47 WINE_DEFAULT_DEBUG_CHANNEL(msvideo);
49 static inline const char *wine_dbgstr_fcc( DWORD fcc )
51 return wine_dbg_sprintf("%c%c%c%c",
52 LOBYTE(LOWORD(fcc)), HIBYTE(LOWORD(fcc)),
53 LOBYTE(HIWORD(fcc)), HIBYTE(HIWORD(fcc)));
56 static WINE_HIC* MSVIDEO_FirstHic /* = NULL */;
58 typedef struct _reg_driver reg_driver;
59 struct _reg_driver
61 DWORD fccType;
62 DWORD fccHandler;
63 DRIVERPROC proc;
64 LPWSTR name;
65 reg_driver* next;
68 static reg_driver* reg_driver_list = NULL;
70 /* This one is a macro such that it works for both ASCII and Unicode */
71 #define fourcc_to_string(str, fcc) do { \
72 (str)[0] = LOBYTE(LOWORD(fcc)); \
73 (str)[1] = HIBYTE(LOWORD(fcc)); \
74 (str)[2] = LOBYTE(HIWORD(fcc)); \
75 (str)[3] = HIBYTE(HIWORD(fcc)); \
76 } while(0)
78 HMODULE MSVFW32_hModule;
80 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
82 TRACE("%p,%x,%p\n", hinst, reason, reserved);
84 switch(reason)
86 case DLL_PROCESS_ATTACH:
87 DisableThreadLibraryCalls(hinst);
88 MSVFW32_hModule = hinst;
89 break;
91 return TRUE;
94 /******************************************************************
95 * MSVIDEO_SendMessage
99 static LRESULT MSVIDEO_SendMessage(WINE_HIC* whic, UINT msg, DWORD_PTR lParam1, DWORD_PTR lParam2)
101 LRESULT ret;
103 #define XX(x) case x: TRACE("(%p,"#x",0x%08lx,0x%08lx)\n",whic,lParam1,lParam2); break
105 switch (msg) {
106 /* DRV_* */
107 XX(DRV_LOAD);
108 XX(DRV_ENABLE);
109 XX(DRV_OPEN);
110 XX(DRV_CLOSE);
111 XX(DRV_DISABLE);
112 XX(DRV_FREE);
113 /* ICM_RESERVED+X */
114 XX(ICM_ABOUT);
115 XX(ICM_CONFIGURE);
116 XX(ICM_GET);
117 XX(ICM_GETINFO);
118 XX(ICM_GETDEFAULTQUALITY);
119 XX(ICM_GETQUALITY);
120 XX(ICM_GETSTATE);
121 XX(ICM_SETQUALITY);
122 XX(ICM_SET);
123 XX(ICM_SETSTATE);
124 /* ICM_USER+X */
125 XX(ICM_COMPRESS_FRAMES_INFO);
126 XX(ICM_COMPRESS_GET_FORMAT);
127 XX(ICM_COMPRESS_GET_SIZE);
128 XX(ICM_COMPRESS_QUERY);
129 XX(ICM_COMPRESS_BEGIN);
130 XX(ICM_COMPRESS);
131 XX(ICM_COMPRESS_END);
132 XX(ICM_DECOMPRESS_GET_FORMAT);
133 XX(ICM_DECOMPRESS_QUERY);
134 XX(ICM_DECOMPRESS_BEGIN);
135 XX(ICM_DECOMPRESS);
136 XX(ICM_DECOMPRESS_END);
137 XX(ICM_DECOMPRESS_SET_PALETTE);
138 XX(ICM_DECOMPRESS_GET_PALETTE);
139 XX(ICM_DRAW_QUERY);
140 XX(ICM_DRAW_BEGIN);
141 XX(ICM_DRAW_GET_PALETTE);
142 XX(ICM_DRAW_START);
143 XX(ICM_DRAW_STOP);
144 XX(ICM_DRAW_END);
145 XX(ICM_DRAW_GETTIME);
146 XX(ICM_DRAW);
147 XX(ICM_DRAW_WINDOW);
148 XX(ICM_DRAW_SETTIME);
149 XX(ICM_DRAW_REALIZE);
150 XX(ICM_DRAW_FLUSH);
151 XX(ICM_DRAW_RENDERBUFFER);
152 XX(ICM_DRAW_START_PLAY);
153 XX(ICM_DRAW_STOP_PLAY);
154 XX(ICM_DRAW_SUGGESTFORMAT);
155 XX(ICM_DRAW_CHANGEPALETTE);
156 XX(ICM_GETBUFFERSWANTED);
157 XX(ICM_GETDEFAULTKEYFRAMERATE);
158 XX(ICM_DECOMPRESSEX_BEGIN);
159 XX(ICM_DECOMPRESSEX_QUERY);
160 XX(ICM_DECOMPRESSEX);
161 XX(ICM_DECOMPRESSEX_END);
162 XX(ICM_SET_STATUS_PROC);
163 default:
164 FIXME("(%p,0x%08x,0x%08lx,0x%08lx) unknown message\n",whic,msg,lParam1,lParam2);
167 #undef XX
169 if (whic->driverproc) {
170 /* dwDriverId parameter is the value returned by the DRV_OPEN */
171 ret = whic->driverproc(whic->driverId, whic->hdrv, msg, lParam1, lParam2);
172 } else {
173 ret = SendDriverMessage(whic->hdrv, msg, lParam1, lParam2);
176 TRACE(" -> 0x%08lx\n", ret);
177 return ret;
180 static int compare_fourcc(DWORD fcc1, DWORD fcc2)
182 char fcc_str1[4];
183 char fcc_str2[4];
184 fourcc_to_string(fcc_str1, fcc1);
185 fourcc_to_string(fcc_str2, fcc2);
186 return strncasecmp(fcc_str1, fcc_str2, 4);
189 typedef BOOL (*enum_handler_t)(const char*, unsigned int, void*);
191 static BOOL enum_drivers(DWORD fccType, enum_handler_t handler, void* param)
193 CHAR buf[2048], fccTypeStr[5], *s;
194 DWORD i, cnt = 0, lRet;
195 BOOL result = FALSE;
196 HKEY hKey;
198 fourcc_to_string(fccTypeStr, fccType);
199 fccTypeStr[4] = '.';
201 /* first, go through the registry entries */
202 lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, HKLM_DRIVERS32, 0, KEY_QUERY_VALUE, &hKey);
203 if (lRet == ERROR_SUCCESS)
205 DWORD name, data, type;
206 i = 0;
207 for (;;)
209 name = 10;
210 data = sizeof buf - name;
211 lRet = RegEnumValueA(hKey, i++, buf, &name, 0, &type, (LPBYTE)(buf+name), &data);
212 if (lRet == ERROR_NO_MORE_ITEMS) break;
213 if (lRet != ERROR_SUCCESS) continue;
214 if (name != 9 || strncasecmp(buf, fccTypeStr, 5)) continue;
215 buf[name] = '=';
216 if ((result = handler(buf, cnt++, param))) break;
218 RegCloseKey( hKey );
220 if (result) return result;
222 /* if that didn't work, go through the values in system.ini */
223 if (GetPrivateProfileSectionA("drivers32", buf, sizeof(buf), "system.ini"))
225 for (s = buf; *s; s += strlen(s) + 1)
227 TRACE("got %s\n", s);
228 if (strncasecmp(s, fccTypeStr, 5) || s[9] != '=') continue;
229 if ((result = handler(s, cnt++, param))) break;
233 return result;
236 /******************************************************************
237 * MSVIDEO_GetHicPtr
241 static WINE_HIC* MSVIDEO_GetHicPtr(HIC hic)
243 WINE_HIC* whic;
245 for (whic = MSVIDEO_FirstHic; whic && whic->hic != hic; whic = whic->next);
246 return whic;
249 /***********************************************************************
250 * VideoForWindowsVersion [MSVFW32.2]
251 * VideoForWindowsVersion [MSVIDEO.2]
252 * Returns the version in major.minor form.
253 * In Windows95 this returns 0x040003b6 (4.950)
255 DWORD WINAPI VideoForWindowsVersion(void)
257 return 0x040003B6; /* 4.950 */
260 static BOOL ICInfo_enum_handler(const char *drv, unsigned int nr, void *param)
262 ICINFO *lpicinfo = param;
263 DWORD fccHandler = mmioStringToFOURCCA(drv + 5, 0);
265 /* exact match of fccHandler or nth driver found */
266 if ((lpicinfo->fccHandler != nr) && (lpicinfo->fccHandler != fccHandler))
267 return FALSE;
269 lpicinfo->fccHandler = fccHandler;
270 lpicinfo->dwFlags = 0;
271 lpicinfo->dwVersion = 0;
272 lpicinfo->dwVersionICM = ICVERSION;
273 lpicinfo->szName[0] = 0;
274 lpicinfo->szDescription[0] = 0;
275 MultiByteToWideChar(CP_ACP, 0, drv + 10, -1, lpicinfo->szDriver,
276 sizeof(lpicinfo->szDriver)/sizeof(WCHAR));
278 return TRUE;
281 /***********************************************************************
282 * ICInfo [MSVFW32.@]
283 * Get information about an installable compressor. Return TRUE if there
284 * is one.
286 * PARAMS
287 * fccType [I] type of compressor (e.g. 'vidc')
288 * fccHandler [I] real fcc for handler or <n>th compressor
289 * lpicinfo [O] information about compressor
291 BOOL VFWAPI ICInfo( DWORD fccType, DWORD fccHandler, ICINFO *lpicinfo)
293 TRACE("(%s,%s/%08x,%p)\n",
294 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), fccHandler, lpicinfo);
296 lpicinfo->fccType = fccType;
297 lpicinfo->fccHandler = fccHandler;
298 return enum_drivers(fccType, ICInfo_enum_handler, lpicinfo);
301 static DWORD IC_HandleRef = 1;
303 /***********************************************************************
304 * ICInstall [MSVFW32.@]
306 BOOL VFWAPI ICInstall(DWORD fccType, DWORD fccHandler, LPARAM lParam, LPSTR szDesc, UINT wFlags)
308 reg_driver* driver;
309 unsigned len;
311 TRACE("(%s,%s,%p,%p,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), (void*)lParam, szDesc, wFlags);
313 /* Check if a driver is already registered */
314 for (driver = reg_driver_list; driver; driver = driver->next)
316 if (!compare_fourcc(fccType, driver->fccType) &&
317 !compare_fourcc(fccHandler, driver->fccHandler))
318 break;
320 if (driver) return FALSE;
322 /* Register the driver */
323 driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(reg_driver));
324 if (!driver) goto oom;
325 driver->fccType = fccType;
326 driver->fccHandler = fccHandler;
328 switch(wFlags)
330 case ICINSTALL_FUNCTION:
331 driver->proc = (DRIVERPROC)lParam;
332 driver->name = NULL;
333 break;
334 case ICINSTALL_DRIVER:
335 driver->proc = NULL;
336 len = MultiByteToWideChar(CP_ACP, 0, (char*)lParam, -1, NULL, 0);
337 driver->name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
338 if (!driver->name) goto oom;
339 MultiByteToWideChar(CP_ACP, 0, (char*)lParam, -1, driver->name, len);
340 break;
341 default:
342 ERR("Invalid flags!\n");
343 HeapFree(GetProcessHeap(), 0, driver);
344 return FALSE;
347 /* Insert our driver in the list*/
348 driver->next = reg_driver_list;
349 reg_driver_list = driver;
351 return TRUE;
352 oom:
353 HeapFree(GetProcessHeap(), 0, driver);
354 return FALSE;
357 /***********************************************************************
358 * ICRemove [MSVFW32.@]
360 BOOL VFWAPI ICRemove(DWORD fccType, DWORD fccHandler, UINT wFlags)
362 reg_driver** pdriver;
363 reg_driver* drv;
365 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wFlags);
367 /* Check if a driver is already registered */
368 for (pdriver = &reg_driver_list; *pdriver; pdriver = &(*pdriver)->next)
370 if (!compare_fourcc(fccType, (*pdriver)->fccType) &&
371 !compare_fourcc(fccHandler, (*pdriver)->fccHandler))
372 break;
374 if (!*pdriver)
375 return FALSE;
377 /* Remove the driver from the list */
378 drv = *pdriver;
379 *pdriver = (*pdriver)->next;
380 HeapFree(GetProcessHeap(), 0, drv->name);
381 HeapFree(GetProcessHeap(), 0, drv);
383 return TRUE;
387 /***********************************************************************
388 * ICOpen [MSVFW32.@]
389 * Opens an installable compressor. Return special handle.
391 HIC VFWAPI ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode)
393 WCHAR codecname[10];
394 ICOPEN icopen;
395 HDRVR hdrv;
396 WINE_HIC* whic;
397 BOOL bIs16;
398 static const WCHAR drv32W[] = {'d','r','i','v','e','r','s','3','2','\0'};
399 reg_driver* driver;
401 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode);
403 /* Check if there is a registered driver that matches */
404 driver = reg_driver_list;
405 while(driver)
406 if (!compare_fourcc(fccType, driver->fccType) &&
407 !compare_fourcc(fccHandler, driver->fccHandler))
408 break;
409 else
410 driver = driver->next;
412 if (driver && driver->proc)
413 /* The driver has been registered at runtime with its driverproc */
414 return ICOpenFunction(fccType, fccHandler, wMode, driver->proc);
416 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
417 * same layout as ICOPEN
419 icopen.dwSize = sizeof(ICOPEN);
420 icopen.fccType = fccType;
421 icopen.fccHandler = fccHandler;
422 icopen.dwVersion = 0x00001000; /* FIXME */
423 icopen.dwFlags = wMode;
424 icopen.dwError = 0;
425 icopen.pV1Reserved = NULL;
426 icopen.pV2Reserved = NULL;
427 icopen.dnDevNode = 0; /* FIXME */
429 if (!driver) {
430 /* The driver is registered in the registry */
431 fourcc_to_string(codecname, fccType);
432 codecname[4] = '.';
433 fourcc_to_string(codecname + 5, fccHandler);
434 codecname[9] = '\0';
436 hdrv = OpenDriver(codecname, drv32W, (LPARAM)&icopen);
437 if (!hdrv)
438 return 0;
439 } else {
440 /* The driver has been registered at runtime with its name */
441 hdrv = OpenDriver(driver->name, NULL, (LPARAM)&icopen);
442 if (!hdrv)
443 return 0;
445 bIs16 = GetDriverFlags(hdrv) & 0x10000000; /* undocumented flag: WINE_GDF_16BIT */
447 if (bIs16)
449 FIXME("Got a 16 bit driver, but no 16 bit support in msvfw\n");
450 CloseDriver(hdrv, 0, 0);
451 return 0;
453 whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
454 if (!whic)
456 CloseDriver(hdrv, 0, 0);
457 return FALSE;
459 whic->hdrv = hdrv;
460 whic->driverproc = NULL;
461 whic->type = fccType;
462 whic->handler = fccHandler;
463 while (MSVIDEO_GetHicPtr((HIC)(ULONG_PTR)IC_HandleRef) != NULL) IC_HandleRef++;
464 whic->hic = (HIC)(ULONG_PTR)IC_HandleRef++;
465 whic->next = MSVIDEO_FirstHic;
466 MSVIDEO_FirstHic = whic;
468 TRACE("=> %p\n", whic->hic);
469 return whic->hic;
472 /***********************************************************************
473 * ICOpenFunction [MSVFW32.@]
475 HIC VFWAPI ICOpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode, FARPROC lpfnHandler)
477 ICOPEN icopen;
478 WINE_HIC* whic;
480 TRACE("(%s,%s,%d,%p)\n",
481 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode, lpfnHandler);
483 icopen.dwSize = sizeof(ICOPEN);
484 icopen.fccType = fccType;
485 icopen.fccHandler = fccHandler;
486 icopen.dwVersion = ICVERSION;
487 icopen.dwFlags = wMode;
488 icopen.dwError = 0;
489 icopen.pV1Reserved = NULL;
490 icopen.pV2Reserved = NULL;
491 icopen.dnDevNode = 0; /* FIXME */
493 whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
494 if (!whic) return 0;
496 whic->driverproc = lpfnHandler;
497 while (MSVIDEO_GetHicPtr((HIC)(ULONG_PTR)IC_HandleRef) != NULL) IC_HandleRef++;
498 whic->hic = (HIC)(ULONG_PTR)IC_HandleRef++;
499 whic->next = MSVIDEO_FirstHic;
500 MSVIDEO_FirstHic = whic;
502 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
503 /* What if the function is used more than once? */
505 if (MSVIDEO_SendMessage(whic, DRV_LOAD, 0L, 0L) != DRV_SUCCESS)
507 WARN("DRV_LOAD failed for hic %p\n", whic->hic);
508 MSVIDEO_FirstHic = whic->next;
509 HeapFree(GetProcessHeap(), 0, whic);
510 return 0;
512 /* return value is not checked */
513 MSVIDEO_SendMessage(whic, DRV_ENABLE, 0L, 0L);
515 whic->driverId = (DWORD)MSVIDEO_SendMessage(whic, DRV_OPEN, 0, (DWORD_PTR)&icopen);
516 /* FIXME: What should we put here? */
517 whic->hdrv = NULL;
519 if (whic->driverId == 0)
521 WARN("DRV_OPEN failed for hic %p\n", whic->hic);
522 MSVIDEO_FirstHic = whic->next;
523 HeapFree(GetProcessHeap(), 0, whic);
524 return 0;
527 TRACE("=> %p\n", whic->hic);
528 return whic->hic;
531 /***********************************************************************
532 * ICGetInfo [MSVFW32.@]
534 LRESULT VFWAPI ICGetInfo(HIC hic, ICINFO *picinfo, DWORD cb)
536 LRESULT ret;
537 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
539 TRACE("(%p,%p,%d)\n", hic, picinfo, cb);
541 whic = MSVIDEO_GetHicPtr(hic);
542 if (!whic) return ICERR_BADHANDLE;
543 if (!picinfo) return MMSYSERR_INVALPARAM;
545 /* (WS) The field szDriver should be initialized because the driver
546 * is not obliged and often will not do it. Some applications, like
547 * VirtualDub, rely on this field and will occasionally crash if it
548 * goes uninitialized.
550 if (cb >= sizeof(ICINFO)) picinfo->szDriver[0] = '\0';
552 ret = ICSendMessage(hic, ICM_GETINFO, (DWORD_PTR)picinfo, cb);
554 /* (WS) When szDriver was not supplied by the driver itself, apparently
555 * Windows will set its value equal to the driver file name. This can
556 * be obtained from the registry as we do here.
558 if (cb >= sizeof(ICINFO) && picinfo->szDriver[0] == 0)
560 ICINFO ii;
562 memset(&ii, 0, sizeof(ii));
563 ii.dwSize = sizeof(ii);
564 ICInfo(picinfo->fccType, picinfo->fccHandler, &ii);
565 lstrcpyW(picinfo->szDriver, ii.szDriver);
568 TRACE(" -> 0x%08lx\n", ret);
569 return ret;
572 typedef struct {
573 DWORD fccType;
574 DWORD fccHandler;
575 LPBITMAPINFOHEADER lpbiIn;
576 LPBITMAPINFOHEADER lpbiOut;
577 WORD wMode;
578 DWORD querymsg;
579 HIC hic;
580 } driver_info_t;
582 static HIC try_driver(driver_info_t *info)
584 HIC hic;
586 if ((hic = ICOpen(info->fccType, info->fccHandler, info->wMode)))
588 if (!ICSendMessage(hic, info->querymsg, (DWORD_PTR)info->lpbiIn, (DWORD_PTR)info->lpbiOut))
589 return hic;
590 ICClose(hic);
592 return 0;
595 static BOOL ICLocate_enum_handler(const char *drv, unsigned int nr, void *param)
597 driver_info_t *info = param;
598 info->fccHandler = mmioStringToFOURCCA(drv + 5, 0);
599 info->hic = try_driver(info);
600 return info->hic != 0;
603 /***********************************************************************
604 * ICLocate [MSVFW32.@]
606 HIC VFWAPI ICLocate(DWORD fccType, DWORD fccHandler, LPBITMAPINFOHEADER lpbiIn,
607 LPBITMAPINFOHEADER lpbiOut, WORD wMode)
609 driver_info_t info;
611 TRACE("(%s,%s,%p,%p,0x%04x)\n",
612 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), lpbiIn, lpbiOut, wMode);
614 info.fccType = fccType;
615 info.fccHandler = fccHandler;
616 info.lpbiIn = lpbiIn;
617 info.lpbiOut = lpbiOut;
618 info.wMode = wMode;
620 switch (wMode)
622 case ICMODE_FASTCOMPRESS:
623 case ICMODE_COMPRESS:
624 info.querymsg = ICM_COMPRESS_QUERY;
625 break;
626 case ICMODE_FASTDECOMPRESS:
627 case ICMODE_DECOMPRESS:
628 info.querymsg = ICM_DECOMPRESS_QUERY;
629 break;
630 case ICMODE_DRAW:
631 info.querymsg = ICM_DRAW_QUERY;
632 break;
633 default:
634 WARN("Unknown mode (%d)\n", wMode);
635 return 0;
638 /* Easy case: handler/type match, we just fire a query and return */
639 info.hic = try_driver(&info);
640 /* If it didn't work, try each driver in turn. 32 bit codecs only. */
641 /* FIXME: Move this to an init routine? */
642 if (!info.hic) enum_drivers(fccType, ICLocate_enum_handler, &info);
644 if (info.hic)
646 TRACE("=> %p\n", info.hic);
647 return info.hic;
650 if (fccType == streamtypeVIDEO)
651 return ICLocate(ICTYPE_VIDEO, fccHandler, lpbiIn, lpbiOut, wMode);
653 WARN("(%s,%s,%p,%p,0x%04x) not found!\n",
654 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), lpbiIn, lpbiOut, wMode);
655 return 0;
658 /***********************************************************************
659 * ICGetDisplayFormat [MSVFW32.@]
661 HIC VFWAPI ICGetDisplayFormat(
662 HIC hic,LPBITMAPINFOHEADER lpbiIn,LPBITMAPINFOHEADER lpbiOut,
663 INT depth,INT dx,INT dy)
665 HIC tmphic = hic;
667 TRACE("(%p,%p,%p,%d,%d,%d)!\n",hic,lpbiIn,lpbiOut,depth,dx,dy);
669 if (!tmphic) {
670 tmphic=ICLocate(ICTYPE_VIDEO,0,lpbiIn,NULL,ICMODE_DECOMPRESS);
671 if (!tmphic)
672 return tmphic;
674 if ((dy == lpbiIn->biHeight) && (dx == lpbiIn->biWidth))
675 dy = dx = 0; /* no resize needed */
677 /* Can we decompress it ? */
678 if (ICDecompressQuery(tmphic,lpbiIn,NULL) != 0)
679 goto errout; /* no, sorry */
681 ICSendMessage(tmphic, ICM_DECOMPRESS_GET_FORMAT, (DWORD_PTR)lpbiIn, (DWORD_PTR)lpbiOut);
683 if (lpbiOut->biCompression != 0) {
684 FIXME("Ooch, how come decompressor outputs compressed data (%d)??\n",
685 lpbiOut->biCompression);
687 if (lpbiOut->biSize < sizeof(*lpbiOut)) {
688 FIXME("Ooch, size of output BIH is too small (%d)\n",
689 lpbiOut->biSize);
690 lpbiOut->biSize = sizeof(*lpbiOut);
692 if (!depth) {
693 HDC hdc;
695 hdc = GetDC(0);
696 depth = GetDeviceCaps(hdc,BITSPIXEL)*GetDeviceCaps(hdc,PLANES);
697 ReleaseDC(0,hdc);
698 if (depth==15) depth = 16;
699 if (depth<8) depth = 8;
701 if (lpbiIn->biBitCount == 8)
702 depth = 8;
704 TRACE("=> %p\n", tmphic);
705 return tmphic;
706 errout:
707 if (hic!=tmphic)
708 ICClose(tmphic);
710 TRACE("=> 0\n");
711 return 0;
714 /***********************************************************************
715 * ICCompress [MSVFW32.@]
717 DWORD VFWAPIV
718 ICCompress(
719 HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiOutput,LPVOID lpData,
720 LPBITMAPINFOHEADER lpbiInput,LPVOID lpBits,LPDWORD lpckid,
721 LPDWORD lpdwFlags,LONG lFrameNum,DWORD dwFrameSize,DWORD dwQuality,
722 LPBITMAPINFOHEADER lpbiPrev,LPVOID lpPrev)
724 ICCOMPRESS iccmp;
726 TRACE("(%p,%d,%p,%p,%p,%p,...)\n",hic,dwFlags,lpbiOutput,lpData,lpbiInput,lpBits);
728 iccmp.dwFlags = dwFlags;
730 iccmp.lpbiOutput = lpbiOutput;
731 iccmp.lpOutput = lpData;
732 iccmp.lpbiInput = lpbiInput;
733 iccmp.lpInput = lpBits;
735 iccmp.lpckid = lpckid;
736 iccmp.lpdwFlags = lpdwFlags;
737 iccmp.lFrameNum = lFrameNum;
738 iccmp.dwFrameSize = dwFrameSize;
739 iccmp.dwQuality = dwQuality;
740 iccmp.lpbiPrev = lpbiPrev;
741 iccmp.lpPrev = lpPrev;
742 return ICSendMessage(hic,ICM_COMPRESS,(DWORD_PTR)&iccmp,sizeof(iccmp));
745 /***********************************************************************
746 * ICDecompress [MSVFW32.@]
748 DWORD VFWAPIV ICDecompress(HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiFormat,
749 LPVOID lpData,LPBITMAPINFOHEADER lpbi,LPVOID lpBits)
751 ICDECOMPRESS icd;
752 DWORD ret;
754 TRACE("(%p,%d,%p,%p,%p,%p)\n",hic,dwFlags,lpbiFormat,lpData,lpbi,lpBits);
756 icd.dwFlags = dwFlags;
757 icd.lpbiInput = lpbiFormat;
758 icd.lpInput = lpData;
760 icd.lpbiOutput = lpbi;
761 icd.lpOutput = lpBits;
762 icd.ckid = 0;
763 ret = ICSendMessage(hic,ICM_DECOMPRESS,(DWORD_PTR)&icd,sizeof(ICDECOMPRESS));
765 TRACE("-> %d\n",ret);
767 return ret;
771 struct choose_compressor
773 UINT flags;
774 LPCSTR title;
775 COMPVARS cv;
778 struct codec_info
780 HIC hic;
781 ICINFO icinfo;
784 static BOOL enum_compressors(HWND list, COMPVARS *pcv, BOOL enum_all)
786 UINT id, total = 0;
787 ICINFO icinfo;
789 id = 0;
791 while (ICInfo(pcv->fccType, id, &icinfo))
793 struct codec_info *ic;
794 DWORD idx;
795 HIC hic;
797 id++;
799 hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_COMPRESS);
801 if (hic)
803 /* for unknown reason fccHandler reported by the driver
804 * doesn't always work, use the one returned by ICInfo instead.
806 DWORD fccHandler = icinfo.fccHandler;
808 if (!enum_all && pcv->lpbiIn)
810 if (ICCompressQuery(hic, pcv->lpbiIn, NULL) != ICERR_OK)
812 TRACE("fccHandler %s doesn't support input DIB format %d\n",
813 wine_dbgstr_fcc(icinfo.fccHandler), pcv->lpbiIn->bmiHeader.biCompression);
814 ICClose(hic);
815 continue;
819 ICGetInfo(hic, &icinfo, sizeof(icinfo));
820 icinfo.fccHandler = fccHandler;
822 idx = SendMessageW(list, CB_ADDSTRING, 0, (LPARAM)icinfo.szDescription);
824 ic = HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info));
825 ic->icinfo = icinfo;
826 ic->hic = hic;
827 SendMessageW(list, CB_SETITEMDATA, idx, (LPARAM)ic);
829 total++;
832 return total != 0;
835 static INT_PTR CALLBACK icm_choose_compressor_dlgproc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
837 switch (msg)
839 case WM_INITDIALOG:
841 struct codec_info *ic;
842 WCHAR buf[128];
843 struct choose_compressor *choose_comp = (struct choose_compressor *)lparam;
845 SetWindowLongPtrW(hdlg, DWLP_USER, lparam);
847 /* FIXME */
848 choose_comp->flags &= ~(ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME);
850 if (choose_comp->title)
851 SetWindowTextA(hdlg, choose_comp->title);
853 if (!(choose_comp->flags & ICMF_CHOOSE_DATARATE))
855 ShowWindow(GetDlgItem(hdlg, IDC_DATARATE_CHECKBOX), SW_HIDE);
856 ShowWindow(GetDlgItem(hdlg, IDC_DATARATE), SW_HIDE);
857 ShowWindow(GetDlgItem(hdlg, IDC_DATARATE_KB), SW_HIDE);
860 if (!(choose_comp->flags & ICMF_CHOOSE_KEYFRAME))
862 ShowWindow(GetDlgItem(hdlg, IDC_KEYFRAME_CHECKBOX), SW_HIDE);
863 ShowWindow(GetDlgItem(hdlg, IDC_KEYFRAME), SW_HIDE);
864 ShowWindow(GetDlgItem(hdlg, IDC_KEYFRAME_FRAMES), SW_HIDE);
867 /* FIXME */
868 EnableWindow(GetDlgItem(hdlg, IDC_QUALITY_SCROLL), FALSE);
869 EnableWindow(GetDlgItem(hdlg, IDC_QUALITY_TXT), FALSE);
871 /*if (!(choose_comp->flags & ICMF_CHOOSE_PREVIEW))
872 ShowWindow(GetDlgItem(hdlg, IDC_PREVIEW), SW_HIDE);*/
874 LoadStringW(MSVFW32_hModule, IDS_FULLFRAMES, buf, 128);
875 SendDlgItemMessageW(hdlg, IDC_COMP_LIST, CB_ADDSTRING, 0, (LPARAM)buf);
877 ic = HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info));
878 ic->icinfo.fccType = streamtypeVIDEO;
879 ic->icinfo.fccHandler = comptypeDIB;
880 ic->hic = 0;
881 SendDlgItemMessageW(hdlg, IDC_COMP_LIST, CB_SETITEMDATA, 0, (LPARAM)ic);
883 enum_compressors(GetDlgItem(hdlg, IDC_COMP_LIST), &choose_comp->cv, choose_comp->flags & ICMF_CHOOSE_ALLCOMPRESSORS);
885 SendDlgItemMessageW(hdlg, IDC_COMP_LIST, CB_SETCURSEL, 0, 0);
886 SetFocus(GetDlgItem(hdlg, IDC_COMP_LIST));
888 SetWindowLongPtrW(hdlg, DWLP_USER, (ULONG_PTR)choose_comp);
889 break;
892 case WM_COMMAND:
893 switch (LOWORD(wparam))
895 case IDC_COMP_LIST:
897 INT cur_sel;
898 struct codec_info *ic;
899 BOOL can_configure = FALSE, can_about = FALSE;
900 struct choose_compressor *choose_comp;
902 if (HIWORD(wparam) != CBN_SELCHANGE && HIWORD(wparam) != CBN_SETFOCUS)
903 break;
905 choose_comp = (struct choose_compressor *)GetWindowLongPtrW(hdlg, DWLP_USER);
907 cur_sel = SendMessageW((HWND)lparam, CB_GETCURSEL, 0, 0);
909 ic = (struct codec_info *)SendMessageW((HWND)lparam, CB_GETITEMDATA, cur_sel, 0);
910 if (ic && ic->hic)
912 if (ICQueryConfigure(ic->hic) == DRVCNF_OK)
913 can_configure = TRUE;
914 if (ICQueryAbout(ic->hic) == DRVCNF_OK)
915 can_about = TRUE;
917 EnableWindow(GetDlgItem(hdlg, IDC_CONFIGURE), can_configure);
918 EnableWindow(GetDlgItem(hdlg, IDC_ABOUT), can_about);
920 if (choose_comp->flags & ICMF_CHOOSE_DATARATE)
922 /* FIXME */
924 if (choose_comp->flags & ICMF_CHOOSE_KEYFRAME)
926 /* FIXME */
929 break;
932 case IDC_CONFIGURE:
933 case IDC_ABOUT:
935 HWND list = GetDlgItem(hdlg, IDC_COMP_LIST);
936 INT cur_sel;
937 struct codec_info *ic;
939 if (HIWORD(wparam) != BN_CLICKED)
940 break;
942 cur_sel = SendMessageW(list, CB_GETCURSEL, 0, 0);
944 ic = (struct codec_info *)SendMessageW(list, CB_GETITEMDATA, cur_sel, 0);
945 if (ic && ic->hic)
947 if (LOWORD(wparam) == IDC_CONFIGURE)
948 ICConfigure(ic->hic, hdlg);
949 else
950 ICAbout(ic->hic, hdlg);
953 break;
956 case IDOK:
958 HWND list = GetDlgItem(hdlg, IDC_COMP_LIST);
959 INT cur_sel;
960 struct codec_info *ic;
962 if (HIWORD(wparam) != BN_CLICKED)
963 break;
965 cur_sel = SendMessageW(list, CB_GETCURSEL, 0, 0);
966 ic = (struct codec_info *)SendMessageW(list, CB_GETITEMDATA, cur_sel, 0);
967 if (ic)
969 struct choose_compressor *choose_comp = (struct choose_compressor *)GetWindowLongPtrW(hdlg, DWLP_USER);
971 choose_comp->cv.hic = ic->hic;
972 choose_comp->cv.fccType = ic->icinfo.fccType;
973 choose_comp->cv.fccHandler = ic->icinfo.fccHandler;
974 /* FIXME: fill everything else */
976 /* prevent closing the codec handle below */
977 ic->hic = 0;
980 /* fall through */
981 case IDCANCEL:
983 HWND list = GetDlgItem(hdlg, IDC_COMP_LIST);
984 INT idx = 0;
986 if (HIWORD(wparam) != BN_CLICKED)
987 break;
989 while (1)
991 struct codec_info *ic;
993 ic = (struct codec_info *)SendMessageW(list, CB_GETITEMDATA, idx++, 0);
995 if (!ic || (LONG_PTR)ic == CB_ERR) break;
997 if (ic->hic) ICClose(ic->hic);
998 HeapFree(GetProcessHeap(), 0, ic);
1001 EndDialog(hdlg, LOWORD(wparam) == IDOK);
1002 break;
1005 default:
1006 break;
1008 break;
1010 default:
1011 break;
1014 return FALSE;
1017 /***********************************************************************
1018 * ICCompressorChoose [MSVFW32.@]
1020 BOOL VFWAPI ICCompressorChoose(HWND hwnd, UINT uiFlags, LPVOID pvIn,
1021 LPVOID lpData, PCOMPVARS pc, LPSTR lpszTitle)
1023 struct choose_compressor choose_comp;
1024 BOOL ret;
1026 TRACE("(%p,%08x,%p,%p,%p,%s)\n", hwnd, uiFlags, pvIn, lpData, pc, lpszTitle);
1028 if (!pc || pc->cbSize != sizeof(COMPVARS))
1029 return FALSE;
1031 if (!(pc->dwFlags & ICMF_COMPVARS_VALID))
1033 pc->dwFlags = 0;
1034 pc->fccType = pc->fccHandler = 0;
1035 pc->hic = NULL;
1036 pc->lpbiIn = NULL;
1037 pc->lpbiOut = NULL;
1038 pc->lpBitsOut = pc->lpBitsPrev = pc->lpState = NULL;
1039 pc->lQ = ICQUALITY_DEFAULT;
1040 pc->lKey = -1;
1041 pc->lDataRate = 300; /* kB */
1042 pc->lpState = NULL;
1043 pc->cbState = 0;
1045 if (pc->fccType == 0)
1046 pc->fccType = ICTYPE_VIDEO;
1048 choose_comp.cv = *pc;
1049 choose_comp.flags = uiFlags;
1050 choose_comp.title = lpszTitle;
1052 ret = DialogBoxParamW(MSVFW32_hModule, MAKEINTRESOURCEW(ICM_CHOOSE_COMPRESSOR), hwnd,
1053 icm_choose_compressor_dlgproc, (LPARAM)&choose_comp);
1055 if (ret)
1057 *pc = choose_comp.cv;
1058 pc->dwFlags |= ICMF_COMPVARS_VALID;
1061 return ret;
1065 /***********************************************************************
1066 * ICCompressorFree [MSVFW32.@]
1068 void VFWAPI ICCompressorFree(PCOMPVARS pc)
1070 TRACE("(%p)\n",pc);
1072 if (pc != NULL && pc->cbSize == sizeof(COMPVARS)) {
1073 if (pc->hic != NULL) {
1074 ICClose(pc->hic);
1075 pc->hic = NULL;
1077 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1078 pc->lpbiIn = NULL;
1079 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
1080 pc->lpBitsOut = NULL;
1081 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1082 pc->lpBitsPrev = NULL;
1083 HeapFree(GetProcessHeap(), 0, pc->lpState);
1084 pc->lpState = NULL;
1085 pc->dwFlags = 0;
1089 /***********************************************************************
1090 * ICSendMessage [MSVFW32.@]
1092 LRESULT VFWAPI ICSendMessage(HIC hic, UINT msg, DWORD_PTR lParam1, DWORD_PTR lParam2)
1094 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
1096 if (!whic) return ICERR_BADHANDLE;
1097 return MSVIDEO_SendMessage(whic, msg, lParam1, lParam2);
1100 /***********************************************************************
1101 * ICDrawBegin [MSVFW32.@]
1103 DWORD VFWAPIV ICDrawBegin(
1104 HIC hic, /* [in] */
1105 DWORD dwFlags, /* [in] flags */
1106 HPALETTE hpal, /* [in] palette to draw with */
1107 HWND hwnd, /* [in] window to draw to */
1108 HDC hdc, /* [in] HDC to draw to */
1109 INT xDst, /* [in] destination rectangle */
1110 INT yDst, /* [in] */
1111 INT dxDst, /* [in] */
1112 INT dyDst, /* [in] */
1113 LPBITMAPINFOHEADER lpbi, /* [in] format of frame to draw */
1114 INT xSrc, /* [in] source rectangle */
1115 INT ySrc, /* [in] */
1116 INT dxSrc, /* [in] */
1117 INT dySrc, /* [in] */
1118 DWORD dwRate, /* [in] frames/second = (dwRate/dwScale) */
1119 DWORD dwScale) /* [in] */
1122 ICDRAWBEGIN icdb;
1124 TRACE("(%p,%d,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%d,%d)\n",
1125 hic, dwFlags, hpal, hwnd, hdc, xDst, yDst, dxDst, dyDst,
1126 lpbi, xSrc, ySrc, dxSrc, dySrc, dwRate, dwScale);
1128 icdb.dwFlags = dwFlags;
1129 icdb.hpal = hpal;
1130 icdb.hwnd = hwnd;
1131 icdb.hdc = hdc;
1132 icdb.xDst = xDst;
1133 icdb.yDst = yDst;
1134 icdb.dxDst = dxDst;
1135 icdb.dyDst = dyDst;
1136 icdb.lpbi = lpbi;
1137 icdb.xSrc = xSrc;
1138 icdb.ySrc = ySrc;
1139 icdb.dxSrc = dxSrc;
1140 icdb.dySrc = dySrc;
1141 icdb.dwRate = dwRate;
1142 icdb.dwScale = dwScale;
1143 return ICSendMessage(hic,ICM_DRAW_BEGIN,(DWORD_PTR)&icdb,sizeof(icdb));
1146 /***********************************************************************
1147 * ICDraw [MSVFW32.@]
1149 DWORD VFWAPIV ICDraw(HIC hic, DWORD dwFlags, LPVOID lpFormat, LPVOID lpData, DWORD cbData, LONG lTime) {
1150 ICDRAW icd;
1152 TRACE("(%p,%d,%p,%p,%d,%d)\n",hic,dwFlags,lpFormat,lpData,cbData,lTime);
1154 icd.dwFlags = dwFlags;
1155 icd.lpFormat = lpFormat;
1156 icd.lpData = lpData;
1157 icd.cbData = cbData;
1158 icd.lTime = lTime;
1160 return ICSendMessage(hic,ICM_DRAW,(DWORD_PTR)&icd,sizeof(icd));
1163 /***********************************************************************
1164 * ICClose [MSVFW32.@]
1166 LRESULT WINAPI ICClose(HIC hic)
1168 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
1169 WINE_HIC** p;
1171 TRACE("(%p)\n",hic);
1173 if (!whic) return ICERR_BADHANDLE;
1175 if (whic->driverproc)
1177 MSVIDEO_SendMessage(whic, DRV_CLOSE, 0, 0);
1178 MSVIDEO_SendMessage(whic, DRV_DISABLE, 0, 0);
1179 MSVIDEO_SendMessage(whic, DRV_FREE, 0, 0);
1181 else
1183 CloseDriver(whic->hdrv, 0, 0);
1186 /* remove whic from list */
1187 for (p = &MSVIDEO_FirstHic; *p != NULL; p = &((*p)->next))
1189 if ((*p) == whic)
1191 *p = whic->next;
1192 break;
1196 HeapFree(GetProcessHeap(), 0, whic);
1197 return 0;
1202 /***********************************************************************
1203 * ICImageCompress [MSVFW32.@]
1205 HANDLE VFWAPI ICImageCompress(
1206 HIC hic, UINT uiFlags,
1207 LPBITMAPINFO lpbiIn, LPVOID lpBits,
1208 LPBITMAPINFO lpbiOut, LONG lQuality,
1209 LONG* plSize)
1211 FIXME("(%p,%08x,%p,%p,%p,%d,%p)\n",
1212 hic, uiFlags, lpbiIn, lpBits, lpbiOut, lQuality, plSize);
1214 return NULL;
1217 /***********************************************************************
1218 * ICImageDecompress [MSVFW32.@]
1221 HANDLE VFWAPI ICImageDecompress(
1222 HIC hic, UINT uiFlags, LPBITMAPINFO lpbiIn,
1223 LPVOID lpBits, LPBITMAPINFO lpbiOut)
1225 HGLOBAL hMem = NULL;
1226 BYTE* pMem = NULL;
1227 BOOL bReleaseIC = FALSE;
1228 BYTE* pHdr = NULL;
1229 ULONG cbHdr = 0;
1230 BOOL bSucceeded = FALSE;
1231 BOOL bInDecompress = FALSE;
1232 DWORD biSizeImage;
1234 TRACE("(%p,%08x,%p,%p,%p)\n",
1235 hic, uiFlags, lpbiIn, lpBits, lpbiOut);
1237 if ( hic == NULL )
1239 hic = ICDecompressOpen( ICTYPE_VIDEO, 0, &lpbiIn->bmiHeader, (lpbiOut != NULL) ? &lpbiOut->bmiHeader : NULL );
1240 if ( hic == NULL )
1242 WARN("no handler\n" );
1243 goto err;
1245 bReleaseIC = TRUE;
1247 if ( uiFlags != 0 )
1249 FIXME( "unknown flag %08x\n", uiFlags );
1250 goto err;
1252 if ( lpbiIn == NULL || lpBits == NULL )
1254 WARN("invalid argument\n");
1255 goto err;
1258 if ( lpbiOut != NULL )
1260 if ( lpbiOut->bmiHeader.biSize != sizeof(BITMAPINFOHEADER) )
1261 goto err;
1262 cbHdr = sizeof(BITMAPINFOHEADER);
1263 if ( lpbiOut->bmiHeader.biCompression == 3 )
1264 cbHdr += sizeof(DWORD)*3;
1265 else
1266 if ( lpbiOut->bmiHeader.biBitCount <= 8 )
1268 if ( lpbiOut->bmiHeader.biClrUsed == 0 )
1269 cbHdr += sizeof(RGBQUAD) * (1<<lpbiOut->bmiHeader.biBitCount);
1270 else
1271 cbHdr += sizeof(RGBQUAD) * lpbiOut->bmiHeader.biClrUsed;
1274 else
1276 TRACE( "get format\n" );
1278 cbHdr = ICDecompressGetFormatSize(hic,lpbiIn);
1279 if ( cbHdr < sizeof(BITMAPINFOHEADER) )
1280 goto err;
1281 pHdr = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,cbHdr+sizeof(RGBQUAD)*256);
1282 if ( pHdr == NULL )
1283 goto err;
1284 if ( ICDecompressGetFormat( hic, lpbiIn, pHdr ) != ICERR_OK )
1285 goto err;
1286 lpbiOut = (BITMAPINFO*)pHdr;
1287 if ( lpbiOut->bmiHeader.biBitCount <= 8 &&
1288 ICDecompressGetPalette( hic, lpbiIn, lpbiOut ) != ICERR_OK &&
1289 lpbiIn->bmiHeader.biBitCount == lpbiOut->bmiHeader.biBitCount )
1291 if ( lpbiIn->bmiHeader.biClrUsed == 0 )
1292 memcpy( lpbiOut->bmiColors, lpbiIn->bmiColors, sizeof(RGBQUAD)*(1<<lpbiOut->bmiHeader.biBitCount) );
1293 else
1294 memcpy( lpbiOut->bmiColors, lpbiIn->bmiColors, sizeof(RGBQUAD)*lpbiIn->bmiHeader.biClrUsed );
1296 if ( lpbiOut->bmiHeader.biBitCount <= 8 &&
1297 lpbiOut->bmiHeader.biClrUsed == 0 )
1298 lpbiOut->bmiHeader.biClrUsed = 1<<lpbiOut->bmiHeader.biBitCount;
1300 lpbiOut->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1301 cbHdr = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*lpbiOut->bmiHeader.biClrUsed;
1304 biSizeImage = lpbiOut->bmiHeader.biSizeImage;
1305 if ( biSizeImage == 0 )
1306 biSizeImage = ((((lpbiOut->bmiHeader.biWidth * lpbiOut->bmiHeader.biBitCount + 7) >> 3) + 3) & (~3)) * abs(lpbiOut->bmiHeader.biHeight);
1308 TRACE( "call ICDecompressBegin\n" );
1310 if ( ICDecompressBegin( hic, lpbiIn, lpbiOut ) != ICERR_OK )
1311 goto err;
1312 bInDecompress = TRUE;
1314 TRACE( "cbHdr %d, biSizeImage %d\n", cbHdr, biSizeImage );
1316 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_ZEROINIT, cbHdr + biSizeImage );
1317 if ( hMem == NULL )
1319 WARN( "out of memory\n" );
1320 goto err;
1322 pMem = GlobalLock( hMem );
1323 if ( pMem == NULL )
1324 goto err;
1325 memcpy( pMem, lpbiOut, cbHdr );
1327 TRACE( "call ICDecompress\n" );
1328 if ( ICDecompress( hic, 0, &lpbiIn->bmiHeader, lpBits, &lpbiOut->bmiHeader, pMem+cbHdr ) != ICERR_OK )
1329 goto err;
1331 bSucceeded = TRUE;
1332 err:
1333 if ( bInDecompress )
1334 ICDecompressEnd( hic );
1335 if ( bReleaseIC )
1336 ICClose(hic);
1337 HeapFree(GetProcessHeap(),0,pHdr);
1338 if ( pMem != NULL )
1339 GlobalUnlock( hMem );
1340 if ( !bSucceeded && hMem != NULL )
1342 GlobalFree(hMem); hMem = NULL;
1345 return hMem;
1348 /***********************************************************************
1349 * ICSeqCompressFrame [MSVFW32.@]
1351 LPVOID VFWAPI ICSeqCompressFrame(PCOMPVARS pc, UINT uiFlags, LPVOID lpBits, BOOL *pfKey, LONG *plSize)
1353 ICCOMPRESS* icComp = pc->lpState;
1354 DWORD ret;
1355 TRACE("(%p, 0x%08x, %p, %p, %p)\n", pc, uiFlags, lpBits, pfKey, plSize);
1357 if (pc->cbState != sizeof(ICCOMPRESS))
1359 ERR("Invalid cbState %i\n", pc->cbState);
1360 return NULL;
1363 if (!pc->lKeyCount++)
1364 icComp->dwFlags = ICCOMPRESS_KEYFRAME;
1365 else
1367 if (pc->lKey && pc->lKeyCount == (pc->lKey - 1))
1368 /* No key frames if pc->lKey == 0 */
1369 pc->lKeyCount = 0;
1370 icComp->dwFlags = 0;
1373 icComp->lpInput = lpBits;
1374 icComp->lFrameNum = pc->lFrame++;
1375 icComp->lpOutput = pc->lpBitsOut;
1376 icComp->lpPrev = pc->lpBitsPrev;
1377 ret = ICSendMessage(pc->hic, ICM_COMPRESS, (DWORD_PTR)icComp, sizeof(icComp));
1379 if (icComp->dwFlags & AVIIF_KEYFRAME)
1381 pc->lKeyCount = 1;
1382 *pfKey = TRUE;
1383 TRACE("Key frame\n");
1385 else
1386 *pfKey = FALSE;
1388 *plSize = icComp->lpbiOutput->biSizeImage;
1389 TRACE(" -- 0x%08x\n", ret);
1390 if (ret == ICERR_OK)
1392 LPVOID oldprev, oldout;
1393 /* We shift Prev and Out, so we don't have to allocate and release memory */
1394 oldprev = pc->lpBitsPrev;
1395 oldout = pc->lpBitsOut;
1396 pc->lpBitsPrev = oldout;
1397 pc->lpBitsOut = oldprev;
1399 TRACE("returning: %p\n", icComp->lpOutput);
1400 return icComp->lpOutput;
1402 return NULL;
1405 /***********************************************************************
1406 * ICSeqCompressFrameEnd [MSVFW32.@]
1408 void VFWAPI ICSeqCompressFrameEnd(PCOMPVARS pc)
1410 DWORD ret;
1411 TRACE("(%p)\n", pc);
1412 ret = ICSendMessage(pc->hic, ICM_COMPRESS_END, 0, 0);
1413 TRACE(" -- %x\n", ret);
1414 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1415 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1416 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
1417 HeapFree(GetProcessHeap(), 0, pc->lpState);
1418 pc->lpbiIn = pc->lpBitsPrev = pc->lpBitsOut = pc->lpState = NULL;
1421 /***********************************************************************
1422 * ICSeqCompressFrameStart [MSVFW32.@]
1424 BOOL VFWAPI ICSeqCompressFrameStart(PCOMPVARS pc, LPBITMAPINFO lpbiIn)
1426 /* I'm ignoring bmiColors as I don't know what to do with it,
1427 * it doesn't appear to be used though
1429 DWORD ret;
1430 pc->lpbiIn = HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO));
1431 if (!pc->lpbiIn)
1432 return FALSE;
1434 *pc->lpbiIn = *lpbiIn;
1435 pc->lpBitsPrev = HeapAlloc(GetProcessHeap(), 0, pc->lpbiIn->bmiHeader.biSizeImage);
1436 if (!pc->lpBitsPrev)
1438 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1439 return FALSE;
1442 pc->lpState = HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS));
1443 if (!pc->lpState)
1445 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1446 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1447 return FALSE;
1449 pc->cbState = sizeof(ICCOMPRESS);
1451 pc->lpBitsOut = HeapAlloc(GetProcessHeap(), 0, pc->lpbiOut->bmiHeader.biSizeImage);
1452 if (!pc->lpBitsOut)
1454 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1455 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1456 HeapFree(GetProcessHeap(), 0, pc->lpState);
1457 return FALSE;
1459 TRACE("Compvars:\n"
1460 "\tpc:\n"
1461 "\tsize: %i\n"
1462 "\tflags: %i\n"
1463 "\thic: %p\n"
1464 "\ttype: %x\n"
1465 "\thandler: %x\n"
1466 "\tin/out: %p/%p\n"
1467 "key/data/quality: %i/%i/%i\n",
1468 pc->cbSize, pc->dwFlags, pc->hic, pc->fccType, pc->fccHandler,
1469 pc->lpbiIn, pc->lpbiOut, pc->lKey, pc->lDataRate, pc->lQ);
1471 ret = ICSendMessage(pc->hic, ICM_COMPRESS_BEGIN, (DWORD_PTR)pc->lpbiIn, (DWORD_PTR)pc->lpbiOut);
1472 TRACE(" -- %x\n", ret);
1473 if (ret == ICERR_OK)
1475 ICCOMPRESS* icComp = pc->lpState;
1476 /* Initialise some variables */
1477 pc->lFrame = 0; pc->lKeyCount = 0;
1479 icComp->lpbiOutput = &pc->lpbiOut->bmiHeader;
1480 icComp->lpbiInput = &pc->lpbiIn->bmiHeader;
1481 icComp->lpckid = NULL;
1482 icComp->dwFrameSize = 0;
1483 icComp->dwQuality = pc->lQ;
1484 icComp->lpbiPrev = &pc->lpbiIn->bmiHeader;
1485 return TRUE;
1487 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1488 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1489 HeapFree(GetProcessHeap(), 0, pc->lpState);
1490 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
1491 pc->lpBitsPrev = pc->lpbiIn = pc->lpState = pc->lpBitsOut = NULL;
1492 return FALSE;
1495 /***********************************************************************
1496 * GetFileNamePreview [MSVFW32.@]
1498 static BOOL GetFileNamePreview(LPVOID lpofn,BOOL bSave,BOOL bUnicode)
1500 CHAR szFunctionName[20];
1501 BOOL (*fnGetFileName)(LPVOID);
1502 HMODULE hComdlg32;
1503 BOOL ret;
1505 FIXME("(%p,%d,%d), semi-stub!\n",lpofn,bSave,bUnicode);
1507 lstrcpyA(szFunctionName, (bSave ? "GetSaveFileName" : "GetOpenFileName"));
1508 lstrcatA(szFunctionName, (bUnicode ? "W" : "A"));
1510 hComdlg32 = LoadLibraryA("COMDLG32.DLL");
1511 if (hComdlg32 == NULL)
1512 return FALSE;
1514 fnGetFileName = (LPVOID)GetProcAddress(hComdlg32, szFunctionName);
1515 if (fnGetFileName == NULL)
1516 return FALSE;
1518 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1519 ret = fnGetFileName(lpofn);
1521 FreeLibrary(hComdlg32);
1522 return ret;
1525 /***********************************************************************
1526 * GetOpenFileNamePreviewA [MSVFW32.@]
1528 BOOL WINAPI GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn)
1530 FIXME("(%p), semi-stub!\n", lpofn);
1532 return GetFileNamePreview(lpofn, FALSE, FALSE);
1535 /***********************************************************************
1536 * GetOpenFileNamePreviewW [MSVFW32.@]
1538 BOOL WINAPI GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn)
1540 FIXME("(%p), semi-stub!\n", lpofn);
1542 return GetFileNamePreview(lpofn, FALSE, TRUE);
1545 /***********************************************************************
1546 * GetSaveFileNamePreviewA [MSVFW32.@]
1548 BOOL WINAPI GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn)
1550 FIXME("(%p), semi-stub!\n", lpofn);
1552 return GetFileNamePreview(lpofn, TRUE, FALSE);
1555 /***********************************************************************
1556 * GetSaveFileNamePreviewW [MSVFW32.@]
1558 BOOL WINAPI GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn)
1560 FIXME("(%p), semi-stub!\n", lpofn);
1562 return GetFileNamePreview(lpofn, TRUE, TRUE);