1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
5 * Copyright 1998, 1999 Eric Kohl
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * I will only improve this control once in a while.
24 * Eric <ekohl@abo.rhein-zeitung.de>
27 * - check for the 'rec ' list in some AVI files
28 * - concurrent access to infoPtr
31 #define COM_NO_WINDOWS_H
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(animate
);
49 HIC (WINAPI
*fnICOpen
)(DWORD
, DWORD
, UINT
);
50 LRESULT (WINAPI
*fnICClose
)(HIC
);
51 LRESULT (WINAPI
*fnICSendMessage
)(HIC
, UINT
, DWORD
, DWORD
);
52 DWORD (WINAPIV
*fnICDecompress
)(HIC
,DWORD
,LPBITMAPINFOHEADER
,LPVOID
,LPBITMAPINFOHEADER
,LPVOID
);
57 /* reference to input stream (file or resource) */
59 HMMIO hMMio
; /* handle to mmio stream */
62 /* information on the loaded AVI file */
65 LPBITMAPINFOHEADER inbih
;
67 /* data for the decompressor */
69 LPBITMAPINFOHEADER outbih
;
72 /* data for the background mechanism */
77 /* data for playing the file */
83 COLORREF transparentColor
;
88 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
89 #define ANIMATE_COLOR_NONE 0xffffffff
91 static void ANIMATE_Notify(ANIMATE_INFO
* infoPtr
, UINT notif
)
93 SendMessageA(infoPtr
->hwndNotify
, WM_COMMAND
,
94 MAKEWPARAM(GetDlgCtrlID(infoPtr
->hwndSelf
), notif
),
95 (LPARAM
)infoPtr
->hwndSelf
);
98 static BOOL
ANIMATE_LoadResA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInst
, LPSTR lpName
)
104 hrsrc
= FindResourceA(hInst
, lpName
, "AVI");
108 infoPtr
->hRes
= LoadResource(hInst
, hrsrc
);
112 lpAvi
= LockResource(infoPtr
->hRes
);
116 memset(&mminfo
, 0, sizeof(mminfo
));
117 mminfo
.fccIOProc
= FOURCC_MEM
;
118 mminfo
.pchBuffer
= (LPSTR
)lpAvi
;
119 mminfo
.cchBuffer
= SizeofResource(hInst
, hrsrc
);
120 infoPtr
->hMMio
= mmioOpenA(NULL
, &mminfo
, MMIO_READ
);
121 if (!infoPtr
->hMMio
) {
122 GlobalFree((HGLOBAL
)lpAvi
);
130 static BOOL
ANIMATE_LoadFileA(ANIMATE_INFO
*infoPtr
, LPSTR lpName
)
132 infoPtr
->hMMio
= mmioOpenA((LPSTR
)lpName
, NULL
,
133 MMIO_ALLOCBUF
| MMIO_READ
| MMIO_DENYWRITE
);
142 static LRESULT
ANIMATE_DoStop(ANIMATE_INFO
*infoPtr
)
144 EnterCriticalSection(&infoPtr
->cs
);
146 /* should stop playing */
147 if (infoPtr
->hThread
)
149 HANDLE handle
= infoPtr
->hThread
;
151 TRACE("stopping animation thread\n");
152 SetEvent( infoPtr
->hStopEvent
);
153 LeaveCriticalSection(&infoPtr
->cs
); /* leave it a chance to run */
154 WaitForSingleObject( handle
, INFINITE
);
155 TRACE("animation thread stopped\n");
156 EnterCriticalSection(&infoPtr
->cs
);
157 CloseHandle( infoPtr
->hThread
);
158 CloseHandle( infoPtr
->hStopEvent
);
159 infoPtr
->hThread
= 0;
161 if (infoPtr
->uTimer
) {
162 KillTimer(infoPtr
->hwndSelf
, infoPtr
->uTimer
);
166 LeaveCriticalSection(&infoPtr
->cs
);
168 ANIMATE_Notify(infoPtr
, ACN_STOP
);
174 static void ANIMATE_Free(ANIMATE_INFO
*infoPtr
)
176 if (infoPtr
->hMMio
) {
177 ANIMATE_DoStop(infoPtr
);
178 mmioClose(infoPtr
->hMMio
, 0);
180 FreeResource(infoPtr
->hRes
);
183 if (infoPtr
->lpIndex
) {
184 HeapFree(GetProcessHeap(), 0, infoPtr
->lpIndex
);
185 infoPtr
->lpIndex
= NULL
;
188 fnIC
.fnICClose(infoPtr
->hic
);
191 if (infoPtr
->inbih
) {
192 HeapFree(GetProcessHeap(), 0, infoPtr
->inbih
);
193 infoPtr
->inbih
= NULL
;
195 if (infoPtr
->outbih
) {
196 HeapFree(GetProcessHeap(), 0, infoPtr
->outbih
);
197 infoPtr
->outbih
= NULL
;
199 if( infoPtr
->indata
)
201 HeapFree(GetProcessHeap(), 0, infoPtr
->indata
);
202 infoPtr
->indata
= NULL
;
204 if( infoPtr
->outdata
)
206 HeapFree(GetProcessHeap(), 0, infoPtr
->outdata
);
207 infoPtr
->outdata
= NULL
;
209 if( infoPtr
->hbmPrevFrame
)
211 DeleteObject(infoPtr
->hbmPrevFrame
);
212 infoPtr
->hbmPrevFrame
= 0;
214 infoPtr
->indata
= infoPtr
->outdata
= NULL
;
215 infoPtr
->hwndSelf
= 0;
218 memset(&infoPtr
->mah
, 0, sizeof(infoPtr
->mah
));
219 memset(&infoPtr
->ash
, 0, sizeof(infoPtr
->ash
));
220 infoPtr
->nFromFrame
= infoPtr
->nToFrame
= infoPtr
->nLoop
= infoPtr
->currFrame
= 0;
222 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
225 static void ANIMATE_TransparentBlt(ANIMATE_INFO
* infoPtr
, HDC hdcDest
, HDC hdcSource
)
231 /* create a transparency mask */
232 hdcMask
= CreateCompatibleDC(hdcDest
);
233 hbmMask
= CreateBitmap(infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, 1,1,NULL
);
234 hbmOld
= SelectObject(hdcMask
, hbmMask
);
236 SetBkColor(hdcSource
,infoPtr
->transparentColor
);
237 BitBlt(hdcMask
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCCOPY
);
239 /* mask the source bitmap */
240 SetBkColor(hdcSource
, RGB(0,0,0));
241 SetTextColor(hdcSource
, RGB(255,255,255));
242 BitBlt(hdcSource
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
244 /* mask the destination bitmap */
245 SetBkColor(hdcDest
, RGB(255,255,255));
246 SetTextColor(hdcDest
, RGB(0,0,0));
247 BitBlt(hdcDest
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
249 /* combine source and destination */
250 BitBlt(hdcDest
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCPAINT
);
252 SelectObject(hdcMask
, hbmOld
);
253 DeleteObject(hbmMask
);
257 static LRESULT
ANIMATE_PaintFrame(ANIMATE_INFO
* infoPtr
, HDC hDC
)
259 void* pBitmapData
= NULL
;
260 LPBITMAPINFO pBitmapInfo
= NULL
;
271 if (!hDC
|| !infoPtr
->inbih
)
276 pBitmapData
= infoPtr
->outdata
;
277 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->outbih
;
279 nWidth
= infoPtr
->outbih
->biWidth
;
280 nHeight
= infoPtr
->outbih
->biHeight
;
283 pBitmapData
= infoPtr
->indata
;
284 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->inbih
;
286 nWidth
= infoPtr
->inbih
->biWidth
;
287 nHeight
= infoPtr
->inbih
->biHeight
;
290 if(!infoPtr
->hbmPrevFrame
)
292 infoPtr
->hbmPrevFrame
=CreateCompatibleBitmap(hDC
, nWidth
,nHeight
);
295 SetDIBits(hDC
, infoPtr
->hbmPrevFrame
, 0, nHeight
, pBitmapData
, (LPBITMAPINFO
)pBitmapInfo
, DIB_RGB_COLORS
);
297 hdcMem
= CreateCompatibleDC(hDC
);
298 hbmOld
= SelectObject(hdcMem
, infoPtr
->hbmPrevFrame
);
301 * we need to get the transparent color even without ACS_TRANSPARENT,
302 * because the style can be changed later on and the color should always
303 * be obtained in the first frame
305 if(infoPtr
->transparentColor
== ANIMATE_COLOR_NONE
)
307 infoPtr
->transparentColor
= GetPixel(hdcMem
,0,0);
310 if(GetWindowLongA(infoPtr
->hwndSelf
, GWL_STYLE
) & ACS_TRANSPARENT
)
312 HDC hdcFinal
= CreateCompatibleDC(hDC
);
313 HBITMAP hbmFinal
= CreateCompatibleBitmap(hDC
,nWidth
, nHeight
);
314 HBITMAP hbmOld2
= SelectObject(hdcFinal
, hbmFinal
);
320 rect
.bottom
= nHeight
;
322 if(!infoPtr
->hbrushBG
)
323 infoPtr
->hbrushBG
= GetCurrentObject(hDC
, OBJ_BRUSH
);
325 FillRect(hdcFinal
, &rect
, infoPtr
->hbrushBG
);
326 ANIMATE_TransparentBlt(infoPtr
, hdcFinal
, hdcMem
);
328 SelectObject(hdcFinal
, hbmOld2
);
329 SelectObject(hdcMem
, hbmFinal
);
331 DeleteObject(infoPtr
->hbmPrevFrame
);
332 infoPtr
->hbmPrevFrame
= hbmFinal
;
335 if (GetWindowLongA(infoPtr
->hwndSelf
, GWL_STYLE
) & ACS_CENTER
)
339 GetWindowRect(infoPtr
->hwndSelf
, &rect
);
340 nOffsetX
= ((rect
.right
- rect
.left
) - nWidth
)/2;
341 nOffsetY
= ((rect
.bottom
- rect
.top
) - nHeight
)/2;
343 BitBlt(hDC
, nOffsetX
, nOffsetY
, nWidth
, nHeight
, hdcMem
, 0, 0, SRCCOPY
);
345 SelectObject(hdcMem
, hbmOld
);
350 static LRESULT
ANIMATE_DrawFrame(ANIMATE_INFO
* infoPtr
)
354 TRACE("Drawing frame %d (loop %d)\n", infoPtr
->currFrame
, infoPtr
->nLoop
);
356 EnterCriticalSection(&infoPtr
->cs
);
358 mmioSeek(infoPtr
->hMMio
, infoPtr
->lpIndex
[infoPtr
->currFrame
], SEEK_SET
);
359 mmioRead(infoPtr
->hMMio
, infoPtr
->indata
, infoPtr
->ash
.dwSuggestedBufferSize
);
362 fnIC
.fnICDecompress(infoPtr
->hic
, 0, infoPtr
->inbih
, infoPtr
->indata
,
363 infoPtr
->outbih
, infoPtr
->outdata
) != ICERR_OK
) {
364 LeaveCriticalSection(&infoPtr
->cs
);
365 WARN("Decompression error\n");
369 if ((hDC
= GetDC(infoPtr
->hwndSelf
)) != 0) {
370 ANIMATE_PaintFrame(infoPtr
, hDC
);
371 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
374 if (infoPtr
->currFrame
++ >= infoPtr
->nToFrame
) {
375 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
376 if (infoPtr
->nLoop
!= -1) {
377 if (--infoPtr
->nLoop
== 0) {
378 ANIMATE_DoStop(infoPtr
);
382 LeaveCriticalSection(&infoPtr
->cs
);
387 static DWORD CALLBACK
ANIMATE_AnimationThread(LPVOID ptr_
)
389 ANIMATE_INFO
* infoPtr
= (ANIMATE_INFO
*)ptr_
;
395 EnterCriticalSection(&infoPtr
->cs
);
396 ANIMATE_DrawFrame(infoPtr
);
397 timeout
= infoPtr
->mah
.dwMicroSecPerFrame
;
398 event
= infoPtr
->hStopEvent
;
399 LeaveCriticalSection(&infoPtr
->cs
);
401 /* time is in microseconds, we should convert it to milliseconds */
402 if (WaitForSingleObject( event
, (timeout
+500)/1000) == WAIT_OBJECT_0
)
408 static LRESULT
ANIMATE_Play(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
410 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
416 if (infoPtr
->hThread
|| infoPtr
->uTimer
) {
417 FIXME("Already playing ? what should I do ??\n");
418 ANIMATE_DoStop(infoPtr
);
421 infoPtr
->nFromFrame
= (INT
)LOWORD(lParam
);
422 infoPtr
->nToFrame
= (INT
)HIWORD(lParam
);
423 infoPtr
->nLoop
= (INT
)wParam
;
425 if (infoPtr
->nToFrame
== 0xFFFF)
426 infoPtr
->nToFrame
= infoPtr
->mah
.dwTotalFrames
- 1;
428 TRACE("(repeat=%d from=%d to=%d);\n",
429 infoPtr
->nLoop
, infoPtr
->nFromFrame
, infoPtr
->nToFrame
);
431 if (infoPtr
->nFromFrame
>= infoPtr
->nToFrame
||
432 infoPtr
->nToFrame
>= infoPtr
->mah
.dwTotalFrames
)
435 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
437 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TIMER
) {
438 TRACE("Using a timer\n");
439 /* create a timer to display AVI */
440 infoPtr
->uTimer
= SetTimer(hWnd
, 1, infoPtr
->mah
.dwMicroSecPerFrame
/ 1000, NULL
);
444 if(GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
446 HDC hDC
= GetDC(hWnd
);
447 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageA(infoPtr
->hwndNotify
,
448 WM_CTLCOLORSTATIC
, 0, (LPARAM
)hWnd
);
452 TRACE("Using an animation thread\n");
453 infoPtr
->hStopEvent
= CreateEventW( NULL
, TRUE
, FALSE
, NULL
);
454 infoPtr
->hThread
= CreateThread(0,0,ANIMATE_AnimationThread
,(LPVOID
)infoPtr
, 0, &threadID
);
455 if(!infoPtr
->hThread
)
457 ERR("Could not create animation thread!\n");
463 ANIMATE_Notify(infoPtr
, ACN_START
);
469 static BOOL
ANIMATE_GetAviInfo(ANIMATE_INFO
*infoPtr
)
478 if (mmioDescend(infoPtr
->hMMio
, &ckMainRIFF
, NULL
, 0) != 0) {
479 WARN("Can't find 'RIFF' chunk\n");
483 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) ||
484 (ckMainRIFF
.fccType
!= mmioFOURCC('A', 'V', 'I', ' '))) {
485 WARN("Can't find 'AVI ' chunk\n");
489 mmckHead
.fccType
= mmioFOURCC('h', 'd', 'r', 'l');
490 if (mmioDescend(infoPtr
->hMMio
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
491 WARN("Can't find 'hdrl' list\n");
495 mmckInfo
.ckid
= mmioFOURCC('a', 'v', 'i', 'h');
496 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
497 WARN("Can't find 'avih' chunk\n");
501 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->mah
, sizeof(infoPtr
->mah
));
503 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr
->mah
.dwMicroSecPerFrame
);
504 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr
->mah
.dwMaxBytesPerSec
);
505 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr
->mah
.dwPaddingGranularity
);
506 TRACE("mah.dwFlags=%ld\n", infoPtr
->mah
.dwFlags
);
507 TRACE("mah.dwTotalFrames=%ld\n", infoPtr
->mah
.dwTotalFrames
);
508 TRACE("mah.dwInitialFrames=%ld\n", infoPtr
->mah
.dwInitialFrames
);
509 TRACE("mah.dwStreams=%ld\n", infoPtr
->mah
.dwStreams
);
510 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr
->mah
.dwSuggestedBufferSize
);
511 TRACE("mah.dwWidth=%ld\n", infoPtr
->mah
.dwWidth
);
512 TRACE("mah.dwHeight=%ld\n", infoPtr
->mah
.dwHeight
);
514 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
516 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
517 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0) {
518 WARN("Can't find 'strl' list\n");
522 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'h');
523 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
524 WARN("Can't find 'strh' chunk\n");
528 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->ash
, sizeof(infoPtr
->ash
));
530 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccType
)),
531 HIBYTE(LOWORD(infoPtr
->ash
.fccType
)),
532 LOBYTE(HIWORD(infoPtr
->ash
.fccType
)),
533 HIBYTE(HIWORD(infoPtr
->ash
.fccType
)));
534 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
535 HIBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
536 LOBYTE(HIWORD(infoPtr
->ash
.fccHandler
)),
537 HIBYTE(HIWORD(infoPtr
->ash
.fccHandler
)));
538 TRACE("ash.dwFlags=%ld\n", infoPtr
->ash
.dwFlags
);
539 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
540 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
541 TRACE("ash.dwInitialFrames=%ld\n", infoPtr
->ash
.dwInitialFrames
);
542 TRACE("ash.dwScale=%ld\n", infoPtr
->ash
.dwScale
);
543 TRACE("ash.dwRate=%ld\n", infoPtr
->ash
.dwRate
);
544 TRACE("ash.dwStart=%ld\n", infoPtr
->ash
.dwStart
);
545 TRACE("ash.dwLength=%ld\n", infoPtr
->ash
.dwLength
);
546 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr
->ash
.dwSuggestedBufferSize
);
547 TRACE("ash.dwQuality=%ld\n", infoPtr
->ash
.dwQuality
);
548 TRACE("ash.dwSampleSize=%ld\n", infoPtr
->ash
.dwSampleSize
);
549 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
550 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
552 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
554 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
555 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
556 WARN("Can't find 'strh' chunk\n");
560 infoPtr
->inbih
= HeapAlloc(GetProcessHeap(), 0, mmckInfo
.cksize
);
561 if (!infoPtr
->inbih
) {
562 WARN("Can't alloc input BIH\n");
566 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
568 TRACE("bih.biSize=%ld\n", infoPtr
->inbih
->biSize
);
569 TRACE("bih.biWidth=%ld\n", infoPtr
->inbih
->biWidth
);
570 TRACE("bih.biHeight=%ld\n", infoPtr
->inbih
->biHeight
);
571 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
572 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
573 TRACE("bih.biCompression=%ld\n", infoPtr
->inbih
->biCompression
);
574 TRACE("bih.biSizeImage=%ld\n", infoPtr
->inbih
->biSizeImage
);
575 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr
->inbih
->biXPelsPerMeter
);
576 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr
->inbih
->biYPelsPerMeter
);
577 TRACE("bih.biClrUsed=%ld\n", infoPtr
->inbih
->biClrUsed
);
578 TRACE("bih.biClrImportant=%ld\n", infoPtr
->inbih
->biClrImportant
);
580 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
582 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
585 /* an AVI has 0 or 1 video stream, and to be animated should not contain
586 * an audio stream, so only one strl is allowed
588 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
589 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
590 WARN("There should be a single 'strl' list\n");
595 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
597 /* no need to read optional JUNK chunk */
599 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
600 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
601 WARN("Can't find 'movi' list\n");
605 /* FIXME: should handle the 'rec ' LIST when present */
607 infoPtr
->lpIndex
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
608 infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
609 if (!infoPtr
->lpIndex
) {
610 WARN("Can't alloc index array\n");
614 numFrame
= insize
= 0;
615 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
616 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
617 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
618 if (insize
< mmckInfo
.cksize
)
619 insize
= mmckInfo
.cksize
;
621 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
623 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
) {
624 WARN("Found %ld frames (/%ld)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
627 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
) {
628 WARN("insize=%ld suggestedSize=%ld\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
629 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
632 infoPtr
->indata
= HeapAlloc(GetProcessHeap(), 0, infoPtr
->ash
.dwSuggestedBufferSize
);
633 if (!infoPtr
->indata
) {
634 WARN("Can't alloc input buffer\n");
642 static BOOL
ANIMATE_GetAviCodec(ANIMATE_INFO
*infoPtr
)
646 /* check uncompressed AVI */
647 if ((infoPtr
->ash
.fccHandler
== mmioFOURCC('D', 'I', 'B', ' ')) ||
648 (infoPtr
->ash
.fccHandler
== mmioFOURCC('R', 'L', 'E', ' ')) ||
649 (infoPtr
->ash
.fccHandler
== mmioFOURCC(0, 0, 0, 0)))
655 /* try to get a decompressor for that type */
656 infoPtr
->hic
= fnIC
.fnICOpen(ICTYPE_VIDEO
, infoPtr
->ash
.fccHandler
, ICMODE_DECOMPRESS
);
658 WARN("Can't load codec for the file\n");
662 outSize
= fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
663 (DWORD
)infoPtr
->inbih
, 0L);
665 infoPtr
->outbih
= HeapAlloc(GetProcessHeap(), 0, outSize
);
666 if (!infoPtr
->outbih
) {
667 WARN("Can't alloc output BIH\n");
671 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
672 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != outSize
) {
673 WARN("Can't get output BIH\n");
677 infoPtr
->outdata
= HeapAlloc(GetProcessHeap(), 0, infoPtr
->outbih
->biSizeImage
);
678 if (!infoPtr
->outdata
) {
679 WARN("Can't alloc output buffer\n");
683 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
684 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != ICERR_OK
) {
685 WARN("Can't begin decompression\n");
692 static LRESULT
ANIMATE_OpenA(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
694 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
695 HINSTANCE hInstance
= (HINSTANCE
)wParam
;
697 ANIMATE_Free(infoPtr
);
698 infoPtr
->hwndSelf
= hWnd
;
701 TRACE("Closing avi!\n");
702 /* installer of thebat! v1.62 requires FALSE here */
703 return (infoPtr
->hMMio
!= 0);
707 hInstance
= (HINSTANCE
)GetWindowLongA(hWnd
, GWL_HINSTANCE
);
709 if (HIWORD(lParam
)) {
710 TRACE("(\"%s\");\n", (LPSTR
)lParam
);
712 if (!ANIMATE_LoadResA(infoPtr
, hInstance
, (LPSTR
)lParam
)) {
713 TRACE("No AVI resource found!\n");
714 if (!ANIMATE_LoadFileA(infoPtr
, (LPSTR
)lParam
)) {
715 WARN("No AVI file found!\n");
720 TRACE("(%u);\n", (WORD
)LOWORD(lParam
));
722 if (!ANIMATE_LoadResA(infoPtr
, hInstance
,
723 MAKEINTRESOURCEA((INT
)lParam
))) {
724 WARN("No AVI resource found!\n");
729 if (!ANIMATE_GetAviInfo(infoPtr
)) {
730 WARN("Can't get AVI information\n");
731 ANIMATE_Free(infoPtr
);
735 if (!ANIMATE_GetAviCodec(infoPtr
)) {
736 WARN("Can't get AVI Codec\n");
737 ANIMATE_Free(infoPtr
);
741 if (!GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_CENTER
) {
742 SetWindowPos(hWnd
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
743 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
746 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_AUTOPLAY
) {
747 return ANIMATE_Play(hWnd
, -1, (LPARAM
)MAKELONG(0, infoPtr
->mah
.dwTotalFrames
-1));
754 /* << ANIMATE_Open32W >> */
756 static LRESULT
ANIMATE_Stop(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
758 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
764 ANIMATE_DoStop(infoPtr
);
769 static LRESULT
ANIMATE_Create(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
771 ANIMATE_INFO
* infoPtr
;
773 if (!fnIC
.hModule
) /* FIXME: not thread safe */
775 /* since there's a circular dep between msvfw32 and comctl32, we could either:
776 * - fix the build chain to allow this circular dep
777 * - handle it by hand
778 * AJ wants the latter :-(
780 fnIC
.hModule
= LoadLibraryA("msvfw32.dll");
781 if (!fnIC
.hModule
) return FALSE
;
783 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
784 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
785 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
786 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
789 /* allocate memory for info structure */
790 infoPtr
= (ANIMATE_INFO
*)Alloc(sizeof(ANIMATE_INFO
));
792 ERR("could not allocate info memory!\n");
796 /* store crossref hWnd <-> info structure */
797 SetWindowLongA(hWnd
, 0, (DWORD
)infoPtr
);
798 infoPtr
->hwndSelf
= hWnd
;
799 infoPtr
->hwndNotify
= ((LPCREATESTRUCTA
)lParam
)->hwndParent
;
800 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
801 infoPtr
->hbmPrevFrame
= 0;
803 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd
, GWL_STYLE
), (DWORD
)infoPtr
->hwndNotify
);
805 InitializeCriticalSection(&infoPtr
->cs
);
811 static LRESULT
ANIMATE_Destroy(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
813 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
817 ANIMATE_Free(infoPtr
);
819 /* free animate info data */
821 SetWindowLongA(hWnd
, 0, 0);
827 static LRESULT
ANIMATE_EraseBackground(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
829 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
833 if(GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
835 hBrush
= (HBRUSH
)SendMessageA(infoPtr
->hwndNotify
,WM_CTLCOLORSTATIC
,
836 wParam
, (LPARAM
)hWnd
);
839 GetClientRect(hWnd
, &rect
);
840 FillRect((HDC
)wParam
, &rect
, hBrush
? hBrush
: GetCurrentObject((HDC
)wParam
, OBJ_BRUSH
));
845 static LRESULT WINAPI
ANIMATE_Size(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
847 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_CENTER
) {
848 InvalidateRect(hWnd
, NULL
, TRUE
);
853 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
855 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd
, uMsg
, wParam
, lParam
);
856 if (!ANIMATE_GetInfoPtr(hWnd
) && (uMsg
!= WM_NCCREATE
))
857 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
861 return ANIMATE_OpenA(hWnd
, wParam
, lParam
);
863 /* case ACM_OPEN32W: FIXME!! */
864 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
867 return ANIMATE_Play(hWnd
, wParam
, lParam
);
870 return ANIMATE_Stop(hWnd
, wParam
, lParam
);
873 ANIMATE_Create(hWnd
, wParam
, lParam
);
874 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
877 return HTTRANSPARENT
;
880 ANIMATE_Destroy(hWnd
, wParam
, lParam
);
881 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
884 ANIMATE_EraseBackground(hWnd
, wParam
, lParam
);
887 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
890 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
892 ANIMATE_INFO
* infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
893 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageA(infoPtr
->hwndNotify
,
895 wParam
, (LPARAM
)hWnd
);
897 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd
));
900 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd
));
905 ANIMATE_INFO
* infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
907 /* the animation isn't playing, or has not decompressed
908 * (and displayed) the first frame yet, don't paint
910 if ((!infoPtr
->uTimer
&& !infoPtr
->hThread
) ||
911 !infoPtr
->hbmPrevFrame
)
913 /* default paint handling */
914 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
917 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
918 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageA(infoPtr
->hwndNotify
,
920 wParam
, (LPARAM
)hWnd
);
924 EnterCriticalSection(&infoPtr
->cs
);
925 ANIMATE_PaintFrame(infoPtr
, (HDC
)wParam
);
926 LeaveCriticalSection(&infoPtr
->cs
);
931 HDC hDC
= BeginPaint(hWnd
, &ps
);
933 EnterCriticalSection(&infoPtr
->cs
);
934 ANIMATE_PaintFrame(infoPtr
, hDC
);
935 LeaveCriticalSection(&infoPtr
->cs
);
943 ANIMATE_Size(hWnd
, wParam
, lParam
);
944 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
947 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
948 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
950 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
955 void ANIMATE_Register(void)
959 ZeroMemory(&wndClass
, sizeof(WNDCLASSA
));
960 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
961 wndClass
.lpfnWndProc
= (WNDPROC
)ANIMATE_WindowProc
;
962 wndClass
.cbClsExtra
= 0;
963 wndClass
.cbWndExtra
= sizeof(ANIMATE_INFO
*);
964 wndClass
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
965 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
966 wndClass
.lpszClassName
= ANIMATE_CLASSA
;
968 RegisterClassA(&wndClass
);
972 void ANIMATE_Unregister(void)
974 UnregisterClassA(ANIMATE_CLASSA
, NULL
);