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 inline int get_stride(int width
, int depth
)
103 return ((depth
* width
+ 31) >> 3) & ~3;
106 static WINE_HIC
* MSVIDEO_FirstHic
/* = NULL */;
108 typedef struct _reg_driver reg_driver
;
118 static reg_driver
* reg_driver_list
= NULL
;
120 HMODULE MSVFW32_hModule
;
122 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
124 TRACE("%p,%x,%p\n", hinst
, reason
, reserved
);
128 case DLL_PROCESS_ATTACH
:
129 DisableThreadLibraryCalls(hinst
);
130 MSVFW32_hModule
= hinst
;
136 /******************************************************************
137 * MSVIDEO_SendMessage
141 static LRESULT
MSVIDEO_SendMessage(WINE_HIC
* whic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
145 #define XX(x) case x: TRACE("(%p,"#x",0x%08lx,0x%08lx)\n",whic,lParam1,lParam2); break
160 XX(ICM_GETDEFAULTQUALITY
);
167 XX(ICM_COMPRESS_FRAMES_INFO
);
168 XX(ICM_COMPRESS_GET_FORMAT
);
169 XX(ICM_COMPRESS_GET_SIZE
);
170 XX(ICM_COMPRESS_QUERY
);
171 XX(ICM_COMPRESS_BEGIN
);
173 XX(ICM_COMPRESS_END
);
174 XX(ICM_DECOMPRESS_GET_FORMAT
);
175 XX(ICM_DECOMPRESS_QUERY
);
176 XX(ICM_DECOMPRESS_BEGIN
);
178 XX(ICM_DECOMPRESS_END
);
179 XX(ICM_DECOMPRESS_SET_PALETTE
);
180 XX(ICM_DECOMPRESS_GET_PALETTE
);
183 XX(ICM_DRAW_GET_PALETTE
);
187 XX(ICM_DRAW_GETTIME
);
190 XX(ICM_DRAW_SETTIME
);
191 XX(ICM_DRAW_REALIZE
);
193 XX(ICM_DRAW_RENDERBUFFER
);
194 XX(ICM_DRAW_START_PLAY
);
195 XX(ICM_DRAW_STOP_PLAY
);
196 XX(ICM_DRAW_SUGGESTFORMAT
);
197 XX(ICM_DRAW_CHANGEPALETTE
);
198 XX(ICM_GETBUFFERSWANTED
);
199 XX(ICM_GETDEFAULTKEYFRAMERATE
);
200 XX(ICM_DECOMPRESSEX_BEGIN
);
201 XX(ICM_DECOMPRESSEX_QUERY
);
202 XX(ICM_DECOMPRESSEX
);
203 XX(ICM_DECOMPRESSEX_END
);
204 XX(ICM_SET_STATUS_PROC
);
206 FIXME("(%p,0x%08x,0x%08lx,0x%08lx) unknown message\n",whic
,msg
,lParam1
,lParam2
);
211 if (whic
->driverproc
) {
212 /* dwDriverId parameter is the value returned by the DRV_OPEN */
213 ret
= whic
->driverproc(whic
->driverId
, whic
->hdrv
, msg
, lParam1
, lParam2
);
215 ret
= SendDriverMessage(whic
->hdrv
, msg
, lParam1
, lParam2
);
218 TRACE(" -> %s\n", wine_dbgstr_icerr(ret
));
222 static int compare_fourcc(DWORD fcc1
, DWORD fcc2
)
226 fourcc_to_string(fcc_str1
, fcc1
);
227 fourcc_to_string(fcc_str2
, fcc2
);
228 return strncasecmp(fcc_str1
, fcc_str2
, 4);
231 typedef BOOL (*enum_handler_t
)(const char *name
, const char *driver
, unsigned int index
, void *param
);
233 static BOOL
enum_drivers(DWORD fccType
, enum_handler_t handler
, void* param
)
239 DWORD i
, cnt
= 0, lRet
;
243 fourcc_to_string(fccTypeStr
, fccType
);
245 /* first, go through the registry entries */
246 lRet
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, HKLM_DRIVERS32
, 0, KEY_QUERY_VALUE
, &hKey
);
247 if (lRet
== ERROR_SUCCESS
)
252 DWORD name_len
= 10, driver_len
= 128;
253 lRet
= RegEnumValueA(hKey
, i
++, name_buf
, &name_len
, 0, 0, (BYTE
*)buf
, &driver_len
);
254 if (lRet
== ERROR_NO_MORE_ITEMS
) break;
255 if (name_len
!= 9 || name_buf
[4] != '.') continue;
256 if (fccType
&& strncasecmp(name_buf
, fccTypeStr
, 4)) continue;
257 if ((result
= handler(name_buf
, buf
, cnt
++, param
))) break;
261 if (result
) return result
;
263 /* if that didn't work, go through the values in system.ini */
264 if (GetPrivateProfileSectionA("drivers32", buf
, sizeof(buf
), "system.ini"))
267 for (s
= buf
; *s
; s
+= strlen(s
) + 1)
269 if (s
[4] != '.' || s
[9] != '=') continue;
270 if (fccType
&& strncasecmp(s
, fccTypeStr
, 4)) continue;
271 if ((result
= handler(s
, s
+ 10, cnt
++, param
))) break;
278 /******************************************************************
283 static WINE_HIC
* MSVIDEO_GetHicPtr(HIC hic
)
287 for (whic
= MSVIDEO_FirstHic
; whic
&& whic
->hic
!= hic
; whic
= whic
->next
);
291 /***********************************************************************
292 * VideoForWindowsVersion [MSVFW32.2]
293 * VideoForWindowsVersion [MSVIDEO.2]
294 * Returns the version in major.minor form.
295 * In Windows95 this returns 0x040003b6 (4.950)
297 DWORD WINAPI
VideoForWindowsVersion(void)
299 return 0x040003B6; /* 4.950 */
302 static BOOL
ICInfo_enum_handler(const char *name
, const char *driver
, unsigned int nr
, void *param
)
304 ICINFO
*lpicinfo
= param
;
305 DWORD fccType
= mmioStringToFOURCCA(name
, 0);
306 DWORD fccHandler
= mmioStringToFOURCCA(name
+ 5, 0);
308 if (lpicinfo
->fccHandler
!= nr
&& compare_fourcc(lpicinfo
->fccHandler
, fccHandler
))
311 lpicinfo
->fccType
= fccType
;
312 lpicinfo
->fccHandler
= fccHandler
;
313 lpicinfo
->dwFlags
= 0;
314 lpicinfo
->dwVersion
= 0;
315 lpicinfo
->dwVersionICM
= ICVERSION
;
316 lpicinfo
->szName
[0] = 0;
317 lpicinfo
->szDescription
[0] = 0;
318 MultiByteToWideChar(CP_ACP
, 0, driver
, -1, lpicinfo
->szDriver
,
319 sizeof(lpicinfo
->szDriver
)/sizeof(WCHAR
));
324 /***********************************************************************
326 * Get information about an installable compressor. Return TRUE if there
330 * fccType [I] type of compressor (e.g. 'vidc')
331 * fccHandler [I] real fcc for handler or <n>th compressor
332 * lpicinfo [O] information about compressor
334 BOOL VFWAPI
ICInfo( DWORD fccType
, DWORD fccHandler
, ICINFO
*lpicinfo
)
336 TRACE("(%s,%s,%p)\n",
337 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), lpicinfo
);
339 lpicinfo
->fccType
= fccType
;
340 lpicinfo
->fccHandler
= fccHandler
;
341 return enum_drivers(fccType
, ICInfo_enum_handler
, lpicinfo
);
344 static DWORD IC_HandleRef
= 1;
346 /***********************************************************************
347 * ICInstall [MSVFW32.@]
349 BOOL VFWAPI
ICInstall(DWORD fccType
, DWORD fccHandler
, LPARAM lParam
, LPSTR szDesc
, UINT wFlags
)
354 TRACE("(%s,%s,%p,%p,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), (void*)lParam
, szDesc
, wFlags
);
356 /* Check if a driver is already registered */
357 for (driver
= reg_driver_list
; driver
; driver
= driver
->next
)
359 if (!compare_fourcc(fccType
, driver
->fccType
) &&
360 !compare_fourcc(fccHandler
, driver
->fccHandler
))
363 if (driver
) return FALSE
;
365 /* Register the driver */
366 driver
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(reg_driver
));
367 if (!driver
) goto oom
;
368 driver
->fccType
= fccType
;
369 driver
->fccHandler
= fccHandler
;
373 case ICINSTALL_FUNCTION
:
374 driver
->proc
= (DRIVERPROC
)lParam
;
377 case ICINSTALL_DRIVER
:
379 len
= MultiByteToWideChar(CP_ACP
, 0, (char*)lParam
, -1, NULL
, 0);
380 driver
->name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
381 if (!driver
->name
) goto oom
;
382 MultiByteToWideChar(CP_ACP
, 0, (char*)lParam
, -1, driver
->name
, len
);
385 ERR("Invalid flags!\n");
386 HeapFree(GetProcessHeap(), 0, driver
);
390 /* Insert our driver in the list*/
391 driver
->next
= reg_driver_list
;
392 reg_driver_list
= driver
;
396 HeapFree(GetProcessHeap(), 0, driver
);
400 /***********************************************************************
401 * ICRemove [MSVFW32.@]
403 BOOL VFWAPI
ICRemove(DWORD fccType
, DWORD fccHandler
, UINT wFlags
)
405 reg_driver
** pdriver
;
408 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wFlags
);
410 /* Check if a driver is already registered */
411 for (pdriver
= ®_driver_list
; *pdriver
; pdriver
= &(*pdriver
)->next
)
413 if (!compare_fourcc(fccType
, (*pdriver
)->fccType
) &&
414 !compare_fourcc(fccHandler
, (*pdriver
)->fccHandler
))
420 /* Remove the driver from the list */
422 *pdriver
= (*pdriver
)->next
;
423 HeapFree(GetProcessHeap(), 0, drv
->name
);
424 HeapFree(GetProcessHeap(), 0, drv
);
430 /***********************************************************************
432 * Opens an installable compressor. Return special handle.
434 HIC VFWAPI
ICOpen(DWORD fccType
, DWORD fccHandler
, UINT wMode
)
440 static const WCHAR drv32W
[] = {'d','r','i','v','e','r','s','3','2','\0'};
443 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wMode
);
445 if (!fccHandler
) /* No specific handler, return the first valid for wMode */
450 info
.dwSize
= sizeof(info
);
451 while(ICInfo(fccType
, loop
++, &info
))
453 /* Ensure fccHandler is not 0x0 because we will recurse on ICOpen */
456 local
= ICOpen(fccType
, info
.fccHandler
, wMode
);
459 TRACE("Returning %s as default handler for %s\n",
460 wine_dbgstr_fcc(info
.fccHandler
), wine_dbgstr_fcc(fccType
));
466 /* Check if there is a registered driver that matches */
467 driver
= reg_driver_list
;
469 if (!compare_fourcc(fccType
, driver
->fccType
) &&
470 !compare_fourcc(fccHandler
, driver
->fccHandler
)) {
471 fccType
= driver
->fccType
;
472 fccHandler
= driver
->fccHandler
;
475 driver
= driver
->next
;
477 if (driver
&& driver
->proc
)
478 /* The driver has been registered at runtime with its driverproc */
479 return ICOpenFunction(fccType
, fccHandler
, wMode
, driver
->proc
);
481 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
482 * same layout as ICOPEN
484 icopen
.dwSize
= sizeof(ICOPEN
);
485 icopen
.fccType
= fccType
;
486 icopen
.fccHandler
= fccHandler
;
487 icopen
.dwVersion
= 0x00001000; /* FIXME */
488 icopen
.dwFlags
= wMode
;
490 icopen
.pV1Reserved
= NULL
;
491 icopen
.pV2Reserved
= NULL
;
492 icopen
.dnDevNode
= 0; /* FIXME */
495 /* normalize to lower case as in 'vidc' */
496 ((char*)&fccType
)[0] = tolower(((char*)&fccType
)[0]);
497 ((char*)&fccType
)[1] = tolower(((char*)&fccType
)[1]);
498 ((char*)&fccType
)[2] = tolower(((char*)&fccType
)[2]);
499 ((char*)&fccType
)[3] = tolower(((char*)&fccType
)[3]);
500 icopen
.fccType
= fccType
;
501 /* Seek the driver in the registry */
502 fourcc_to_string(codecname
, fccType
);
504 fourcc_to_string(codecname
+ 5, fccHandler
);
507 hdrv
= OpenDriver(codecname
, drv32W
, (LPARAM
)&icopen
);
511 /* The driver has been registered at runtime with its name */
512 hdrv
= OpenDriver(driver
->name
, NULL
, (LPARAM
)&icopen
);
517 whic
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC
));
520 CloseDriver(hdrv
, 0, 0);
524 whic
->driverproc
= NULL
;
525 whic
->type
= fccType
;
526 whic
->handler
= fccHandler
;
527 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
528 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
529 whic
->next
= MSVIDEO_FirstHic
;
530 MSVIDEO_FirstHic
= whic
;
532 TRACE("=> %p\n", whic
->hic
);
536 /***********************************************************************
537 * ICOpenFunction [MSVFW32.@]
539 HIC VFWAPI
ICOpenFunction(DWORD fccType
, DWORD fccHandler
, UINT wMode
, DRIVERPROC lpfnHandler
)
544 TRACE("(%s,%s,%d,%p)\n",
545 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wMode
, lpfnHandler
);
547 icopen
.dwSize
= sizeof(ICOPEN
);
548 icopen
.fccType
= fccType
;
549 icopen
.fccHandler
= fccHandler
;
550 icopen
.dwVersion
= ICVERSION
;
551 icopen
.dwFlags
= wMode
;
553 icopen
.pV1Reserved
= NULL
;
554 icopen
.pV2Reserved
= NULL
;
555 icopen
.dnDevNode
= 0; /* FIXME */
557 whic
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC
));
560 whic
->driverproc
= lpfnHandler
;
561 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
562 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
563 whic
->next
= MSVIDEO_FirstHic
;
564 MSVIDEO_FirstHic
= whic
;
566 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
567 /* What if the function is used more than once? */
569 if (MSVIDEO_SendMessage(whic
, DRV_LOAD
, 0L, 0L) != DRV_SUCCESS
)
571 WARN("DRV_LOAD failed for hic %p\n", whic
->hic
);
572 MSVIDEO_FirstHic
= whic
->next
;
573 HeapFree(GetProcessHeap(), 0, whic
);
576 /* return value is not checked */
577 MSVIDEO_SendMessage(whic
, DRV_ENABLE
, 0L, 0L);
579 whic
->driverId
= (DWORD
)MSVIDEO_SendMessage(whic
, DRV_OPEN
, 0, (DWORD_PTR
)&icopen
);
580 /* FIXME: What should we put here? */
583 if (whic
->driverId
== 0)
585 WARN("DRV_OPEN failed for hic %p\n", whic
->hic
);
586 MSVIDEO_FirstHic
= whic
->next
;
587 HeapFree(GetProcessHeap(), 0, whic
);
591 TRACE("=> %p\n", whic
->hic
);
595 /***********************************************************************
596 * ICGetInfo [MSVFW32.@]
598 LRESULT VFWAPI
ICGetInfo(HIC hic
, ICINFO
*picinfo
, DWORD cb
)
601 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
603 TRACE("(%p,%p,%d)\n", hic
, picinfo
, cb
);
605 if (!whic
) return ICERR_BADHANDLE
;
606 if (!picinfo
) return MMSYSERR_INVALPARAM
;
608 /* (WS) The field szDriver should be initialized because the driver
609 * is not obliged and often will not do it. Some applications, like
610 * VirtualDub, rely on this field and will occasionally crash if it
611 * goes uninitialized.
613 if (cb
>= sizeof(ICINFO
)) picinfo
->szDriver
[0] = '\0';
615 ret
= ICSendMessage(hic
, ICM_GETINFO
, (DWORD_PTR
)picinfo
, cb
);
617 /* (WS) When szDriver was not supplied by the driver itself, apparently
618 * Windows will set its value equal to the driver file name. This can
619 * be obtained from the registry as we do here.
621 if (cb
>= sizeof(ICINFO
) && picinfo
->szDriver
[0] == 0)
625 memset(&ii
, 0, sizeof(ii
));
626 ii
.dwSize
= sizeof(ii
);
627 ICInfo(picinfo
->fccType
, picinfo
->fccHandler
, &ii
);
628 lstrcpyW(picinfo
->szDriver
, ii
.szDriver
);
637 LPBITMAPINFOHEADER lpbiIn
;
638 LPBITMAPINFOHEADER lpbiOut
;
644 static HIC
try_driver(driver_info_t
*info
)
648 if ((hic
= ICOpen(info
->fccType
, info
->fccHandler
, info
->wMode
)))
650 if (!ICSendMessage(hic
, info
->querymsg
, (DWORD_PTR
)info
->lpbiIn
, (DWORD_PTR
)info
->lpbiOut
))
657 static BOOL
ICLocate_enum_handler(const char *name
, const char *driver
, unsigned int nr
, void *param
)
659 driver_info_t
*info
= param
;
660 info
->fccHandler
= mmioStringToFOURCCA(name
+ 5, 0);
661 info
->hic
= try_driver(info
);
662 return info
->hic
!= 0;
665 /***********************************************************************
666 * ICLocate [MSVFW32.@]
668 HIC VFWAPI
ICLocate(DWORD fccType
, DWORD fccHandler
, LPBITMAPINFOHEADER lpbiIn
,
669 LPBITMAPINFOHEADER lpbiOut
, WORD wMode
)
673 TRACE("(%s,%s,%p,%p,0x%04x)\n",
674 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), lpbiIn
, lpbiOut
, wMode
);
676 info
.fccType
= fccType
;
677 info
.fccHandler
= fccHandler
;
678 info
.lpbiIn
= lpbiIn
;
679 info
.lpbiOut
= lpbiOut
;
684 case ICMODE_FASTCOMPRESS
:
685 case ICMODE_COMPRESS
:
686 info
.querymsg
= ICM_COMPRESS_QUERY
;
688 case ICMODE_FASTDECOMPRESS
:
689 case ICMODE_DECOMPRESS
:
690 info
.querymsg
= ICM_DECOMPRESS_QUERY
;
693 info
.querymsg
= ICM_DRAW_QUERY
;
696 WARN("Unknown mode (%d)\n", wMode
);
700 /* Easy case: handler/type match, we just fire a query and return */
701 info
.hic
= try_driver(&info
);
702 /* If it didn't work, try each driver in turn. 32 bit codecs only. */
703 /* FIXME: Move this to an init routine? */
704 if (!info
.hic
) enum_drivers(fccType
, ICLocate_enum_handler
, &info
);
708 TRACE("=> %p\n", info
.hic
);
712 if (fccType
== streamtypeVIDEO
)
713 return ICLocate(ICTYPE_VIDEO
, fccHandler
, lpbiIn
, lpbiOut
, wMode
);
715 ERR("Required media codec '%s %s' not found!\n",
716 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
));
720 /***********************************************************************
721 * ICGetDisplayFormat [MSVFW32.@]
723 HIC VFWAPI
ICGetDisplayFormat(
724 HIC hic
,LPBITMAPINFOHEADER lpbiIn
,LPBITMAPINFOHEADER lpbiOut
,
725 INT depth
,INT dx
,INT dy
)
746 TRACE("(%p,%p,%p,%d,%d,%d)!\n", hic
, lpbiIn
, lpbiOut
, depth
, dx
, dy
);
748 tmphic
= hic
? hic
: ICLocate(ICTYPE_VIDEO
, 0, lpbiIn
, NULL
, ICMODE_DECOMPRESS
);
749 if (!tmphic
) return tmphic
;
752 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
) * GetDeviceCaps(hdc
, PLANES
);
755 if (dx
<= 0) dx
= lpbiIn
->biWidth
;
756 if (dy
<= 0) dy
= lpbiIn
->biHeight
;
757 if (!depth
) depth
= screen_depth
;
759 /* Can we decompress it ? */
760 if (ICDecompressQuery(tmphic
, lpbiIn
, NULL
) != ICERR_OK
)
761 goto errout
; /* no, sorry */
763 ICSendMessage(tmphic
, ICM_DECOMPRESS_GET_FORMAT
, (DWORD_PTR
)lpbiIn
, (DWORD_PTR
)lpbiOut
);
765 lpbiOut
->biSize
= sizeof(BITMAPINFOHEADER
);
766 lpbiOut
->biWidth
= dx
;
767 lpbiOut
->biHeight
= dy
;
768 lpbiOut
->biPlanes
= 1;
770 for (i
= 0; i
< sizeof(try_depths
) / sizeof(try_depths
[0]); i
++)
772 if (!found
&& try_depths
[i
].depth
!= depth
)
776 lpbiOut
->biBitCount
= try_depths
[i
].depth
;
777 lpbiOut
->biCompression
= try_depths
[i
].compression
;
778 lpbiOut
->biSizeImage
= dx
* get_stride(dy
, lpbiOut
->biBitCount
);
780 if (ICDecompressQuery(tmphic
, lpbiIn
, lpbiOut
) == ICERR_OK
)
782 if (try_depths
[i
].depth
== 8)
783 ICDecompressGetPalette(tmphic
, lpbiIn
, lpbiOut
);
790 lpbiOut
->biBitCount
= depth
;
791 lpbiOut
->biCompression
= BI_RGB
;
792 lpbiOut
->biSizeImage
= dx
* get_stride(dy
, lpbiOut
->biBitCount
);
793 if (ICDecompressQuery(tmphic
, lpbiIn
, lpbiOut
) == ICERR_OK
)
796 lpbiOut
->biBitCount
= screen_depth
;
797 lpbiOut
->biCompression
= BI_RGB
;
798 lpbiOut
->biSizeImage
= dx
* get_stride(dy
, lpbiOut
->biBitCount
);
799 if (ICDecompressQuery(tmphic
, lpbiIn
, lpbiOut
) == ICERR_OK
)
803 if (ICSendMessage(tmphic
, ICM_DECOMPRESS_GET_FORMAT
, (DWORD_PTR
)lpbiIn
, (DWORD_PTR
)lpbiOut
))
806 if (lpbiOut
->biCompression
!= 0) {
807 FIXME("Ooch, how come decompressor outputs compressed data (%d)??\n",
808 lpbiOut
->biCompression
);
810 if (lpbiOut
->biSize
< sizeof(*lpbiOut
)) {
811 FIXME("Ooch, size of output BIH is too small (%d)\n",
813 lpbiOut
->biSize
= sizeof(*lpbiOut
);
817 TRACE("=> %p\n", tmphic
);
828 /***********************************************************************
829 * ICCompress [MSVFW32.@]
833 HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiOutput
,LPVOID lpData
,
834 LPBITMAPINFOHEADER lpbiInput
,LPVOID lpBits
,LPDWORD lpckid
,
835 LPDWORD lpdwFlags
,LONG lFrameNum
,DWORD dwFrameSize
,DWORD dwQuality
,
836 LPBITMAPINFOHEADER lpbiPrev
,LPVOID lpPrev
)
840 TRACE("(%p,%d,%p,%p,%p,%p,...)\n",hic
,dwFlags
,lpbiOutput
,lpData
,lpbiInput
,lpBits
);
842 iccmp
.dwFlags
= dwFlags
;
844 iccmp
.lpbiOutput
= lpbiOutput
;
845 iccmp
.lpOutput
= lpData
;
846 iccmp
.lpbiInput
= lpbiInput
;
847 iccmp
.lpInput
= lpBits
;
849 iccmp
.lpckid
= lpckid
;
850 iccmp
.lpdwFlags
= lpdwFlags
;
851 iccmp
.lFrameNum
= lFrameNum
;
852 iccmp
.dwFrameSize
= dwFrameSize
;
853 iccmp
.dwQuality
= dwQuality
;
854 iccmp
.lpbiPrev
= lpbiPrev
;
855 iccmp
.lpPrev
= lpPrev
;
856 return ICSendMessage(hic
,ICM_COMPRESS
,(DWORD_PTR
)&iccmp
,sizeof(iccmp
));
859 /***********************************************************************
860 * ICDecompress [MSVFW32.@]
862 DWORD VFWAPIV
ICDecompress(HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiFormat
,
863 LPVOID lpData
,LPBITMAPINFOHEADER lpbi
,LPVOID lpBits
)
868 TRACE("(%p,%d,%p,%p,%p,%p)\n",hic
,dwFlags
,lpbiFormat
,lpData
,lpbi
,lpBits
);
870 icd
.dwFlags
= dwFlags
;
871 icd
.lpbiInput
= lpbiFormat
;
872 icd
.lpInput
= lpData
;
874 icd
.lpbiOutput
= lpbi
;
875 icd
.lpOutput
= lpBits
;
877 ret
= ICSendMessage(hic
,ICM_DECOMPRESS
,(DWORD_PTR
)&icd
,sizeof(ICDECOMPRESS
));
883 struct choose_compressor
896 static BOOL
enum_compressors(HWND list
, COMPVARS
*pcv
, BOOL enum_all
)
903 while (ICInfo(pcv
->fccType
, id
, &icinfo
))
905 struct codec_info
*ic
;
911 hic
= ICOpen(icinfo
.fccType
, icinfo
.fccHandler
, ICMODE_COMPRESS
);
915 /* for unknown reason fccHandler reported by the driver
916 * doesn't always work, use the one returned by ICInfo instead.
918 DWORD fccHandler
= icinfo
.fccHandler
;
920 if (!enum_all
&& pcv
->lpbiIn
)
922 if (ICCompressQuery(hic
, pcv
->lpbiIn
, NULL
) != ICERR_OK
)
924 TRACE("fccHandler %s doesn't support input DIB format %d\n",
925 wine_dbgstr_fcc(icinfo
.fccHandler
), pcv
->lpbiIn
->bmiHeader
.biCompression
);
931 ICGetInfo(hic
, &icinfo
, sizeof(icinfo
));
932 icinfo
.fccHandler
= fccHandler
;
934 idx
= SendMessageW(list
, CB_ADDSTRING
, 0, (LPARAM
)icinfo
.szDescription
);
936 ic
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info
));
939 SendMessageW(list
, CB_SETITEMDATA
, idx
, (LPARAM
)ic
);
947 static INT_PTR CALLBACK
icm_choose_compressor_dlgproc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
953 struct codec_info
*ic
;
955 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)lparam
;
957 SetWindowLongPtrW(hdlg
, DWLP_USER
, lparam
);
960 choose_comp
->flags
&= ~(ICMF_CHOOSE_DATARATE
| ICMF_CHOOSE_KEYFRAME
);
962 if (choose_comp
->title
)
963 SetWindowTextA(hdlg
, choose_comp
->title
);
965 if (!(choose_comp
->flags
& ICMF_CHOOSE_DATARATE
))
967 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_CHECKBOX
), SW_HIDE
);
968 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE
), SW_HIDE
);
969 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_KB
), SW_HIDE
);
972 if (!(choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
))
974 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_CHECKBOX
), SW_HIDE
);
975 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME
), SW_HIDE
);
976 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_FRAMES
), SW_HIDE
);
980 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_SCROLL
), FALSE
);
981 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_TXT
), FALSE
);
983 /*if (!(choose_comp->flags & ICMF_CHOOSE_PREVIEW))
984 ShowWindow(GetDlgItem(hdlg, IDC_PREVIEW), SW_HIDE);*/
986 LoadStringW(MSVFW32_hModule
, IDS_FULLFRAMES
, buf
, 128);
987 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
989 ic
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info
));
990 ic
->icinfo
.fccType
= streamtypeVIDEO
;
991 ic
->icinfo
.fccHandler
= comptypeDIB
;
993 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETITEMDATA
, 0, (LPARAM
)ic
);
995 enum_compressors(GetDlgItem(hdlg
, IDC_COMP_LIST
), &choose_comp
->cv
, choose_comp
->flags
& ICMF_CHOOSE_ALLCOMPRESSORS
);
997 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETCURSEL
, 0, 0);
998 SetFocus(GetDlgItem(hdlg
, IDC_COMP_LIST
));
1000 SetWindowLongPtrW(hdlg
, DWLP_USER
, (ULONG_PTR
)choose_comp
);
1005 switch (LOWORD(wparam
))
1010 struct codec_info
*ic
;
1011 BOOL can_configure
= FALSE
, can_about
= FALSE
;
1012 struct choose_compressor
*choose_comp
;
1014 if (HIWORD(wparam
) != CBN_SELCHANGE
&& HIWORD(wparam
) != CBN_SETFOCUS
)
1017 choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
1019 cur_sel
= SendMessageW((HWND
)lparam
, CB_GETCURSEL
, 0, 0);
1021 ic
= (struct codec_info
*)SendMessageW((HWND
)lparam
, CB_GETITEMDATA
, cur_sel
, 0);
1024 if (ICQueryConfigure(ic
->hic
) == DRVCNF_OK
)
1025 can_configure
= TRUE
;
1026 if (ICQueryAbout(ic
->hic
) == DRVCNF_OK
)
1029 EnableWindow(GetDlgItem(hdlg
, IDC_CONFIGURE
), can_configure
);
1030 EnableWindow(GetDlgItem(hdlg
, IDC_ABOUT
), can_about
);
1032 if (choose_comp
->flags
& ICMF_CHOOSE_DATARATE
)
1036 if (choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
)
1047 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1049 struct codec_info
*ic
;
1051 if (HIWORD(wparam
) != BN_CLICKED
)
1054 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
1056 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1059 if (LOWORD(wparam
) == IDC_CONFIGURE
)
1060 ICConfigure(ic
->hic
, hdlg
);
1062 ICAbout(ic
->hic
, hdlg
);
1070 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1072 struct codec_info
*ic
;
1074 if (HIWORD(wparam
) != BN_CLICKED
)
1077 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
1078 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1081 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
1083 choose_comp
->cv
.hic
= ic
->hic
;
1084 choose_comp
->cv
.fccType
= ic
->icinfo
.fccType
;
1085 choose_comp
->cv
.fccHandler
= ic
->icinfo
.fccHandler
;
1086 /* FIXME: fill everything else */
1088 /* prevent closing the codec handle below */
1095 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1098 if (HIWORD(wparam
) != BN_CLICKED
)
1103 struct codec_info
*ic
;
1105 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, idx
++, 0);
1107 if (!ic
|| (LONG_PTR
)ic
== CB_ERR
) break;
1109 if (ic
->hic
) ICClose(ic
->hic
);
1110 HeapFree(GetProcessHeap(), 0, ic
);
1113 EndDialog(hdlg
, LOWORD(wparam
) == IDOK
);
1129 /***********************************************************************
1130 * ICCompressorChoose [MSVFW32.@]
1132 BOOL VFWAPI
ICCompressorChoose(HWND hwnd
, UINT uiFlags
, LPVOID pvIn
,
1133 LPVOID lpData
, PCOMPVARS pc
, LPSTR lpszTitle
)
1135 struct choose_compressor choose_comp
;
1138 TRACE("(%p,%08x,%p,%p,%p,%s)\n", hwnd
, uiFlags
, pvIn
, lpData
, pc
, lpszTitle
);
1140 if (!pc
|| pc
->cbSize
!= sizeof(COMPVARS
))
1143 if (!(pc
->dwFlags
& ICMF_COMPVARS_VALID
))
1146 pc
->fccType
= pc
->fccHandler
= 0;
1150 pc
->lpBitsOut
= pc
->lpBitsPrev
= pc
->lpState
= NULL
;
1151 pc
->lQ
= ICQUALITY_DEFAULT
;
1153 pc
->lDataRate
= 300; /* kB */
1157 if (pc
->fccType
== 0)
1158 pc
->fccType
= ICTYPE_VIDEO
;
1160 choose_comp
.cv
= *pc
;
1161 choose_comp
.flags
= uiFlags
;
1162 choose_comp
.title
= lpszTitle
;
1164 ret
= DialogBoxParamW(MSVFW32_hModule
, MAKEINTRESOURCEW(ICM_CHOOSE_COMPRESSOR
), hwnd
,
1165 icm_choose_compressor_dlgproc
, (LPARAM
)&choose_comp
);
1169 *pc
= choose_comp
.cv
;
1170 pc
->dwFlags
|= ICMF_COMPVARS_VALID
;
1177 /***********************************************************************
1178 * ICCompressorFree [MSVFW32.@]
1180 void VFWAPI
ICCompressorFree(PCOMPVARS pc
)
1184 if (pc
!= NULL
&& pc
->cbSize
== sizeof(COMPVARS
)) {
1185 if (pc
->hic
!= NULL
) {
1189 HeapFree(GetProcessHeap(), 0, pc
->lpbiIn
);
1191 HeapFree(GetProcessHeap(), 0, pc
->lpBitsOut
);
1192 pc
->lpBitsOut
= NULL
;
1193 HeapFree(GetProcessHeap(), 0, pc
->lpBitsPrev
);
1194 pc
->lpBitsPrev
= NULL
;
1195 HeapFree(GetProcessHeap(), 0, pc
->lpState
);
1201 /***********************************************************************
1202 * ICSendMessage [MSVFW32.@]
1204 LRESULT VFWAPI
ICSendMessage(HIC hic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
1206 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1208 if (!whic
) return ICERR_BADHANDLE
;
1209 return MSVIDEO_SendMessage(whic
, msg
, lParam1
, lParam2
);
1212 /***********************************************************************
1213 * ICDrawBegin [MSVFW32.@]
1215 DWORD VFWAPIV
ICDrawBegin(
1217 DWORD dwFlags
, /* [in] flags */
1218 HPALETTE hpal
, /* [in] palette to draw with */
1219 HWND hwnd
, /* [in] window to draw to */
1220 HDC hdc
, /* [in] HDC to draw to */
1221 INT xDst
, /* [in] destination rectangle */
1222 INT yDst
, /* [in] */
1223 INT dxDst
, /* [in] */
1224 INT dyDst
, /* [in] */
1225 LPBITMAPINFOHEADER lpbi
, /* [in] format of frame to draw */
1226 INT xSrc
, /* [in] source rectangle */
1227 INT ySrc
, /* [in] */
1228 INT dxSrc
, /* [in] */
1229 INT dySrc
, /* [in] */
1230 DWORD dwRate
, /* [in] frames/second = (dwRate/dwScale) */
1231 DWORD dwScale
) /* [in] */
1236 TRACE("(%p,%d,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%d,%d)\n",
1237 hic
, dwFlags
, hpal
, hwnd
, hdc
, xDst
, yDst
, dxDst
, dyDst
,
1238 lpbi
, xSrc
, ySrc
, dxSrc
, dySrc
, dwRate
, dwScale
);
1240 icdb
.dwFlags
= dwFlags
;
1253 icdb
.dwRate
= dwRate
;
1254 icdb
.dwScale
= dwScale
;
1255 return ICSendMessage(hic
,ICM_DRAW_BEGIN
,(DWORD_PTR
)&icdb
,sizeof(icdb
));
1258 /***********************************************************************
1259 * ICDraw [MSVFW32.@]
1261 DWORD VFWAPIV
ICDraw(HIC hic
, DWORD dwFlags
, LPVOID lpFormat
, LPVOID lpData
, DWORD cbData
, LONG lTime
) {
1264 TRACE("(%p,%d,%p,%p,%d,%d)\n",hic
,dwFlags
,lpFormat
,lpData
,cbData
,lTime
);
1266 icd
.dwFlags
= dwFlags
;
1267 icd
.lpFormat
= lpFormat
;
1268 icd
.lpData
= lpData
;
1269 icd
.cbData
= cbData
;
1272 return ICSendMessage(hic
,ICM_DRAW
,(DWORD_PTR
)&icd
,sizeof(icd
));
1275 /***********************************************************************
1276 * ICClose [MSVFW32.@]
1278 LRESULT WINAPI
ICClose(HIC hic
)
1280 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1283 TRACE("(%p)\n",hic
);
1285 if (!whic
) return ICERR_BADHANDLE
;
1287 if (whic
->driverproc
)
1289 MSVIDEO_SendMessage(whic
, DRV_CLOSE
, 0, 0);
1290 MSVIDEO_SendMessage(whic
, DRV_DISABLE
, 0, 0);
1291 MSVIDEO_SendMessage(whic
, DRV_FREE
, 0, 0);
1295 CloseDriver(whic
->hdrv
, 0, 0);
1298 /* remove whic from list */
1299 for (p
= &MSVIDEO_FirstHic
; *p
!= NULL
; p
= &((*p
)->next
))
1308 HeapFree(GetProcessHeap(), 0, whic
);
1314 /***********************************************************************
1315 * ICImageCompress [MSVFW32.@]
1317 HANDLE VFWAPI
ICImageCompress(
1318 HIC hic
, UINT uiFlags
,
1319 LPBITMAPINFO lpbiIn
, LPVOID lpBits
,
1320 LPBITMAPINFO lpbiOut
, LONG lQuality
,
1323 FIXME("(%p,%08x,%p,%p,%p,%d,%p)\n",
1324 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
, lQuality
, plSize
);
1329 /***********************************************************************
1330 * ICImageDecompress [MSVFW32.@]
1333 HANDLE VFWAPI
ICImageDecompress(
1334 HIC hic
, UINT uiFlags
, LPBITMAPINFO lpbiIn
,
1335 LPVOID lpBits
, LPBITMAPINFO lpbiOut
)
1337 HGLOBAL hMem
= NULL
;
1339 BOOL bReleaseIC
= FALSE
;
1342 BOOL bSucceeded
= FALSE
;
1343 BOOL bInDecompress
= FALSE
;
1346 TRACE("(%p,%08x,%p,%p,%p)\n",
1347 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
);
1351 hic
= ICDecompressOpen( ICTYPE_VIDEO
, 0, &lpbiIn
->bmiHeader
, (lpbiOut
!= NULL
) ? &lpbiOut
->bmiHeader
: NULL
);
1354 WARN("no handler\n" );
1361 FIXME( "unknown flag %08x\n", uiFlags
);
1364 if ( lpbiIn
== NULL
|| lpBits
== NULL
)
1366 WARN("invalid argument\n");
1370 if ( lpbiOut
!= NULL
)
1372 if ( lpbiOut
->bmiHeader
.biSize
!= sizeof(BITMAPINFOHEADER
) )
1374 cbHdr
= sizeof(BITMAPINFOHEADER
);
1375 if ( lpbiOut
->bmiHeader
.biCompression
== 3 )
1376 cbHdr
+= sizeof(DWORD
)*3;
1378 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 )
1380 if ( lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1381 cbHdr
+= sizeof(RGBQUAD
) * (1<<lpbiOut
->bmiHeader
.biBitCount
);
1383 cbHdr
+= sizeof(RGBQUAD
) * lpbiOut
->bmiHeader
.biClrUsed
;
1388 TRACE( "get format\n" );
1390 cbHdr
= ICDecompressGetFormatSize(hic
,lpbiIn
);
1391 if ( cbHdr
< sizeof(BITMAPINFOHEADER
) )
1393 pHdr
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,cbHdr
+sizeof(RGBQUAD
)*256);
1396 if ( ICDecompressGetFormat( hic
, lpbiIn
, pHdr
) != ICERR_OK
)
1398 lpbiOut
= (BITMAPINFO
*)pHdr
;
1399 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1400 ICDecompressGetPalette( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
&&
1401 lpbiIn
->bmiHeader
.biBitCount
== lpbiOut
->bmiHeader
.biBitCount
)
1403 if ( lpbiIn
->bmiHeader
.biClrUsed
== 0 )
1404 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*(1<<lpbiOut
->bmiHeader
.biBitCount
) );
1406 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*lpbiIn
->bmiHeader
.biClrUsed
);
1408 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1409 lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1410 lpbiOut
->bmiHeader
.biClrUsed
= 1<<lpbiOut
->bmiHeader
.biBitCount
;
1412 lpbiOut
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1413 cbHdr
= sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
)*lpbiOut
->bmiHeader
.biClrUsed
;
1416 biSizeImage
= lpbiOut
->bmiHeader
.biSizeImage
;
1417 if ( biSizeImage
== 0 )
1418 biSizeImage
= ((((lpbiOut
->bmiHeader
.biWidth
* lpbiOut
->bmiHeader
.biBitCount
+ 7) >> 3) + 3) & (~3)) * abs(lpbiOut
->bmiHeader
.biHeight
);
1420 TRACE( "call ICDecompressBegin\n" );
1422 if ( ICDecompressBegin( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
)
1424 bInDecompress
= TRUE
;
1426 TRACE( "cbHdr %d, biSizeImage %d\n", cbHdr
, biSizeImage
);
1428 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_ZEROINIT
, cbHdr
+ biSizeImage
);
1431 WARN( "out of memory\n" );
1434 pMem
= GlobalLock( hMem
);
1437 memcpy( pMem
, lpbiOut
, cbHdr
);
1439 TRACE( "call ICDecompress\n" );
1440 if ( ICDecompress( hic
, 0, &lpbiIn
->bmiHeader
, lpBits
, &lpbiOut
->bmiHeader
, pMem
+cbHdr
) != ICERR_OK
)
1445 if ( bInDecompress
)
1446 ICDecompressEnd( hic
);
1449 HeapFree(GetProcessHeap(),0,pHdr
);
1451 GlobalUnlock( hMem
);
1452 if ( !bSucceeded
&& hMem
!= NULL
)
1454 GlobalFree(hMem
); hMem
= NULL
;
1460 /***********************************************************************
1461 * ICSeqCompressFrame [MSVFW32.@]
1463 LPVOID VFWAPI
ICSeqCompressFrame(PCOMPVARS pc
, UINT uiFlags
, LPVOID lpBits
, BOOL
*pfKey
, LONG
*plSize
)
1465 ICCOMPRESS
* icComp
= pc
->lpState
;
1467 TRACE("(%p, 0x%08x, %p, %p, %p)\n", pc
, uiFlags
, lpBits
, pfKey
, plSize
);
1469 if (pc
->cbState
!= sizeof(ICCOMPRESS
))
1471 ERR("Invalid cbState %i\n", pc
->cbState
);
1475 if (!pc
->lKeyCount
++)
1476 icComp
->dwFlags
= ICCOMPRESS_KEYFRAME
;
1479 if (pc
->lKey
&& pc
->lKeyCount
== (pc
->lKey
- 1))
1480 /* No key frames if pc->lKey == 0 */
1482 icComp
->dwFlags
= 0;
1485 icComp
->lpInput
= lpBits
;
1486 icComp
->lFrameNum
= pc
->lFrame
++;
1487 icComp
->lpOutput
= pc
->lpBitsOut
;
1488 icComp
->lpPrev
= pc
->lpBitsPrev
;
1489 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS
, (DWORD_PTR
)icComp
, sizeof(*icComp
));
1491 if (ret
== ICERR_OK
)
1493 LPVOID oldprev
, oldout
;
1495 if (icComp
->dwFlags
& AVIIF_KEYFRAME
)
1499 TRACE("Key frame\n");
1504 *plSize
= icComp
->lpbiOutput
->biSizeImage
;
1506 /* We shift Prev and Out, so we don't have to allocate and release memory */
1507 oldprev
= pc
->lpBitsPrev
;
1508 oldout
= pc
->lpBitsOut
;
1509 pc
->lpBitsPrev
= oldout
;
1510 pc
->lpBitsOut
= oldprev
;
1512 TRACE("returning: %p, compressed frame size %u\n", icComp
->lpOutput
, *plSize
);
1513 return icComp
->lpOutput
;
1518 static void clear_compvars(PCOMPVARS pc
)
1520 HeapFree(GetProcessHeap(), 0, pc
->lpbiIn
);
1521 HeapFree(GetProcessHeap(), 0, pc
->lpBitsPrev
);
1522 HeapFree(GetProcessHeap(), 0, pc
->lpBitsOut
);
1523 HeapFree(GetProcessHeap(), 0, pc
->lpState
);
1524 pc
->lpbiIn
= pc
->lpBitsPrev
= pc
->lpBitsOut
= pc
->lpState
= NULL
;
1525 if (pc
->dwFlags
& 0x80000000)
1527 HeapFree(GetProcessHeap(), 0, pc
->lpbiOut
);
1529 pc
->dwFlags
&= ~0x80000000;
1533 /***********************************************************************
1534 * ICSeqCompressFrameEnd [MSVFW32.@]
1536 void VFWAPI
ICSeqCompressFrameEnd(PCOMPVARS pc
)
1538 TRACE("(%p)\n", pc
);
1539 ICSendMessage(pc
->hic
, ICM_COMPRESS_END
, 0, 0);
1543 /***********************************************************************
1544 * ICSeqCompressFrameStart [MSVFW32.@]
1546 BOOL VFWAPI
ICSeqCompressFrameStart(PCOMPVARS pc
, LPBITMAPINFO lpbiIn
)
1548 /* I'm ignoring bmiColors as I don't know what to do with it,
1549 * it doesn't appear to be used though
1553 pc
->lpbiIn
= HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO
));
1557 *pc
->lpbiIn
= *lpbiIn
;
1559 pc
->lpState
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS
)
1560 + sizeof(*icComp
->lpckid
) + sizeof(*icComp
->lpdwFlags
));
1564 pc
->cbState
= sizeof(ICCOMPRESS
);
1568 /* Ask compressor for needed header size */
1569 int size
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1570 (DWORD_PTR
)pc
->lpbiIn
, 0);
1574 pc
->lpbiOut
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1577 /* Flag to show that we allocated lpbiOut for proper cleanup */
1578 pc
->dwFlags
|= 0x80000000;
1580 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1581 (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1582 if (ret
!= ICERR_OK
)
1584 ERR("Could not get output format from compressor\n");
1587 if (!pc
->lpbiOut
->bmiHeader
.biSizeImage
)
1589 /* If we can't know the output frame size for sure at least allocate
1590 * the same size of the input frame and also at least 8Kb to be sure
1591 * that poor compressors will have enough memory to work if the input
1592 * frame is too small.
1594 pc
->lpbiOut
->bmiHeader
.biSizeImage
= max(8192, pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1595 ERR("Bad codec! Invalid output frame size, guessing from input\n");
1599 TRACE("Input: %ux%u, fcc %s, bpp %u, size %u\n",
1600 pc
->lpbiIn
->bmiHeader
.biWidth
, pc
->lpbiIn
->bmiHeader
.biHeight
,
1601 wine_dbgstr_fcc(pc
->lpbiIn
->bmiHeader
.biCompression
),
1602 pc
->lpbiIn
->bmiHeader
.biBitCount
,
1603 pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1604 TRACE("Output: %ux%u, fcc %s, bpp %u, size %u\n",
1605 pc
->lpbiOut
->bmiHeader
.biWidth
, pc
->lpbiOut
->bmiHeader
.biHeight
,
1606 wine_dbgstr_fcc(pc
->lpbiOut
->bmiHeader
.biCompression
),
1607 pc
->lpbiOut
->bmiHeader
.biBitCount
,
1608 pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1610 /* Buffer for compressed frame data */
1611 pc
->lpBitsOut
= HeapAlloc(GetProcessHeap(), 0, pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1615 /* Buffer for previous compressed frame data */
1616 pc
->lpBitsPrev
= HeapAlloc(GetProcessHeap(), 0, pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1617 if (!pc
->lpBitsPrev
)
1627 "\tkey/data/quality: %i/%i/%i\n",
1628 pc
->cbSize
, pc
->dwFlags
, pc
->hic
, wine_dbgstr_fcc(pc
->fccType
),
1629 wine_dbgstr_fcc(pc
->fccHandler
), pc
->lpbiIn
, pc
->lpbiOut
, pc
->lKey
,
1630 pc
->lDataRate
, pc
->lQ
);
1632 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_BEGIN
, (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1633 if (ret
== ICERR_OK
)
1635 icComp
= pc
->lpState
;
1636 /* Initialise some variables */
1637 pc
->lFrame
= 0; pc
->lKeyCount
= 0;
1639 icComp
->lpbiOutput
= &pc
->lpbiOut
->bmiHeader
;
1640 icComp
->lpbiInput
= &pc
->lpbiIn
->bmiHeader
;
1641 icComp
->lpckid
= (DWORD
*)(icComp
+ 1);
1642 *icComp
->lpckid
= 0;
1643 icComp
->lpdwFlags
= (DWORD
*)((char *)(icComp
+ 1) + sizeof(*icComp
->lpckid
));
1644 *icComp
->lpdwFlags
= 0;
1645 icComp
->dwFrameSize
= 0;
1646 icComp
->dwQuality
= pc
->lQ
;
1647 icComp
->lpbiPrev
= &pc
->lpbiIn
->bmiHeader
;
1655 /***********************************************************************
1656 * GetFileNamePreview [MSVFW32.@]
1658 static BOOL
GetFileNamePreview(LPVOID lpofn
,BOOL bSave
,BOOL bUnicode
)
1660 CHAR szFunctionName
[20];
1661 BOOL (*fnGetFileName
)(LPVOID
);
1665 FIXME("(%p,%d,%d), semi-stub!\n",lpofn
,bSave
,bUnicode
);
1667 lstrcpyA(szFunctionName
, (bSave
? "GetSaveFileName" : "GetOpenFileName"));
1668 lstrcatA(szFunctionName
, (bUnicode
? "W" : "A"));
1670 hComdlg32
= LoadLibraryA("COMDLG32.DLL");
1671 if (hComdlg32
== NULL
)
1674 fnGetFileName
= (LPVOID
)GetProcAddress(hComdlg32
, szFunctionName
);
1675 if (fnGetFileName
== NULL
)
1677 FreeLibrary(hComdlg32
);
1681 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1682 ret
= fnGetFileName(lpofn
);
1684 FreeLibrary(hComdlg32
);
1688 /***********************************************************************
1689 * GetOpenFileNamePreviewA [MSVFW32.@]
1691 BOOL WINAPI
GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1693 FIXME("(%p), semi-stub!\n", lpofn
);
1695 return GetFileNamePreview(lpofn
, FALSE
, FALSE
);
1698 /***********************************************************************
1699 * GetOpenFileNamePreviewW [MSVFW32.@]
1701 BOOL WINAPI
GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1703 FIXME("(%p), semi-stub!\n", lpofn
);
1705 return GetFileNamePreview(lpofn
, FALSE
, TRUE
);
1708 /***********************************************************************
1709 * GetSaveFileNamePreviewA [MSVFW32.@]
1711 BOOL WINAPI
GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1713 FIXME("(%p), semi-stub!\n", lpofn
);
1715 return GetFileNamePreview(lpofn
, TRUE
, FALSE
);
1718 /***********************************************************************
1719 * GetSaveFileNamePreviewW [MSVFW32.@]
1721 BOOL WINAPI
GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1723 FIXME("(%p), semi-stub!\n", lpofn
);
1725 return GetFileNamePreview(lpofn
, TRUE
, TRUE
);