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.
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 LRESULT (CALLBACK *pFnCallTo16)(HDRVR, HIC, UINT, LPARAM, LPARAM) = NULL;
58 static WINE_HIC* MSVIDEO_FirstHic /* = NULL */;
60 typedef struct _reg_driver reg_driver;
70 static reg_driver* reg_driver_list = NULL;
72 /* This one is a macro such that it works for both ASCII and Unicode */
73 #define fourcc_to_string(str, fcc) do { \
74 (str)[0] = LOBYTE(LOWORD(fcc)); \
75 (str)[1] = HIBYTE(LOWORD(fcc)); \
76 (str)[2] = LOBYTE(HIWORD(fcc)); \
77 (str)[3] = HIBYTE(HIWORD(fcc)); \
80 HMODULE MSVFW32_hModule;
82 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
84 TRACE("%p,%x,%p\n", hinst, reason, reserved);
88 case DLL_PROCESS_ATTACH:
89 DisableThreadLibraryCalls(hinst);
90 MSVFW32_hModule = hinst;
96 static int compare_fourcc(DWORD fcc1, DWORD fcc2)
100 fourcc_to_string(fcc_str1, fcc1);
101 fourcc_to_string(fcc_str2, fcc2);
102 return strncasecmp(fcc_str1, fcc_str2, 4);
105 typedef BOOL (*enum_handler_t)(const char*, unsigned int, void*);
107 static BOOL enum_drivers(DWORD fccType, enum_handler_t handler, void* param)
109 CHAR buf[2048], fccTypeStr[5], *s;
110 DWORD i, cnt = 0, lRet;
114 fourcc_to_string(fccTypeStr, fccType);
117 /* first, go through the registry entries */
118 lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, HKLM_DRIVERS32, 0, KEY_QUERY_VALUE, &hKey);
119 if (lRet == ERROR_SUCCESS)
121 DWORD name, data, type;
126 data = sizeof buf - name;
127 lRet = RegEnumValueA(hKey, i++, buf, &name, 0, &type, (LPBYTE)(buf+name), &data);
128 if (lRet == ERROR_NO_MORE_ITEMS) break;
129 if (lRet != ERROR_SUCCESS) continue;
130 if (name != 9 || strncasecmp(buf, fccTypeStr, 5)) continue;
132 if ((result = handler(buf, cnt++, param))) break;
136 if (result) return result;
138 /* if that didn't work, go through the values in system.ini */
139 if (GetPrivateProfileSectionA("drivers32", buf, sizeof(buf), "system.ini"))
141 for (s = buf; *s; s += strlen(s) + 1)
143 TRACE("got %s\n", s);
144 if (strncasecmp(s, fccTypeStr, 5) || s[9] != '=') continue;
145 if ((result = handler(s, cnt++, param))) break;
152 /******************************************************************
157 WINE_HIC* MSVIDEO_GetHicPtr(HIC hic)
161 for (whic = MSVIDEO_FirstHic; whic && whic->hic != hic; whic = whic->next);
165 /***********************************************************************
166 * VideoForWindowsVersion [MSVFW32.2]
167 * VideoForWindowsVersion [MSVIDEO.2]
168 * Returns the version in major.minor form.
169 * In Windows95 this returns 0x040003b6 (4.950)
171 DWORD WINAPI VideoForWindowsVersion(void)
173 return 0x040003B6; /* 4.950 */
176 static BOOL ICInfo_enum_handler(const char *drv, unsigned int nr, void *param)
178 ICINFO *lpicinfo = (ICINFO *)param;
179 DWORD fccHandler = mmioStringToFOURCCA(drv + 5, 0);
181 /* exact match of fccHandler or nth driver found */
182 if ((lpicinfo->fccHandler != nr) && (lpicinfo->fccHandler != fccHandler))
185 lpicinfo->fccHandler = fccHandler;
186 lpicinfo->dwFlags = 0;
187 lpicinfo->dwVersion = 0;
188 lpicinfo->dwVersionICM = ICVERSION;
189 lpicinfo->szName[0] = 0;
190 lpicinfo->szDescription[0] = 0;
191 MultiByteToWideChar(CP_ACP, 0, drv + 10, -1, lpicinfo->szDriver,
192 sizeof(lpicinfo->szDriver)/sizeof(WCHAR));
197 /***********************************************************************
199 * Get information about an installable compressor. Return TRUE if there
203 * fccType [I] type of compressor (e.g. 'vidc')
204 * fccHandler [I] real fcc for handler or <n>th compressor
205 * lpicinfo [O] information about compressor
207 BOOL VFWAPI ICInfo( DWORD fccType, DWORD fccHandler, ICINFO *lpicinfo)
209 TRACE("(%s,%s/%08x,%p)\n",
210 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), fccHandler, lpicinfo);
212 lpicinfo->fccType = fccType;
213 lpicinfo->fccHandler = fccHandler;
214 return enum_drivers(fccType, ICInfo_enum_handler, lpicinfo);
217 static DWORD IC_HandleRef = 1;
219 /***********************************************************************
220 * ICInstall [MSVFW32.@]
222 BOOL VFWAPI ICInstall(DWORD fccType, DWORD fccHandler, LPARAM lParam, LPSTR szDesc, UINT wFlags)
227 TRACE("(%s,%s,%p,%p,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), (void*)lParam, szDesc, wFlags);
229 /* Check if a driver is already registered */
230 for (driver = reg_driver_list; driver; driver = driver->next)
232 if (!compare_fourcc(fccType, driver->fccType) &&
233 !compare_fourcc(fccHandler, driver->fccHandler))
236 if (driver) return FALSE;
238 /* Register the driver */
239 driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(reg_driver));
240 if (!driver) goto oom;
241 driver->fccType = fccType;
242 driver->fccHandler = fccHandler;
246 case ICINSTALL_FUNCTION:
247 driver->proc = (DRIVERPROC)lParam;
250 case ICINSTALL_DRIVER:
252 len = MultiByteToWideChar(CP_ACP, 0, (char*)lParam, -1, NULL, 0);
253 driver->name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
254 if (!driver->name) goto oom;
255 MultiByteToWideChar(CP_ACP, 0, (char*)lParam, -1, driver->name, len);
258 ERR("Invalid flags!\n");
259 HeapFree(GetProcessHeap(), 0, driver);
263 /* Insert our driver in the list*/
264 driver->next = reg_driver_list;
265 reg_driver_list = driver;
269 HeapFree(GetProcessHeap(), 0, driver);
273 /***********************************************************************
274 * ICRemove [MSVFW32.@]
276 BOOL VFWAPI ICRemove(DWORD fccType, DWORD fccHandler, UINT wFlags)
278 reg_driver** pdriver;
281 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wFlags);
283 /* Check if a driver is already registered */
284 for (pdriver = ®_driver_list; *pdriver; pdriver = &(*pdriver)->next)
286 if (!compare_fourcc(fccType, (*pdriver)->fccType) &&
287 !compare_fourcc(fccHandler, (*pdriver)->fccHandler))
293 /* Remove the driver from the list */
295 *pdriver = (*pdriver)->next;
296 HeapFree(GetProcessHeap(), 0, drv->name);
297 HeapFree(GetProcessHeap(), 0, drv);
303 /***********************************************************************
305 * Opens an installable compressor. Return special handle.
307 HIC VFWAPI ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode)
314 static const WCHAR drv32W[] = {'d','r','i','v','e','r','s','3','2','\0'};
317 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode);
319 /* Check if there is a registered driver that matches */
320 driver = reg_driver_list;
322 if (!compare_fourcc(fccType, driver->fccType) &&
323 !compare_fourcc(fccHandler, driver->fccHandler))
326 driver = driver->next;
328 if (driver && driver->proc)
329 /* The driver has been registered at runtime with its driverproc */
330 return MSVIDEO_OpenFunction(fccType, fccHandler, wMode, driver->proc, 0);
332 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
333 * same layout as ICOPEN
335 icopen.dwSize = sizeof(ICOPEN);
336 icopen.fccType = fccType;
337 icopen.fccHandler = fccHandler;
338 icopen.dwVersion = 0x00001000; /* FIXME */
339 icopen.dwFlags = wMode;
341 icopen.pV1Reserved = NULL;
342 icopen.pV2Reserved = NULL;
343 icopen.dnDevNode = 0; /* FIXME */
346 /* The driver is registered in the registry */
347 fourcc_to_string(codecname, fccType);
349 fourcc_to_string(codecname + 5, fccHandler);
352 hdrv = OpenDriver(codecname, drv32W, (LPARAM)&icopen);
356 /* The driver has been registered at runtime with its name */
357 hdrv = OpenDriver(driver->name, NULL, (LPARAM)&icopen);
361 bIs16 = GetDriverFlags(hdrv) & 0x10000000; /* undocumented flag: WINE_GDF_16BIT */
363 if (bIs16 && !pFnCallTo16)
365 FIXME("Got a 16 bit driver, but no 16 bit support in msvfw\n");
368 whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
371 CloseDriver(hdrv, 0, 0);
375 /* FIXME: is the signature the real one ? */
376 whic->driverproc = bIs16 ? (DRIVERPROC)pFnCallTo16 : NULL;
377 whic->driverproc16 = 0;
378 whic->type = fccType;
379 whic->handler = fccHandler;
380 while (MSVIDEO_GetHicPtr(HIC_32(IC_HandleRef)) != NULL) IC_HandleRef++;
381 whic->hic = HIC_32(IC_HandleRef++);
382 whic->next = MSVIDEO_FirstHic;
383 MSVIDEO_FirstHic = whic;
385 TRACE("=> %p\n", whic->hic);
389 /***********************************************************************
390 * MSVIDEO_OpenFunction
392 HIC MSVIDEO_OpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode,
393 DRIVERPROC lpfnHandler, DWORD lpfnHandler16)
398 TRACE("(%s,%s,%d,%p,%08x)\n",
399 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode, lpfnHandler, lpfnHandler16);
401 icopen.dwSize = sizeof(ICOPEN);
402 icopen.fccType = fccType;
403 icopen.fccHandler = fccHandler;
404 icopen.dwVersion = ICVERSION;
405 icopen.dwFlags = wMode;
407 icopen.pV1Reserved = NULL;
408 icopen.pV2Reserved = NULL;
409 icopen.dnDevNode = 0; /* FIXME */
411 whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
414 whic->driverproc = lpfnHandler;
415 whic->driverproc16 = lpfnHandler16;
416 while (MSVIDEO_GetHicPtr(HIC_32(IC_HandleRef)) != NULL) IC_HandleRef++;
417 whic->hic = HIC_32(IC_HandleRef++);
418 whic->next = MSVIDEO_FirstHic;
419 MSVIDEO_FirstHic = whic;
421 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
422 /* What if the function is used more than once? */
424 if (MSVIDEO_SendMessage(whic, DRV_LOAD, 0L, 0L) != DRV_SUCCESS)
426 WARN("DRV_LOAD failed for hic %p\n", whic->hic);
427 MSVIDEO_FirstHic = whic->next;
428 HeapFree(GetProcessHeap(), 0, whic);
431 /* return value is not checked */
432 MSVIDEO_SendMessage(whic, DRV_ENABLE, 0L, 0L);
434 whic->driverId = (DWORD)MSVIDEO_SendMessage(whic, DRV_OPEN, 0, (DWORD_PTR)&icopen);
435 /* FIXME: What should we put here? */
438 if (whic->driverId == 0)
440 WARN("DRV_OPEN failed for hic %p\n", whic->hic);
441 MSVIDEO_FirstHic = whic->next;
442 HeapFree(GetProcessHeap(), 0, whic);
446 TRACE("=> %p\n", whic->hic);
450 /***********************************************************************
451 * ICOpenFunction [MSVFW32.@]
453 HIC VFWAPI ICOpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode, FARPROC lpfnHandler)
455 return MSVIDEO_OpenFunction(fccType, fccHandler, wMode, (DRIVERPROC)lpfnHandler, 0);
458 /***********************************************************************
459 * ICGetInfo [MSVFW32.@]
461 LRESULT VFWAPI ICGetInfo(HIC hic, ICINFO *picinfo, DWORD cb)
464 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
466 TRACE("(%p,%p,%d)\n", hic, picinfo, cb);
468 whic = MSVIDEO_GetHicPtr(hic);
469 if (!whic) return ICERR_BADHANDLE;
470 if (!picinfo) return MMSYSERR_INVALPARAM;
472 /* (WS) The field szDriver should be initialized because the driver
473 * is not obliged and often will not do it. Some applications, like
474 * VirtualDub, rely on this field and will occasionally crash if it
475 * goes uninitialized.
477 if (cb >= sizeof(ICINFO)) picinfo->szDriver[0] = '\0';
479 ret = ICSendMessage(hic, ICM_GETINFO, (DWORD_PTR)picinfo, cb);
481 /* (WS) When szDriver was not supplied by the driver itself, apparently
482 * Windows will set its value equal to the driver file name. This can
483 * be obtained from the registry as we do here.
485 if (cb >= sizeof(ICINFO) && picinfo->szDriver[0] == 0)
489 memset(&ii, 0, sizeof(ii));
490 ii.dwSize = sizeof(ii);
491 ICInfo(picinfo->fccType, picinfo->fccHandler, &ii);
492 lstrcpyW(picinfo->szDriver, ii.szDriver);
495 TRACE(" -> 0x%08lx\n", ret);
502 LPBITMAPINFOHEADER lpbiIn;
503 LPBITMAPINFOHEADER lpbiOut;
509 static HIC try_driver(driver_info_t *info)
513 if ((hic = ICOpen(info->fccType, info->fccHandler, info->wMode)))
515 if (!ICSendMessage(hic, info->querymsg, (DWORD_PTR)info->lpbiIn, (DWORD_PTR)info->lpbiOut))
522 static BOOL ICLocate_enum_handler(const char *drv, unsigned int nr, void *param)
524 driver_info_t *info = (driver_info_t *)param;
525 info->fccHandler = mmioStringToFOURCCA(drv + 5, 0);
526 info->hic = try_driver(info);
527 return info->hic != 0;
530 /***********************************************************************
531 * ICLocate [MSVFW32.@]
533 HIC VFWAPI ICLocate(DWORD fccType, DWORD fccHandler, LPBITMAPINFOHEADER lpbiIn,
534 LPBITMAPINFOHEADER lpbiOut, WORD wMode)
538 TRACE("(%s,%s,%p,%p,0x%04x)\n",
539 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), lpbiIn, lpbiOut, wMode);
541 info.fccType = fccType;
542 info.fccHandler = fccHandler;
543 info.lpbiIn = lpbiIn;
544 info.lpbiOut = lpbiOut;
549 case ICMODE_FASTCOMPRESS:
550 case ICMODE_COMPRESS:
551 info.querymsg = ICM_COMPRESS_QUERY;
553 case ICMODE_FASTDECOMPRESS:
554 case ICMODE_DECOMPRESS:
555 info.querymsg = ICM_DECOMPRESS_QUERY;
558 info.querymsg = ICM_DRAW_QUERY;
561 WARN("Unknown mode (%d)\n", wMode);
565 /* Easy case: handler/type match, we just fire a query and return */
566 info.hic = try_driver(&info);
567 /* If it didn't work, try each driver in turn. 32 bit codecs only. */
568 /* FIXME: Move this to an init routine? */
569 if (!info.hic) enum_drivers(fccType, ICLocate_enum_handler, &info);
573 TRACE("=> %p\n", info.hic);
577 if (fccType == streamtypeVIDEO)
578 return ICLocate(ICTYPE_VIDEO, fccHandler, lpbiIn, lpbiOut, wMode);
580 WARN("(%s,%s,%p,%p,0x%04x) not found!\n",
581 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), lpbiIn, lpbiOut, wMode);
585 /***********************************************************************
586 * ICGetDisplayFormat [MSVFW32.@]
588 HIC VFWAPI ICGetDisplayFormat(
589 HIC hic,LPBITMAPINFOHEADER lpbiIn,LPBITMAPINFOHEADER lpbiOut,
590 INT depth,INT dx,INT dy)
594 TRACE("(%p,%p,%p,%d,%d,%d)!\n",hic,lpbiIn,lpbiOut,depth,dx,dy);
597 tmphic=ICLocate(ICTYPE_VIDEO,0,lpbiIn,NULL,ICMODE_DECOMPRESS);
601 if ((dy == lpbiIn->biHeight) && (dx == lpbiIn->biWidth))
602 dy = dx = 0; /* no resize needed */
604 /* Can we decompress it ? */
605 if (ICDecompressQuery(tmphic,lpbiIn,NULL) != 0)
606 goto errout; /* no, sorry */
608 ICSendMessage(tmphic, ICM_DECOMPRESS_GET_FORMAT, (DWORD_PTR)lpbiIn, (DWORD_PTR)lpbiOut);
610 if (lpbiOut->biCompression != 0) {
611 FIXME("Ooch, how come decompressor outputs compressed data (%d)??\n",
612 lpbiOut->biCompression);
614 if (lpbiOut->biSize < sizeof(*lpbiOut)) {
615 FIXME("Ooch, size of output BIH is too small (%d)\n",
617 lpbiOut->biSize = sizeof(*lpbiOut);
623 depth = GetDeviceCaps(hdc,BITSPIXEL)*GetDeviceCaps(hdc,PLANES);
625 if (depth==15) depth = 16;
626 if (depth<8) depth = 8;
628 if (lpbiIn->biBitCount == 8)
631 TRACE("=> %p\n", tmphic);
641 /***********************************************************************
642 * ICCompress [MSVFW32.@]
646 HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiOutput,LPVOID lpData,
647 LPBITMAPINFOHEADER lpbiInput,LPVOID lpBits,LPDWORD lpckid,
648 LPDWORD lpdwFlags,LONG lFrameNum,DWORD dwFrameSize,DWORD dwQuality,
649 LPBITMAPINFOHEADER lpbiPrev,LPVOID lpPrev)
653 TRACE("(%p,%d,%p,%p,%p,%p,...)\n",hic,dwFlags,lpbiOutput,lpData,lpbiInput,lpBits);
655 iccmp.dwFlags = dwFlags;
657 iccmp.lpbiOutput = lpbiOutput;
658 iccmp.lpOutput = lpData;
659 iccmp.lpbiInput = lpbiInput;
660 iccmp.lpInput = lpBits;
662 iccmp.lpckid = lpckid;
663 iccmp.lpdwFlags = lpdwFlags;
664 iccmp.lFrameNum = lFrameNum;
665 iccmp.dwFrameSize = dwFrameSize;
666 iccmp.dwQuality = dwQuality;
667 iccmp.lpbiPrev = lpbiPrev;
668 iccmp.lpPrev = lpPrev;
669 return ICSendMessage(hic,ICM_COMPRESS,(DWORD_PTR)&iccmp,sizeof(iccmp));
672 /***********************************************************************
673 * ICDecompress [MSVFW32.@]
675 DWORD VFWAPIV ICDecompress(HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiFormat,
676 LPVOID lpData,LPBITMAPINFOHEADER lpbi,LPVOID lpBits)
681 TRACE("(%p,%d,%p,%p,%p,%p)\n",hic,dwFlags,lpbiFormat,lpData,lpbi,lpBits);
683 TRACE("lpBits[0] == %x\n",((LPDWORD)lpBits)[0]);
685 icd.dwFlags = dwFlags;
686 icd.lpbiInput = lpbiFormat;
687 icd.lpInput = lpData;
689 icd.lpbiOutput = lpbi;
690 icd.lpOutput = lpBits;
692 ret = ICSendMessage(hic,ICM_DECOMPRESS,(DWORD_PTR)&icd,sizeof(ICDECOMPRESS));
694 TRACE("lpBits[0] == %x\n",((LPDWORD)lpBits)[0]);
696 TRACE("-> %d\n",ret);
702 struct choose_compressor
715 static BOOL enum_compressors(HWND list, COMPVARS *pcv, BOOL enum_all)
722 while (ICInfo(pcv->fccType, id, &icinfo))
724 struct codec_info *ic;
730 hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_COMPRESS);
734 /* for unknown reason fccHandler reported by the driver
735 * doesn't always work, use the one returned by ICInfo instead.
737 DWORD fccHandler = icinfo.fccHandler;
739 if (!enum_all && pcv->lpbiIn)
741 if (ICCompressQuery(hic, pcv->lpbiIn, NULL) != ICERR_OK)
743 TRACE("fccHandler %s doesn't support input DIB format %d\n",
744 wine_dbgstr_fcc(icinfo.fccHandler), pcv->lpbiIn->bmiHeader.biCompression);
750 ICGetInfo(hic, &icinfo, sizeof(icinfo));
751 icinfo.fccHandler = fccHandler;
753 idx = SendMessageW(list, CB_ADDSTRING, 0, (LPARAM)icinfo.szDescription);
755 ic = HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info));
758 SendMessageW(list, CB_SETITEMDATA, idx, (LPARAM)ic);
766 static INT_PTR CALLBACK icm_choose_compressor_dlgproc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
772 struct codec_info *ic;
774 struct choose_compressor *choose_comp = (struct choose_compressor *)lparam;
776 SetWindowLongPtrW(hdlg, DWLP_USER, lparam);
779 choose_comp->flags &= ~(ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME);
781 if (choose_comp->title)
782 SetWindowTextA(hdlg, choose_comp->title);
784 if (!(choose_comp->flags & ICMF_CHOOSE_DATARATE))
786 ShowWindow(GetDlgItem(hdlg, IDC_DATARATE_CHECKBOX), SW_HIDE);
787 ShowWindow(GetDlgItem(hdlg, IDC_DATARATE), SW_HIDE);
788 ShowWindow(GetDlgItem(hdlg, IDC_DATARATE_KB), SW_HIDE);
791 if (!(choose_comp->flags & ICMF_CHOOSE_KEYFRAME))
793 ShowWindow(GetDlgItem(hdlg, IDC_KEYFRAME_CHECKBOX), SW_HIDE);
794 ShowWindow(GetDlgItem(hdlg, IDC_KEYFRAME), SW_HIDE);
795 ShowWindow(GetDlgItem(hdlg, IDC_KEYFRAME_FRAMES), SW_HIDE);
799 EnableWindow(GetDlgItem(hdlg, IDC_QUALITY_SCROLL), FALSE);
800 EnableWindow(GetDlgItem(hdlg, IDC_QUALITY_TXT), FALSE);
802 /*if (!(choose_comp->flags & ICMF_CHOOSE_PREVIEW))
803 ShowWindow(GetDlgItem(hdlg, IDC_PREVIEW), SW_HIDE);*/
805 LoadStringW(MSVFW32_hModule, IDS_FULLFRAMES, buf, 128);
806 SendDlgItemMessageW(hdlg, IDC_COMP_LIST, CB_ADDSTRING, 0, (LPARAM)buf);
808 ic = HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info));
809 ic->icinfo.fccType = streamtypeVIDEO;
810 ic->icinfo.fccHandler = comptypeDIB;
812 SendDlgItemMessageW(hdlg, IDC_COMP_LIST, CB_SETITEMDATA, 0, (LPARAM)ic);
814 enum_compressors(GetDlgItem(hdlg, IDC_COMP_LIST), &choose_comp->cv, choose_comp->flags & ICMF_CHOOSE_ALLCOMPRESSORS);
816 SendDlgItemMessageW(hdlg, IDC_COMP_LIST, CB_SETCURSEL, 0, 0);
817 SetFocus(GetDlgItem(hdlg, IDC_COMP_LIST));
819 SetWindowLongPtrW(hdlg, DWLP_USER, (ULONG_PTR)choose_comp);
824 switch (LOWORD(wparam))
829 struct codec_info *ic;
830 BOOL can_configure = FALSE, can_about = FALSE;
831 struct choose_compressor *choose_comp;
833 if (HIWORD(wparam) != CBN_SELCHANGE && HIWORD(wparam) != CBN_SETFOCUS)
836 choose_comp = (struct choose_compressor *)GetWindowLongPtrW(hdlg, DWLP_USER);
838 cur_sel = SendMessageW((HWND)lparam, CB_GETCURSEL, 0, 0);
840 ic = (struct codec_info *)SendMessageW((HWND)lparam, CB_GETITEMDATA, cur_sel, 0);
843 if (ICQueryConfigure(ic->hic) == DRVCNF_OK)
844 can_configure = TRUE;
845 if (ICQueryAbout(ic->hic) == DRVCNF_OK)
848 EnableWindow(GetDlgItem(hdlg, IDC_CONFIGURE), can_configure);
849 EnableWindow(GetDlgItem(hdlg, IDC_ABOUT), can_about);
851 if (choose_comp->flags & ICMF_CHOOSE_DATARATE)
855 if (choose_comp->flags & ICMF_CHOOSE_KEYFRAME)
866 HWND list = GetDlgItem(hdlg, IDC_COMP_LIST);
868 struct codec_info *ic;
870 if (HIWORD(wparam) != BN_CLICKED)
873 cur_sel = SendMessageW(list, CB_GETCURSEL, 0, 0);
875 ic = (struct codec_info *)SendMessageW(list, CB_GETITEMDATA, cur_sel, 0);
878 if (LOWORD(wparam) == IDC_CONFIGURE)
879 ICConfigure(ic->hic, hdlg);
881 ICAbout(ic->hic, hdlg);
889 HWND list = GetDlgItem(hdlg, IDC_COMP_LIST);
891 struct codec_info *ic;
893 if (HIWORD(wparam) != BN_CLICKED)
896 cur_sel = SendMessageW(list, CB_GETCURSEL, 0, 0);
897 ic = (struct codec_info *)SendMessageW(list, CB_GETITEMDATA, cur_sel, 0);
900 struct choose_compressor *choose_comp = (struct choose_compressor *)GetWindowLongPtrW(hdlg, DWLP_USER);
902 choose_comp->cv.hic = ic->hic;
903 choose_comp->cv.fccType = ic->icinfo.fccType;
904 choose_comp->cv.fccHandler = ic->icinfo.fccHandler;
905 /* FIXME: fill everything else */
907 /* prevent closing the codec handle below */
914 HWND list = GetDlgItem(hdlg, IDC_COMP_LIST);
917 if (HIWORD(wparam) != BN_CLICKED)
922 struct codec_info *ic;
924 ic = (struct codec_info *)SendMessageW(list, CB_GETITEMDATA, idx++, 0);
926 if (!ic || (LONG_PTR)ic == CB_ERR) break;
928 if (ic->hic) ICClose(ic->hic);
929 HeapFree(GetProcessHeap(), 0, ic);
932 EndDialog(hdlg, LOWORD(wparam) == IDOK);
948 /***********************************************************************
949 * ICCompressorChoose [MSVFW32.@]
951 BOOL VFWAPI ICCompressorChoose(HWND hwnd, UINT uiFlags, LPVOID pvIn,
952 LPVOID lpData, PCOMPVARS pc, LPSTR lpszTitle)
954 struct choose_compressor choose_comp;
957 TRACE("(%p,%08x,%p,%p,%p,%s)\n", hwnd, uiFlags, pvIn, lpData, pc, lpszTitle);
959 if (!pc || pc->cbSize != sizeof(COMPVARS))
962 if (!(pc->dwFlags & ICMF_COMPVARS_VALID))
965 pc->fccType = pc->fccHandler = 0;
969 pc->lpBitsOut = pc->lpBitsPrev = pc->lpState = NULL;
970 pc->lQ = ICQUALITY_DEFAULT;
972 pc->lDataRate = 300; /* kB */
976 if (pc->fccType == 0)
977 pc->fccType = ICTYPE_VIDEO;
979 choose_comp.cv = *pc;
980 choose_comp.flags = uiFlags;
981 choose_comp.title = lpszTitle;
983 ret = DialogBoxParamW(MSVFW32_hModule, MAKEINTRESOURCEW(ICM_CHOOSE_COMPRESSOR), hwnd,
984 icm_choose_compressor_dlgproc, (LPARAM)&choose_comp);
988 *pc = choose_comp.cv;
989 pc->dwFlags |= ICMF_COMPVARS_VALID;
996 /***********************************************************************
997 * ICCompressorFree [MSVFW32.@]
999 void VFWAPI ICCompressorFree(PCOMPVARS pc)
1003 if (pc != NULL && pc->cbSize == sizeof(COMPVARS)) {
1004 if (pc->hic != NULL) {
1008 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1010 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
1011 pc->lpBitsOut = NULL;
1012 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1013 pc->lpBitsPrev = NULL;
1014 HeapFree(GetProcessHeap(), 0, pc->lpState);
1021 /******************************************************************
1022 * MSVIDEO_SendMessage
1026 LRESULT MSVIDEO_SendMessage(WINE_HIC* whic, UINT msg, DWORD_PTR lParam1, DWORD_PTR lParam2)
1030 #define XX(x) case x: TRACE("(%p,"#x",0x%08lx,0x%08lx)\n",whic,lParam1,lParam2); break;
1040 /* ICM_RESERVED+X */
1045 XX(ICM_GETDEFAULTQUALITY);
1052 XX(ICM_COMPRESS_FRAMES_INFO);
1053 XX(ICM_COMPRESS_GET_FORMAT);
1054 XX(ICM_COMPRESS_GET_SIZE);
1055 XX(ICM_COMPRESS_QUERY);
1056 XX(ICM_COMPRESS_BEGIN);
1058 XX(ICM_COMPRESS_END);
1059 XX(ICM_DECOMPRESS_GET_FORMAT);
1060 XX(ICM_DECOMPRESS_QUERY);
1061 XX(ICM_DECOMPRESS_BEGIN);
1063 XX(ICM_DECOMPRESS_END);
1064 XX(ICM_DECOMPRESS_SET_PALETTE);
1065 XX(ICM_DECOMPRESS_GET_PALETTE);
1068 XX(ICM_DRAW_GET_PALETTE);
1072 XX(ICM_DRAW_GETTIME);
1074 XX(ICM_DRAW_WINDOW);
1075 XX(ICM_DRAW_SETTIME);
1076 XX(ICM_DRAW_REALIZE);
1078 XX(ICM_DRAW_RENDERBUFFER);
1079 XX(ICM_DRAW_START_PLAY);
1080 XX(ICM_DRAW_STOP_PLAY);
1081 XX(ICM_DRAW_SUGGESTFORMAT);
1082 XX(ICM_DRAW_CHANGEPALETTE);
1083 XX(ICM_GETBUFFERSWANTED);
1084 XX(ICM_GETDEFAULTKEYFRAMERATE);
1085 XX(ICM_DECOMPRESSEX_BEGIN);
1086 XX(ICM_DECOMPRESSEX_QUERY);
1087 XX(ICM_DECOMPRESSEX);
1088 XX(ICM_DECOMPRESSEX_END);
1089 XX(ICM_SET_STATUS_PROC);
1091 FIXME("(%p,0x%08x,0x%08lx,0x%08lx) unknown message\n",whic,msg,lParam1,lParam2);
1096 if (whic->driverproc) {
1097 /* dwDriverId parameter is the value returned by the DRV_OPEN */
1098 ret = whic->driverproc(whic->driverId, whic->hdrv, msg, lParam1, lParam2);
1100 ret = SendDriverMessage(whic->hdrv, msg, lParam1, lParam2);
1103 TRACE(" -> 0x%08lx\n", ret);
1107 /***********************************************************************
1108 * ICSendMessage [MSVFW32.@]
1110 LRESULT VFWAPI ICSendMessage(HIC hic, UINT msg, DWORD_PTR lParam1, DWORD_PTR lParam2)
1112 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
1114 if (!whic) return ICERR_BADHANDLE;
1115 return MSVIDEO_SendMessage(whic, msg, lParam1, lParam2);
1118 /***********************************************************************
1119 * ICDrawBegin [MSVFW32.@]
1121 DWORD VFWAPIV ICDrawBegin(
1123 DWORD dwFlags, /* [in] flags */
1124 HPALETTE hpal, /* [in] palette to draw with */
1125 HWND hwnd, /* [in] window to draw to */
1126 HDC hdc, /* [in] HDC to draw to */
1127 INT xDst, /* [in] destination rectangle */
1128 INT yDst, /* [in] */
1129 INT dxDst, /* [in] */
1130 INT dyDst, /* [in] */
1131 LPBITMAPINFOHEADER lpbi, /* [in] format of frame to draw */
1132 INT xSrc, /* [in] source rectangle */
1133 INT ySrc, /* [in] */
1134 INT dxSrc, /* [in] */
1135 INT dySrc, /* [in] */
1136 DWORD dwRate, /* [in] frames/second = (dwRate/dwScale) */
1137 DWORD dwScale) /* [in] */
1142 TRACE("(%p,%d,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%d,%d)\n",
1143 hic, dwFlags, hpal, hwnd, hdc, xDst, yDst, dxDst, dyDst,
1144 lpbi, xSrc, ySrc, dxSrc, dySrc, dwRate, dwScale);
1146 icdb.dwFlags = dwFlags;
1159 icdb.dwRate = dwRate;
1160 icdb.dwScale = dwScale;
1161 return ICSendMessage(hic,ICM_DRAW_BEGIN,(DWORD_PTR)&icdb,sizeof(icdb));
1164 /***********************************************************************
1165 * ICDraw [MSVFW32.@]
1167 DWORD VFWAPIV ICDraw(HIC hic, DWORD dwFlags, LPVOID lpFormat, LPVOID lpData, DWORD cbData, LONG lTime) {
1170 TRACE("(%p,%d,%p,%p,%d,%d)\n",hic,dwFlags,lpFormat,lpData,cbData,lTime);
1172 icd.dwFlags = dwFlags;
1173 icd.lpFormat = lpFormat;
1174 icd.lpData = lpData;
1175 icd.cbData = cbData;
1178 return ICSendMessage(hic,ICM_DRAW,(DWORD_PTR)&icd,sizeof(icd));
1181 /***********************************************************************
1182 * ICClose [MSVFW32.@]
1184 LRESULT WINAPI ICClose(HIC hic)
1186 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
1189 TRACE("(%p)\n",hic);
1191 if (!whic) return ICERR_BADHANDLE;
1193 if (whic->driverproc)
1195 MSVIDEO_SendMessage(whic, DRV_CLOSE, 0, 0);
1196 MSVIDEO_SendMessage(whic, DRV_DISABLE, 0, 0);
1197 MSVIDEO_SendMessage(whic, DRV_FREE, 0, 0);
1201 CloseDriver(whic->hdrv, 0, 0);
1204 /* remove whic from list */
1205 for (p = &MSVIDEO_FirstHic; *p != NULL; p = &((*p)->next))
1214 HeapFree(GetProcessHeap(), 0, whic);
1220 /***********************************************************************
1221 * ICImageCompress [MSVFW32.@]
1223 HANDLE VFWAPI ICImageCompress(
1224 HIC hic, UINT uiFlags,
1225 LPBITMAPINFO lpbiIn, LPVOID lpBits,
1226 LPBITMAPINFO lpbiOut, LONG lQuality,
1229 FIXME("(%p,%08x,%p,%p,%p,%d,%p)\n",
1230 hic, uiFlags, lpbiIn, lpBits, lpbiOut, lQuality, plSize);
1235 /***********************************************************************
1236 * ICImageDecompress [MSVFW32.@]
1239 HANDLE VFWAPI ICImageDecompress(
1240 HIC hic, UINT uiFlags, LPBITMAPINFO lpbiIn,
1241 LPVOID lpBits, LPBITMAPINFO lpbiOut)
1243 HGLOBAL hMem = NULL;
1245 BOOL bReleaseIC = FALSE;
1248 BOOL bSucceeded = FALSE;
1249 BOOL bInDecompress = FALSE;
1252 TRACE("(%p,%08x,%p,%p,%p)\n",
1253 hic, uiFlags, lpbiIn, lpBits, lpbiOut);
1257 hic = ICDecompressOpen( ICTYPE_VIDEO, 0, &lpbiIn->bmiHeader, (lpbiOut != NULL) ? &lpbiOut->bmiHeader : NULL );
1260 WARN("no handler\n" );
1267 FIXME( "unknown flag %08x\n", uiFlags );
1270 if ( lpbiIn == NULL || lpBits == NULL )
1272 WARN("invalid argument\n");
1276 if ( lpbiOut != NULL )
1278 if ( lpbiOut->bmiHeader.biSize != sizeof(BITMAPINFOHEADER) )
1280 cbHdr = sizeof(BITMAPINFOHEADER);
1281 if ( lpbiOut->bmiHeader.biCompression == 3 )
1282 cbHdr += sizeof(DWORD)*3;
1284 if ( lpbiOut->bmiHeader.biBitCount <= 8 )
1286 if ( lpbiOut->bmiHeader.biClrUsed == 0 )
1287 cbHdr += sizeof(RGBQUAD) * (1<<lpbiOut->bmiHeader.biBitCount);
1289 cbHdr += sizeof(RGBQUAD) * lpbiOut->bmiHeader.biClrUsed;
1294 TRACE( "get format\n" );
1296 cbHdr = ICDecompressGetFormatSize(hic,lpbiIn);
1297 if ( cbHdr < sizeof(BITMAPINFOHEADER) )
1299 pHdr = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,cbHdr+sizeof(RGBQUAD)*256);
1302 if ( ICDecompressGetFormat( hic, lpbiIn, (BITMAPINFO*)pHdr ) != ICERR_OK )
1304 lpbiOut = (BITMAPINFO*)pHdr;
1305 if ( lpbiOut->bmiHeader.biBitCount <= 8 &&
1306 ICDecompressGetPalette( hic, lpbiIn, lpbiOut ) != ICERR_OK &&
1307 lpbiIn->bmiHeader.biBitCount == lpbiOut->bmiHeader.biBitCount )
1309 if ( lpbiIn->bmiHeader.biClrUsed == 0 )
1310 memcpy( lpbiOut->bmiColors, lpbiIn->bmiColors, sizeof(RGBQUAD)*(1<<lpbiOut->bmiHeader.biBitCount) );
1312 memcpy( lpbiOut->bmiColors, lpbiIn->bmiColors, sizeof(RGBQUAD)*lpbiIn->bmiHeader.biClrUsed );
1314 if ( lpbiOut->bmiHeader.biBitCount <= 8 &&
1315 lpbiOut->bmiHeader.biClrUsed == 0 )
1316 lpbiOut->bmiHeader.biClrUsed = 1<<lpbiOut->bmiHeader.biBitCount;
1318 lpbiOut->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1319 cbHdr = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*lpbiOut->bmiHeader.biClrUsed;
1322 biSizeImage = lpbiOut->bmiHeader.biSizeImage;
1323 if ( biSizeImage == 0 )
1324 biSizeImage = ((((lpbiOut->bmiHeader.biWidth * lpbiOut->bmiHeader.biBitCount + 7) >> 3) + 3) & (~3)) * abs(lpbiOut->bmiHeader.biHeight);
1326 TRACE( "call ICDecompressBegin\n" );
1328 if ( ICDecompressBegin( hic, lpbiIn, lpbiOut ) != ICERR_OK )
1330 bInDecompress = TRUE;
1332 TRACE( "cbHdr %d, biSizeImage %d\n", cbHdr, biSizeImage );
1334 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_ZEROINIT, cbHdr + biSizeImage );
1337 WARN( "out of memory\n" );
1340 pMem = (BYTE*)GlobalLock( hMem );
1343 memcpy( pMem, lpbiOut, cbHdr );
1345 TRACE( "call ICDecompress\n" );
1346 if ( ICDecompress( hic, 0, &lpbiIn->bmiHeader, lpBits, &lpbiOut->bmiHeader, pMem+cbHdr ) != ICERR_OK )
1351 if ( bInDecompress )
1352 ICDecompressEnd( hic );
1355 HeapFree(GetProcessHeap(),0,pHdr);
1357 GlobalUnlock( hMem );
1358 if ( !bSucceeded && hMem != NULL )
1360 GlobalFree(hMem); hMem = NULL;
1366 /***********************************************************************
1367 * ICSeqCompressFrame [MSVFW32.@]
1369 LPVOID VFWAPI ICSeqCompressFrame(PCOMPVARS pc, UINT uiFlags, LPVOID lpBits, BOOL *pfKey, LONG *plSize)
1371 ICCOMPRESS* icComp = (ICCOMPRESS *)pc->lpState;
1373 TRACE("(%p, 0x%08x, %p, %p, %p)\n", pc, uiFlags, lpBits, pfKey, plSize);
1375 if (pc->cbState != sizeof(ICCOMPRESS))
1377 ERR("Invalid cbState %i\n", pc->cbState);
1381 if (!pc->lKeyCount++)
1382 icComp->dwFlags = ICCOMPRESS_KEYFRAME;
1385 if (pc->lKey && pc->lKeyCount == (pc->lKey - 1))
1386 /* No key frames if pc->lKey == 0 */
1388 icComp->dwFlags = 0;
1391 icComp->lpInput = lpBits;
1392 icComp->lFrameNum = pc->lFrame++;
1393 icComp->lpOutput = pc->lpBitsOut;
1394 icComp->lpPrev = pc->lpBitsPrev;
1395 ret = ICSendMessage(pc->hic, ICM_COMPRESS, (DWORD_PTR)icComp, sizeof(icComp));
1397 if (icComp->dwFlags & AVIIF_KEYFRAME)
1401 TRACE("Key frame\n");
1406 *plSize = icComp->lpbiOutput->biSizeImage;
1407 TRACE(" -- 0x%08x\n", ret);
1408 if (ret == ICERR_OK)
1410 LPVOID oldprev, oldout;
1411 /* We shift Prev and Out, so we don't have to allocate and release memory */
1412 oldprev = pc->lpBitsPrev;
1413 oldout = pc->lpBitsOut;
1414 pc->lpBitsPrev = oldout;
1415 pc->lpBitsOut = oldprev;
1417 TRACE("returning: %p\n", icComp->lpOutput);
1418 return icComp->lpOutput;
1423 /***********************************************************************
1424 * ICSeqCompressFrameEnd [MSVFW32.@]
1426 void VFWAPI ICSeqCompressFrameEnd(PCOMPVARS pc)
1429 TRACE("(%p)\n", pc);
1430 ret = ICSendMessage(pc->hic, ICM_COMPRESS_END, 0, 0);
1431 TRACE(" -- %x\n", ret);
1432 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1433 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1434 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
1435 HeapFree(GetProcessHeap(), 0, pc->lpState);
1436 pc->lpbiIn = pc->lpBitsPrev = pc->lpBitsOut = pc->lpState = NULL;
1439 /***********************************************************************
1440 * ICSeqCompressFrameStart [MSVFW32.@]
1442 BOOL VFWAPI ICSeqCompressFrameStart(PCOMPVARS pc, LPBITMAPINFO lpbiIn)
1444 /* I'm ignoring bmiColors as I don't know what to do with it,
1445 * it doesn't appear to be used though
1448 pc->lpbiIn = HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO));
1452 *pc->lpbiIn = *lpbiIn;
1453 pc->lpBitsPrev = HeapAlloc(GetProcessHeap(), 0, pc->lpbiIn->bmiHeader.biSizeImage);
1454 if (!pc->lpBitsPrev)
1456 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1460 pc->lpState = HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS));
1463 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1464 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1467 pc->cbState = sizeof(ICCOMPRESS);
1469 pc->lpBitsOut = HeapAlloc(GetProcessHeap(), 0, pc->lpbiOut->bmiHeader.biSizeImage);
1472 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1473 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1474 HeapFree(GetProcessHeap(), 0, pc->lpState);
1485 "key/data/quality: %i/%i/%i\n",
1486 pc->cbSize, pc->dwFlags, pc->hic, pc->fccType, pc->fccHandler,
1487 pc->lpbiIn, pc->lpbiOut, pc->lKey, pc->lDataRate, pc->lQ);
1489 ret = ICSendMessage(pc->hic, ICM_COMPRESS_BEGIN, (DWORD_PTR)pc->lpbiIn, (DWORD_PTR)pc->lpbiOut);
1490 TRACE(" -- %x\n", ret);
1491 if (ret == ICERR_OK)
1493 ICCOMPRESS* icComp = (ICCOMPRESS *)pc->lpState;
1494 /* Initialise some variables */
1495 pc->lFrame = 0; pc->lKeyCount = 0;
1497 icComp->lpbiOutput = &pc->lpbiOut->bmiHeader;
1498 icComp->lpbiInput = &pc->lpbiIn->bmiHeader;
1499 icComp->lpckid = NULL;
1500 icComp->dwFrameSize = 0;
1501 icComp->dwQuality = pc->lQ;
1502 icComp->lpbiPrev = &pc->lpbiIn->bmiHeader;
1505 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1506 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1507 HeapFree(GetProcessHeap(), 0, pc->lpState);
1508 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
1509 pc->lpBitsPrev = pc->lpbiIn = pc->lpState = pc->lpBitsOut = NULL;
1513 /***********************************************************************
1514 * GetFileNamePreview [MSVFW32.@]
1516 static BOOL GetFileNamePreview(LPVOID lpofn,BOOL bSave,BOOL bUnicode)
1518 CHAR szFunctionName[20];
1519 BOOL (*fnGetFileName)(LPVOID);
1523 FIXME("(%p,%d,%d), semi-stub!\n",lpofn,bSave,bUnicode);
1525 lstrcpyA(szFunctionName, (bSave ? "GetSaveFileName" : "GetOpenFileName"));
1526 lstrcatA(szFunctionName, (bUnicode ? "W" : "A"));
1528 hComdlg32 = LoadLibraryA("COMDLG32.DLL");
1529 if (hComdlg32 == NULL)
1532 fnGetFileName = (LPVOID)GetProcAddress(hComdlg32, szFunctionName);
1533 if (fnGetFileName == NULL)
1536 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1537 ret = fnGetFileName(lpofn);
1539 FreeLibrary(hComdlg32);
1543 /***********************************************************************
1544 * GetOpenFileNamePreviewA [MSVFW32.@]
1546 BOOL WINAPI GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn)
1548 FIXME("(%p), semi-stub!\n", lpofn);
1550 return GetFileNamePreview(lpofn, FALSE, FALSE);
1553 /***********************************************************************
1554 * GetOpenFileNamePreviewW [MSVFW32.@]
1556 BOOL WINAPI GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn)
1558 FIXME("(%p), semi-stub!\n", lpofn);
1560 return GetFileNamePreview(lpofn, FALSE, TRUE);
1563 /***********************************************************************
1564 * GetSaveFileNamePreviewA [MSVFW32.@]
1566 BOOL WINAPI GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn)
1568 FIXME("(%p), semi-stub!\n", lpofn);
1570 return GetFileNamePreview(lpofn, TRUE, FALSE);
1573 /***********************************************************************
1574 * GetSaveFileNamePreviewW [MSVFW32.@]
1576 BOOL WINAPI GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn)
1578 FIXME("(%p), semi-stub!\n", lpofn);
1580 return GetFileNamePreview(lpofn, TRUE, TRUE);