2 * Copyright 1998 Marcus Meissner
3 * Copyright 2000 Bradley Baetz
4 * Copyright 2003 Michael Günnewig
5 * Copyright 2005 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * FIXME: This all assumes 32 bit codecs
22 * Win95 appears to prefer 32 bit codecs, even from 16 bit code.
23 * There is the ICOpenFunction16 to worry about still, though.
29 #include "msvideo_private.h"
36 /* Drivers32 settings */
37 #define HKLM_DRIVERS32 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32"
39 WINE_DEFAULT_DEBUG_CHANNEL(msvideo
);
41 /* This one is a macro in order to work for both ASCII and Unicode */
42 #define fourcc_to_string(str, fcc) do { \
43 (str)[0] = LOBYTE(LOWORD(fcc)); \
44 (str)[1] = HIBYTE(LOWORD(fcc)); \
45 (str)[2] = LOBYTE(HIWORD(fcc)); \
46 (str)[3] = HIBYTE(HIWORD(fcc)); \
49 static inline const char *wine_dbgstr_fcc( DWORD fcc
)
52 fourcc_to_string(fcc_str
, fcc
);
54 /* Last byte may be ' ' in some cases like "DIB " */
55 if (isalnum(fcc_str
[0]) && isalnum(fcc_str
[1]) && isalnum(fcc_str
[2])
56 && (isalnum(fcc_str
[3]) || isspace(fcc_str
[3])))
57 return wine_dbg_sprintf("%s", fcc_str
);
58 return wine_dbg_sprintf("0x%08x", fcc
);
61 static const char *wine_dbgstr_icerr( int ret
)
64 if (ret
<= ICERR_CUSTOM
)
65 return wine_dbg_sprintf("ICERR_CUSTOM (%d)", ret
);
66 #define XX(x) case (x): str = #x; break
72 XX(ICERR_GOTOKEYFRAME
);
73 XX(ICERR_STOPDRAWING
);
74 XX(ICERR_UNSUPPORTED
);
85 XX(ICERR_BADBITDEPTH
);
86 XX(ICERR_BADIMAGESIZE
);
87 default: str
= wine_dbg_sprintf("UNKNOWN (%d)", ret
);
93 static inline int get_stride(int width
, int depth
)
95 return ((depth
* width
+ 31) >> 3) & ~3;
98 static WINE_HIC
* MSVIDEO_FirstHic
/* = NULL */;
100 typedef struct _reg_driver reg_driver
;
110 static reg_driver
* reg_driver_list
= NULL
;
112 HMODULE MSVFW32_hModule
;
114 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
116 TRACE("%p,%x,%p\n", hinst
, reason
, reserved
);
120 case DLL_PROCESS_ATTACH
:
121 DisableThreadLibraryCalls(hinst
);
122 MSVFW32_hModule
= hinst
;
128 /******************************************************************
129 * MSVIDEO_SendMessage
133 static LRESULT
MSVIDEO_SendMessage(WINE_HIC
* whic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
137 #define XX(x) case x: TRACE("(%p,"#x",0x%08lx,0x%08lx)\n",whic,lParam1,lParam2); break
152 XX(ICM_GETDEFAULTQUALITY
);
159 XX(ICM_COMPRESS_FRAMES_INFO
);
160 XX(ICM_COMPRESS_GET_FORMAT
);
161 XX(ICM_COMPRESS_GET_SIZE
);
162 XX(ICM_COMPRESS_QUERY
);
163 XX(ICM_COMPRESS_BEGIN
);
165 XX(ICM_COMPRESS_END
);
166 XX(ICM_DECOMPRESS_GET_FORMAT
);
167 XX(ICM_DECOMPRESS_QUERY
);
168 XX(ICM_DECOMPRESS_BEGIN
);
170 XX(ICM_DECOMPRESS_END
);
171 XX(ICM_DECOMPRESS_SET_PALETTE
);
172 XX(ICM_DECOMPRESS_GET_PALETTE
);
175 XX(ICM_DRAW_GET_PALETTE
);
179 XX(ICM_DRAW_GETTIME
);
182 XX(ICM_DRAW_SETTIME
);
183 XX(ICM_DRAW_REALIZE
);
185 XX(ICM_DRAW_RENDERBUFFER
);
186 XX(ICM_DRAW_START_PLAY
);
187 XX(ICM_DRAW_STOP_PLAY
);
188 XX(ICM_DRAW_SUGGESTFORMAT
);
189 XX(ICM_DRAW_CHANGEPALETTE
);
190 XX(ICM_GETBUFFERSWANTED
);
191 XX(ICM_GETDEFAULTKEYFRAMERATE
);
192 XX(ICM_DECOMPRESSEX_BEGIN
);
193 XX(ICM_DECOMPRESSEX_QUERY
);
194 XX(ICM_DECOMPRESSEX
);
195 XX(ICM_DECOMPRESSEX_END
);
196 XX(ICM_SET_STATUS_PROC
);
198 FIXME("(%p,0x%08x,0x%08lx,0x%08lx) unknown message\n",whic
,msg
,lParam1
,lParam2
);
203 if (whic
->driverproc
) {
204 /* dwDriverId parameter is the value returned by the DRV_OPEN */
205 ret
= whic
->driverproc(whic
->driverId
, whic
->hdrv
, msg
, lParam1
, lParam2
);
207 ret
= SendDriverMessage(whic
->hdrv
, msg
, lParam1
, lParam2
);
210 TRACE(" -> %s\n", wine_dbgstr_icerr(ret
));
214 static int compare_fourcc(DWORD fcc1
, DWORD fcc2
)
218 fourcc_to_string(fcc_str1
, fcc1
);
219 fourcc_to_string(fcc_str2
, fcc2
);
220 return strncasecmp(fcc_str1
, fcc_str2
, 4);
223 typedef BOOL (*enum_handler_t
)(const char*, unsigned int, void*);
225 static BOOL
enum_drivers(DWORD fccType
, enum_handler_t handler
, void* param
)
227 CHAR buf
[2048], fccTypeStr
[5], *s
;
228 DWORD i
, cnt
= 0, lRet
;
232 fourcc_to_string(fccTypeStr
, fccType
);
235 /* first, go through the registry entries */
236 lRet
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, HKLM_DRIVERS32
, 0, KEY_QUERY_VALUE
, &hKey
);
237 if (lRet
== ERROR_SUCCESS
)
239 DWORD name
, data
, type
;
244 data
= sizeof buf
- name
;
245 lRet
= RegEnumValueA(hKey
, i
++, buf
, &name
, 0, &type
, (LPBYTE
)(buf
+name
), &data
);
246 if (lRet
== ERROR_NO_MORE_ITEMS
) break;
247 if (lRet
!= ERROR_SUCCESS
) continue;
248 if (fccType
&& (name
!= 9 || strncasecmp(buf
, fccTypeStr
, 5))) continue;
250 if ((result
= handler(buf
, cnt
++, param
))) break;
254 if (result
) return result
;
256 /* if that didn't work, go through the values in system.ini */
257 if (GetPrivateProfileSectionA("drivers32", buf
, sizeof(buf
), "system.ini"))
259 for (s
= buf
; *s
; s
+= strlen(s
) + 1)
261 TRACE("got %s\n", s
);
262 if (fccType
&& (strncasecmp(s
, fccTypeStr
, 5) || s
[9] != '=')) continue;
263 if ((result
= handler(s
, cnt
++, param
))) break;
270 /******************************************************************
275 static WINE_HIC
* MSVIDEO_GetHicPtr(HIC hic
)
279 for (whic
= MSVIDEO_FirstHic
; whic
&& whic
->hic
!= hic
; whic
= whic
->next
);
283 /***********************************************************************
284 * VideoForWindowsVersion [MSVFW32.2]
285 * VideoForWindowsVersion [MSVIDEO.2]
286 * Returns the version in major.minor form.
287 * In Windows95 this returns 0x040003b6 (4.950)
289 DWORD WINAPI
VideoForWindowsVersion(void)
291 return 0x040003B6; /* 4.950 */
294 static BOOL
ICInfo_enum_handler(const char *drv
, unsigned int nr
, void *param
)
296 ICINFO
*lpicinfo
= param
;
297 DWORD fccHandler
= mmioStringToFOURCCA(drv
+ 5, 0);
299 if (lpicinfo
->fccHandler
!= nr
&& compare_fourcc(lpicinfo
->fccHandler
, fccHandler
))
302 lpicinfo
->fccHandler
= fccHandler
;
303 lpicinfo
->dwFlags
= 0;
304 lpicinfo
->dwVersion
= 0;
305 lpicinfo
->dwVersionICM
= ICVERSION
;
306 lpicinfo
->szName
[0] = 0;
307 lpicinfo
->szDescription
[0] = 0;
308 MultiByteToWideChar(CP_ACP
, 0, drv
+ 10, -1, lpicinfo
->szDriver
,
309 sizeof(lpicinfo
->szDriver
)/sizeof(WCHAR
));
314 /***********************************************************************
316 * Get information about an installable compressor. Return TRUE if there
320 * fccType [I] type of compressor (e.g. 'vidc')
321 * fccHandler [I] real fcc for handler or <n>th compressor
322 * lpicinfo [O] information about compressor
324 BOOL VFWAPI
ICInfo( DWORD fccType
, DWORD fccHandler
, ICINFO
*lpicinfo
)
326 TRACE("(%s,%s,%p)\n",
327 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), lpicinfo
);
329 lpicinfo
->fccType
= fccType
;
330 lpicinfo
->fccHandler
= fccHandler
;
331 return enum_drivers(fccType
, ICInfo_enum_handler
, lpicinfo
);
334 static DWORD IC_HandleRef
= 1;
336 /***********************************************************************
337 * ICInstall [MSVFW32.@]
339 BOOL VFWAPI
ICInstall(DWORD fccType
, DWORD fccHandler
, LPARAM lParam
, LPSTR szDesc
, UINT wFlags
)
344 TRACE("(%s,%s,%p,%p,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), (void*)lParam
, szDesc
, wFlags
);
346 /* Check if a driver is already registered */
347 for (driver
= reg_driver_list
; driver
; driver
= driver
->next
)
349 if (!compare_fourcc(fccType
, driver
->fccType
) &&
350 !compare_fourcc(fccHandler
, driver
->fccHandler
))
353 if (driver
) return FALSE
;
355 /* Register the driver */
356 driver
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(reg_driver
));
357 if (!driver
) goto oom
;
358 driver
->fccType
= fccType
;
359 driver
->fccHandler
= fccHandler
;
363 case ICINSTALL_FUNCTION
:
364 driver
->proc
= (DRIVERPROC
)lParam
;
367 case ICINSTALL_DRIVER
:
369 len
= MultiByteToWideChar(CP_ACP
, 0, (char*)lParam
, -1, NULL
, 0);
370 driver
->name
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
371 if (!driver
->name
) goto oom
;
372 MultiByteToWideChar(CP_ACP
, 0, (char*)lParam
, -1, driver
->name
, len
);
375 ERR("Invalid flags!\n");
376 HeapFree(GetProcessHeap(), 0, driver
);
380 /* Insert our driver in the list*/
381 driver
->next
= reg_driver_list
;
382 reg_driver_list
= driver
;
386 HeapFree(GetProcessHeap(), 0, driver
);
390 /***********************************************************************
391 * ICRemove [MSVFW32.@]
393 BOOL VFWAPI
ICRemove(DWORD fccType
, DWORD fccHandler
, UINT wFlags
)
395 reg_driver
** pdriver
;
398 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wFlags
);
400 /* Check if a driver is already registered */
401 for (pdriver
= ®_driver_list
; *pdriver
; pdriver
= &(*pdriver
)->next
)
403 if (!compare_fourcc(fccType
, (*pdriver
)->fccType
) &&
404 !compare_fourcc(fccHandler
, (*pdriver
)->fccHandler
))
410 /* Remove the driver from the list */
412 *pdriver
= (*pdriver
)->next
;
413 HeapFree(GetProcessHeap(), 0, drv
->name
);
414 HeapFree(GetProcessHeap(), 0, drv
);
420 /***********************************************************************
422 * Opens an installable compressor. Return special handle.
424 HIC VFWAPI
ICOpen(DWORD fccType
, DWORD fccHandler
, UINT wMode
)
430 static const WCHAR drv32W
[] = {'d','r','i','v','e','r','s','3','2','\0'};
433 TRACE("(%s,%s,0x%08x)\n", wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wMode
);
435 if (!fccHandler
) /* No specific handler, return the first valid for wMode */
440 info
.dwSize
= sizeof(info
);
441 while(ICInfo(fccType
, loop
++, &info
))
443 /* Ensure fccHandler is not 0x0 because we will recurse on ICOpen */
446 local
= ICOpen(fccType
, info
.fccHandler
, wMode
);
449 TRACE("Returning %s as default handler for %s\n",
450 wine_dbgstr_fcc(info
.fccHandler
), wine_dbgstr_fcc(fccType
));
456 /* Check if there is a registered driver that matches */
457 driver
= reg_driver_list
;
459 if (!compare_fourcc(fccType
, driver
->fccType
) &&
460 !compare_fourcc(fccHandler
, driver
->fccHandler
)) {
461 fccType
= driver
->fccType
;
462 fccHandler
= driver
->fccHandler
;
465 driver
= driver
->next
;
467 if (driver
&& driver
->proc
)
468 /* The driver has been registered at runtime with its driverproc */
469 return ICOpenFunction(fccType
, fccHandler
, wMode
, driver
->proc
);
471 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
472 * same layout as ICOPEN
474 icopen
.dwSize
= sizeof(ICOPEN
);
475 icopen
.fccType
= fccType
;
476 icopen
.fccHandler
= fccHandler
;
477 icopen
.dwVersion
= 0x00001000; /* FIXME */
478 icopen
.dwFlags
= wMode
;
480 icopen
.pV1Reserved
= NULL
;
481 icopen
.pV2Reserved
= NULL
;
482 icopen
.dnDevNode
= 0; /* FIXME */
485 /* normalize to lower case as in 'vidc' */
486 ((char*)&fccType
)[0] = tolower(((char*)&fccType
)[0]);
487 ((char*)&fccType
)[1] = tolower(((char*)&fccType
)[1]);
488 ((char*)&fccType
)[2] = tolower(((char*)&fccType
)[2]);
489 ((char*)&fccType
)[3] = tolower(((char*)&fccType
)[3]);
490 icopen
.fccType
= fccType
;
491 /* Seek the driver in the registry */
492 fourcc_to_string(codecname
, fccType
);
494 fourcc_to_string(codecname
+ 5, fccHandler
);
497 hdrv
= OpenDriver(codecname
, drv32W
, (LPARAM
)&icopen
);
501 /* The driver has been registered at runtime with its name */
502 hdrv
= OpenDriver(driver
->name
, NULL
, (LPARAM
)&icopen
);
507 whic
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC
));
510 CloseDriver(hdrv
, 0, 0);
514 whic
->driverproc
= NULL
;
515 whic
->type
= fccType
;
516 whic
->handler
= fccHandler
;
517 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
518 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
519 whic
->next
= MSVIDEO_FirstHic
;
520 MSVIDEO_FirstHic
= whic
;
522 TRACE("=> %p\n", whic
->hic
);
526 /***********************************************************************
527 * ICOpenFunction [MSVFW32.@]
529 HIC VFWAPI
ICOpenFunction(DWORD fccType
, DWORD fccHandler
, UINT wMode
, DRIVERPROC lpfnHandler
)
534 TRACE("(%s,%s,%d,%p)\n",
535 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), wMode
, lpfnHandler
);
537 icopen
.dwSize
= sizeof(ICOPEN
);
538 icopen
.fccType
= fccType
;
539 icopen
.fccHandler
= fccHandler
;
540 icopen
.dwVersion
= ICVERSION
;
541 icopen
.dwFlags
= wMode
;
543 icopen
.pV1Reserved
= NULL
;
544 icopen
.pV2Reserved
= NULL
;
545 icopen
.dnDevNode
= 0; /* FIXME */
547 whic
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HIC
));
550 whic
->driverproc
= lpfnHandler
;
551 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
552 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
553 whic
->next
= MSVIDEO_FirstHic
;
554 MSVIDEO_FirstHic
= whic
;
556 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
557 /* What if the function is used more than once? */
559 if (MSVIDEO_SendMessage(whic
, DRV_LOAD
, 0L, 0L) != DRV_SUCCESS
)
561 WARN("DRV_LOAD failed for hic %p\n", whic
->hic
);
562 MSVIDEO_FirstHic
= whic
->next
;
563 HeapFree(GetProcessHeap(), 0, whic
);
566 /* return value is not checked */
567 MSVIDEO_SendMessage(whic
, DRV_ENABLE
, 0L, 0L);
569 whic
->driverId
= (DWORD
)MSVIDEO_SendMessage(whic
, DRV_OPEN
, 0, (DWORD_PTR
)&icopen
);
570 /* FIXME: What should we put here? */
573 if (whic
->driverId
== 0)
575 WARN("DRV_OPEN failed for hic %p\n", whic
->hic
);
576 MSVIDEO_FirstHic
= whic
->next
;
577 HeapFree(GetProcessHeap(), 0, whic
);
581 TRACE("=> %p\n", whic
->hic
);
585 /***********************************************************************
586 * ICGetInfo [MSVFW32.@]
588 LRESULT VFWAPI
ICGetInfo(HIC hic
, ICINFO
*picinfo
, DWORD cb
)
591 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
593 TRACE("(%p,%p,%d)\n", hic
, picinfo
, cb
);
595 if (!whic
) return ICERR_BADHANDLE
;
596 if (!picinfo
) return MMSYSERR_INVALPARAM
;
598 /* (WS) The field szDriver should be initialized because the driver
599 * is not obliged and often will not do it. Some applications, like
600 * VirtualDub, rely on this field and will occasionally crash if it
601 * goes uninitialized.
603 if (cb
>= sizeof(ICINFO
)) picinfo
->szDriver
[0] = '\0';
605 ret
= ICSendMessage(hic
, ICM_GETINFO
, (DWORD_PTR
)picinfo
, cb
);
607 /* (WS) When szDriver was not supplied by the driver itself, apparently
608 * Windows will set its value equal to the driver file name. This can
609 * be obtained from the registry as we do here.
611 if (cb
>= sizeof(ICINFO
) && picinfo
->szDriver
[0] == 0)
615 memset(&ii
, 0, sizeof(ii
));
616 ii
.dwSize
= sizeof(ii
);
617 ICInfo(picinfo
->fccType
, picinfo
->fccHandler
, &ii
);
618 lstrcpyW(picinfo
->szDriver
, ii
.szDriver
);
627 LPBITMAPINFOHEADER lpbiIn
;
628 LPBITMAPINFOHEADER lpbiOut
;
634 static HIC
try_driver(driver_info_t
*info
)
638 if ((hic
= ICOpen(info
->fccType
, info
->fccHandler
, info
->wMode
)))
640 if (!ICSendMessage(hic
, info
->querymsg
, (DWORD_PTR
)info
->lpbiIn
, (DWORD_PTR
)info
->lpbiOut
))
647 static BOOL
ICLocate_enum_handler(const char *drv
, unsigned int nr
, void *param
)
649 driver_info_t
*info
= param
;
650 info
->fccHandler
= mmioStringToFOURCCA(drv
+ 5, 0);
651 info
->hic
= try_driver(info
);
652 return info
->hic
!= 0;
655 /***********************************************************************
656 * ICLocate [MSVFW32.@]
658 HIC VFWAPI
ICLocate(DWORD fccType
, DWORD fccHandler
, LPBITMAPINFOHEADER lpbiIn
,
659 LPBITMAPINFOHEADER lpbiOut
, WORD wMode
)
663 TRACE("(%s,%s,%p,%p,0x%04x)\n",
664 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
), lpbiIn
, lpbiOut
, wMode
);
666 info
.fccType
= fccType
;
667 info
.fccHandler
= fccHandler
;
668 info
.lpbiIn
= lpbiIn
;
669 info
.lpbiOut
= lpbiOut
;
674 case ICMODE_FASTCOMPRESS
:
675 case ICMODE_COMPRESS
:
676 info
.querymsg
= ICM_COMPRESS_QUERY
;
678 case ICMODE_FASTDECOMPRESS
:
679 case ICMODE_DECOMPRESS
:
680 info
.querymsg
= ICM_DECOMPRESS_QUERY
;
683 info
.querymsg
= ICM_DRAW_QUERY
;
686 WARN("Unknown mode (%d)\n", wMode
);
690 /* Easy case: handler/type match, we just fire a query and return */
691 info
.hic
= try_driver(&info
);
692 /* If it didn't work, try each driver in turn. 32 bit codecs only. */
693 /* FIXME: Move this to an init routine? */
694 if (!info
.hic
) enum_drivers(fccType
, ICLocate_enum_handler
, &info
);
698 TRACE("=> %p\n", info
.hic
);
702 if (fccType
== streamtypeVIDEO
)
703 return ICLocate(ICTYPE_VIDEO
, fccHandler
, lpbiIn
, lpbiOut
, wMode
);
705 ERR("Required media codec '%s %s' not found!\n",
706 wine_dbgstr_fcc(fccType
), wine_dbgstr_fcc(fccHandler
));
710 /***********************************************************************
711 * ICGetDisplayFormat [MSVFW32.@]
713 HIC VFWAPI
ICGetDisplayFormat(
714 HIC hic
,LPBITMAPINFOHEADER lpbiIn
,LPBITMAPINFOHEADER lpbiOut
,
715 INT depth
,INT dx
,INT dy
)
736 TRACE("(%p,%p,%p,%d,%d,%d)!\n", hic
, lpbiIn
, lpbiOut
, depth
, dx
, dy
);
738 tmphic
= hic
? hic
: ICLocate(ICTYPE_VIDEO
, 0, lpbiIn
, NULL
, ICMODE_DECOMPRESS
);
739 if (!tmphic
) return tmphic
;
742 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
) * GetDeviceCaps(hdc
, PLANES
);
745 if (dx
<= 0) dx
= lpbiIn
->biWidth
;
746 if (dy
<= 0) dy
= lpbiIn
->biHeight
;
747 if (!depth
) depth
= screen_depth
;
749 /* Can we decompress it ? */
750 if (ICDecompressQuery(tmphic
, lpbiIn
, NULL
) != ICERR_OK
)
751 goto errout
; /* no, sorry */
753 ICSendMessage(tmphic
, ICM_DECOMPRESS_GET_FORMAT
, (DWORD_PTR
)lpbiIn
, (DWORD_PTR
)lpbiOut
);
755 lpbiOut
->biSize
= sizeof(BITMAPINFOHEADER
);
756 lpbiOut
->biWidth
= dx
;
757 lpbiOut
->biHeight
= dy
;
758 lpbiOut
->biPlanes
= 1;
760 for (i
= 0; i
< sizeof(try_depths
) / sizeof(try_depths
[0]); i
++)
762 if (!found
&& try_depths
[i
].depth
!= depth
)
766 lpbiOut
->biBitCount
= try_depths
[i
].depth
;
767 lpbiOut
->biCompression
= try_depths
[i
].compression
;
768 lpbiOut
->biSizeImage
= dx
* get_stride(dy
, lpbiOut
->biBitCount
);
770 if (ICDecompressQuery(tmphic
, lpbiIn
, lpbiOut
) == ICERR_OK
)
772 if (try_depths
[i
].depth
== 8)
773 ICDecompressGetPalette(tmphic
, lpbiIn
, lpbiOut
);
780 lpbiOut
->biBitCount
= depth
;
781 lpbiOut
->biCompression
= BI_RGB
;
782 lpbiOut
->biSizeImage
= dx
* get_stride(dy
, lpbiOut
->biBitCount
);
783 if (ICDecompressQuery(tmphic
, lpbiIn
, lpbiOut
) == ICERR_OK
)
786 lpbiOut
->biBitCount
= screen_depth
;
787 lpbiOut
->biCompression
= BI_RGB
;
788 lpbiOut
->biSizeImage
= dx
* get_stride(dy
, lpbiOut
->biBitCount
);
789 if (ICDecompressQuery(tmphic
, lpbiIn
, lpbiOut
) == ICERR_OK
)
793 if (ICSendMessage(tmphic
, ICM_DECOMPRESS_GET_FORMAT
, (DWORD_PTR
)lpbiIn
, (DWORD_PTR
)lpbiOut
))
796 if (lpbiOut
->biCompression
!= 0) {
797 FIXME("Ooch, how come decompressor outputs compressed data (%d)??\n",
798 lpbiOut
->biCompression
);
800 if (lpbiOut
->biSize
< sizeof(*lpbiOut
)) {
801 FIXME("Ooch, size of output BIH is too small (%d)\n",
803 lpbiOut
->biSize
= sizeof(*lpbiOut
);
807 TRACE("=> %p\n", tmphic
);
818 /***********************************************************************
819 * ICCompress [MSVFW32.@]
823 HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiOutput
,LPVOID lpData
,
824 LPBITMAPINFOHEADER lpbiInput
,LPVOID lpBits
,LPDWORD lpckid
,
825 LPDWORD lpdwFlags
,LONG lFrameNum
,DWORD dwFrameSize
,DWORD dwQuality
,
826 LPBITMAPINFOHEADER lpbiPrev
,LPVOID lpPrev
)
830 TRACE("(%p,%d,%p,%p,%p,%p,...)\n",hic
,dwFlags
,lpbiOutput
,lpData
,lpbiInput
,lpBits
);
832 iccmp
.dwFlags
= dwFlags
;
834 iccmp
.lpbiOutput
= lpbiOutput
;
835 iccmp
.lpOutput
= lpData
;
836 iccmp
.lpbiInput
= lpbiInput
;
837 iccmp
.lpInput
= lpBits
;
839 iccmp
.lpckid
= lpckid
;
840 iccmp
.lpdwFlags
= lpdwFlags
;
841 iccmp
.lFrameNum
= lFrameNum
;
842 iccmp
.dwFrameSize
= dwFrameSize
;
843 iccmp
.dwQuality
= dwQuality
;
844 iccmp
.lpbiPrev
= lpbiPrev
;
845 iccmp
.lpPrev
= lpPrev
;
846 return ICSendMessage(hic
,ICM_COMPRESS
,(DWORD_PTR
)&iccmp
,sizeof(iccmp
));
849 /***********************************************************************
850 * ICDecompress [MSVFW32.@]
852 DWORD VFWAPIV
ICDecompress(HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiFormat
,
853 LPVOID lpData
,LPBITMAPINFOHEADER lpbi
,LPVOID lpBits
)
858 TRACE("(%p,%d,%p,%p,%p,%p)\n",hic
,dwFlags
,lpbiFormat
,lpData
,lpbi
,lpBits
);
860 icd
.dwFlags
= dwFlags
;
861 icd
.lpbiInput
= lpbiFormat
;
862 icd
.lpInput
= lpData
;
864 icd
.lpbiOutput
= lpbi
;
865 icd
.lpOutput
= lpBits
;
867 ret
= ICSendMessage(hic
,ICM_DECOMPRESS
,(DWORD_PTR
)&icd
,sizeof(ICDECOMPRESS
));
873 struct choose_compressor
886 static BOOL
enum_compressors(HWND list
, COMPVARS
*pcv
, BOOL enum_all
)
893 while (ICInfo(pcv
->fccType
, id
, &icinfo
))
895 struct codec_info
*ic
;
901 hic
= ICOpen(icinfo
.fccType
, icinfo
.fccHandler
, ICMODE_COMPRESS
);
905 /* for unknown reason fccHandler reported by the driver
906 * doesn't always work, use the one returned by ICInfo instead.
908 DWORD fccHandler
= icinfo
.fccHandler
;
910 if (!enum_all
&& pcv
->lpbiIn
)
912 if (ICCompressQuery(hic
, pcv
->lpbiIn
, NULL
) != ICERR_OK
)
914 TRACE("fccHandler %s doesn't support input DIB format %d\n",
915 wine_dbgstr_fcc(icinfo
.fccHandler
), pcv
->lpbiIn
->bmiHeader
.biCompression
);
921 ICGetInfo(hic
, &icinfo
, sizeof(icinfo
));
922 icinfo
.fccHandler
= fccHandler
;
924 idx
= SendMessageW(list
, CB_ADDSTRING
, 0, (LPARAM
)icinfo
.szDescription
);
926 ic
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info
));
929 SendMessageW(list
, CB_SETITEMDATA
, idx
, (LPARAM
)ic
);
937 static INT_PTR CALLBACK
icm_choose_compressor_dlgproc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
943 struct codec_info
*ic
;
945 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)lparam
;
947 SetWindowLongPtrW(hdlg
, DWLP_USER
, lparam
);
950 choose_comp
->flags
&= ~(ICMF_CHOOSE_DATARATE
| ICMF_CHOOSE_KEYFRAME
);
952 if (choose_comp
->title
)
953 SetWindowTextA(hdlg
, choose_comp
->title
);
955 if (!(choose_comp
->flags
& ICMF_CHOOSE_DATARATE
))
957 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_CHECKBOX
), SW_HIDE
);
958 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE
), SW_HIDE
);
959 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_KB
), SW_HIDE
);
962 if (!(choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
))
964 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_CHECKBOX
), SW_HIDE
);
965 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME
), SW_HIDE
);
966 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_FRAMES
), SW_HIDE
);
970 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_SCROLL
), FALSE
);
971 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_TXT
), FALSE
);
973 /*if (!(choose_comp->flags & ICMF_CHOOSE_PREVIEW))
974 ShowWindow(GetDlgItem(hdlg, IDC_PREVIEW), SW_HIDE);*/
976 LoadStringW(MSVFW32_hModule
, IDS_FULLFRAMES
, buf
, 128);
977 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
979 ic
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info
));
980 ic
->icinfo
.fccType
= streamtypeVIDEO
;
981 ic
->icinfo
.fccHandler
= comptypeDIB
;
983 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETITEMDATA
, 0, (LPARAM
)ic
);
985 enum_compressors(GetDlgItem(hdlg
, IDC_COMP_LIST
), &choose_comp
->cv
, choose_comp
->flags
& ICMF_CHOOSE_ALLCOMPRESSORS
);
987 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETCURSEL
, 0, 0);
988 SetFocus(GetDlgItem(hdlg
, IDC_COMP_LIST
));
990 SetWindowLongPtrW(hdlg
, DWLP_USER
, (ULONG_PTR
)choose_comp
);
995 switch (LOWORD(wparam
))
1000 struct codec_info
*ic
;
1001 BOOL can_configure
= FALSE
, can_about
= FALSE
;
1002 struct choose_compressor
*choose_comp
;
1004 if (HIWORD(wparam
) != CBN_SELCHANGE
&& HIWORD(wparam
) != CBN_SETFOCUS
)
1007 choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
1009 cur_sel
= SendMessageW((HWND
)lparam
, CB_GETCURSEL
, 0, 0);
1011 ic
= (struct codec_info
*)SendMessageW((HWND
)lparam
, CB_GETITEMDATA
, cur_sel
, 0);
1014 if (ICQueryConfigure(ic
->hic
) == DRVCNF_OK
)
1015 can_configure
= TRUE
;
1016 if (ICQueryAbout(ic
->hic
) == DRVCNF_OK
)
1019 EnableWindow(GetDlgItem(hdlg
, IDC_CONFIGURE
), can_configure
);
1020 EnableWindow(GetDlgItem(hdlg
, IDC_ABOUT
), can_about
);
1022 if (choose_comp
->flags
& ICMF_CHOOSE_DATARATE
)
1026 if (choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
)
1037 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1039 struct codec_info
*ic
;
1041 if (HIWORD(wparam
) != BN_CLICKED
)
1044 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
1046 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1049 if (LOWORD(wparam
) == IDC_CONFIGURE
)
1050 ICConfigure(ic
->hic
, hdlg
);
1052 ICAbout(ic
->hic
, hdlg
);
1060 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1062 struct codec_info
*ic
;
1064 if (HIWORD(wparam
) != BN_CLICKED
)
1067 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
1068 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1071 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
1073 choose_comp
->cv
.hic
= ic
->hic
;
1074 choose_comp
->cv
.fccType
= ic
->icinfo
.fccType
;
1075 choose_comp
->cv
.fccHandler
= ic
->icinfo
.fccHandler
;
1076 /* FIXME: fill everything else */
1078 /* prevent closing the codec handle below */
1085 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1088 if (HIWORD(wparam
) != BN_CLICKED
)
1093 struct codec_info
*ic
;
1095 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, idx
++, 0);
1097 if (!ic
|| (LONG_PTR
)ic
== CB_ERR
) break;
1099 if (ic
->hic
) ICClose(ic
->hic
);
1100 HeapFree(GetProcessHeap(), 0, ic
);
1103 EndDialog(hdlg
, LOWORD(wparam
) == IDOK
);
1119 /***********************************************************************
1120 * ICCompressorChoose [MSVFW32.@]
1122 BOOL VFWAPI
ICCompressorChoose(HWND hwnd
, UINT uiFlags
, LPVOID pvIn
,
1123 LPVOID lpData
, PCOMPVARS pc
, LPSTR lpszTitle
)
1125 struct choose_compressor choose_comp
;
1128 TRACE("(%p,%08x,%p,%p,%p,%s)\n", hwnd
, uiFlags
, pvIn
, lpData
, pc
, lpszTitle
);
1130 if (!pc
|| pc
->cbSize
!= sizeof(COMPVARS
))
1133 if (!(pc
->dwFlags
& ICMF_COMPVARS_VALID
))
1136 pc
->fccType
= pc
->fccHandler
= 0;
1140 pc
->lpBitsOut
= pc
->lpBitsPrev
= pc
->lpState
= NULL
;
1141 pc
->lQ
= ICQUALITY_DEFAULT
;
1143 pc
->lDataRate
= 300; /* kB */
1147 if (pc
->fccType
== 0)
1148 pc
->fccType
= ICTYPE_VIDEO
;
1150 choose_comp
.cv
= *pc
;
1151 choose_comp
.flags
= uiFlags
;
1152 choose_comp
.title
= lpszTitle
;
1154 ret
= DialogBoxParamW(MSVFW32_hModule
, MAKEINTRESOURCEW(ICM_CHOOSE_COMPRESSOR
), hwnd
,
1155 icm_choose_compressor_dlgproc
, (LPARAM
)&choose_comp
);
1159 *pc
= choose_comp
.cv
;
1160 pc
->dwFlags
|= ICMF_COMPVARS_VALID
;
1167 /***********************************************************************
1168 * ICCompressorFree [MSVFW32.@]
1170 void VFWAPI
ICCompressorFree(PCOMPVARS pc
)
1174 if (pc
!= NULL
&& pc
->cbSize
== sizeof(COMPVARS
)) {
1175 if (pc
->hic
!= NULL
) {
1179 HeapFree(GetProcessHeap(), 0, pc
->lpbiIn
);
1181 HeapFree(GetProcessHeap(), 0, pc
->lpBitsOut
);
1182 pc
->lpBitsOut
= NULL
;
1183 HeapFree(GetProcessHeap(), 0, pc
->lpBitsPrev
);
1184 pc
->lpBitsPrev
= NULL
;
1185 HeapFree(GetProcessHeap(), 0, pc
->lpState
);
1191 /***********************************************************************
1192 * ICSendMessage [MSVFW32.@]
1194 LRESULT VFWAPI
ICSendMessage(HIC hic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
1196 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1198 if (!whic
) return ICERR_BADHANDLE
;
1199 return MSVIDEO_SendMessage(whic
, msg
, lParam1
, lParam2
);
1202 /***********************************************************************
1203 * ICDrawBegin [MSVFW32.@]
1205 DWORD VFWAPIV
ICDrawBegin(
1207 DWORD dwFlags
, /* [in] flags */
1208 HPALETTE hpal
, /* [in] palette to draw with */
1209 HWND hwnd
, /* [in] window to draw to */
1210 HDC hdc
, /* [in] HDC to draw to */
1211 INT xDst
, /* [in] destination rectangle */
1212 INT yDst
, /* [in] */
1213 INT dxDst
, /* [in] */
1214 INT dyDst
, /* [in] */
1215 LPBITMAPINFOHEADER lpbi
, /* [in] format of frame to draw */
1216 INT xSrc
, /* [in] source rectangle */
1217 INT ySrc
, /* [in] */
1218 INT dxSrc
, /* [in] */
1219 INT dySrc
, /* [in] */
1220 DWORD dwRate
, /* [in] frames/second = (dwRate/dwScale) */
1221 DWORD dwScale
) /* [in] */
1226 TRACE("(%p,%d,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%d,%d)\n",
1227 hic
, dwFlags
, hpal
, hwnd
, hdc
, xDst
, yDst
, dxDst
, dyDst
,
1228 lpbi
, xSrc
, ySrc
, dxSrc
, dySrc
, dwRate
, dwScale
);
1230 icdb
.dwFlags
= dwFlags
;
1243 icdb
.dwRate
= dwRate
;
1244 icdb
.dwScale
= dwScale
;
1245 return ICSendMessage(hic
,ICM_DRAW_BEGIN
,(DWORD_PTR
)&icdb
,sizeof(icdb
));
1248 /***********************************************************************
1249 * ICDraw [MSVFW32.@]
1251 DWORD VFWAPIV
ICDraw(HIC hic
, DWORD dwFlags
, LPVOID lpFormat
, LPVOID lpData
, DWORD cbData
, LONG lTime
) {
1254 TRACE("(%p,%d,%p,%p,%d,%d)\n",hic
,dwFlags
,lpFormat
,lpData
,cbData
,lTime
);
1256 icd
.dwFlags
= dwFlags
;
1257 icd
.lpFormat
= lpFormat
;
1258 icd
.lpData
= lpData
;
1259 icd
.cbData
= cbData
;
1262 return ICSendMessage(hic
,ICM_DRAW
,(DWORD_PTR
)&icd
,sizeof(icd
));
1265 /***********************************************************************
1266 * ICClose [MSVFW32.@]
1268 LRESULT WINAPI
ICClose(HIC hic
)
1270 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1273 TRACE("(%p)\n",hic
);
1275 if (!whic
) return ICERR_BADHANDLE
;
1277 if (whic
->driverproc
)
1279 MSVIDEO_SendMessage(whic
, DRV_CLOSE
, 0, 0);
1280 MSVIDEO_SendMessage(whic
, DRV_DISABLE
, 0, 0);
1281 MSVIDEO_SendMessage(whic
, DRV_FREE
, 0, 0);
1285 CloseDriver(whic
->hdrv
, 0, 0);
1288 /* remove whic from list */
1289 for (p
= &MSVIDEO_FirstHic
; *p
!= NULL
; p
= &((*p
)->next
))
1298 HeapFree(GetProcessHeap(), 0, whic
);
1304 /***********************************************************************
1305 * ICImageCompress [MSVFW32.@]
1307 HANDLE VFWAPI
ICImageCompress(
1308 HIC hic
, UINT uiFlags
,
1309 LPBITMAPINFO lpbiIn
, LPVOID lpBits
,
1310 LPBITMAPINFO lpbiOut
, LONG lQuality
,
1313 FIXME("(%p,%08x,%p,%p,%p,%d,%p)\n",
1314 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
, lQuality
, plSize
);
1319 /***********************************************************************
1320 * ICImageDecompress [MSVFW32.@]
1323 HANDLE VFWAPI
ICImageDecompress(
1324 HIC hic
, UINT uiFlags
, LPBITMAPINFO lpbiIn
,
1325 LPVOID lpBits
, LPBITMAPINFO lpbiOut
)
1327 HGLOBAL hMem
= NULL
;
1329 BOOL bReleaseIC
= FALSE
;
1332 BOOL bSucceeded
= FALSE
;
1333 BOOL bInDecompress
= FALSE
;
1336 TRACE("(%p,%08x,%p,%p,%p)\n",
1337 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
);
1341 hic
= ICDecompressOpen( ICTYPE_VIDEO
, 0, &lpbiIn
->bmiHeader
, (lpbiOut
!= NULL
) ? &lpbiOut
->bmiHeader
: NULL
);
1344 WARN("no handler\n" );
1351 FIXME( "unknown flag %08x\n", uiFlags
);
1354 if ( lpbiIn
== NULL
|| lpBits
== NULL
)
1356 WARN("invalid argument\n");
1360 if ( lpbiOut
!= NULL
)
1362 if ( lpbiOut
->bmiHeader
.biSize
!= sizeof(BITMAPINFOHEADER
) )
1364 cbHdr
= sizeof(BITMAPINFOHEADER
);
1365 if ( lpbiOut
->bmiHeader
.biCompression
== 3 )
1366 cbHdr
+= sizeof(DWORD
)*3;
1368 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 )
1370 if ( lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1371 cbHdr
+= sizeof(RGBQUAD
) * (1<<lpbiOut
->bmiHeader
.biBitCount
);
1373 cbHdr
+= sizeof(RGBQUAD
) * lpbiOut
->bmiHeader
.biClrUsed
;
1378 TRACE( "get format\n" );
1380 cbHdr
= ICDecompressGetFormatSize(hic
,lpbiIn
);
1381 if ( cbHdr
< sizeof(BITMAPINFOHEADER
) )
1383 pHdr
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,cbHdr
+sizeof(RGBQUAD
)*256);
1386 if ( ICDecompressGetFormat( hic
, lpbiIn
, pHdr
) != ICERR_OK
)
1388 lpbiOut
= (BITMAPINFO
*)pHdr
;
1389 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1390 ICDecompressGetPalette( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
&&
1391 lpbiIn
->bmiHeader
.biBitCount
== lpbiOut
->bmiHeader
.biBitCount
)
1393 if ( lpbiIn
->bmiHeader
.biClrUsed
== 0 )
1394 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*(1<<lpbiOut
->bmiHeader
.biBitCount
) );
1396 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*lpbiIn
->bmiHeader
.biClrUsed
);
1398 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1399 lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1400 lpbiOut
->bmiHeader
.biClrUsed
= 1<<lpbiOut
->bmiHeader
.biBitCount
;
1402 lpbiOut
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1403 cbHdr
= sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
)*lpbiOut
->bmiHeader
.biClrUsed
;
1406 biSizeImage
= lpbiOut
->bmiHeader
.biSizeImage
;
1407 if ( biSizeImage
== 0 )
1408 biSizeImage
= ((((lpbiOut
->bmiHeader
.biWidth
* lpbiOut
->bmiHeader
.biBitCount
+ 7) >> 3) + 3) & (~3)) * abs(lpbiOut
->bmiHeader
.biHeight
);
1410 TRACE( "call ICDecompressBegin\n" );
1412 if ( ICDecompressBegin( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
)
1414 bInDecompress
= TRUE
;
1416 TRACE( "cbHdr %d, biSizeImage %d\n", cbHdr
, biSizeImage
);
1418 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_ZEROINIT
, cbHdr
+ biSizeImage
);
1421 WARN( "out of memory\n" );
1424 pMem
= GlobalLock( hMem
);
1427 memcpy( pMem
, lpbiOut
, cbHdr
);
1429 TRACE( "call ICDecompress\n" );
1430 if ( ICDecompress( hic
, 0, &lpbiIn
->bmiHeader
, lpBits
, &lpbiOut
->bmiHeader
, pMem
+cbHdr
) != ICERR_OK
)
1435 if ( bInDecompress
)
1436 ICDecompressEnd( hic
);
1439 HeapFree(GetProcessHeap(),0,pHdr
);
1441 GlobalUnlock( hMem
);
1442 if ( !bSucceeded
&& hMem
!= NULL
)
1444 GlobalFree(hMem
); hMem
= NULL
;
1450 /***********************************************************************
1451 * ICSeqCompressFrame [MSVFW32.@]
1453 LPVOID VFWAPI
ICSeqCompressFrame(PCOMPVARS pc
, UINT uiFlags
, LPVOID lpBits
, BOOL
*pfKey
, LONG
*plSize
)
1455 ICCOMPRESS
* icComp
= pc
->lpState
;
1457 TRACE("(%p, 0x%08x, %p, %p, %p)\n", pc
, uiFlags
, lpBits
, pfKey
, plSize
);
1459 if (pc
->cbState
!= sizeof(ICCOMPRESS
))
1461 ERR("Invalid cbState %i\n", pc
->cbState
);
1465 if (!pc
->lKeyCount
++)
1466 icComp
->dwFlags
= ICCOMPRESS_KEYFRAME
;
1469 if (pc
->lKey
&& pc
->lKeyCount
== (pc
->lKey
- 1))
1470 /* No key frames if pc->lKey == 0 */
1472 icComp
->dwFlags
= 0;
1475 icComp
->lpInput
= lpBits
;
1476 icComp
->lFrameNum
= pc
->lFrame
++;
1477 icComp
->lpOutput
= pc
->lpBitsOut
;
1478 icComp
->lpPrev
= pc
->lpBitsPrev
;
1479 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS
, (DWORD_PTR
)icComp
, sizeof(*icComp
));
1481 if (ret
== ICERR_OK
)
1483 LPVOID oldprev
, oldout
;
1485 if (icComp
->dwFlags
& AVIIF_KEYFRAME
)
1489 TRACE("Key frame\n");
1494 *plSize
= icComp
->lpbiOutput
->biSizeImage
;
1496 /* We shift Prev and Out, so we don't have to allocate and release memory */
1497 oldprev
= pc
->lpBitsPrev
;
1498 oldout
= pc
->lpBitsOut
;
1499 pc
->lpBitsPrev
= oldout
;
1500 pc
->lpBitsOut
= oldprev
;
1502 TRACE("returning: %p, compressed frame size %u\n", icComp
->lpOutput
, *plSize
);
1503 return icComp
->lpOutput
;
1508 static void clear_compvars(PCOMPVARS pc
)
1510 HeapFree(GetProcessHeap(), 0, pc
->lpbiIn
);
1511 HeapFree(GetProcessHeap(), 0, pc
->lpBitsPrev
);
1512 HeapFree(GetProcessHeap(), 0, pc
->lpBitsOut
);
1513 HeapFree(GetProcessHeap(), 0, pc
->lpState
);
1514 pc
->lpbiIn
= pc
->lpBitsPrev
= pc
->lpBitsOut
= pc
->lpState
= NULL
;
1515 if (pc
->dwFlags
& 0x80000000)
1517 HeapFree(GetProcessHeap(), 0, pc
->lpbiOut
);
1519 pc
->dwFlags
&= ~0x80000000;
1523 /***********************************************************************
1524 * ICSeqCompressFrameEnd [MSVFW32.@]
1526 void VFWAPI
ICSeqCompressFrameEnd(PCOMPVARS pc
)
1528 TRACE("(%p)\n", pc
);
1529 ICSendMessage(pc
->hic
, ICM_COMPRESS_END
, 0, 0);
1533 /***********************************************************************
1534 * ICSeqCompressFrameStart [MSVFW32.@]
1536 BOOL VFWAPI
ICSeqCompressFrameStart(PCOMPVARS pc
, LPBITMAPINFO lpbiIn
)
1538 /* I'm ignoring bmiColors as I don't know what to do with it,
1539 * it doesn't appear to be used though
1543 pc
->lpbiIn
= HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFO
));
1547 *pc
->lpbiIn
= *lpbiIn
;
1549 pc
->lpState
= HeapAlloc(GetProcessHeap(), 0, sizeof(ICCOMPRESS
)
1550 + sizeof(*icComp
->lpckid
) + sizeof(*icComp
->lpdwFlags
));
1554 pc
->cbState
= sizeof(ICCOMPRESS
);
1558 /* Ask compressor for needed header size */
1559 int size
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1560 (DWORD_PTR
)pc
->lpbiIn
, 0);
1564 pc
->lpbiOut
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1567 /* Flag to show that we allocated lpbiOut for proper cleanup */
1568 pc
->dwFlags
|= 0x80000000;
1570 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1571 (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1572 if (ret
!= ICERR_OK
)
1574 ERR("Could not get output format from compressor\n");
1577 if (!pc
->lpbiOut
->bmiHeader
.biSizeImage
)
1579 /* If we can't know the output frame size for sure at least allocate
1580 * the same size of the input frame and also at least 8Kb to be sure
1581 * that poor compressors will have enough memory to work if the input
1582 * frame is too small.
1584 pc
->lpbiOut
->bmiHeader
.biSizeImage
= max(8192, pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1585 ERR("Bad codec! Invalid output frame size, guessing from input\n");
1589 TRACE("Input: %ux%u, fcc %s, bpp %u, size %u\n",
1590 pc
->lpbiIn
->bmiHeader
.biWidth
, pc
->lpbiIn
->bmiHeader
.biHeight
,
1591 wine_dbgstr_fcc(pc
->lpbiIn
->bmiHeader
.biCompression
),
1592 pc
->lpbiIn
->bmiHeader
.biBitCount
,
1593 pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1594 TRACE("Output: %ux%u, fcc %s, bpp %u, size %u\n",
1595 pc
->lpbiOut
->bmiHeader
.biWidth
, pc
->lpbiOut
->bmiHeader
.biHeight
,
1596 wine_dbgstr_fcc(pc
->lpbiOut
->bmiHeader
.biCompression
),
1597 pc
->lpbiOut
->bmiHeader
.biBitCount
,
1598 pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1600 /* Buffer for compressed frame data */
1601 pc
->lpBitsOut
= HeapAlloc(GetProcessHeap(), 0, pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1605 /* Buffer for previous compressed frame data */
1606 pc
->lpBitsPrev
= HeapAlloc(GetProcessHeap(), 0, pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1607 if (!pc
->lpBitsPrev
)
1617 "\tkey/data/quality: %i/%i/%i\n",
1618 pc
->cbSize
, pc
->dwFlags
, pc
->hic
, wine_dbgstr_fcc(pc
->fccType
),
1619 wine_dbgstr_fcc(pc
->fccHandler
), pc
->lpbiIn
, pc
->lpbiOut
, pc
->lKey
,
1620 pc
->lDataRate
, pc
->lQ
);
1622 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_BEGIN
, (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1623 if (ret
== ICERR_OK
)
1625 icComp
= pc
->lpState
;
1626 /* Initialise some variables */
1627 pc
->lFrame
= 0; pc
->lKeyCount
= 0;
1629 icComp
->lpbiOutput
= &pc
->lpbiOut
->bmiHeader
;
1630 icComp
->lpbiInput
= &pc
->lpbiIn
->bmiHeader
;
1631 icComp
->lpckid
= (DWORD
*)(icComp
+ 1);
1632 *icComp
->lpckid
= 0;
1633 icComp
->lpdwFlags
= (DWORD
*)((char *)(icComp
+ 1) + sizeof(*icComp
->lpckid
));
1634 *icComp
->lpdwFlags
= 0;
1635 icComp
->dwFrameSize
= 0;
1636 icComp
->dwQuality
= pc
->lQ
;
1637 icComp
->lpbiPrev
= &pc
->lpbiIn
->bmiHeader
;
1645 /***********************************************************************
1646 * GetFileNamePreview [MSVFW32.@]
1648 static BOOL
GetFileNamePreview(LPVOID lpofn
,BOOL bSave
,BOOL bUnicode
)
1650 CHAR szFunctionName
[20];
1651 BOOL (*fnGetFileName
)(LPVOID
);
1655 FIXME("(%p,%d,%d), semi-stub!\n",lpofn
,bSave
,bUnicode
);
1657 lstrcpyA(szFunctionName
, (bSave
? "GetSaveFileName" : "GetOpenFileName"));
1658 lstrcatA(szFunctionName
, (bUnicode
? "W" : "A"));
1660 hComdlg32
= LoadLibraryA("COMDLG32.DLL");
1661 if (hComdlg32
== NULL
)
1664 fnGetFileName
= (LPVOID
)GetProcAddress(hComdlg32
, szFunctionName
);
1665 if (fnGetFileName
== NULL
)
1667 FreeLibrary(hComdlg32
);
1671 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1672 ret
= fnGetFileName(lpofn
);
1674 FreeLibrary(hComdlg32
);
1678 /***********************************************************************
1679 * GetOpenFileNamePreviewA [MSVFW32.@]
1681 BOOL WINAPI
GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1683 FIXME("(%p), semi-stub!\n", lpofn
);
1685 return GetFileNamePreview(lpofn
, FALSE
, FALSE
);
1688 /***********************************************************************
1689 * GetOpenFileNamePreviewW [MSVFW32.@]
1691 BOOL WINAPI
GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1693 FIXME("(%p), semi-stub!\n", lpofn
);
1695 return GetFileNamePreview(lpofn
, FALSE
, TRUE
);
1698 /***********************************************************************
1699 * GetSaveFileNamePreviewA [MSVFW32.@]
1701 BOOL WINAPI
GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1703 FIXME("(%p), semi-stub!\n", lpofn
);
1705 return GetFileNamePreview(lpofn
, TRUE
, FALSE
);
1708 /***********************************************************************
1709 * GetSaveFileNamePreviewW [MSVFW32.@]
1711 BOOL WINAPI
GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1713 FIXME("(%p), semi-stub!\n", lpofn
);
1715 return GetFileNamePreview(lpofn
, TRUE
, TRUE
);