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 (fccType
&& (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 (fccType
&& (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 if (lpicinfo
->fccHandler
!= nr
&& compare_fourcc(lpicinfo
->fccHandler
, fccHandler
))
305 lpicinfo
->fccHandler
= fccHandler
;
306 lpicinfo
->dwFlags
= 0;
307 lpicinfo
->dwVersion
= 0;
308 lpicinfo
->dwVersionICM
= ICVERSION
;
309 lpicinfo
->szName
[0] = 0;
310 lpicinfo
->szDescription
[0] = 0;
311 MultiByteToWideChar(CP_ACP
, 0, drv
+ 10, -1, lpicinfo
->szDriver
,
312 sizeof(lpicinfo
->szDriver
)/sizeof(WCHAR
));
317 /***********************************************************************
319 * Get information about an installable compressor. Return TRUE if there
323 * fccType [I] type of compressor (e.g. 'vidc')
324 * fccHandler [I] real fcc for handler or <n>th compressor
325 * lpicinfo [O] information about compressor
327 BOOL VFWAPI
ICInfo( DWORD fccType
, DWORD fccHandler
, ICINFO
*lpicinfo
)
329 TRACE("(%s,%s,%p)\n",
330 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), lpicinfo
);
332 lpicinfo
->fccType
= fccType
;
333 lpicinfo
->fccHandler
= fccHandler
;
334 return enum_drivers(fccType
, ICInfo_enum_handler
, lpicinfo
);
337 static DWORD IC_HandleRef
= 1;
339 /***********************************************************************
340 * ICInstall [MSVFW32.@]
342 BOOL VFWAPI
ICInstall(DWORD fccType
, DWORD fccHandler
, LPARAM lParam
, LPSTR szDesc
, UINT wFlags
)
347 TRACE("(%s,%s,%p,%p,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), (void*)lParam
, szDesc
, wFlags
);
349 /* Check if a driver is already registered */
350 for (driver
= reg_driver_list
; driver
; driver
= driver
->next
)
352 if (!compare_fourcc(fccType
, driver
->fccType
) &&
353 !compare_fourcc(fccHandler
, driver
->fccHandler
))
356 if (driver
) return FALSE
;
358 /* Register the driver */
359 driver
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(reg_driver
));
360 if (!driver
) goto oom
;
361 driver
->fccType
= fccType
;
362 driver
->fccHandler
= fccHandler
;
366 case ICINSTALL_FUNCTION
:
367 driver
->proc
= (DRIVERPROC
)lParam
;
370 case ICINSTALL_DRIVER
:
372 len
= MultiByteToWideChar(CP_ACP
, 0, (char*)lParam
, -1, NULL
, 0);
373 driver
->name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
374 if (!driver
->name
) goto oom
;
375 MultiByteToWideChar(CP_ACP
, 0, (char*)lParam
, -1, driver
->name
, len
);
378 ERR("Invalid flags!\n");
379 HeapFree(GetProcessHeap(), 0, driver
);
383 /* Insert our driver in the list*/
384 driver
->next
= reg_driver_list
;
385 reg_driver_list
= driver
;
389 HeapFree(GetProcessHeap(), 0, driver
);
393 /***********************************************************************
394 * ICRemove [MSVFW32.@]
396 BOOL VFWAPI
ICRemove(DWORD fccType
, DWORD fccHandler
, UINT wFlags
)
398 reg_driver
** pdriver
;
401 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wFlags
);
403 /* Check if a driver is already registered */
404 for (pdriver
= ®_driver_list
; *pdriver
; pdriver
= &(*pdriver
)->next
)
406 if (!compare_fourcc(fccType
, (*pdriver
)->fccType
) &&
407 !compare_fourcc(fccHandler
, (*pdriver
)->fccHandler
))
413 /* Remove the driver from the list */
415 *pdriver
= (*pdriver
)->next
;
416 HeapFree(GetProcessHeap(), 0, drv
->name
);
417 HeapFree(GetProcessHeap(), 0, drv
);
423 /***********************************************************************
425 * Opens an installable compressor. Return special handle.
427 HIC VFWAPI
ICOpen(DWORD fccType
, DWORD fccHandler
, UINT wMode
)
433 static const WCHAR drv32W
[] = {'d','r','i','v','e','r','s','3','2','\0'};
436 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wMode
);
438 if (!fccHandler
) /* No specific handler, return the first valid for wMode */
443 info
.dwSize
= sizeof(info
);
444 while(ICInfo(fccType
, loop
++, &info
))
446 /* Ensure fccHandler is not 0x0 because we will recurse on ICOpen */
449 local
= ICOpen(fccType
, info
.fccHandler
, wMode
);
452 TRACE("Returning %s as default handler for %s\n",
453 wine_dbgstr_fcc(info
.fccHandler
), wine_dbgstr_fcc(fccType
));
459 /* Check if there is a registered driver that matches */
460 driver
= reg_driver_list
;
462 if (!compare_fourcc(fccType
, driver
->fccType
) &&
463 !compare_fourcc(fccHandler
, driver
->fccHandler
)) {
464 fccType
= driver
->fccType
;
465 fccHandler
= driver
->fccHandler
;
468 driver
= driver
->next
;
470 if (driver
&& driver
->proc
)
471 /* The driver has been registered at runtime with its driverproc */
472 return ICOpenFunction(fccType
, fccHandler
, wMode
, driver
->proc
);
474 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
475 * same layout as ICOPEN
477 icopen
.dwSize
= sizeof(ICOPEN
);
478 icopen
.fccType
= fccType
;
479 icopen
.fccHandler
= fccHandler
;
480 icopen
.dwVersion
= 0x00001000; /* FIXME */
481 icopen
.dwFlags
= wMode
;
483 icopen
.pV1Reserved
= NULL
;
484 icopen
.pV2Reserved
= NULL
;
485 icopen
.dnDevNode
= 0; /* FIXME */
488 /* normalize to lower case as in 'vidc' */
489 ((char*)&fccType
)[0] = tolower(((char*)&fccType
)[0]);
490 ((char*)&fccType
)[1] = tolower(((char*)&fccType
)[1]);
491 ((char*)&fccType
)[2] = tolower(((char*)&fccType
)[2]);
492 ((char*)&fccType
)[3] = tolower(((char*)&fccType
)[3]);
493 icopen
.fccType
= fccType
;
494 /* Seek the driver in the registry */
495 fourcc_to_string(codecname
, fccType
);
497 fourcc_to_string(codecname
+ 5, fccHandler
);
500 hdrv
= OpenDriver(codecname
, drv32W
, (LPARAM
)&icopen
);
504 /* The driver has been registered at runtime with its name */
505 hdrv
= OpenDriver(driver
->name
, NULL
, (LPARAM
)&icopen
);
510 whic
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC
));
513 CloseDriver(hdrv
, 0, 0);
517 whic
->driverproc
= NULL
;
518 whic
->type
= fccType
;
519 whic
->handler
= fccHandler
;
520 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
521 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
522 whic
->next
= MSVIDEO_FirstHic
;
523 MSVIDEO_FirstHic
= whic
;
525 TRACE("=> %p\n", whic
->hic
);
529 /***********************************************************************
530 * ICOpenFunction [MSVFW32.@]
532 HIC VFWAPI
ICOpenFunction(DWORD fccType
, DWORD fccHandler
, UINT wMode
, DRIVERPROC lpfnHandler
)
537 TRACE("(%s,%s,%d,%p)\n",
538 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wMode
, lpfnHandler
);
540 icopen
.dwSize
= sizeof(ICOPEN
);
541 icopen
.fccType
= fccType
;
542 icopen
.fccHandler
= fccHandler
;
543 icopen
.dwVersion
= ICVERSION
;
544 icopen
.dwFlags
= wMode
;
546 icopen
.pV1Reserved
= NULL
;
547 icopen
.pV2Reserved
= NULL
;
548 icopen
.dnDevNode
= 0; /* FIXME */
550 whic
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC
));
553 whic
->driverproc
= lpfnHandler
;
554 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
555 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
556 whic
->next
= MSVIDEO_FirstHic
;
557 MSVIDEO_FirstHic
= whic
;
559 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
560 /* What if the function is used more than once? */
562 if (MSVIDEO_SendMessage(whic
, DRV_LOAD
, 0L, 0L) != DRV_SUCCESS
)
564 WARN("DRV_LOAD failed for hic %p\n", whic
->hic
);
565 MSVIDEO_FirstHic
= whic
->next
;
566 HeapFree(GetProcessHeap(), 0, whic
);
569 /* return value is not checked */
570 MSVIDEO_SendMessage(whic
, DRV_ENABLE
, 0L, 0L);
572 whic
->driverId
= (DWORD
)MSVIDEO_SendMessage(whic
, DRV_OPEN
, 0, (DWORD_PTR
)&icopen
);
573 /* FIXME: What should we put here? */
576 if (whic
->driverId
== 0)
578 WARN("DRV_OPEN failed for hic %p\n", whic
->hic
);
579 MSVIDEO_FirstHic
= whic
->next
;
580 HeapFree(GetProcessHeap(), 0, whic
);
584 TRACE("=> %p\n", whic
->hic
);
588 /***********************************************************************
589 * ICGetInfo [MSVFW32.@]
591 LRESULT VFWAPI
ICGetInfo(HIC hic
, ICINFO
*picinfo
, DWORD cb
)
594 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
596 TRACE("(%p,%p,%d)\n", hic
, picinfo
, cb
);
598 if (!whic
) return ICERR_BADHANDLE
;
599 if (!picinfo
) return MMSYSERR_INVALPARAM
;
601 /* (WS) The field szDriver should be initialized because the driver
602 * is not obliged and often will not do it. Some applications, like
603 * VirtualDub, rely on this field and will occasionally crash if it
604 * goes uninitialized.
606 if (cb
>= sizeof(ICINFO
)) picinfo
->szDriver
[0] = '\0';
608 ret
= ICSendMessage(hic
, ICM_GETINFO
, (DWORD_PTR
)picinfo
, cb
);
610 /* (WS) When szDriver was not supplied by the driver itself, apparently
611 * Windows will set its value equal to the driver file name. This can
612 * be obtained from the registry as we do here.
614 if (cb
>= sizeof(ICINFO
) && picinfo
->szDriver
[0] == 0)
618 memset(&ii
, 0, sizeof(ii
));
619 ii
.dwSize
= sizeof(ii
);
620 ICInfo(picinfo
->fccType
, picinfo
->fccHandler
, &ii
);
621 lstrcpyW(picinfo
->szDriver
, ii
.szDriver
);
630 LPBITMAPINFOHEADER lpbiIn
;
631 LPBITMAPINFOHEADER lpbiOut
;
637 static HIC
try_driver(driver_info_t
*info
)
641 if ((hic
= ICOpen(info
->fccType
, info
->fccHandler
, info
->wMode
)))
643 if (!ICSendMessage(hic
, info
->querymsg
, (DWORD_PTR
)info
->lpbiIn
, (DWORD_PTR
)info
->lpbiOut
))
650 static BOOL
ICLocate_enum_handler(const char *drv
, unsigned int nr
, void *param
)
652 driver_info_t
*info
= param
;
653 info
->fccHandler
= mmioStringToFOURCCA(drv
+ 5, 0);
654 info
->hic
= try_driver(info
);
655 return info
->hic
!= 0;
658 /***********************************************************************
659 * ICLocate [MSVFW32.@]
661 HIC VFWAPI
ICLocate(DWORD fccType
, DWORD fccHandler
, LPBITMAPINFOHEADER lpbiIn
,
662 LPBITMAPINFOHEADER lpbiOut
, WORD wMode
)
666 TRACE("(%s,%s,%p,%p,0x%04x)\n",
667 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), lpbiIn
, lpbiOut
, wMode
);
669 info
.fccType
= fccType
;
670 info
.fccHandler
= fccHandler
;
671 info
.lpbiIn
= lpbiIn
;
672 info
.lpbiOut
= lpbiOut
;
677 case ICMODE_FASTCOMPRESS
:
678 case ICMODE_COMPRESS
:
679 info
.querymsg
= ICM_COMPRESS_QUERY
;
681 case ICMODE_FASTDECOMPRESS
:
682 case ICMODE_DECOMPRESS
:
683 info
.querymsg
= ICM_DECOMPRESS_QUERY
;
686 info
.querymsg
= ICM_DRAW_QUERY
;
689 WARN("Unknown mode (%d)\n", wMode
);
693 /* Easy case: handler/type match, we just fire a query and return */
694 info
.hic
= try_driver(&info
);
695 /* If it didn't work, try each driver in turn. 32 bit codecs only. */
696 /* FIXME: Move this to an init routine? */
697 if (!info
.hic
) enum_drivers(fccType
, ICLocate_enum_handler
, &info
);
701 TRACE("=> %p\n", info
.hic
);
705 if (fccType
== streamtypeVIDEO
)
706 return ICLocate(ICTYPE_VIDEO
, fccHandler
, lpbiIn
, lpbiOut
, wMode
);
708 ERR("Required media codec '%s %s' not found!\n",
709 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
));
713 /***********************************************************************
714 * ICGetDisplayFormat [MSVFW32.@]
716 HIC VFWAPI
ICGetDisplayFormat(
717 HIC hic
,LPBITMAPINFOHEADER lpbiIn
,LPBITMAPINFOHEADER lpbiOut
,
718 INT depth
,INT dx
,INT dy
)
722 TRACE("(%p,%p,%p,%d,%d,%d)!\n",hic
,lpbiIn
,lpbiOut
,depth
,dx
,dy
);
725 tmphic
=ICLocate(ICTYPE_VIDEO
,0,lpbiIn
,NULL
,ICMODE_DECOMPRESS
);
729 if ((dy
== lpbiIn
->biHeight
) && (dx
== lpbiIn
->biWidth
))
730 dy
= dx
= 0; /* no resize needed */
732 /* Can we decompress it ? */
733 if (ICDecompressQuery(tmphic
,lpbiIn
,NULL
) != 0)
734 goto errout
; /* no, sorry */
736 ICSendMessage(tmphic
, ICM_DECOMPRESS_GET_FORMAT
, (DWORD_PTR
)lpbiIn
, (DWORD_PTR
)lpbiOut
);
738 if (lpbiOut
->biCompression
!= 0) {
739 FIXME("Ooch, how come decompressor outputs compressed data (%d)??\n",
740 lpbiOut
->biCompression
);
742 if (lpbiOut
->biSize
< sizeof(*lpbiOut
)) {
743 FIXME("Ooch, size of output BIH is too small (%d)\n",
745 lpbiOut
->biSize
= sizeof(*lpbiOut
);
751 depth
= GetDeviceCaps(hdc
,BITSPIXEL
)*GetDeviceCaps(hdc
,PLANES
);
753 if (depth
==15) depth
= 16;
754 if (depth
<8) depth
= 8;
756 if (lpbiIn
->biBitCount
== 8)
759 TRACE("=> %p\n", tmphic
);
769 /***********************************************************************
770 * ICCompress [MSVFW32.@]
774 HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiOutput
,LPVOID lpData
,
775 LPBITMAPINFOHEADER lpbiInput
,LPVOID lpBits
,LPDWORD lpckid
,
776 LPDWORD lpdwFlags
,LONG lFrameNum
,DWORD dwFrameSize
,DWORD dwQuality
,
777 LPBITMAPINFOHEADER lpbiPrev
,LPVOID lpPrev
)
781 TRACE("(%p,%d,%p,%p,%p,%p,...)\n",hic
,dwFlags
,lpbiOutput
,lpData
,lpbiInput
,lpBits
);
783 iccmp
.dwFlags
= dwFlags
;
785 iccmp
.lpbiOutput
= lpbiOutput
;
786 iccmp
.lpOutput
= lpData
;
787 iccmp
.lpbiInput
= lpbiInput
;
788 iccmp
.lpInput
= lpBits
;
790 iccmp
.lpckid
= lpckid
;
791 iccmp
.lpdwFlags
= lpdwFlags
;
792 iccmp
.lFrameNum
= lFrameNum
;
793 iccmp
.dwFrameSize
= dwFrameSize
;
794 iccmp
.dwQuality
= dwQuality
;
795 iccmp
.lpbiPrev
= lpbiPrev
;
796 iccmp
.lpPrev
= lpPrev
;
797 return ICSendMessage(hic
,ICM_COMPRESS
,(DWORD_PTR
)&iccmp
,sizeof(iccmp
));
800 /***********************************************************************
801 * ICDecompress [MSVFW32.@]
803 DWORD VFWAPIV
ICDecompress(HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiFormat
,
804 LPVOID lpData
,LPBITMAPINFOHEADER lpbi
,LPVOID lpBits
)
809 TRACE("(%p,%d,%p,%p,%p,%p)\n",hic
,dwFlags
,lpbiFormat
,lpData
,lpbi
,lpBits
);
811 icd
.dwFlags
= dwFlags
;
812 icd
.lpbiInput
= lpbiFormat
;
813 icd
.lpInput
= lpData
;
815 icd
.lpbiOutput
= lpbi
;
816 icd
.lpOutput
= lpBits
;
818 ret
= ICSendMessage(hic
,ICM_DECOMPRESS
,(DWORD_PTR
)&icd
,sizeof(ICDECOMPRESS
));
824 struct choose_compressor
837 static BOOL
enum_compressors(HWND list
, COMPVARS
*pcv
, BOOL enum_all
)
844 while (ICInfo(pcv
->fccType
, id
, &icinfo
))
846 struct codec_info
*ic
;
852 hic
= ICOpen(icinfo
.fccType
, icinfo
.fccHandler
, ICMODE_COMPRESS
);
856 /* for unknown reason fccHandler reported by the driver
857 * doesn't always work, use the one returned by ICInfo instead.
859 DWORD fccHandler
= icinfo
.fccHandler
;
861 if (!enum_all
&& pcv
->lpbiIn
)
863 if (ICCompressQuery(hic
, pcv
->lpbiIn
, NULL
) != ICERR_OK
)
865 TRACE("fccHandler %s doesn't support input DIB format %d\n",
866 wine_dbgstr_fcc(icinfo
.fccHandler
), pcv
->lpbiIn
->bmiHeader
.biCompression
);
872 ICGetInfo(hic
, &icinfo
, sizeof(icinfo
));
873 icinfo
.fccHandler
= fccHandler
;
875 idx
= SendMessageW(list
, CB_ADDSTRING
, 0, (LPARAM
)icinfo
.szDescription
);
877 ic
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info
));
880 SendMessageW(list
, CB_SETITEMDATA
, idx
, (LPARAM
)ic
);
888 static INT_PTR CALLBACK
icm_choose_compressor_dlgproc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
894 struct codec_info
*ic
;
896 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)lparam
;
898 SetWindowLongPtrW(hdlg
, DWLP_USER
, lparam
);
901 choose_comp
->flags
&= ~(ICMF_CHOOSE_DATARATE
| ICMF_CHOOSE_KEYFRAME
);
903 if (choose_comp
->title
)
904 SetWindowTextA(hdlg
, choose_comp
->title
);
906 if (!(choose_comp
->flags
& ICMF_CHOOSE_DATARATE
))
908 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_CHECKBOX
), SW_HIDE
);
909 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE
), SW_HIDE
);
910 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_KB
), SW_HIDE
);
913 if (!(choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
))
915 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_CHECKBOX
), SW_HIDE
);
916 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME
), SW_HIDE
);
917 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_FRAMES
), SW_HIDE
);
921 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_SCROLL
), FALSE
);
922 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_TXT
), FALSE
);
924 /*if (!(choose_comp->flags & ICMF_CHOOSE_PREVIEW))
925 ShowWindow(GetDlgItem(hdlg, IDC_PREVIEW), SW_HIDE);*/
927 LoadStringW(MSVFW32_hModule
, IDS_FULLFRAMES
, buf
, 128);
928 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
930 ic
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info
));
931 ic
->icinfo
.fccType
= streamtypeVIDEO
;
932 ic
->icinfo
.fccHandler
= comptypeDIB
;
934 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETITEMDATA
, 0, (LPARAM
)ic
);
936 enum_compressors(GetDlgItem(hdlg
, IDC_COMP_LIST
), &choose_comp
->cv
, choose_comp
->flags
& ICMF_CHOOSE_ALLCOMPRESSORS
);
938 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETCURSEL
, 0, 0);
939 SetFocus(GetDlgItem(hdlg
, IDC_COMP_LIST
));
941 SetWindowLongPtrW(hdlg
, DWLP_USER
, (ULONG_PTR
)choose_comp
);
946 switch (LOWORD(wparam
))
951 struct codec_info
*ic
;
952 BOOL can_configure
= FALSE
, can_about
= FALSE
;
953 struct choose_compressor
*choose_comp
;
955 if (HIWORD(wparam
) != CBN_SELCHANGE
&& HIWORD(wparam
) != CBN_SETFOCUS
)
958 choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
960 cur_sel
= SendMessageW((HWND
)lparam
, CB_GETCURSEL
, 0, 0);
962 ic
= (struct codec_info
*)SendMessageW((HWND
)lparam
, CB_GETITEMDATA
, cur_sel
, 0);
965 if (ICQueryConfigure(ic
->hic
) == DRVCNF_OK
)
966 can_configure
= TRUE
;
967 if (ICQueryAbout(ic
->hic
) == DRVCNF_OK
)
970 EnableWindow(GetDlgItem(hdlg
, IDC_CONFIGURE
), can_configure
);
971 EnableWindow(GetDlgItem(hdlg
, IDC_ABOUT
), can_about
);
973 if (choose_comp
->flags
& ICMF_CHOOSE_DATARATE
)
977 if (choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
)
988 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
990 struct codec_info
*ic
;
992 if (HIWORD(wparam
) != BN_CLICKED
)
995 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
997 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1000 if (LOWORD(wparam
) == IDC_CONFIGURE
)
1001 ICConfigure(ic
->hic
, hdlg
);
1003 ICAbout(ic
->hic
, hdlg
);
1011 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1013 struct codec_info
*ic
;
1015 if (HIWORD(wparam
) != BN_CLICKED
)
1018 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
1019 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1022 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
1024 choose_comp
->cv
.hic
= ic
->hic
;
1025 choose_comp
->cv
.fccType
= ic
->icinfo
.fccType
;
1026 choose_comp
->cv
.fccHandler
= ic
->icinfo
.fccHandler
;
1027 /* FIXME: fill everything else */
1029 /* prevent closing the codec handle below */
1036 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1039 if (HIWORD(wparam
) != BN_CLICKED
)
1044 struct codec_info
*ic
;
1046 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, idx
++, 0);
1048 if (!ic
|| (LONG_PTR
)ic
== CB_ERR
) break;
1050 if (ic
->hic
) ICClose(ic
->hic
);
1051 HeapFree(GetProcessHeap(), 0, ic
);
1054 EndDialog(hdlg
, LOWORD(wparam
) == IDOK
);
1070 /***********************************************************************
1071 * ICCompressorChoose [MSVFW32.@]
1073 BOOL VFWAPI
ICCompressorChoose(HWND hwnd
, UINT uiFlags
, LPVOID pvIn
,
1074 LPVOID lpData
, PCOMPVARS pc
, LPSTR lpszTitle
)
1076 struct choose_compressor choose_comp
;
1079 TRACE("(%p,%08x,%p,%p,%p,%s)\n", hwnd
, uiFlags
, pvIn
, lpData
, pc
, lpszTitle
);
1081 if (!pc
|| pc
->cbSize
!= sizeof(COMPVARS
))
1084 if (!(pc
->dwFlags
& ICMF_COMPVARS_VALID
))
1087 pc
->fccType
= pc
->fccHandler
= 0;
1091 pc
->lpBitsOut
= pc
->lpBitsPrev
= pc
->lpState
= NULL
;
1092 pc
->lQ
= ICQUALITY_DEFAULT
;
1094 pc
->lDataRate
= 300; /* kB */
1098 if (pc
->fccType
== 0)
1099 pc
->fccType
= ICTYPE_VIDEO
;
1101 choose_comp
.cv
= *pc
;
1102 choose_comp
.flags
= uiFlags
;
1103 choose_comp
.title
= lpszTitle
;
1105 ret
= DialogBoxParamW(MSVFW32_hModule
, MAKEINTRESOURCEW(ICM_CHOOSE_COMPRESSOR
), hwnd
,
1106 icm_choose_compressor_dlgproc
, (LPARAM
)&choose_comp
);
1110 *pc
= choose_comp
.cv
;
1111 pc
->dwFlags
|= ICMF_COMPVARS_VALID
;
1118 /***********************************************************************
1119 * ICCompressorFree [MSVFW32.@]
1121 void VFWAPI
ICCompressorFree(PCOMPVARS pc
)
1125 if (pc
!= NULL
&& pc
->cbSize
== sizeof(COMPVARS
)) {
1126 if (pc
->hic
!= NULL
) {
1130 HeapFree(GetProcessHeap(), 0, pc
->lpbiIn
);
1132 HeapFree(GetProcessHeap(), 0, pc
->lpBitsOut
);
1133 pc
->lpBitsOut
= NULL
;
1134 HeapFree(GetProcessHeap(), 0, pc
->lpBitsPrev
);
1135 pc
->lpBitsPrev
= NULL
;
1136 HeapFree(GetProcessHeap(), 0, pc
->lpState
);
1142 /***********************************************************************
1143 * ICSendMessage [MSVFW32.@]
1145 LRESULT VFWAPI
ICSendMessage(HIC hic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
1147 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1149 if (!whic
) return ICERR_BADHANDLE
;
1150 return MSVIDEO_SendMessage(whic
, msg
, lParam1
, lParam2
);
1153 /***********************************************************************
1154 * ICDrawBegin [MSVFW32.@]
1156 DWORD VFWAPIV
ICDrawBegin(
1158 DWORD dwFlags
, /* [in] flags */
1159 HPALETTE hpal
, /* [in] palette to draw with */
1160 HWND hwnd
, /* [in] window to draw to */
1161 HDC hdc
, /* [in] HDC to draw to */
1162 INT xDst
, /* [in] destination rectangle */
1163 INT yDst
, /* [in] */
1164 INT dxDst
, /* [in] */
1165 INT dyDst
, /* [in] */
1166 LPBITMAPINFOHEADER lpbi
, /* [in] format of frame to draw */
1167 INT xSrc
, /* [in] source rectangle */
1168 INT ySrc
, /* [in] */
1169 INT dxSrc
, /* [in] */
1170 INT dySrc
, /* [in] */
1171 DWORD dwRate
, /* [in] frames/second = (dwRate/dwScale) */
1172 DWORD dwScale
) /* [in] */
1177 TRACE("(%p,%d,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%d,%d)\n",
1178 hic
, dwFlags
, hpal
, hwnd
, hdc
, xDst
, yDst
, dxDst
, dyDst
,
1179 lpbi
, xSrc
, ySrc
, dxSrc
, dySrc
, dwRate
, dwScale
);
1181 icdb
.dwFlags
= dwFlags
;
1194 icdb
.dwRate
= dwRate
;
1195 icdb
.dwScale
= dwScale
;
1196 return ICSendMessage(hic
,ICM_DRAW_BEGIN
,(DWORD_PTR
)&icdb
,sizeof(icdb
));
1199 /***********************************************************************
1200 * ICDraw [MSVFW32.@]
1202 DWORD VFWAPIV
ICDraw(HIC hic
, DWORD dwFlags
, LPVOID lpFormat
, LPVOID lpData
, DWORD cbData
, LONG lTime
) {
1205 TRACE("(%p,%d,%p,%p,%d,%d)\n",hic
,dwFlags
,lpFormat
,lpData
,cbData
,lTime
);
1207 icd
.dwFlags
= dwFlags
;
1208 icd
.lpFormat
= lpFormat
;
1209 icd
.lpData
= lpData
;
1210 icd
.cbData
= cbData
;
1213 return ICSendMessage(hic
,ICM_DRAW
,(DWORD_PTR
)&icd
,sizeof(icd
));
1216 /***********************************************************************
1217 * ICClose [MSVFW32.@]
1219 LRESULT WINAPI
ICClose(HIC hic
)
1221 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1224 TRACE("(%p)\n",hic
);
1226 if (!whic
) return ICERR_BADHANDLE
;
1228 if (whic
->driverproc
)
1230 MSVIDEO_SendMessage(whic
, DRV_CLOSE
, 0, 0);
1231 MSVIDEO_SendMessage(whic
, DRV_DISABLE
, 0, 0);
1232 MSVIDEO_SendMessage(whic
, DRV_FREE
, 0, 0);
1236 CloseDriver(whic
->hdrv
, 0, 0);
1239 /* remove whic from list */
1240 for (p
= &MSVIDEO_FirstHic
; *p
!= NULL
; p
= &((*p
)->next
))
1249 HeapFree(GetProcessHeap(), 0, whic
);
1255 /***********************************************************************
1256 * ICImageCompress [MSVFW32.@]
1258 HANDLE VFWAPI
ICImageCompress(
1259 HIC hic
, UINT uiFlags
,
1260 LPBITMAPINFO lpbiIn
, LPVOID lpBits
,
1261 LPBITMAPINFO lpbiOut
, LONG lQuality
,
1264 FIXME("(%p,%08x,%p,%p,%p,%d,%p)\n",
1265 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
, lQuality
, plSize
);
1270 /***********************************************************************
1271 * ICImageDecompress [MSVFW32.@]
1274 HANDLE VFWAPI
ICImageDecompress(
1275 HIC hic
, UINT uiFlags
, LPBITMAPINFO lpbiIn
,
1276 LPVOID lpBits
, LPBITMAPINFO lpbiOut
)
1278 HGLOBAL hMem
= NULL
;
1280 BOOL bReleaseIC
= FALSE
;
1283 BOOL bSucceeded
= FALSE
;
1284 BOOL bInDecompress
= FALSE
;
1287 TRACE("(%p,%08x,%p,%p,%p)\n",
1288 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
);
1292 hic
= ICDecompressOpen( ICTYPE_VIDEO
, 0, &lpbiIn
->bmiHeader
, (lpbiOut
!= NULL
) ? &lpbiOut
->bmiHeader
: NULL
);
1295 WARN("no handler\n" );
1302 FIXME( "unknown flag %08x\n", uiFlags
);
1305 if ( lpbiIn
== NULL
|| lpBits
== NULL
)
1307 WARN("invalid argument\n");
1311 if ( lpbiOut
!= NULL
)
1313 if ( lpbiOut
->bmiHeader
.biSize
!= sizeof(BITMAPINFOHEADER
) )
1315 cbHdr
= sizeof(BITMAPINFOHEADER
);
1316 if ( lpbiOut
->bmiHeader
.biCompression
== 3 )
1317 cbHdr
+= sizeof(DWORD
)*3;
1319 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 )
1321 if ( lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1322 cbHdr
+= sizeof(RGBQUAD
) * (1<<lpbiOut
->bmiHeader
.biBitCount
);
1324 cbHdr
+= sizeof(RGBQUAD
) * lpbiOut
->bmiHeader
.biClrUsed
;
1329 TRACE( "get format\n" );
1331 cbHdr
= ICDecompressGetFormatSize(hic
,lpbiIn
);
1332 if ( cbHdr
< sizeof(BITMAPINFOHEADER
) )
1334 pHdr
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,cbHdr
+sizeof(RGBQUAD
)*256);
1337 if ( ICDecompressGetFormat( hic
, lpbiIn
, pHdr
) != ICERR_OK
)
1339 lpbiOut
= (BITMAPINFO
*)pHdr
;
1340 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1341 ICDecompressGetPalette( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
&&
1342 lpbiIn
->bmiHeader
.biBitCount
== lpbiOut
->bmiHeader
.biBitCount
)
1344 if ( lpbiIn
->bmiHeader
.biClrUsed
== 0 )
1345 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*(1<<lpbiOut
->bmiHeader
.biBitCount
) );
1347 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*lpbiIn
->bmiHeader
.biClrUsed
);
1349 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1350 lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1351 lpbiOut
->bmiHeader
.biClrUsed
= 1<<lpbiOut
->bmiHeader
.biBitCount
;
1353 lpbiOut
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1354 cbHdr
= sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
)*lpbiOut
->bmiHeader
.biClrUsed
;
1357 biSizeImage
= lpbiOut
->bmiHeader
.biSizeImage
;
1358 if ( biSizeImage
== 0 )
1359 biSizeImage
= ((((lpbiOut
->bmiHeader
.biWidth
* lpbiOut
->bmiHeader
.biBitCount
+ 7) >> 3) + 3) & (~3)) * abs(lpbiOut
->bmiHeader
.biHeight
);
1361 TRACE( "call ICDecompressBegin\n" );
1363 if ( ICDecompressBegin( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
)
1365 bInDecompress
= TRUE
;
1367 TRACE( "cbHdr %d, biSizeImage %d\n", cbHdr
, biSizeImage
);
1369 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_ZEROINIT
, cbHdr
+ biSizeImage
);
1372 WARN( "out of memory\n" );
1375 pMem
= GlobalLock( hMem
);
1378 memcpy( pMem
, lpbiOut
, cbHdr
);
1380 TRACE( "call ICDecompress\n" );
1381 if ( ICDecompress( hic
, 0, &lpbiIn
->bmiHeader
, lpBits
, &lpbiOut
->bmiHeader
, pMem
+cbHdr
) != ICERR_OK
)
1386 if ( bInDecompress
)
1387 ICDecompressEnd( hic
);
1390 HeapFree(GetProcessHeap(),0,pHdr
);
1392 GlobalUnlock( hMem
);
1393 if ( !bSucceeded
&& hMem
!= NULL
)
1395 GlobalFree(hMem
); hMem
= NULL
;
1401 /***********************************************************************
1402 * ICSeqCompressFrame [MSVFW32.@]
1404 LPVOID VFWAPI
ICSeqCompressFrame(PCOMPVARS pc
, UINT uiFlags
, LPVOID lpBits
, BOOL
*pfKey
, LONG
*plSize
)
1406 ICCOMPRESS
* icComp
= pc
->lpState
;
1408 TRACE("(%p, 0x%08x, %p, %p, %p)\n", pc
, uiFlags
, lpBits
, pfKey
, plSize
);
1410 if (pc
->cbState
!= sizeof(ICCOMPRESS
))
1412 ERR("Invalid cbState %i\n", pc
->cbState
);
1416 if (!pc
->lKeyCount
++)
1417 icComp
->dwFlags
= ICCOMPRESS_KEYFRAME
;
1420 if (pc
->lKey
&& pc
->lKeyCount
== (pc
->lKey
- 1))
1421 /* No key frames if pc->lKey == 0 */
1423 icComp
->dwFlags
= 0;
1426 icComp
->lpInput
= lpBits
;
1427 icComp
->lFrameNum
= pc
->lFrame
++;
1428 icComp
->lpOutput
= pc
->lpBitsOut
;
1429 icComp
->lpPrev
= pc
->lpBitsPrev
;
1430 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS
, (DWORD_PTR
)icComp
, sizeof(*icComp
));
1432 if (ret
== ICERR_OK
)
1434 LPVOID oldprev
, oldout
;
1436 if (icComp
->dwFlags
& AVIIF_KEYFRAME
)
1440 TRACE("Key frame\n");
1445 *plSize
= icComp
->lpbiOutput
->biSizeImage
;
1447 /* We shift Prev and Out, so we don't have to allocate and release memory */
1448 oldprev
= pc
->lpBitsPrev
;
1449 oldout
= pc
->lpBitsOut
;
1450 pc
->lpBitsPrev
= oldout
;
1451 pc
->lpBitsOut
= oldprev
;
1453 TRACE("returning: %p, compressed frame size %u\n", icComp
->lpOutput
, *plSize
);
1454 return icComp
->lpOutput
;
1459 static void clear_compvars(PCOMPVARS pc
)
1461 HeapFree(GetProcessHeap(), 0, pc
->lpbiIn
);
1462 HeapFree(GetProcessHeap(), 0, pc
->lpBitsPrev
);
1463 HeapFree(GetProcessHeap(), 0, pc
->lpBitsOut
);
1464 HeapFree(GetProcessHeap(), 0, pc
->lpState
);
1465 pc
->lpbiIn
= pc
->lpBitsPrev
= pc
->lpBitsOut
= pc
->lpState
= NULL
;
1466 if (pc
->dwFlags
& 0x80000000)
1468 HeapFree(GetProcessHeap(), 0, pc
->lpbiOut
);
1470 pc
->dwFlags
&= ~0x80000000;
1474 /***********************************************************************
1475 * ICSeqCompressFrameEnd [MSVFW32.@]
1477 void VFWAPI
ICSeqCompressFrameEnd(PCOMPVARS pc
)
1479 TRACE("(%p)\n", pc
);
1480 ICSendMessage(pc
->hic
, ICM_COMPRESS_END
, 0, 0);
1484 /***********************************************************************
1485 * ICSeqCompressFrameStart [MSVFW32.@]
1487 BOOL VFWAPI
ICSeqCompressFrameStart(PCOMPVARS pc
, LPBITMAPINFO lpbiIn
)
1489 /* I'm ignoring bmiColors as I don't know what to do with it,
1490 * it doesn't appear to be used though
1494 pc
->lpbiIn
= HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO
));
1498 *pc
->lpbiIn
= *lpbiIn
;
1500 pc
->lpState
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS
)
1501 + sizeof(*icComp
->lpckid
) + sizeof(*icComp
->lpdwFlags
));
1505 pc
->cbState
= sizeof(ICCOMPRESS
);
1509 /* Ask compressor for needed header size */
1510 int size
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1511 (DWORD_PTR
)pc
->lpbiIn
, 0);
1515 pc
->lpbiOut
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1518 /* Flag to show that we allocated lpbiOut for proper cleanup */
1519 pc
->dwFlags
|= 0x80000000;
1521 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1522 (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1523 if (ret
!= ICERR_OK
)
1525 ERR("Could not get output format from compressor\n");
1528 if (!pc
->lpbiOut
->bmiHeader
.biSizeImage
)
1530 /* If we can't know the output frame size for sure at least allocate
1531 * the same size of the input frame and also at least 8Kb to be sure
1532 * that poor compressors will have enough memory to work if the input
1533 * frame is too small.
1535 pc
->lpbiOut
->bmiHeader
.biSizeImage
= max(8192, pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1536 ERR("Bad codec! Invalid output frame size, guessing from input\n");
1540 TRACE("Input: %ux%u, fcc %s, bpp %u, size %u\n",
1541 pc
->lpbiIn
->bmiHeader
.biWidth
, pc
->lpbiIn
->bmiHeader
.biHeight
,
1542 wine_dbgstr_fcc(pc
->lpbiIn
->bmiHeader
.biCompression
),
1543 pc
->lpbiIn
->bmiHeader
.biBitCount
,
1544 pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1545 TRACE("Output: %ux%u, fcc %s, bpp %u, size %u\n",
1546 pc
->lpbiOut
->bmiHeader
.biWidth
, pc
->lpbiOut
->bmiHeader
.biHeight
,
1547 wine_dbgstr_fcc(pc
->lpbiOut
->bmiHeader
.biCompression
),
1548 pc
->lpbiOut
->bmiHeader
.biBitCount
,
1549 pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1551 /* Buffer for compressed frame data */
1552 pc
->lpBitsOut
= HeapAlloc(GetProcessHeap(), 0, pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1556 /* Buffer for previous compressed frame data */
1557 pc
->lpBitsPrev
= HeapAlloc(GetProcessHeap(), 0, pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1558 if (!pc
->lpBitsPrev
)
1568 "\tkey/data/quality: %i/%i/%i\n",
1569 pc
->cbSize
, pc
->dwFlags
, pc
->hic
, wine_dbgstr_fcc(pc
->fccType
),
1570 wine_dbgstr_fcc(pc
->fccHandler
), pc
->lpbiIn
, pc
->lpbiOut
, pc
->lKey
,
1571 pc
->lDataRate
, pc
->lQ
);
1573 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_BEGIN
, (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1574 if (ret
== ICERR_OK
)
1576 icComp
= pc
->lpState
;
1577 /* Initialise some variables */
1578 pc
->lFrame
= 0; pc
->lKeyCount
= 0;
1580 icComp
->lpbiOutput
= &pc
->lpbiOut
->bmiHeader
;
1581 icComp
->lpbiInput
= &pc
->lpbiIn
->bmiHeader
;
1582 icComp
->lpckid
= (DWORD
*)(icComp
+ 1);
1583 *icComp
->lpckid
= 0;
1584 icComp
->lpdwFlags
= (DWORD
*)((char *)(icComp
+ 1) + sizeof(*icComp
->lpckid
));
1585 *icComp
->lpdwFlags
= 0;
1586 icComp
->dwFrameSize
= 0;
1587 icComp
->dwQuality
= pc
->lQ
;
1588 icComp
->lpbiPrev
= &pc
->lpbiIn
->bmiHeader
;
1596 /***********************************************************************
1597 * GetFileNamePreview [MSVFW32.@]
1599 static BOOL
GetFileNamePreview(LPVOID lpofn
,BOOL bSave
,BOOL bUnicode
)
1601 CHAR szFunctionName
[20];
1602 BOOL (*fnGetFileName
)(LPVOID
);
1606 FIXME("(%p,%d,%d), semi-stub!\n",lpofn
,bSave
,bUnicode
);
1608 lstrcpyA(szFunctionName
, (bSave
? "GetSaveFileName" : "GetOpenFileName"));
1609 lstrcatA(szFunctionName
, (bUnicode
? "W" : "A"));
1611 hComdlg32
= LoadLibraryA("COMDLG32.DLL");
1612 if (hComdlg32
== NULL
)
1615 fnGetFileName
= (LPVOID
)GetProcAddress(hComdlg32
, szFunctionName
);
1616 if (fnGetFileName
== NULL
)
1618 FreeLibrary(hComdlg32
);
1622 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1623 ret
= fnGetFileName(lpofn
);
1625 FreeLibrary(hComdlg32
);
1629 /***********************************************************************
1630 * GetOpenFileNamePreviewA [MSVFW32.@]
1632 BOOL WINAPI
GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1634 FIXME("(%p), semi-stub!\n", lpofn
);
1636 return GetFileNamePreview(lpofn
, FALSE
, FALSE
);
1639 /***********************************************************************
1640 * GetOpenFileNamePreviewW [MSVFW32.@]
1642 BOOL WINAPI
GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1644 FIXME("(%p), semi-stub!\n", lpofn
);
1646 return GetFileNamePreview(lpofn
, FALSE
, TRUE
);
1649 /***********************************************************************
1650 * GetSaveFileNamePreviewA [MSVFW32.@]
1652 BOOL WINAPI
GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1654 FIXME("(%p), semi-stub!\n", lpofn
);
1656 return GetFileNamePreview(lpofn
, TRUE
, FALSE
);
1659 /***********************************************************************
1660 * GetSaveFileNamePreviewW [MSVFW32.@]
1662 BOOL WINAPI
GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1664 FIXME("(%p), semi-stub!\n", lpofn
);
1666 return GetFileNamePreview(lpofn
, TRUE
, TRUE
);