Clean up devenum and properly implement DllCanUnloadNow ref counting.
[wine/multimedia.git] / dlls / msvideo / msvideo_main.c
blob0dc97b1a9e130b7bf2cc897633c867d25f15d195
1 /*
2 * Copyright 1998 Marcus Meissner
3 * Copyright 2000 Bradley Baetz
4 * Copyright 2003 Michael Günnewig
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * FIXME: This all assumes 32 bit codecs
21 * Win95 appears to prefer 32 bit codecs, even from 16 bit code.
22 * There is the ICOpenFunction16 to worry about still, though.
24 * TODO
25 * - no thread safety
28 #include <stdio.h>
29 #include <string.h>
31 #include "msvideo_private.h"
32 #include "winnls.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "winreg.h"
37 #include "windowsx.h"
39 #include "wine/debug.h"
41 /* Drivers32 settings */
42 #define HKLM_DRIVERS32 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32"
44 WINE_DEFAULT_DEBUG_CHANNEL(msvideo);
46 static inline const char *wine_dbgstr_fcc( DWORD fcc )
48 return wine_dbg_sprintf("%c%c%c%c",
49 LOBYTE(LOWORD(fcc)), HIBYTE(LOWORD(fcc)),
50 LOBYTE(HIWORD(fcc)), HIBYTE(HIWORD(fcc)));
53 LRESULT (CALLBACK *pFnCallTo16)(HDRVR, HIC, UINT, LPARAM, LPARAM) = NULL;
55 static WINE_HIC* MSVIDEO_FirstHic /* = NULL */;
57 typedef struct _reg_driver reg_driver;
58 struct _reg_driver
60 DWORD fccType;
61 DWORD fccHandler;
62 DRIVERPROC proc;
63 LPWSTR name;
64 reg_driver* next;
67 static reg_driver* reg_driver_list = NULL;
69 /* This one is a macro such that it works for both ASCII and Unicode */
70 #define fourcc_to_string(str, fcc) do { \
71 (str)[0] = LOBYTE(LOWORD(fcc)); \
72 (str)[1] = HIBYTE(LOWORD(fcc)); \
73 (str)[2] = LOBYTE(HIWORD(fcc)); \
74 (str)[3] = HIBYTE(HIWORD(fcc)); \
75 } while(0)
77 HMODULE MSVFW32_hModule;
79 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
81 TRACE("%p,%lx,%p\n", hinst, reason, reserved);
83 switch(reason)
85 case DLL_PROCESS_ATTACH:
86 DisableThreadLibraryCalls(hinst);
87 MSVFW32_hModule = (HMODULE)hinst;
88 break;
90 return TRUE;
93 static int compare_fourcc(DWORD fcc1, DWORD fcc2)
95 char fcc_str1[4];
96 char fcc_str2[4];
97 fourcc_to_string(fcc_str1, fcc1);
98 fourcc_to_string(fcc_str2, fcc2);
99 return strncasecmp(fcc_str1, fcc_str2, 4);
102 typedef BOOL (*enum_handler_t)(const char*, int, void*);
104 static BOOL enum_drivers(DWORD fccType, enum_handler_t handler, void* param)
106 CHAR buf[2048], fccTypeStr[5], *s;
107 DWORD i, cnt = 0, bufLen, lRet;
108 BOOL result = FALSE;
109 FILETIME lastWrite;
110 HKEY hKey;
112 fourcc_to_string(fccTypeStr, fccType);
113 fccTypeStr[4] = '.';
115 /* first, go through the registry entries */
116 lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, HKLM_DRIVERS32, 0, KEY_QUERY_VALUE, &hKey);
117 if (lRet == ERROR_SUCCESS)
119 RegQueryInfoKeyA( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
120 for (i = 0; i < cnt; i++)
122 bufLen = sizeof(buf) / sizeof(buf[0]);
123 lRet = RegEnumKeyExA(hKey, i, buf, &bufLen, 0, 0, 0, &lastWrite);
124 if (lRet != ERROR_SUCCESS) continue;
125 if (strncasecmp(buf, fccTypeStr, 5) || buf[9] != '=') continue;
126 if ((result = handler(buf, i, param))) break;
128 RegCloseKey( hKey );
130 if (result) return result;
132 /* if that didn't work, go through the values in system.ini */
133 if (GetPrivateProfileSectionA("drivers32", buf, sizeof(buf), "system.ini"))
135 for (s = buf; *s; cnt++, s += strlen(s) + 1)
137 if (strncasecmp(s, fccTypeStr, 5) || s[9] != '=') continue;
138 if ((result = handler(s, cnt, param))) break;
142 return result;
145 /******************************************************************
146 * MSVIDEO_GetHicPtr
150 WINE_HIC* MSVIDEO_GetHicPtr(HIC hic)
152 WINE_HIC* whic;
154 for (whic = MSVIDEO_FirstHic; whic && whic->hic != hic; whic = whic->next);
155 return whic;
158 /***********************************************************************
159 * VideoForWindowsVersion [MSVFW32.2]
160 * VideoForWindowsVersion [MSVIDEO.2]
161 * Returns the version in major.minor form.
162 * In Windows95 this returns 0x040003b6 (4.950)
164 DWORD WINAPI VideoForWindowsVersion(void)
166 return 0x040003B6; /* 4.950 */
169 static BOOL ICInfo_enum_handler(const char *drv, int nr, void *param)
171 ICINFO *lpicinfo = (ICINFO *)param;
172 DWORD fccHandler = mmioStringToFOURCCA(drv + 5, 0);
174 /* exact match of fccHandler or nth driver found */
175 if ((lpicinfo->fccHandler != nr) && (lpicinfo->fccHandler != fccHandler))
176 return FALSE;
178 lpicinfo->fccType = mmioStringToFOURCCA(drv, 0);
179 lpicinfo->fccHandler = fccHandler;
180 lpicinfo->dwFlags = 0;
181 lpicinfo->dwVersion = 0;
182 lpicinfo->dwVersionICM = 0x104;
183 lpicinfo->szName[0] = 0;
184 lpicinfo->szDescription[0] = 0;
185 MultiByteToWideChar(CP_ACP, 0, drv + 10, -1, lpicinfo->szDriver,
186 sizeof(lpicinfo->szDriver)/sizeof(WCHAR));
188 return TRUE;
191 /***********************************************************************
192 * ICInfo [MSVFW32.@]
193 * Get information about an installable compressor. Return TRUE if there
194 * is one.
196 * PARAMS
197 * fccType [I] type of compressor (e.g. 'vidc')
198 * fccHandler [I] real fcc for handler or <n>th compressor
199 * lpicinfo [O] information about compressor
201 BOOL VFWAPI ICInfo( DWORD fccType, DWORD fccHandler, ICINFO *lpicinfo)
203 TRACE("(%s,%s/%08lx,%p)\n",
204 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), fccHandler, lpicinfo);
206 lpicinfo->fccHandler = fccHandler;
207 return enum_drivers(fccType, ICInfo_enum_handler, lpicinfo);
210 static DWORD IC_HandleRef = 1;
212 /***********************************************************************
213 * ICInstall [MSVFW32.@]
215 BOOL VFWAPI ICInstall(DWORD fccType, DWORD fccHandler, LPARAM lParam, LPSTR szDesc, UINT wFlags)
217 reg_driver* driver;
218 unsigned len;
220 TRACE("(%s,%s,%p,%p,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), (void*)lParam, szDesc, wFlags);
222 /* Check if a driver is already registered */
223 for (driver = reg_driver_list; driver; driver = driver->next)
225 if (!compare_fourcc(fccType, driver->fccType) &&
226 !compare_fourcc(fccHandler, driver->fccHandler))
227 break;
229 if (driver) return FALSE;
231 /* Register the driver */
232 driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(reg_driver));
233 if (!driver) goto oom;
234 driver->fccType = fccType;
235 driver->fccHandler = fccHandler;
237 switch(wFlags)
239 case ICINSTALL_FUNCTION:
240 driver->proc = (DRIVERPROC)lParam;
241 driver->name = NULL;
242 break;
243 case ICINSTALL_DRIVER:
244 driver->proc = NULL;
245 len = MultiByteToWideChar(CP_ACP, 0, (char*)lParam, -1, NULL, 0);
246 driver->name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
247 if (!driver->name) goto oom;
248 MultiByteToWideChar(CP_ACP, 0, (char*)lParam, -1, driver->name, len);
249 break;
250 default:
251 ERR("Invalid flags!\n");
252 HeapFree(GetProcessHeap(), 0, driver);
253 return FALSE;
256 /* Insert our driver in the list*/
257 driver->next = reg_driver_list;
258 reg_driver_list = driver;
260 return TRUE;
261 oom:
262 if (driver) HeapFree(GetProcessHeap(), 0, driver);
263 return FALSE;
266 /***********************************************************************
267 * ICRemove [MSVFW32.@]
269 BOOL VFWAPI ICRemove(DWORD fccType, DWORD fccHandler, UINT wFlags)
271 reg_driver** pdriver;
273 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wFlags);
275 /* Check if a driver is already registered */
276 for (pdriver = &reg_driver_list; *pdriver; pdriver = &(*pdriver)->next)
278 if (!compare_fourcc(fccType, (*pdriver)->fccType) &&
279 !compare_fourcc(fccHandler, (*pdriver)->fccHandler))
280 break;
282 if (!*pdriver)
283 return FALSE;
285 /* Remove the driver from the list */
286 *pdriver = (*pdriver)->next;
287 if ((*pdriver)->name)
288 HeapFree(GetProcessHeap(), 0, (*pdriver)->name);
289 HeapFree(GetProcessHeap(), 0, *pdriver);
291 return TRUE;
295 /***********************************************************************
296 * ICOpen [MSVFW32.@]
297 * Opens an installable compressor. Return special handle.
299 HIC VFWAPI ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode)
301 WCHAR codecname[10];
302 ICOPEN icopen;
303 HDRVR hdrv;
304 WINE_HIC* whic;
305 BOOL bIs16;
306 static const WCHAR drv32W[] = {'d','r','i','v','e','r','s','3','2','\0'};
307 reg_driver* driver;
309 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode);
311 /* Check if there is a registered driver that matches */
312 driver = reg_driver_list;
313 while(driver)
314 if (!compare_fourcc(fccType, driver->fccType) &&
315 !compare_fourcc(fccHandler, driver->fccHandler))
316 break;
317 else
318 driver = driver->next;
320 if (driver && driver->proc)
321 /* The driver has been registered at runtime with its driverproc */
322 return MSVIDEO_OpenFunction(fccType, fccHandler, wMode, (DRIVERPROC)driver->proc, (DWORD)NULL);
324 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
325 * same layout as ICOPEN
327 icopen.dwSize = sizeof(ICOPEN);
328 icopen.fccType = fccType;
329 icopen.fccHandler = fccHandler;
330 icopen.dwVersion = 0x00001000; /* FIXME */
331 icopen.dwFlags = wMode;
332 icopen.dwError = 0;
333 icopen.pV1Reserved = NULL;
334 icopen.pV2Reserved = NULL;
335 icopen.dnDevNode = 0; /* FIXME */
337 if (!driver) {
338 /* The driver is registered in the registry */
339 fourcc_to_string(codecname, fccType);
340 codecname[4] = '.';
341 fourcc_to_string(codecname + 5, fccHandler);
342 codecname[9] = '\0';
344 hdrv = OpenDriver(codecname, drv32W, (LPARAM)&icopen);
345 if (!hdrv)
347 if (fccType == streamtypeVIDEO)
349 codecname[0] = 'v';
350 codecname[1] = 'i';
351 codecname[2] = 'd';
352 codecname[3] = 'c';
354 fccType = ICTYPE_VIDEO;
355 hdrv = OpenDriver(codecname, drv32W, (LPARAM)&icopen);
357 if (!hdrv)
358 return 0;
360 } else {
361 /* The driver has been registered at runtime with its name */
362 hdrv = OpenDriver(driver->name, NULL, (LPARAM)&icopen);
363 if (!hdrv)
364 return 0;
366 bIs16 = GetDriverFlags(hdrv) & 0x10000000; /* undocumented flag: WINE_GDF_16BIT */
368 if (bIs16 && !pFnCallTo16)
370 FIXME("Got a 16 bit driver, but no 16 bit support in msvfw\n");
371 return 0;
373 whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
374 if (!whic)
376 CloseDriver(hdrv, 0, 0);
377 return FALSE;
379 whic->hdrv = hdrv;
380 /* FIXME: is the signature the real one ? */
381 whic->driverproc = bIs16 ? (DRIVERPROC)pFnCallTo16 : NULL;
382 whic->driverproc16 = 0;
383 whic->type = fccType;
384 whic->handler = fccHandler;
385 while (MSVIDEO_GetHicPtr(HIC_32(IC_HandleRef)) != NULL) IC_HandleRef++;
386 whic->hic = HIC_32(IC_HandleRef++);
387 whic->next = MSVIDEO_FirstHic;
388 MSVIDEO_FirstHic = whic;
390 TRACE("=> %p\n", whic->hic);
391 return whic->hic;
394 /***********************************************************************
395 * MSVIDEO_OpenFunction
397 HIC MSVIDEO_OpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode,
398 DRIVERPROC lpfnHandler, DWORD lpfnHandler16)
400 ICOPEN icopen;
401 WINE_HIC* whic;
403 TRACE("(%s,%s,%d,%p,%08lx)\n",
404 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode, lpfnHandler, lpfnHandler16);
406 icopen.dwSize = sizeof(ICOPEN);
407 icopen.fccType = fccType;
408 icopen.fccHandler = fccHandler;
409 icopen.dwVersion = 0x00001000; /* FIXME */
410 icopen.dwFlags = wMode;
411 icopen.dwError = 0;
412 icopen.pV1Reserved = NULL;
413 icopen.pV2Reserved = NULL;
414 icopen.dnDevNode = 0; /* FIXME */
416 whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
417 if (!whic) return 0;
419 whic->driverproc = lpfnHandler;
420 whic->driverproc16 = lpfnHandler16;
421 while (MSVIDEO_GetHicPtr(HIC_32(IC_HandleRef)) != NULL) IC_HandleRef++;
422 whic->hic = HIC_32(IC_HandleRef++);
423 whic->next = MSVIDEO_FirstHic;
424 MSVIDEO_FirstHic = whic;
426 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
427 /* What if the function is used more than once? */
429 if (MSVIDEO_SendMessage(whic, DRV_LOAD, 0L, 0L) != DRV_SUCCESS)
431 WARN("DRV_LOAD failed for hic %p\n", whic->hic);
432 MSVIDEO_FirstHic = whic->next;
433 HeapFree(GetProcessHeap(), 0, whic);
434 return 0;
436 /* return value is not checked */
437 MSVIDEO_SendMessage(whic, DRV_ENABLE, 0L, 0L);
439 whic->driverId = (DWORD)MSVIDEO_SendMessage(whic, DRV_OPEN, 0, (DWORD)&icopen);
440 /* FIXME: What should we put here? */
441 whic->hdrv = (HDRVR)0;
443 if (whic->driverId == 0)
445 WARN("DRV_OPEN failed for hic %p\n", whic->hic);
446 MSVIDEO_FirstHic = whic->next;
447 HeapFree(GetProcessHeap(), 0, whic);
448 return 0;
451 TRACE("=> %p\n", whic->hic);
452 return whic->hic;
455 /***********************************************************************
456 * ICOpenFunction [MSVFW32.@]
458 HIC VFWAPI ICOpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode, FARPROC lpfnHandler)
460 return MSVIDEO_OpenFunction(fccType, fccHandler, wMode, (DRIVERPROC)lpfnHandler, 0);
463 /***********************************************************************
464 * ICGetInfo [MSVFW32.@]
466 LRESULT VFWAPI ICGetInfo(HIC hic, ICINFO *picinfo, DWORD cb)
468 LRESULT ret;
469 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
471 TRACE("(%p,%p,%ld)\n", hic, picinfo, cb);
473 whic = MSVIDEO_GetHicPtr(hic);
474 if (!whic) return ICERR_BADHANDLE;
475 if (!picinfo) return MMSYSERR_INVALPARAM;
477 /* (WS) The field szDriver should be initialized because the driver
478 * is not obliged and often will not do it. Some applications, like
479 * VirtualDub, rely on this field and will occasionally crash if it
480 * goes unitialized.
482 if (cb >= sizeof(ICINFO)) picinfo->szDriver[0] = '\0';
484 ret = ICSendMessage(hic, ICM_GETINFO, (DWORD)picinfo, cb);
486 /* (WS) When szDriver was not supplied by the driver itself, apparently
487 * Windows will set its value equal to the driver file name. This can
488 * be obtained from the registry as we do here.
490 if (cb >= sizeof(ICINFO) && picinfo->szDriver[0] == 0)
492 ICINFO ii;
494 memset(&ii, 0, sizeof(ii));
495 ii.dwSize = sizeof(ii);
496 ICInfo(picinfo->fccType, picinfo->fccHandler, &ii);
497 lstrcpyW(picinfo->szDriver, ii.szDriver);
500 TRACE(" -> 0x%08lx\n", ret);
501 return ret;
504 typedef struct {
505 DWORD fccType;
506 DWORD fccHandler;
507 LPBITMAPINFOHEADER lpbiIn;
508 LPBITMAPINFOHEADER lpbiOut;
509 WORD wMode;
510 DWORD querymsg;
511 HIC hic;
512 } driver_info_t;
514 static HIC try_driver(driver_info_t *info)
516 HIC hic;
518 if ((hic = ICOpen(info->fccType, info->fccHandler, info->wMode)))
520 if (!ICSendMessage(hic, info->querymsg, (DWORD)info->lpbiIn, (DWORD)info->lpbiOut))
521 return hic;
522 ICClose(hic);
524 return 0;
527 static BOOL ICLocate_enum_handler(const char *drv, int nr, void *param)
529 driver_info_t *info = (driver_info_t *)param;
530 info->fccHandler = mmioStringToFOURCCA(drv + 5, 0);
531 info->hic = try_driver(info);
532 return info->hic != 0;
535 /***********************************************************************
536 * ICLocate [MSVFW32.@]
538 HIC VFWAPI ICLocate(DWORD fccType, DWORD fccHandler, LPBITMAPINFOHEADER lpbiIn,
539 LPBITMAPINFOHEADER lpbiOut, WORD wMode)
541 driver_info_t info;
543 TRACE("(%s,%s,%p,%p,0x%04x)\n",
544 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), lpbiIn, lpbiOut, wMode);
546 info.fccType = fccType;
547 info.fccHandler = fccHandler;
548 info.lpbiIn = lpbiIn;
549 info.lpbiOut = lpbiOut;
550 info.wMode = wMode;
552 switch (wMode)
554 case ICMODE_FASTCOMPRESS:
555 case ICMODE_COMPRESS:
556 info.querymsg = ICM_COMPRESS_QUERY;
557 break;
558 case ICMODE_FASTDECOMPRESS:
559 case ICMODE_DECOMPRESS:
560 info.querymsg = ICM_DECOMPRESS_QUERY;
561 break;
562 case ICMODE_DRAW:
563 info.querymsg = ICM_DRAW_QUERY;
564 break;
565 default:
566 WARN("Unknown mode (%d)\n", wMode);
567 return 0;
570 /* Easy case: handler/type match, we just fire a query and return */
571 info.hic = try_driver(&info);
572 /* If it didn't work, try each driver in turn. 32 bit codecs only. */
573 /* FIXME: Move this to an init routine? */
574 if (!info.hic) enum_drivers(fccType, ICLocate_enum_handler, &info);
576 if (info.hic)
578 TRACE("=> %p\n", info.hic);
579 return info.hic;
582 if (fccType == streamtypeVIDEO)
583 return ICLocate(ICTYPE_VIDEO, fccHandler, lpbiIn, lpbiOut, wMode);
585 WARN("(%s,%s,%p,%p,0x%04x) not found!\n",
586 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), lpbiIn, lpbiOut, wMode);
587 return 0;
590 /***********************************************************************
591 * ICGetDisplayFormat [MSVFW32.@]
593 HIC VFWAPI ICGetDisplayFormat(
594 HIC hic,LPBITMAPINFOHEADER lpbiIn,LPBITMAPINFOHEADER lpbiOut,
595 INT depth,INT dx,INT dy)
597 HIC tmphic = hic;
599 TRACE("(%p,%p,%p,%d,%d,%d)!\n",hic,lpbiIn,lpbiOut,depth,dx,dy);
601 if (!tmphic) {
602 tmphic=ICLocate(ICTYPE_VIDEO,0,lpbiIn,NULL,ICMODE_DECOMPRESS);
603 if (!tmphic)
604 return tmphic;
606 if ((dy == lpbiIn->biHeight) && (dx == lpbiIn->biWidth))
607 dy = dx = 0; /* no resize needed */
609 /* Can we decompress it ? */
610 if (ICDecompressQuery(tmphic,lpbiIn,NULL) != 0)
611 goto errout; /* no, sorry */
613 ICDecompressGetFormat(tmphic,lpbiIn,lpbiOut);
615 if (lpbiOut->biCompression != 0) {
616 FIXME("Ooch, how come decompressor outputs compressed data (%ld)??\n",
617 lpbiOut->biCompression);
619 if (lpbiOut->biSize < sizeof(*lpbiOut)) {
620 FIXME("Ooch, size of output BIH is too small (%ld)\n",
621 lpbiOut->biSize);
622 lpbiOut->biSize = sizeof(*lpbiOut);
624 if (!depth) {
625 HDC hdc;
627 hdc = GetDC(0);
628 depth = GetDeviceCaps(hdc,BITSPIXEL)*GetDeviceCaps(hdc,PLANES);
629 ReleaseDC(0,hdc);
630 if (depth==15) depth = 16;
631 if (depth<8) depth = 8;
633 if (lpbiIn->biBitCount == 8)
634 depth = 8;
636 TRACE("=> %p\n", tmphic);
637 return tmphic;
638 errout:
639 if (hic!=tmphic)
640 ICClose(tmphic);
642 TRACE("=> 0\n");
643 return 0;
646 /***********************************************************************
647 * ICCompress [MSVFW32.@]
649 DWORD VFWAPIV
650 ICCompress(
651 HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiOutput,LPVOID lpData,
652 LPBITMAPINFOHEADER lpbiInput,LPVOID lpBits,LPDWORD lpckid,
653 LPDWORD lpdwFlags,LONG lFrameNum,DWORD dwFrameSize,DWORD dwQuality,
654 LPBITMAPINFOHEADER lpbiPrev,LPVOID lpPrev)
656 ICCOMPRESS iccmp;
658 TRACE("(%p,%ld,%p,%p,%p,%p,...)\n",hic,dwFlags,lpbiOutput,lpData,lpbiInput,lpBits);
660 iccmp.dwFlags = dwFlags;
662 iccmp.lpbiOutput = lpbiOutput;
663 iccmp.lpOutput = lpData;
664 iccmp.lpbiInput = lpbiInput;
665 iccmp.lpInput = lpBits;
667 iccmp.lpckid = lpckid;
668 iccmp.lpdwFlags = lpdwFlags;
669 iccmp.lFrameNum = lFrameNum;
670 iccmp.dwFrameSize = dwFrameSize;
671 iccmp.dwQuality = dwQuality;
672 iccmp.lpbiPrev = lpbiPrev;
673 iccmp.lpPrev = lpPrev;
674 return ICSendMessage(hic,ICM_COMPRESS,(DWORD)&iccmp,sizeof(iccmp));
677 /***********************************************************************
678 * ICDecompress [MSVFW32.@]
680 DWORD VFWAPIV ICDecompress(HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiFormat,
681 LPVOID lpData,LPBITMAPINFOHEADER lpbi,LPVOID lpBits)
683 ICDECOMPRESS icd;
684 DWORD ret;
686 TRACE("(%p,%ld,%p,%p,%p,%p)\n",hic,dwFlags,lpbiFormat,lpData,lpbi,lpBits);
688 TRACE("lpBits[0] == %lx\n",((LPDWORD)lpBits)[0]);
690 icd.dwFlags = dwFlags;
691 icd.lpbiInput = lpbiFormat;
692 icd.lpInput = lpData;
694 icd.lpbiOutput = lpbi;
695 icd.lpOutput = lpBits;
696 icd.ckid = 0;
697 ret = ICSendMessage(hic,ICM_DECOMPRESS,(DWORD)&icd,sizeof(ICDECOMPRESS));
699 TRACE("lpBits[0] == %lx\n",((LPDWORD)lpBits)[0]);
701 TRACE("-> %ld\n",ret);
703 return ret;
707 /***********************************************************************
708 * ICCompressorChoose [MSVFW32.@]
710 BOOL VFWAPI ICCompressorChoose(HWND hwnd, UINT uiFlags, LPVOID pvIn,
711 LPVOID lpData, PCOMPVARS pc, LPSTR lpszTitle)
713 FIXME("(%p,0x%X,%p,%p,%p,%s),stub!\n",hwnd,uiFlags,pvIn,lpData,pc,lpszTitle);
715 if (pc == NULL || pc->cbSize != sizeof(COMPVARS))
716 return FALSE;
718 if ((pc->dwFlags & ICMF_COMPVARS_VALID) == 0) {
719 pc->dwFlags = 0;
720 pc->fccType = pc->fccHandler = 0;
721 pc->hic = NULL;
722 pc->lpbiOut = NULL;
723 pc->lpBitsOut = pc->lpBitsPrev = pc->lpState = NULL;
724 pc->lQ = ICQUALITY_DEFAULT;
725 pc->lKey = -1;
726 pc->lDataRate = 300; /* kB */
727 pc->lpState = NULL;
728 pc->cbState = 0;
730 if (pc->fccType == 0)
731 pc->fccType = ICTYPE_VIDEO;
733 /* FIXME */
735 return FALSE;
739 /***********************************************************************
740 * ICCompressorFree [MSVFW32.@]
742 void VFWAPI ICCompressorFree(PCOMPVARS pc)
744 TRACE("(%p)\n",pc);
746 if (pc != NULL && pc->cbSize == sizeof(COMPVARS)) {
747 if (pc->hic != NULL) {
748 ICClose(pc->hic);
749 pc->hic = NULL;
751 if (pc->lpbiOut != NULL) {
752 GlobalFreePtr(pc->lpbiOut);
753 pc->lpbiOut = NULL;
755 if (pc->lpBitsOut != NULL) {
756 GlobalFreePtr(pc->lpBitsOut);
757 pc->lpBitsOut = NULL;
759 if (pc->lpBitsPrev != NULL) {
760 GlobalFreePtr(pc->lpBitsPrev);
761 pc->lpBitsPrev = NULL;
763 if (pc->lpState != NULL) {
764 GlobalFreePtr(pc->lpBitsPrev);
765 pc->lpState = NULL;
767 pc->dwFlags = 0;
772 /******************************************************************
773 * MSVIDEO_SendMessage
777 LRESULT MSVIDEO_SendMessage(WINE_HIC* whic, UINT msg, DWORD lParam1, DWORD lParam2)
779 LRESULT ret;
781 #define XX(x) case x: TRACE("(%p,"#x",0x%08lx,0x%08lx)\n",whic,lParam1,lParam2); break;
783 switch (msg) {
784 /* DRV_* */
785 XX(DRV_LOAD);
786 XX(DRV_ENABLE);
787 XX(DRV_OPEN);
788 XX(DRV_CLOSE);
789 XX(DRV_DISABLE);
790 XX(DRV_FREE);
791 /* ICM_RESERVED+X */
792 XX(ICM_ABOUT);
793 XX(ICM_CONFIGURE);
794 XX(ICM_GET);
795 XX(ICM_GETINFO);
796 XX(ICM_GETDEFAULTQUALITY);
797 XX(ICM_GETQUALITY);
798 XX(ICM_GETSTATE);
799 XX(ICM_SETQUALITY);
800 XX(ICM_SET);
801 XX(ICM_SETSTATE);
802 /* ICM_USER+X */
803 XX(ICM_COMPRESS_FRAMES_INFO);
804 XX(ICM_COMPRESS_GET_FORMAT);
805 XX(ICM_COMPRESS_GET_SIZE);
806 XX(ICM_COMPRESS_QUERY);
807 XX(ICM_COMPRESS_BEGIN);
808 XX(ICM_COMPRESS);
809 XX(ICM_COMPRESS_END);
810 XX(ICM_DECOMPRESS_GET_FORMAT);
811 XX(ICM_DECOMPRESS_QUERY);
812 XX(ICM_DECOMPRESS_BEGIN);
813 XX(ICM_DECOMPRESS);
814 XX(ICM_DECOMPRESS_END);
815 XX(ICM_DECOMPRESS_SET_PALETTE);
816 XX(ICM_DECOMPRESS_GET_PALETTE);
817 XX(ICM_DRAW_QUERY);
818 XX(ICM_DRAW_BEGIN);
819 XX(ICM_DRAW_GET_PALETTE);
820 XX(ICM_DRAW_START);
821 XX(ICM_DRAW_STOP);
822 XX(ICM_DRAW_END);
823 XX(ICM_DRAW_GETTIME);
824 XX(ICM_DRAW);
825 XX(ICM_DRAW_WINDOW);
826 XX(ICM_DRAW_SETTIME);
827 XX(ICM_DRAW_REALIZE);
828 XX(ICM_DRAW_FLUSH);
829 XX(ICM_DRAW_RENDERBUFFER);
830 XX(ICM_DRAW_START_PLAY);
831 XX(ICM_DRAW_STOP_PLAY);
832 XX(ICM_DRAW_SUGGESTFORMAT);
833 XX(ICM_DRAW_CHANGEPALETTE);
834 XX(ICM_GETBUFFERSWANTED);
835 XX(ICM_GETDEFAULTKEYFRAMERATE);
836 XX(ICM_DECOMPRESSEX_BEGIN);
837 XX(ICM_DECOMPRESSEX_QUERY);
838 XX(ICM_DECOMPRESSEX);
839 XX(ICM_DECOMPRESSEX_END);
840 XX(ICM_SET_STATUS_PROC);
841 default:
842 FIXME("(%p,0x%08lx,0x%08lx,0x%08lx) unknown message\n",whic,(DWORD)msg,lParam1,lParam2);
845 #undef XX
847 if (whic->driverproc) {
848 /* dwDriverId parameter is the value returned by the DRV_OPEN */
849 ret = whic->driverproc(whic->driverId, whic->hdrv, msg, lParam1, lParam2);
850 } else {
851 ret = SendDriverMessage(whic->hdrv, msg, lParam1, lParam2);
854 TRACE(" -> 0x%08lx\n", ret);
855 return ret;
858 /***********************************************************************
859 * ICSendMessage [MSVFW32.@]
861 LRESULT VFWAPI ICSendMessage(HIC hic, UINT msg, DWORD lParam1, DWORD lParam2)
863 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
865 if (!whic) return ICERR_BADHANDLE;
866 return MSVIDEO_SendMessage(whic, msg, lParam1, lParam2);
869 /***********************************************************************
870 * ICDrawBegin [MSVFW32.@]
872 DWORD VFWAPIV ICDrawBegin(
873 HIC hic, /* [in] */
874 DWORD dwFlags, /* [in] flags */
875 HPALETTE hpal, /* [in] palette to draw with */
876 HWND hwnd, /* [in] window to draw to */
877 HDC hdc, /* [in] HDC to draw to */
878 INT xDst, /* [in] destination rectangle */
879 INT yDst, /* [in] */
880 INT dxDst, /* [in] */
881 INT dyDst, /* [in] */
882 LPBITMAPINFOHEADER lpbi, /* [in] format of frame to draw */
883 INT xSrc, /* [in] source rectangle */
884 INT ySrc, /* [in] */
885 INT dxSrc, /* [in] */
886 INT dySrc, /* [in] */
887 DWORD dwRate, /* [in] frames/second = (dwRate/dwScale) */
888 DWORD dwScale) /* [in] */
891 ICDRAWBEGIN icdb;
893 TRACE("(%p,%ld,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%ld,%ld)\n",
894 hic, dwFlags, hpal, hwnd, hdc, xDst, yDst, dxDst, dyDst,
895 lpbi, xSrc, ySrc, dxSrc, dySrc, dwRate, dwScale);
897 icdb.dwFlags = dwFlags;
898 icdb.hpal = hpal;
899 icdb.hwnd = hwnd;
900 icdb.hdc = hdc;
901 icdb.xDst = xDst;
902 icdb.yDst = yDst;
903 icdb.dxDst = dxDst;
904 icdb.dyDst = dyDst;
905 icdb.lpbi = lpbi;
906 icdb.xSrc = xSrc;
907 icdb.ySrc = ySrc;
908 icdb.dxSrc = dxSrc;
909 icdb.dySrc = dySrc;
910 icdb.dwRate = dwRate;
911 icdb.dwScale = dwScale;
912 return ICSendMessage(hic,ICM_DRAW_BEGIN,(DWORD)&icdb,sizeof(icdb));
915 /***********************************************************************
916 * ICDraw [MSVFW32.@]
918 DWORD VFWAPIV ICDraw(HIC hic, DWORD dwFlags, LPVOID lpFormat, LPVOID lpData, DWORD cbData, LONG lTime) {
919 ICDRAW icd;
921 TRACE("(%p,%ld,%p,%p,%ld,%ld)\n",hic,dwFlags,lpFormat,lpData,cbData,lTime);
923 icd.dwFlags = dwFlags;
924 icd.lpFormat = lpFormat;
925 icd.lpData = lpData;
926 icd.cbData = cbData;
927 icd.lTime = lTime;
929 return ICSendMessage(hic,ICM_DRAW,(DWORD)&icd,sizeof(icd));
932 /***********************************************************************
933 * ICClose [MSVFW32.@]
935 LRESULT WINAPI ICClose(HIC hic)
937 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
938 WINE_HIC** p;
940 TRACE("(%p)\n",hic);
942 if (!whic) return ICERR_BADHANDLE;
944 if (whic->driverproc)
946 MSVIDEO_SendMessage(whic, DRV_CLOSE, 0, 0);
947 MSVIDEO_SendMessage(whic, DRV_DISABLE, 0, 0);
948 MSVIDEO_SendMessage(whic, DRV_FREE, 0, 0);
950 else
952 CloseDriver(whic->hdrv, 0, 0);
955 /* remove whic from list */
956 for (p = &MSVIDEO_FirstHic; *p != NULL; p = &((*p)->next))
958 if ((*p) == whic)
960 *p = whic->next;
961 break;
965 HeapFree(GetProcessHeap(), 0, whic);
966 return 0;
971 /***********************************************************************
972 * ICImageCompress [MSVFW32.@]
974 HANDLE VFWAPI ICImageCompress(
975 HIC hic, UINT uiFlags,
976 LPBITMAPINFO lpbiIn, LPVOID lpBits,
977 LPBITMAPINFO lpbiOut, LONG lQuality,
978 LONG* plSize)
980 FIXME("(%p,%08x,%p,%p,%p,%ld,%p)\n",
981 hic, uiFlags, lpbiIn, lpBits, lpbiOut, lQuality, plSize);
983 return NULL;
986 /***********************************************************************
987 * ICImageDecompress [MSVFW32.@]
990 HANDLE VFWAPI ICImageDecompress(
991 HIC hic, UINT uiFlags, LPBITMAPINFO lpbiIn,
992 LPVOID lpBits, LPBITMAPINFO lpbiOut)
994 HGLOBAL hMem = NULL;
995 BYTE* pMem = NULL;
996 BOOL bReleaseIC = FALSE;
997 BYTE* pHdr = NULL;
998 ULONG cbHdr = 0;
999 BOOL bSucceeded = FALSE;
1000 BOOL bInDecompress = FALSE;
1001 DWORD biSizeImage;
1003 TRACE("(%p,%08x,%p,%p,%p)\n",
1004 hic, uiFlags, lpbiIn, lpBits, lpbiOut);
1006 if ( hic == NULL )
1008 hic = ICDecompressOpen( ICTYPE_VIDEO, 0, &lpbiIn->bmiHeader, (lpbiOut != NULL) ? &lpbiOut->bmiHeader : NULL );
1009 if ( hic == NULL )
1011 WARN("no handler\n" );
1012 goto err;
1014 bReleaseIC = TRUE;
1016 if ( uiFlags != 0 )
1018 FIXME( "unknown flag %08x\n", uiFlags );
1019 goto err;
1021 if ( lpbiIn == NULL || lpBits == NULL )
1023 WARN("invalid argument\n");
1024 goto err;
1027 if ( lpbiOut != NULL )
1029 if ( lpbiOut->bmiHeader.biSize != sizeof(BITMAPINFOHEADER) )
1030 goto err;
1031 cbHdr = sizeof(BITMAPINFOHEADER);
1032 if ( lpbiOut->bmiHeader.biCompression == 3 )
1033 cbHdr += sizeof(DWORD)*3;
1034 else
1035 if ( lpbiOut->bmiHeader.biBitCount <= 8 )
1037 if ( lpbiOut->bmiHeader.biClrUsed == 0 )
1038 cbHdr += sizeof(RGBQUAD) * (1<<lpbiOut->bmiHeader.biBitCount);
1039 else
1040 cbHdr += sizeof(RGBQUAD) * lpbiOut->bmiHeader.biClrUsed;
1043 else
1045 TRACE( "get format\n" );
1047 cbHdr = ICDecompressGetFormatSize(hic,lpbiIn);
1048 if ( cbHdr < sizeof(BITMAPINFOHEADER) )
1049 goto err;
1050 pHdr = (BYTE*)HeapAlloc(GetProcessHeap(),0,cbHdr+sizeof(RGBQUAD)*256);
1051 if ( pHdr == NULL )
1052 goto err;
1053 ZeroMemory( pHdr, cbHdr+sizeof(RGBQUAD)*256 );
1054 if ( ICDecompressGetFormat( hic, lpbiIn, (BITMAPINFO*)pHdr ) != ICERR_OK )
1055 goto err;
1056 lpbiOut = (BITMAPINFO*)pHdr;
1057 if ( lpbiOut->bmiHeader.biBitCount <= 8 &&
1058 ICDecompressGetPalette( hic, lpbiIn, lpbiOut ) != ICERR_OK &&
1059 lpbiIn->bmiHeader.biBitCount == lpbiOut->bmiHeader.biBitCount )
1061 if ( lpbiIn->bmiHeader.biClrUsed == 0 )
1062 memcpy( lpbiOut->bmiColors, lpbiIn->bmiColors, sizeof(RGBQUAD)*(1<<lpbiOut->bmiHeader.biBitCount) );
1063 else
1064 memcpy( lpbiOut->bmiColors, lpbiIn->bmiColors, sizeof(RGBQUAD)*lpbiIn->bmiHeader.biClrUsed );
1066 if ( lpbiOut->bmiHeader.biBitCount <= 8 &&
1067 lpbiOut->bmiHeader.biClrUsed == 0 )
1068 lpbiOut->bmiHeader.biClrUsed = 1<<lpbiOut->bmiHeader.biBitCount;
1070 lpbiOut->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1071 cbHdr = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*lpbiOut->bmiHeader.biClrUsed;
1074 biSizeImage = lpbiOut->bmiHeader.biSizeImage;
1075 if ( biSizeImage == 0 )
1076 biSizeImage = ((((lpbiOut->bmiHeader.biWidth * lpbiOut->bmiHeader.biBitCount + 7) >> 3) + 3) & (~3)) * abs(lpbiOut->bmiHeader.biHeight);
1078 TRACE( "call ICDecompressBegin\n" );
1080 if ( ICDecompressBegin( hic, lpbiIn, lpbiOut ) != ICERR_OK )
1081 goto err;
1082 bInDecompress = TRUE;
1084 TRACE( "cbHdr %ld, biSizeImage %ld\n", cbHdr, biSizeImage );
1086 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_ZEROINIT, cbHdr + biSizeImage );
1087 if ( hMem == NULL )
1089 WARN( "out of memory\n" );
1090 goto err;
1092 pMem = (BYTE*)GlobalLock( hMem );
1093 if ( pMem == NULL )
1094 goto err;
1095 memcpy( pMem, lpbiOut, cbHdr );
1097 TRACE( "call ICDecompress\n" );
1098 if ( ICDecompress( hic, 0, &lpbiIn->bmiHeader, lpBits, &lpbiOut->bmiHeader, pMem+cbHdr ) != ICERR_OK )
1099 goto err;
1101 bSucceeded = TRUE;
1102 err:
1103 if ( bInDecompress )
1104 ICDecompressEnd( hic );
1105 if ( bReleaseIC )
1106 ICClose(hic);
1107 if ( pHdr != NULL )
1108 HeapFree(GetProcessHeap(),0,pHdr);
1109 if ( pMem != NULL )
1110 GlobalUnlock( hMem );
1111 if ( !bSucceeded && hMem != NULL )
1113 GlobalFree(hMem); hMem = NULL;
1116 return (HANDLE)hMem;
1119 static BOOL GetFileNamePreview(LPVOID lpofn,BOOL bSave,BOOL bUnicode)
1121 CHAR szFunctionName[20];
1122 BOOL (*fnGetFileName)(LPVOID);
1123 HMODULE hComdlg32;
1124 BOOL ret;
1126 FIXME("(%p,%d,%d), semi-stub!\n",lpofn,bSave,bUnicode);
1128 lstrcpyA(szFunctionName, (bSave ? "GetSaveFileName" : "GetOpenFileName"));
1129 lstrcatA(szFunctionName, (bUnicode ? "W" : "A"));
1131 hComdlg32 = LoadLibraryA("COMDLG32.DLL");
1132 if (hComdlg32 == NULL)
1133 return FALSE;
1135 fnGetFileName = (LPVOID)GetProcAddress(hComdlg32, szFunctionName);
1136 if (fnGetFileName == NULL)
1137 return FALSE;
1139 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1140 ret = fnGetFileName(lpofn);
1142 FreeLibrary(hComdlg32);
1143 return ret;
1146 /***********************************************************************
1147 * GetOpenFileNamePreviewA [MSVFW32.@]
1149 BOOL WINAPI GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn)
1151 FIXME("(%p), semi-stub!\n", lpofn);
1153 return GetFileNamePreview(lpofn, FALSE, FALSE);
1156 /***********************************************************************
1157 * GetOpenFileNamePreviewW [MSVFW32.@]
1159 BOOL WINAPI GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn)
1161 FIXME("(%p), semi-stub!\n", lpofn);
1163 return GetFileNamePreview(lpofn, FALSE, TRUE);
1166 /***********************************************************************
1167 * GetSaveFileNamePreviewA [MSVFW32.@]
1169 BOOL WINAPI GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn)
1171 FIXME("(%p), semi-stub!\n", lpofn);
1173 return GetFileNamePreview(lpofn, TRUE, FALSE);
1176 /***********************************************************************
1177 * GetSaveFileNamePreviewW [MSVFW32.@]
1179 BOOL WINAPI GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn)
1181 FIXME("(%p), semi-stub!\n", lpofn);
1183 return GetFileNamePreview(lpofn, TRUE, TRUE);