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 /* This one is a macro in order to work for both ASCII and Unicode */
50 #define fourcc_to_string(str, fcc) do { \
51 (str)[0] = LOBYTE(LOWORD(fcc)); \
52 (str)[1] = HIBYTE(LOWORD(fcc)); \
53 (str)[2] = LOBYTE(HIWORD(fcc)); \
54 (str)[3] = HIBYTE(HIWORD(fcc)); \
57 static inline const char *wine_dbgstr_fcc( DWORD fcc
)
60 fourcc_to_string(fcc_str
, fcc
);
62 /* Last byte may be ' ' in some cases like "DIB " */
63 if (isalnum(fcc_str
[0]) && isalnum(fcc_str
[1]) && isalnum(fcc_str
[2])
64 && (isalnum(fcc_str
[3]) || isspace(fcc_str
[3])))
65 return wine_dbg_sprintf("%s", fcc_str
);
66 return wine_dbg_sprintf("0x%08x", fcc
);
69 static const char *wine_dbgstr_icerr( int ret
)
72 if (ret
<= ICERR_CUSTOM
)
73 return wine_dbg_sprintf("ICERR_CUSTOM (%d)", ret
);
74 #define XX(x) case (x): str = #x; break
80 XX(ICERR_GOTOKEYFRAME
);
81 XX(ICERR_STOPDRAWING
);
82 XX(ICERR_UNSUPPORTED
);
93 XX(ICERR_BADBITDEPTH
);
94 XX(ICERR_BADIMAGESIZE
);
95 default: str
= wine_dbg_sprintf("UNKNOWN (%d)", ret
);
101 static WINE_HIC
* MSVIDEO_FirstHic
/* = NULL */;
103 typedef struct _reg_driver reg_driver
;
113 static reg_driver
* reg_driver_list
= NULL
;
115 HMODULE MSVFW32_hModule
;
117 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
119 TRACE("%p,%x,%p\n", hinst
, reason
, reserved
);
123 case DLL_PROCESS_ATTACH
:
124 DisableThreadLibraryCalls(hinst
);
125 MSVFW32_hModule
= hinst
;
131 /******************************************************************
132 * MSVIDEO_SendMessage
136 static LRESULT
MSVIDEO_SendMessage(WINE_HIC
* whic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
140 #define XX(x) case x: TRACE("(%p,"#x",0x%08lx,0x%08lx)\n",whic,lParam1,lParam2); break
155 XX(ICM_GETDEFAULTQUALITY
);
162 XX(ICM_COMPRESS_FRAMES_INFO
);
163 XX(ICM_COMPRESS_GET_FORMAT
);
164 XX(ICM_COMPRESS_GET_SIZE
);
165 XX(ICM_COMPRESS_QUERY
);
166 XX(ICM_COMPRESS_BEGIN
);
168 XX(ICM_COMPRESS_END
);
169 XX(ICM_DECOMPRESS_GET_FORMAT
);
170 XX(ICM_DECOMPRESS_QUERY
);
171 XX(ICM_DECOMPRESS_BEGIN
);
173 XX(ICM_DECOMPRESS_END
);
174 XX(ICM_DECOMPRESS_SET_PALETTE
);
175 XX(ICM_DECOMPRESS_GET_PALETTE
);
178 XX(ICM_DRAW_GET_PALETTE
);
182 XX(ICM_DRAW_GETTIME
);
185 XX(ICM_DRAW_SETTIME
);
186 XX(ICM_DRAW_REALIZE
);
188 XX(ICM_DRAW_RENDERBUFFER
);
189 XX(ICM_DRAW_START_PLAY
);
190 XX(ICM_DRAW_STOP_PLAY
);
191 XX(ICM_DRAW_SUGGESTFORMAT
);
192 XX(ICM_DRAW_CHANGEPALETTE
);
193 XX(ICM_GETBUFFERSWANTED
);
194 XX(ICM_GETDEFAULTKEYFRAMERATE
);
195 XX(ICM_DECOMPRESSEX_BEGIN
);
196 XX(ICM_DECOMPRESSEX_QUERY
);
197 XX(ICM_DECOMPRESSEX
);
198 XX(ICM_DECOMPRESSEX_END
);
199 XX(ICM_SET_STATUS_PROC
);
201 FIXME("(%p,0x%08x,0x%08lx,0x%08lx) unknown message\n",whic
,msg
,lParam1
,lParam2
);
206 if (whic
->driverproc
) {
207 /* dwDriverId parameter is the value returned by the DRV_OPEN */
208 ret
= whic
->driverproc(whic
->driverId
, whic
->hdrv
, msg
, lParam1
, lParam2
);
210 ret
= SendDriverMessage(whic
->hdrv
, msg
, lParam1
, lParam2
);
213 TRACE(" -> %s\n", wine_dbgstr_icerr(ret
));
217 static int compare_fourcc(DWORD fcc1
, DWORD fcc2
)
221 fourcc_to_string(fcc_str1
, fcc1
);
222 fourcc_to_string(fcc_str2
, fcc2
);
223 return strncasecmp(fcc_str1
, fcc_str2
, 4);
226 typedef BOOL (*enum_handler_t
)(const char*, unsigned int, void*);
228 static BOOL
enum_drivers(DWORD fccType
, enum_handler_t handler
, void* param
)
230 CHAR buf
[2048], fccTypeStr
[5], *s
;
231 DWORD i
, cnt
= 0, lRet
;
235 fourcc_to_string(fccTypeStr
, fccType
);
238 /* first, go through the registry entries */
239 lRet
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, HKLM_DRIVERS32
, 0, KEY_QUERY_VALUE
, &hKey
);
240 if (lRet
== ERROR_SUCCESS
)
242 DWORD name
, data
, type
;
247 data
= sizeof buf
- name
;
248 lRet
= RegEnumValueA(hKey
, i
++, buf
, &name
, 0, &type
, (LPBYTE
)(buf
+name
), &data
);
249 if (lRet
== ERROR_NO_MORE_ITEMS
) break;
250 if (lRet
!= ERROR_SUCCESS
) continue;
251 if (name
!= 9 || strncasecmp(buf
, fccTypeStr
, 5)) continue;
253 if ((result
= handler(buf
, cnt
++, param
))) break;
257 if (result
) return result
;
259 /* if that didn't work, go through the values in system.ini */
260 if (GetPrivateProfileSectionA("drivers32", buf
, sizeof(buf
), "system.ini"))
262 for (s
= buf
; *s
; s
+= strlen(s
) + 1)
264 TRACE("got %s\n", s
);
265 if (strncasecmp(s
, fccTypeStr
, 5) || s
[9] != '=') continue;
266 if ((result
= handler(s
, cnt
++, param
))) break;
273 /******************************************************************
278 static WINE_HIC
* MSVIDEO_GetHicPtr(HIC hic
)
282 for (whic
= MSVIDEO_FirstHic
; whic
&& whic
->hic
!= hic
; whic
= whic
->next
);
286 /***********************************************************************
287 * VideoForWindowsVersion [MSVFW32.2]
288 * VideoForWindowsVersion [MSVIDEO.2]
289 * Returns the version in major.minor form.
290 * In Windows95 this returns 0x040003b6 (4.950)
292 DWORD WINAPI
VideoForWindowsVersion(void)
294 return 0x040003B6; /* 4.950 */
297 static BOOL
ICInfo_enum_handler(const char *drv
, unsigned int nr
, void *param
)
299 ICINFO
*lpicinfo
= param
;
300 DWORD fccHandler
= mmioStringToFOURCCA(drv
+ 5, 0);
302 /* exact match of fccHandler or nth driver found */
303 if ((lpicinfo
->fccHandler
!= nr
) && (lpicinfo
->fccHandler
!= fccHandler
))
306 lpicinfo
->fccHandler
= fccHandler
;
307 lpicinfo
->dwFlags
= 0;
308 lpicinfo
->dwVersion
= 0;
309 lpicinfo
->dwVersionICM
= ICVERSION
;
310 lpicinfo
->szName
[0] = 0;
311 lpicinfo
->szDescription
[0] = 0;
312 MultiByteToWideChar(CP_ACP
, 0, drv
+ 10, -1, lpicinfo
->szDriver
,
313 sizeof(lpicinfo
->szDriver
)/sizeof(WCHAR
));
318 /***********************************************************************
320 * Get information about an installable compressor. Return TRUE if there
324 * fccType [I] type of compressor (e.g. 'vidc')
325 * fccHandler [I] real fcc for handler or <n>th compressor
326 * lpicinfo [O] information about compressor
328 BOOL VFWAPI
ICInfo( DWORD fccType
, DWORD fccHandler
, ICINFO
*lpicinfo
)
330 TRACE("(%s,%s,%p)\n",
331 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), lpicinfo
);
333 lpicinfo
->fccType
= fccType
;
334 lpicinfo
->fccHandler
= fccHandler
;
335 return enum_drivers(fccType
, ICInfo_enum_handler
, lpicinfo
);
338 static DWORD IC_HandleRef
= 1;
340 /***********************************************************************
341 * ICInstall [MSVFW32.@]
343 BOOL VFWAPI
ICInstall(DWORD fccType
, DWORD fccHandler
, LPARAM lParam
, LPSTR szDesc
, UINT wFlags
)
348 TRACE("(%s,%s,%p,%p,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), (void*)lParam
, szDesc
, wFlags
);
350 /* Check if a driver is already registered */
351 for (driver
= reg_driver_list
; driver
; driver
= driver
->next
)
353 if (!compare_fourcc(fccType
, driver
->fccType
) &&
354 !compare_fourcc(fccHandler
, driver
->fccHandler
))
357 if (driver
) return FALSE
;
359 /* Register the driver */
360 driver
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(reg_driver
));
361 if (!driver
) goto oom
;
362 driver
->fccType
= fccType
;
363 driver
->fccHandler
= fccHandler
;
367 case ICINSTALL_FUNCTION
:
368 driver
->proc
= (DRIVERPROC
)lParam
;
371 case ICINSTALL_DRIVER
:
373 len
= MultiByteToWideChar(CP_ACP
, 0, (char*)lParam
, -1, NULL
, 0);
374 driver
->name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
375 if (!driver
->name
) goto oom
;
376 MultiByteToWideChar(CP_ACP
, 0, (char*)lParam
, -1, driver
->name
, len
);
379 ERR("Invalid flags!\n");
380 HeapFree(GetProcessHeap(), 0, driver
);
384 /* Insert our driver in the list*/
385 driver
->next
= reg_driver_list
;
386 reg_driver_list
= driver
;
390 HeapFree(GetProcessHeap(), 0, driver
);
394 /***********************************************************************
395 * ICRemove [MSVFW32.@]
397 BOOL VFWAPI
ICRemove(DWORD fccType
, DWORD fccHandler
, UINT wFlags
)
399 reg_driver
** pdriver
;
402 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wFlags
);
404 /* Check if a driver is already registered */
405 for (pdriver
= ®_driver_list
; *pdriver
; pdriver
= &(*pdriver
)->next
)
407 if (!compare_fourcc(fccType
, (*pdriver
)->fccType
) &&
408 !compare_fourcc(fccHandler
, (*pdriver
)->fccHandler
))
414 /* Remove the driver from the list */
416 *pdriver
= (*pdriver
)->next
;
417 HeapFree(GetProcessHeap(), 0, drv
->name
);
418 HeapFree(GetProcessHeap(), 0, drv
);
424 /***********************************************************************
426 * Opens an installable compressor. Return special handle.
428 HIC VFWAPI
ICOpen(DWORD fccType
, DWORD fccHandler
, UINT wMode
)
434 static const WCHAR drv32W
[] = {'d','r','i','v','e','r','s','3','2','\0'};
437 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wMode
);
439 if (!fccHandler
) /* No specific handler, return the first valid for wMode */
444 info
.dwSize
= sizeof(info
);
445 while(ICInfo(fccType
, loop
++, &info
))
447 /* Ensure fccHandler is not 0x0 because we will recurse on ICOpen */
450 local
= ICOpen(fccType
, info
.fccHandler
, wMode
);
453 TRACE("Returning %s as defult handler for %s\n",
454 wine_dbgstr_fcc(info
.fccHandler
), wine_dbgstr_fcc(fccType
));
460 /* Check if there is a registered driver that matches */
461 driver
= reg_driver_list
;
463 if (!compare_fourcc(fccType
, driver
->fccType
) &&
464 !compare_fourcc(fccHandler
, driver
->fccHandler
)) {
465 fccType
= driver
->fccType
;
466 fccHandler
= driver
->fccHandler
;
469 driver
= driver
->next
;
471 if (driver
&& driver
->proc
)
472 /* The driver has been registered at runtime with its driverproc */
473 return ICOpenFunction(fccType
, fccHandler
, wMode
, driver
->proc
);
475 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
476 * same layout as ICOPEN
478 icopen
.dwSize
= sizeof(ICOPEN
);
479 icopen
.fccType
= fccType
;
480 icopen
.fccHandler
= fccHandler
;
481 icopen
.dwVersion
= 0x00001000; /* FIXME */
482 icopen
.dwFlags
= wMode
;
484 icopen
.pV1Reserved
= NULL
;
485 icopen
.pV2Reserved
= NULL
;
486 icopen
.dnDevNode
= 0; /* FIXME */
489 /* normalize to lower case as in 'vidc' */
490 ((char*)&fccType
)[0] = tolower(((char*)&fccType
)[0]);
491 ((char*)&fccType
)[1] = tolower(((char*)&fccType
)[1]);
492 ((char*)&fccType
)[2] = tolower(((char*)&fccType
)[2]);
493 ((char*)&fccType
)[3] = tolower(((char*)&fccType
)[3]);
494 icopen
.fccType
= fccType
;
495 /* Seek the driver in the registry */
496 fourcc_to_string(codecname
, fccType
);
498 fourcc_to_string(codecname
+ 5, fccHandler
);
501 hdrv
= OpenDriver(codecname
, drv32W
, (LPARAM
)&icopen
);
505 /* The driver has been registered at runtime with its name */
506 hdrv
= OpenDriver(driver
->name
, NULL
, (LPARAM
)&icopen
);
511 whic
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC
));
514 CloseDriver(hdrv
, 0, 0);
518 whic
->driverproc
= NULL
;
519 whic
->type
= fccType
;
520 whic
->handler
= fccHandler
;
521 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
522 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
523 whic
->next
= MSVIDEO_FirstHic
;
524 MSVIDEO_FirstHic
= whic
;
526 TRACE("=> %p\n", whic
->hic
);
530 /***********************************************************************
531 * ICOpenFunction [MSVFW32.@]
533 HIC VFWAPI
ICOpenFunction(DWORD fccType
, DWORD fccHandler
, UINT wMode
, DRIVERPROC lpfnHandler
)
538 TRACE("(%s,%s,%d,%p)\n",
539 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wMode
, lpfnHandler
);
541 icopen
.dwSize
= sizeof(ICOPEN
);
542 icopen
.fccType
= fccType
;
543 icopen
.fccHandler
= fccHandler
;
544 icopen
.dwVersion
= ICVERSION
;
545 icopen
.dwFlags
= wMode
;
547 icopen
.pV1Reserved
= NULL
;
548 icopen
.pV2Reserved
= NULL
;
549 icopen
.dnDevNode
= 0; /* FIXME */
551 whic
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC
));
554 whic
->driverproc
= lpfnHandler
;
555 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
556 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
557 whic
->next
= MSVIDEO_FirstHic
;
558 MSVIDEO_FirstHic
= whic
;
560 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
561 /* What if the function is used more than once? */
563 if (MSVIDEO_SendMessage(whic
, DRV_LOAD
, 0L, 0L) != DRV_SUCCESS
)
565 WARN("DRV_LOAD failed for hic %p\n", whic
->hic
);
566 MSVIDEO_FirstHic
= whic
->next
;
567 HeapFree(GetProcessHeap(), 0, whic
);
570 /* return value is not checked */
571 MSVIDEO_SendMessage(whic
, DRV_ENABLE
, 0L, 0L);
573 whic
->driverId
= (DWORD
)MSVIDEO_SendMessage(whic
, DRV_OPEN
, 0, (DWORD_PTR
)&icopen
);
574 /* FIXME: What should we put here? */
577 if (whic
->driverId
== 0)
579 WARN("DRV_OPEN failed for hic %p\n", whic
->hic
);
580 MSVIDEO_FirstHic
= whic
->next
;
581 HeapFree(GetProcessHeap(), 0, whic
);
585 TRACE("=> %p\n", whic
->hic
);
589 /***********************************************************************
590 * ICGetInfo [MSVFW32.@]
592 LRESULT VFWAPI
ICGetInfo(HIC hic
, ICINFO
*picinfo
, DWORD cb
)
595 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
597 TRACE("(%p,%p,%d)\n", hic
, picinfo
, cb
);
599 if (!whic
) return ICERR_BADHANDLE
;
600 if (!picinfo
) return MMSYSERR_INVALPARAM
;
602 /* (WS) The field szDriver should be initialized because the driver
603 * is not obliged and often will not do it. Some applications, like
604 * VirtualDub, rely on this field and will occasionally crash if it
605 * goes uninitialized.
607 if (cb
>= sizeof(ICINFO
)) picinfo
->szDriver
[0] = '\0';
609 ret
= ICSendMessage(hic
, ICM_GETINFO
, (DWORD_PTR
)picinfo
, cb
);
611 /* (WS) When szDriver was not supplied by the driver itself, apparently
612 * Windows will set its value equal to the driver file name. This can
613 * be obtained from the registry as we do here.
615 if (cb
>= sizeof(ICINFO
) && picinfo
->szDriver
[0] == 0)
619 memset(&ii
, 0, sizeof(ii
));
620 ii
.dwSize
= sizeof(ii
);
621 ICInfo(picinfo
->fccType
, picinfo
->fccHandler
, &ii
);
622 lstrcpyW(picinfo
->szDriver
, ii
.szDriver
);
625 TRACE(" -> %s\n", wine_dbgstr_icerr(ret
));
632 LPBITMAPINFOHEADER lpbiIn
;
633 LPBITMAPINFOHEADER lpbiOut
;
639 static HIC
try_driver(driver_info_t
*info
)
643 if ((hic
= ICOpen(info
->fccType
, info
->fccHandler
, info
->wMode
)))
645 if (!ICSendMessage(hic
, info
->querymsg
, (DWORD_PTR
)info
->lpbiIn
, (DWORD_PTR
)info
->lpbiOut
))
652 static BOOL
ICLocate_enum_handler(const char *drv
, unsigned int nr
, void *param
)
654 driver_info_t
*info
= param
;
655 info
->fccHandler
= mmioStringToFOURCCA(drv
+ 5, 0);
656 info
->hic
= try_driver(info
);
657 return info
->hic
!= 0;
660 /***********************************************************************
661 * ICLocate [MSVFW32.@]
663 HIC VFWAPI
ICLocate(DWORD fccType
, DWORD fccHandler
, LPBITMAPINFOHEADER lpbiIn
,
664 LPBITMAPINFOHEADER lpbiOut
, WORD wMode
)
668 TRACE("(%s,%s,%p,%p,0x%04x)\n",
669 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), lpbiIn
, lpbiOut
, wMode
);
671 info
.fccType
= fccType
;
672 info
.fccHandler
= fccHandler
;
673 info
.lpbiIn
= lpbiIn
;
674 info
.lpbiOut
= lpbiOut
;
679 case ICMODE_FASTCOMPRESS
:
680 case ICMODE_COMPRESS
:
681 info
.querymsg
= ICM_COMPRESS_QUERY
;
683 case ICMODE_FASTDECOMPRESS
:
684 case ICMODE_DECOMPRESS
:
685 info
.querymsg
= ICM_DECOMPRESS_QUERY
;
688 info
.querymsg
= ICM_DRAW_QUERY
;
691 WARN("Unknown mode (%d)\n", wMode
);
695 /* Easy case: handler/type match, we just fire a query and return */
696 info
.hic
= try_driver(&info
);
697 /* If it didn't work, try each driver in turn. 32 bit codecs only. */
698 /* FIXME: Move this to an init routine? */
699 if (!info
.hic
) enum_drivers(fccType
, ICLocate_enum_handler
, &info
);
703 TRACE("=> %p\n", info
.hic
);
707 if (fccType
== streamtypeVIDEO
)
708 return ICLocate(ICTYPE_VIDEO
, fccHandler
, lpbiIn
, lpbiOut
, wMode
);
710 ERR("Required media codec '%s %s' not found!\n",
711 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
));
715 /***********************************************************************
716 * ICGetDisplayFormat [MSVFW32.@]
718 HIC VFWAPI
ICGetDisplayFormat(
719 HIC hic
,LPBITMAPINFOHEADER lpbiIn
,LPBITMAPINFOHEADER lpbiOut
,
720 INT depth
,INT dx
,INT dy
)
724 TRACE("(%p,%p,%p,%d,%d,%d)!\n",hic
,lpbiIn
,lpbiOut
,depth
,dx
,dy
);
727 tmphic
=ICLocate(ICTYPE_VIDEO
,0,lpbiIn
,NULL
,ICMODE_DECOMPRESS
);
731 if ((dy
== lpbiIn
->biHeight
) && (dx
== lpbiIn
->biWidth
))
732 dy
= dx
= 0; /* no resize needed */
734 /* Can we decompress it ? */
735 if (ICDecompressQuery(tmphic
,lpbiIn
,NULL
) != 0)
736 goto errout
; /* no, sorry */
738 ICSendMessage(tmphic
, ICM_DECOMPRESS_GET_FORMAT
, (DWORD_PTR
)lpbiIn
, (DWORD_PTR
)lpbiOut
);
740 if (lpbiOut
->biCompression
!= 0) {
741 FIXME("Ooch, how come decompressor outputs compressed data (%d)??\n",
742 lpbiOut
->biCompression
);
744 if (lpbiOut
->biSize
< sizeof(*lpbiOut
)) {
745 FIXME("Ooch, size of output BIH is too small (%d)\n",
747 lpbiOut
->biSize
= sizeof(*lpbiOut
);
753 depth
= GetDeviceCaps(hdc
,BITSPIXEL
)*GetDeviceCaps(hdc
,PLANES
);
755 if (depth
==15) depth
= 16;
756 if (depth
<8) depth
= 8;
758 if (lpbiIn
->biBitCount
== 8)
761 TRACE("=> %p\n", tmphic
);
771 /***********************************************************************
772 * ICCompress [MSVFW32.@]
776 HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiOutput
,LPVOID lpData
,
777 LPBITMAPINFOHEADER lpbiInput
,LPVOID lpBits
,LPDWORD lpckid
,
778 LPDWORD lpdwFlags
,LONG lFrameNum
,DWORD dwFrameSize
,DWORD dwQuality
,
779 LPBITMAPINFOHEADER lpbiPrev
,LPVOID lpPrev
)
783 TRACE("(%p,%d,%p,%p,%p,%p,...)\n",hic
,dwFlags
,lpbiOutput
,lpData
,lpbiInput
,lpBits
);
785 iccmp
.dwFlags
= dwFlags
;
787 iccmp
.lpbiOutput
= lpbiOutput
;
788 iccmp
.lpOutput
= lpData
;
789 iccmp
.lpbiInput
= lpbiInput
;
790 iccmp
.lpInput
= lpBits
;
792 iccmp
.lpckid
= lpckid
;
793 iccmp
.lpdwFlags
= lpdwFlags
;
794 iccmp
.lFrameNum
= lFrameNum
;
795 iccmp
.dwFrameSize
= dwFrameSize
;
796 iccmp
.dwQuality
= dwQuality
;
797 iccmp
.lpbiPrev
= lpbiPrev
;
798 iccmp
.lpPrev
= lpPrev
;
799 return ICSendMessage(hic
,ICM_COMPRESS
,(DWORD_PTR
)&iccmp
,sizeof(iccmp
));
802 /***********************************************************************
803 * ICDecompress [MSVFW32.@]
805 DWORD VFWAPIV
ICDecompress(HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiFormat
,
806 LPVOID lpData
,LPBITMAPINFOHEADER lpbi
,LPVOID lpBits
)
811 TRACE("(%p,%d,%p,%p,%p,%p)\n",hic
,dwFlags
,lpbiFormat
,lpData
,lpbi
,lpBits
);
813 icd
.dwFlags
= dwFlags
;
814 icd
.lpbiInput
= lpbiFormat
;
815 icd
.lpInput
= lpData
;
817 icd
.lpbiOutput
= lpbi
;
818 icd
.lpOutput
= lpBits
;
820 ret
= ICSendMessage(hic
,ICM_DECOMPRESS
,(DWORD_PTR
)&icd
,sizeof(ICDECOMPRESS
));
822 TRACE("-> %s\n",wine_dbgstr_icerr(ret
));
828 struct choose_compressor
841 static BOOL
enum_compressors(HWND list
, COMPVARS
*pcv
, BOOL enum_all
)
848 while (ICInfo(pcv
->fccType
, id
, &icinfo
))
850 struct codec_info
*ic
;
856 hic
= ICOpen(icinfo
.fccType
, icinfo
.fccHandler
, ICMODE_COMPRESS
);
860 /* for unknown reason fccHandler reported by the driver
861 * doesn't always work, use the one returned by ICInfo instead.
863 DWORD fccHandler
= icinfo
.fccHandler
;
865 if (!enum_all
&& pcv
->lpbiIn
)
867 if (ICCompressQuery(hic
, pcv
->lpbiIn
, NULL
) != ICERR_OK
)
869 TRACE("fccHandler %s doesn't support input DIB format %d\n",
870 wine_dbgstr_fcc(icinfo
.fccHandler
), pcv
->lpbiIn
->bmiHeader
.biCompression
);
876 ICGetInfo(hic
, &icinfo
, sizeof(icinfo
));
877 icinfo
.fccHandler
= fccHandler
;
879 idx
= SendMessageW(list
, CB_ADDSTRING
, 0, (LPARAM
)icinfo
.szDescription
);
881 ic
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info
));
884 SendMessageW(list
, CB_SETITEMDATA
, idx
, (LPARAM
)ic
);
892 static INT_PTR CALLBACK
icm_choose_compressor_dlgproc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
898 struct codec_info
*ic
;
900 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)lparam
;
902 SetWindowLongPtrW(hdlg
, DWLP_USER
, lparam
);
905 choose_comp
->flags
&= ~(ICMF_CHOOSE_DATARATE
| ICMF_CHOOSE_KEYFRAME
);
907 if (choose_comp
->title
)
908 SetWindowTextA(hdlg
, choose_comp
->title
);
910 if (!(choose_comp
->flags
& ICMF_CHOOSE_DATARATE
))
912 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_CHECKBOX
), SW_HIDE
);
913 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE
), SW_HIDE
);
914 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_KB
), SW_HIDE
);
917 if (!(choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
))
919 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_CHECKBOX
), SW_HIDE
);
920 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME
), SW_HIDE
);
921 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_FRAMES
), SW_HIDE
);
925 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_SCROLL
), FALSE
);
926 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_TXT
), FALSE
);
928 /*if (!(choose_comp->flags & ICMF_CHOOSE_PREVIEW))
929 ShowWindow(GetDlgItem(hdlg, IDC_PREVIEW), SW_HIDE);*/
931 LoadStringW(MSVFW32_hModule
, IDS_FULLFRAMES
, buf
, 128);
932 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
934 ic
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info
));
935 ic
->icinfo
.fccType
= streamtypeVIDEO
;
936 ic
->icinfo
.fccHandler
= comptypeDIB
;
938 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETITEMDATA
, 0, (LPARAM
)ic
);
940 enum_compressors(GetDlgItem(hdlg
, IDC_COMP_LIST
), &choose_comp
->cv
, choose_comp
->flags
& ICMF_CHOOSE_ALLCOMPRESSORS
);
942 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETCURSEL
, 0, 0);
943 SetFocus(GetDlgItem(hdlg
, IDC_COMP_LIST
));
945 SetWindowLongPtrW(hdlg
, DWLP_USER
, (ULONG_PTR
)choose_comp
);
950 switch (LOWORD(wparam
))
955 struct codec_info
*ic
;
956 BOOL can_configure
= FALSE
, can_about
= FALSE
;
957 struct choose_compressor
*choose_comp
;
959 if (HIWORD(wparam
) != CBN_SELCHANGE
&& HIWORD(wparam
) != CBN_SETFOCUS
)
962 choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
964 cur_sel
= SendMessageW((HWND
)lparam
, CB_GETCURSEL
, 0, 0);
966 ic
= (struct codec_info
*)SendMessageW((HWND
)lparam
, CB_GETITEMDATA
, cur_sel
, 0);
969 if (ICQueryConfigure(ic
->hic
) == DRVCNF_OK
)
970 can_configure
= TRUE
;
971 if (ICQueryAbout(ic
->hic
) == DRVCNF_OK
)
974 EnableWindow(GetDlgItem(hdlg
, IDC_CONFIGURE
), can_configure
);
975 EnableWindow(GetDlgItem(hdlg
, IDC_ABOUT
), can_about
);
977 if (choose_comp
->flags
& ICMF_CHOOSE_DATARATE
)
981 if (choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
)
992 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
994 struct codec_info
*ic
;
996 if (HIWORD(wparam
) != BN_CLICKED
)
999 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
1001 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1004 if (LOWORD(wparam
) == IDC_CONFIGURE
)
1005 ICConfigure(ic
->hic
, hdlg
);
1007 ICAbout(ic
->hic
, hdlg
);
1015 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1017 struct codec_info
*ic
;
1019 if (HIWORD(wparam
) != BN_CLICKED
)
1022 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
1023 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1026 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
1028 choose_comp
->cv
.hic
= ic
->hic
;
1029 choose_comp
->cv
.fccType
= ic
->icinfo
.fccType
;
1030 choose_comp
->cv
.fccHandler
= ic
->icinfo
.fccHandler
;
1031 /* FIXME: fill everything else */
1033 /* prevent closing the codec handle below */
1040 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1043 if (HIWORD(wparam
) != BN_CLICKED
)
1048 struct codec_info
*ic
;
1050 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, idx
++, 0);
1052 if (!ic
|| (LONG_PTR
)ic
== CB_ERR
) break;
1054 if (ic
->hic
) ICClose(ic
->hic
);
1055 HeapFree(GetProcessHeap(), 0, ic
);
1058 EndDialog(hdlg
, LOWORD(wparam
) == IDOK
);
1074 /***********************************************************************
1075 * ICCompressorChoose [MSVFW32.@]
1077 BOOL VFWAPI
ICCompressorChoose(HWND hwnd
, UINT uiFlags
, LPVOID pvIn
,
1078 LPVOID lpData
, PCOMPVARS pc
, LPSTR lpszTitle
)
1080 struct choose_compressor choose_comp
;
1083 TRACE("(%p,%08x,%p,%p,%p,%s)\n", hwnd
, uiFlags
, pvIn
, lpData
, pc
, lpszTitle
);
1085 if (!pc
|| pc
->cbSize
!= sizeof(COMPVARS
))
1088 if (!(pc
->dwFlags
& ICMF_COMPVARS_VALID
))
1091 pc
->fccType
= pc
->fccHandler
= 0;
1095 pc
->lpBitsOut
= pc
->lpBitsPrev
= pc
->lpState
= NULL
;
1096 pc
->lQ
= ICQUALITY_DEFAULT
;
1098 pc
->lDataRate
= 300; /* kB */
1102 if (pc
->fccType
== 0)
1103 pc
->fccType
= ICTYPE_VIDEO
;
1105 choose_comp
.cv
= *pc
;
1106 choose_comp
.flags
= uiFlags
;
1107 choose_comp
.title
= lpszTitle
;
1109 ret
= DialogBoxParamW(MSVFW32_hModule
, MAKEINTRESOURCEW(ICM_CHOOSE_COMPRESSOR
), hwnd
,
1110 icm_choose_compressor_dlgproc
, (LPARAM
)&choose_comp
);
1114 *pc
= choose_comp
.cv
;
1115 pc
->dwFlags
|= ICMF_COMPVARS_VALID
;
1122 /***********************************************************************
1123 * ICCompressorFree [MSVFW32.@]
1125 void VFWAPI
ICCompressorFree(PCOMPVARS pc
)
1129 if (pc
!= NULL
&& pc
->cbSize
== sizeof(COMPVARS
)) {
1130 if (pc
->hic
!= NULL
) {
1134 HeapFree(GetProcessHeap(), 0, pc
->lpbiIn
);
1136 HeapFree(GetProcessHeap(), 0, pc
->lpBitsOut
);
1137 pc
->lpBitsOut
= NULL
;
1138 HeapFree(GetProcessHeap(), 0, pc
->lpBitsPrev
);
1139 pc
->lpBitsPrev
= NULL
;
1140 HeapFree(GetProcessHeap(), 0, pc
->lpState
);
1146 /***********************************************************************
1147 * ICSendMessage [MSVFW32.@]
1149 LRESULT VFWAPI
ICSendMessage(HIC hic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
1151 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1153 if (!whic
) return ICERR_BADHANDLE
;
1154 return MSVIDEO_SendMessage(whic
, msg
, lParam1
, lParam2
);
1157 /***********************************************************************
1158 * ICDrawBegin [MSVFW32.@]
1160 DWORD VFWAPIV
ICDrawBegin(
1162 DWORD dwFlags
, /* [in] flags */
1163 HPALETTE hpal
, /* [in] palette to draw with */
1164 HWND hwnd
, /* [in] window to draw to */
1165 HDC hdc
, /* [in] HDC to draw to */
1166 INT xDst
, /* [in] destination rectangle */
1167 INT yDst
, /* [in] */
1168 INT dxDst
, /* [in] */
1169 INT dyDst
, /* [in] */
1170 LPBITMAPINFOHEADER lpbi
, /* [in] format of frame to draw */
1171 INT xSrc
, /* [in] source rectangle */
1172 INT ySrc
, /* [in] */
1173 INT dxSrc
, /* [in] */
1174 INT dySrc
, /* [in] */
1175 DWORD dwRate
, /* [in] frames/second = (dwRate/dwScale) */
1176 DWORD dwScale
) /* [in] */
1181 TRACE("(%p,%d,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%d,%d)\n",
1182 hic
, dwFlags
, hpal
, hwnd
, hdc
, xDst
, yDst
, dxDst
, dyDst
,
1183 lpbi
, xSrc
, ySrc
, dxSrc
, dySrc
, dwRate
, dwScale
);
1185 icdb
.dwFlags
= dwFlags
;
1198 icdb
.dwRate
= dwRate
;
1199 icdb
.dwScale
= dwScale
;
1200 return ICSendMessage(hic
,ICM_DRAW_BEGIN
,(DWORD_PTR
)&icdb
,sizeof(icdb
));
1203 /***********************************************************************
1204 * ICDraw [MSVFW32.@]
1206 DWORD VFWAPIV
ICDraw(HIC hic
, DWORD dwFlags
, LPVOID lpFormat
, LPVOID lpData
, DWORD cbData
, LONG lTime
) {
1209 TRACE("(%p,%d,%p,%p,%d,%d)\n",hic
,dwFlags
,lpFormat
,lpData
,cbData
,lTime
);
1211 icd
.dwFlags
= dwFlags
;
1212 icd
.lpFormat
= lpFormat
;
1213 icd
.lpData
= lpData
;
1214 icd
.cbData
= cbData
;
1217 return ICSendMessage(hic
,ICM_DRAW
,(DWORD_PTR
)&icd
,sizeof(icd
));
1220 /***********************************************************************
1221 * ICClose [MSVFW32.@]
1223 LRESULT WINAPI
ICClose(HIC hic
)
1225 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1228 TRACE("(%p)\n",hic
);
1230 if (!whic
) return ICERR_BADHANDLE
;
1232 if (whic
->driverproc
)
1234 MSVIDEO_SendMessage(whic
, DRV_CLOSE
, 0, 0);
1235 MSVIDEO_SendMessage(whic
, DRV_DISABLE
, 0, 0);
1236 MSVIDEO_SendMessage(whic
, DRV_FREE
, 0, 0);
1240 CloseDriver(whic
->hdrv
, 0, 0);
1243 /* remove whic from list */
1244 for (p
= &MSVIDEO_FirstHic
; *p
!= NULL
; p
= &((*p
)->next
))
1253 HeapFree(GetProcessHeap(), 0, whic
);
1259 /***********************************************************************
1260 * ICImageCompress [MSVFW32.@]
1262 HANDLE VFWAPI
ICImageCompress(
1263 HIC hic
, UINT uiFlags
,
1264 LPBITMAPINFO lpbiIn
, LPVOID lpBits
,
1265 LPBITMAPINFO lpbiOut
, LONG lQuality
,
1268 FIXME("(%p,%08x,%p,%p,%p,%d,%p)\n",
1269 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
, lQuality
, plSize
);
1274 /***********************************************************************
1275 * ICImageDecompress [MSVFW32.@]
1278 HANDLE VFWAPI
ICImageDecompress(
1279 HIC hic
, UINT uiFlags
, LPBITMAPINFO lpbiIn
,
1280 LPVOID lpBits
, LPBITMAPINFO lpbiOut
)
1282 HGLOBAL hMem
= NULL
;
1284 BOOL bReleaseIC
= FALSE
;
1287 BOOL bSucceeded
= FALSE
;
1288 BOOL bInDecompress
= FALSE
;
1291 TRACE("(%p,%08x,%p,%p,%p)\n",
1292 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
);
1296 hic
= ICDecompressOpen( ICTYPE_VIDEO
, 0, &lpbiIn
->bmiHeader
, (lpbiOut
!= NULL
) ? &lpbiOut
->bmiHeader
: NULL
);
1299 WARN("no handler\n" );
1306 FIXME( "unknown flag %08x\n", uiFlags
);
1309 if ( lpbiIn
== NULL
|| lpBits
== NULL
)
1311 WARN("invalid argument\n");
1315 if ( lpbiOut
!= NULL
)
1317 if ( lpbiOut
->bmiHeader
.biSize
!= sizeof(BITMAPINFOHEADER
) )
1319 cbHdr
= sizeof(BITMAPINFOHEADER
);
1320 if ( lpbiOut
->bmiHeader
.biCompression
== 3 )
1321 cbHdr
+= sizeof(DWORD
)*3;
1323 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 )
1325 if ( lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1326 cbHdr
+= sizeof(RGBQUAD
) * (1<<lpbiOut
->bmiHeader
.biBitCount
);
1328 cbHdr
+= sizeof(RGBQUAD
) * lpbiOut
->bmiHeader
.biClrUsed
;
1333 TRACE( "get format\n" );
1335 cbHdr
= ICDecompressGetFormatSize(hic
,lpbiIn
);
1336 if ( cbHdr
< sizeof(BITMAPINFOHEADER
) )
1338 pHdr
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,cbHdr
+sizeof(RGBQUAD
)*256);
1341 if ( ICDecompressGetFormat( hic
, lpbiIn
, pHdr
) != ICERR_OK
)
1343 lpbiOut
= (BITMAPINFO
*)pHdr
;
1344 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1345 ICDecompressGetPalette( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
&&
1346 lpbiIn
->bmiHeader
.biBitCount
== lpbiOut
->bmiHeader
.biBitCount
)
1348 if ( lpbiIn
->bmiHeader
.biClrUsed
== 0 )
1349 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*(1<<lpbiOut
->bmiHeader
.biBitCount
) );
1351 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*lpbiIn
->bmiHeader
.biClrUsed
);
1353 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1354 lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1355 lpbiOut
->bmiHeader
.biClrUsed
= 1<<lpbiOut
->bmiHeader
.biBitCount
;
1357 lpbiOut
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1358 cbHdr
= sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
)*lpbiOut
->bmiHeader
.biClrUsed
;
1361 biSizeImage
= lpbiOut
->bmiHeader
.biSizeImage
;
1362 if ( biSizeImage
== 0 )
1363 biSizeImage
= ((((lpbiOut
->bmiHeader
.biWidth
* lpbiOut
->bmiHeader
.biBitCount
+ 7) >> 3) + 3) & (~3)) * abs(lpbiOut
->bmiHeader
.biHeight
);
1365 TRACE( "call ICDecompressBegin\n" );
1367 if ( ICDecompressBegin( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
)
1369 bInDecompress
= TRUE
;
1371 TRACE( "cbHdr %d, biSizeImage %d\n", cbHdr
, biSizeImage
);
1373 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_ZEROINIT
, cbHdr
+ biSizeImage
);
1376 WARN( "out of memory\n" );
1379 pMem
= GlobalLock( hMem
);
1382 memcpy( pMem
, lpbiOut
, cbHdr
);
1384 TRACE( "call ICDecompress\n" );
1385 if ( ICDecompress( hic
, 0, &lpbiIn
->bmiHeader
, lpBits
, &lpbiOut
->bmiHeader
, pMem
+cbHdr
) != ICERR_OK
)
1390 if ( bInDecompress
)
1391 ICDecompressEnd( hic
);
1394 HeapFree(GetProcessHeap(),0,pHdr
);
1396 GlobalUnlock( hMem
);
1397 if ( !bSucceeded
&& hMem
!= NULL
)
1399 GlobalFree(hMem
); hMem
= NULL
;
1405 /***********************************************************************
1406 * ICSeqCompressFrame [MSVFW32.@]
1408 LPVOID VFWAPI
ICSeqCompressFrame(PCOMPVARS pc
, UINT uiFlags
, LPVOID lpBits
, BOOL
*pfKey
, LONG
*plSize
)
1410 ICCOMPRESS
* icComp
= pc
->lpState
;
1412 TRACE("(%p, 0x%08x, %p, %p, %p)\n", pc
, uiFlags
, lpBits
, pfKey
, plSize
);
1414 if (pc
->cbState
!= sizeof(ICCOMPRESS
))
1416 ERR("Invalid cbState %i\n", pc
->cbState
);
1420 if (!pc
->lKeyCount
++)
1421 icComp
->dwFlags
= ICCOMPRESS_KEYFRAME
;
1424 if (pc
->lKey
&& pc
->lKeyCount
== (pc
->lKey
- 1))
1425 /* No key frames if pc->lKey == 0 */
1427 icComp
->dwFlags
= 0;
1430 icComp
->lpInput
= lpBits
;
1431 icComp
->lFrameNum
= pc
->lFrame
++;
1432 icComp
->lpOutput
= pc
->lpBitsOut
;
1433 icComp
->lpPrev
= pc
->lpBitsPrev
;
1434 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS
, (DWORD_PTR
)icComp
, sizeof(*icComp
));
1436 if (ret
== ICERR_OK
)
1438 LPVOID oldprev
, oldout
;
1440 if (icComp
->dwFlags
& AVIIF_KEYFRAME
)
1444 TRACE("Key frame\n");
1449 *plSize
= icComp
->lpbiOutput
->biSizeImage
;
1451 /* We shift Prev and Out, so we don't have to allocate and release memory */
1452 oldprev
= pc
->lpBitsPrev
;
1453 oldout
= pc
->lpBitsOut
;
1454 pc
->lpBitsPrev
= oldout
;
1455 pc
->lpBitsOut
= oldprev
;
1457 TRACE("returning: %p, compressed frame size %u\n", icComp
->lpOutput
, *plSize
);
1458 return icComp
->lpOutput
;
1463 static void clear_compvars(PCOMPVARS pc
)
1465 HeapFree(GetProcessHeap(), 0, pc
->lpbiIn
);
1466 HeapFree(GetProcessHeap(), 0, pc
->lpBitsPrev
);
1467 HeapFree(GetProcessHeap(), 0, pc
->lpBitsOut
);
1468 HeapFree(GetProcessHeap(), 0, pc
->lpState
);
1469 pc
->lpbiIn
= pc
->lpBitsPrev
= pc
->lpBitsOut
= pc
->lpState
= NULL
;
1470 if (pc
->dwFlags
& 0x80000000)
1472 HeapFree(GetProcessHeap(), 0, pc
->lpbiOut
);
1474 pc
->dwFlags
&= ~0x80000000;
1478 /***********************************************************************
1479 * ICSeqCompressFrameEnd [MSVFW32.@]
1481 void VFWAPI
ICSeqCompressFrameEnd(PCOMPVARS pc
)
1483 TRACE("(%p)\n", pc
);
1484 ICSendMessage(pc
->hic
, ICM_COMPRESS_END
, 0, 0);
1488 /***********************************************************************
1489 * ICSeqCompressFrameStart [MSVFW32.@]
1491 BOOL VFWAPI
ICSeqCompressFrameStart(PCOMPVARS pc
, LPBITMAPINFO lpbiIn
)
1493 /* I'm ignoring bmiColors as I don't know what to do with it,
1494 * it doesn't appear to be used though
1498 pc
->lpbiIn
= HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO
));
1502 *pc
->lpbiIn
= *lpbiIn
;
1504 pc
->lpState
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS
)
1505 + sizeof(*icComp
->lpckid
) + sizeof(*icComp
->lpdwFlags
));
1509 pc
->cbState
= sizeof(ICCOMPRESS
);
1513 /* Ask compressor for needed header size */
1514 int size
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1515 (DWORD_PTR
)pc
->lpbiIn
, 0);
1519 pc
->lpbiOut
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1522 /* Flag to show that we allocated lpbiOut for proper cleanup */
1523 pc
->dwFlags
|= 0x80000000;
1525 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1526 (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1527 if (ret
!= ICERR_OK
)
1529 ERR("Could not get output format from compressor\n");
1532 if (!pc
->lpbiOut
->bmiHeader
.biSizeImage
)
1534 /* If we can't know the output frame size for sure at least allocate
1535 * the same size of the input frame and also at least 8Kb to be sure
1536 * that poor compressors will have enough memory to work if the input
1537 * frame is too small.
1539 pc
->lpbiOut
->bmiHeader
.biSizeImage
= max(8192, pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1540 ERR("Bad codec! Invalid output frame size, guessing from input\n");
1544 TRACE("Input: %ux%u, fcc %s, bpp %u, size %u\n",
1545 pc
->lpbiIn
->bmiHeader
.biWidth
, pc
->lpbiIn
->bmiHeader
.biHeight
,
1546 wine_dbgstr_fcc(pc
->lpbiIn
->bmiHeader
.biCompression
),
1547 pc
->lpbiIn
->bmiHeader
.biBitCount
,
1548 pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1549 TRACE("Output: %ux%u, fcc %s, bpp %u, size %u\n",
1550 pc
->lpbiOut
->bmiHeader
.biWidth
, pc
->lpbiOut
->bmiHeader
.biHeight
,
1551 wine_dbgstr_fcc(pc
->lpbiOut
->bmiHeader
.biCompression
),
1552 pc
->lpbiOut
->bmiHeader
.biBitCount
,
1553 pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1555 /* Buffer for compressed frame data */
1556 pc
->lpBitsOut
= HeapAlloc(GetProcessHeap(), 0, pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1560 /* Buffer for previous compressed frame data */
1561 pc
->lpBitsPrev
= HeapAlloc(GetProcessHeap(), 0, pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1562 if (!pc
->lpBitsPrev
)
1572 "\tkey/data/quality: %i/%i/%i\n",
1573 pc
->cbSize
, pc
->dwFlags
, pc
->hic
, wine_dbgstr_fcc(pc
->fccType
),
1574 wine_dbgstr_fcc(pc
->fccHandler
), pc
->lpbiIn
, pc
->lpbiOut
, pc
->lKey
,
1575 pc
->lDataRate
, pc
->lQ
);
1577 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_BEGIN
, (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1578 if (ret
== ICERR_OK
)
1580 icComp
= pc
->lpState
;
1581 /* Initialise some variables */
1582 pc
->lFrame
= 0; pc
->lKeyCount
= 0;
1584 icComp
->lpbiOutput
= &pc
->lpbiOut
->bmiHeader
;
1585 icComp
->lpbiInput
= &pc
->lpbiIn
->bmiHeader
;
1586 icComp
->lpckid
= (DWORD
*)(icComp
+ 1);
1587 *icComp
->lpckid
= 0;
1588 icComp
->lpdwFlags
= (DWORD
*)((char *)(icComp
+ 1) + sizeof(*icComp
->lpckid
));
1589 *icComp
->lpdwFlags
= 0;
1590 icComp
->dwFrameSize
= 0;
1591 icComp
->dwQuality
= pc
->lQ
;
1592 icComp
->lpbiPrev
= &pc
->lpbiIn
->bmiHeader
;
1600 /***********************************************************************
1601 * GetFileNamePreview [MSVFW32.@]
1603 static BOOL
GetFileNamePreview(LPVOID lpofn
,BOOL bSave
,BOOL bUnicode
)
1605 CHAR szFunctionName
[20];
1606 BOOL (*fnGetFileName
)(LPVOID
);
1610 FIXME("(%p,%d,%d), semi-stub!\n",lpofn
,bSave
,bUnicode
);
1612 lstrcpyA(szFunctionName
, (bSave
? "GetSaveFileName" : "GetOpenFileName"));
1613 lstrcatA(szFunctionName
, (bUnicode
? "W" : "A"));
1615 hComdlg32
= LoadLibraryA("COMDLG32.DLL");
1616 if (hComdlg32
== NULL
)
1619 fnGetFileName
= (LPVOID
)GetProcAddress(hComdlg32
, szFunctionName
);
1620 if (fnGetFileName
== NULL
)
1622 FreeLibrary(hComdlg32
);
1626 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1627 ret
= fnGetFileName(lpofn
);
1629 FreeLibrary(hComdlg32
);
1633 /***********************************************************************
1634 * GetOpenFileNamePreviewA [MSVFW32.@]
1636 BOOL WINAPI
GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1638 FIXME("(%p), semi-stub!\n", lpofn
);
1640 return GetFileNamePreview(lpofn
, FALSE
, FALSE
);
1643 /***********************************************************************
1644 * GetOpenFileNamePreviewW [MSVFW32.@]
1646 BOOL WINAPI
GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1648 FIXME("(%p), semi-stub!\n", lpofn
);
1650 return GetFileNamePreview(lpofn
, FALSE
, TRUE
);
1653 /***********************************************************************
1654 * GetSaveFileNamePreviewA [MSVFW32.@]
1656 BOOL WINAPI
GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1658 FIXME("(%p), semi-stub!\n", lpofn
);
1660 return GetFileNamePreview(lpofn
, TRUE
, FALSE
);
1663 /***********************************************************************
1664 * GetSaveFileNamePreviewW [MSVFW32.@]
1666 BOOL WINAPI
GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1668 FIXME("(%p), semi-stub!\n", lpofn
);
1670 return GetFileNamePreview(lpofn
, TRUE
, TRUE
);