push cc8bc80451cc24f4d7cf75168b569f0ebfe19547
[wine/hacks.git] / dlls / msvfw32 / msvideo_main.c
blob7c98a1613c9ddbb2aa09e4764b707e68ce8701d7
1 /*
2 * Copyright 1998 Marcus Meissner
3 * Copyright 2000 Bradley Baetz
4 * Copyright 2003 Michael Günnewig
5 * Copyright 2005 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * FIXME: This all assumes 32 bit codecs
22 * Win95 appears to prefer 32 bit codecs, even from 16 bit code.
23 * There is the ICOpenFunction16 to worry about still, though.
25 * TODO
26 * - no thread safety
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <string.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winreg.h"
36 #include "winnls.h"
37 #include "wingdi.h"
38 #include "winuser.h"
39 #include "commdlg.h"
40 #include "vfw.h"
41 #include "msvideo_private.h"
42 #include "wine/debug.h"
44 /* Drivers32 settings */
45 #define HKLM_DRIVERS32 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32"
47 WINE_DEFAULT_DEBUG_CHANNEL(msvideo);
49 static inline const char *wine_dbgstr_fcc( DWORD fcc )
51 return wine_dbg_sprintf("%c%c%c%c",
52 LOBYTE(LOWORD(fcc)), HIBYTE(LOWORD(fcc)),
53 LOBYTE(HIWORD(fcc)), HIBYTE(HIWORD(fcc)));
56 static WINE_HIC* MSVIDEO_FirstHic /* = NULL */;
58 typedef struct _reg_driver reg_driver;
59 struct _reg_driver
61 DWORD fccType;
62 DWORD fccHandler;
63 DRIVERPROC proc;
64 LPWSTR name;
65 reg_driver* next;
68 static reg_driver* reg_driver_list = NULL;
70 /* This one is a macro such that it works for both ASCII and Unicode */
71 #define fourcc_to_string(str, fcc) do { \
72 (str)[0] = LOBYTE(LOWORD(fcc)); \
73 (str)[1] = HIBYTE(LOWORD(fcc)); \
74 (str)[2] = LOBYTE(HIWORD(fcc)); \
75 (str)[3] = HIBYTE(HIWORD(fcc)); \
76 } while(0)
78 HMODULE MSVFW32_hModule;
80 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
82 TRACE("%p,%x,%p\n", hinst, reason, reserved);
84 switch(reason)
86 case DLL_PROCESS_ATTACH:
87 DisableThreadLibraryCalls(hinst);
88 MSVFW32_hModule = hinst;
89 break;
91 return TRUE;
94 static int compare_fourcc(DWORD fcc1, DWORD fcc2)
96 char fcc_str1[4];
97 char fcc_str2[4];
98 fourcc_to_string(fcc_str1, fcc1);
99 fourcc_to_string(fcc_str2, fcc2);
100 return strncasecmp(fcc_str1, fcc_str2, 4);
103 typedef BOOL (*enum_handler_t)(const char*, unsigned int, void*);
105 static BOOL enum_drivers(DWORD fccType, enum_handler_t handler, void* param)
107 CHAR buf[2048], fccTypeStr[5], *s;
108 DWORD i, cnt = 0, lRet;
109 BOOL result = FALSE;
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 DWORD name, data, type;
120 i = 0;
121 for (;;)
123 name = 10;
124 data = sizeof buf - name;
125 lRet = RegEnumValueA(hKey, i++, buf, &name, 0, &type, (LPBYTE)(buf+name), &data);
126 if (lRet == ERROR_NO_MORE_ITEMS) break;
127 if (lRet != ERROR_SUCCESS) continue;
128 if (name != 9 || strncasecmp(buf, fccTypeStr, 5)) continue;
129 buf[name] = '=';
130 if ((result = handler(buf, cnt++, param))) break;
132 RegCloseKey( hKey );
134 if (result) return result;
136 /* if that didn't work, go through the values in system.ini */
137 if (GetPrivateProfileSectionA("drivers32", buf, sizeof(buf), "system.ini"))
139 for (s = buf; *s; s += strlen(s) + 1)
141 TRACE("got %s\n", s);
142 if (strncasecmp(s, fccTypeStr, 5) || s[9] != '=') continue;
143 if ((result = handler(s, cnt++, param))) break;
147 return result;
150 /******************************************************************
151 * MSVIDEO_GetHicPtr
155 WINE_HIC* MSVIDEO_GetHicPtr(HIC hic)
157 WINE_HIC* whic;
159 for (whic = MSVIDEO_FirstHic; whic && whic->hic != hic; whic = whic->next);
160 return whic;
163 /***********************************************************************
164 * VideoForWindowsVersion [MSVFW32.2]
165 * VideoForWindowsVersion [MSVIDEO.2]
166 * Returns the version in major.minor form.
167 * In Windows95 this returns 0x040003b6 (4.950)
169 DWORD WINAPI VideoForWindowsVersion(void)
171 return 0x040003B6; /* 4.950 */
174 static BOOL ICInfo_enum_handler(const char *drv, unsigned int nr, void *param)
176 ICINFO *lpicinfo = param;
177 DWORD fccHandler = mmioStringToFOURCCA(drv + 5, 0);
179 /* exact match of fccHandler or nth driver found */
180 if ((lpicinfo->fccHandler != nr) && (lpicinfo->fccHandler != fccHandler))
181 return FALSE;
183 lpicinfo->fccHandler = fccHandler;
184 lpicinfo->dwFlags = 0;
185 lpicinfo->dwVersion = 0;
186 lpicinfo->dwVersionICM = ICVERSION;
187 lpicinfo->szName[0] = 0;
188 lpicinfo->szDescription[0] = 0;
189 MultiByteToWideChar(CP_ACP, 0, drv + 10, -1, lpicinfo->szDriver,
190 sizeof(lpicinfo->szDriver)/sizeof(WCHAR));
192 return TRUE;
195 /***********************************************************************
196 * ICInfo [MSVFW32.@]
197 * Get information about an installable compressor. Return TRUE if there
198 * is one.
200 * PARAMS
201 * fccType [I] type of compressor (e.g. 'vidc')
202 * fccHandler [I] real fcc for handler or <n>th compressor
203 * lpicinfo [O] information about compressor
205 BOOL VFWAPI ICInfo( DWORD fccType, DWORD fccHandler, ICINFO *lpicinfo)
207 TRACE("(%s,%s/%08x,%p)\n",
208 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), fccHandler, lpicinfo);
210 lpicinfo->fccType = fccType;
211 lpicinfo->fccHandler = fccHandler;
212 return enum_drivers(fccType, ICInfo_enum_handler, lpicinfo);
215 static DWORD IC_HandleRef = 1;
217 /***********************************************************************
218 * ICInstall [MSVFW32.@]
220 BOOL VFWAPI ICInstall(DWORD fccType, DWORD fccHandler, LPARAM lParam, LPSTR szDesc, UINT wFlags)
222 reg_driver* driver;
223 unsigned len;
225 TRACE("(%s,%s,%p,%p,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), (void*)lParam, szDesc, wFlags);
227 /* Check if a driver is already registered */
228 for (driver = reg_driver_list; driver; driver = driver->next)
230 if (!compare_fourcc(fccType, driver->fccType) &&
231 !compare_fourcc(fccHandler, driver->fccHandler))
232 break;
234 if (driver) return FALSE;
236 /* Register the driver */
237 driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(reg_driver));
238 if (!driver) goto oom;
239 driver->fccType = fccType;
240 driver->fccHandler = fccHandler;
242 switch(wFlags)
244 case ICINSTALL_FUNCTION:
245 driver->proc = (DRIVERPROC)lParam;
246 driver->name = NULL;
247 break;
248 case ICINSTALL_DRIVER:
249 driver->proc = NULL;
250 len = MultiByteToWideChar(CP_ACP, 0, (char*)lParam, -1, NULL, 0);
251 driver->name = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
252 if (!driver->name) goto oom;
253 MultiByteToWideChar(CP_ACP, 0, (char*)lParam, -1, driver->name, len);
254 break;
255 default:
256 ERR("Invalid flags!\n");
257 HeapFree(GetProcessHeap(), 0, driver);
258 return FALSE;
261 /* Insert our driver in the list*/
262 driver->next = reg_driver_list;
263 reg_driver_list = driver;
265 return TRUE;
266 oom:
267 HeapFree(GetProcessHeap(), 0, driver);
268 return FALSE;
271 /***********************************************************************
272 * ICRemove [MSVFW32.@]
274 BOOL VFWAPI ICRemove(DWORD fccType, DWORD fccHandler, UINT wFlags)
276 reg_driver** pdriver;
277 reg_driver* drv;
279 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wFlags);
281 /* Check if a driver is already registered */
282 for (pdriver = &reg_driver_list; *pdriver; pdriver = &(*pdriver)->next)
284 if (!compare_fourcc(fccType, (*pdriver)->fccType) &&
285 !compare_fourcc(fccHandler, (*pdriver)->fccHandler))
286 break;
288 if (!*pdriver)
289 return FALSE;
291 /* Remove the driver from the list */
292 drv = *pdriver;
293 *pdriver = (*pdriver)->next;
294 HeapFree(GetProcessHeap(), 0, drv->name);
295 HeapFree(GetProcessHeap(), 0, drv);
297 return TRUE;
301 /***********************************************************************
302 * ICOpen [MSVFW32.@]
303 * Opens an installable compressor. Return special handle.
305 HIC VFWAPI ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode)
307 WCHAR codecname[10];
308 ICOPEN icopen;
309 HDRVR hdrv;
310 WINE_HIC* whic;
311 BOOL bIs16;
312 static const WCHAR drv32W[] = {'d','r','i','v','e','r','s','3','2','\0'};
313 reg_driver* driver;
315 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode);
317 /* Check if there is a registered driver that matches */
318 driver = reg_driver_list;
319 while(driver)
320 if (!compare_fourcc(fccType, driver->fccType) &&
321 !compare_fourcc(fccHandler, driver->fccHandler))
322 break;
323 else
324 driver = driver->next;
326 if (driver && driver->proc)
327 /* The driver has been registered at runtime with its driverproc */
328 return ICOpenFunction(fccType, fccHandler, wMode, driver->proc);
330 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
331 * same layout as ICOPEN
333 icopen.dwSize = sizeof(ICOPEN);
334 icopen.fccType = fccType;
335 icopen.fccHandler = fccHandler;
336 icopen.dwVersion = 0x00001000; /* FIXME */
337 icopen.dwFlags = wMode;
338 icopen.dwError = 0;
339 icopen.pV1Reserved = NULL;
340 icopen.pV2Reserved = NULL;
341 icopen.dnDevNode = 0; /* FIXME */
343 if (!driver) {
344 /* The driver is registered in the registry */
345 fourcc_to_string(codecname, fccType);
346 codecname[4] = '.';
347 fourcc_to_string(codecname + 5, fccHandler);
348 codecname[9] = '\0';
350 hdrv = OpenDriver(codecname, drv32W, (LPARAM)&icopen);
351 if (!hdrv)
352 return 0;
353 } else {
354 /* The driver has been registered at runtime with its name */
355 hdrv = OpenDriver(driver->name, NULL, (LPARAM)&icopen);
356 if (!hdrv)
357 return 0;
359 bIs16 = GetDriverFlags(hdrv) & 0x10000000; /* undocumented flag: WINE_GDF_16BIT */
361 if (bIs16)
363 FIXME("Got a 16 bit driver, but no 16 bit support in msvfw\n");
364 CloseDriver(hdrv, 0, 0);
365 return 0;
367 whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
368 if (!whic)
370 CloseDriver(hdrv, 0, 0);
371 return FALSE;
373 whic->hdrv = hdrv;
374 whic->driverproc = NULL;
375 whic->type = fccType;
376 whic->handler = fccHandler;
377 while (MSVIDEO_GetHicPtr((HIC)(ULONG_PTR)IC_HandleRef) != NULL) IC_HandleRef++;
378 whic->hic = (HIC)(ULONG_PTR)IC_HandleRef++;
379 whic->next = MSVIDEO_FirstHic;
380 MSVIDEO_FirstHic = whic;
382 TRACE("=> %p\n", whic->hic);
383 return whic->hic;
386 /***********************************************************************
387 * ICOpenFunction [MSVFW32.@]
389 HIC VFWAPI ICOpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode, FARPROC lpfnHandler)
391 ICOPEN icopen;
392 WINE_HIC* whic;
394 TRACE("(%s,%s,%d,%p)\n",
395 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), wMode, lpfnHandler);
397 icopen.dwSize = sizeof(ICOPEN);
398 icopen.fccType = fccType;
399 icopen.fccHandler = fccHandler;
400 icopen.dwVersion = ICVERSION;
401 icopen.dwFlags = wMode;
402 icopen.dwError = 0;
403 icopen.pV1Reserved = NULL;
404 icopen.pV2Reserved = NULL;
405 icopen.dnDevNode = 0; /* FIXME */
407 whic = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC));
408 if (!whic) return 0;
410 whic->driverproc = lpfnHandler;
411 while (MSVIDEO_GetHicPtr((HIC)(ULONG_PTR)IC_HandleRef) != NULL) IC_HandleRef++;
412 whic->hic = (HIC)(ULONG_PTR)IC_HandleRef++;
413 whic->next = MSVIDEO_FirstHic;
414 MSVIDEO_FirstHic = whic;
416 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
417 /* What if the function is used more than once? */
419 if (MSVIDEO_SendMessage(whic, DRV_LOAD, 0L, 0L) != DRV_SUCCESS)
421 WARN("DRV_LOAD failed for hic %p\n", whic->hic);
422 MSVIDEO_FirstHic = whic->next;
423 HeapFree(GetProcessHeap(), 0, whic);
424 return 0;
426 /* return value is not checked */
427 MSVIDEO_SendMessage(whic, DRV_ENABLE, 0L, 0L);
429 whic->driverId = (DWORD)MSVIDEO_SendMessage(whic, DRV_OPEN, 0, (DWORD_PTR)&icopen);
430 /* FIXME: What should we put here? */
431 whic->hdrv = NULL;
433 if (whic->driverId == 0)
435 WARN("DRV_OPEN failed for hic %p\n", whic->hic);
436 MSVIDEO_FirstHic = whic->next;
437 HeapFree(GetProcessHeap(), 0, whic);
438 return 0;
441 TRACE("=> %p\n", whic->hic);
442 return whic->hic;
445 /***********************************************************************
446 * ICGetInfo [MSVFW32.@]
448 LRESULT VFWAPI ICGetInfo(HIC hic, ICINFO *picinfo, DWORD cb)
450 LRESULT ret;
451 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
453 TRACE("(%p,%p,%d)\n", hic, picinfo, cb);
455 whic = MSVIDEO_GetHicPtr(hic);
456 if (!whic) return ICERR_BADHANDLE;
457 if (!picinfo) return MMSYSERR_INVALPARAM;
459 /* (WS) The field szDriver should be initialized because the driver
460 * is not obliged and often will not do it. Some applications, like
461 * VirtualDub, rely on this field and will occasionally crash if it
462 * goes uninitialized.
464 if (cb >= sizeof(ICINFO)) picinfo->szDriver[0] = '\0';
466 ret = ICSendMessage(hic, ICM_GETINFO, (DWORD_PTR)picinfo, cb);
468 /* (WS) When szDriver was not supplied by the driver itself, apparently
469 * Windows will set its value equal to the driver file name. This can
470 * be obtained from the registry as we do here.
472 if (cb >= sizeof(ICINFO) && picinfo->szDriver[0] == 0)
474 ICINFO ii;
476 memset(&ii, 0, sizeof(ii));
477 ii.dwSize = sizeof(ii);
478 ICInfo(picinfo->fccType, picinfo->fccHandler, &ii);
479 lstrcpyW(picinfo->szDriver, ii.szDriver);
482 TRACE(" -> 0x%08lx\n", ret);
483 return ret;
486 typedef struct {
487 DWORD fccType;
488 DWORD fccHandler;
489 LPBITMAPINFOHEADER lpbiIn;
490 LPBITMAPINFOHEADER lpbiOut;
491 WORD wMode;
492 DWORD querymsg;
493 HIC hic;
494 } driver_info_t;
496 static HIC try_driver(driver_info_t *info)
498 HIC hic;
500 if ((hic = ICOpen(info->fccType, info->fccHandler, info->wMode)))
502 if (!ICSendMessage(hic, info->querymsg, (DWORD_PTR)info->lpbiIn, (DWORD_PTR)info->lpbiOut))
503 return hic;
504 ICClose(hic);
506 return 0;
509 static BOOL ICLocate_enum_handler(const char *drv, unsigned int nr, void *param)
511 driver_info_t *info = param;
512 info->fccHandler = mmioStringToFOURCCA(drv + 5, 0);
513 info->hic = try_driver(info);
514 return info->hic != 0;
517 /***********************************************************************
518 * ICLocate [MSVFW32.@]
520 HIC VFWAPI ICLocate(DWORD fccType, DWORD fccHandler, LPBITMAPINFOHEADER lpbiIn,
521 LPBITMAPINFOHEADER lpbiOut, WORD wMode)
523 driver_info_t info;
525 TRACE("(%s,%s,%p,%p,0x%04x)\n",
526 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), lpbiIn, lpbiOut, wMode);
528 info.fccType = fccType;
529 info.fccHandler = fccHandler;
530 info.lpbiIn = lpbiIn;
531 info.lpbiOut = lpbiOut;
532 info.wMode = wMode;
534 switch (wMode)
536 case ICMODE_FASTCOMPRESS:
537 case ICMODE_COMPRESS:
538 info.querymsg = ICM_COMPRESS_QUERY;
539 break;
540 case ICMODE_FASTDECOMPRESS:
541 case ICMODE_DECOMPRESS:
542 info.querymsg = ICM_DECOMPRESS_QUERY;
543 break;
544 case ICMODE_DRAW:
545 info.querymsg = ICM_DRAW_QUERY;
546 break;
547 default:
548 WARN("Unknown mode (%d)\n", wMode);
549 return 0;
552 /* Easy case: handler/type match, we just fire a query and return */
553 info.hic = try_driver(&info);
554 /* If it didn't work, try each driver in turn. 32 bit codecs only. */
555 /* FIXME: Move this to an init routine? */
556 if (!info.hic) enum_drivers(fccType, ICLocate_enum_handler, &info);
558 if (info.hic)
560 TRACE("=> %p\n", info.hic);
561 return info.hic;
564 if (fccType == streamtypeVIDEO)
565 return ICLocate(ICTYPE_VIDEO, fccHandler, lpbiIn, lpbiOut, wMode);
567 WARN("(%s,%s,%p,%p,0x%04x) not found!\n",
568 wine_dbgstr_fcc(fccType), wine_dbgstr_fcc(fccHandler), lpbiIn, lpbiOut, wMode);
569 return 0;
572 /***********************************************************************
573 * ICGetDisplayFormat [MSVFW32.@]
575 HIC VFWAPI ICGetDisplayFormat(
576 HIC hic,LPBITMAPINFOHEADER lpbiIn,LPBITMAPINFOHEADER lpbiOut,
577 INT depth,INT dx,INT dy)
579 HIC tmphic = hic;
581 TRACE("(%p,%p,%p,%d,%d,%d)!\n",hic,lpbiIn,lpbiOut,depth,dx,dy);
583 if (!tmphic) {
584 tmphic=ICLocate(ICTYPE_VIDEO,0,lpbiIn,NULL,ICMODE_DECOMPRESS);
585 if (!tmphic)
586 return tmphic;
588 if ((dy == lpbiIn->biHeight) && (dx == lpbiIn->biWidth))
589 dy = dx = 0; /* no resize needed */
591 /* Can we decompress it ? */
592 if (ICDecompressQuery(tmphic,lpbiIn,NULL) != 0)
593 goto errout; /* no, sorry */
595 ICSendMessage(tmphic, ICM_DECOMPRESS_GET_FORMAT, (DWORD_PTR)lpbiIn, (DWORD_PTR)lpbiOut);
597 if (lpbiOut->biCompression != 0) {
598 FIXME("Ooch, how come decompressor outputs compressed data (%d)??\n",
599 lpbiOut->biCompression);
601 if (lpbiOut->biSize < sizeof(*lpbiOut)) {
602 FIXME("Ooch, size of output BIH is too small (%d)\n",
603 lpbiOut->biSize);
604 lpbiOut->biSize = sizeof(*lpbiOut);
606 if (!depth) {
607 HDC hdc;
609 hdc = GetDC(0);
610 depth = GetDeviceCaps(hdc,BITSPIXEL)*GetDeviceCaps(hdc,PLANES);
611 ReleaseDC(0,hdc);
612 if (depth==15) depth = 16;
613 if (depth<8) depth = 8;
615 if (lpbiIn->biBitCount == 8)
616 depth = 8;
618 TRACE("=> %p\n", tmphic);
619 return tmphic;
620 errout:
621 if (hic!=tmphic)
622 ICClose(tmphic);
624 TRACE("=> 0\n");
625 return 0;
628 /***********************************************************************
629 * ICCompress [MSVFW32.@]
631 DWORD VFWAPIV
632 ICCompress(
633 HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiOutput,LPVOID lpData,
634 LPBITMAPINFOHEADER lpbiInput,LPVOID lpBits,LPDWORD lpckid,
635 LPDWORD lpdwFlags,LONG lFrameNum,DWORD dwFrameSize,DWORD dwQuality,
636 LPBITMAPINFOHEADER lpbiPrev,LPVOID lpPrev)
638 ICCOMPRESS iccmp;
640 TRACE("(%p,%d,%p,%p,%p,%p,...)\n",hic,dwFlags,lpbiOutput,lpData,lpbiInput,lpBits);
642 iccmp.dwFlags = dwFlags;
644 iccmp.lpbiOutput = lpbiOutput;
645 iccmp.lpOutput = lpData;
646 iccmp.lpbiInput = lpbiInput;
647 iccmp.lpInput = lpBits;
649 iccmp.lpckid = lpckid;
650 iccmp.lpdwFlags = lpdwFlags;
651 iccmp.lFrameNum = lFrameNum;
652 iccmp.dwFrameSize = dwFrameSize;
653 iccmp.dwQuality = dwQuality;
654 iccmp.lpbiPrev = lpbiPrev;
655 iccmp.lpPrev = lpPrev;
656 return ICSendMessage(hic,ICM_COMPRESS,(DWORD_PTR)&iccmp,sizeof(iccmp));
659 /***********************************************************************
660 * ICDecompress [MSVFW32.@]
662 DWORD VFWAPIV ICDecompress(HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiFormat,
663 LPVOID lpData,LPBITMAPINFOHEADER lpbi,LPVOID lpBits)
665 ICDECOMPRESS icd;
666 DWORD ret;
668 TRACE("(%p,%d,%p,%p,%p,%p)\n",hic,dwFlags,lpbiFormat,lpData,lpbi,lpBits);
670 icd.dwFlags = dwFlags;
671 icd.lpbiInput = lpbiFormat;
672 icd.lpInput = lpData;
674 icd.lpbiOutput = lpbi;
675 icd.lpOutput = lpBits;
676 icd.ckid = 0;
677 ret = ICSendMessage(hic,ICM_DECOMPRESS,(DWORD_PTR)&icd,sizeof(ICDECOMPRESS));
679 TRACE("-> %d\n",ret);
681 return ret;
685 struct choose_compressor
687 UINT flags;
688 LPCSTR title;
689 COMPVARS cv;
692 struct codec_info
694 HIC hic;
695 ICINFO icinfo;
698 static BOOL enum_compressors(HWND list, COMPVARS *pcv, BOOL enum_all)
700 UINT id, total = 0;
701 ICINFO icinfo;
703 id = 0;
705 while (ICInfo(pcv->fccType, id, &icinfo))
707 struct codec_info *ic;
708 DWORD idx;
709 HIC hic;
711 id++;
713 hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_COMPRESS);
715 if (hic)
717 /* for unknown reason fccHandler reported by the driver
718 * doesn't always work, use the one returned by ICInfo instead.
720 DWORD fccHandler = icinfo.fccHandler;
722 if (!enum_all && pcv->lpbiIn)
724 if (ICCompressQuery(hic, pcv->lpbiIn, NULL) != ICERR_OK)
726 TRACE("fccHandler %s doesn't support input DIB format %d\n",
727 wine_dbgstr_fcc(icinfo.fccHandler), pcv->lpbiIn->bmiHeader.biCompression);
728 ICClose(hic);
729 continue;
733 ICGetInfo(hic, &icinfo, sizeof(icinfo));
734 icinfo.fccHandler = fccHandler;
736 idx = SendMessageW(list, CB_ADDSTRING, 0, (LPARAM)icinfo.szDescription);
738 ic = HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info));
739 ic->icinfo = icinfo;
740 ic->hic = hic;
741 SendMessageW(list, CB_SETITEMDATA, idx, (LPARAM)ic);
743 total++;
746 return total != 0;
749 static INT_PTR CALLBACK icm_choose_compressor_dlgproc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
751 switch (msg)
753 case WM_INITDIALOG:
755 struct codec_info *ic;
756 WCHAR buf[128];
757 struct choose_compressor *choose_comp = (struct choose_compressor *)lparam;
759 SetWindowLongPtrW(hdlg, DWLP_USER, lparam);
761 /* FIXME */
762 choose_comp->flags &= ~(ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME);
764 if (choose_comp->title)
765 SetWindowTextA(hdlg, choose_comp->title);
767 if (!(choose_comp->flags & ICMF_CHOOSE_DATARATE))
769 ShowWindow(GetDlgItem(hdlg, IDC_DATARATE_CHECKBOX), SW_HIDE);
770 ShowWindow(GetDlgItem(hdlg, IDC_DATARATE), SW_HIDE);
771 ShowWindow(GetDlgItem(hdlg, IDC_DATARATE_KB), SW_HIDE);
774 if (!(choose_comp->flags & ICMF_CHOOSE_KEYFRAME))
776 ShowWindow(GetDlgItem(hdlg, IDC_KEYFRAME_CHECKBOX), SW_HIDE);
777 ShowWindow(GetDlgItem(hdlg, IDC_KEYFRAME), SW_HIDE);
778 ShowWindow(GetDlgItem(hdlg, IDC_KEYFRAME_FRAMES), SW_HIDE);
781 /* FIXME */
782 EnableWindow(GetDlgItem(hdlg, IDC_QUALITY_SCROLL), FALSE);
783 EnableWindow(GetDlgItem(hdlg, IDC_QUALITY_TXT), FALSE);
785 /*if (!(choose_comp->flags & ICMF_CHOOSE_PREVIEW))
786 ShowWindow(GetDlgItem(hdlg, IDC_PREVIEW), SW_HIDE);*/
788 LoadStringW(MSVFW32_hModule, IDS_FULLFRAMES, buf, 128);
789 SendDlgItemMessageW(hdlg, IDC_COMP_LIST, CB_ADDSTRING, 0, (LPARAM)buf);
791 ic = HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info));
792 ic->icinfo.fccType = streamtypeVIDEO;
793 ic->icinfo.fccHandler = comptypeDIB;
794 ic->hic = 0;
795 SendDlgItemMessageW(hdlg, IDC_COMP_LIST, CB_SETITEMDATA, 0, (LPARAM)ic);
797 enum_compressors(GetDlgItem(hdlg, IDC_COMP_LIST), &choose_comp->cv, choose_comp->flags & ICMF_CHOOSE_ALLCOMPRESSORS);
799 SendDlgItemMessageW(hdlg, IDC_COMP_LIST, CB_SETCURSEL, 0, 0);
800 SetFocus(GetDlgItem(hdlg, IDC_COMP_LIST));
802 SetWindowLongPtrW(hdlg, DWLP_USER, (ULONG_PTR)choose_comp);
803 break;
806 case WM_COMMAND:
807 switch (LOWORD(wparam))
809 case IDC_COMP_LIST:
811 INT cur_sel;
812 struct codec_info *ic;
813 BOOL can_configure = FALSE, can_about = FALSE;
814 struct choose_compressor *choose_comp;
816 if (HIWORD(wparam) != CBN_SELCHANGE && HIWORD(wparam) != CBN_SETFOCUS)
817 break;
819 choose_comp = (struct choose_compressor *)GetWindowLongPtrW(hdlg, DWLP_USER);
821 cur_sel = SendMessageW((HWND)lparam, CB_GETCURSEL, 0, 0);
823 ic = (struct codec_info *)SendMessageW((HWND)lparam, CB_GETITEMDATA, cur_sel, 0);
824 if (ic && ic->hic)
826 if (ICQueryConfigure(ic->hic) == DRVCNF_OK)
827 can_configure = TRUE;
828 if (ICQueryAbout(ic->hic) == DRVCNF_OK)
829 can_about = TRUE;
831 EnableWindow(GetDlgItem(hdlg, IDC_CONFIGURE), can_configure);
832 EnableWindow(GetDlgItem(hdlg, IDC_ABOUT), can_about);
834 if (choose_comp->flags & ICMF_CHOOSE_DATARATE)
836 /* FIXME */
838 if (choose_comp->flags & ICMF_CHOOSE_KEYFRAME)
840 /* FIXME */
843 break;
846 case IDC_CONFIGURE:
847 case IDC_ABOUT:
849 HWND list = GetDlgItem(hdlg, IDC_COMP_LIST);
850 INT cur_sel;
851 struct codec_info *ic;
853 if (HIWORD(wparam) != BN_CLICKED)
854 break;
856 cur_sel = SendMessageW(list, CB_GETCURSEL, 0, 0);
858 ic = (struct codec_info *)SendMessageW(list, CB_GETITEMDATA, cur_sel, 0);
859 if (ic && ic->hic)
861 if (LOWORD(wparam) == IDC_CONFIGURE)
862 ICConfigure(ic->hic, hdlg);
863 else
864 ICAbout(ic->hic, hdlg);
867 break;
870 case IDOK:
872 HWND list = GetDlgItem(hdlg, IDC_COMP_LIST);
873 INT cur_sel;
874 struct codec_info *ic;
876 if (HIWORD(wparam) != BN_CLICKED)
877 break;
879 cur_sel = SendMessageW(list, CB_GETCURSEL, 0, 0);
880 ic = (struct codec_info *)SendMessageW(list, CB_GETITEMDATA, cur_sel, 0);
881 if (ic)
883 struct choose_compressor *choose_comp = (struct choose_compressor *)GetWindowLongPtrW(hdlg, DWLP_USER);
885 choose_comp->cv.hic = ic->hic;
886 choose_comp->cv.fccType = ic->icinfo.fccType;
887 choose_comp->cv.fccHandler = ic->icinfo.fccHandler;
888 /* FIXME: fill everything else */
890 /* prevent closing the codec handle below */
891 ic->hic = 0;
894 /* fall through */
895 case IDCANCEL:
897 HWND list = GetDlgItem(hdlg, IDC_COMP_LIST);
898 INT idx = 0;
900 if (HIWORD(wparam) != BN_CLICKED)
901 break;
903 while (1)
905 struct codec_info *ic;
907 ic = (struct codec_info *)SendMessageW(list, CB_GETITEMDATA, idx++, 0);
909 if (!ic || (LONG_PTR)ic == CB_ERR) break;
911 if (ic->hic) ICClose(ic->hic);
912 HeapFree(GetProcessHeap(), 0, ic);
915 EndDialog(hdlg, LOWORD(wparam) == IDOK);
916 break;
919 default:
920 break;
922 break;
924 default:
925 break;
928 return FALSE;
931 /***********************************************************************
932 * ICCompressorChoose [MSVFW32.@]
934 BOOL VFWAPI ICCompressorChoose(HWND hwnd, UINT uiFlags, LPVOID pvIn,
935 LPVOID lpData, PCOMPVARS pc, LPSTR lpszTitle)
937 struct choose_compressor choose_comp;
938 BOOL ret;
940 TRACE("(%p,%08x,%p,%p,%p,%s)\n", hwnd, uiFlags, pvIn, lpData, pc, lpszTitle);
942 if (!pc || pc->cbSize != sizeof(COMPVARS))
943 return FALSE;
945 if (!(pc->dwFlags & ICMF_COMPVARS_VALID))
947 pc->dwFlags = 0;
948 pc->fccType = pc->fccHandler = 0;
949 pc->hic = NULL;
950 pc->lpbiIn = NULL;
951 pc->lpbiOut = NULL;
952 pc->lpBitsOut = pc->lpBitsPrev = pc->lpState = NULL;
953 pc->lQ = ICQUALITY_DEFAULT;
954 pc->lKey = -1;
955 pc->lDataRate = 300; /* kB */
956 pc->lpState = NULL;
957 pc->cbState = 0;
959 if (pc->fccType == 0)
960 pc->fccType = ICTYPE_VIDEO;
962 choose_comp.cv = *pc;
963 choose_comp.flags = uiFlags;
964 choose_comp.title = lpszTitle;
966 ret = DialogBoxParamW(MSVFW32_hModule, MAKEINTRESOURCEW(ICM_CHOOSE_COMPRESSOR), hwnd,
967 icm_choose_compressor_dlgproc, (LPARAM)&choose_comp);
969 if (ret)
971 *pc = choose_comp.cv;
972 pc->dwFlags |= ICMF_COMPVARS_VALID;
975 return ret;
979 /***********************************************************************
980 * ICCompressorFree [MSVFW32.@]
982 void VFWAPI ICCompressorFree(PCOMPVARS pc)
984 TRACE("(%p)\n",pc);
986 if (pc != NULL && pc->cbSize == sizeof(COMPVARS)) {
987 if (pc->hic != NULL) {
988 ICClose(pc->hic);
989 pc->hic = NULL;
991 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
992 pc->lpbiIn = NULL;
993 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
994 pc->lpBitsOut = NULL;
995 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
996 pc->lpBitsPrev = NULL;
997 HeapFree(GetProcessHeap(), 0, pc->lpState);
998 pc->lpState = NULL;
999 pc->dwFlags = 0;
1004 /******************************************************************
1005 * MSVIDEO_SendMessage
1009 LRESULT MSVIDEO_SendMessage(WINE_HIC* whic, UINT msg, DWORD_PTR lParam1, DWORD_PTR lParam2)
1011 LRESULT ret;
1013 #define XX(x) case x: TRACE("(%p,"#x",0x%08lx,0x%08lx)\n",whic,lParam1,lParam2); break
1015 switch (msg) {
1016 /* DRV_* */
1017 XX(DRV_LOAD);
1018 XX(DRV_ENABLE);
1019 XX(DRV_OPEN);
1020 XX(DRV_CLOSE);
1021 XX(DRV_DISABLE);
1022 XX(DRV_FREE);
1023 /* ICM_RESERVED+X */
1024 XX(ICM_ABOUT);
1025 XX(ICM_CONFIGURE);
1026 XX(ICM_GET);
1027 XX(ICM_GETINFO);
1028 XX(ICM_GETDEFAULTQUALITY);
1029 XX(ICM_GETQUALITY);
1030 XX(ICM_GETSTATE);
1031 XX(ICM_SETQUALITY);
1032 XX(ICM_SET);
1033 XX(ICM_SETSTATE);
1034 /* ICM_USER+X */
1035 XX(ICM_COMPRESS_FRAMES_INFO);
1036 XX(ICM_COMPRESS_GET_FORMAT);
1037 XX(ICM_COMPRESS_GET_SIZE);
1038 XX(ICM_COMPRESS_QUERY);
1039 XX(ICM_COMPRESS_BEGIN);
1040 XX(ICM_COMPRESS);
1041 XX(ICM_COMPRESS_END);
1042 XX(ICM_DECOMPRESS_GET_FORMAT);
1043 XX(ICM_DECOMPRESS_QUERY);
1044 XX(ICM_DECOMPRESS_BEGIN);
1045 XX(ICM_DECOMPRESS);
1046 XX(ICM_DECOMPRESS_END);
1047 XX(ICM_DECOMPRESS_SET_PALETTE);
1048 XX(ICM_DECOMPRESS_GET_PALETTE);
1049 XX(ICM_DRAW_QUERY);
1050 XX(ICM_DRAW_BEGIN);
1051 XX(ICM_DRAW_GET_PALETTE);
1052 XX(ICM_DRAW_START);
1053 XX(ICM_DRAW_STOP);
1054 XX(ICM_DRAW_END);
1055 XX(ICM_DRAW_GETTIME);
1056 XX(ICM_DRAW);
1057 XX(ICM_DRAW_WINDOW);
1058 XX(ICM_DRAW_SETTIME);
1059 XX(ICM_DRAW_REALIZE);
1060 XX(ICM_DRAW_FLUSH);
1061 XX(ICM_DRAW_RENDERBUFFER);
1062 XX(ICM_DRAW_START_PLAY);
1063 XX(ICM_DRAW_STOP_PLAY);
1064 XX(ICM_DRAW_SUGGESTFORMAT);
1065 XX(ICM_DRAW_CHANGEPALETTE);
1066 XX(ICM_GETBUFFERSWANTED);
1067 XX(ICM_GETDEFAULTKEYFRAMERATE);
1068 XX(ICM_DECOMPRESSEX_BEGIN);
1069 XX(ICM_DECOMPRESSEX_QUERY);
1070 XX(ICM_DECOMPRESSEX);
1071 XX(ICM_DECOMPRESSEX_END);
1072 XX(ICM_SET_STATUS_PROC);
1073 default:
1074 FIXME("(%p,0x%08x,0x%08lx,0x%08lx) unknown message\n",whic,msg,lParam1,lParam2);
1077 #undef XX
1079 if (whic->driverproc) {
1080 /* dwDriverId parameter is the value returned by the DRV_OPEN */
1081 ret = whic->driverproc(whic->driverId, whic->hdrv, msg, lParam1, lParam2);
1082 } else {
1083 ret = SendDriverMessage(whic->hdrv, msg, lParam1, lParam2);
1086 TRACE(" -> 0x%08lx\n", ret);
1087 return ret;
1090 /***********************************************************************
1091 * ICSendMessage [MSVFW32.@]
1093 LRESULT VFWAPI ICSendMessage(HIC hic, UINT msg, DWORD_PTR lParam1, DWORD_PTR lParam2)
1095 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
1097 if (!whic) return ICERR_BADHANDLE;
1098 return MSVIDEO_SendMessage(whic, msg, lParam1, lParam2);
1101 /***********************************************************************
1102 * ICDrawBegin [MSVFW32.@]
1104 DWORD VFWAPIV ICDrawBegin(
1105 HIC hic, /* [in] */
1106 DWORD dwFlags, /* [in] flags */
1107 HPALETTE hpal, /* [in] palette to draw with */
1108 HWND hwnd, /* [in] window to draw to */
1109 HDC hdc, /* [in] HDC to draw to */
1110 INT xDst, /* [in] destination rectangle */
1111 INT yDst, /* [in] */
1112 INT dxDst, /* [in] */
1113 INT dyDst, /* [in] */
1114 LPBITMAPINFOHEADER lpbi, /* [in] format of frame to draw */
1115 INT xSrc, /* [in] source rectangle */
1116 INT ySrc, /* [in] */
1117 INT dxSrc, /* [in] */
1118 INT dySrc, /* [in] */
1119 DWORD dwRate, /* [in] frames/second = (dwRate/dwScale) */
1120 DWORD dwScale) /* [in] */
1123 ICDRAWBEGIN icdb;
1125 TRACE("(%p,%d,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%d,%d)\n",
1126 hic, dwFlags, hpal, hwnd, hdc, xDst, yDst, dxDst, dyDst,
1127 lpbi, xSrc, ySrc, dxSrc, dySrc, dwRate, dwScale);
1129 icdb.dwFlags = dwFlags;
1130 icdb.hpal = hpal;
1131 icdb.hwnd = hwnd;
1132 icdb.hdc = hdc;
1133 icdb.xDst = xDst;
1134 icdb.yDst = yDst;
1135 icdb.dxDst = dxDst;
1136 icdb.dyDst = dyDst;
1137 icdb.lpbi = lpbi;
1138 icdb.xSrc = xSrc;
1139 icdb.ySrc = ySrc;
1140 icdb.dxSrc = dxSrc;
1141 icdb.dySrc = dySrc;
1142 icdb.dwRate = dwRate;
1143 icdb.dwScale = dwScale;
1144 return ICSendMessage(hic,ICM_DRAW_BEGIN,(DWORD_PTR)&icdb,sizeof(icdb));
1147 /***********************************************************************
1148 * ICDraw [MSVFW32.@]
1150 DWORD VFWAPIV ICDraw(HIC hic, DWORD dwFlags, LPVOID lpFormat, LPVOID lpData, DWORD cbData, LONG lTime) {
1151 ICDRAW icd;
1153 TRACE("(%p,%d,%p,%p,%d,%d)\n",hic,dwFlags,lpFormat,lpData,cbData,lTime);
1155 icd.dwFlags = dwFlags;
1156 icd.lpFormat = lpFormat;
1157 icd.lpData = lpData;
1158 icd.cbData = cbData;
1159 icd.lTime = lTime;
1161 return ICSendMessage(hic,ICM_DRAW,(DWORD_PTR)&icd,sizeof(icd));
1164 /***********************************************************************
1165 * ICClose [MSVFW32.@]
1167 LRESULT WINAPI ICClose(HIC hic)
1169 WINE_HIC* whic = MSVIDEO_GetHicPtr(hic);
1170 WINE_HIC** p;
1172 TRACE("(%p)\n",hic);
1174 if (!whic) return ICERR_BADHANDLE;
1176 if (whic->driverproc)
1178 MSVIDEO_SendMessage(whic, DRV_CLOSE, 0, 0);
1179 MSVIDEO_SendMessage(whic, DRV_DISABLE, 0, 0);
1180 MSVIDEO_SendMessage(whic, DRV_FREE, 0, 0);
1182 else
1184 CloseDriver(whic->hdrv, 0, 0);
1187 /* remove whic from list */
1188 for (p = &MSVIDEO_FirstHic; *p != NULL; p = &((*p)->next))
1190 if ((*p) == whic)
1192 *p = whic->next;
1193 break;
1197 HeapFree(GetProcessHeap(), 0, whic);
1198 return 0;
1203 /***********************************************************************
1204 * ICImageCompress [MSVFW32.@]
1206 HANDLE VFWAPI ICImageCompress(
1207 HIC hic, UINT uiFlags,
1208 LPBITMAPINFO lpbiIn, LPVOID lpBits,
1209 LPBITMAPINFO lpbiOut, LONG lQuality,
1210 LONG* plSize)
1212 FIXME("(%p,%08x,%p,%p,%p,%d,%p)\n",
1213 hic, uiFlags, lpbiIn, lpBits, lpbiOut, lQuality, plSize);
1215 return NULL;
1218 /***********************************************************************
1219 * ICImageDecompress [MSVFW32.@]
1222 HANDLE VFWAPI ICImageDecompress(
1223 HIC hic, UINT uiFlags, LPBITMAPINFO lpbiIn,
1224 LPVOID lpBits, LPBITMAPINFO lpbiOut)
1226 HGLOBAL hMem = NULL;
1227 BYTE* pMem = NULL;
1228 BOOL bReleaseIC = FALSE;
1229 BYTE* pHdr = NULL;
1230 ULONG cbHdr = 0;
1231 BOOL bSucceeded = FALSE;
1232 BOOL bInDecompress = FALSE;
1233 DWORD biSizeImage;
1235 TRACE("(%p,%08x,%p,%p,%p)\n",
1236 hic, uiFlags, lpbiIn, lpBits, lpbiOut);
1238 if ( hic == NULL )
1240 hic = ICDecompressOpen( ICTYPE_VIDEO, 0, &lpbiIn->bmiHeader, (lpbiOut != NULL) ? &lpbiOut->bmiHeader : NULL );
1241 if ( hic == NULL )
1243 WARN("no handler\n" );
1244 goto err;
1246 bReleaseIC = TRUE;
1248 if ( uiFlags != 0 )
1250 FIXME( "unknown flag %08x\n", uiFlags );
1251 goto err;
1253 if ( lpbiIn == NULL || lpBits == NULL )
1255 WARN("invalid argument\n");
1256 goto err;
1259 if ( lpbiOut != NULL )
1261 if ( lpbiOut->bmiHeader.biSize != sizeof(BITMAPINFOHEADER) )
1262 goto err;
1263 cbHdr = sizeof(BITMAPINFOHEADER);
1264 if ( lpbiOut->bmiHeader.biCompression == 3 )
1265 cbHdr += sizeof(DWORD)*3;
1266 else
1267 if ( lpbiOut->bmiHeader.biBitCount <= 8 )
1269 if ( lpbiOut->bmiHeader.biClrUsed == 0 )
1270 cbHdr += sizeof(RGBQUAD) * (1<<lpbiOut->bmiHeader.biBitCount);
1271 else
1272 cbHdr += sizeof(RGBQUAD) * lpbiOut->bmiHeader.biClrUsed;
1275 else
1277 TRACE( "get format\n" );
1279 cbHdr = ICDecompressGetFormatSize(hic,lpbiIn);
1280 if ( cbHdr < sizeof(BITMAPINFOHEADER) )
1281 goto err;
1282 pHdr = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,cbHdr+sizeof(RGBQUAD)*256);
1283 if ( pHdr == NULL )
1284 goto err;
1285 if ( ICDecompressGetFormat( hic, lpbiIn, pHdr ) != ICERR_OK )
1286 goto err;
1287 lpbiOut = (BITMAPINFO*)pHdr;
1288 if ( lpbiOut->bmiHeader.biBitCount <= 8 &&
1289 ICDecompressGetPalette( hic, lpbiIn, lpbiOut ) != ICERR_OK &&
1290 lpbiIn->bmiHeader.biBitCount == lpbiOut->bmiHeader.biBitCount )
1292 if ( lpbiIn->bmiHeader.biClrUsed == 0 )
1293 memcpy( lpbiOut->bmiColors, lpbiIn->bmiColors, sizeof(RGBQUAD)*(1<<lpbiOut->bmiHeader.biBitCount) );
1294 else
1295 memcpy( lpbiOut->bmiColors, lpbiIn->bmiColors, sizeof(RGBQUAD)*lpbiIn->bmiHeader.biClrUsed );
1297 if ( lpbiOut->bmiHeader.biBitCount <= 8 &&
1298 lpbiOut->bmiHeader.biClrUsed == 0 )
1299 lpbiOut->bmiHeader.biClrUsed = 1<<lpbiOut->bmiHeader.biBitCount;
1301 lpbiOut->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1302 cbHdr = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*lpbiOut->bmiHeader.biClrUsed;
1305 biSizeImage = lpbiOut->bmiHeader.biSizeImage;
1306 if ( biSizeImage == 0 )
1307 biSizeImage = ((((lpbiOut->bmiHeader.biWidth * lpbiOut->bmiHeader.biBitCount + 7) >> 3) + 3) & (~3)) * abs(lpbiOut->bmiHeader.biHeight);
1309 TRACE( "call ICDecompressBegin\n" );
1311 if ( ICDecompressBegin( hic, lpbiIn, lpbiOut ) != ICERR_OK )
1312 goto err;
1313 bInDecompress = TRUE;
1315 TRACE( "cbHdr %d, biSizeImage %d\n", cbHdr, biSizeImage );
1317 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_ZEROINIT, cbHdr + biSizeImage );
1318 if ( hMem == NULL )
1320 WARN( "out of memory\n" );
1321 goto err;
1323 pMem = GlobalLock( hMem );
1324 if ( pMem == NULL )
1325 goto err;
1326 memcpy( pMem, lpbiOut, cbHdr );
1328 TRACE( "call ICDecompress\n" );
1329 if ( ICDecompress( hic, 0, &lpbiIn->bmiHeader, lpBits, &lpbiOut->bmiHeader, pMem+cbHdr ) != ICERR_OK )
1330 goto err;
1332 bSucceeded = TRUE;
1333 err:
1334 if ( bInDecompress )
1335 ICDecompressEnd( hic );
1336 if ( bReleaseIC )
1337 ICClose(hic);
1338 HeapFree(GetProcessHeap(),0,pHdr);
1339 if ( pMem != NULL )
1340 GlobalUnlock( hMem );
1341 if ( !bSucceeded && hMem != NULL )
1343 GlobalFree(hMem); hMem = NULL;
1346 return hMem;
1349 /***********************************************************************
1350 * ICSeqCompressFrame [MSVFW32.@]
1352 LPVOID VFWAPI ICSeqCompressFrame(PCOMPVARS pc, UINT uiFlags, LPVOID lpBits, BOOL *pfKey, LONG *plSize)
1354 ICCOMPRESS* icComp = pc->lpState;
1355 DWORD ret;
1356 TRACE("(%p, 0x%08x, %p, %p, %p)\n", pc, uiFlags, lpBits, pfKey, plSize);
1358 if (pc->cbState != sizeof(ICCOMPRESS))
1360 ERR("Invalid cbState %i\n", pc->cbState);
1361 return NULL;
1364 if (!pc->lKeyCount++)
1365 icComp->dwFlags = ICCOMPRESS_KEYFRAME;
1366 else
1368 if (pc->lKey && pc->lKeyCount == (pc->lKey - 1))
1369 /* No key frames if pc->lKey == 0 */
1370 pc->lKeyCount = 0;
1371 icComp->dwFlags = 0;
1374 icComp->lpInput = lpBits;
1375 icComp->lFrameNum = pc->lFrame++;
1376 icComp->lpOutput = pc->lpBitsOut;
1377 icComp->lpPrev = pc->lpBitsPrev;
1378 ret = ICSendMessage(pc->hic, ICM_COMPRESS, (DWORD_PTR)icComp, sizeof(icComp));
1380 if (icComp->dwFlags & AVIIF_KEYFRAME)
1382 pc->lKeyCount = 1;
1383 *pfKey = TRUE;
1384 TRACE("Key frame\n");
1386 else
1387 *pfKey = FALSE;
1389 *plSize = icComp->lpbiOutput->biSizeImage;
1390 TRACE(" -- 0x%08x\n", ret);
1391 if (ret == ICERR_OK)
1393 LPVOID oldprev, oldout;
1394 /* We shift Prev and Out, so we don't have to allocate and release memory */
1395 oldprev = pc->lpBitsPrev;
1396 oldout = pc->lpBitsOut;
1397 pc->lpBitsPrev = oldout;
1398 pc->lpBitsOut = oldprev;
1400 TRACE("returning: %p\n", icComp->lpOutput);
1401 return icComp->lpOutput;
1403 return NULL;
1406 /***********************************************************************
1407 * ICSeqCompressFrameEnd [MSVFW32.@]
1409 void VFWAPI ICSeqCompressFrameEnd(PCOMPVARS pc)
1411 DWORD ret;
1412 TRACE("(%p)\n", pc);
1413 ret = ICSendMessage(pc->hic, ICM_COMPRESS_END, 0, 0);
1414 TRACE(" -- %x\n", ret);
1415 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1416 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1417 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
1418 HeapFree(GetProcessHeap(), 0, pc->lpState);
1419 pc->lpbiIn = pc->lpBitsPrev = pc->lpBitsOut = pc->lpState = NULL;
1422 /***********************************************************************
1423 * ICSeqCompressFrameStart [MSVFW32.@]
1425 BOOL VFWAPI ICSeqCompressFrameStart(PCOMPVARS pc, LPBITMAPINFO lpbiIn)
1427 /* I'm ignoring bmiColors as I don't know what to do with it,
1428 * it doesn't appear to be used though
1430 DWORD ret;
1431 pc->lpbiIn = HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO));
1432 if (!pc->lpbiIn)
1433 return FALSE;
1435 *pc->lpbiIn = *lpbiIn;
1436 pc->lpBitsPrev = HeapAlloc(GetProcessHeap(), 0, pc->lpbiIn->bmiHeader.biSizeImage);
1437 if (!pc->lpBitsPrev)
1439 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1440 return FALSE;
1443 pc->lpState = HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS));
1444 if (!pc->lpState)
1446 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1447 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1448 return FALSE;
1450 pc->cbState = sizeof(ICCOMPRESS);
1452 pc->lpBitsOut = HeapAlloc(GetProcessHeap(), 0, pc->lpbiOut->bmiHeader.biSizeImage);
1453 if (!pc->lpBitsOut)
1455 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1456 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1457 HeapFree(GetProcessHeap(), 0, pc->lpState);
1458 return FALSE;
1460 TRACE("Compvars:\n"
1461 "\tpc:\n"
1462 "\tsize: %i\n"
1463 "\tflags: %i\n"
1464 "\thic: %p\n"
1465 "\ttype: %x\n"
1466 "\thandler: %x\n"
1467 "\tin/out: %p/%p\n"
1468 "key/data/quality: %i/%i/%i\n",
1469 pc->cbSize, pc->dwFlags, pc->hic, pc->fccType, pc->fccHandler,
1470 pc->lpbiIn, pc->lpbiOut, pc->lKey, pc->lDataRate, pc->lQ);
1472 ret = ICSendMessage(pc->hic, ICM_COMPRESS_BEGIN, (DWORD_PTR)pc->lpbiIn, (DWORD_PTR)pc->lpbiOut);
1473 TRACE(" -- %x\n", ret);
1474 if (ret == ICERR_OK)
1476 ICCOMPRESS* icComp = pc->lpState;
1477 /* Initialise some variables */
1478 pc->lFrame = 0; pc->lKeyCount = 0;
1480 icComp->lpbiOutput = &pc->lpbiOut->bmiHeader;
1481 icComp->lpbiInput = &pc->lpbiIn->bmiHeader;
1482 icComp->lpckid = NULL;
1483 icComp->dwFrameSize = 0;
1484 icComp->dwQuality = pc->lQ;
1485 icComp->lpbiPrev = &pc->lpbiIn->bmiHeader;
1486 return TRUE;
1488 HeapFree(GetProcessHeap(), 0, pc->lpbiIn);
1489 HeapFree(GetProcessHeap(), 0, pc->lpBitsPrev);
1490 HeapFree(GetProcessHeap(), 0, pc->lpState);
1491 HeapFree(GetProcessHeap(), 0, pc->lpBitsOut);
1492 pc->lpBitsPrev = pc->lpbiIn = pc->lpState = pc->lpBitsOut = NULL;
1493 return FALSE;
1496 /***********************************************************************
1497 * GetFileNamePreview [MSVFW32.@]
1499 static BOOL GetFileNamePreview(LPVOID lpofn,BOOL bSave,BOOL bUnicode)
1501 CHAR szFunctionName[20];
1502 BOOL (*fnGetFileName)(LPVOID);
1503 HMODULE hComdlg32;
1504 BOOL ret;
1506 FIXME("(%p,%d,%d), semi-stub!\n",lpofn,bSave,bUnicode);
1508 lstrcpyA(szFunctionName, (bSave ? "GetSaveFileName" : "GetOpenFileName"));
1509 lstrcatA(szFunctionName, (bUnicode ? "W" : "A"));
1511 hComdlg32 = LoadLibraryA("COMDLG32.DLL");
1512 if (hComdlg32 == NULL)
1513 return FALSE;
1515 fnGetFileName = (LPVOID)GetProcAddress(hComdlg32, szFunctionName);
1516 if (fnGetFileName == NULL)
1517 return FALSE;
1519 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1520 ret = fnGetFileName(lpofn);
1522 FreeLibrary(hComdlg32);
1523 return ret;
1526 /***********************************************************************
1527 * GetOpenFileNamePreviewA [MSVFW32.@]
1529 BOOL WINAPI GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn)
1531 FIXME("(%p), semi-stub!\n", lpofn);
1533 return GetFileNamePreview(lpofn, FALSE, FALSE);
1536 /***********************************************************************
1537 * GetOpenFileNamePreviewW [MSVFW32.@]
1539 BOOL WINAPI GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn)
1541 FIXME("(%p), semi-stub!\n", lpofn);
1543 return GetFileNamePreview(lpofn, FALSE, TRUE);
1546 /***********************************************************************
1547 * GetSaveFileNamePreviewA [MSVFW32.@]
1549 BOOL WINAPI GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn)
1551 FIXME("(%p), semi-stub!\n", lpofn);
1553 return GetFileNamePreview(lpofn, TRUE, FALSE);
1556 /***********************************************************************
1557 * GetSaveFileNamePreviewW [MSVFW32.@]
1559 BOOL WINAPI GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn)
1561 FIXME("(%p), semi-stub!\n", lpofn);
1563 return GetFileNamePreview(lpofn, TRUE, TRUE);