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=%s\n", debugstr_fourcc(infoPtr
->ash
.fccType
));
538 TRACE("ash.fccHandler=%s\n", debugstr_fourcc(infoPtr
->ash
.fccHandler
));
539 TRACE("ash.dwFlags=%ld\n", infoPtr
->ash
.dwFlags
);
540 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
541 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
542 TRACE("ash.dwInitialFrames=%ld\n", infoPtr
->ash
.dwInitialFrames
);
543 TRACE("ash.dwScale=%ld\n", infoPtr
->ash
.dwScale
);
544 TRACE("ash.dwRate=%ld\n", infoPtr
->ash
.dwRate
);
545 TRACE("ash.dwStart=%ld\n", infoPtr
->ash
.dwStart
);
546 TRACE("ash.dwLength=%lu\n", infoPtr
->ash
.dwLength
);
547 TRACE("ash.dwSuggestedBufferSize=%lu\n", infoPtr
->ash
.dwSuggestedBufferSize
);
548 TRACE("ash.dwQuality=%lu\n", infoPtr
->ash
.dwQuality
);
549 TRACE("ash.dwSampleSize=%lu\n", infoPtr
->ash
.dwSampleSize
);
550 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
551 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
553 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
555 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
556 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
557 WARN("Can't find 'strh' chunk\n");
561 infoPtr
->inbih
= Alloc(mmckInfo
.cksize
);
562 if (!infoPtr
->inbih
) {
563 WARN("Can't alloc input BIH\n");
567 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
569 TRACE("bih.biSize=%lu\n", infoPtr
->inbih
->biSize
);
570 TRACE("bih.biWidth=%ld\n", infoPtr
->inbih
->biWidth
);
571 TRACE("bih.biHeight=%ld\n", infoPtr
->inbih
->biHeight
);
572 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
573 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
574 TRACE("bih.biCompression=%lu\n", infoPtr
->inbih
->biCompression
);
575 TRACE("bih.biSizeImage=%lu\n", infoPtr
->inbih
->biSizeImage
);
576 TRACE("bih.biXPelsPerMeter=%lu\n", infoPtr
->inbih
->biXPelsPerMeter
);
577 TRACE("bih.biYPelsPerMeter=%lu\n", infoPtr
->inbih
->biYPelsPerMeter
);
578 TRACE("bih.biClrUsed=%lu\n", infoPtr
->inbih
->biClrUsed
);
579 TRACE("bih.biClrImportant=%lu\n", infoPtr
->inbih
->biClrImportant
);
581 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
583 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
586 /* an AVI has 0 or 1 video stream, and to be animated should not contain
587 * an audio stream, so only one strl is allowed
589 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
590 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
591 WARN("There should be a single 'strl' list\n");
596 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
598 /* no need to read optional JUNK chunk */
600 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
601 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
602 WARN("Can't find 'movi' list\n");
606 /* FIXME: should handle the 'rec ' LIST when present */
608 infoPtr
->lpIndex
= Alloc(infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
609 if (!infoPtr
->lpIndex
)
612 numFrame
= insize
= 0;
613 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
614 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
615 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
616 if (insize
< mmckInfo
.cksize
)
617 insize
= mmckInfo
.cksize
;
619 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
621 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
)
623 WARN("Found %lu frames (/%lu)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
626 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
)
628 WARN("insize %lu suggestedSize %lu\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
629 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
632 infoPtr
->indata
= Alloc(infoPtr
->ash
.dwSuggestedBufferSize
);
633 if (!infoPtr
->indata
)
640 static BOOL
ANIMATE_GetAviCodec(ANIMATE_INFO
*infoPtr
)
644 /* check uncompressed AVI */
645 if ((infoPtr
->ash
.fccHandler
== mmioFOURCC('D', 'I', 'B', ' ')) ||
646 (infoPtr
->ash
.fccHandler
== mmioFOURCC('R', 'L', 'E', ' ')) ||
647 (infoPtr
->ash
.fccHandler
== mmioFOURCC(0, 0, 0, 0)))
653 /* try to get a decompressor for that type */
654 infoPtr
->hic
= fnIC
.fnICOpen(ICTYPE_VIDEO
, infoPtr
->ash
.fccHandler
, ICMODE_DECOMPRESS
);
656 WARN("Can't load codec for the file\n");
660 outSize
= fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
661 (DWORD_PTR
)infoPtr
->inbih
, 0L);
663 if (!(infoPtr
->outbih
= Alloc(outSize
)))
666 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
667 (DWORD_PTR
)infoPtr
->inbih
, (DWORD_PTR
)infoPtr
->outbih
) != ICERR_OK
)
669 WARN("Can't get output BIH\n");
673 if (!(infoPtr
->outdata
= Alloc(infoPtr
->outbih
->biSizeImage
)))
676 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
677 (DWORD_PTR
)infoPtr
->inbih
, (DWORD_PTR
)infoPtr
->outbih
) != ICERR_OK
) {
678 WARN("Can't begin decompression\n");
686 static BOOL
ANIMATE_OpenW(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPWSTR lpszName
)
690 ANIMATE_Free(infoPtr
);
694 TRACE("Closing avi.\n");
695 /* installer of thebat! v1.62 requires FALSE here */
696 return (infoPtr
->hMMio
!= 0);
700 hInstance
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
702 TRACE("(%s)\n", debugstr_w(lpszName
));
704 if (!IS_INTRESOURCE(lpszName
))
706 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
708 TRACE("No AVI resource found.\n");
709 if (!ANIMATE_LoadFileW(infoPtr
, lpszName
))
711 WARN("No AVI file found.\n");
718 if (!ANIMATE_LoadResW(infoPtr
, hInstance
, lpszName
))
720 WARN("No AVI resource found.\n");
725 if (!ANIMATE_GetAviInfo(infoPtr
))
727 WARN("Can't get AVI information\n");
728 ANIMATE_Free(infoPtr
);
732 if (!ANIMATE_GetAviCodec(infoPtr
))
734 WARN("Can't get AVI Codec\n");
735 ANIMATE_Free(infoPtr
);
739 hdc
= GetDC(infoPtr
->hwndSelf
);
740 /* native looks at the top left pixel of the first frame here too. */
741 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLORSTATIC
,
742 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
743 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
745 if (!(infoPtr
->dwStyle
& ACS_CENTER
))
746 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
747 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
749 if (infoPtr
->dwStyle
& ACS_AUTOPLAY
)
750 return ANIMATE_Play(infoPtr
, -1, 0, infoPtr
->mah
.dwTotalFrames
- 1);
756 static BOOL
ANIMATE_OpenA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInstance
, LPSTR lpszName
)
762 if (IS_INTRESOURCE(lpszName
))
763 return ANIMATE_OpenW(infoPtr
, hInstance
, (LPWSTR
)lpszName
);
765 len
= MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, NULL
, 0);
766 lpwszName
= Alloc(len
* sizeof(WCHAR
));
767 if (!lpwszName
) return FALSE
;
768 MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, lpwszName
, len
);
770 result
= ANIMATE_OpenW(infoPtr
, hInstance
, lpwszName
);
776 static BOOL
ANIMATE_Stop(ANIMATE_INFO
*infoPtr
)
782 ANIMATE_DoStop(infoPtr
);
787 static BOOL
ANIMATE_Create(HWND hWnd
, const CREATESTRUCTW
*lpcs
)
789 ANIMATE_INFO
*infoPtr
;
793 fnIC
.hModule
= LoadLibraryW(L
"msvfw32.dll");
794 if (!fnIC
.hModule
) return FALSE
;
796 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
797 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
798 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
799 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
802 /* allocate memory for info structure */
803 infoPtr
= Alloc(sizeof(*infoPtr
));
804 if (!infoPtr
) return FALSE
;
806 /* store crossref hWnd <-> info structure */
807 SetWindowLongPtrW(hWnd
, 0, (DWORD_PTR
)infoPtr
);
808 infoPtr
->hwndSelf
= hWnd
;
809 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
810 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
811 infoPtr
->hbmPrevFrame
= 0;
812 infoPtr
->dwStyle
= lpcs
->style
;
814 TRACE("Animate style %#lx, parent %p\n", infoPtr
->dwStyle
, infoPtr
->hwndNotify
);
816 InitializeCriticalSection(&infoPtr
->cs
);
817 infoPtr
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": ANIMATE_INFO*->cs");
823 static LRESULT
ANIMATE_Destroy(ANIMATE_INFO
*infoPtr
)
826 ANIMATE_Free(infoPtr
);
828 /* free animate info data */
829 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
831 infoPtr
->cs
.DebugInfo
->Spare
[0] = 0;
832 DeleteCriticalSection(&infoPtr
->cs
);
839 static BOOL
ANIMATE_EraseBackground(ANIMATE_INFO
const *infoPtr
, HDC hdc
)
844 hBrush
= (HBRUSH
)SendMessageW(infoPtr
->hwndNotify
, WM_CTLCOLORSTATIC
,
845 (WPARAM
)hdc
, (LPARAM
)infoPtr
->hwndSelf
);
846 GetClientRect(infoPtr
->hwndSelf
, &rect
);
847 FillRect(hdc
, &rect
, hBrush
? hBrush
: GetCurrentObject(hdc
, OBJ_BRUSH
));
853 static LRESULT
ANIMATE_StyleChanged(ANIMATE_INFO
*infoPtr
, WPARAM wStyleType
, const STYLESTRUCT
*lpss
)
855 TRACE("%#Ix, styleOld %#lx, styleNew %#lx.\n", wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
857 if (wStyleType
!= GWL_STYLE
) return 0;
859 infoPtr
->dwStyle
= lpss
->styleNew
;
864 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
866 ANIMATE_INFO
*infoPtr
= (ANIMATE_INFO
*)GetWindowLongPtrW(hWnd
, 0);
868 TRACE("hwnd %p, msg %x, wparam %#Ix, lparam %#Ix.\n", hWnd
, uMsg
, wParam
, lParam
);
870 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
871 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
875 return ANIMATE_OpenA(infoPtr
, (HINSTANCE
)wParam
, (LPSTR
)lParam
);
878 return ANIMATE_OpenW(infoPtr
, (HINSTANCE
)wParam
, (LPWSTR
)lParam
);
881 return ANIMATE_Play(infoPtr
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
));
884 return ANIMATE_Stop(infoPtr
);
887 ANIMATE_Free(infoPtr
);
891 return ANIMATE_Create(hWnd
, (LPCREATESTRUCTW
)lParam
);
894 return HTTRANSPARENT
;
897 return ANIMATE_Destroy(infoPtr
);
900 return ANIMATE_EraseBackground(infoPtr
, (HDC
)wParam
);
902 case WM_STYLECHANGED
:
903 return ANIMATE_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
906 return ANIMATE_Timer(infoPtr
);
911 /* the animation has not decompressed
912 * (and displayed) the first frame yet, don't paint
914 if (!infoPtr
->hbmPrevFrame
)
916 /* default paint handling */
917 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
922 EnterCriticalSection(&infoPtr
->cs
);
923 ANIMATE_PaintFrame(infoPtr
, (HDC
)wParam
);
924 LeaveCriticalSection(&infoPtr
->cs
);
929 HDC hDC
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
931 EnterCriticalSection(&infoPtr
->cs
);
932 ANIMATE_PaintFrame(infoPtr
, hDC
);
933 LeaveCriticalSection(&infoPtr
->cs
);
935 EndPaint(infoPtr
->hwndSelf
, &ps
);
941 if (infoPtr
->dwStyle
& ACS_CENTER
)
942 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
943 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
946 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
947 ERR("unknown msg %#x, wp %#Ix, lp %#Ix.\n", uMsg
, wParam
, lParam
);
949 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
954 void ANIMATE_Register(void)
958 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
959 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
960 wndClass
.lpfnWndProc
= ANIMATE_WindowProc
;
961 wndClass
.cbClsExtra
= 0;
962 wndClass
.cbWndExtra
= sizeof(ANIMATE_INFO
*);
963 wndClass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
964 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
965 wndClass
.lpszClassName
= ANIMATE_CLASSW
;
967 RegisterClassW(&wndClass
);
971 void ANIMATE_Unregister(void)
973 UnregisterClassW(ANIMATE_CLASSW
, NULL
);