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.
29 #include "msvideo_private.h"
36 /* Drivers32 settings */
37 #define HKLM_DRIVERS32 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32"
39 WINE_DEFAULT_DEBUG_CHANNEL(msvideo
);
41 /* This one is a macro in order to work for both ASCII and Unicode */
42 #define fourcc_to_string(str, fcc) do { \
43 (str)[0] = LOBYTE(LOWORD(fcc)); \
44 (str)[1] = HIBYTE(LOWORD(fcc)); \
45 (str)[2] = LOBYTE(HIWORD(fcc)); \
46 (str)[3] = HIBYTE(HIWORD(fcc)); \
49 static inline const char *wine_dbgstr_fcc( DWORD fcc
)
52 fourcc_to_string(fcc_str
, fcc
);
54 /* Last byte may be ' ' in some cases like "DIB " */
55 if (isalnum(fcc_str
[0]) && isalnum(fcc_str
[1]) && isalnum(fcc_str
[2])
56 && (isalnum(fcc_str
[3]) || isspace(fcc_str
[3])))
57 return wine_dbg_sprintf("%s", fcc_str
);
58 return wine_dbg_sprintf("0x%08x", fcc
);
61 static const char *wine_dbgstr_icerr( int ret
)
64 if (ret
<= ICERR_CUSTOM
)
65 return wine_dbg_sprintf("ICERR_CUSTOM (%d)", ret
);
66 #define XX(x) case (x): str = #x; break
72 XX(ICERR_GOTOKEYFRAME
);
73 XX(ICERR_STOPDRAWING
);
74 XX(ICERR_UNSUPPORTED
);
85 XX(ICERR_BADBITDEPTH
);
86 XX(ICERR_BADIMAGESIZE
);
87 default: str
= wine_dbg_sprintf("UNKNOWN (%d)", ret
);
93 static WINE_HIC
* MSVIDEO_FirstHic
/* = NULL */;
95 typedef struct _reg_driver reg_driver
;
105 static reg_driver
* reg_driver_list
= NULL
;
107 HMODULE MSVFW32_hModule
;
109 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
111 TRACE("%p,%x,%p\n", hinst
, reason
, reserved
);
115 case DLL_PROCESS_ATTACH
:
116 DisableThreadLibraryCalls(hinst
);
117 MSVFW32_hModule
= hinst
;
123 /******************************************************************
124 * MSVIDEO_SendMessage
128 static LRESULT
MSVIDEO_SendMessage(WINE_HIC
* whic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
132 #define XX(x) case x: TRACE("(%p,"#x",0x%08lx,0x%08lx)\n",whic,lParam1,lParam2); break
147 XX(ICM_GETDEFAULTQUALITY
);
154 XX(ICM_COMPRESS_FRAMES_INFO
);
155 XX(ICM_COMPRESS_GET_FORMAT
);
156 XX(ICM_COMPRESS_GET_SIZE
);
157 XX(ICM_COMPRESS_QUERY
);
158 XX(ICM_COMPRESS_BEGIN
);
160 XX(ICM_COMPRESS_END
);
161 XX(ICM_DECOMPRESS_GET_FORMAT
);
162 XX(ICM_DECOMPRESS_QUERY
);
163 XX(ICM_DECOMPRESS_BEGIN
);
165 XX(ICM_DECOMPRESS_END
);
166 XX(ICM_DECOMPRESS_SET_PALETTE
);
167 XX(ICM_DECOMPRESS_GET_PALETTE
);
170 XX(ICM_DRAW_GET_PALETTE
);
174 XX(ICM_DRAW_GETTIME
);
177 XX(ICM_DRAW_SETTIME
);
178 XX(ICM_DRAW_REALIZE
);
180 XX(ICM_DRAW_RENDERBUFFER
);
181 XX(ICM_DRAW_START_PLAY
);
182 XX(ICM_DRAW_STOP_PLAY
);
183 XX(ICM_DRAW_SUGGESTFORMAT
);
184 XX(ICM_DRAW_CHANGEPALETTE
);
185 XX(ICM_GETBUFFERSWANTED
);
186 XX(ICM_GETDEFAULTKEYFRAMERATE
);
187 XX(ICM_DECOMPRESSEX_BEGIN
);
188 XX(ICM_DECOMPRESSEX_QUERY
);
189 XX(ICM_DECOMPRESSEX
);
190 XX(ICM_DECOMPRESSEX_END
);
191 XX(ICM_SET_STATUS_PROC
);
193 FIXME("(%p,0x%08x,0x%08lx,0x%08lx) unknown message\n",whic
,msg
,lParam1
,lParam2
);
198 if (whic
->driverproc
) {
199 /* dwDriverId parameter is the value returned by the DRV_OPEN */
200 ret
= whic
->driverproc(whic
->driverId
, whic
->hdrv
, msg
, lParam1
, lParam2
);
202 ret
= SendDriverMessage(whic
->hdrv
, msg
, lParam1
, lParam2
);
205 TRACE(" -> %s\n", wine_dbgstr_icerr(ret
));
209 static int compare_fourcc(DWORD fcc1
, DWORD fcc2
)
213 fourcc_to_string(fcc_str1
, fcc1
);
214 fourcc_to_string(fcc_str2
, fcc2
);
215 return strncasecmp(fcc_str1
, fcc_str2
, 4);
218 typedef BOOL (*enum_handler_t
)(const char*, unsigned int, void*);
220 static BOOL
enum_drivers(DWORD fccType
, enum_handler_t handler
, void* param
)
222 CHAR buf
[2048], fccTypeStr
[5], *s
;
223 DWORD i
, cnt
= 0, lRet
;
227 fourcc_to_string(fccTypeStr
, fccType
);
230 /* first, go through the registry entries */
231 lRet
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, HKLM_DRIVERS32
, 0, KEY_QUERY_VALUE
, &hKey
);
232 if (lRet
== ERROR_SUCCESS
)
234 DWORD name
, data
, type
;
239 data
= sizeof buf
- name
;
240 lRet
= RegEnumValueA(hKey
, i
++, buf
, &name
, 0, &type
, (LPBYTE
)(buf
+name
), &data
);
241 if (lRet
== ERROR_NO_MORE_ITEMS
) break;
242 if (lRet
!= ERROR_SUCCESS
) continue;
243 if (name
!= 9 || strncasecmp(buf
, fccTypeStr
, 5)) continue;
245 if ((result
= handler(buf
, cnt
++, param
))) break;
249 if (result
) return result
;
251 /* if that didn't work, go through the values in system.ini */
252 if (GetPrivateProfileSectionA("drivers32", buf
, sizeof(buf
), "system.ini"))
254 for (s
= buf
; *s
; s
+= strlen(s
) + 1)
256 TRACE("got %s\n", s
);
257 if (strncasecmp(s
, fccTypeStr
, 5) || s
[9] != '=') continue;
258 if ((result
= handler(s
, cnt
++, param
))) break;
265 /******************************************************************
270 static WINE_HIC
* MSVIDEO_GetHicPtr(HIC hic
)
274 for (whic
= MSVIDEO_FirstHic
; whic
&& whic
->hic
!= hic
; whic
= whic
->next
);
278 /***********************************************************************
279 * VideoForWindowsVersion [MSVFW32.2]
280 * VideoForWindowsVersion [MSVIDEO.2]
281 * Returns the version in major.minor form.
282 * In Windows95 this returns 0x040003b6 (4.950)
284 DWORD WINAPI
VideoForWindowsVersion(void)
286 return 0x040003B6; /* 4.950 */
289 static BOOL
ICInfo_enum_handler(const char *drv
, unsigned int nr
, void *param
)
291 ICINFO
*lpicinfo
= param
;
292 DWORD fccHandler
= mmioStringToFOURCCA(drv
+ 5, 0);
294 /* exact match of fccHandler or nth driver found */
295 if ((lpicinfo
->fccHandler
!= nr
) && (lpicinfo
->fccHandler
!= fccHandler
))
298 lpicinfo
->fccHandler
= fccHandler
;
299 lpicinfo
->dwFlags
= 0;
300 lpicinfo
->dwVersion
= 0;
301 lpicinfo
->dwVersionICM
= ICVERSION
;
302 lpicinfo
->szName
[0] = 0;
303 lpicinfo
->szDescription
[0] = 0;
304 MultiByteToWideChar(CP_ACP
, 0, drv
+ 10, -1, lpicinfo
->szDriver
,
305 sizeof(lpicinfo
->szDriver
)/sizeof(WCHAR
));
310 /***********************************************************************
312 * Get information about an installable compressor. Return TRUE if there
316 * fccType [I] type of compressor (e.g. 'vidc')
317 * fccHandler [I] real fcc for handler or <n>th compressor
318 * lpicinfo [O] information about compressor
320 BOOL VFWAPI
ICInfo( DWORD fccType
, DWORD fccHandler
, ICINFO
*lpicinfo
)
322 TRACE("(%s,%s,%p)\n",
323 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), lpicinfo
);
325 lpicinfo
->fccType
= fccType
;
326 lpicinfo
->fccHandler
= fccHandler
;
327 return enum_drivers(fccType
, ICInfo_enum_handler
, lpicinfo
);
330 static DWORD IC_HandleRef
= 1;
332 /***********************************************************************
333 * ICInstall [MSVFW32.@]
335 BOOL VFWAPI
ICInstall(DWORD fccType
, DWORD fccHandler
, LPARAM lParam
, LPSTR szDesc
, UINT wFlags
)
340 TRACE("(%s,%s,%p,%p,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), (void*)lParam
, szDesc
, wFlags
);
342 /* Check if a driver is already registered */
343 for (driver
= reg_driver_list
; driver
; driver
= driver
->next
)
345 if (!compare_fourcc(fccType
, driver
->fccType
) &&
346 !compare_fourcc(fccHandler
, driver
->fccHandler
))
349 if (driver
) return FALSE
;
351 /* Register the driver */
352 driver
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(reg_driver
));
353 if (!driver
) goto oom
;
354 driver
->fccType
= fccType
;
355 driver
->fccHandler
= fccHandler
;
359 case ICINSTALL_FUNCTION
:
360 driver
->proc
= (DRIVERPROC
)lParam
;
363 case ICINSTALL_DRIVER
:
365 len
= MultiByteToWideChar(CP_ACP
, 0, (char*)lParam
, -1, NULL
, 0);
366 driver
->name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
367 if (!driver
->name
) goto oom
;
368 MultiByteToWideChar(CP_ACP
, 0, (char*)lParam
, -1, driver
->name
, len
);
371 ERR("Invalid flags!\n");
372 HeapFree(GetProcessHeap(), 0, driver
);
376 /* Insert our driver in the list*/
377 driver
->next
= reg_driver_list
;
378 reg_driver_list
= driver
;
382 HeapFree(GetProcessHeap(), 0, driver
);
386 /***********************************************************************
387 * ICRemove [MSVFW32.@]
389 BOOL VFWAPI
ICRemove(DWORD fccType
, DWORD fccHandler
, UINT wFlags
)
391 reg_driver
** pdriver
;
394 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wFlags
);
396 /* Check if a driver is already registered */
397 for (pdriver
= ®_driver_list
; *pdriver
; pdriver
= &(*pdriver
)->next
)
399 if (!compare_fourcc(fccType
, (*pdriver
)->fccType
) &&
400 !compare_fourcc(fccHandler
, (*pdriver
)->fccHandler
))
406 /* Remove the driver from the list */
408 *pdriver
= (*pdriver
)->next
;
409 HeapFree(GetProcessHeap(), 0, drv
->name
);
410 HeapFree(GetProcessHeap(), 0, drv
);
416 /***********************************************************************
418 * Opens an installable compressor. Return special handle.
420 HIC VFWAPI
ICOpen(DWORD fccType
, DWORD fccHandler
, UINT wMode
)
426 static const WCHAR drv32W
[] = {'d','r','i','v','e','r','s','3','2','\0'};
429 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wMode
);
431 if (!fccHandler
) /* No specific handler, return the first valid for wMode */
436 info
.dwSize
= sizeof(info
);
437 while(ICInfo(fccType
, loop
++, &info
))
439 /* Ensure fccHandler is not 0x0 because we will recurse on ICOpen */
442 local
= ICOpen(fccType
, info
.fccHandler
, wMode
);
445 TRACE("Returning %s as defult handler for %s\n",
446 wine_dbgstr_fcc(info
.fccHandler
), wine_dbgstr_fcc(fccType
));
452 /* Check if there is a registered driver that matches */
453 driver
= reg_driver_list
;
455 if (!compare_fourcc(fccType
, driver
->fccType
) &&
456 !compare_fourcc(fccHandler
, driver
->fccHandler
)) {
457 fccType
= driver
->fccType
;
458 fccHandler
= driver
->fccHandler
;
461 driver
= driver
->next
;
463 if (driver
&& driver
->proc
)
464 /* The driver has been registered at runtime with its driverproc */
465 return ICOpenFunction(fccType
, fccHandler
, wMode
, driver
->proc
);
467 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
468 * same layout as ICOPEN
470 icopen
.dwSize
= sizeof(ICOPEN
);
471 icopen
.fccType
= fccType
;
472 icopen
.fccHandler
= fccHandler
;
473 icopen
.dwVersion
= 0x00001000; /* FIXME */
474 icopen
.dwFlags
= wMode
;
476 icopen
.pV1Reserved
= NULL
;
477 icopen
.pV2Reserved
= NULL
;
478 icopen
.dnDevNode
= 0; /* FIXME */
481 /* normalize to lower case as in 'vidc' */
482 ((char*)&fccType
)[0] = tolower(((char*)&fccType
)[0]);
483 ((char*)&fccType
)[1] = tolower(((char*)&fccType
)[1]);
484 ((char*)&fccType
)[2] = tolower(((char*)&fccType
)[2]);
485 ((char*)&fccType
)[3] = tolower(((char*)&fccType
)[3]);
486 icopen
.fccType
= fccType
;
487 /* Seek the driver in the registry */
488 fourcc_to_string(codecname
, fccType
);
490 fourcc_to_string(codecname
+ 5, fccHandler
);
493 hdrv
= OpenDriver(codecname
, drv32W
, (LPARAM
)&icopen
);
497 /* The driver has been registered at runtime with its name */
498 hdrv
= OpenDriver(driver
->name
, NULL
, (LPARAM
)&icopen
);
503 whic
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC
));
506 CloseDriver(hdrv
, 0, 0);
510 whic
->driverproc
= NULL
;
511 whic
->type
= fccType
;
512 whic
->handler
= fccHandler
;
513 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
514 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
515 whic
->next
= MSVIDEO_FirstHic
;
516 MSVIDEO_FirstHic
= whic
;
518 TRACE("=> %p\n", whic
->hic
);
522 /***********************************************************************
523 * ICOpenFunction [MSVFW32.@]
525 HIC VFWAPI
ICOpenFunction(DWORD fccType
, DWORD fccHandler
, UINT wMode
, DRIVERPROC lpfnHandler
)
530 TRACE("(%s,%s,%d,%p)\n",
531 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wMode
, lpfnHandler
);
533 icopen
.dwSize
= sizeof(ICOPEN
);
534 icopen
.fccType
= fccType
;
535 icopen
.fccHandler
= fccHandler
;
536 icopen
.dwVersion
= ICVERSION
;
537 icopen
.dwFlags
= wMode
;
539 icopen
.pV1Reserved
= NULL
;
540 icopen
.pV2Reserved
= NULL
;
541 icopen
.dnDevNode
= 0; /* FIXME */
543 whic
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC
));
546 whic
->driverproc
= lpfnHandler
;
547 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
548 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
549 whic
->next
= MSVIDEO_FirstHic
;
550 MSVIDEO_FirstHic
= whic
;
552 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
553 /* What if the function is used more than once? */
555 if (MSVIDEO_SendMessage(whic
, DRV_LOAD
, 0L, 0L) != DRV_SUCCESS
)
557 WARN("DRV_LOAD failed for hic %p\n", whic
->hic
);
558 MSVIDEO_FirstHic
= whic
->next
;
559 HeapFree(GetProcessHeap(), 0, whic
);
562 /* return value is not checked */
563 MSVIDEO_SendMessage(whic
, DRV_ENABLE
, 0L, 0L);
565 whic
->driverId
= (DWORD
)MSVIDEO_SendMessage(whic
, DRV_OPEN
, 0, (DWORD_PTR
)&icopen
);
566 /* FIXME: What should we put here? */
569 if (whic
->driverId
== 0)
571 WARN("DRV_OPEN failed for hic %p\n", whic
->hic
);
572 MSVIDEO_FirstHic
= whic
->next
;
573 HeapFree(GetProcessHeap(), 0, whic
);
577 TRACE("=> %p\n", whic
->hic
);
581 /***********************************************************************
582 * ICGetInfo [MSVFW32.@]
584 LRESULT VFWAPI
ICGetInfo(HIC hic
, ICINFO
*picinfo
, DWORD cb
)
587 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
589 TRACE("(%p,%p,%d)\n", hic
, picinfo
, cb
);
591 if (!whic
) return ICERR_BADHANDLE
;
592 if (!picinfo
) return MMSYSERR_INVALPARAM
;
594 /* (WS) The field szDriver should be initialized because the driver
595 * is not obliged and often will not do it. Some applications, like
596 * VirtualDub, rely on this field and will occasionally crash if it
597 * goes uninitialized.
599 if (cb
>= sizeof(ICINFO
)) picinfo
->szDriver
[0] = '\0';
601 ret
= ICSendMessage(hic
, ICM_GETINFO
, (DWORD_PTR
)picinfo
, cb
);
603 /* (WS) When szDriver was not supplied by the driver itself, apparently
604 * Windows will set its value equal to the driver file name. This can
605 * be obtained from the registry as we do here.
607 if (cb
>= sizeof(ICINFO
) && picinfo
->szDriver
[0] == 0)
611 memset(&ii
, 0, sizeof(ii
));
612 ii
.dwSize
= sizeof(ii
);
613 ICInfo(picinfo
->fccType
, picinfo
->fccHandler
, &ii
);
614 lstrcpyW(picinfo
->szDriver
, ii
.szDriver
);
617 TRACE(" -> %s\n", wine_dbgstr_icerr(ret
));
624 LPBITMAPINFOHEADER lpbiIn
;
625 LPBITMAPINFOHEADER lpbiOut
;
631 static HIC
try_driver(driver_info_t
*info
)
635 if ((hic
= ICOpen(info
->fccType
, info
->fccHandler
, info
->wMode
)))
637 if (!ICSendMessage(hic
, info
->querymsg
, (DWORD_PTR
)info
->lpbiIn
, (DWORD_PTR
)info
->lpbiOut
))
644 static BOOL
ICLocate_enum_handler(const char *drv
, unsigned int nr
, void *param
)
646 driver_info_t
*info
= param
;
647 info
->fccHandler
= mmioStringToFOURCCA(drv
+ 5, 0);
648 info
->hic
= try_driver(info
);
649 return info
->hic
!= 0;
652 /***********************************************************************
653 * ICLocate [MSVFW32.@]
655 HIC VFWAPI
ICLocate(DWORD fccType
, DWORD fccHandler
, LPBITMAPINFOHEADER lpbiIn
,
656 LPBITMAPINFOHEADER lpbiOut
, WORD wMode
)
660 TRACE("(%s,%s,%p,%p,0x%04x)\n",
661 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), lpbiIn
, lpbiOut
, wMode
);
663 info
.fccType
= fccType
;
664 info
.fccHandler
= fccHandler
;
665 info
.lpbiIn
= lpbiIn
;
666 info
.lpbiOut
= lpbiOut
;
671 case ICMODE_FASTCOMPRESS
:
672 case ICMODE_COMPRESS
:
673 info
.querymsg
= ICM_COMPRESS_QUERY
;
675 case ICMODE_FASTDECOMPRESS
:
676 case ICMODE_DECOMPRESS
:
677 info
.querymsg
= ICM_DECOMPRESS_QUERY
;
680 info
.querymsg
= ICM_DRAW_QUERY
;
683 WARN("Unknown mode (%d)\n", wMode
);
687 /* Easy case: handler/type match, we just fire a query and return */
688 info
.hic
= try_driver(&info
);
689 /* If it didn't work, try each driver in turn. 32 bit codecs only. */
690 /* FIXME: Move this to an init routine? */
691 if (!info
.hic
) enum_drivers(fccType
, ICLocate_enum_handler
, &info
);
695 TRACE("=> %p\n", info
.hic
);
699 if (fccType
== streamtypeVIDEO
)
700 return ICLocate(ICTYPE_VIDEO
, fccHandler
, lpbiIn
, lpbiOut
, wMode
);
702 ERR("Required media codec '%s %s' not found!\n",
703 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
));
707 /***********************************************************************
708 * ICGetDisplayFormat [MSVFW32.@]
710 HIC VFWAPI
ICGetDisplayFormat(
711 HIC hic
,LPBITMAPINFOHEADER lpbiIn
,LPBITMAPINFOHEADER lpbiOut
,
712 INT depth
,INT dx
,INT dy
)
716 TRACE("(%p,%p,%p,%d,%d,%d)!\n",hic
,lpbiIn
,lpbiOut
,depth
,dx
,dy
);
719 tmphic
=ICLocate(ICTYPE_VIDEO
,0,lpbiIn
,NULL
,ICMODE_DECOMPRESS
);
723 if ((dy
== lpbiIn
->biHeight
) && (dx
== lpbiIn
->biWidth
))
724 dy
= dx
= 0; /* no resize needed */
726 /* Can we decompress it ? */
727 if (ICDecompressQuery(tmphic
,lpbiIn
,NULL
) != 0)
728 goto errout
; /* no, sorry */
730 ICSendMessage(tmphic
, ICM_DECOMPRESS_GET_FORMAT
, (DWORD_PTR
)lpbiIn
, (DWORD_PTR
)lpbiOut
);
732 if (lpbiOut
->biCompression
!= 0) {
733 FIXME("Ooch, how come decompressor outputs compressed data (%d)??\n",
734 lpbiOut
->biCompression
);
736 if (lpbiOut
->biSize
< sizeof(*lpbiOut
)) {
737 FIXME("Ooch, size of output BIH is too small (%d)\n",
739 lpbiOut
->biSize
= sizeof(*lpbiOut
);
745 depth
= GetDeviceCaps(hdc
,BITSPIXEL
)*GetDeviceCaps(hdc
,PLANES
);
747 if (depth
==15) depth
= 16;
748 if (depth
<8) depth
= 8;
750 if (lpbiIn
->biBitCount
== 8)
753 TRACE("=> %p\n", tmphic
);
763 /***********************************************************************
764 * ICCompress [MSVFW32.@]
768 HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiOutput
,LPVOID lpData
,
769 LPBITMAPINFOHEADER lpbiInput
,LPVOID lpBits
,LPDWORD lpckid
,
770 LPDWORD lpdwFlags
,LONG lFrameNum
,DWORD dwFrameSize
,DWORD dwQuality
,
771 LPBITMAPINFOHEADER lpbiPrev
,LPVOID lpPrev
)
775 TRACE("(%p,%d,%p,%p,%p,%p,...)\n",hic
,dwFlags
,lpbiOutput
,lpData
,lpbiInput
,lpBits
);
777 iccmp
.dwFlags
= dwFlags
;
779 iccmp
.lpbiOutput
= lpbiOutput
;
780 iccmp
.lpOutput
= lpData
;
781 iccmp
.lpbiInput
= lpbiInput
;
782 iccmp
.lpInput
= lpBits
;
784 iccmp
.lpckid
= lpckid
;
785 iccmp
.lpdwFlags
= lpdwFlags
;
786 iccmp
.lFrameNum
= lFrameNum
;
787 iccmp
.dwFrameSize
= dwFrameSize
;
788 iccmp
.dwQuality
= dwQuality
;
789 iccmp
.lpbiPrev
= lpbiPrev
;
790 iccmp
.lpPrev
= lpPrev
;
791 return ICSendMessage(hic
,ICM_COMPRESS
,(DWORD_PTR
)&iccmp
,sizeof(iccmp
));
794 /***********************************************************************
795 * ICDecompress [MSVFW32.@]
797 DWORD VFWAPIV
ICDecompress(HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiFormat
,
798 LPVOID lpData
,LPBITMAPINFOHEADER lpbi
,LPVOID lpBits
)
803 TRACE("(%p,%d,%p,%p,%p,%p)\n",hic
,dwFlags
,lpbiFormat
,lpData
,lpbi
,lpBits
);
805 icd
.dwFlags
= dwFlags
;
806 icd
.lpbiInput
= lpbiFormat
;
807 icd
.lpInput
= lpData
;
809 icd
.lpbiOutput
= lpbi
;
810 icd
.lpOutput
= lpBits
;
812 ret
= ICSendMessage(hic
,ICM_DECOMPRESS
,(DWORD_PTR
)&icd
,sizeof(ICDECOMPRESS
));
814 TRACE("-> %s\n",wine_dbgstr_icerr(ret
));
820 struct choose_compressor
833 static BOOL
enum_compressors(HWND list
, COMPVARS
*pcv
, BOOL enum_all
)
840 while (ICInfo(pcv
->fccType
, id
, &icinfo
))
842 struct codec_info
*ic
;
848 hic
= ICOpen(icinfo
.fccType
, icinfo
.fccHandler
, ICMODE_COMPRESS
);
852 /* for unknown reason fccHandler reported by the driver
853 * doesn't always work, use the one returned by ICInfo instead.
855 DWORD fccHandler
= icinfo
.fccHandler
;
857 if (!enum_all
&& pcv
->lpbiIn
)
859 if (ICCompressQuery(hic
, pcv
->lpbiIn
, NULL
) != ICERR_OK
)
861 TRACE("fccHandler %s doesn't support input DIB format %d\n",
862 wine_dbgstr_fcc(icinfo
.fccHandler
), pcv
->lpbiIn
->bmiHeader
.biCompression
);
868 ICGetInfo(hic
, &icinfo
, sizeof(icinfo
));
869 icinfo
.fccHandler
= fccHandler
;
871 idx
= SendMessageW(list
, CB_ADDSTRING
, 0, (LPARAM
)icinfo
.szDescription
);
873 ic
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info
));
876 SendMessageW(list
, CB_SETITEMDATA
, idx
, (LPARAM
)ic
);
884 static INT_PTR CALLBACK
icm_choose_compressor_dlgproc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
890 struct codec_info
*ic
;
892 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)lparam
;
894 SetWindowLongPtrW(hdlg
, DWLP_USER
, lparam
);
897 choose_comp
->flags
&= ~(ICMF_CHOOSE_DATARATE
| ICMF_CHOOSE_KEYFRAME
);
899 if (choose_comp
->title
)
900 SetWindowTextA(hdlg
, choose_comp
->title
);
902 if (!(choose_comp
->flags
& ICMF_CHOOSE_DATARATE
))
904 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_CHECKBOX
), SW_HIDE
);
905 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE
), SW_HIDE
);
906 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_KB
), SW_HIDE
);
909 if (!(choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
))
911 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_CHECKBOX
), SW_HIDE
);
912 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME
), SW_HIDE
);
913 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_FRAMES
), SW_HIDE
);
917 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_SCROLL
), FALSE
);
918 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_TXT
), FALSE
);
920 /*if (!(choose_comp->flags & ICMF_CHOOSE_PREVIEW))
921 ShowWindow(GetDlgItem(hdlg, IDC_PREVIEW), SW_HIDE);*/
923 LoadStringW(MSVFW32_hModule
, IDS_FULLFRAMES
, buf
, 128);
924 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
926 ic
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info
));
927 ic
->icinfo
.fccType
= streamtypeVIDEO
;
928 ic
->icinfo
.fccHandler
= comptypeDIB
;
930 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETITEMDATA
, 0, (LPARAM
)ic
);
932 enum_compressors(GetDlgItem(hdlg
, IDC_COMP_LIST
), &choose_comp
->cv
, choose_comp
->flags
& ICMF_CHOOSE_ALLCOMPRESSORS
);
934 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETCURSEL
, 0, 0);
935 SetFocus(GetDlgItem(hdlg
, IDC_COMP_LIST
));
937 SetWindowLongPtrW(hdlg
, DWLP_USER
, (ULONG_PTR
)choose_comp
);
942 switch (LOWORD(wparam
))
947 struct codec_info
*ic
;
948 BOOL can_configure
= FALSE
, can_about
= FALSE
;
949 struct choose_compressor
*choose_comp
;
951 if (HIWORD(wparam
) != CBN_SELCHANGE
&& HIWORD(wparam
) != CBN_SETFOCUS
)
954 choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
956 cur_sel
= SendMessageW((HWND
)lparam
, CB_GETCURSEL
, 0, 0);
958 ic
= (struct codec_info
*)SendMessageW((HWND
)lparam
, CB_GETITEMDATA
, cur_sel
, 0);
961 if (ICQueryConfigure(ic
->hic
) == DRVCNF_OK
)
962 can_configure
= TRUE
;
963 if (ICQueryAbout(ic
->hic
) == DRVCNF_OK
)
966 EnableWindow(GetDlgItem(hdlg
, IDC_CONFIGURE
), can_configure
);
967 EnableWindow(GetDlgItem(hdlg
, IDC_ABOUT
), can_about
);
969 if (choose_comp
->flags
& ICMF_CHOOSE_DATARATE
)
973 if (choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
)
984 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
986 struct codec_info
*ic
;
988 if (HIWORD(wparam
) != BN_CLICKED
)
991 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
993 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
996 if (LOWORD(wparam
) == IDC_CONFIGURE
)
997 ICConfigure(ic
->hic
, hdlg
);
999 ICAbout(ic
->hic
, hdlg
);
1007 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1009 struct codec_info
*ic
;
1011 if (HIWORD(wparam
) != BN_CLICKED
)
1014 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
1015 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1018 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
1020 choose_comp
->cv
.hic
= ic
->hic
;
1021 choose_comp
->cv
.fccType
= ic
->icinfo
.fccType
;
1022 choose_comp
->cv
.fccHandler
= ic
->icinfo
.fccHandler
;
1023 /* FIXME: fill everything else */
1025 /* prevent closing the codec handle below */
1032 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1035 if (HIWORD(wparam
) != BN_CLICKED
)
1040 struct codec_info
*ic
;
1042 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, idx
++, 0);
1044 if (!ic
|| (LONG_PTR
)ic
== CB_ERR
) break;
1046 if (ic
->hic
) ICClose(ic
->hic
);
1047 HeapFree(GetProcessHeap(), 0, ic
);
1050 EndDialog(hdlg
, LOWORD(wparam
) == IDOK
);
1066 /***********************************************************************
1067 * ICCompressorChoose [MSVFW32.@]
1069 BOOL VFWAPI
ICCompressorChoose(HWND hwnd
, UINT uiFlags
, LPVOID pvIn
,
1070 LPVOID lpData
, PCOMPVARS pc
, LPSTR lpszTitle
)
1072 struct choose_compressor choose_comp
;
1075 TRACE("(%p,%08x,%p,%p,%p,%s)\n", hwnd
, uiFlags
, pvIn
, lpData
, pc
, lpszTitle
);
1077 if (!pc
|| pc
->cbSize
!= sizeof(COMPVARS
))
1080 if (!(pc
->dwFlags
& ICMF_COMPVARS_VALID
))
1083 pc
->fccType
= pc
->fccHandler
= 0;
1087 pc
->lpBitsOut
= pc
->lpBitsPrev
= pc
->lpState
= NULL
;
1088 pc
->lQ
= ICQUALITY_DEFAULT
;
1090 pc
->lDataRate
= 300; /* kB */
1094 if (pc
->fccType
== 0)
1095 pc
->fccType
= ICTYPE_VIDEO
;
1097 choose_comp
.cv
= *pc
;
1098 choose_comp
.flags
= uiFlags
;
1099 choose_comp
.title
= lpszTitle
;
1101 ret
= DialogBoxParamW(MSVFW32_hModule
, MAKEINTRESOURCEW(ICM_CHOOSE_COMPRESSOR
), hwnd
,
1102 icm_choose_compressor_dlgproc
, (LPARAM
)&choose_comp
);
1106 *pc
= choose_comp
.cv
;
1107 pc
->dwFlags
|= ICMF_COMPVARS_VALID
;
1114 /***********************************************************************
1115 * ICCompressorFree [MSVFW32.@]
1117 void VFWAPI
ICCompressorFree(PCOMPVARS pc
)
1121 if (pc
!= NULL
&& pc
->cbSize
== sizeof(COMPVARS
)) {
1122 if (pc
->hic
!= NULL
) {
1126 HeapFree(GetProcessHeap(), 0, pc
->lpbiIn
);
1128 HeapFree(GetProcessHeap(), 0, pc
->lpBitsOut
);
1129 pc
->lpBitsOut
= NULL
;
1130 HeapFree(GetProcessHeap(), 0, pc
->lpBitsPrev
);
1131 pc
->lpBitsPrev
= NULL
;
1132 HeapFree(GetProcessHeap(), 0, pc
->lpState
);
1138 /***********************************************************************
1139 * ICSendMessage [MSVFW32.@]
1141 LRESULT VFWAPI
ICSendMessage(HIC hic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
1143 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1145 if (!whic
) return ICERR_BADHANDLE
;
1146 return MSVIDEO_SendMessage(whic
, msg
, lParam1
, lParam2
);
1149 /***********************************************************************
1150 * ICDrawBegin [MSVFW32.@]
1152 DWORD VFWAPIV
ICDrawBegin(
1154 DWORD dwFlags
, /* [in] flags */
1155 HPALETTE hpal
, /* [in] palette to draw with */
1156 HWND hwnd
, /* [in] window to draw to */
1157 HDC hdc
, /* [in] HDC to draw to */
1158 INT xDst
, /* [in] destination rectangle */
1159 INT yDst
, /* [in] */
1160 INT dxDst
, /* [in] */
1161 INT dyDst
, /* [in] */
1162 LPBITMAPINFOHEADER lpbi
, /* [in] format of frame to draw */
1163 INT xSrc
, /* [in] source rectangle */
1164 INT ySrc
, /* [in] */
1165 INT dxSrc
, /* [in] */
1166 INT dySrc
, /* [in] */
1167 DWORD dwRate
, /* [in] frames/second = (dwRate/dwScale) */
1168 DWORD dwScale
) /* [in] */
1173 TRACE("(%p,%d,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%d,%d)\n",
1174 hic
, dwFlags
, hpal
, hwnd
, hdc
, xDst
, yDst
, dxDst
, dyDst
,
1175 lpbi
, xSrc
, ySrc
, dxSrc
, dySrc
, dwRate
, dwScale
);
1177 icdb
.dwFlags
= dwFlags
;
1190 icdb
.dwRate
= dwRate
;
1191 icdb
.dwScale
= dwScale
;
1192 return ICSendMessage(hic
,ICM_DRAW_BEGIN
,(DWORD_PTR
)&icdb
,sizeof(icdb
));
1195 /***********************************************************************
1196 * ICDraw [MSVFW32.@]
1198 DWORD VFWAPIV
ICDraw(HIC hic
, DWORD dwFlags
, LPVOID lpFormat
, LPVOID lpData
, DWORD cbData
, LONG lTime
) {
1201 TRACE("(%p,%d,%p,%p,%d,%d)\n",hic
,dwFlags
,lpFormat
,lpData
,cbData
,lTime
);
1203 icd
.dwFlags
= dwFlags
;
1204 icd
.lpFormat
= lpFormat
;
1205 icd
.lpData
= lpData
;
1206 icd
.cbData
= cbData
;
1209 return ICSendMessage(hic
,ICM_DRAW
,(DWORD_PTR
)&icd
,sizeof(icd
));
1212 /***********************************************************************
1213 * ICClose [MSVFW32.@]
1215 LRESULT WINAPI
ICClose(HIC hic
)
1217 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1220 TRACE("(%p)\n",hic
);
1222 if (!whic
) return ICERR_BADHANDLE
;
1224 if (whic
->driverproc
)
1226 MSVIDEO_SendMessage(whic
, DRV_CLOSE
, 0, 0);
1227 MSVIDEO_SendMessage(whic
, DRV_DISABLE
, 0, 0);
1228 MSVIDEO_SendMessage(whic
, DRV_FREE
, 0, 0);
1232 CloseDriver(whic
->hdrv
, 0, 0);
1235 /* remove whic from list */
1236 for (p
= &MSVIDEO_FirstHic
; *p
!= NULL
; p
= &((*p
)->next
))
1245 HeapFree(GetProcessHeap(), 0, whic
);
1251 /***********************************************************************
1252 * ICImageCompress [MSVFW32.@]
1254 HANDLE VFWAPI
ICImageCompress(
1255 HIC hic
, UINT uiFlags
,
1256 LPBITMAPINFO lpbiIn
, LPVOID lpBits
,
1257 LPBITMAPINFO lpbiOut
, LONG lQuality
,
1260 FIXME("(%p,%08x,%p,%p,%p,%d,%p)\n",
1261 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
, lQuality
, plSize
);
1266 /***********************************************************************
1267 * ICImageDecompress [MSVFW32.@]
1270 HANDLE VFWAPI
ICImageDecompress(
1271 HIC hic
, UINT uiFlags
, LPBITMAPINFO lpbiIn
,
1272 LPVOID lpBits
, LPBITMAPINFO lpbiOut
)
1274 HGLOBAL hMem
= NULL
;
1276 BOOL bReleaseIC
= FALSE
;
1279 BOOL bSucceeded
= FALSE
;
1280 BOOL bInDecompress
= FALSE
;
1283 TRACE("(%p,%08x,%p,%p,%p)\n",
1284 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
);
1288 hic
= ICDecompressOpen( ICTYPE_VIDEO
, 0, &lpbiIn
->bmiHeader
, (lpbiOut
!= NULL
) ? &lpbiOut
->bmiHeader
: NULL
);
1291 WARN("no handler\n" );
1298 FIXME( "unknown flag %08x\n", uiFlags
);
1301 if ( lpbiIn
== NULL
|| lpBits
== NULL
)
1303 WARN("invalid argument\n");
1307 if ( lpbiOut
!= NULL
)
1309 if ( lpbiOut
->bmiHeader
.biSize
!= sizeof(BITMAPINFOHEADER
) )
1311 cbHdr
= sizeof(BITMAPINFOHEADER
);
1312 if ( lpbiOut
->bmiHeader
.biCompression
== 3 )
1313 cbHdr
+= sizeof(DWORD
)*3;
1315 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 )
1317 if ( lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1318 cbHdr
+= sizeof(RGBQUAD
) * (1<<lpbiOut
->bmiHeader
.biBitCount
);
1320 cbHdr
+= sizeof(RGBQUAD
) * lpbiOut
->bmiHeader
.biClrUsed
;
1325 TRACE( "get format\n" );
1327 cbHdr
= ICDecompressGetFormatSize(hic
,lpbiIn
);
1328 if ( cbHdr
< sizeof(BITMAPINFOHEADER
) )
1330 pHdr
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,cbHdr
+sizeof(RGBQUAD
)*256);
1333 if ( ICDecompressGetFormat( hic
, lpbiIn
, pHdr
) != ICERR_OK
)
1335 lpbiOut
= (BITMAPINFO
*)pHdr
;
1336 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1337 ICDecompressGetPalette( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
&&
1338 lpbiIn
->bmiHeader
.biBitCount
== lpbiOut
->bmiHeader
.biBitCount
)
1340 if ( lpbiIn
->bmiHeader
.biClrUsed
== 0 )
1341 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*(1<<lpbiOut
->bmiHeader
.biBitCount
) );
1343 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*lpbiIn
->bmiHeader
.biClrUsed
);
1345 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1346 lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1347 lpbiOut
->bmiHeader
.biClrUsed
= 1<<lpbiOut
->bmiHeader
.biBitCount
;
1349 lpbiOut
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1350 cbHdr
= sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
)*lpbiOut
->bmiHeader
.biClrUsed
;
1353 biSizeImage
= lpbiOut
->bmiHeader
.biSizeImage
;
1354 if ( biSizeImage
== 0 )
1355 biSizeImage
= ((((lpbiOut
->bmiHeader
.biWidth
* lpbiOut
->bmiHeader
.biBitCount
+ 7) >> 3) + 3) & (~3)) * abs(lpbiOut
->bmiHeader
.biHeight
);
1357 TRACE( "call ICDecompressBegin\n" );
1359 if ( ICDecompressBegin( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
)
1361 bInDecompress
= TRUE
;
1363 TRACE( "cbHdr %d, biSizeImage %d\n", cbHdr
, biSizeImage
);
1365 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_ZEROINIT
, cbHdr
+ biSizeImage
);
1368 WARN( "out of memory\n" );
1371 pMem
= GlobalLock( hMem
);
1374 memcpy( pMem
, lpbiOut
, cbHdr
);
1376 TRACE( "call ICDecompress\n" );
1377 if ( ICDecompress( hic
, 0, &lpbiIn
->bmiHeader
, lpBits
, &lpbiOut
->bmiHeader
, pMem
+cbHdr
) != ICERR_OK
)
1382 if ( bInDecompress
)
1383 ICDecompressEnd( hic
);
1386 HeapFree(GetProcessHeap(),0,pHdr
);
1388 GlobalUnlock( hMem
);
1389 if ( !bSucceeded
&& hMem
!= NULL
)
1391 GlobalFree(hMem
); hMem
= NULL
;
1397 /***********************************************************************
1398 * ICSeqCompressFrame [MSVFW32.@]
1400 LPVOID VFWAPI
ICSeqCompressFrame(PCOMPVARS pc
, UINT uiFlags
, LPVOID lpBits
, BOOL
*pfKey
, LONG
*plSize
)
1402 ICCOMPRESS
* icComp
= pc
->lpState
;
1404 TRACE("(%p, 0x%08x, %p, %p, %p)\n", pc
, uiFlags
, lpBits
, pfKey
, plSize
);
1406 if (pc
->cbState
!= sizeof(ICCOMPRESS
))
1408 ERR("Invalid cbState %i\n", pc
->cbState
);
1412 if (!pc
->lKeyCount
++)
1413 icComp
->dwFlags
= ICCOMPRESS_KEYFRAME
;
1416 if (pc
->lKey
&& pc
->lKeyCount
== (pc
->lKey
- 1))
1417 /* No key frames if pc->lKey == 0 */
1419 icComp
->dwFlags
= 0;
1422 icComp
->lpInput
= lpBits
;
1423 icComp
->lFrameNum
= pc
->lFrame
++;
1424 icComp
->lpOutput
= pc
->lpBitsOut
;
1425 icComp
->lpPrev
= pc
->lpBitsPrev
;
1426 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS
, (DWORD_PTR
)icComp
, sizeof(*icComp
));
1428 if (ret
== ICERR_OK
)
1430 LPVOID oldprev
, oldout
;
1432 if (icComp
->dwFlags
& AVIIF_KEYFRAME
)
1436 TRACE("Key frame\n");
1441 *plSize
= icComp
->lpbiOutput
->biSizeImage
;
1443 /* We shift Prev and Out, so we don't have to allocate and release memory */
1444 oldprev
= pc
->lpBitsPrev
;
1445 oldout
= pc
->lpBitsOut
;
1446 pc
->lpBitsPrev
= oldout
;
1447 pc
->lpBitsOut
= oldprev
;
1449 TRACE("returning: %p, compressed frame size %u\n", icComp
->lpOutput
, *plSize
);
1450 return icComp
->lpOutput
;
1455 static void clear_compvars(PCOMPVARS pc
)
1457 HeapFree(GetProcessHeap(), 0, pc
->lpbiIn
);
1458 HeapFree(GetProcessHeap(), 0, pc
->lpBitsPrev
);
1459 HeapFree(GetProcessHeap(), 0, pc
->lpBitsOut
);
1460 HeapFree(GetProcessHeap(), 0, pc
->lpState
);
1461 pc
->lpbiIn
= pc
->lpBitsPrev
= pc
->lpBitsOut
= pc
->lpState
= NULL
;
1462 if (pc
->dwFlags
& 0x80000000)
1464 HeapFree(GetProcessHeap(), 0, pc
->lpbiOut
);
1466 pc
->dwFlags
&= ~0x80000000;
1470 /***********************************************************************
1471 * ICSeqCompressFrameEnd [MSVFW32.@]
1473 void VFWAPI
ICSeqCompressFrameEnd(PCOMPVARS pc
)
1475 TRACE("(%p)\n", pc
);
1476 ICSendMessage(pc
->hic
, ICM_COMPRESS_END
, 0, 0);
1480 /***********************************************************************
1481 * ICSeqCompressFrameStart [MSVFW32.@]
1483 BOOL VFWAPI
ICSeqCompressFrameStart(PCOMPVARS pc
, LPBITMAPINFO lpbiIn
)
1485 /* I'm ignoring bmiColors as I don't know what to do with it,
1486 * it doesn't appear to be used though
1490 pc
->lpbiIn
= HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO
));
1494 *pc
->lpbiIn
= *lpbiIn
;
1496 pc
->lpState
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS
)
1497 + sizeof(*icComp
->lpckid
) + sizeof(*icComp
->lpdwFlags
));
1501 pc
->cbState
= sizeof(ICCOMPRESS
);
1505 /* Ask compressor for needed header size */
1506 int size
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1507 (DWORD_PTR
)pc
->lpbiIn
, 0);
1511 pc
->lpbiOut
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1514 /* Flag to show that we allocated lpbiOut for proper cleanup */
1515 pc
->dwFlags
|= 0x80000000;
1517 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1518 (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1519 if (ret
!= ICERR_OK
)
1521 ERR("Could not get output format from compressor\n");
1524 if (!pc
->lpbiOut
->bmiHeader
.biSizeImage
)
1526 /* If we can't know the output frame size for sure at least allocate
1527 * the same size of the input frame and also at least 8Kb to be sure
1528 * that poor compressors will have enough memory to work if the input
1529 * frame is too small.
1531 pc
->lpbiOut
->bmiHeader
.biSizeImage
= max(8192, pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1532 ERR("Bad codec! Invalid output frame size, guessing from input\n");
1536 TRACE("Input: %ux%u, fcc %s, bpp %u, size %u\n",
1537 pc
->lpbiIn
->bmiHeader
.biWidth
, pc
->lpbiIn
->bmiHeader
.biHeight
,
1538 wine_dbgstr_fcc(pc
->lpbiIn
->bmiHeader
.biCompression
),
1539 pc
->lpbiIn
->bmiHeader
.biBitCount
,
1540 pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1541 TRACE("Output: %ux%u, fcc %s, bpp %u, size %u\n",
1542 pc
->lpbiOut
->bmiHeader
.biWidth
, pc
->lpbiOut
->bmiHeader
.biHeight
,
1543 wine_dbgstr_fcc(pc
->lpbiOut
->bmiHeader
.biCompression
),
1544 pc
->lpbiOut
->bmiHeader
.biBitCount
,
1545 pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1547 /* Buffer for compressed frame data */
1548 pc
->lpBitsOut
= HeapAlloc(GetProcessHeap(), 0, pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1552 /* Buffer for previous compressed frame data */
1553 pc
->lpBitsPrev
= HeapAlloc(GetProcessHeap(), 0, pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1554 if (!pc
->lpBitsPrev
)
1564 "\tkey/data/quality: %i/%i/%i\n",
1565 pc
->cbSize
, pc
->dwFlags
, pc
->hic
, wine_dbgstr_fcc(pc
->fccType
),
1566 wine_dbgstr_fcc(pc
->fccHandler
), pc
->lpbiIn
, pc
->lpbiOut
, pc
->lKey
,
1567 pc
->lDataRate
, pc
->lQ
);
1569 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_BEGIN
, (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1570 if (ret
== ICERR_OK
)
1572 icComp
= pc
->lpState
;
1573 /* Initialise some variables */
1574 pc
->lFrame
= 0; pc
->lKeyCount
= 0;
1576 icComp
->lpbiOutput
= &pc
->lpbiOut
->bmiHeader
;
1577 icComp
->lpbiInput
= &pc
->lpbiIn
->bmiHeader
;
1578 icComp
->lpckid
= (DWORD
*)(icComp
+ 1);
1579 *icComp
->lpckid
= 0;
1580 icComp
->lpdwFlags
= (DWORD
*)((char *)(icComp
+ 1) + sizeof(*icComp
->lpckid
));
1581 *icComp
->lpdwFlags
= 0;
1582 icComp
->dwFrameSize
= 0;
1583 icComp
->dwQuality
= pc
->lQ
;
1584 icComp
->lpbiPrev
= &pc
->lpbiIn
->bmiHeader
;
1592 /***********************************************************************
1593 * GetFileNamePreview [MSVFW32.@]
1595 static BOOL
GetFileNamePreview(LPVOID lpofn
,BOOL bSave
,BOOL bUnicode
)
1597 CHAR szFunctionName
[20];
1598 BOOL (*fnGetFileName
)(LPVOID
);
1602 FIXME("(%p,%d,%d), semi-stub!\n",lpofn
,bSave
,bUnicode
);
1604 lstrcpyA(szFunctionName
, (bSave
? "GetSaveFileName" : "GetOpenFileName"));
1605 lstrcatA(szFunctionName
, (bUnicode
? "W" : "A"));
1607 hComdlg32
= LoadLibraryA("COMDLG32.DLL");
1608 if (hComdlg32
== NULL
)
1611 fnGetFileName
= (LPVOID
)GetProcAddress(hComdlg32
, szFunctionName
);
1612 if (fnGetFileName
== NULL
)
1614 FreeLibrary(hComdlg32
);
1618 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1619 ret
= fnGetFileName(lpofn
);
1621 FreeLibrary(hComdlg32
);
1625 /***********************************************************************
1626 * GetOpenFileNamePreviewA [MSVFW32.@]
1628 BOOL WINAPI
GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1630 FIXME("(%p), semi-stub!\n", lpofn
);
1632 return GetFileNamePreview(lpofn
, FALSE
, FALSE
);
1635 /***********************************************************************
1636 * GetOpenFileNamePreviewW [MSVFW32.@]
1638 BOOL WINAPI
GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1640 FIXME("(%p), semi-stub!\n", lpofn
);
1642 return GetFileNamePreview(lpofn
, FALSE
, TRUE
);
1645 /***********************************************************************
1646 * GetSaveFileNamePreviewA [MSVFW32.@]
1648 BOOL WINAPI
GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1650 FIXME("(%p), semi-stub!\n", lpofn
);
1652 return GetFileNamePreview(lpofn
, TRUE
, FALSE
);
1655 /***********************************************************************
1656 * GetSaveFileNamePreviewW [MSVFW32.@]
1658 BOOL WINAPI
GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1660 FIXME("(%p), semi-stub!\n", lpofn
);
1662 return GetFileNamePreview(lpofn
, TRUE
, TRUE
);