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 HeapFree(GetProcessHeap(), 0, infoPtr
->lpIndex
);
194 infoPtr
->lpIndex
= NULL
;
196 fnIC
.fnICClose(infoPtr
->hic
);
199 HeapFree(GetProcessHeap(), 0, infoPtr
->inbih
);
200 infoPtr
->inbih
= NULL
;
201 HeapFree(GetProcessHeap(), 0, infoPtr
->outbih
);
202 infoPtr
->outbih
= NULL
;
203 HeapFree(GetProcessHeap(), 0, infoPtr
->indata
);
204 infoPtr
->indata
= NULL
;
205 HeapFree(GetProcessHeap(), 0, 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 EnterCriticalSection(&infoPtr
->cs
);
354 mmioSeek(infoPtr
->hMMio
, infoPtr
->lpIndex
[infoPtr
->currFrame
], SEEK_SET
);
355 mmioRead(infoPtr
->hMMio
, infoPtr
->indata
, infoPtr
->ash
.dwSuggestedBufferSize
);
358 fnIC
.fnICDecompress(infoPtr
->hic
, 0, infoPtr
->inbih
, infoPtr
->indata
,
359 infoPtr
->outbih
, infoPtr
->outdata
) != ICERR_OK
) {
360 LeaveCriticalSection(&infoPtr
->cs
);
361 WARN("Decompression error\n");
365 if ((hDC
= GetDC(infoPtr
->hwndSelf
)) != 0) {
366 ANIMATE_PaintFrame(infoPtr
, hDC
);
367 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
370 if (infoPtr
->currFrame
++ >= infoPtr
->nToFrame
) {
371 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
372 if (infoPtr
->nLoop
!= -1) {
373 if (--infoPtr
->nLoop
== 0) {
374 ANIMATE_DoStop(infoPtr
);
378 LeaveCriticalSection(&infoPtr
->cs
);
383 static DWORD CALLBACK
ANIMATE_AnimationThread(LPVOID ptr_
)
385 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)ptr_
;
391 EnterCriticalSection(&infoPtr
->cs
);
392 ANIMATE_DrawFrame(infoPtr
);
393 timeout
= infoPtr
->mah
.dwMicroSecPerFrame
;
394 event
= infoPtr
->hStopEvent
;
395 LeaveCriticalSection(&infoPtr
->cs
);
397 /* time is in microseconds, we should convert it to milliseconds */
398 if ((event
== 0) || WaitForSingleObject( event
, (timeout
+500)/1000) == WAIT_OBJECT_0
)
404 static LRESULT
ANIMATE_Play(ANIMATE_INFO
*infoPtr
, UINT cRepeat
, WORD wFrom
, WORD wTo
)
410 if (infoPtr
->hThread
|| infoPtr
->uTimer
) {
411 TRACE("Already playing\n");
415 infoPtr
->nFromFrame
= wFrom
;
416 infoPtr
->nToFrame
= wTo
;
417 infoPtr
->nLoop
= cRepeat
;
419 if (infoPtr
->nToFrame
== 0xFFFF)
420 infoPtr
->nToFrame
= infoPtr
->mah
.dwTotalFrames
- 1;
422 TRACE("(repeat=%d from=%d to=%d);\n",
423 infoPtr
->nLoop
, infoPtr
->nFromFrame
, infoPtr
->nToFrame
);
425 if (infoPtr
->nFromFrame
>= infoPtr
->nToFrame
||
426 infoPtr
->nToFrame
>= infoPtr
->mah
.dwTotalFrames
)
429 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
431 if (infoPtr
->dwStyle
& ACS_TIMER
)
433 TRACE("Using a timer\n");
434 /* create a timer to display AVI */
435 infoPtr
->uTimer
= SetTimer(infoPtr
->hwndSelf
, 1,
436 infoPtr
->mah
.dwMicroSecPerFrame
/ 1000, NULL
);
440 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
441 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
442 WM_CTLCOLORSTATIC
, 0,
443 (LPARAM
)infoPtr
->hwndSelf
);
445 TRACE("Using an animation thread\n");
446 infoPtr
->hStopEvent
= CreateEventW( NULL
, TRUE
, FALSE
, NULL
);
447 infoPtr
->hThread
= CreateThread(0, 0, ANIMATE_AnimationThread
,
448 (LPVOID
)infoPtr
, 0, &infoPtr
->threadId
);
449 if(!infoPtr
->hThread
) return FALSE
;
453 ANIMATE_Notify(infoPtr
, ACN_START
);
459 static BOOL
ANIMATE_GetAviInfo(ANIMATE_INFO
*infoPtr
)
468 if (mmioDescend(infoPtr
->hMMio
, &ckMainRIFF
, NULL
, 0) != 0) {
469 WARN("Can't find 'RIFF' chunk\n");
473 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) ||
474 (ckMainRIFF
.fccType
!= mmioFOURCC('A', 'V', 'I', ' '))) {
475 WARN("Can't find 'AVI ' chunk\n");
479 mmckHead
.fccType
= mmioFOURCC('h', 'd', 'r', 'l');
480 if (mmioDescend(infoPtr
->hMMio
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
481 WARN("Can't find 'hdrl' list\n");
485 mmckInfo
.ckid
= mmioFOURCC('a', 'v', 'i', 'h');
486 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
487 WARN("Can't find 'avih' chunk\n");
491 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->mah
, sizeof(infoPtr
->mah
));
493 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr
->mah
.dwMicroSecPerFrame
);
494 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr
->mah
.dwMaxBytesPerSec
);
495 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr
->mah
.dwPaddingGranularity
);
496 TRACE("mah.dwFlags=%ld\n", infoPtr
->mah
.dwFlags
);
497 TRACE("mah.dwTotalFrames=%ld\n", infoPtr
->mah
.dwTotalFrames
);
498 TRACE("mah.dwInitialFrames=%ld\n", infoPtr
->mah
.dwInitialFrames
);
499 TRACE("mah.dwStreams=%ld\n", infoPtr
->mah
.dwStreams
);
500 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr
->mah
.dwSuggestedBufferSize
);
501 TRACE("mah.dwWidth=%ld\n", infoPtr
->mah
.dwWidth
);
502 TRACE("mah.dwHeight=%ld\n", infoPtr
->mah
.dwHeight
);
504 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
506 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
507 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0) {
508 WARN("Can't find 'strl' list\n");
512 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'h');
513 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
514 WARN("Can't find 'strh' chunk\n");
518 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->ash
, sizeof(infoPtr
->ash
));
520 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccType
)),
521 HIBYTE(LOWORD(infoPtr
->ash
.fccType
)),
522 LOBYTE(HIWORD(infoPtr
->ash
.fccType
)),
523 HIBYTE(HIWORD(infoPtr
->ash
.fccType
)));
524 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
525 HIBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
526 LOBYTE(HIWORD(infoPtr
->ash
.fccHandler
)),
527 HIBYTE(HIWORD(infoPtr
->ash
.fccHandler
)));
528 TRACE("ash.dwFlags=%ld\n", infoPtr
->ash
.dwFlags
);
529 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
530 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
531 TRACE("ash.dwInitialFrames=%ld\n", infoPtr
->ash
.dwInitialFrames
);
532 TRACE("ash.dwScale=%ld\n", infoPtr
->ash
.dwScale
);
533 TRACE("ash.dwRate=%ld\n", infoPtr
->ash
.dwRate
);
534 TRACE("ash.dwStart=%ld\n", infoPtr
->ash
.dwStart
);
535 TRACE("ash.dwLength=%ld\n", infoPtr
->ash
.dwLength
);
536 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr
->ash
.dwSuggestedBufferSize
);
537 TRACE("ash.dwQuality=%ld\n", infoPtr
->ash
.dwQuality
);
538 TRACE("ash.dwSampleSize=%ld\n", infoPtr
->ash
.dwSampleSize
);
539 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
540 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
542 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
544 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
545 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
546 WARN("Can't find 'strh' chunk\n");
550 infoPtr
->inbih
= HeapAlloc(GetProcessHeap(), 0, mmckInfo
.cksize
);
551 if (!infoPtr
->inbih
) {
552 WARN("Can't alloc input BIH\n");
556 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
558 TRACE("bih.biSize=%ld\n", infoPtr
->inbih
->biSize
);
559 TRACE("bih.biWidth=%ld\n", infoPtr
->inbih
->biWidth
);
560 TRACE("bih.biHeight=%ld\n", infoPtr
->inbih
->biHeight
);
561 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
562 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
563 TRACE("bih.biCompression=%ld\n", infoPtr
->inbih
->biCompression
);
564 TRACE("bih.biSizeImage=%ld\n", infoPtr
->inbih
->biSizeImage
);
565 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr
->inbih
->biXPelsPerMeter
);
566 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr
->inbih
->biYPelsPerMeter
);
567 TRACE("bih.biClrUsed=%ld\n", infoPtr
->inbih
->biClrUsed
);
568 TRACE("bih.biClrImportant=%ld\n", infoPtr
->inbih
->biClrImportant
);
570 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
572 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
575 /* an AVI has 0 or 1 video stream, and to be animated should not contain
576 * an audio stream, so only one strl is allowed
578 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
579 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
580 WARN("There should be a single 'strl' list\n");
585 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
587 /* no need to read optional JUNK chunk */
589 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
590 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
591 WARN("Can't find 'movi' list\n");
595 /* FIXME: should handle the 'rec ' LIST when present */
597 infoPtr
->lpIndex
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
598 infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
599 if (!infoPtr
->lpIndex
)
602 numFrame
= insize
= 0;
603 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
604 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
605 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
606 if (insize
< mmckInfo
.cksize
)
607 insize
= mmckInfo
.cksize
;
609 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
611 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
) {
612 WARN("Found %ld frames (/%ld)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
615 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
) {
616 WARN("insize=%ld suggestedSize=%ld\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
617 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
620 infoPtr
->indata
= HeapAlloc(GetProcessHeap(), 0, infoPtr
->ash
.dwSuggestedBufferSize
);
621 if (!infoPtr
->indata
)
628 static BOOL
ANIMATE_GetAviCodec(ANIMATE_INFO
*infoPtr
)
632 /* check uncompressed AVI */
633 if ((infoPtr
->ash
.fccHandler
== mmioFOURCC('D', 'I', 'B', ' ')) ||
634 (infoPtr
->ash
.fccHandler
== mmioFOURCC('R', 'L', 'E', ' ')) ||
635 (infoPtr
->ash
.fccHandler
== mmioFOURCC(0, 0, 0, 0)))
641 /* try to get a decompressor for that type */
642 infoPtr
->hic
= fnIC
.fnICOpen(ICTYPE_VIDEO
, infoPtr
->ash
.fccHandler
, ICMODE_DECOMPRESS
);
644 WARN("Can't load codec for the file\n");
648 outSize
= fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
649 (DWORD
)infoPtr
->inbih
, 0L);
651 infoPtr
->outbih
= HeapAlloc(GetProcessHeap(), 0, outSize
);
652 if (!infoPtr
->outbih
)
655 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
656 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != outSize
)
658 WARN("Can't get output BIH\n");
662 infoPtr
->outdata
= HeapAlloc(GetProcessHeap(), 0, infoPtr
->outbih
->biSizeImage
);
663 if (!infoPtr
->outdata
)
666 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
667 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != ICERR_OK
) {
668 WARN("Can't begin decompression\n");
676 static BOOL
ANIMATE_OpenW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPWSTR lpszName
)
678 ANIMATE_Free(infoPtr
);
682 TRACE("Closing avi!\n");
683 /* installer of thebat! v1.62 requires FALSE here */
684 return (infoPtr
->hMMio
!= 0);
688 hInstance
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
690 if (HIWORD(lpszName
))
692 TRACE("(\"%s\");\n", debugstr_w(lpszName
));
694 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
696 TRACE("No AVI resource found!\n");
697 if (!ANIMATE_LoadFileW(infoPtr
, lpszName
))
699 WARN("No AVI file found!\n");
706 TRACE("(%u);\n", (WORD
)(DWORD
)lpszName
);
708 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, MAKEINTRESOURCEW((INT
)lpszName
)))
710 WARN("No AVI resource found!\n");
715 if (!ANIMATE_GetAviInfo(infoPtr
))
717 WARN("Can't get AVI information\n");
718 ANIMATE_Free(infoPtr
);
722 if (!ANIMATE_GetAviCodec(infoPtr
))
724 WARN("Can't get AVI Codec\n");
725 ANIMATE_Free(infoPtr
);
729 if (!(infoPtr
->dwStyle
& ACS_CENTER
))
730 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
731 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
733 if (infoPtr
->dwStyle
& ACS_AUTOPLAY
)
734 return ANIMATE_Play(infoPtr
, -1, 0, infoPtr
->mah
.dwTotalFrames
- 1);
740 static BOOL
ANIMATE_OpenA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPSTR lpszName
)
746 if (!HIWORD(lpszName
))
747 return ANIMATE_OpenW(infoPtr
, hInstance
, (LPWSTR
)lpszName
);
749 len
= MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, NULL
, 0);
750 lpwszName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
751 if (!lpwszName
) return FALSE
;
752 MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, lpwszName
, len
);
754 result
= ANIMATE_OpenW(infoPtr
, hInstance
, lpwszName
);
755 HeapFree(GetProcessHeap(), 0, lpwszName
);
760 static BOOL
ANIMATE_Stop(ANIMATE_INFO
*infoPtr
)
766 ANIMATE_DoStop(infoPtr
);
771 static BOOL
ANIMATE_Create(HWND hWnd
, LPCREATESTRUCTW lpcs
)
773 static const WCHAR msvfw32W
[] = { 'm', 's', 'v', 'f', 'w', '3', '2', '.', 'd', 'l', 'l', 0 };
774 ANIMATE_INFO
*infoPtr
;
778 fnIC
.hModule
= LoadLibraryW(msvfw32W
);
779 if (!fnIC
.hModule
) return FALSE
;
781 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
782 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
783 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
784 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
787 /* allocate memory for info structure */
788 infoPtr
= (ANIMATE_INFO
*)Alloc(sizeof(ANIMATE_INFO
));
789 if (!infoPtr
) return FALSE
;
791 /* store crossref hWnd <-> info structure */
792 SetWindowLongPtrW(hWnd
, 0, (DWORD_PTR
)infoPtr
);
793 infoPtr
->hwndSelf
= hWnd
;
794 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
795 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
796 infoPtr
->hbmPrevFrame
= 0;
797 infoPtr
->dwStyle
= lpcs
->style
;
799 TRACE("Animate style=0x%08lx, parent=%p\n", infoPtr
->dwStyle
, infoPtr
->hwndNotify
);
801 InitializeCriticalSection(&infoPtr
->cs
);
807 static LRESULT
ANIMATE_Destroy(ANIMATE_INFO
*infoPtr
)
810 ANIMATE_Free(infoPtr
);
812 /* free animate info data */
813 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
820 static BOOL
ANIMATE_EraseBackground(ANIMATE_INFO
*infoPtr
, HDC hdc
)
825 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
827 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLORSTATIC
,
828 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
831 GetClientRect(infoPtr
->hwndSelf
, &rect
);
832 FillRect(hdc
, &rect
, hBrush
? hBrush
: GetCurrentObject(hdc
, OBJ_BRUSH
));
838 static LRESULT
ANIMATE_StyleChanged(ANIMATE_INFO
*infoPtr
, WPARAM wStyleType
, LPSTYLESTRUCT lpss
)
840 TRACE("(styletype=%x, styleOld=0x%08lx, styleNew=0x%08lx)\n",
841 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
843 if (wStyleType
!= GWL_STYLE
) return 0;
845 infoPtr
->dwStyle
= lpss
->styleNew
;
847 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
852 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
854 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)GetWindowLongPtrW(hWnd
, 0);
856 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd
, uMsg
, wParam
, lParam
);
857 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
858 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
862 return ANIMATE_OpenA(infoPtr
, (HINSTANCE
)wParam
, (LPSTR
)lParam
);
865 return ANIMATE_OpenW(infoPtr
, (HINSTANCE
)wParam
, (LPWSTR
)lParam
);
868 return ANIMATE_Play(infoPtr
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
871 return ANIMATE_Stop(infoPtr
);
874 ANIMATE_Free(infoPtr
);
878 return ANIMATE_Create(hWnd
, (LPCREATESTRUCTW
)lParam
);
881 return HTTRANSPARENT
;
884 return ANIMATE_Destroy(infoPtr
);
887 return ANIMATE_EraseBackground(infoPtr
, (HDC
)wParam
);
889 case WM_STYLECHANGED
:
890 return ANIMATE_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
893 if (infoPtr
->dwStyle
& ACS_TRANSPARENT
)
894 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
896 wParam
, (LPARAM
)infoPtr
->hwndSelf
);
897 return ANIMATE_DrawFrame(infoPtr
);
901 /* the animation isn't playing, or has not decompressed
902 * (and displayed) the first frame yet, don't paint
904 if ((!infoPtr
->uTimer
&& !infoPtr
->hThread
) ||
905 !infoPtr
->hbmPrevFrame
)
907 /* default paint handling */
908 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
911 if (infoPtr
->dwStyle
& ACS_TRANSPARENT
)
912 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
,
914 wParam
, (LPARAM
)infoPtr
->hwndSelf
);
918 EnterCriticalSection(&infoPtr
->cs
);
919 ANIMATE_PaintFrame(infoPtr
, (HDC
)wParam
);
920 LeaveCriticalSection(&infoPtr
->cs
);
925 HDC hDC
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
927 EnterCriticalSection(&infoPtr
->cs
);
928 ANIMATE_PaintFrame(infoPtr
, hDC
);
929 LeaveCriticalSection(&infoPtr
->cs
);
931 EndPaint(infoPtr
->hwndSelf
, &ps
);
937 if (infoPtr
->dwStyle
& ACS_CENTER
)
938 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
939 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
942 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
943 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
945 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
950 void ANIMATE_Register(void)
954 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
955 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
956 wndClass
.lpfnWndProc
= ANIMATE_WindowProc
;
957 wndClass
.cbClsExtra
= 0;
958 wndClass
.cbWndExtra
= sizeof(ANIMATE_INFO
*);
959 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
960 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
961 wndClass
.lpszClassName
= ANIMATE_CLASSW
;
963 RegisterClassW(&wndClass
);
967 void ANIMATE_Unregister(void)
969 UnregisterClassW(ANIMATE_CLASSW
, NULL
);