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.
31 #include "msvideo_private.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;
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)); \
77 HMODULE MSVFW32_hModule;
79 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
81 TRACE("%p,%lx,%p\n", hinst, reason, reserved);
85 case DLL_PROCESS_ATTACH:
86 DisableThreadLibraryCalls(hinst);
87 MSVFW32_hModule = (HMODULE)hinst;
93 static int compare_fourcc(DWORD fcc1, DWORD fcc2)
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;
112 fourcc_to_string(fccTypeStr, fccType);
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)
120 RegQueryInfoKeyA( hKey, 0, 0, 0, &numkeys, 0, 0, 0, 0, 0, 0, 0);
121 for (i = 0; i < numkeys; i++)
123 bufLen = sizeof(buf) / sizeof(buf[0]);
124 lRet = RegEnumKeyExA(hKey, i, buf, &bufLen, 0, 0, 0, &lastWrite);
125 if (lRet != ERROR_SUCCESS) continue;
126 if (strncasecmp(buf, fccTypeStr, 5) || buf[9] != '=') continue;
127 if ((result = handler(buf, cnt++, param))) break;
131 if (result) return result;
133 /* if that didn't work, go through the values in system.ini */
134 if (GetPrivateProfileSectionA("drivers32", buf, sizeof(buf), "system.ini"))
136 for (s = buf; *s; s += strlen(s) + 1)
138 if (strncasecmp(s, fccTypeStr, 5) || s[9] != '=') continue;
139 if ((result = handler(s, cnt++, param))) break;
146 /******************************************************************
151 WINE_HIC* MSVIDEO_GetHicPtr(HIC hic)
155 for (whic = MSVIDEO_FirstHic; whic && whic->hic != hic; whic = whic->next);
159 /***********************************************************************
160 * VideoForWindowsVersion [MSVFW32.2]
161 * VideoForWindowsVersion [MSVIDEO.2]
162 * Returns the version in major.minor form.
163 * In Windows95 this returns 0x040003b6 (4.950)
165 DWORD WINAPI VideoForWindowsVersion(void)
167 return 0x040003B6; /* 4.950 */
170 static BOOL ICInfo_enum_handler(const char *drv, int nr, void *param)
172 ICINFO *lpicinfo = (ICINFO *)param;
173 DWORD fccHandler = mmioStringToFOURCCA(drv + 5, 0);
175 /* exact match of fccHandler or nth driver found */
176 if ((lpicinfo->fccHandler != nr) && (lpicinfo->fccHandler != fccHandler))
179 lpicinfo->fccType = mmioStringToFOURCCA(drv, 0);
180 lpicinfo->fccHandler = fccHandler;
181 lpicinfo->dwFlags = 0;
182 lpicinfo->dwVersion = 0;
183 lpicinfo->dwVersionICM = 0x104;
184 lpicinfo->szName[0] = 0;
185 lpicinfo->szDescription[0] = 0;
186 MultiByteToWideChar(CP_ACP, 0, drv + 10, -1, lpicinfo->szDriver,
187 sizeof(lpicinfo->szDriver)/sizeof(WCHAR));
192 /***********************************************************************
194 * Get information about an installable compressor. Return TRUE if there
198 * fccType [I] type of compressor (e.g. 'vidc')
199 * fccHandler [I] real fcc for handler or <n>th compressor
200 * lpicinfo [O] information about compressor
202 BOOL VFWAPI ICInfo( DWORD fccType, DWORD fccHandler, ICINFO *lpicinfo)
204 TRACE("(%s,%s/%08lx,%p)\n",
205 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), fccHandler, lpicinfo);
207 lpicinfo->fccHandler = fccHandler;
208 return enum_drivers(fccType, ICInfo_enum_handler, lpicinfo);
211 static DWORD IC_HandleRef = 1;
213 /***********************************************************************
214 * ICInstall [MSVFW32.@]
216 BOOL VFWAPI ICInstall(DWORD fccType, DWORD fccHandler, LPARAM lParam, LPSTR szDesc, UINT wFlags)
221 TRACE("(%s,%s,%p,%p,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), (void*)lParam, szDesc, wFlags);
223 /* Check if a driver is already registered */
224 for (driver = reg_driver_list; driver; driver = driver->next)
226 if (!compare_fourcc(fccType, driver->fccType) &&
227 !compare_fourcc(fccHandler, driver->fccHandler))
230 if (driver) return FALSE;
232 /* Register the driver */
233 driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(reg_driver));
234 if (!driver) goto oom;
235 driver->fccType = fccType;
236 driver->fccHandler = fccHandler;
240 case ICINSTALL_FUNCTION:
241 driver->proc = (DRIVERPROC)lParam;
244 case ICINSTALL_DRIVER:
246 len = MultiByteToWideChar(CP_ACP, 0, (char*)lParam, -1, NULL, 0);
247 driver->name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
248 if (!driver->name) goto oom;
249 MultiByteToWideChar(CP_ACP, 0, (char*)lParam, -1, driver->name, len);
252 ERR("Invalid flags!\n");
253 HeapFree(GetProcessHeap(), 0, driver);
257 /* Insert our driver in the list*/
258 driver->next = reg_driver_list;
259 reg_driver_list = driver;
263 HeapFree(GetProcessHeap(), 0, driver);
267 /***********************************************************************
268 * ICRemove [MSVFW32.@]
270 BOOL VFWAPI ICRemove(DWORD fccType, DWORD fccHandler, UINT wFlags)
272 reg_driver** pdriver;
275 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wFlags);
277 /* Check if a driver is already registered */
278 for (pdriver = ®_driver_list; *pdriver; pdriver = &(*pdriver)->next)
280 if (!compare_fourcc(fccType, (*pdriver)->fccType) &&
281 !compare_fourcc(fccHandler, (*pdriver)->fccHandler))
287 /* Remove the driver from the list */
289 *pdriver = (*pdriver)->next;
290 HeapFree(GetProcessHeap(), 0, drv->name);
291 HeapFree(GetProcessHeap(), 0, drv);
297 /***********************************************************************
299 * Opens an installable compressor. Return special handle.
301 HIC VFWAPI ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode)
308 static const WCHAR drv32W[] = {'d','r','i','v','e','r','s','3','2','\0'};
311 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode);
313 /* Check if there is a registered driver that matches */
314 driver = reg_driver_list;
316 if (!compare_fourcc(fccType, driver->fccType) &&
317 !compare_fourcc(fccHandler, driver->fccHandler))
320 driver = driver->next;
322 if (driver && driver->proc)
323 /* The driver has been registered at runtime with its driverproc */
324 return MSVIDEO_OpenFunction(fccType, fccHandler, wMode, (DRIVERPROC)driver->proc, (DWORD)NULL);
326 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
327 * same layout as ICOPEN
329 icopen.dwSize = sizeof(ICOPEN);
330 icopen.fccType = fccType;
331 icopen.fccHandler = fccHandler;
332 icopen.dwVersion = 0x00001000; /* FIXME */
333 icopen.dwFlags = wMode;
335 icopen.pV1Reserved = NULL;
336 icopen.pV2Reserved = NULL;
337 icopen.dnDevNode = 0; /* FIXME */
340 /* The driver is registered in the registry */
341 fourcc_to_string(codecname, fccType);
343 fourcc_to_string(codecname + 5, fccHandler);
346 hdrv = OpenDriver(codecname, drv32W, (LPARAM)&icopen);
349 if (fccType == streamtypeVIDEO)
356 fccType = ICTYPE_VIDEO;
357 hdrv = OpenDriver(codecname, drv32W, (LPARAM)&icopen);
363 /* The driver has been registered at runtime with its name */
364 hdrv = OpenDriver(driver->name, NULL, (LPARAM)&icopen);
368 bIs16 = GetDriverFlags(hdrv) & 0x10000000; /* undocumented flag: WINE_GDF_16BIT */
370 if (bIs16 && !pFnCallTo16)
372 FIXME("Got a 16 bit driver, but no 16 bit support in msvfw\n");
375 whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
378 CloseDriver(hdrv, 0, 0);
382 /* FIXME: is the signature the real one ? */
383 whic->driverproc = bIs16 ? (DRIVERPROC)pFnCallTo16 : NULL;
384 whic->driverproc16 = 0;
385 whic->type = fccType;
386 whic->handler = fccHandler;
387 while (MSVIDEO_GetHicPtr(HIC_32(IC_HandleRef)) != NULL) IC_HandleRef++;
388 whic->hic = HIC_32(IC_HandleRef++);
389 whic->next = MSVIDEO_FirstHic;
390 MSVIDEO_FirstHic = whic;
392 TRACE("=> %p\n", whic->hic);
396 /***********************************************************************
397 * MSVIDEO_OpenFunction
399 HIC MSVIDEO_OpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode,
400 DRIVERPROC lpfnHandler, DWORD lpfnHandler16)
405 TRACE("(%s,%s,%d,%p,%08lx)\n",
406 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode, lpfnHandler, lpfnHandler16);
408 icopen.dwSize = sizeof(ICOPEN);
409 icopen.fccType = fccType;
410 icopen.fccHandler = fccHandler;
411 icopen.dwVersion = 0x00001000; /* FIXME */
412 icopen.dwFlags = wMode;
414 icopen.pV1Reserved = NULL;
415 icopen.pV2Reserved = NULL;
416 icopen.dnDevNode = 0; /* FIXME */
418 whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
421 whic->driverproc = lpfnHandler;
422 whic->driverproc16 = lpfnHandler16;
423 while (MSVIDEO_GetHicPtr(HIC_32(IC_HandleRef)) != NULL) IC_HandleRef++;
424 whic->hic = HIC_32(IC_HandleRef++);
425 whic->next = MSVIDEO_FirstHic;
426 MSVIDEO_FirstHic = whic;
428 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
429 /* What if the function is used more than once? */
431 if (MSVIDEO_SendMessage(whic, DRV_LOAD, 0L, 0L) != DRV_SUCCESS)
433 WARN("DRV_LOAD failed for hic %p\n", whic->hic);
434 MSVIDEO_FirstHic = whic->next;
435 HeapFree(GetProcessHeap(), 0, whic);
438 /* return value is not checked */
439 MSVIDEO_SendMessage(whic, DRV_ENABLE, 0L, 0L);
441 whic->driverId = (DWORD)MSVIDEO_SendMessage(whic, DRV_OPEN, 0, (DWORD_PTR)&icopen);
442 /* FIXME: What should we put here? */
445 if (whic->driverId == 0)
447 WARN("DRV_OPEN failed for hic %p\n", whic->hic);
448 MSVIDEO_FirstHic = whic->next;
449 HeapFree(GetProcessHeap(), 0, whic);
453 TRACE("=> %p\n", whic->hic);
457 /***********************************************************************
458 * ICOpenFunction [MSVFW32.@]
460 HIC VFWAPI ICOpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode, FARPROC lpfnHandler)
462 return MSVIDEO_OpenFunction(fccType, fccHandler, wMode, (DRIVERPROC)lpfnHandler, 0);
465 /***********************************************************************
466 * ICGetInfo [MSVFW32.@]
468 LRESULT VFWAPI ICGetInfo(HIC hic, ICINFO *picinfo, DWORD cb)
471 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
473 TRACE("(%p,%p,%ld)\n", hic, picinfo, cb);
475 whic = MSVIDEO_GetHicPtr(hic);
476 if (!whic) return ICERR_BADHANDLE;
477 if (!picinfo) return MMSYSERR_INVALPARAM;
479 /* (WS) The field szDriver should be initialized because the driver
480 * is not obliged and often will not do it. Some applications, like
481 * VirtualDub, rely on this field and will occasionally crash if it
484 if (cb >= sizeof(ICINFO)) picinfo->szDriver[0] = '\0';
486 ret = ICSendMessage(hic, ICM_GETINFO, (DWORD_PTR)picinfo, cb);
488 /* (WS) When szDriver was not supplied by the driver itself, apparently
489 * Windows will set its value equal to the driver file name. This can
490 * be obtained from the registry as we do here.
492 if (cb >= sizeof(ICINFO) && picinfo->szDriver[0] == 0)
496 memset(&ii, 0, sizeof(ii));
497 ii.dwSize = sizeof(ii);
498 ICInfo(picinfo->fccType, picinfo->fccHandler, &ii);
499 lstrcpyW(picinfo->szDriver, ii.szDriver);
502 TRACE(" -> 0x%08lx\n", ret);
509 LPBITMAPINFOHEADER lpbiIn;
510 LPBITMAPINFOHEADER lpbiOut;
516 static HIC try_driver(driver_info_t *info)
520 if ((hic = ICOpen(info->fccType, info->fccHandler, info->wMode)))
522 if (!ICSendMessage(hic, info->querymsg, (DWORD_PTR)info->lpbiIn, (DWORD_PTR)info->lpbiOut))
529 static BOOL ICLocate_enum_handler(const char *drv, int nr, void *param)
531 driver_info_t *info = (driver_info_t *)param;
532 info->fccHandler = mmioStringToFOURCCA(drv + 5, 0);
533 info->hic = try_driver(info);
534 return info->hic != 0;
537 /***********************************************************************
538 * ICLocate [MSVFW32.@]
540 HIC VFWAPI ICLocate(DWORD fccType, DWORD fccHandler, LPBITMAPINFOHEADER lpbiIn,
541 LPBITMAPINFOHEADER lpbiOut, WORD wMode)
545 TRACE("(%s,%s,%p,%p,0x%04x)\n",
546 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), lpbiIn, lpbiOut, wMode);
548 info.fccType = fccType;
549 info.fccHandler = fccHandler;
550 info.lpbiIn = lpbiIn;
551 info.lpbiOut = lpbiOut;
556 case ICMODE_FASTCOMPRESS:
557 case ICMODE_COMPRESS:
558 info.querymsg = ICM_COMPRESS_QUERY;
560 case ICMODE_FASTDECOMPRESS:
561 case ICMODE_DECOMPRESS:
562 info.querymsg = ICM_DECOMPRESS_QUERY;
565 info.querymsg = ICM_DRAW_QUERY;
568 WARN("Unknown mode (%d)\n", wMode);
572 /* Easy case: handler/type match, we just fire a query and return */
573 info.hic = try_driver(&info);
574 /* If it didn't work, try each driver in turn. 32 bit codecs only. */
575 /* FIXME: Move this to an init routine? */
576 if (!info.hic) enum_drivers(fccType, ICLocate_enum_handler, &info);
580 TRACE("=> %p\n", info.hic);
584 if (fccType == streamtypeVIDEO)
585 return ICLocate(ICTYPE_VIDEO, fccHandler, lpbiIn, lpbiOut, wMode);
587 WARN("(%s,%s,%p,%p,0x%04x) not found!\n",
588 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), lpbiIn, lpbiOut, wMode);
592 /***********************************************************************
593 * ICGetDisplayFormat [MSVFW32.@]
595 HIC VFWAPI ICGetDisplayFormat(
596 HIC hic,LPBITMAPINFOHEADER lpbiIn,LPBITMAPINFOHEADER lpbiOut,
597 INT depth,INT dx,INT dy)
601 TRACE("(%p,%p,%p,%d,%d,%d)!\n",hic,lpbiIn,lpbiOut,depth,dx,dy);
604 tmphic=ICLocate(ICTYPE_VIDEO,0,lpbiIn,NULL,ICMODE_DECOMPRESS);
608 if ((dy == lpbiIn->biHeight) && (dx == lpbiIn->biWidth))
609 dy = dx = 0; /* no resize needed */
611 /* Can we decompress it ? */
612 if (ICDecompressQuery(tmphic,lpbiIn,NULL) != 0)
613 goto errout; /* no, sorry */
615 ICDecompressGetFormat(tmphic,lpbiIn,lpbiOut);
617 if (lpbiOut->biCompression != 0) {
618 FIXME("Ooch, how come decompressor outputs compressed data (%ld)??\n",
619 lpbiOut->biCompression);
621 if (lpbiOut->biSize < sizeof(*lpbiOut)) {
622 FIXME("Ooch, size of output BIH is too small (%ld)\n",
624 lpbiOut->biSize = sizeof(*lpbiOut);
630 depth = GetDeviceCaps(hdc,BITSPIXEL)*GetDeviceCaps(hdc,PLANES);
632 if (depth==15) depth = 16;
633 if (depth<8) depth = 8;
635 if (lpbiIn->biBitCount == 8)
638 TRACE("=> %p\n", tmphic);
648 /***********************************************************************
649 * ICCompress [MSVFW32.@]
653 HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiOutput,LPVOID lpData,
654 LPBITMAPINFOHEADER lpbiInput,LPVOID lpBits,LPDWORD lpckid,
655 LPDWORD lpdwFlags,LONG lFrameNum,DWORD dwFrameSize,DWORD dwQuality,
656 LPBITMAPINFOHEADER lpbiPrev,LPVOID lpPrev)
660 TRACE("(%p,%ld,%p,%p,%p,%p,...)\n",hic,dwFlags,lpbiOutput,lpData,lpbiInput,lpBits);
662 iccmp.dwFlags = dwFlags;
664 iccmp.lpbiOutput = lpbiOutput;
665 iccmp.lpOutput = lpData;
666 iccmp.lpbiInput = lpbiInput;
667 iccmp.lpInput = lpBits;
669 iccmp.lpckid = lpckid;
670 iccmp.lpdwFlags = lpdwFlags;
671 iccmp.lFrameNum = lFrameNum;
672 iccmp.dwFrameSize = dwFrameSize;
673 iccmp.dwQuality = dwQuality;
674 iccmp.lpbiPrev = lpbiPrev;
675 iccmp.lpPrev = lpPrev;
676 return ICSendMessage(hic,ICM_COMPRESS,(DWORD_PTR)&iccmp,sizeof(iccmp));
679 /***********************************************************************
680 * ICDecompress [MSVFW32.@]
682 DWORD VFWAPIV ICDecompress(HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiFormat,
683 LPVOID lpData,LPBITMAPINFOHEADER lpbi,LPVOID lpBits)
688 TRACE("(%p,%ld,%p,%p,%p,%p)\n",hic,dwFlags,lpbiFormat,lpData,lpbi,lpBits);
690 TRACE("lpBits[0] == %lx\n",((LPDWORD)lpBits)[0]);
692 icd.dwFlags = dwFlags;
693 icd.lpbiInput = lpbiFormat;
694 icd.lpInput = lpData;
696 icd.lpbiOutput = lpbi;
697 icd.lpOutput = lpBits;
699 ret = ICSendMessage(hic,ICM_DECOMPRESS,(DWORD_PTR)&icd,sizeof(ICDECOMPRESS));
701 TRACE("lpBits[0] == %lx\n",((LPDWORD)lpBits)[0]);
703 TRACE("-> %ld\n",ret);
708 /***********************************************************************
709 * ICCompressorChoose [MSVFW32.@]
711 BOOL VFWAPI ICCompressorChoose(HWND hwnd, UINT uiFlags, LPVOID pvIn,
712 LPVOID lpData, PCOMPVARS pc, LPSTR lpszTitle)
714 FIXME("(%p,0x%X,%p,%p,%p,%s),stub!\n",hwnd,uiFlags,pvIn,lpData,pc,lpszTitle);
716 if (pc == NULL || pc->cbSize != sizeof(COMPVARS))
719 if ((pc->dwFlags & ICMF_COMPVARS_VALID) == 0) {
721 pc->fccType = pc->fccHandler = 0;
724 pc->lpBitsOut = pc->lpBitsPrev = pc->lpState = NULL;
725 pc->lQ = ICQUALITY_DEFAULT;
727 pc->lDataRate = 300; /* kB */
731 if (pc->fccType == 0)
732 pc->fccType = ICTYPE_VIDEO;
740 /***********************************************************************
741 * ICCompressorFree [MSVFW32.@]
743 void VFWAPI ICCompressorFree(PCOMPVARS pc)
747 if (pc != NULL && pc->cbSize == sizeof(COMPVARS)) {
748 if (pc->hic != NULL) {
752 if (pc->lpbiIn != NULL) {
753 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
756 if (pc->lpBitsOut != NULL) {
757 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
758 pc->lpBitsOut = NULL;
760 if (pc->lpBitsPrev != NULL) {
761 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
762 pc->lpBitsPrev = NULL;
764 if (pc->lpState != NULL) {
765 HeapFree(GetProcessHeap(), 0, pc->lpState);
773 /******************************************************************
774 * MSVIDEO_SendMessage
778 LRESULT MSVIDEO_SendMessage(WINE_HIC* whic, UINT msg, DWORD_PTR lParam1, DWORD_PTR lParam2)
782 #define XX(x) case x: TRACE("(%p,"#x",0x%08lx,0x%08lx)\n",whic,lParam1,lParam2); break;
797 XX(ICM_GETDEFAULTQUALITY);
804 XX(ICM_COMPRESS_FRAMES_INFO);
805 XX(ICM_COMPRESS_GET_FORMAT);
806 XX(ICM_COMPRESS_GET_SIZE);
807 XX(ICM_COMPRESS_QUERY);
808 XX(ICM_COMPRESS_BEGIN);
810 XX(ICM_COMPRESS_END);
811 XX(ICM_DECOMPRESS_GET_FORMAT);
812 XX(ICM_DECOMPRESS_QUERY);
813 XX(ICM_DECOMPRESS_BEGIN);
815 XX(ICM_DECOMPRESS_END);
816 XX(ICM_DECOMPRESS_SET_PALETTE);
817 XX(ICM_DECOMPRESS_GET_PALETTE);
820 XX(ICM_DRAW_GET_PALETTE);
824 XX(ICM_DRAW_GETTIME);
827 XX(ICM_DRAW_SETTIME);
828 XX(ICM_DRAW_REALIZE);
830 XX(ICM_DRAW_RENDERBUFFER);
831 XX(ICM_DRAW_START_PLAY);
832 XX(ICM_DRAW_STOP_PLAY);
833 XX(ICM_DRAW_SUGGESTFORMAT);
834 XX(ICM_DRAW_CHANGEPALETTE);
835 XX(ICM_GETBUFFERSWANTED);
836 XX(ICM_GETDEFAULTKEYFRAMERATE);
837 XX(ICM_DECOMPRESSEX_BEGIN);
838 XX(ICM_DECOMPRESSEX_QUERY);
839 XX(ICM_DECOMPRESSEX);
840 XX(ICM_DECOMPRESSEX_END);
841 XX(ICM_SET_STATUS_PROC);
843 FIXME("(%p,0x%08lx,0x%08lx,0x%08lx) unknown message\n",whic,(DWORD)msg,lParam1,lParam2);
848 if (whic->driverproc) {
849 /* dwDriverId parameter is the value returned by the DRV_OPEN */
850 ret = whic->driverproc(whic->driverId, whic->hdrv, msg, lParam1, lParam2);
852 ret = SendDriverMessage(whic->hdrv, msg, lParam1, lParam2);
855 TRACE(" -> 0x%08lx\n", ret);
859 /***********************************************************************
860 * ICSendMessage [MSVFW32.@]
862 LRESULT VFWAPI ICSendMessage(HIC hic, UINT msg, DWORD_PTR lParam1, DWORD_PTR lParam2)
864 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
866 if (!whic) return ICERR_BADHANDLE;
867 return MSVIDEO_SendMessage(whic, msg, lParam1, lParam2);
870 /***********************************************************************
871 * ICDrawBegin [MSVFW32.@]
873 DWORD VFWAPIV ICDrawBegin(
875 DWORD dwFlags, /* [in] flags */
876 HPALETTE hpal, /* [in] palette to draw with */
877 HWND hwnd, /* [in] window to draw to */
878 HDC hdc, /* [in] HDC to draw to */
879 INT xDst, /* [in] destination rectangle */
881 INT dxDst, /* [in] */
882 INT dyDst, /* [in] */
883 LPBITMAPINFOHEADER lpbi, /* [in] format of frame to draw */
884 INT xSrc, /* [in] source rectangle */
886 INT dxSrc, /* [in] */
887 INT dySrc, /* [in] */
888 DWORD dwRate, /* [in] frames/second = (dwRate/dwScale) */
889 DWORD dwScale) /* [in] */
894 TRACE("(%p,%ld,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%ld,%ld)\n",
895 hic, dwFlags, hpal, hwnd, hdc, xDst, yDst, dxDst, dyDst,
896 lpbi, xSrc, ySrc, dxSrc, dySrc, dwRate, dwScale);
898 icdb.dwFlags = dwFlags;
911 icdb.dwRate = dwRate;
912 icdb.dwScale = dwScale;
913 return ICSendMessage(hic,ICM_DRAW_BEGIN,(DWORD_PTR)&icdb,sizeof(icdb));
916 /***********************************************************************
919 DWORD VFWAPIV ICDraw(HIC hic, DWORD dwFlags, LPVOID lpFormat, LPVOID lpData, DWORD cbData, LONG lTime) {
922 TRACE("(%p,%ld,%p,%p,%ld,%ld)\n",hic,dwFlags,lpFormat,lpData,cbData,lTime);
924 icd.dwFlags = dwFlags;
925 icd.lpFormat = lpFormat;
930 return ICSendMessage(hic,ICM_DRAW,(DWORD_PTR)&icd,sizeof(icd));
933 /***********************************************************************
934 * ICClose [MSVFW32.@]
936 LRESULT WINAPI ICClose(HIC hic)
938 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
943 if (!whic) return ICERR_BADHANDLE;
945 if (whic->driverproc)
947 MSVIDEO_SendMessage(whic, DRV_CLOSE, 0, 0);
948 MSVIDEO_SendMessage(whic, DRV_DISABLE, 0, 0);
949 MSVIDEO_SendMessage(whic, DRV_FREE, 0, 0);
953 CloseDriver(whic->hdrv, 0, 0);
956 /* remove whic from list */
957 for (p = &MSVIDEO_FirstHic; *p != NULL; p = &((*p)->next))
966 HeapFree(GetProcessHeap(), 0, whic);
972 /***********************************************************************
973 * ICImageCompress [MSVFW32.@]
975 HANDLE VFWAPI ICImageCompress(
976 HIC hic, UINT uiFlags,
977 LPBITMAPINFO lpbiIn, LPVOID lpBits,
978 LPBITMAPINFO lpbiOut, LONG lQuality,
981 FIXME("(%p,%08x,%p,%p,%p,%ld,%p)\n",
982 hic, uiFlags, lpbiIn, lpBits, lpbiOut, lQuality, plSize);
987 /***********************************************************************
988 * ICImageDecompress [MSVFW32.@]
991 HANDLE VFWAPI ICImageDecompress(
992 HIC hic, UINT uiFlags, LPBITMAPINFO lpbiIn,
993 LPVOID lpBits, LPBITMAPINFO lpbiOut)
997 BOOL bReleaseIC = FALSE;
1000 BOOL bSucceeded = FALSE;
1001 BOOL bInDecompress = FALSE;
1004 TRACE("(%p,%08x,%p,%p,%p)\n",
1005 hic, uiFlags, lpbiIn, lpBits, lpbiOut);
1009 hic = ICDecompressOpen( ICTYPE_VIDEO, 0, &lpbiIn->bmiHeader, (lpbiOut != NULL) ? &lpbiOut->bmiHeader : NULL );
1012 WARN("no handler\n" );
1019 FIXME( "unknown flag %08x\n", uiFlags );
1022 if ( lpbiIn == NULL || lpBits == NULL )
1024 WARN("invalid argument\n");
1028 if ( lpbiOut != NULL )
1030 if ( lpbiOut->bmiHeader.biSize != sizeof(BITMAPINFOHEADER) )
1032 cbHdr = sizeof(BITMAPINFOHEADER);
1033 if ( lpbiOut->bmiHeader.biCompression == 3 )
1034 cbHdr += sizeof(DWORD)*3;
1036 if ( lpbiOut->bmiHeader.biBitCount <= 8 )
1038 if ( lpbiOut->bmiHeader.biClrUsed == 0 )
1039 cbHdr += sizeof(RGBQUAD) * (1<<lpbiOut->bmiHeader.biBitCount);
1041 cbHdr += sizeof(RGBQUAD) * lpbiOut->bmiHeader.biClrUsed;
1046 TRACE( "get format\n" );
1048 cbHdr = ICDecompressGetFormatSize(hic,lpbiIn);
1049 if ( cbHdr < sizeof(BITMAPINFOHEADER) )
1051 pHdr = HeapAlloc(GetProcessHeap(),0,cbHdr+sizeof(RGBQUAD)*256);
1054 ZeroMemory( pHdr, cbHdr+sizeof(RGBQUAD)*256 );
1055 if ( ICDecompressGetFormat( hic, lpbiIn, (BITMAPINFO*)pHdr ) != ICERR_OK )
1057 lpbiOut = (BITMAPINFO*)pHdr;
1058 if ( lpbiOut->bmiHeader.biBitCount <= 8 &&
1059 ICDecompressGetPalette( hic, lpbiIn, lpbiOut ) != ICERR_OK &&
1060 lpbiIn->bmiHeader.biBitCount == lpbiOut->bmiHeader.biBitCount )
1062 if ( lpbiIn->bmiHeader.biClrUsed == 0 )
1063 memcpy( lpbiOut->bmiColors, lpbiIn->bmiColors, sizeof(RGBQUAD)*(1<<lpbiOut->bmiHeader.biBitCount) );
1065 memcpy( lpbiOut->bmiColors, lpbiIn->bmiColors, sizeof(RGBQUAD)*lpbiIn->bmiHeader.biClrUsed );
1067 if ( lpbiOut->bmiHeader.biBitCount <= 8 &&
1068 lpbiOut->bmiHeader.biClrUsed == 0 )
1069 lpbiOut->bmiHeader.biClrUsed = 1<<lpbiOut->bmiHeader.biBitCount;
1071 lpbiOut->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1072 cbHdr = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*lpbiOut->bmiHeader.biClrUsed;
1075 biSizeImage = lpbiOut->bmiHeader.biSizeImage;
1076 if ( biSizeImage == 0 )
1077 biSizeImage = ((((lpbiOut->bmiHeader.biWidth * lpbiOut->bmiHeader.biBitCount + 7) >> 3) + 3) & (~3)) * abs(lpbiOut->bmiHeader.biHeight);
1079 TRACE( "call ICDecompressBegin\n" );
1081 if ( ICDecompressBegin( hic, lpbiIn, lpbiOut ) != ICERR_OK )
1083 bInDecompress = TRUE;
1085 TRACE( "cbHdr %ld, biSizeImage %ld\n", cbHdr, biSizeImage );
1087 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_ZEROINIT, cbHdr + biSizeImage );
1090 WARN( "out of memory\n" );
1093 pMem = (BYTE*)GlobalLock( hMem );
1096 memcpy( pMem, lpbiOut, cbHdr );
1098 TRACE( "call ICDecompress\n" );
1099 if ( ICDecompress( hic, 0, &lpbiIn->bmiHeader, lpBits, &lpbiOut->bmiHeader, pMem+cbHdr ) != ICERR_OK )
1104 if ( bInDecompress )
1105 ICDecompressEnd( hic );
1108 HeapFree(GetProcessHeap(),0,pHdr);
1110 GlobalUnlock( hMem );
1111 if ( !bSucceeded && hMem != NULL )
1113 GlobalFree(hMem); hMem = NULL;
1116 return (HANDLE)hMem;
1119 /***********************************************************************
1120 * ICSeqCompressFrame [MSVFW32.@]
1122 LPVOID VFWAPI ICSeqCompressFrame(PCOMPVARS pc, UINT uiFlags, LPVOID lpBits, BOOL *pfKey, LONG *plSize)
1124 ICCOMPRESS* icComp = (ICCOMPRESS *)pc->lpState;
1126 TRACE("(%p, 0x%08x, %p, %p, %p)\n", pc, uiFlags, lpBits, pfKey, plSize);
1128 if (pc->cbState != sizeof(ICCOMPRESS))
1130 ERR("Invalid cbState (%li should be %i)\n", pc->cbState, sizeof(ICCOMPRESS));
1134 if (!pc->lKeyCount++)
1135 icComp->dwFlags = ICCOMPRESS_KEYFRAME;
1138 if (pc->lKey && pc->lKeyCount == (pc->lKey - 1))
1139 /* No key frames if pc->lKey == 0 */
1141 icComp->dwFlags = 0;
1144 icComp->lpInput = lpBits;
1145 icComp->lFrameNum = pc->lFrame++;
1146 icComp->lpOutput = pc->lpBitsOut;
1147 icComp->lpPrev = pc->lpBitsPrev;
1148 ret = ICSendMessage(pc->hic, ICM_COMPRESS, (DWORD_PTR)icComp, sizeof(icComp));
1150 if (icComp->dwFlags & AVIIF_KEYFRAME)
1154 TRACE("Key frame\n");
1159 *plSize = icComp->lpbiOutput->biSizeImage;
1160 TRACE(" -- 0x%08lx\n", ret);
1161 if (ret == ICERR_OK)
1163 LPVOID oldprev, oldout;
1164 /* We shift Prev and Out, so we don't have to allocate and release memory */
1165 oldprev = pc->lpBitsPrev;
1166 oldout = pc->lpBitsOut;
1167 pc->lpBitsPrev = oldout;
1168 pc->lpBitsOut = oldprev;
1170 TRACE("returning: %p\n", icComp->lpOutput);
1171 return icComp->lpOutput;
1176 /***********************************************************************
1177 * ICSeqCompressFrameEnd [MSVFW32.@]
1179 void VFWAPI ICSeqCompressFrameEnd(PCOMPVARS pc)
1182 TRACE("(%p)\n", pc);
1183 ret = ICSendMessage(pc->hic, ICM_COMPRESS_END, 0, 0);
1184 TRACE(" -- %lx", ret);
1186 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1188 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1190 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
1192 HeapFree(GetProcessHeap(), 0, pc->lpState);
1193 pc->lpbiIn = pc->lpBitsPrev = pc->lpBitsOut = pc->lpState = NULL;
1196 /***********************************************************************
1197 * ICSeqCompressFrameStart [MSVFW32.@]
1199 BOOL VFWAPI ICSeqCompressFrameStart(PCOMPVARS pc, LPBITMAPINFO lpbiIn)
1201 /* I'm ignoring bmiColors as I don't know what to do with it,
1202 * it doesn't appear to be used though
1205 pc->lpbiIn = HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO));
1209 memcpy(pc->lpbiIn, lpbiIn, sizeof(BITMAPINFO));
1210 pc->lpBitsPrev = HeapAlloc(GetProcessHeap(), 0, pc->lpbiIn->bmiHeader.biSizeImage);
1211 if (!pc->lpBitsPrev)
1213 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1217 pc->lpState = HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS));
1220 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1221 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1224 pc->cbState = sizeof(ICCOMPRESS);
1226 pc->lpBitsOut = HeapAlloc(GetProcessHeap(), 0, pc->lpbiOut->bmiHeader.biSizeImage);
1229 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1230 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1231 HeapFree(GetProcessHeap(), 0, pc->lpState);
1242 "key/data/quality: %li/%li/%li\n",
1243 pc->cbSize, pc->dwFlags, pc->hic, pc->fccType, pc->fccHandler,
1244 pc->lpbiIn, pc->lpbiOut, pc->lKey, pc->lDataRate, pc->lQ);
1246 ret = ICSendMessage(pc->hic, ICM_COMPRESS_BEGIN, (DWORD_PTR)pc->lpbiIn, (DWORD_PTR)pc->lpbiOut);
1247 TRACE(" -- %lx\n", ret);
1248 if (ret == ICERR_OK)
1250 ICCOMPRESS* icComp = (ICCOMPRESS *)pc->lpState;
1251 /* Initialise some variables */
1252 pc->lFrame = 0; pc->lKeyCount = 0;
1254 icComp->lpbiOutput = &pc->lpbiOut->bmiHeader;
1255 icComp->lpbiInput = &pc->lpbiIn->bmiHeader;
1256 icComp->lpckid = NULL;
1257 icComp->dwFrameSize = 0;
1258 icComp->dwQuality = pc->lQ;
1259 icComp->lpbiPrev = &pc->lpbiIn->bmiHeader;
1262 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1263 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1264 HeapFree(GetProcessHeap(), 0, pc->lpState);
1265 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
1266 pc->lpBitsPrev = pc->lpbiIn = pc->lpState = pc->lpBitsOut = NULL;
1270 /***********************************************************************
1271 * GetFileNamePreview [MSVFW32.@]
1273 static BOOL GetFileNamePreview(LPVOID lpofn,BOOL bSave,BOOL bUnicode)
1275 CHAR szFunctionName[20];
1276 BOOL (*fnGetFileName)(LPVOID);
1280 FIXME("(%p,%d,%d), semi-stub!\n",lpofn,bSave,bUnicode);
1282 lstrcpyA(szFunctionName, (bSave ? "GetSaveFileName" : "GetOpenFileName"));
1283 lstrcatA(szFunctionName, (bUnicode ? "W" : "A"));
1285 hComdlg32 = LoadLibraryA("COMDLG32.DLL");
1286 if (hComdlg32 == NULL)
1289 fnGetFileName = (LPVOID)GetProcAddress(hComdlg32, szFunctionName);
1290 if (fnGetFileName == NULL)
1293 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1294 ret = fnGetFileName(lpofn);
1296 FreeLibrary(hComdlg32);
1300 /***********************************************************************
1301 * GetOpenFileNamePreviewA [MSVFW32.@]
1303 BOOL WINAPI GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn)
1305 FIXME("(%p), semi-stub!\n", lpofn);
1307 return GetFileNamePreview(lpofn, FALSE, FALSE);
1310 /***********************************************************************
1311 * GetOpenFileNamePreviewW [MSVFW32.@]
1313 BOOL WINAPI GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn)
1315 FIXME("(%p), semi-stub!\n", lpofn);
1317 return GetFileNamePreview(lpofn, FALSE, TRUE);
1320 /***********************************************************************
1321 * GetSaveFileNamePreviewA [MSVFW32.@]
1323 BOOL WINAPI GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn)
1325 FIXME("(%p), semi-stub!\n", lpofn);
1327 return GetFileNamePreview(lpofn, TRUE, FALSE);
1330 /***********************************************************************
1331 * GetSaveFileNamePreviewW [MSVFW32.@]
1333 BOOL WINAPI GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn)
1335 FIXME("(%p), semi-stub!\n", lpofn);
1337 return GetFileNamePreview(lpofn, TRUE, TRUE);