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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
36 #define COM_NO_WINDOWS_H
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(animate
);
54 HIC (WINAPI
*fnICOpen
)(DWORD
, DWORD
, UINT
);
55 LRESULT (WINAPI
*fnICClose
)(HIC
);
56 LRESULT (WINAPI
*fnICSendMessage
)(HIC
, UINT
, DWORD
, DWORD
);
57 DWORD (WINAPIV
*fnICDecompress
)(HIC
,DWORD
,LPBITMAPINFOHEADER
,LPVOID
,LPBITMAPINFOHEADER
,LPVOID
);
62 /* reference to input stream (file or resource) */
64 HMMIO hMMio
; /* handle to mmio stream */
68 /* information on the loaded AVI file */
71 LPBITMAPINFOHEADER inbih
;
73 /* data for the decompressor */
75 LPBITMAPINFOHEADER outbih
;
78 /* data for the background mechanism */
84 /* data for playing the file */
90 COLORREF transparentColor
;
95 #define ANIMATE_COLOR_NONE 0xffffffff
97 static void ANIMATE_Notify(ANIMATE_INFO
*infoPtr
, UINT notif
)
99 SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
,
100 MAKEWPARAM(GetDlgCtrlID(infoPtr
->hwndSelf
), notif
),
101 (LPARAM
)infoPtr
->hwndSelf
);
104 static BOOL
ANIMATE_LoadResW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInst
, LPWSTR lpName
)
106 static const WCHAR aviW
[] = { 'A', 'V', 'I', 0 };
111 hrsrc
= FindResourceW(hInst
, lpName
, aviW
);
115 infoPtr
->hRes
= LoadResource(hInst
, hrsrc
);
119 lpAvi
= LockResource(infoPtr
->hRes
);
123 memset(&mminfo
, 0, sizeof(mminfo
));
124 mminfo
.fccIOProc
= FOURCC_MEM
;
125 mminfo
.pchBuffer
= (LPSTR
)lpAvi
;
126 mminfo
.cchBuffer
= SizeofResource(hInst
, hrsrc
);
127 infoPtr
->hMMio
= mmioOpenW(NULL
, &mminfo
, MMIO_READ
);
130 FreeResource(infoPtr
->hRes
);
138 static BOOL
ANIMATE_LoadFileW(ANIMATE_INFO
*infoPtr
, LPWSTR lpName
)
140 infoPtr
->hMMio
= mmioOpenW(lpName
, 0, MMIO_ALLOCBUF
| MMIO_READ
| MMIO_DENYWRITE
);
142 return (BOOL
)infoPtr
->hMMio
;
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
*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* pBitmapData
= NULL
;
255 LPBITMAPINFO pBitmapInfo
= NULL
;
266 if (!hDC
|| !infoPtr
->inbih
)
271 pBitmapData
= infoPtr
->outdata
;
272 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->outbih
;
274 nWidth
= infoPtr
->outbih
->biWidth
;
275 nHeight
= infoPtr
->outbih
->biHeight
;
279 pBitmapData
= infoPtr
->indata
;
280 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->inbih
;
282 nWidth
= infoPtr
->inbih
->biWidth
;
283 nHeight
= infoPtr
->inbih
->biHeight
;
286 if(!infoPtr
->hbmPrevFrame
)
288 infoPtr
->hbmPrevFrame
=CreateCompatibleBitmap(hDC
, nWidth
,nHeight
);
291 SetDIBits(hDC
, infoPtr
->hbmPrevFrame
, 0, nHeight
, pBitmapData
, (LPBITMAPINFO
)pBitmapInfo
, DIB_RGB_COLORS
);
293 hdcMem
= CreateCompatibleDC(hDC
);
294 hbmOld
= SelectObject(hdcMem
, infoPtr
->hbmPrevFrame
);
297 * we need to get the transparent color even without ACS_TRANSPARENT,
298 * because the style can be changed later on and the color should always
299 * be obtained in the first frame
301 if(infoPtr
->transparentColor
== ANIMATE_COLOR_NONE
)
303 infoPtr
->transparentColor
= GetPixel(hdcMem
,0,0);
306 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
308 HDC hdcFinal
= CreateCompatibleDC(hDC
);
309 HBITMAP hbmFinal
= CreateCompatibleBitmap(hDC
,nWidth
, nHeight
);
310 HBITMAP hbmOld2
= SelectObject(hdcFinal
, hbmFinal
);
316 rect
.bottom
= nHeight
;
318 if(!infoPtr
->hbrushBG
)
319 infoPtr
->hbrushBG
= GetCurrentObject(hDC
, OBJ_BRUSH
);
321 FillRect(hdcFinal
, &rect
, infoPtr
->hbrushBG
);
322 ANIMATE_TransparentBlt(infoPtr
, hdcFinal
, hdcMem
);
324 SelectObject(hdcFinal
, hbmOld2
);
325 SelectObject(hdcMem
, hbmFinal
);
327 DeleteObject(infoPtr
->hbmPrevFrame
);
328 infoPtr
->hbmPrevFrame
= hbmFinal
;
331 if (infoPtr
->dwStyle
& ACS_CENTER
)
335 GetWindowRect(infoPtr
->hwndSelf
, &rect
);
336 nOffsetX
= ((rect
.right
- rect
.left
) - nWidth
)/2;
337 nOffsetY
= ((rect
.bottom
- rect
.top
) - nHeight
)/2;
339 BitBlt(hDC
, nOffsetX
, nOffsetY
, nWidth
, nHeight
, hdcMem
, 0, 0, SRCCOPY
);
341 SelectObject(hdcMem
, hbmOld
);
346 static BOOL
ANIMATE_DrawFrame(ANIMATE_INFO
*infoPtr
)
350 TRACE("Drawing frame %d (loop %d)\n", infoPtr
->currFrame
, infoPtr
->nLoop
);
352 mmioSeek(infoPtr
->hMMio
, infoPtr
->lpIndex
[infoPtr
->currFrame
], SEEK_SET
);
353 mmioRead(infoPtr
->hMMio
, infoPtr
->indata
, infoPtr
->ash
.dwSuggestedBufferSize
);
356 fnIC
.fnICDecompress(infoPtr
->hic
, 0, infoPtr
->inbih
, infoPtr
->indata
,
357 infoPtr
->outbih
, infoPtr
->outdata
) != ICERR_OK
) {
358 WARN("Decompression error\n");
362 if ((hDC
= GetDC(infoPtr
->hwndSelf
)) != 0) {
363 ANIMATE_PaintFrame(infoPtr
, hDC
);
364 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
367 if (infoPtr
->currFrame
++ >= infoPtr
->nToFrame
) {
368 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
369 if (infoPtr
->nLoop
!= -1) {
370 if (--infoPtr
->nLoop
== 0) {
371 ANIMATE_DoStop(infoPtr
);
379 static LRESULT
ANIMATE_Timer(ANIMATE_INFO
*infoPtr
)
381 /* FIXME: we should pass the hDC instead of 0 to WM_CTLCOLORSTATIC */
382 if (infoPtr
->dwStyle
& ACS_TRANSPARENT
)
383 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
385 0, (LPARAM
)infoPtr
->hwndSelf
);
386 EnterCriticalSection(&infoPtr
->cs
);
387 ANIMATE_DrawFrame(infoPtr
);
388 LeaveCriticalSection(&infoPtr
->cs
);
393 static DWORD CALLBACK
ANIMATE_AnimationThread(LPVOID ptr_
)
395 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)ptr_
;
401 EnterCriticalSection(&infoPtr
->cs
);
402 ANIMATE_DrawFrame(infoPtr
);
403 timeout
= infoPtr
->mah
.dwMicroSecPerFrame
;
404 event
= infoPtr
->hStopEvent
;
405 LeaveCriticalSection(&infoPtr
->cs
);
407 /* time is in microseconds, we should convert it to milliseconds */
408 if ((event
== 0) || WaitForSingleObject( event
, (timeout
+500)/1000) == WAIT_OBJECT_0
)
414 static LRESULT
ANIMATE_Play(ANIMATE_INFO
*infoPtr
, UINT cRepeat
, WORD wFrom
, WORD wTo
)
420 if (infoPtr
->hThread
|| infoPtr
->uTimer
) {
421 TRACE("Already playing\n");
425 infoPtr
->nFromFrame
= wFrom
;
426 infoPtr
->nToFrame
= wTo
;
427 infoPtr
->nLoop
= cRepeat
;
429 if (infoPtr
->nToFrame
== 0xFFFF)
430 infoPtr
->nToFrame
= infoPtr
->mah
.dwTotalFrames
- 1;
432 TRACE("(repeat=%d from=%d to=%d);\n",
433 infoPtr
->nLoop
, infoPtr
->nFromFrame
, infoPtr
->nToFrame
);
435 if (infoPtr
->nFromFrame
>= infoPtr
->nToFrame
||
436 infoPtr
->nToFrame
>= infoPtr
->mah
.dwTotalFrames
)
439 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
441 if (infoPtr
->dwStyle
& ACS_TIMER
)
443 TRACE("Using a timer\n");
444 /* create a timer to display AVI */
445 infoPtr
->uTimer
= SetTimer(infoPtr
->hwndSelf
, 1,
446 infoPtr
->mah
.dwMicroSecPerFrame
/ 1000, NULL
);
450 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
451 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
452 WM_CTLCOLORSTATIC
, 0,
453 (LPARAM
)infoPtr
->hwndSelf
);
455 TRACE("Using an animation thread\n");
456 infoPtr
->hStopEvent
= CreateEventW( NULL
, TRUE
, FALSE
, NULL
);
457 infoPtr
->hThread
= CreateThread(0, 0, ANIMATE_AnimationThread
,
458 (LPVOID
)infoPtr
, 0, &infoPtr
->threadId
);
459 if(!infoPtr
->hThread
) return FALSE
;
463 ANIMATE_Notify(infoPtr
, ACN_START
);
469 static BOOL
ANIMATE_GetAviInfo(ANIMATE_INFO
*infoPtr
)
478 if (mmioDescend(infoPtr
->hMMio
, &ckMainRIFF
, NULL
, 0) != 0) {
479 WARN("Can't find 'RIFF' chunk\n");
483 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) ||
484 (ckMainRIFF
.fccType
!= mmioFOURCC('A', 'V', 'I', ' '))) {
485 WARN("Can't find 'AVI ' chunk\n");
489 mmckHead
.fccType
= mmioFOURCC('h', 'd', 'r', 'l');
490 if (mmioDescend(infoPtr
->hMMio
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
491 WARN("Can't find 'hdrl' list\n");
495 mmckInfo
.ckid
= mmioFOURCC('a', 'v', 'i', 'h');
496 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
497 WARN("Can't find 'avih' chunk\n");
501 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->mah
, sizeof(infoPtr
->mah
));
503 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr
->mah
.dwMicroSecPerFrame
);
504 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr
->mah
.dwMaxBytesPerSec
);
505 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr
->mah
.dwPaddingGranularity
);
506 TRACE("mah.dwFlags=%ld\n", infoPtr
->mah
.dwFlags
);
507 TRACE("mah.dwTotalFrames=%ld\n", infoPtr
->mah
.dwTotalFrames
);
508 TRACE("mah.dwInitialFrames=%ld\n", infoPtr
->mah
.dwInitialFrames
);
509 TRACE("mah.dwStreams=%ld\n", infoPtr
->mah
.dwStreams
);
510 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr
->mah
.dwSuggestedBufferSize
);
511 TRACE("mah.dwWidth=%ld\n", infoPtr
->mah
.dwWidth
);
512 TRACE("mah.dwHeight=%ld\n", infoPtr
->mah
.dwHeight
);
514 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
516 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
517 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0) {
518 WARN("Can't find 'strl' list\n");
522 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'h');
523 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
524 WARN("Can't find 'strh' chunk\n");
528 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->ash
, sizeof(infoPtr
->ash
));
530 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccType
)),
531 HIBYTE(LOWORD(infoPtr
->ash
.fccType
)),
532 LOBYTE(HIWORD(infoPtr
->ash
.fccType
)),
533 HIBYTE(HIWORD(infoPtr
->ash
.fccType
)));
534 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
535 HIBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
536 LOBYTE(HIWORD(infoPtr
->ash
.fccHandler
)),
537 HIBYTE(HIWORD(infoPtr
->ash
.fccHandler
)));
538 TRACE("ash.dwFlags=%ld\n", infoPtr
->ash
.dwFlags
);
539 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
540 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
541 TRACE("ash.dwInitialFrames=%ld\n", infoPtr
->ash
.dwInitialFrames
);
542 TRACE("ash.dwScale=%ld\n", infoPtr
->ash
.dwScale
);
543 TRACE("ash.dwRate=%ld\n", infoPtr
->ash
.dwRate
);
544 TRACE("ash.dwStart=%ld\n", infoPtr
->ash
.dwStart
);
545 TRACE("ash.dwLength=%ld\n", infoPtr
->ash
.dwLength
);
546 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr
->ash
.dwSuggestedBufferSize
);
547 TRACE("ash.dwQuality=%ld\n", infoPtr
->ash
.dwQuality
);
548 TRACE("ash.dwSampleSize=%ld\n", infoPtr
->ash
.dwSampleSize
);
549 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
550 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
552 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
554 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
555 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
556 WARN("Can't find 'strh' chunk\n");
560 infoPtr
->inbih
= Alloc(mmckInfo
.cksize
);
561 if (!infoPtr
->inbih
) {
562 WARN("Can't alloc input BIH\n");
566 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
568 TRACE("bih.biSize=%ld\n", infoPtr
->inbih
->biSize
);
569 TRACE("bih.biWidth=%ld\n", infoPtr
->inbih
->biWidth
);
570 TRACE("bih.biHeight=%ld\n", infoPtr
->inbih
->biHeight
);
571 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
572 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
573 TRACE("bih.biCompression=%ld\n", infoPtr
->inbih
->biCompression
);
574 TRACE("bih.biSizeImage=%ld\n", infoPtr
->inbih
->biSizeImage
);
575 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr
->inbih
->biXPelsPerMeter
);
576 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr
->inbih
->biYPelsPerMeter
);
577 TRACE("bih.biClrUsed=%ld\n", infoPtr
->inbih
->biClrUsed
);
578 TRACE("bih.biClrImportant=%ld\n", infoPtr
->inbih
->biClrImportant
);
580 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
582 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
585 /* an AVI has 0 or 1 video stream, and to be animated should not contain
586 * an audio stream, so only one strl is allowed
588 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
589 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
590 WARN("There should be a single 'strl' list\n");
595 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
597 /* no need to read optional JUNK chunk */
599 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
600 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
601 WARN("Can't find 'movi' list\n");
605 /* FIXME: should handle the 'rec ' LIST when present */
607 infoPtr
->lpIndex
= Alloc(infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
608 if (!infoPtr
->lpIndex
)
611 numFrame
= insize
= 0;
612 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
613 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
614 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
615 if (insize
< mmckInfo
.cksize
)
616 insize
= mmckInfo
.cksize
;
618 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
620 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
) {
621 WARN("Found %ld frames (/%ld)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
624 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
) {
625 WARN("insize=%ld suggestedSize=%ld\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
626 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
629 infoPtr
->indata
= Alloc(infoPtr
->ash
.dwSuggestedBufferSize
);
630 if (!infoPtr
->indata
)
637 static BOOL
ANIMATE_GetAviCodec(ANIMATE_INFO
*infoPtr
)
641 /* check uncompressed AVI */
642 if ((infoPtr
->ash
.fccHandler
== mmioFOURCC('D', 'I', 'B', ' ')) ||
643 (infoPtr
->ash
.fccHandler
== mmioFOURCC('R', 'L', 'E', ' ')) ||
644 (infoPtr
->ash
.fccHandler
== mmioFOURCC(0, 0, 0, 0)))
650 /* try to get a decompressor for that type */
651 infoPtr
->hic
= fnIC
.fnICOpen(ICTYPE_VIDEO
, infoPtr
->ash
.fccHandler
, ICMODE_DECOMPRESS
);
653 WARN("Can't load codec for the file\n");
657 outSize
= fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
658 (DWORD
)infoPtr
->inbih
, 0L);
660 infoPtr
->outbih
= Alloc(outSize
);
661 if (!infoPtr
->outbih
)
664 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
665 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != outSize
)
667 WARN("Can't get output BIH\n");
671 infoPtr
->outdata
= Alloc(infoPtr
->outbih
->biSizeImage
);
672 if (!infoPtr
->outdata
)
675 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
676 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != ICERR_OK
) {
677 WARN("Can't begin decompression\n");
685 static BOOL
ANIMATE_OpenW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPWSTR lpszName
)
687 ANIMATE_Free(infoPtr
);
691 TRACE("Closing avi!\n");
692 /* installer of thebat! v1.62 requires FALSE here */
693 return (infoPtr
->hMMio
!= 0);
697 hInstance
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
699 if (HIWORD(lpszName
))
701 TRACE("(\"%s\");\n", debugstr_w(lpszName
));
703 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
705 TRACE("No AVI resource found!\n");
706 if (!ANIMATE_LoadFileW(infoPtr
, lpszName
))
708 WARN("No AVI file found!\n");
715 TRACE("(%u);\n", (WORD
)(DWORD
)lpszName
);
717 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, MAKEINTRESOURCEW((INT
)lpszName
)))
719 WARN("No AVI resource found!\n");
724 if (!ANIMATE_GetAviInfo(infoPtr
))
726 WARN("Can't get AVI information\n");
727 ANIMATE_Free(infoPtr
);
731 if (!ANIMATE_GetAviCodec(infoPtr
))
733 WARN("Can't get AVI Codec\n");
734 ANIMATE_Free(infoPtr
);
738 if (!(infoPtr
->dwStyle
& ACS_CENTER
))
739 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
740 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
742 if (infoPtr
->dwStyle
& ACS_AUTOPLAY
)
743 return ANIMATE_Play(infoPtr
, -1, 0, infoPtr
->mah
.dwTotalFrames
- 1);
749 static BOOL
ANIMATE_OpenA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPSTR lpszName
)
755 if (!HIWORD(lpszName
))
756 return ANIMATE_OpenW(infoPtr
, hInstance
, (LPWSTR
)lpszName
);
758 len
= MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, NULL
, 0);
759 lpwszName
= Alloc(len
* sizeof(WCHAR
));
760 if (!lpwszName
) return FALSE
;
761 MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, lpwszName
, len
);
763 result
= ANIMATE_OpenW(infoPtr
, hInstance
, lpwszName
);
769 static BOOL
ANIMATE_Stop(ANIMATE_INFO
*infoPtr
)
775 ANIMATE_DoStop(infoPtr
);
780 static BOOL
ANIMATE_Create(HWND hWnd
, LPCREATESTRUCTW lpcs
)
782 static const WCHAR msvfw32W
[] = { 'm', 's', 'v', 'f', 'w', '3', '2', '.', 'd', 'l', 'l', 0 };
783 ANIMATE_INFO
*infoPtr
;
787 fnIC
.hModule
= LoadLibraryW(msvfw32W
);
788 if (!fnIC
.hModule
) return FALSE
;
790 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
791 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
792 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
793 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
796 /* allocate memory for info structure */
797 infoPtr
= (ANIMATE_INFO
*)Alloc(sizeof(ANIMATE_INFO
));
798 if (!infoPtr
) return FALSE
;
800 /* store crossref hWnd <-> info structure */
801 SetWindowLongPtrW(hWnd
, 0, (DWORD_PTR
)infoPtr
);
802 infoPtr
->hwndSelf
= hWnd
;
803 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
804 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
805 infoPtr
->hbmPrevFrame
= 0;
806 infoPtr
->dwStyle
= lpcs
->style
;
808 TRACE("Animate style=0x%08lx, parent=%p\n", infoPtr
->dwStyle
, infoPtr
->hwndNotify
);
810 InitializeCriticalSection(&infoPtr
->cs
);
816 static LRESULT
ANIMATE_Destroy(ANIMATE_INFO
*infoPtr
)
819 ANIMATE_Free(infoPtr
);
821 /* free animate info data */
822 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
824 DeleteCriticalSection(&infoPtr
->cs
);
831 static BOOL
ANIMATE_EraseBackground(ANIMATE_INFO
*infoPtr
, HDC hdc
)
836 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
838 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLORSTATIC
,
839 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
842 GetClientRect(infoPtr
->hwndSelf
, &rect
);
843 FillRect(hdc
, &rect
, hBrush
? hBrush
: GetCurrentObject(hdc
, OBJ_BRUSH
));
849 static LRESULT
ANIMATE_StyleChanged(ANIMATE_INFO
*infoPtr
, WPARAM wStyleType
, LPSTYLESTRUCT lpss
)
851 TRACE("(styletype=%x, styleOld=0x%08lx, styleNew=0x%08lx)\n",
852 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
854 if (wStyleType
!= GWL_STYLE
) return 0;
856 infoPtr
->dwStyle
= lpss
->styleNew
;
858 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
863 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
865 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)GetWindowLongPtrW(hWnd
, 0);
867 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd
, uMsg
, wParam
, lParam
);
868 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
869 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
873 return ANIMATE_OpenA(infoPtr
, (HINSTANCE
)wParam
, (LPSTR
)lParam
);
876 return ANIMATE_OpenW(infoPtr
, (HINSTANCE
)wParam
, (LPWSTR
)lParam
);
879 return ANIMATE_Play(infoPtr
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
882 return ANIMATE_Stop(infoPtr
);
885 ANIMATE_Free(infoPtr
);
889 return ANIMATE_Create(hWnd
, (LPCREATESTRUCTW
)lParam
);
892 return HTTRANSPARENT
;
895 return ANIMATE_Destroy(infoPtr
);
898 return ANIMATE_EraseBackground(infoPtr
, (HDC
)wParam
);
900 case WM_STYLECHANGED
:
901 return ANIMATE_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
904 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=%08x 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
);