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.
42 #include "msvideo_private.h"
43 #include "wine/debug.h"
44 #include "wine/list.h"
46 /* Drivers32 settings */
47 #define HKLM_DRIVERS32 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32"
49 WINE_DEFAULT_DEBUG_CHANNEL(msvideo
);
51 /* This one is a macro in order to work for both ASCII and Unicode */
52 #define fourcc_to_string(str, fcc) do { \
53 (str)[0] = LOBYTE(LOWORD(fcc)); \
54 (str)[1] = HIBYTE(LOWORD(fcc)); \
55 (str)[2] = LOBYTE(HIWORD(fcc)); \
56 (str)[3] = HIBYTE(HIWORD(fcc)); \
59 static const char *wine_dbgstr_icerr( int ret
)
62 if (ret
<= ICERR_CUSTOM
)
63 return wine_dbg_sprintf("ICERR_CUSTOM (%d)", ret
);
64 #define XX(x) case (x): str = #x; break
70 XX(ICERR_GOTOKEYFRAME
);
71 XX(ICERR_STOPDRAWING
);
72 XX(ICERR_UNSUPPORTED
);
83 XX(ICERR_BADBITDEPTH
);
84 XX(ICERR_BADIMAGESIZE
);
85 default: str
= wine_dbg_sprintf("UNKNOWN (%d)", ret
);
91 static WINE_HIC
* MSVIDEO_FirstHic
/* = NULL */;
101 static struct list reg_driver_list
= LIST_INIT(reg_driver_list
);
103 HMODULE MSVFW32_hModule
;
105 BOOL WINAPI
DllMain( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
107 TRACE("%p,%lx,%p\n", hinst
, reason
, reserved
);
111 case DLL_PROCESS_ATTACH
:
112 DisableThreadLibraryCalls(hinst
);
113 MSVFW32_hModule
= hinst
;
119 /******************************************************************
120 * MSVIDEO_SendMessage
124 static LRESULT
MSVIDEO_SendMessage(WINE_HIC
* whic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
128 #define XX(x) case x: TRACE("(%p,"#x",0x%08Ix,0x%08Ix)\n",whic,lParam1,lParam2); break
143 XX(ICM_GETDEFAULTQUALITY
);
150 XX(ICM_COMPRESS_FRAMES_INFO
);
151 XX(ICM_COMPRESS_GET_FORMAT
);
152 XX(ICM_COMPRESS_GET_SIZE
);
153 XX(ICM_COMPRESS_QUERY
);
154 XX(ICM_COMPRESS_BEGIN
);
156 XX(ICM_COMPRESS_END
);
157 XX(ICM_DECOMPRESS_GET_FORMAT
);
158 XX(ICM_DECOMPRESS_QUERY
);
159 XX(ICM_DECOMPRESS_BEGIN
);
161 XX(ICM_DECOMPRESS_END
);
162 XX(ICM_DECOMPRESS_SET_PALETTE
);
163 XX(ICM_DECOMPRESS_GET_PALETTE
);
166 XX(ICM_DRAW_GET_PALETTE
);
170 XX(ICM_DRAW_GETTIME
);
173 XX(ICM_DRAW_SETTIME
);
174 XX(ICM_DRAW_REALIZE
);
176 XX(ICM_DRAW_RENDERBUFFER
);
177 XX(ICM_DRAW_START_PLAY
);
178 XX(ICM_DRAW_STOP_PLAY
);
179 XX(ICM_DRAW_SUGGESTFORMAT
);
180 XX(ICM_DRAW_CHANGEPALETTE
);
181 XX(ICM_GETBUFFERSWANTED
);
182 XX(ICM_GETDEFAULTKEYFRAMERATE
);
183 XX(ICM_DECOMPRESSEX_BEGIN
);
184 XX(ICM_DECOMPRESSEX_QUERY
);
185 XX(ICM_DECOMPRESSEX
);
186 XX(ICM_DECOMPRESSEX_END
);
187 XX(ICM_SET_STATUS_PROC
);
189 FIXME("(%p,0x%08x,0x%08Ix,0x%08Ix) unknown message\n",whic
,msg
,lParam1
,lParam2
);
194 if (whic
->driverproc
) {
195 /* dwDriverId parameter is the value returned by the DRV_OPEN */
196 ret
= whic
->driverproc(whic
->driverId
, whic
->hdrv
, msg
, lParam1
, lParam2
);
198 ret
= SendDriverMessage(whic
->hdrv
, msg
, lParam1
, lParam2
);
201 TRACE(" -> %s\n", wine_dbgstr_icerr(ret
));
205 static int compare_fourcc(DWORD fcc1
, DWORD fcc2
)
209 fourcc_to_string(fcc_str1
, fcc1
);
210 fourcc_to_string(fcc_str2
, fcc2
);
211 return _strnicmp(fcc_str1
, fcc_str2
, 4);
214 static DWORD
get_size_image(LONG width
, LONG height
, WORD depth
)
216 DWORD ret
= width
* depth
;
217 ret
= (ret
+ 7) / 8; /* divide by byte size, rounding up */
218 ret
= (ret
+ 3) & ~3; /* align to 4 bytes */
223 /******************************************************************
228 static WINE_HIC
* MSVIDEO_GetHicPtr(HIC hic
)
232 for (whic
= MSVIDEO_FirstHic
; whic
&& whic
->hic
!= hic
; whic
= whic
->next
);
236 /***********************************************************************
237 * VideoForWindowsVersion [MSVFW32.2]
238 * VideoForWindowsVersion [MSVIDEO.2]
239 * Returns the version in major.minor form.
240 * In Windows95 this returns 0x040003b6 (4.950)
242 DWORD WINAPI
VideoForWindowsVersion(void)
244 return 0x040003B6; /* 4.950 */
247 /***********************************************************************
249 * Get information about an installable compressor. Return TRUE if there
253 * fccType [I] type of compressor (e.g. 'vidc')
254 * fccHandler [I] real fcc for handler or <n>th compressor
255 * lpicinfo [O] information about compressor
257 BOOL VFWAPI
ICInfo(DWORD type
, DWORD handler
, ICINFO
*info
)
259 char name_buf
[10], buf
[2048];
260 DWORD ret_type
, ret_handler
;
261 struct reg_driver
*driver
;
266 TRACE("type %s, handler %s, info %p.\n",
267 debugstr_fourcc(type
), debugstr_fourcc(handler
), info
);
269 memset(info
, 0, sizeof(*info
));
270 info
->dwSize
= sizeof(*info
);
271 info
->dwVersionICM
= ICVERSION
;
273 if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE
, HKLM_DRIVERS32
, 0, KEY_QUERY_VALUE
, &key
))
278 DWORD name_len
= ARRAY_SIZE(name_buf
), driver_len
= ARRAY_SIZE(info
->szDriver
);
280 res
= RegEnumValueA(key
, i
++, name_buf
, &name_len
, 0, 0, (BYTE
*)buf
, &driver_len
);
281 if (res
== ERROR_NO_MORE_ITEMS
) break;
283 if (name_len
!= 9 || name_buf
[4] != '.') continue;
284 ret_type
= mmioStringToFOURCCA(name_buf
, 0);
285 ret_handler
= mmioStringToFOURCCA(name_buf
+ 5, 0);
286 if (type
&& compare_fourcc(type
, ret_type
)) continue;
287 if (compare_fourcc(handler
, ret_handler
) && handler
!= count
++) continue;
289 info
->fccType
= ret_type
;
290 info
->fccHandler
= ret_handler
;
291 MultiByteToWideChar(CP_ACP
, 0, buf
, -1, info
->szDriver
, ARRAY_SIZE(info
->szDriver
));
292 TRACE("Returning codec %s, driver %s.\n", debugstr_a(name_buf
), debugstr_a(buf
));
298 if (GetPrivateProfileSectionA("drivers32", buf
, sizeof(buf
), "system.ini"))
301 for (s
= buf
; *s
; s
+= strlen(s
) + 1)
303 if (s
[4] != '.' || s
[9] != '=') continue;
304 ret_type
= mmioStringToFOURCCA(s
, 0);
305 ret_handler
= mmioStringToFOURCCA(s
+ 5, 0);
306 if (type
&& compare_fourcc(type
, ret_type
)) continue;
307 if (compare_fourcc(handler
, ret_handler
) && handler
!= count
++) continue;
309 info
->fccType
= ret_type
;
310 info
->fccHandler
= ret_handler
;
311 MultiByteToWideChar(CP_ACP
, 0, s
+ 10, -1, info
->szDriver
, ARRAY_SIZE(info
->szDriver
));
312 TRACE("Returning codec %s, driver %s.\n", debugstr_an(s
, 9), debugstr_a(s
+ 10));
317 LIST_FOR_EACH_ENTRY(driver
, ®_driver_list
, struct reg_driver
, entry
)
319 if (type
&& compare_fourcc(type
, driver
->fccType
)) continue;
320 if (compare_fourcc(handler
, driver
->fccHandler
) && handler
!= count
++) continue;
321 if (driver
->proc(0, NULL
, ICM_GETINFO
, (DWORD_PTR
)info
, sizeof(*info
)) == sizeof(*info
))
325 info
->fccType
= type
;
326 info
->fccHandler
= handler
;
327 WARN("No driver found for codec %s.%s.\n", debugstr_fourcc(type
), debugstr_fourcc(handler
));
331 static DWORD IC_HandleRef
= 1;
333 /***********************************************************************
334 * ICInstall [MSVFW32.@]
336 BOOL VFWAPI
ICInstall(DWORD type
, DWORD handler
, LPARAM lparam
, char *desc
, UINT flags
)
338 struct reg_driver
*driver
;
340 TRACE("type %s, handler %s, lparam %#Ix, desc %s, flags %#x.\n",
341 debugstr_fourcc(type
), debugstr_fourcc(handler
), lparam
, debugstr_a(desc
), flags
);
343 LIST_FOR_EACH_ENTRY(driver
, ®_driver_list
, struct reg_driver
, entry
)
345 if (!compare_fourcc(type
, driver
->fccType
)
346 && !compare_fourcc(handler
, driver
->fccHandler
))
354 case ICINSTALL_FUNCTION
:
355 if (!(driver
= calloc(1, sizeof(*driver
))))
357 driver
->fccType
= type
;
358 driver
->fccHandler
= handler
;
359 driver
->proc
= (DRIVERPROC
)lparam
;
360 list_add_tail(®_driver_list
, &driver
->entry
);
362 case ICINSTALL_DRIVER
:
364 const char *driver
= (const char *)lparam
;
369 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
, HKLM_DRIVERS32
, 0, KEY_SET_VALUE
, &key
))
371 fourcc_to_string(value
, type
);
373 fourcc_to_string(value
+ 5, handler
);
375 res
= RegSetValueExA(key
, value
, 0, REG_SZ
, (const BYTE
*)driver
, strlen(driver
) + 1);
380 FIXME("Unhandled flags %#x.\n", flags
);
385 /***********************************************************************
386 * ICRemove [MSVFW32.@]
388 BOOL VFWAPI
ICRemove(DWORD type
, DWORD handler
, UINT flags
)
390 struct reg_driver
*driver
;
395 TRACE("type %s, handler %s, flags %#x.\n",
396 debugstr_fourcc(type
), debugstr_fourcc(handler
), flags
);
398 LIST_FOR_EACH_ENTRY(driver
, ®_driver_list
, struct reg_driver
, entry
)
400 if (!compare_fourcc(type
, driver
->fccType
)
401 && !compare_fourcc(handler
, driver
->fccHandler
))
403 list_remove(&driver
->entry
);
409 if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE
, HKLM_DRIVERS32
, 0, KEY_SET_VALUE
, &key
))
411 fourcc_to_string(value
, type
);
413 fourcc_to_string(value
+ 5, handler
);
415 res
= RegDeleteValueA(key
, value
);
424 /***********************************************************************
426 * Opens an installable compressor. Return special handle.
428 HIC VFWAPI
ICOpen(DWORD fccType
, DWORD fccHandler
, UINT wMode
)
433 static const WCHAR drv32W
[] = {'d','r','i','v','e','r','s','3','2','\0'};
434 struct reg_driver
*driver
;
437 TRACE("(%s,%s,0x%08x)\n", debugstr_fourcc(fccType
), debugstr_fourcc(fccHandler
), wMode
);
439 if (!fccHandler
) /* No specific handler, return the first valid for wMode */
444 info
.dwSize
= sizeof(info
);
445 while(ICInfo(fccType
, loop
++, &info
))
447 /* Ensure fccHandler is not 0x0 because we will recurse on ICOpen */
450 local
= ICOpen(fccType
, info
.fccHandler
, wMode
);
453 TRACE("Returning %s as default handler for %s\n",
454 debugstr_fourcc(info
.fccHandler
), debugstr_fourcc(fccType
));
460 LIST_FOR_EACH_ENTRY(driver
, ®_driver_list
, struct reg_driver
, entry
)
462 if (!compare_fourcc(fccType
, driver
->fccType
)
463 && !compare_fourcc(fccHandler
, driver
->fccHandler
))
465 return ICOpenFunction(driver
->fccType
, driver
->fccHandler
, wMode
, driver
->proc
);
469 /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the
470 * same layout as ICOPEN
472 icopen
.dwSize
= sizeof(ICOPEN
);
473 icopen
.fccType
= fccType
;
474 icopen
.fccHandler
= fccHandler
;
475 icopen
.dwVersion
= 0x00001000; /* FIXME */
476 icopen
.dwFlags
= wMode
;
478 icopen
.pV1Reserved
= NULL
;
479 icopen
.pV2Reserved
= NULL
;
480 icopen
.dnDevNode
= 0; /* FIXME */
484 /* normalize to lower case as in 'vidc' */
485 ((char*)&fccType
)[0] = tolower(((char*)&fccType
)[0]);
486 ((char*)&fccType
)[1] = tolower(((char*)&fccType
)[1]);
487 ((char*)&fccType
)[2] = tolower(((char*)&fccType
)[2]);
488 ((char*)&fccType
)[3] = tolower(((char*)&fccType
)[3]);
489 icopen
.fccType
= fccType
;
490 /* Seek the driver in the registry */
491 fourcc_to_string(codecname
, fccType
);
493 fourcc_to_string(codecname
+ 5, fccHandler
);
496 hdrv
= OpenDriver(codecname
, drv32W
, (LPARAM
)&icopen
);
501 if (!(whic
= malloc(sizeof(*whic
))))
503 CloseDriver(hdrv
, 0, 0);
507 whic
->driverproc
= NULL
;
508 whic
->type
= fccType
;
509 whic
->handler
= fccHandler
;
510 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
511 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
512 whic
->next
= MSVIDEO_FirstHic
;
513 MSVIDEO_FirstHic
= whic
;
515 TRACE("=> %p\n", whic
->hic
);
519 /***********************************************************************
520 * ICOpenFunction [MSVFW32.@]
522 HIC VFWAPI
ICOpenFunction(DWORD fccType
, DWORD fccHandler
, UINT wMode
, DRIVERPROC lpfnHandler
)
527 TRACE("(%s,%s,%d,%p)\n",
528 debugstr_fourcc(fccType
), debugstr_fourcc(fccHandler
), wMode
, lpfnHandler
);
530 icopen
.dwSize
= sizeof(ICOPEN
);
531 icopen
.fccType
= fccType
;
532 icopen
.fccHandler
= fccHandler
;
533 icopen
.dwVersion
= ICVERSION
;
534 icopen
.dwFlags
= wMode
;
536 icopen
.pV1Reserved
= NULL
;
537 icopen
.pV2Reserved
= NULL
;
538 icopen
.dnDevNode
= 0; /* FIXME */
540 if (!(whic
= malloc(sizeof(*whic
))))
543 whic
->driverproc
= lpfnHandler
;
544 while (MSVIDEO_GetHicPtr((HIC
)(ULONG_PTR
)IC_HandleRef
) != NULL
) IC_HandleRef
++;
545 whic
->hic
= (HIC
)(ULONG_PTR
)IC_HandleRef
++;
546 whic
->next
= MSVIDEO_FirstHic
;
547 MSVIDEO_FirstHic
= whic
;
549 /* Now try opening/loading the driver. Taken from DRIVER_AddToList */
550 /* What if the function is used more than once? */
552 if (MSVIDEO_SendMessage(whic
, DRV_LOAD
, 0L, 0L) != DRV_SUCCESS
)
554 WARN("DRV_LOAD failed for hic %p\n", whic
->hic
);
555 MSVIDEO_FirstHic
= whic
->next
;
559 /* return value is not checked */
560 MSVIDEO_SendMessage(whic
, DRV_ENABLE
, 0L, 0L);
562 whic
->driverId
= (DWORD
)MSVIDEO_SendMessage(whic
, DRV_OPEN
, 0, (DWORD_PTR
)&icopen
);
563 /* FIXME: What should we put here? */
566 if (whic
->driverId
== 0)
568 WARN("DRV_OPEN failed for hic %p\n", whic
->hic
);
569 MSVIDEO_FirstHic
= whic
->next
;
574 TRACE("=> %p\n", whic
->hic
);
578 /***********************************************************************
579 * ICGetInfo [MSVFW32.@]
581 LRESULT VFWAPI
ICGetInfo(HIC hic
, ICINFO
*picinfo
, DWORD cb
)
584 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
586 TRACE("(%p,%p,%ld)\n", hic
, picinfo
, cb
);
588 if (!whic
) return ICERR_BADHANDLE
;
589 if (!picinfo
) return MMSYSERR_INVALPARAM
;
591 /* (WS) The field szDriver should be initialized because the driver
592 * is not obliged and often will not do it. Some applications, like
593 * VirtualDub, rely on this field and will occasionally crash if it
594 * goes uninitialized.
596 if (cb
>= sizeof(ICINFO
)) picinfo
->szDriver
[0] = '\0';
598 ret
= ICSendMessage(hic
, ICM_GETINFO
, (DWORD_PTR
)picinfo
, cb
);
600 /* (WS) When szDriver was not supplied by the driver itself, apparently
601 * Windows will set its value equal to the driver file name. This can
602 * be obtained from the registry as we do here.
604 if (cb
>= sizeof(ICINFO
) && picinfo
->szDriver
[0] == 0)
608 memset(&ii
, 0, sizeof(ii
));
609 ii
.dwSize
= sizeof(ii
);
610 ICInfo(picinfo
->fccType
, picinfo
->fccHandler
, &ii
);
611 lstrcpyW(picinfo
->szDriver
, ii
.szDriver
);
617 /***********************************************************************
618 * ICLocate [MSVFW32.@]
620 HIC VFWAPI
ICLocate(DWORD type
, DWORD handler
, BITMAPINFOHEADER
*in
,
621 BITMAPINFOHEADER
*out
, WORD mode
)
623 ICINFO info
= {sizeof(info
)};
628 TRACE("type %s, handler %s, in %p, out %p, mode %u.\n",
629 debugstr_fourcc(type
), debugstr_fourcc(handler
), in
, out
, mode
);
633 case ICMODE_FASTCOMPRESS
:
634 case ICMODE_COMPRESS
:
635 msg
= ICM_COMPRESS_QUERY
;
637 case ICMODE_FASTDECOMPRESS
:
638 case ICMODE_DECOMPRESS
:
639 msg
= ICM_DECOMPRESS_QUERY
;
642 msg
= ICM_DRAW_QUERY
;
645 FIXME("Unhandled mode %#x.\n", mode
);
649 if ((hic
= ICOpen(type
, handler
, mode
)))
651 if (!ICSendMessage(hic
, msg
, (DWORD_PTR
)in
, (DWORD_PTR
)out
))
653 TRACE("Found codec %s.%s.\n", debugstr_fourcc(type
),
654 debugstr_fourcc(handler
));
660 for (i
= 0; ICInfo(type
, i
, &info
); ++i
)
662 if ((hic
= ICOpen(info
.fccType
, info
.fccHandler
, mode
)))
664 if (!ICSendMessage(hic
, msg
, (DWORD_PTR
)in
, (DWORD_PTR
)out
))
666 TRACE("Found codec %s.%s.\n", debugstr_fourcc(info
.fccType
),
667 debugstr_fourcc(info
.fccHandler
));
674 if (type
== streamtypeVIDEO
)
675 return ICLocate(ICTYPE_VIDEO
, handler
, in
, out
, mode
);
677 WARN("Could not find a driver for codec %s.%s.\n",
678 debugstr_fourcc(type
), debugstr_fourcc(handler
));
683 /***********************************************************************
684 * ICGetDisplayFormat [MSVFW32.@]
686 HIC VFWAPI
ICGetDisplayFormat(HIC hic
, BITMAPINFOHEADER
*in
, BITMAPINFOHEADER
*out
,
687 int depth
, int width
, int height
)
691 TRACE("(%p, %p, %p, %d, %d, %d)\n", hic
, in
, out
, depth
, width
, height
);
695 tmphic
= ICLocate(ICTYPE_VIDEO
, 0, in
, NULL
, ICMODE_DECOMPRESS
);
700 if (ICDecompressQuery(tmphic
, in
, NULL
))
703 if (width
<= 0 || height
<= 0)
706 height
= in
->biHeight
;
713 out
->biSize
= sizeof(*out
);
714 out
->biWidth
= width
;
715 out
->biHeight
= height
;
716 out
->biCompression
= BI_RGB
;
717 out
->biSizeImage
= get_size_image(width
, height
, depth
);
719 /* first try the given depth */
720 out
->biBitCount
= depth
;
721 out
->biSizeImage
= get_size_image(width
, height
, out
->biBitCount
);
722 if (!ICDecompressQuery(tmphic
, in
, out
))
725 ICDecompressGetPalette(tmphic
, in
, out
);
729 /* then try 16, both with BI_RGB and BI_BITFIELDS */
732 out
->biBitCount
= 16;
733 out
->biSizeImage
= get_size_image(width
, height
, out
->biBitCount
);
734 if (!ICDecompressQuery(tmphic
, in
, out
))
737 out
->biCompression
= BI_BITFIELDS
;
738 if (!ICDecompressQuery(tmphic
, in
, out
))
740 out
->biCompression
= BI_RGB
;
746 out
->biBitCount
= 24;
747 out
->biSizeImage
= get_size_image(width
, height
, out
->biBitCount
);
748 if (!ICDecompressQuery(tmphic
, in
, out
))
755 out
->biBitCount
= 32;
756 out
->biSizeImage
= get_size_image(width
, height
, out
->biBitCount
);
757 if (!ICDecompressQuery(tmphic
, in
, out
))
761 /* as a last resort, try 32 bpp with the original width and height */
762 out
->biWidth
= in
->biWidth
;
763 out
->biHeight
= in
->biHeight
;
764 out
->biBitCount
= 32;
765 out
->biSizeImage
= get_size_image(out
->biWidth
, out
->biHeight
, out
->biBitCount
);
766 if (!ICDecompressQuery(tmphic
, in
, out
))
769 /* finally, ask the compressor for its default output format */
770 if (!ICSendMessage(tmphic
, ICM_DECOMPRESS_GET_FORMAT
, (DWORD_PTR
)in
, (DWORD_PTR
)out
))
780 /***********************************************************************
781 * ICCompress [MSVFW32.@]
785 HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiOutput
,LPVOID lpData
,
786 LPBITMAPINFOHEADER lpbiInput
,LPVOID lpBits
,LPDWORD lpckid
,
787 LPDWORD lpdwFlags
,LONG lFrameNum
,DWORD dwFrameSize
,DWORD dwQuality
,
788 LPBITMAPINFOHEADER lpbiPrev
,LPVOID lpPrev
)
792 TRACE("(%p,%ld,%p,%p,%p,%p,...)\n",hic
,dwFlags
,lpbiOutput
,lpData
,lpbiInput
,lpBits
);
794 iccmp
.dwFlags
= dwFlags
;
796 iccmp
.lpbiOutput
= lpbiOutput
;
797 iccmp
.lpOutput
= lpData
;
798 iccmp
.lpbiInput
= lpbiInput
;
799 iccmp
.lpInput
= lpBits
;
801 iccmp
.lpckid
= lpckid
;
802 iccmp
.lpdwFlags
= lpdwFlags
;
803 iccmp
.lFrameNum
= lFrameNum
;
804 iccmp
.dwFrameSize
= dwFrameSize
;
805 iccmp
.dwQuality
= dwQuality
;
806 iccmp
.lpbiPrev
= lpbiPrev
;
807 iccmp
.lpPrev
= lpPrev
;
808 return ICSendMessage(hic
,ICM_COMPRESS
,(DWORD_PTR
)&iccmp
,sizeof(iccmp
));
811 /***********************************************************************
812 * ICDecompress [MSVFW32.@]
814 DWORD VFWAPIV
ICDecompress(HIC hic
,DWORD dwFlags
,LPBITMAPINFOHEADER lpbiFormat
,
815 LPVOID lpData
,LPBITMAPINFOHEADER lpbi
,LPVOID lpBits
)
820 TRACE("(%p,%ld,%p,%p,%p,%p)\n",hic
,dwFlags
,lpbiFormat
,lpData
,lpbi
,lpBits
);
822 icd
.dwFlags
= dwFlags
;
823 icd
.lpbiInput
= lpbiFormat
;
824 icd
.lpInput
= lpData
;
826 icd
.lpbiOutput
= lpbi
;
827 icd
.lpOutput
= lpBits
;
829 ret
= ICSendMessage(hic
,ICM_DECOMPRESS
,(DWORD_PTR
)&icd
,sizeof(ICDECOMPRESS
));
835 struct choose_compressor
848 static BOOL
enum_compressors(HWND list
, COMPVARS
*pcv
, BOOL enum_all
)
855 while (ICInfo(pcv
->fccType
, id
, &icinfo
))
857 struct codec_info
*ic
;
863 hic
= ICOpen(icinfo
.fccType
, icinfo
.fccHandler
, ICMODE_COMPRESS
);
867 /* for unknown reason fccHandler reported by the driver
868 * doesn't always work, use the one returned by ICInfo instead.
870 DWORD fccHandler
= icinfo
.fccHandler
;
872 if (!enum_all
&& pcv
->lpbiIn
)
874 if (ICCompressQuery(hic
, pcv
->lpbiIn
, NULL
) != ICERR_OK
)
876 TRACE("fccHandler %s doesn't support input DIB format %ld\n",
877 debugstr_fourcc(icinfo
.fccHandler
), pcv
->lpbiIn
->bmiHeader
.biCompression
);
883 ICGetInfo(hic
, &icinfo
, sizeof(icinfo
));
884 icinfo
.fccHandler
= fccHandler
;
886 idx
= SendMessageW(list
, CB_ADDSTRING
, 0, (LPARAM
)icinfo
.szDescription
);
888 ic
= malloc(sizeof(*ic
));
891 SendMessageW(list
, CB_SETITEMDATA
, idx
, (LPARAM
)ic
);
899 static INT_PTR CALLBACK
icm_choose_compressor_dlgproc(HWND hdlg
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
905 struct codec_info
*ic
;
907 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)lparam
;
909 SetWindowLongPtrW(hdlg
, DWLP_USER
, lparam
);
912 choose_comp
->flags
&= ~(ICMF_CHOOSE_DATARATE
| ICMF_CHOOSE_KEYFRAME
);
914 if (choose_comp
->title
)
915 SetWindowTextA(hdlg
, choose_comp
->title
);
917 if (!(choose_comp
->flags
& ICMF_CHOOSE_DATARATE
))
919 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_CHECKBOX
), SW_HIDE
);
920 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE
), SW_HIDE
);
921 ShowWindow(GetDlgItem(hdlg
, IDC_DATARATE_KB
), SW_HIDE
);
924 if (!(choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
))
926 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_CHECKBOX
), SW_HIDE
);
927 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME
), SW_HIDE
);
928 ShowWindow(GetDlgItem(hdlg
, IDC_KEYFRAME_FRAMES
), SW_HIDE
);
932 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_SCROLL
), FALSE
);
933 EnableWindow(GetDlgItem(hdlg
, IDC_QUALITY_TXT
), FALSE
);
935 /*if (!(choose_comp->flags & ICMF_CHOOSE_PREVIEW))
936 ShowWindow(GetDlgItem(hdlg, IDC_PREVIEW), SW_HIDE);*/
938 LoadStringW(MSVFW32_hModule
, IDS_FULLFRAMES
, buf
, 128);
939 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_ADDSTRING
, 0, (LPARAM
)buf
);
941 ic
= malloc(sizeof(*ic
));
942 ic
->icinfo
.fccType
= streamtypeVIDEO
;
943 ic
->icinfo
.fccHandler
= comptypeDIB
;
945 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETITEMDATA
, 0, (LPARAM
)ic
);
947 enum_compressors(GetDlgItem(hdlg
, IDC_COMP_LIST
), &choose_comp
->cv
, choose_comp
->flags
& ICMF_CHOOSE_ALLCOMPRESSORS
);
949 SendDlgItemMessageW(hdlg
, IDC_COMP_LIST
, CB_SETCURSEL
, 0, 0);
950 SetFocus(GetDlgItem(hdlg
, IDC_COMP_LIST
));
952 SetWindowLongPtrW(hdlg
, DWLP_USER
, (ULONG_PTR
)choose_comp
);
957 switch (LOWORD(wparam
))
962 struct codec_info
*ic
;
963 BOOL can_configure
= FALSE
, can_about
= FALSE
;
964 struct choose_compressor
*choose_comp
;
966 if (HIWORD(wparam
) != CBN_SELCHANGE
&& HIWORD(wparam
) != CBN_SETFOCUS
)
969 choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
971 cur_sel
= SendMessageW((HWND
)lparam
, CB_GETCURSEL
, 0, 0);
973 ic
= (struct codec_info
*)SendMessageW((HWND
)lparam
, CB_GETITEMDATA
, cur_sel
, 0);
976 if (ICQueryConfigure(ic
->hic
) == DRVCNF_OK
)
977 can_configure
= TRUE
;
978 if (ICQueryAbout(ic
->hic
) == DRVCNF_OK
)
981 EnableWindow(GetDlgItem(hdlg
, IDC_CONFIGURE
), can_configure
);
982 EnableWindow(GetDlgItem(hdlg
, IDC_ABOUT
), can_about
);
984 if (choose_comp
->flags
& ICMF_CHOOSE_DATARATE
)
988 if (choose_comp
->flags
& ICMF_CHOOSE_KEYFRAME
)
999 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1001 struct codec_info
*ic
;
1003 if (HIWORD(wparam
) != BN_CLICKED
)
1006 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
1008 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1011 if (LOWORD(wparam
) == IDC_CONFIGURE
)
1012 ICConfigure(ic
->hic
, hdlg
);
1014 ICAbout(ic
->hic
, hdlg
);
1022 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1024 struct codec_info
*ic
;
1026 if (HIWORD(wparam
) != BN_CLICKED
)
1029 cur_sel
= SendMessageW(list
, CB_GETCURSEL
, 0, 0);
1030 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, cur_sel
, 0);
1033 struct choose_compressor
*choose_comp
= (struct choose_compressor
*)GetWindowLongPtrW(hdlg
, DWLP_USER
);
1035 choose_comp
->cv
.hic
= ic
->hic
;
1036 choose_comp
->cv
.fccType
= ic
->icinfo
.fccType
;
1037 choose_comp
->cv
.fccHandler
= ic
->icinfo
.fccHandler
;
1038 /* FIXME: fill everything else */
1040 /* prevent closing the codec handle below */
1047 HWND list
= GetDlgItem(hdlg
, IDC_COMP_LIST
);
1050 if (HIWORD(wparam
) != BN_CLICKED
)
1055 struct codec_info
*ic
;
1057 ic
= (struct codec_info
*)SendMessageW(list
, CB_GETITEMDATA
, idx
++, 0);
1059 if (!ic
|| (LONG_PTR
)ic
== CB_ERR
) break;
1061 if (ic
->hic
) ICClose(ic
->hic
);
1065 EndDialog(hdlg
, LOWORD(wparam
) == IDOK
);
1081 /***********************************************************************
1082 * ICCompressorChoose [MSVFW32.@]
1084 BOOL VFWAPI
ICCompressorChoose(HWND hwnd
, UINT uiFlags
, LPVOID pvIn
,
1085 LPVOID lpData
, PCOMPVARS pc
, LPSTR lpszTitle
)
1087 struct choose_compressor choose_comp
;
1090 TRACE("(%p,%08x,%p,%p,%p,%s)\n", hwnd
, uiFlags
, pvIn
, lpData
, pc
, lpszTitle
);
1092 if (!pc
|| pc
->cbSize
!= sizeof(COMPVARS
))
1095 if (!(pc
->dwFlags
& ICMF_COMPVARS_VALID
))
1098 pc
->fccType
= pc
->fccHandler
= 0;
1102 pc
->lpBitsOut
= pc
->lpBitsPrev
= pc
->lpState
= NULL
;
1103 pc
->lQ
= ICQUALITY_DEFAULT
;
1105 pc
->lDataRate
= 300; /* kB */
1109 if (pc
->fccType
== 0)
1110 pc
->fccType
= ICTYPE_VIDEO
;
1112 choose_comp
.cv
= *pc
;
1113 choose_comp
.flags
= uiFlags
;
1114 choose_comp
.title
= lpszTitle
;
1116 ret
= DialogBoxParamW(MSVFW32_hModule
, MAKEINTRESOURCEW(ICM_CHOOSE_COMPRESSOR
), hwnd
,
1117 icm_choose_compressor_dlgproc
, (LPARAM
)&choose_comp
);
1121 *pc
= choose_comp
.cv
;
1122 pc
->dwFlags
|= ICMF_COMPVARS_VALID
;
1129 /***********************************************************************
1130 * ICCompressorFree [MSVFW32.@]
1132 void VFWAPI
ICCompressorFree(PCOMPVARS pc
)
1134 TRACE("(%p)\n", pc
);
1136 if (pc
&& pc
->cbSize
== sizeof(COMPVARS
))
1145 free(pc
->lpBitsOut
);
1146 pc
->lpBitsOut
= NULL
;
1147 free(pc
->lpBitsPrev
);
1148 pc
->lpBitsPrev
= NULL
;
1155 /***********************************************************************
1156 * ICSendMessage [MSVFW32.@]
1158 LRESULT VFWAPI
ICSendMessage(HIC hic
, UINT msg
, DWORD_PTR lParam1
, DWORD_PTR lParam2
)
1160 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1162 if (!whic
) return ICERR_BADHANDLE
;
1163 return MSVIDEO_SendMessage(whic
, msg
, lParam1
, lParam2
);
1166 /***********************************************************************
1167 * ICDrawBegin [MSVFW32.@]
1169 DWORD VFWAPIV
ICDrawBegin(
1171 DWORD dwFlags
, /* [in] flags */
1172 HPALETTE hpal
, /* [in] palette to draw with */
1173 HWND hwnd
, /* [in] window to draw to */
1174 HDC hdc
, /* [in] HDC to draw to */
1175 INT xDst
, /* [in] destination rectangle */
1176 INT yDst
, /* [in] */
1177 INT dxDst
, /* [in] */
1178 INT dyDst
, /* [in] */
1179 LPBITMAPINFOHEADER lpbi
, /* [in] format of frame to draw */
1180 INT xSrc
, /* [in] source rectangle */
1181 INT ySrc
, /* [in] */
1182 INT dxSrc
, /* [in] */
1183 INT dySrc
, /* [in] */
1184 DWORD dwRate
, /* [in] frames/second = (dwRate/dwScale) */
1185 DWORD dwScale
) /* [in] */
1190 TRACE("(%p,%ld,%p,%p,%p,%u,%u,%u,%u,%p,%u,%u,%u,%u,%ld,%ld)\n",
1191 hic
, dwFlags
, hpal
, hwnd
, hdc
, xDst
, yDst
, dxDst
, dyDst
,
1192 lpbi
, xSrc
, ySrc
, dxSrc
, dySrc
, dwRate
, dwScale
);
1194 icdb
.dwFlags
= dwFlags
;
1207 icdb
.dwRate
= dwRate
;
1208 icdb
.dwScale
= dwScale
;
1209 return ICSendMessage(hic
,ICM_DRAW_BEGIN
,(DWORD_PTR
)&icdb
,sizeof(icdb
));
1212 /***********************************************************************
1213 * ICDraw [MSVFW32.@]
1215 DWORD VFWAPIV
ICDraw(HIC hic
, DWORD dwFlags
, LPVOID lpFormat
, LPVOID lpData
, DWORD cbData
, LONG lTime
) {
1218 TRACE("(%p,%ld,%p,%p,%ld,%ld)\n",hic
,dwFlags
,lpFormat
,lpData
,cbData
,lTime
);
1220 icd
.dwFlags
= dwFlags
;
1221 icd
.lpFormat
= lpFormat
;
1222 icd
.lpData
= lpData
;
1223 icd
.cbData
= cbData
;
1226 return ICSendMessage(hic
,ICM_DRAW
,(DWORD_PTR
)&icd
,sizeof(icd
));
1229 /***********************************************************************
1230 * ICClose [MSVFW32.@]
1232 LRESULT WINAPI
ICClose(HIC hic
)
1234 WINE_HIC
* whic
= MSVIDEO_GetHicPtr(hic
);
1237 TRACE("(%p)\n",hic
);
1239 if (!whic
) return ICERR_BADHANDLE
;
1241 if (whic
->driverproc
)
1243 MSVIDEO_SendMessage(whic
, DRV_CLOSE
, 0, 0);
1244 MSVIDEO_SendMessage(whic
, DRV_DISABLE
, 0, 0);
1245 MSVIDEO_SendMessage(whic
, DRV_FREE
, 0, 0);
1249 CloseDriver(whic
->hdrv
, 0, 0);
1252 /* remove whic from list */
1253 for (p
= &MSVIDEO_FirstHic
; *p
!= NULL
; p
= &((*p
)->next
))
1268 /***********************************************************************
1269 * ICImageCompress [MSVFW32.@]
1271 HANDLE VFWAPI
ICImageCompress(
1272 HIC hic
, UINT uiFlags
,
1273 LPBITMAPINFO lpbiIn
, LPVOID lpBits
,
1274 LPBITMAPINFO lpbiOut
, LONG lQuality
,
1277 FIXME("(%p,%08x,%p,%p,%p,%ld,%p)\n",
1278 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
, lQuality
, plSize
);
1283 /***********************************************************************
1284 * ICImageDecompress [MSVFW32.@]
1287 HANDLE VFWAPI
ICImageDecompress(
1288 HIC hic
, UINT uiFlags
, LPBITMAPINFO lpbiIn
,
1289 LPVOID lpBits
, LPBITMAPINFO lpbiOut
)
1291 HGLOBAL hMem
= NULL
;
1293 BOOL bReleaseIC
= FALSE
;
1296 BOOL bSucceeded
= FALSE
;
1297 BOOL bInDecompress
= FALSE
;
1300 TRACE("(%p,%08x,%p,%p,%p)\n",
1301 hic
, uiFlags
, lpbiIn
, lpBits
, lpbiOut
);
1305 hic
= ICDecompressOpen( ICTYPE_VIDEO
, 0, &lpbiIn
->bmiHeader
, (lpbiOut
!= NULL
) ? &lpbiOut
->bmiHeader
: NULL
);
1308 WARN("no handler\n" );
1315 FIXME( "unknown flag %08x\n", uiFlags
);
1318 if ( lpbiIn
== NULL
|| lpBits
== NULL
)
1320 WARN("invalid argument\n");
1324 if ( lpbiOut
!= NULL
)
1326 if ( lpbiOut
->bmiHeader
.biSize
!= sizeof(BITMAPINFOHEADER
) )
1328 cbHdr
= sizeof(BITMAPINFOHEADER
);
1329 if ( lpbiOut
->bmiHeader
.biCompression
== 3 )
1330 cbHdr
+= sizeof(DWORD
)*3;
1332 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 )
1334 if ( lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1335 cbHdr
+= sizeof(RGBQUAD
) * (1<<lpbiOut
->bmiHeader
.biBitCount
);
1337 cbHdr
+= sizeof(RGBQUAD
) * lpbiOut
->bmiHeader
.biClrUsed
;
1342 TRACE( "get format\n" );
1344 cbHdr
= ICDecompressGetFormatSize(hic
,lpbiIn
);
1345 if ( cbHdr
< sizeof(BITMAPINFOHEADER
) )
1347 if (!(pHdr
= calloc(1, cbHdr
+ sizeof(RGBQUAD
) * 256)))
1349 if ( ICDecompressGetFormat( hic
, lpbiIn
, pHdr
) != ICERR_OK
)
1351 lpbiOut
= (BITMAPINFO
*)pHdr
;
1352 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1353 ICDecompressGetPalette( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
&&
1354 lpbiIn
->bmiHeader
.biBitCount
== lpbiOut
->bmiHeader
.biBitCount
)
1356 if ( lpbiIn
->bmiHeader
.biClrUsed
== 0 )
1357 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*(1<<lpbiOut
->bmiHeader
.biBitCount
) );
1359 memcpy( lpbiOut
->bmiColors
, lpbiIn
->bmiColors
, sizeof(RGBQUAD
)*lpbiIn
->bmiHeader
.biClrUsed
);
1361 if ( lpbiOut
->bmiHeader
.biBitCount
<= 8 &&
1362 lpbiOut
->bmiHeader
.biClrUsed
== 0 )
1363 lpbiOut
->bmiHeader
.biClrUsed
= 1<<lpbiOut
->bmiHeader
.biBitCount
;
1365 lpbiOut
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1366 cbHdr
= sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
)*lpbiOut
->bmiHeader
.biClrUsed
;
1369 biSizeImage
= lpbiOut
->bmiHeader
.biSizeImage
;
1370 if ( biSizeImage
== 0 )
1371 biSizeImage
= get_size_image(lpbiOut
->bmiHeader
.biWidth
, lpbiOut
->bmiHeader
.biHeight
, lpbiOut
->bmiHeader
.biBitCount
);
1373 TRACE( "call ICDecompressBegin\n" );
1375 if ( ICDecompressBegin( hic
, lpbiIn
, lpbiOut
) != ICERR_OK
)
1377 bInDecompress
= TRUE
;
1379 TRACE( "cbHdr %ld, biSizeImage %ld\n", cbHdr
, biSizeImage
);
1381 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_ZEROINIT
, cbHdr
+ biSizeImage
);
1384 WARN( "out of memory\n" );
1387 pMem
= GlobalLock( hMem
);
1390 memcpy( pMem
, lpbiOut
, cbHdr
);
1392 TRACE( "call ICDecompress\n" );
1393 if ( ICDecompress( hic
, 0, &lpbiIn
->bmiHeader
, lpBits
, &lpbiOut
->bmiHeader
, pMem
+cbHdr
) != ICERR_OK
)
1398 if ( bInDecompress
)
1399 ICDecompressEnd( hic
);
1404 GlobalUnlock( hMem
);
1405 if ( !bSucceeded
&& hMem
!= NULL
)
1407 GlobalFree(hMem
); hMem
= NULL
;
1413 /***********************************************************************
1414 * ICSeqCompressFrame [MSVFW32.@]
1416 LPVOID VFWAPI
ICSeqCompressFrame(PCOMPVARS pc
, UINT uiFlags
, LPVOID lpBits
, BOOL
*pfKey
, LONG
*plSize
)
1418 ICCOMPRESS
* icComp
= pc
->lpState
;
1420 TRACE("(%p, 0x%08x, %p, %p, %p)\n", pc
, uiFlags
, lpBits
, pfKey
, plSize
);
1422 if (pc
->cbState
!= sizeof(ICCOMPRESS
))
1424 ERR("Invalid cbState %li\n", pc
->cbState
);
1428 if (!pc
->lKeyCount
++)
1429 icComp
->dwFlags
= ICCOMPRESS_KEYFRAME
;
1432 if (pc
->lKey
&& pc
->lKeyCount
== (pc
->lKey
- 1))
1433 /* No key frames if pc->lKey == 0 */
1435 icComp
->dwFlags
= 0;
1438 icComp
->lpInput
= lpBits
;
1439 icComp
->lFrameNum
= pc
->lFrame
++;
1440 icComp
->lpOutput
= pc
->lpBitsOut
;
1441 icComp
->lpPrev
= pc
->lpBitsPrev
;
1442 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS
, (DWORD_PTR
)icComp
, sizeof(*icComp
));
1444 if (ret
== ICERR_OK
)
1446 LPVOID oldprev
, oldout
;
1448 if (icComp
->dwFlags
& AVIIF_KEYFRAME
)
1452 TRACE("Key frame\n");
1457 *plSize
= icComp
->lpbiOutput
->biSizeImage
;
1459 /* We shift Prev and Out, so we don't have to allocate and release memory */
1460 oldprev
= pc
->lpBitsPrev
;
1461 oldout
= pc
->lpBitsOut
;
1462 pc
->lpBitsPrev
= oldout
;
1463 pc
->lpBitsOut
= oldprev
;
1465 TRACE("returning: %p, compressed frame size %lu\n", icComp
->lpOutput
, *plSize
);
1466 return icComp
->lpOutput
;
1471 static void clear_compvars(PCOMPVARS pc
)
1474 free(pc
->lpBitsPrev
);
1475 free(pc
->lpBitsOut
);
1477 pc
->lpbiIn
= pc
->lpBitsPrev
= pc
->lpBitsOut
= pc
->lpState
= NULL
;
1478 if (pc
->dwFlags
& 0x80000000)
1482 pc
->dwFlags
&= ~0x80000000;
1486 /***********************************************************************
1487 * ICSeqCompressFrameEnd [MSVFW32.@]
1489 void VFWAPI
ICSeqCompressFrameEnd(PCOMPVARS pc
)
1491 TRACE("(%p)\n", pc
);
1492 ICSendMessage(pc
->hic
, ICM_COMPRESS_END
, 0, 0);
1496 static BITMAPINFO
*copy_bitmapinfo(const BITMAPINFO
*src
)
1502 if (src
->bmiHeader
.biClrUsed
)
1503 num_colors
= min(src
->bmiHeader
.biClrUsed
, 256);
1505 num_colors
= src
->bmiHeader
.biBitCount
> 8 ? 0 : 1 << src
->bmiHeader
.biBitCount
;
1507 size
= FIELD_OFFSET(BITMAPINFO
, bmiColors
[num_colors
]);
1508 if (src
->bmiHeader
.biCompression
== BI_BITFIELDS
)
1509 size
+= 3 * sizeof(DWORD
);
1511 if (!(dst
= malloc(size
)))
1514 memcpy(dst
, src
, size
);
1518 /***********************************************************************
1519 * ICSeqCompressFrameStart [MSVFW32.@]
1521 BOOL VFWAPI
ICSeqCompressFrameStart(PCOMPVARS pc
, LPBITMAPINFO lpbiIn
)
1523 /* I'm ignoring bmiColors as I don't know what to do with it,
1524 * it doesn't appear to be used though
1529 if (!(pc
->lpbiIn
= copy_bitmapinfo(lpbiIn
)))
1532 if (!(pc
->lpState
= malloc(sizeof(ICCOMPRESS
) + sizeof(*icComp
->lpckid
) + sizeof(*icComp
->lpdwFlags
))))
1535 pc
->cbState
= sizeof(ICCOMPRESS
);
1539 /* Ask compressor for needed header size */
1540 int size
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1541 (DWORD_PTR
)pc
->lpbiIn
, 0);
1545 if (!(pc
->lpbiOut
= calloc(1, size
)))
1547 /* Flag to show that we allocated lpbiOut for proper cleanup */
1548 pc
->dwFlags
|= 0x80000000;
1550 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_GET_FORMAT
,
1551 (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1552 if (ret
!= ICERR_OK
)
1554 ERR("Could not get output format from compressor\n");
1557 if (!pc
->lpbiOut
->bmiHeader
.biSizeImage
)
1559 /* If we can't know the output frame size for sure at least allocate
1560 * the same size of the input frame and also at least 8Kb to be sure
1561 * that poor compressors will have enough memory to work if the input
1562 * frame is too small.
1564 pc
->lpbiOut
->bmiHeader
.biSizeImage
= max(8192, pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1565 ERR("Bad codec! Invalid output frame size, guessing from input\n");
1569 TRACE("Input: %lux%lu, fcc %s, bpp %u, size %lu\n",
1570 pc
->lpbiIn
->bmiHeader
.biWidth
, pc
->lpbiIn
->bmiHeader
.biHeight
,
1571 debugstr_fourcc(pc
->lpbiIn
->bmiHeader
.biCompression
),
1572 pc
->lpbiIn
->bmiHeader
.biBitCount
,
1573 pc
->lpbiIn
->bmiHeader
.biSizeImage
);
1574 TRACE("Output: %lux%lu, fcc %s, bpp %u, size %lu\n",
1575 pc
->lpbiOut
->bmiHeader
.biWidth
, pc
->lpbiOut
->bmiHeader
.biHeight
,
1576 debugstr_fourcc(pc
->lpbiOut
->bmiHeader
.biCompression
),
1577 pc
->lpbiOut
->bmiHeader
.biBitCount
,
1578 pc
->lpbiOut
->bmiHeader
.biSizeImage
);
1580 /* Buffer for compressed frame data */
1581 if (!(pc
->lpBitsOut
= malloc(pc
->lpbiOut
->bmiHeader
.biSizeImage
)))
1584 /* Buffer for previous compressed frame data */
1585 if (!(pc
->lpBitsPrev
= malloc(pc
->lpbiOut
->bmiHeader
.biSizeImage
)))
1595 "\tkey/data/quality: %li/%li/%li\n",
1596 pc
->cbSize
, pc
->dwFlags
, pc
->hic
, debugstr_fourcc(pc
->fccType
),
1597 debugstr_fourcc(pc
->fccHandler
), pc
->lpbiIn
, pc
->lpbiOut
, pc
->lKey
,
1598 pc
->lDataRate
, pc
->lQ
);
1600 ret
= ICSendMessage(pc
->hic
, ICM_COMPRESS_BEGIN
, (DWORD_PTR
)pc
->lpbiIn
, (DWORD_PTR
)pc
->lpbiOut
);
1601 if (ret
== ICERR_OK
)
1603 icComp
= pc
->lpState
;
1604 /* Initialise some variables */
1605 pc
->lFrame
= 0; pc
->lKeyCount
= 0;
1607 icComp
->lpbiOutput
= &pc
->lpbiOut
->bmiHeader
;
1608 icComp
->lpbiInput
= &pc
->lpbiIn
->bmiHeader
;
1609 icComp
->lpckid
= (DWORD
*)(icComp
+ 1);
1610 *icComp
->lpckid
= 0;
1611 icComp
->lpdwFlags
= (DWORD
*)((char *)(icComp
+ 1) + sizeof(*icComp
->lpckid
));
1612 *icComp
->lpdwFlags
= 0;
1613 icComp
->dwFrameSize
= 0;
1614 icComp
->dwQuality
= pc
->lQ
;
1615 icComp
->lpbiPrev
= &pc
->lpbiIn
->bmiHeader
;
1623 /***********************************************************************
1624 * GetFileNamePreview [MSVFW32.@]
1626 static BOOL
GetFileNamePreview(LPVOID lpofn
,BOOL bSave
,BOOL bUnicode
)
1628 CHAR szFunctionName
[20];
1629 BOOL (*fnGetFileName
)(LPVOID
);
1633 FIXME("(%p,%d,%d), semi-stub!\n",lpofn
,bSave
,bUnicode
);
1635 lstrcpyA(szFunctionName
, (bSave
? "GetSaveFileName" : "GetOpenFileName"));
1636 lstrcatA(szFunctionName
, (bUnicode
? "W" : "A"));
1638 hComdlg32
= LoadLibraryA("COMDLG32.DLL");
1639 if (hComdlg32
== NULL
)
1642 fnGetFileName
= (LPVOID
)GetProcAddress(hComdlg32
, szFunctionName
);
1643 if (fnGetFileName
== NULL
)
1645 FreeLibrary(hComdlg32
);
1649 /* FIXME: need to add OFN_ENABLEHOOK and our own handler */
1650 ret
= fnGetFileName(lpofn
);
1652 FreeLibrary(hComdlg32
);
1656 /***********************************************************************
1657 * GetOpenFileNamePreviewA [MSVFW32.@]
1659 BOOL WINAPI
GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1661 FIXME("(%p), semi-stub!\n", lpofn
);
1663 return GetFileNamePreview(lpofn
, FALSE
, FALSE
);
1666 /***********************************************************************
1667 * GetOpenFileNamePreviewW [MSVFW32.@]
1669 BOOL WINAPI
GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1671 FIXME("(%p), semi-stub!\n", lpofn
);
1673 return GetFileNamePreview(lpofn
, FALSE
, TRUE
);
1676 /***********************************************************************
1677 * GetSaveFileNamePreviewA [MSVFW32.@]
1679 BOOL WINAPI
GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn
)
1681 FIXME("(%p), semi-stub!\n", lpofn
);
1683 return GetFileNamePreview(lpofn
, TRUE
, FALSE
);
1686 /***********************************************************************
1687 * GetSaveFileNamePreviewW [MSVFW32.@]
1689 BOOL WINAPI
GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn
)
1691 FIXME("(%p), semi-stub!\n", lpofn
);
1693 return GetFileNamePreview(lpofn
, TRUE
, TRUE
);