1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
5 * Copyright 1998, 1999 Eric Kohl
6 * Copyright 1999 Eric Pouech
7 * Copyright 2005 Dimitrie O. Paun
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Mar. 15, 2005, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - check for the 'rec ' list in some AVI files
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(animate
);
53 HIC (WINAPI
*fnICOpen
)(DWORD
, DWORD
, UINT
);
54 LRESULT (WINAPI
*fnICClose
)(HIC
);
55 LRESULT (WINAPI
*fnICSendMessage
)(HIC
, UINT
, DWORD_PTR
, DWORD_PTR
);
56 DWORD (WINAPIV
*fnICDecompress
)(HIC
,DWORD
,LPBITMAPINFOHEADER
,LPVOID
,LPBITMAPINFOHEADER
,LPVOID
);
61 /* reference to input stream (file or resource) */
63 HMMIO hMMio
; /* handle to mmio stream */
67 /* information on the loaded AVI file */
70 LPBITMAPINFOHEADER inbih
;
72 /* data for the decompressor */
74 LPBITMAPINFOHEADER outbih
;
77 /* data for the background mechanism */
83 /* data for playing the file */
89 COLORREF transparentColor
;
94 #define ANIMATE_COLOR_NONE 0xffffffff
96 static void ANIMATE_Notify(const ANIMATE_INFO
*infoPtr
, UINT notif
)
98 SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
,
99 MAKEWPARAM(GetDlgCtrlID(infoPtr
->hwndSelf
), notif
),
100 (LPARAM
)infoPtr
->hwndSelf
);
103 static BOOL
ANIMATE_LoadResW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInst
, LPCWSTR lpName
)
105 static const WCHAR aviW
[] = { 'A', 'V', 'I', 0 };
110 hrsrc
= FindResourceW(hInst
, lpName
, aviW
);
114 infoPtr
->hRes
= LoadResource(hInst
, hrsrc
);
118 lpAvi
= LockResource(infoPtr
->hRes
);
122 memset(&mminfo
, 0, sizeof(mminfo
));
123 mminfo
.fccIOProc
= FOURCC_MEM
;
124 mminfo
.pchBuffer
= (LPSTR
)lpAvi
;
125 mminfo
.cchBuffer
= SizeofResource(hInst
, hrsrc
);
126 infoPtr
->hMMio
= mmioOpenW(NULL
, &mminfo
, MMIO_READ
);
129 FreeResource(infoPtr
->hRes
);
137 static BOOL
ANIMATE_LoadFileW(ANIMATE_INFO
*infoPtr
, LPWSTR lpName
)
139 infoPtr
->hMMio
= mmioOpenW(lpName
, 0, MMIO_ALLOCBUF
| MMIO_READ
| MMIO_DENYWRITE
);
141 if(!infoPtr
->hMMio
) return FALSE
;
146 static BOOL
ANIMATE_DoStop(ANIMATE_INFO
*infoPtr
)
148 EnterCriticalSection(&infoPtr
->cs
);
150 /* should stop playing */
151 if (infoPtr
->hThread
)
153 HANDLE handle
= infoPtr
->hThread
;
155 TRACE("stopping animation thread\n");
156 infoPtr
->hThread
= 0;
157 SetEvent( infoPtr
->hStopEvent
);
159 if (infoPtr
->threadId
!= GetCurrentThreadId())
161 LeaveCriticalSection(&infoPtr
->cs
); /* leave it a chance to run */
162 WaitForSingleObject( handle
, INFINITE
);
163 TRACE("animation thread stopped\n");
164 EnterCriticalSection(&infoPtr
->cs
);
167 CloseHandle( handle
);
168 CloseHandle( infoPtr
->hStopEvent
);
169 infoPtr
->hStopEvent
= 0;
171 if (infoPtr
->uTimer
) {
172 KillTimer(infoPtr
->hwndSelf
, infoPtr
->uTimer
);
176 LeaveCriticalSection(&infoPtr
->cs
);
178 ANIMATE_Notify(infoPtr
, ACN_STOP
);
184 static void ANIMATE_Free(ANIMATE_INFO
*infoPtr
)
186 if (infoPtr
->hMMio
) {
187 ANIMATE_DoStop(infoPtr
);
188 mmioClose(infoPtr
->hMMio
, 0);
190 FreeResource(infoPtr
->hRes
);
193 Free (infoPtr
->lpIndex
);
194 infoPtr
->lpIndex
= NULL
;
196 fnIC
.fnICClose(infoPtr
->hic
);
199 Free (infoPtr
->inbih
);
200 infoPtr
->inbih
= NULL
;
201 Free (infoPtr
->outbih
);
202 infoPtr
->outbih
= NULL
;
203 Free (infoPtr
->indata
);
204 infoPtr
->indata
= NULL
;
205 Free (infoPtr
->outdata
);
206 infoPtr
->outdata
= NULL
;
207 if( infoPtr
->hbmPrevFrame
)
209 DeleteObject(infoPtr
->hbmPrevFrame
);
210 infoPtr
->hbmPrevFrame
= 0;
213 memset(&infoPtr
->mah
, 0, sizeof(infoPtr
->mah
));
214 memset(&infoPtr
->ash
, 0, sizeof(infoPtr
->ash
));
215 infoPtr
->nFromFrame
= infoPtr
->nToFrame
= infoPtr
->nLoop
= infoPtr
->currFrame
= 0;
217 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
220 static void ANIMATE_TransparentBlt(ANIMATE_INFO
const *infoPtr
, HDC hdcDest
, HDC hdcSource
)
226 /* create a transparency mask */
227 hdcMask
= CreateCompatibleDC(hdcDest
);
228 hbmMask
= CreateBitmap(infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, 1,1,NULL
);
229 hbmOld
= SelectObject(hdcMask
, hbmMask
);
231 SetBkColor(hdcSource
,infoPtr
->transparentColor
);
232 BitBlt(hdcMask
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCCOPY
);
234 /* mask the source bitmap */
235 SetBkColor(hdcSource
, RGB(0,0,0));
236 SetTextColor(hdcSource
, RGB(255,255,255));
237 BitBlt(hdcSource
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
239 /* mask the destination bitmap */
240 SetBkColor(hdcDest
, RGB(255,255,255));
241 SetTextColor(hdcDest
, RGB(0,0,0));
242 BitBlt(hdcDest
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
244 /* combine source and destination */
245 BitBlt(hdcDest
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCPAINT
);
247 SelectObject(hdcMask
, hbmOld
);
248 DeleteObject(hbmMask
);
252 static BOOL
ANIMATE_PaintFrame(ANIMATE_INFO
* infoPtr
, HDC hDC
)
254 void const *pBitmapData
;
255 BITMAPINFO
const *pBitmapInfo
;
263 if (!hDC
|| !infoPtr
->inbih
)
268 pBitmapData
= infoPtr
->outdata
;
269 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->outbih
;
271 nWidth
= infoPtr
->outbih
->biWidth
;
272 nHeight
= infoPtr
->outbih
->biHeight
;
276 pBitmapData
= infoPtr
->indata
;
277 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->inbih
;
279 nWidth
= infoPtr
->inbih
->biWidth
;
280 nHeight
= infoPtr
->inbih
->biHeight
;
283 if(!infoPtr
->hbmPrevFrame
)
285 infoPtr
->hbmPrevFrame
=CreateCompatibleBitmap(hDC
, nWidth
,nHeight
);
288 hdcMem
= CreateCompatibleDC(hDC
);
289 hbmOld
= SelectObject(hdcMem
, infoPtr
->hbmPrevFrame
);
291 SetDIBits(hdcMem
, infoPtr
->hbmPrevFrame
, 0, nHeight
, pBitmapData
, pBitmapInfo
, DIB_RGB_COLORS
);
294 * we need to get the transparent color even without ACS_TRANSPARENT,
295 * because the style can be changed later on and the color should always
296 * be obtained in the first frame
298 if(infoPtr
->transparentColor
== ANIMATE_COLOR_NONE
)
300 infoPtr
->transparentColor
= GetPixel(hdcMem
,0,0);
303 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
305 HDC hdcFinal
= CreateCompatibleDC(hDC
);
306 HBITMAP hbmFinal
= CreateCompatibleBitmap(hDC
,nWidth
, nHeight
);
307 HBITMAP hbmOld2
= SelectObject(hdcFinal
, hbmFinal
);
313 rect
.bottom
= nHeight
;
315 if(!infoPtr
->hbrushBG
)
316 infoPtr
->hbrushBG
= GetCurrentObject(hDC
, OBJ_BRUSH
);
318 FillRect(hdcFinal
, &rect
, infoPtr
->hbrushBG
);
319 ANIMATE_TransparentBlt(infoPtr
, hdcFinal
, hdcMem
);
321 SelectObject(hdcFinal
, hbmOld2
);
322 SelectObject(hdcMem
, hbmFinal
);
324 DeleteObject(infoPtr
->hbmPrevFrame
);
325 infoPtr
->hbmPrevFrame
= hbmFinal
;
328 if (infoPtr
->dwStyle
& ACS_CENTER
)
332 GetWindowRect(infoPtr
->hwndSelf
, &rect
);
333 nOffsetX
= ((rect
.right
- rect
.left
) - nWidth
)/2;
334 nOffsetY
= ((rect
.bottom
- rect
.top
) - nHeight
)/2;
336 BitBlt(hDC
, nOffsetX
, nOffsetY
, nWidth
, nHeight
, hdcMem
, 0, 0, SRCCOPY
);
338 SelectObject(hdcMem
, hbmOld
);
343 static BOOL
ANIMATE_DrawFrame(ANIMATE_INFO
*infoPtr
)
347 TRACE("Drawing frame %d (loop %d)\n", infoPtr
->currFrame
, infoPtr
->nLoop
);
349 mmioSeek(infoPtr
->hMMio
, infoPtr
->lpIndex
[infoPtr
->currFrame
], SEEK_SET
);
350 mmioRead(infoPtr
->hMMio
, infoPtr
->indata
, infoPtr
->ash
.dwSuggestedBufferSize
);
353 fnIC
.fnICDecompress(infoPtr
->hic
, 0, infoPtr
->inbih
, infoPtr
->indata
,
354 infoPtr
->outbih
, infoPtr
->outdata
) != ICERR_OK
) {
355 WARN("Decompression error\n");
359 if ((hDC
= GetDC(infoPtr
->hwndSelf
)) != 0) {
360 ANIMATE_PaintFrame(infoPtr
, hDC
);
361 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
364 if (infoPtr
->currFrame
++ >= infoPtr
->nToFrame
) {
365 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
366 if (infoPtr
->nLoop
!= -1) {
367 if (--infoPtr
->nLoop
== 0) {
368 ANIMATE_DoStop(infoPtr
);
376 static LRESULT
ANIMATE_Timer(ANIMATE_INFO
*infoPtr
)
378 /* FIXME: we should pass the hDC instead of 0 to WM_CTLCOLORSTATIC */
379 if (infoPtr
->dwStyle
& ACS_TRANSPARENT
)
380 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
382 0, (LPARAM
)infoPtr
->hwndSelf
);
383 EnterCriticalSection(&infoPtr
->cs
);
384 ANIMATE_DrawFrame(infoPtr
);
385 LeaveCriticalSection(&infoPtr
->cs
);
390 static DWORD CALLBACK
ANIMATE_AnimationThread(LPVOID ptr_
)
392 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)ptr_
;
396 RENAME_CURRENT_THREAD("comctl32 animation thread");
400 EnterCriticalSection(&infoPtr
->cs
);
401 ANIMATE_DrawFrame(infoPtr
);
402 timeout
= infoPtr
->mah
.dwMicroSecPerFrame
;
403 event
= infoPtr
->hStopEvent
;
404 LeaveCriticalSection(&infoPtr
->cs
);
406 /* time is in microseconds, we should convert it to milliseconds */
407 if ((event
== 0) || WaitForSingleObject( event
, (timeout
+500)/1000) == WAIT_OBJECT_0
)
413 static LRESULT
ANIMATE_Play(ANIMATE_INFO
*infoPtr
, UINT cRepeat
, WORD wFrom
, WORD wTo
)
419 if (infoPtr
->hThread
|| infoPtr
->uTimer
) {
420 TRACE("Already playing\n");
424 infoPtr
->nFromFrame
= wFrom
;
425 infoPtr
->nToFrame
= wTo
;
426 infoPtr
->nLoop
= cRepeat
;
428 if (infoPtr
->nToFrame
== 0xFFFF)
429 infoPtr
->nToFrame
= infoPtr
->mah
.dwTotalFrames
- 1;
431 TRACE("(repeat=%d from=%d to=%d);\n",
432 infoPtr
->nLoop
, infoPtr
->nFromFrame
, infoPtr
->nToFrame
);
434 if (infoPtr
->nFromFrame
>= infoPtr
->nToFrame
||
435 infoPtr
->nToFrame
>= infoPtr
->mah
.dwTotalFrames
)
438 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
440 if (infoPtr
->dwStyle
& ACS_TIMER
)
442 TRACE("Using a timer\n");
443 /* create a timer to display AVI */
444 infoPtr
->uTimer
= SetTimer(infoPtr
->hwndSelf
, 1,
445 infoPtr
->mah
.dwMicroSecPerFrame
/ 1000, NULL
);
449 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
450 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
451 WM_CTLCOLORSTATIC
, 0,
452 (LPARAM
)infoPtr
->hwndSelf
);
454 TRACE("Using an animation thread\n");
455 infoPtr
->hStopEvent
= CreateEventW( NULL
, TRUE
, FALSE
, NULL
);
456 infoPtr
->hThread
= CreateThread(0, 0, ANIMATE_AnimationThread
,
457 (LPVOID
)infoPtr
, 0, &infoPtr
->threadId
);
458 if(!infoPtr
->hThread
) return FALSE
;
462 ANIMATE_Notify(infoPtr
, ACN_START
);
468 static BOOL
ANIMATE_GetAviInfo(ANIMATE_INFO
*infoPtr
)
477 if (mmioDescend(infoPtr
->hMMio
, &ckMainRIFF
, NULL
, 0) != 0) {
478 WARN("Can't find 'RIFF' chunk\n");
482 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) ||
483 (ckMainRIFF
.fccType
!= mmioFOURCC('A', 'V', 'I', ' '))) {
484 WARN("Can't find 'AVI ' chunk\n");
488 mmckHead
.fccType
= mmioFOURCC('h', 'd', 'r', 'l');
489 if (mmioDescend(infoPtr
->hMMio
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
490 WARN("Can't find 'hdrl' list\n");
494 mmckInfo
.ckid
= mmioFOURCC('a', 'v', 'i', 'h');
495 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
496 WARN("Can't find 'avih' chunk\n");
500 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->mah
, sizeof(infoPtr
->mah
));
502 TRACE("mah.dwMicroSecPerFrame=%d\n", infoPtr
->mah
.dwMicroSecPerFrame
);
503 TRACE("mah.dwMaxBytesPerSec=%d\n", infoPtr
->mah
.dwMaxBytesPerSec
);
504 TRACE("mah.dwPaddingGranularity=%d\n", infoPtr
->mah
.dwPaddingGranularity
);
505 TRACE("mah.dwFlags=%d\n", infoPtr
->mah
.dwFlags
);
506 TRACE("mah.dwTotalFrames=%d\n", infoPtr
->mah
.dwTotalFrames
);
507 TRACE("mah.dwInitialFrames=%d\n", infoPtr
->mah
.dwInitialFrames
);
508 TRACE("mah.dwStreams=%d\n", infoPtr
->mah
.dwStreams
);
509 TRACE("mah.dwSuggestedBufferSize=%d\n", infoPtr
->mah
.dwSuggestedBufferSize
);
510 TRACE("mah.dwWidth=%d\n", infoPtr
->mah
.dwWidth
);
511 TRACE("mah.dwHeight=%d\n", infoPtr
->mah
.dwHeight
);
513 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
515 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
516 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0) {
517 WARN("Can't find 'strl' list\n");
521 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'h');
522 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
523 WARN("Can't find 'strh' chunk\n");
527 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->ash
, sizeof(infoPtr
->ash
));
529 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccType
)),
530 HIBYTE(LOWORD(infoPtr
->ash
.fccType
)),
531 LOBYTE(HIWORD(infoPtr
->ash
.fccType
)),
532 HIBYTE(HIWORD(infoPtr
->ash
.fccType
)));
533 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
534 HIBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
535 LOBYTE(HIWORD(infoPtr
->ash
.fccHandler
)),
536 HIBYTE(HIWORD(infoPtr
->ash
.fccHandler
)));
537 TRACE("ash.dwFlags=%d\n", infoPtr
->ash
.dwFlags
);
538 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
539 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
540 TRACE("ash.dwInitialFrames=%d\n", infoPtr
->ash
.dwInitialFrames
);
541 TRACE("ash.dwScale=%d\n", infoPtr
->ash
.dwScale
);
542 TRACE("ash.dwRate=%d\n", infoPtr
->ash
.dwRate
);
543 TRACE("ash.dwStart=%d\n", infoPtr
->ash
.dwStart
);
544 TRACE("ash.dwLength=%d\n", infoPtr
->ash
.dwLength
);
545 TRACE("ash.dwSuggestedBufferSize=%d\n", infoPtr
->ash
.dwSuggestedBufferSize
);
546 TRACE("ash.dwQuality=%d\n", infoPtr
->ash
.dwQuality
);
547 TRACE("ash.dwSampleSize=%d\n", infoPtr
->ash
.dwSampleSize
);
548 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
549 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
551 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
553 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
554 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
555 WARN("Can't find 'strh' chunk\n");
559 infoPtr
->inbih
= Alloc(mmckInfo
.cksize
);
560 if (!infoPtr
->inbih
) {
561 WARN("Can't alloc input BIH\n");
565 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
567 TRACE("bih.biSize=%d\n", infoPtr
->inbih
->biSize
);
568 TRACE("bih.biWidth=%d\n", infoPtr
->inbih
->biWidth
);
569 TRACE("bih.biHeight=%d\n", infoPtr
->inbih
->biHeight
);
570 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
571 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
572 TRACE("bih.biCompression=%d\n", infoPtr
->inbih
->biCompression
);
573 TRACE("bih.biSizeImage=%d\n", infoPtr
->inbih
->biSizeImage
);
574 TRACE("bih.biXPelsPerMeter=%d\n", infoPtr
->inbih
->biXPelsPerMeter
);
575 TRACE("bih.biYPelsPerMeter=%d\n", infoPtr
->inbih
->biYPelsPerMeter
);
576 TRACE("bih.biClrUsed=%d\n", infoPtr
->inbih
->biClrUsed
);
577 TRACE("bih.biClrImportant=%d\n", infoPtr
->inbih
->biClrImportant
);
579 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
581 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
584 /* an AVI has 0 or 1 video stream, and to be animated should not contain
585 * an audio stream, so only one strl is allowed
587 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
588 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
589 WARN("There should be a single 'strl' list\n");
594 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
596 /* no need to read optional JUNK chunk */
598 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
599 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
600 WARN("Can't find 'movi' list\n");
604 /* FIXME: should handle the 'rec ' LIST when present */
606 infoPtr
->lpIndex
= Alloc(infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
607 if (!infoPtr
->lpIndex
)
610 numFrame
= insize
= 0;
611 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
612 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
613 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
614 if (insize
< mmckInfo
.cksize
)
615 insize
= mmckInfo
.cksize
;
617 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
619 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
) {
620 WARN("Found %d frames (/%d)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
623 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
) {
624 WARN("insize=%d suggestedSize=%d\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
625 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
628 infoPtr
->indata
= Alloc(infoPtr
->ash
.dwSuggestedBufferSize
);
629 if (!infoPtr
->indata
)
636 static BOOL
ANIMATE_GetAviCodec(ANIMATE_INFO
*infoPtr
)
640 /* check uncompressed AVI */
641 if ((infoPtr
->ash
.fccHandler
== mmioFOURCC('D', 'I', 'B', ' ')) ||
642 (infoPtr
->ash
.fccHandler
== mmioFOURCC('R', 'L', 'E', ' ')) ||
643 (infoPtr
->ash
.fccHandler
== mmioFOURCC(0, 0, 0, 0)))
649 /* try to get a decompressor for that type */
650 infoPtr
->hic
= fnIC
.fnICOpen(ICTYPE_VIDEO
, infoPtr
->ash
.fccHandler
, ICMODE_DECOMPRESS
);
652 WARN("Can't load codec for the file\n");
656 outSize
= fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
657 (DWORD_PTR
)infoPtr
->inbih
, 0L);
659 infoPtr
->outbih
= Alloc(outSize
);
660 if (!infoPtr
->outbih
)
663 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
664 (DWORD_PTR
)infoPtr
->inbih
, (DWORD_PTR
)infoPtr
->outbih
) != ICERR_OK
)
666 WARN("Can't get output BIH\n");
670 infoPtr
->outdata
= Alloc(infoPtr
->outbih
->biSizeImage
);
671 if (!infoPtr
->outdata
)
674 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
675 (DWORD_PTR
)infoPtr
->inbih
, (DWORD_PTR
)infoPtr
->outbih
) != ICERR_OK
) {
676 WARN("Can't begin decompression\n");
684 static BOOL
ANIMATE_OpenW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPWSTR lpszName
)
686 ANIMATE_Free(infoPtr
);
690 TRACE("Closing avi!\n");
691 /* installer of thebat! v1.62 requires FALSE here */
692 return (infoPtr
->hMMio
!= 0);
696 hInstance
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
698 TRACE("(%s)\n", debugstr_w(lpszName
));
700 if (HIWORD(lpszName
))
702 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
704 TRACE("No AVI resource found!\n");
705 if (!ANIMATE_LoadFileW(infoPtr
, lpszName
))
707 WARN("No AVI file found!\n");
714 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
716 WARN("No AVI resource found!\n");
721 if (!ANIMATE_GetAviInfo(infoPtr
))
723 WARN("Can't get AVI information\n");
724 ANIMATE_Free(infoPtr
);
728 if (!ANIMATE_GetAviCodec(infoPtr
))
730 WARN("Can't get AVI Codec\n");
731 ANIMATE_Free(infoPtr
);
735 if (!(infoPtr
->dwStyle
& ACS_CENTER
))
736 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
737 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
739 if (infoPtr
->dwStyle
& ACS_AUTOPLAY
)
740 return ANIMATE_Play(infoPtr
, -1, 0, infoPtr
->mah
.dwTotalFrames
- 1);
746 static BOOL
ANIMATE_OpenA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPSTR lpszName
)
752 if (!HIWORD(lpszName
))
753 return ANIMATE_OpenW(infoPtr
, hInstance
, (LPWSTR
)lpszName
);
755 len
= MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, NULL
, 0);
756 lpwszName
= Alloc(len
* sizeof(WCHAR
));
757 if (!lpwszName
) return FALSE
;
758 MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, lpwszName
, len
);
760 result
= ANIMATE_OpenW(infoPtr
, hInstance
, lpwszName
);
766 static BOOL
ANIMATE_Stop(ANIMATE_INFO
*infoPtr
)
772 ANIMATE_DoStop(infoPtr
);
777 static BOOL
ANIMATE_Create(HWND hWnd
, const CREATESTRUCTW
*lpcs
)
779 static const WCHAR msvfw32W
[] = { 'm', 's', 'v', 'f', 'w', '3', '2', '.', 'd', 'l', 'l', 0 };
780 ANIMATE_INFO
*infoPtr
;
784 fnIC
.hModule
= LoadLibraryW(msvfw32W
);
785 if (!fnIC
.hModule
) return FALSE
;
787 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
788 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
789 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
790 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
793 /* allocate memory for info structure */
794 infoPtr
= (ANIMATE_INFO
*)Alloc(sizeof(ANIMATE_INFO
));
795 if (!infoPtr
) return FALSE
;
797 /* store crossref hWnd <-> info structure */
798 SetWindowLongPtrW(hWnd
, 0, (DWORD_PTR
)infoPtr
);
799 infoPtr
->hwndSelf
= hWnd
;
800 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
801 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
802 infoPtr
->hbmPrevFrame
= 0;
803 infoPtr
->dwStyle
= lpcs
->style
;
805 TRACE("Animate style=0x%08x, parent=%p\n", infoPtr
->dwStyle
, infoPtr
->hwndNotify
);
807 InitializeCriticalSection(&infoPtr
->cs
);
808 infoPtr
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ANIMATE_INFO*->cs");
814 static LRESULT
ANIMATE_Destroy(ANIMATE_INFO
*infoPtr
)
817 ANIMATE_Free(infoPtr
);
819 /* free animate info data */
820 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
822 infoPtr
->cs
.DebugInfo
->Spare
[0] = 0;
823 DeleteCriticalSection(&infoPtr
->cs
);
830 static BOOL
ANIMATE_EraseBackground(ANIMATE_INFO
const *infoPtr
, HDC hdc
)
835 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
837 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLORSTATIC
,
838 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
841 GetClientRect(infoPtr
->hwndSelf
, &rect
);
842 FillRect(hdc
, &rect
, hBrush
? hBrush
: GetCurrentObject(hdc
, OBJ_BRUSH
));
848 static LRESULT
ANIMATE_StyleChanged(ANIMATE_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
850 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
851 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
853 if (wStyleType
!= GWL_STYLE
) return 0;
855 infoPtr
->dwStyle
= lpss
->styleNew
;
857 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
862 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
864 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)GetWindowLongPtrW(hWnd
, 0);
866 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hWnd
, uMsg
, wParam
, lParam
);
867 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
868 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
872 return ANIMATE_OpenA(infoPtr
, (HINSTANCE
)wParam
, (LPSTR
)lParam
);
875 return ANIMATE_OpenW(infoPtr
, (HINSTANCE
)wParam
, (LPWSTR
)lParam
);
878 return ANIMATE_Play(infoPtr
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
881 return ANIMATE_Stop(infoPtr
);
884 ANIMATE_Free(infoPtr
);
888 return ANIMATE_Create(hWnd
, (LPCREATESTRUCTW
)lParam
);
891 return HTTRANSPARENT
;
894 return ANIMATE_Destroy(infoPtr
);
897 return ANIMATE_EraseBackground(infoPtr
, (HDC
)wParam
);
899 case WM_STYLECHANGED
:
900 return ANIMATE_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
903 return ANIMATE_Timer(infoPtr
);
908 /* the animation isn't playing, or has not decompressed
909 * (and displayed) the first frame yet, don't paint
911 if ((!infoPtr
->uTimer
&& !infoPtr
->hThread
) ||
912 !infoPtr
->hbmPrevFrame
)
914 /* default paint handling */
915 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
918 if (infoPtr
->dwStyle
& ACS_TRANSPARENT
)
919 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
921 wParam
, (LPARAM
)infoPtr
->hwndSelf
);
925 EnterCriticalSection(&infoPtr
->cs
);
926 ANIMATE_PaintFrame(infoPtr
, (HDC
)wParam
);
927 LeaveCriticalSection(&infoPtr
->cs
);
932 HDC hDC
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
934 EnterCriticalSection(&infoPtr
->cs
);
935 ANIMATE_PaintFrame(infoPtr
, hDC
);
936 LeaveCriticalSection(&infoPtr
->cs
);
938 EndPaint(infoPtr
->hwndSelf
, &ps
);
944 if (infoPtr
->dwStyle
& ACS_CENTER
)
945 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
946 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
949 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
950 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
952 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
957 void ANIMATE_Register(void)
961 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
962 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
963 wndClass
.lpfnWndProc
= ANIMATE_WindowProc
;
964 wndClass
.cbClsExtra
= 0;
965 wndClass
.cbWndExtra
= sizeof(ANIMATE_INFO
*);
966 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
967 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
968 wndClass
.lpszClassName
= ANIMATE_CLASSW
;
970 RegisterClassW(&wndClass
);
974 void ANIMATE_Unregister(void)
976 UnregisterClassW(ANIMATE_CLASSW
, NULL
);