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
24 * - check for the 'rec ' list in some AVI files
38 #include "wine/debug.h"
39 #include "wine/heap.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(animate
);
45 HIC (WINAPI
*fnICOpen
)(DWORD
, DWORD
, UINT
);
46 LRESULT (WINAPI
*fnICClose
)(HIC
);
47 LRESULT (WINAPI
*fnICSendMessage
)(HIC
, UINT
, DWORD_PTR
, DWORD_PTR
);
48 DWORD (WINAPIV
*fnICDecompress
)(HIC
,DWORD
,LPBITMAPINFOHEADER
,LPVOID
,LPBITMAPINFOHEADER
,LPVOID
);
53 /* reference to input stream (file or resource) */
55 HMMIO hMMio
; /* handle to mmio stream */
59 /* information on the loaded AVI file */
62 LPBITMAPINFOHEADER inbih
;
64 /* data for the decompressor */
66 LPBITMAPINFOHEADER outbih
;
69 /* data for the background mechanism */
75 /* data for playing the file */
80 /* transparency info*/
81 COLORREF transparentColor
;
86 #define ANIMATE_COLOR_NONE 0xffffffff
88 static void ANIMATE_Notify(const ANIMATE_INFO
*infoPtr
, UINT notif
)
90 PostMessageW(infoPtr
->hwndNotify
, WM_COMMAND
,
91 MAKEWPARAM(GetDlgCtrlID(infoPtr
->hwndSelf
), notif
),
92 (LPARAM
)infoPtr
->hwndSelf
);
95 static BOOL
ANIMATE_LoadResW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInst
, LPCWSTR lpName
)
97 static const WCHAR aviW
[] = { 'A', 'V', 'I', 0 };
102 hrsrc
= FindResourceW(hInst
, lpName
, aviW
);
106 infoPtr
->hRes
= LoadResource(hInst
, hrsrc
);
110 lpAvi
= LockResource(infoPtr
->hRes
);
114 memset(&mminfo
, 0, sizeof(mminfo
));
115 mminfo
.fccIOProc
= FOURCC_MEM
;
116 mminfo
.pchBuffer
= lpAvi
;
117 mminfo
.cchBuffer
= SizeofResource(hInst
, hrsrc
);
118 infoPtr
->hMMio
= mmioOpenW(NULL
, &mminfo
, MMIO_READ
);
121 FreeResource(infoPtr
->hRes
);
129 static BOOL
ANIMATE_LoadFileW(ANIMATE_INFO
*infoPtr
, LPWSTR lpName
)
131 infoPtr
->hMMio
= mmioOpenW(lpName
, 0, MMIO_ALLOCBUF
| MMIO_READ
| MMIO_DENYWRITE
);
133 if(!infoPtr
->hMMio
) return FALSE
;
138 static BOOL
ANIMATE_DoStop(ANIMATE_INFO
*infoPtr
)
140 BOOL stopped
= FALSE
;
142 EnterCriticalSection(&infoPtr
->cs
);
144 /* should stop playing */
145 if (infoPtr
->hThread
)
147 HANDLE handle
= infoPtr
->hThread
;
149 TRACE("stopping animation thread\n");
150 infoPtr
->hThread
= 0;
151 SetEvent( infoPtr
->hStopEvent
);
153 if (infoPtr
->threadId
!= GetCurrentThreadId())
155 LeaveCriticalSection(&infoPtr
->cs
); /* leave it a chance to run */
156 WaitForSingleObject( handle
, INFINITE
);
157 TRACE("animation thread stopped\n");
158 EnterCriticalSection(&infoPtr
->cs
);
161 CloseHandle( handle
);
162 CloseHandle( infoPtr
->hStopEvent
);
163 infoPtr
->hStopEvent
= 0;
166 if (infoPtr
->uTimer
) {
167 KillTimer(infoPtr
->hwndSelf
, infoPtr
->uTimer
);
172 LeaveCriticalSection(&infoPtr
->cs
);
175 ANIMATE_Notify(infoPtr
, ACN_STOP
);
181 static void ANIMATE_Free(ANIMATE_INFO
*infoPtr
)
185 ANIMATE_DoStop(infoPtr
);
186 mmioClose(infoPtr
->hMMio
, 0);
189 FreeResource(infoPtr
->hRes
);
192 heap_free (infoPtr
->lpIndex
);
193 infoPtr
->lpIndex
= NULL
;
196 fnIC
.fnICClose(infoPtr
->hic
);
199 heap_free (infoPtr
->inbih
);
200 infoPtr
->inbih
= NULL
;
201 heap_free (infoPtr
->outbih
);
202 infoPtr
->outbih
= NULL
;
203 heap_free (infoPtr
->indata
);
204 infoPtr
->indata
= NULL
;
205 heap_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
);
310 SetRect(&rect
, 0, 0, nWidth
, nHeight
);
312 if(!infoPtr
->hbrushBG
)
313 infoPtr
->hbrushBG
= GetCurrentObject(hDC
, OBJ_BRUSH
);
315 FillRect(hdcFinal
, &rect
, infoPtr
->hbrushBG
);
316 ANIMATE_TransparentBlt(infoPtr
, hdcFinal
, hdcMem
);
318 SelectObject(hdcFinal
, hbmOld2
);
319 SelectObject(hdcMem
, hbmFinal
);
321 DeleteObject(infoPtr
->hbmPrevFrame
);
322 infoPtr
->hbmPrevFrame
= hbmFinal
;
325 if (infoPtr
->dwStyle
& ACS_CENTER
)
329 GetWindowRect(infoPtr
->hwndSelf
, &rect
);
330 nOffsetX
= ((rect
.right
- rect
.left
) - nWidth
)/2;
331 nOffsetY
= ((rect
.bottom
- rect
.top
) - nHeight
)/2;
333 BitBlt(hDC
, nOffsetX
, nOffsetY
, nWidth
, nHeight
, hdcMem
, 0, 0, SRCCOPY
);
335 SelectObject(hdcMem
, hbmOld
);
340 static BOOL
ANIMATE_DrawFrame(ANIMATE_INFO
*infoPtr
, HDC hDC
)
342 TRACE("Drawing frame %d (loop %d)\n", infoPtr
->currFrame
, infoPtr
->nLoop
);
344 mmioSeek(infoPtr
->hMMio
, infoPtr
->lpIndex
[infoPtr
->currFrame
], SEEK_SET
);
345 mmioRead(infoPtr
->hMMio
, infoPtr
->indata
, infoPtr
->ash
.dwSuggestedBufferSize
);
348 fnIC
.fnICDecompress(infoPtr
->hic
, 0, infoPtr
->inbih
, infoPtr
->indata
,
349 infoPtr
->outbih
, infoPtr
->outdata
) != ICERR_OK
) {
350 WARN("Decompression error\n");
354 ANIMATE_PaintFrame(infoPtr
, hDC
);
356 if (infoPtr
->currFrame
++ >= infoPtr
->nToFrame
) {
357 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
358 if (infoPtr
->nLoop
!= -1) {
359 if (--infoPtr
->nLoop
== 0) {
360 ANIMATE_DoStop(infoPtr
);
368 static LRESULT
ANIMATE_Timer(ANIMATE_INFO
*infoPtr
)
372 if ((hDC
= GetDC(infoPtr
->hwndSelf
)) != 0)
374 EnterCriticalSection(&infoPtr
->cs
);
375 ANIMATE_DrawFrame(infoPtr
, hDC
);
376 LeaveCriticalSection(&infoPtr
->cs
);
378 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
384 static DWORD CALLBACK
ANIMATE_AnimationThread(LPVOID ptr_
)
386 ANIMATE_INFO
*infoPtr
= ptr_
;
392 HDC hDC
= GetDC(infoPtr
->hwndSelf
);
394 EnterCriticalSection(&infoPtr
->cs
);
395 ANIMATE_DrawFrame(infoPtr
, hDC
);
396 timeout
= infoPtr
->mah
.dwMicroSecPerFrame
;
397 event
= infoPtr
->hStopEvent
;
398 LeaveCriticalSection(&infoPtr
->cs
);
400 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
402 /* time is in microseconds, we should convert it to milliseconds */
403 if ((event
== 0) || WaitForSingleObject( event
, (timeout
+500)/1000) == WAIT_OBJECT_0
)
409 static LRESULT
ANIMATE_Play(ANIMATE_INFO
*infoPtr
, UINT cRepeat
, WORD wFrom
, WORD wTo
)
415 if (infoPtr
->hThread
|| infoPtr
->uTimer
) {
416 TRACE("Already playing\n");
420 infoPtr
->nFromFrame
= wFrom
;
421 infoPtr
->nToFrame
= wTo
;
422 infoPtr
->nLoop
= cRepeat
;
424 if (infoPtr
->nToFrame
== 0xFFFF)
425 infoPtr
->nToFrame
= infoPtr
->mah
.dwTotalFrames
- 1;
427 TRACE("(repeat=%d from=%d to=%d);\n",
428 infoPtr
->nLoop
, infoPtr
->nFromFrame
, infoPtr
->nToFrame
);
430 if (infoPtr
->nFromFrame
>= infoPtr
->mah
.dwTotalFrames
&&
431 (SHORT
)infoPtr
->nFromFrame
< 0)
432 infoPtr
->nFromFrame
= 0;
434 if (infoPtr
->nFromFrame
> infoPtr
->nToFrame
||
435 infoPtr
->nToFrame
>= infoPtr
->mah
.dwTotalFrames
)
438 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
440 /* seek - doesn't need to start a thread or set a timer and neither
441 * does it send a notification */
442 if (infoPtr
->nFromFrame
== infoPtr
->nToFrame
)
446 if ((hDC
= GetDC(infoPtr
->hwndSelf
)) != 0)
448 ANIMATE_DrawFrame(infoPtr
, hDC
);
450 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
455 if (infoPtr
->dwStyle
& ACS_TIMER
)
457 TRACE("Using a timer\n");
458 /* create a timer to display AVI */
459 infoPtr
->uTimer
= SetTimer(infoPtr
->hwndSelf
, 1,
460 infoPtr
->mah
.dwMicroSecPerFrame
/ 1000, NULL
);
464 TRACE("Using an animation thread\n");
465 infoPtr
->hStopEvent
= CreateEventW( NULL
, TRUE
, FALSE
, NULL
);
466 infoPtr
->hThread
= CreateThread(0, 0, ANIMATE_AnimationThread
,
467 infoPtr
, 0, &infoPtr
->threadId
);
468 if(!infoPtr
->hThread
) return FALSE
;
472 ANIMATE_Notify(infoPtr
, ACN_START
);
478 static BOOL
ANIMATE_GetAviInfo(ANIMATE_INFO
*infoPtr
)
487 if (mmioDescend(infoPtr
->hMMio
, &ckMainRIFF
, NULL
, 0) != 0) {
488 WARN("Can't find 'RIFF' chunk\n");
492 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) ||
493 (ckMainRIFF
.fccType
!= mmioFOURCC('A', 'V', 'I', ' '))) {
494 WARN("Can't find 'AVI ' chunk\n");
498 mmckHead
.fccType
= mmioFOURCC('h', 'd', 'r', 'l');
499 if (mmioDescend(infoPtr
->hMMio
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
500 WARN("Can't find 'hdrl' list\n");
504 mmckInfo
.ckid
= mmioFOURCC('a', 'v', 'i', 'h');
505 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
506 WARN("Can't find 'avih' chunk\n");
510 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->mah
, sizeof(infoPtr
->mah
));
512 TRACE("mah.dwMicroSecPerFrame=%d\n", infoPtr
->mah
.dwMicroSecPerFrame
);
513 TRACE("mah.dwMaxBytesPerSec=%d\n", infoPtr
->mah
.dwMaxBytesPerSec
);
514 TRACE("mah.dwPaddingGranularity=%d\n", infoPtr
->mah
.dwPaddingGranularity
);
515 TRACE("mah.dwFlags=%d\n", infoPtr
->mah
.dwFlags
);
516 TRACE("mah.dwTotalFrames=%d\n", infoPtr
->mah
.dwTotalFrames
);
517 TRACE("mah.dwInitialFrames=%d\n", infoPtr
->mah
.dwInitialFrames
);
518 TRACE("mah.dwStreams=%d\n", infoPtr
->mah
.dwStreams
);
519 TRACE("mah.dwSuggestedBufferSize=%d\n", infoPtr
->mah
.dwSuggestedBufferSize
);
520 TRACE("mah.dwWidth=%d\n", infoPtr
->mah
.dwWidth
);
521 TRACE("mah.dwHeight=%d\n", infoPtr
->mah
.dwHeight
);
523 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
525 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
526 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0) {
527 WARN("Can't find 'strl' list\n");
531 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'h');
532 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
533 WARN("Can't find 'strh' chunk\n");
537 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->ash
, sizeof(infoPtr
->ash
));
539 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccType
)),
540 HIBYTE(LOWORD(infoPtr
->ash
.fccType
)),
541 LOBYTE(HIWORD(infoPtr
->ash
.fccType
)),
542 HIBYTE(HIWORD(infoPtr
->ash
.fccType
)));
543 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
544 HIBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
545 LOBYTE(HIWORD(infoPtr
->ash
.fccHandler
)),
546 HIBYTE(HIWORD(infoPtr
->ash
.fccHandler
)));
547 TRACE("ash.dwFlags=%d\n", infoPtr
->ash
.dwFlags
);
548 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
549 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
550 TRACE("ash.dwInitialFrames=%d\n", infoPtr
->ash
.dwInitialFrames
);
551 TRACE("ash.dwScale=%d\n", infoPtr
->ash
.dwScale
);
552 TRACE("ash.dwRate=%d\n", infoPtr
->ash
.dwRate
);
553 TRACE("ash.dwStart=%d\n", infoPtr
->ash
.dwStart
);
554 TRACE("ash.dwLength=%d\n", infoPtr
->ash
.dwLength
);
555 TRACE("ash.dwSuggestedBufferSize=%d\n", infoPtr
->ash
.dwSuggestedBufferSize
);
556 TRACE("ash.dwQuality=%d\n", infoPtr
->ash
.dwQuality
);
557 TRACE("ash.dwSampleSize=%d\n", infoPtr
->ash
.dwSampleSize
);
558 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
559 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
561 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
563 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
564 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
565 WARN("Can't find 'strh' chunk\n");
569 infoPtr
->inbih
= heap_alloc_zero(mmckInfo
.cksize
);
570 if (!infoPtr
->inbih
) {
571 WARN("Can't alloc input BIH\n");
575 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
577 TRACE("bih.biSize=%d\n", infoPtr
->inbih
->biSize
);
578 TRACE("bih.biWidth=%d\n", infoPtr
->inbih
->biWidth
);
579 TRACE("bih.biHeight=%d\n", infoPtr
->inbih
->biHeight
);
580 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
581 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
582 TRACE("bih.biCompression=%d\n", infoPtr
->inbih
->biCompression
);
583 TRACE("bih.biSizeImage=%d\n", infoPtr
->inbih
->biSizeImage
);
584 TRACE("bih.biXPelsPerMeter=%d\n", infoPtr
->inbih
->biXPelsPerMeter
);
585 TRACE("bih.biYPelsPerMeter=%d\n", infoPtr
->inbih
->biYPelsPerMeter
);
586 TRACE("bih.biClrUsed=%d\n", infoPtr
->inbih
->biClrUsed
);
587 TRACE("bih.biClrImportant=%d\n", infoPtr
->inbih
->biClrImportant
);
589 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
591 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
594 /* an AVI has 0 or 1 video stream, and to be animated should not contain
595 * an audio stream, so only one strl is allowed
597 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
598 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
599 WARN("There should be a single 'strl' list\n");
604 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
606 /* no need to read optional JUNK chunk */
608 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
609 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
610 WARN("Can't find 'movi' list\n");
614 /* FIXME: should handle the 'rec ' LIST when present */
616 infoPtr
->lpIndex
= heap_alloc_zero(infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
617 if (!infoPtr
->lpIndex
)
620 numFrame
= insize
= 0;
621 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
622 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
623 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
624 if (insize
< mmckInfo
.cksize
)
625 insize
= mmckInfo
.cksize
;
627 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
629 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
) {
630 WARN("Found %d frames (/%d)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
633 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
) {
634 WARN("insize=%d suggestedSize=%d\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
635 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
638 infoPtr
->indata
= heap_alloc_zero(infoPtr
->ash
.dwSuggestedBufferSize
);
639 if (!infoPtr
->indata
)
646 static BOOL
ANIMATE_GetAviCodec(ANIMATE_INFO
*infoPtr
)
650 /* check uncompressed AVI */
651 if ((infoPtr
->ash
.fccHandler
== mmioFOURCC('D', 'I', 'B', ' ')) ||
652 (infoPtr
->ash
.fccHandler
== mmioFOURCC('R', 'L', 'E', ' ')) ||
653 (infoPtr
->ash
.fccHandler
== mmioFOURCC(0, 0, 0, 0)))
659 /* try to get a decompressor for that type */
660 infoPtr
->hic
= fnIC
.fnICOpen(ICTYPE_VIDEO
, infoPtr
->ash
.fccHandler
, ICMODE_DECOMPRESS
);
662 WARN("Can't load codec for the file\n");
666 outSize
= fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
667 (DWORD_PTR
)infoPtr
->inbih
, 0L);
669 infoPtr
->outbih
= heap_alloc_zero(outSize
);
670 if (!infoPtr
->outbih
)
673 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
674 (DWORD_PTR
)infoPtr
->inbih
, (DWORD_PTR
)infoPtr
->outbih
) != ICERR_OK
)
676 WARN("Can't get output BIH\n");
680 infoPtr
->outdata
= heap_alloc_zero(infoPtr
->outbih
->biSizeImage
);
681 if (!infoPtr
->outdata
)
684 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
685 (DWORD_PTR
)infoPtr
->inbih
, (DWORD_PTR
)infoPtr
->outbih
) != ICERR_OK
) {
686 WARN("Can't begin decompression\n");
694 static BOOL
ANIMATE_OpenW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPWSTR lpszName
)
698 ANIMATE_Free(infoPtr
);
702 TRACE("Closing avi.\n");
703 /* installer of thebat! v1.62 requires FALSE here */
704 return (infoPtr
->hMMio
!= 0);
708 hInstance
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
710 TRACE("(%s)\n", debugstr_w(lpszName
));
712 if (!IS_INTRESOURCE(lpszName
))
714 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
716 TRACE("No AVI resource found.\n");
717 if (!ANIMATE_LoadFileW(infoPtr
, lpszName
))
719 WARN("No AVI file found.\n");
726 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
728 WARN("No AVI resource found.\n");
733 if (!ANIMATE_GetAviInfo(infoPtr
))
735 WARN("Can't get AVI information\n");
736 ANIMATE_Free(infoPtr
);
740 if (!ANIMATE_GetAviCodec(infoPtr
))
742 WARN("Can't get AVI Codec\n");
743 ANIMATE_Free(infoPtr
);
747 hdc
= GetDC(infoPtr
->hwndSelf
);
748 /* native looks at the top left pixel of the first frame here too. */
749 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLORSTATIC
,
750 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
751 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
753 if (!(infoPtr
->dwStyle
& ACS_CENTER
))
754 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
755 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
757 if (infoPtr
->dwStyle
& ACS_AUTOPLAY
)
758 return ANIMATE_Play(infoPtr
, -1, 0, infoPtr
->mah
.dwTotalFrames
- 1);
764 static BOOL
ANIMATE_OpenA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPSTR lpszName
)
770 if (IS_INTRESOURCE(lpszName
))
771 return ANIMATE_OpenW(infoPtr
, hInstance
, (LPWSTR
)lpszName
);
773 len
= MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, NULL
, 0);
774 lpwszName
= heap_alloc(len
* sizeof(WCHAR
));
775 if (!lpwszName
) return FALSE
;
776 MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, lpwszName
, len
);
778 result
= ANIMATE_OpenW(infoPtr
, hInstance
, lpwszName
);
779 heap_free (lpwszName
);
784 static BOOL
ANIMATE_Stop(ANIMATE_INFO
*infoPtr
)
790 ANIMATE_DoStop(infoPtr
);
795 static BOOL
ANIMATE_Create(HWND hWnd
, const CREATESTRUCTW
*lpcs
)
797 static const WCHAR msvfw32W
[] = { 'm', 's', 'v', 'f', 'w', '3', '2', '.', 'd', 'l', 'l', 0 };
798 ANIMATE_INFO
*infoPtr
;
802 fnIC
.hModule
= LoadLibraryW(msvfw32W
);
803 if (!fnIC
.hModule
) return FALSE
;
805 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
806 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
807 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
808 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
811 /* allocate memory for info structure */
812 infoPtr
= heap_alloc_zero(sizeof(*infoPtr
));
813 if (!infoPtr
) return FALSE
;
815 /* store crossref hWnd <-> info structure */
816 SetWindowLongPtrW(hWnd
, 0, (DWORD_PTR
)infoPtr
);
817 infoPtr
->hwndSelf
= hWnd
;
818 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
819 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
820 infoPtr
->hbmPrevFrame
= 0;
821 infoPtr
->dwStyle
= lpcs
->style
;
823 TRACE("Animate style=0x%08x, parent=%p\n", infoPtr
->dwStyle
, infoPtr
->hwndNotify
);
825 InitializeCriticalSection(&infoPtr
->cs
);
826 infoPtr
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ANIMATE_INFO*->cs");
832 static LRESULT
ANIMATE_Destroy(ANIMATE_INFO
*infoPtr
)
835 ANIMATE_Free(infoPtr
);
837 /* free animate info data */
838 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
840 infoPtr
->cs
.DebugInfo
->Spare
[0] = 0;
841 DeleteCriticalSection(&infoPtr
->cs
);
848 static BOOL
ANIMATE_EraseBackground(ANIMATE_INFO
const *infoPtr
, HDC hdc
)
853 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLORSTATIC
,
854 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
855 GetClientRect(infoPtr
->hwndSelf
, &rect
);
856 FillRect(hdc
, &rect
, hBrush
? hBrush
: GetCurrentObject(hdc
, OBJ_BRUSH
));
862 static LRESULT
ANIMATE_StyleChanged(ANIMATE_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
864 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
865 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
867 if (wStyleType
!= GWL_STYLE
) return 0;
869 infoPtr
->dwStyle
= lpss
->styleNew
;
871 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
876 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
878 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)GetWindowLongPtrW(hWnd
, 0);
880 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hWnd
, uMsg
, wParam
, lParam
);
881 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
882 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
886 return ANIMATE_OpenA(infoPtr
, (HINSTANCE
)wParam
, (LPSTR
)lParam
);
889 return ANIMATE_OpenW(infoPtr
, (HINSTANCE
)wParam
, (LPWSTR
)lParam
);
892 return ANIMATE_Play(infoPtr
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
895 return ANIMATE_Stop(infoPtr
);
898 ANIMATE_Free(infoPtr
);
902 return ANIMATE_Create(hWnd
, (LPCREATESTRUCTW
)lParam
);
905 return HTTRANSPARENT
;
908 return ANIMATE_Destroy(infoPtr
);
911 return ANIMATE_EraseBackground(infoPtr
, (HDC
)wParam
);
913 case WM_STYLECHANGED
:
914 return ANIMATE_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
917 return ANIMATE_Timer(infoPtr
);
922 /* the animation has not decompressed
923 * (and displayed) the first frame yet, don't paint
925 if (!infoPtr
->hbmPrevFrame
)
927 /* default paint handling */
928 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
933 EnterCriticalSection(&infoPtr
->cs
);
934 ANIMATE_PaintFrame(infoPtr
, (HDC
)wParam
);
935 LeaveCriticalSection(&infoPtr
->cs
);
940 HDC hDC
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
942 EnterCriticalSection(&infoPtr
->cs
);
943 ANIMATE_PaintFrame(infoPtr
, hDC
);
944 LeaveCriticalSection(&infoPtr
->cs
);
946 EndPaint(infoPtr
->hwndSelf
, &ps
);
952 if (infoPtr
->dwStyle
& ACS_CENTER
)
953 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
954 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
957 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
958 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
960 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
965 void ANIMATE_Register(void)
969 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
970 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
971 wndClass
.lpfnWndProc
= ANIMATE_WindowProc
;
972 wndClass
.cbClsExtra
= 0;
973 wndClass
.cbWndExtra
= sizeof(ANIMATE_INFO
*);
974 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
975 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
976 wndClass
.lpszClassName
= ANIMATE_CLASSW
;
978 RegisterClassW(&wndClass
);
982 void ANIMATE_Unregister(void)
984 UnregisterClassW(ANIMATE_CLASSW
, NULL
);