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"
40 WINE_DEFAULT_DEBUG_CHANNEL(animate
);
44 HIC (WINAPI
*fnICOpen
)(DWORD
, DWORD
, UINT
);
45 LRESULT (WINAPI
*fnICClose
)(HIC
);
46 LRESULT (WINAPI
*fnICSendMessage
)(HIC
, UINT
, DWORD_PTR
, DWORD_PTR
);
47 DWORD (WINAPIV
*fnICDecompress
)(HIC
,DWORD
,LPBITMAPINFOHEADER
,LPVOID
,LPBITMAPINFOHEADER
,LPVOID
);
52 /* reference to input stream (file or resource) */
54 HMMIO hMMio
; /* handle to mmio stream */
58 /* information on the loaded AVI file */
61 LPBITMAPINFOHEADER inbih
;
63 /* data for the decompressor */
65 LPBITMAPINFOHEADER outbih
;
68 /* data for the background mechanism */
74 /* data for playing the file */
79 /* transparency info*/
80 COLORREF transparentColor
;
85 #define ANIMATE_COLOR_NONE 0xffffffff
87 static void ANIMATE_Notify(const ANIMATE_INFO
*infoPtr
, UINT notif
)
89 PostMessageW(infoPtr
->hwndNotify
, WM_COMMAND
,
90 MAKEWPARAM(GetDlgCtrlID(infoPtr
->hwndSelf
), notif
),
91 (LPARAM
)infoPtr
->hwndSelf
);
94 static BOOL
ANIMATE_LoadResW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInst
, LPCWSTR lpName
)
100 hrsrc
= FindResourceW(hInst
, lpName
, L
"AVI");
104 infoPtr
->hRes
= LoadResource(hInst
, hrsrc
);
108 lpAvi
= LockResource(infoPtr
->hRes
);
112 memset(&mminfo
, 0, sizeof(mminfo
));
113 mminfo
.fccIOProc
= FOURCC_MEM
;
114 mminfo
.pchBuffer
= lpAvi
;
115 mminfo
.cchBuffer
= SizeofResource(hInst
, hrsrc
);
116 infoPtr
->hMMio
= mmioOpenW(NULL
, &mminfo
, MMIO_READ
);
119 FreeResource(infoPtr
->hRes
);
127 static BOOL
ANIMATE_LoadFileW(ANIMATE_INFO
*infoPtr
, LPWSTR lpName
)
129 infoPtr
->hMMio
= mmioOpenW(lpName
, 0, MMIO_ALLOCBUF
| MMIO_READ
| MMIO_DENYWRITE
);
131 if(!infoPtr
->hMMio
) return FALSE
;
136 static BOOL
ANIMATE_DoStop(ANIMATE_INFO
*infoPtr
)
138 BOOL stopped
= FALSE
;
140 EnterCriticalSection(&infoPtr
->cs
);
142 /* should stop playing */
143 if (infoPtr
->hThread
)
145 HANDLE handle
= infoPtr
->hThread
;
147 TRACE("stopping animation thread\n");
148 infoPtr
->hThread
= 0;
149 SetEvent( infoPtr
->hStopEvent
);
151 if (infoPtr
->threadId
!= GetCurrentThreadId())
153 LeaveCriticalSection(&infoPtr
->cs
); /* leave it a chance to run */
154 WaitForSingleObject( handle
, INFINITE
);
155 TRACE("animation thread stopped\n");
156 EnterCriticalSection(&infoPtr
->cs
);
159 CloseHandle( handle
);
160 CloseHandle( infoPtr
->hStopEvent
);
161 infoPtr
->hStopEvent
= 0;
164 if (infoPtr
->uTimer
) {
165 KillTimer(infoPtr
->hwndSelf
, infoPtr
->uTimer
);
170 LeaveCriticalSection(&infoPtr
->cs
);
173 ANIMATE_Notify(infoPtr
, ACN_STOP
);
179 static void ANIMATE_Free(ANIMATE_INFO
*infoPtr
)
183 ANIMATE_DoStop(infoPtr
);
184 mmioClose(infoPtr
->hMMio
, 0);
187 FreeResource(infoPtr
->hRes
);
190 Free (infoPtr
->lpIndex
);
191 infoPtr
->lpIndex
= NULL
;
194 fnIC
.fnICClose(infoPtr
->hic
);
197 Free (infoPtr
->inbih
);
198 infoPtr
->inbih
= NULL
;
199 Free (infoPtr
->outbih
);
200 infoPtr
->outbih
= NULL
;
201 Free (infoPtr
->indata
);
202 infoPtr
->indata
= NULL
;
203 Free (infoPtr
->outdata
);
204 infoPtr
->outdata
= NULL
;
205 if (infoPtr
->hbmPrevFrame
)
207 DeleteObject(infoPtr
->hbmPrevFrame
);
208 infoPtr
->hbmPrevFrame
= 0;
211 memset(&infoPtr
->mah
, 0, sizeof(infoPtr
->mah
));
212 memset(&infoPtr
->ash
, 0, sizeof(infoPtr
->ash
));
213 infoPtr
->nFromFrame
= infoPtr
->nToFrame
= infoPtr
->nLoop
= infoPtr
->currFrame
= 0;
215 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
218 static void ANIMATE_TransparentBlt(ANIMATE_INFO
const *infoPtr
, HDC hdcDest
, HDC hdcSource
)
224 /* create a transparency mask */
225 hdcMask
= CreateCompatibleDC(hdcDest
);
226 hbmMask
= CreateBitmap(infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, 1,1,NULL
);
227 hbmOld
= SelectObject(hdcMask
, hbmMask
);
229 SetBkColor(hdcSource
,infoPtr
->transparentColor
);
230 BitBlt(hdcMask
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCCOPY
);
232 /* mask the source bitmap */
233 SetBkColor(hdcSource
, RGB(0,0,0));
234 SetTextColor(hdcSource
, RGB(255,255,255));
235 BitBlt(hdcSource
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
237 /* mask the destination bitmap */
238 SetBkColor(hdcDest
, RGB(255,255,255));
239 SetTextColor(hdcDest
, RGB(0,0,0));
240 BitBlt(hdcDest
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
242 /* combine source and destination */
243 BitBlt(hdcDest
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCPAINT
);
245 SelectObject(hdcMask
, hbmOld
);
246 DeleteObject(hbmMask
);
250 static BOOL
ANIMATE_PaintFrame(ANIMATE_INFO
* infoPtr
, HDC hDC
)
252 void const *pBitmapData
;
253 BITMAPINFO
const *pBitmapInfo
;
261 if (!hDC
|| !infoPtr
->inbih
)
266 pBitmapData
= infoPtr
->outdata
;
267 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->outbih
;
269 nWidth
= infoPtr
->outbih
->biWidth
;
270 nHeight
= infoPtr
->outbih
->biHeight
;
274 pBitmapData
= infoPtr
->indata
;
275 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->inbih
;
277 nWidth
= infoPtr
->inbih
->biWidth
;
278 nHeight
= infoPtr
->inbih
->biHeight
;
281 if(!infoPtr
->hbmPrevFrame
)
283 infoPtr
->hbmPrevFrame
=CreateCompatibleBitmap(hDC
, nWidth
,nHeight
);
286 hdcMem
= CreateCompatibleDC(hDC
);
287 hbmOld
= SelectObject(hdcMem
, infoPtr
->hbmPrevFrame
);
289 SetDIBits(hdcMem
, infoPtr
->hbmPrevFrame
, 0, nHeight
, pBitmapData
, pBitmapInfo
, DIB_RGB_COLORS
);
292 * we need to get the transparent color even without ACS_TRANSPARENT,
293 * because the style can be changed later on and the color should always
294 * be obtained in the first frame
296 if(infoPtr
->transparentColor
== ANIMATE_COLOR_NONE
)
298 infoPtr
->transparentColor
= GetPixel(hdcMem
,0,0);
301 if(infoPtr
->dwStyle
& ACS_TRANSPARENT
)
303 HDC hdcFinal
= CreateCompatibleDC(hDC
);
304 HBITMAP hbmFinal
= CreateCompatibleBitmap(hDC
,nWidth
, nHeight
);
305 HBITMAP hbmOld2
= SelectObject(hdcFinal
, hbmFinal
);
308 SetRect(&rect
, 0, 0, nWidth
, nHeight
);
310 if(!infoPtr
->hbrushBG
)
311 infoPtr
->hbrushBG
= GetCurrentObject(hDC
, OBJ_BRUSH
);
313 FillRect(hdcFinal
, &rect
, infoPtr
->hbrushBG
);
314 ANIMATE_TransparentBlt(infoPtr
, hdcFinal
, hdcMem
);
316 SelectObject(hdcFinal
, hbmOld2
);
317 SelectObject(hdcMem
, hbmFinal
);
319 DeleteObject(infoPtr
->hbmPrevFrame
);
320 infoPtr
->hbmPrevFrame
= hbmFinal
;
323 if (infoPtr
->dwStyle
& ACS_CENTER
)
327 GetWindowRect(infoPtr
->hwndSelf
, &rect
);
328 nOffsetX
= ((rect
.right
- rect
.left
) - nWidth
)/2;
329 nOffsetY
= ((rect
.bottom
- rect
.top
) - nHeight
)/2;
331 BitBlt(hDC
, nOffsetX
, nOffsetY
, nWidth
, nHeight
, hdcMem
, 0, 0, SRCCOPY
);
333 SelectObject(hdcMem
, hbmOld
);
338 static BOOL
ANIMATE_DrawFrame(ANIMATE_INFO
*infoPtr
, HDC hDC
)
340 TRACE("Drawing frame %d (loop %d)\n", infoPtr
->currFrame
, infoPtr
->nLoop
);
342 mmioSeek(infoPtr
->hMMio
, infoPtr
->lpIndex
[infoPtr
->currFrame
], SEEK_SET
);
343 mmioRead(infoPtr
->hMMio
, infoPtr
->indata
, infoPtr
->ash
.dwSuggestedBufferSize
);
346 fnIC
.fnICDecompress(infoPtr
->hic
, 0, infoPtr
->inbih
, infoPtr
->indata
,
347 infoPtr
->outbih
, infoPtr
->outdata
) != ICERR_OK
) {
348 WARN("Decompression error\n");
352 ANIMATE_PaintFrame(infoPtr
, hDC
);
354 if (infoPtr
->currFrame
++ >= infoPtr
->nToFrame
) {
355 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
356 if (infoPtr
->nLoop
!= -1) {
357 if (--infoPtr
->nLoop
== 0) {
358 ANIMATE_DoStop(infoPtr
);
366 static LRESULT
ANIMATE_Timer(ANIMATE_INFO
*infoPtr
)
370 if ((hDC
= GetDC(infoPtr
->hwndSelf
)) != 0)
372 EnterCriticalSection(&infoPtr
->cs
);
373 ANIMATE_DrawFrame(infoPtr
, hDC
);
374 LeaveCriticalSection(&infoPtr
->cs
);
376 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
382 static DWORD CALLBACK
ANIMATE_AnimationThread(LPVOID ptr_
)
384 ANIMATE_INFO
*infoPtr
= ptr_
;
390 HDC hDC
= GetDC(infoPtr
->hwndSelf
);
392 EnterCriticalSection(&infoPtr
->cs
);
393 ANIMATE_DrawFrame(infoPtr
, hDC
);
394 timeout
= infoPtr
->mah
.dwMicroSecPerFrame
;
395 event
= infoPtr
->hStopEvent
;
396 LeaveCriticalSection(&infoPtr
->cs
);
398 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
400 /* time is in microseconds, we should convert it to milliseconds */
401 if ((event
== 0) || WaitForSingleObject( event
, (timeout
+500)/1000) == WAIT_OBJECT_0
)
407 static LRESULT
ANIMATE_Play(ANIMATE_INFO
*infoPtr
, UINT cRepeat
, WORD wFrom
, WORD wTo
)
413 if (infoPtr
->hThread
|| infoPtr
->uTimer
) {
414 TRACE("Already playing\n");
418 infoPtr
->nFromFrame
= wFrom
;
419 infoPtr
->nToFrame
= wTo
;
420 infoPtr
->nLoop
= cRepeat
;
422 if (infoPtr
->nToFrame
== 0xFFFF)
423 infoPtr
->nToFrame
= infoPtr
->mah
.dwTotalFrames
- 1;
425 TRACE("(repeat=%d from=%d to=%d);\n",
426 infoPtr
->nLoop
, infoPtr
->nFromFrame
, infoPtr
->nToFrame
);
428 if (infoPtr
->nFromFrame
>= infoPtr
->mah
.dwTotalFrames
&&
429 (SHORT
)infoPtr
->nFromFrame
< 0)
430 infoPtr
->nFromFrame
= 0;
432 if (infoPtr
->nFromFrame
> infoPtr
->nToFrame
||
433 infoPtr
->nToFrame
>= infoPtr
->mah
.dwTotalFrames
)
436 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
438 /* seek - doesn't need to start a thread or set a timer and neither
439 * does it send a notification */
440 if (infoPtr
->nFromFrame
== infoPtr
->nToFrame
)
444 if ((hDC
= GetDC(infoPtr
->hwndSelf
)) != 0)
446 ANIMATE_DrawFrame(infoPtr
, hDC
);
448 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
453 if (infoPtr
->dwStyle
& ACS_TIMER
)
455 TRACE("Using a timer\n");
456 /* create a timer to display AVI */
457 infoPtr
->uTimer
= SetTimer(infoPtr
->hwndSelf
, 1,
458 infoPtr
->mah
.dwMicroSecPerFrame
/ 1000, NULL
);
462 TRACE("Using an animation thread\n");
463 infoPtr
->hStopEvent
= CreateEventW( NULL
, TRUE
, FALSE
, NULL
);
464 infoPtr
->hThread
= CreateThread(0, 0, ANIMATE_AnimationThread
,
465 infoPtr
, 0, &infoPtr
->threadId
);
466 if(!infoPtr
->hThread
) return FALSE
;
470 ANIMATE_Notify(infoPtr
, ACN_START
);
476 static BOOL
ANIMATE_GetAviInfo(ANIMATE_INFO
*infoPtr
)
485 if (mmioDescend(infoPtr
->hMMio
, &ckMainRIFF
, NULL
, 0) != 0) {
486 WARN("Can't find 'RIFF' chunk\n");
490 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) ||
491 (ckMainRIFF
.fccType
!= mmioFOURCC('A', 'V', 'I', ' '))) {
492 WARN("Can't find 'AVI ' chunk\n");
496 mmckHead
.fccType
= mmioFOURCC('h', 'd', 'r', 'l');
497 if (mmioDescend(infoPtr
->hMMio
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
498 WARN("Can't find 'hdrl' list\n");
502 mmckInfo
.ckid
= mmioFOURCC('a', 'v', 'i', 'h');
503 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
504 WARN("Can't find 'avih' chunk\n");
508 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->mah
, sizeof(infoPtr
->mah
));
510 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr
->mah
.dwMicroSecPerFrame
);
511 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr
->mah
.dwMaxBytesPerSec
);
512 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr
->mah
.dwPaddingGranularity
);
513 TRACE("mah.dwFlags=%ld\n", infoPtr
->mah
.dwFlags
);
514 TRACE("mah.dwTotalFrames=%ld\n", infoPtr
->mah
.dwTotalFrames
);
515 TRACE("mah.dwInitialFrames=%ld\n", infoPtr
->mah
.dwInitialFrames
);
516 TRACE("mah.dwStreams=%ld\n", infoPtr
->mah
.dwStreams
);
517 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr
->mah
.dwSuggestedBufferSize
);
518 TRACE("mah.dwWidth=%ld\n", infoPtr
->mah
.dwWidth
);
519 TRACE("mah.dwHeight=%ld\n", infoPtr
->mah
.dwHeight
);
521 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
523 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
524 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0) {
525 WARN("Can't find 'strl' list\n");
529 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'h');
530 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
531 WARN("Can't find 'strh' chunk\n");
535 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->ash
, sizeof(infoPtr
->ash
));
537 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccType
)),
538 HIBYTE(LOWORD(infoPtr
->ash
.fccType
)),
539 LOBYTE(HIWORD(infoPtr
->ash
.fccType
)),
540 HIBYTE(HIWORD(infoPtr
->ash
.fccType
)));
541 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
542 HIBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
543 LOBYTE(HIWORD(infoPtr
->ash
.fccHandler
)),
544 HIBYTE(HIWORD(infoPtr
->ash
.fccHandler
)));
545 TRACE("ash.dwFlags=%ld\n", infoPtr
->ash
.dwFlags
);
546 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
547 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
548 TRACE("ash.dwInitialFrames=%ld\n", infoPtr
->ash
.dwInitialFrames
);
549 TRACE("ash.dwScale=%ld\n", infoPtr
->ash
.dwScale
);
550 TRACE("ash.dwRate=%ld\n", infoPtr
->ash
.dwRate
);
551 TRACE("ash.dwStart=%ld\n", infoPtr
->ash
.dwStart
);
552 TRACE("ash.dwLength=%lu\n", infoPtr
->ash
.dwLength
);
553 TRACE("ash.dwSuggestedBufferSize=%lu\n", infoPtr
->ash
.dwSuggestedBufferSize
);
554 TRACE("ash.dwQuality=%lu\n", infoPtr
->ash
.dwQuality
);
555 TRACE("ash.dwSampleSize=%lu\n", infoPtr
->ash
.dwSampleSize
);
556 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
557 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
559 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
561 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
562 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
563 WARN("Can't find 'strh' chunk\n");
567 infoPtr
->inbih
= Alloc(mmckInfo
.cksize
);
568 if (!infoPtr
->inbih
) {
569 WARN("Can't alloc input BIH\n");
573 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
575 TRACE("bih.biSize=%lu\n", infoPtr
->inbih
->biSize
);
576 TRACE("bih.biWidth=%ld\n", infoPtr
->inbih
->biWidth
);
577 TRACE("bih.biHeight=%ld\n", infoPtr
->inbih
->biHeight
);
578 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
579 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
580 TRACE("bih.biCompression=%lu\n", infoPtr
->inbih
->biCompression
);
581 TRACE("bih.biSizeImage=%lu\n", infoPtr
->inbih
->biSizeImage
);
582 TRACE("bih.biXPelsPerMeter=%lu\n", infoPtr
->inbih
->biXPelsPerMeter
);
583 TRACE("bih.biYPelsPerMeter=%lu\n", infoPtr
->inbih
->biYPelsPerMeter
);
584 TRACE("bih.biClrUsed=%lu\n", infoPtr
->inbih
->biClrUsed
);
585 TRACE("bih.biClrImportant=%lu\n", infoPtr
->inbih
->biClrImportant
);
587 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
589 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
592 /* an AVI has 0 or 1 video stream, and to be animated should not contain
593 * an audio stream, so only one strl is allowed
595 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
596 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
597 WARN("There should be a single 'strl' list\n");
602 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
604 /* no need to read optional JUNK chunk */
606 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
607 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
608 WARN("Can't find 'movi' list\n");
612 /* FIXME: should handle the 'rec ' LIST when present */
614 infoPtr
->lpIndex
= Alloc(infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
615 if (!infoPtr
->lpIndex
)
618 numFrame
= insize
= 0;
619 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
620 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
621 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
622 if (insize
< mmckInfo
.cksize
)
623 insize
= mmckInfo
.cksize
;
625 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
627 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
)
629 WARN("Found %lu frames (/%lu)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
632 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
)
634 WARN("insize %lu suggestedSize %lu\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
635 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
638 infoPtr
->indata
= Alloc(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 if (!(infoPtr
->outbih
= Alloc(outSize
)))
672 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
673 (DWORD_PTR
)infoPtr
->inbih
, (DWORD_PTR
)infoPtr
->outbih
) != ICERR_OK
)
675 WARN("Can't get output BIH\n");
679 if (!(infoPtr
->outdata
= Alloc(infoPtr
->outbih
->biSizeImage
)))
682 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
683 (DWORD_PTR
)infoPtr
->inbih
, (DWORD_PTR
)infoPtr
->outbih
) != ICERR_OK
) {
684 WARN("Can't begin decompression\n");
692 static BOOL
ANIMATE_OpenW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPWSTR lpszName
)
696 ANIMATE_Free(infoPtr
);
700 TRACE("Closing avi.\n");
701 /* installer of thebat! v1.62 requires FALSE here */
702 return (infoPtr
->hMMio
!= 0);
706 hInstance
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
708 TRACE("(%s)\n", debugstr_w(lpszName
));
710 if (!IS_INTRESOURCE(lpszName
))
712 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
714 TRACE("No AVI resource found.\n");
715 if (!ANIMATE_LoadFileW(infoPtr
, lpszName
))
717 WARN("No AVI file found.\n");
724 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
726 WARN("No AVI resource found.\n");
731 if (!ANIMATE_GetAviInfo(infoPtr
))
733 WARN("Can't get AVI information\n");
734 ANIMATE_Free(infoPtr
);
738 if (!ANIMATE_GetAviCodec(infoPtr
))
740 WARN("Can't get AVI Codec\n");
741 ANIMATE_Free(infoPtr
);
745 hdc
= GetDC(infoPtr
->hwndSelf
);
746 /* native looks at the top left pixel of the first frame here too. */
747 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLORSTATIC
,
748 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
749 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
751 if (!(infoPtr
->dwStyle
& ACS_CENTER
))
752 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
753 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
755 if (infoPtr
->dwStyle
& ACS_AUTOPLAY
)
756 return ANIMATE_Play(infoPtr
, -1, 0, infoPtr
->mah
.dwTotalFrames
- 1);
762 static BOOL
ANIMATE_OpenA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPSTR lpszName
)
768 if (IS_INTRESOURCE(lpszName
))
769 return ANIMATE_OpenW(infoPtr
, hInstance
, (LPWSTR
)lpszName
);
771 len
= MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, NULL
, 0);
772 lpwszName
= Alloc(len
* sizeof(WCHAR
));
773 if (!lpwszName
) return FALSE
;
774 MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, lpwszName
, len
);
776 result
= ANIMATE_OpenW(infoPtr
, hInstance
, lpwszName
);
782 static BOOL
ANIMATE_Stop(ANIMATE_INFO
*infoPtr
)
788 ANIMATE_DoStop(infoPtr
);
793 static BOOL
ANIMATE_Create(HWND hWnd
, const CREATESTRUCTW
*lpcs
)
795 ANIMATE_INFO
*infoPtr
;
799 fnIC
.hModule
= LoadLibraryW(L
"msvfw32.dll");
800 if (!fnIC
.hModule
) return FALSE
;
802 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
803 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
804 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
805 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
808 /* allocate memory for info structure */
809 infoPtr
= Alloc(sizeof(*infoPtr
));
810 if (!infoPtr
) return FALSE
;
812 /* store crossref hWnd <-> info structure */
813 SetWindowLongPtrW(hWnd
, 0, (DWORD_PTR
)infoPtr
);
814 infoPtr
->hwndSelf
= hWnd
;
815 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
816 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
817 infoPtr
->hbmPrevFrame
= 0;
818 infoPtr
->dwStyle
= lpcs
->style
;
820 TRACE("Animate style %#lx, parent %p\n", infoPtr
->dwStyle
, infoPtr
->hwndNotify
);
822 InitializeCriticalSection(&infoPtr
->cs
);
823 infoPtr
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ANIMATE_INFO*->cs");
829 static LRESULT
ANIMATE_Destroy(ANIMATE_INFO
*infoPtr
)
832 ANIMATE_Free(infoPtr
);
834 /* free animate info data */
835 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
837 infoPtr
->cs
.DebugInfo
->Spare
[0] = 0;
838 DeleteCriticalSection(&infoPtr
->cs
);
845 static BOOL
ANIMATE_EraseBackground(ANIMATE_INFO
const *infoPtr
, HDC hdc
)
850 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLORSTATIC
,
851 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
852 GetClientRect(infoPtr
->hwndSelf
, &rect
);
853 FillRect(hdc
, &rect
, hBrush
? hBrush
: GetCurrentObject(hdc
, OBJ_BRUSH
));
859 static LRESULT
ANIMATE_StyleChanged(ANIMATE_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
861 TRACE("%#Ix, styleOld %#lx, styleNew %#lx.\n", wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
863 if (wStyleType
!= GWL_STYLE
) return 0;
865 infoPtr
->dwStyle
= lpss
->styleNew
;
870 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
872 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)GetWindowLongPtrW(hWnd
, 0);
874 TRACE("hwnd %p, msg %x, wparam %#Ix, lparam %#Ix.\n", hWnd
, uMsg
, wParam
, lParam
);
876 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
877 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
881 return ANIMATE_OpenA(infoPtr
, (HINSTANCE
)wParam
, (LPSTR
)lParam
);
884 return ANIMATE_OpenW(infoPtr
, (HINSTANCE
)wParam
, (LPWSTR
)lParam
);
887 return ANIMATE_Play(infoPtr
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
890 return ANIMATE_Stop(infoPtr
);
893 ANIMATE_Free(infoPtr
);
897 return ANIMATE_Create(hWnd
, (LPCREATESTRUCTW
)lParam
);
900 return HTTRANSPARENT
;
903 return ANIMATE_Destroy(infoPtr
);
906 return ANIMATE_EraseBackground(infoPtr
, (HDC
)wParam
);
908 case WM_STYLECHANGED
:
909 return ANIMATE_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
912 return ANIMATE_Timer(infoPtr
);
917 /* the animation has not decompressed
918 * (and displayed) the first frame yet, don't paint
920 if (!infoPtr
->hbmPrevFrame
)
922 /* default paint handling */
923 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
928 EnterCriticalSection(&infoPtr
->cs
);
929 ANIMATE_PaintFrame(infoPtr
, (HDC
)wParam
);
930 LeaveCriticalSection(&infoPtr
->cs
);
935 HDC hDC
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
937 EnterCriticalSection(&infoPtr
->cs
);
938 ANIMATE_PaintFrame(infoPtr
, hDC
);
939 LeaveCriticalSection(&infoPtr
->cs
);
941 EndPaint(infoPtr
->hwndSelf
, &ps
);
947 if (infoPtr
->dwStyle
& ACS_CENTER
)
948 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
949 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
952 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
953 ERR("unknown msg %#x, wp %#Ix, lp %#Ix.\n", uMsg
, wParam
, lParam
);
955 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
960 void ANIMATE_Register(void)
964 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
965 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
966 wndClass
.lpfnWndProc
= ANIMATE_WindowProc
;
967 wndClass
.cbClsExtra
= 0;
968 wndClass
.cbWndExtra
= sizeof(ANIMATE_INFO
*);
969 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
970 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
971 wndClass
.lpszClassName
= ANIMATE_CLASSW
;
973 RegisterClassW(&wndClass
);
977 void ANIMATE_Unregister(void)
979 UnregisterClassW(ANIMATE_CLASSW
, NULL
);