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 */
61 /* information on the loaded AVI file */
64 LPBITMAPINFOHEADER inbih
;
66 /* data for the decompressor */
68 LPBITMAPINFOHEADER outbih
;
71 /* data for the background mechanism */
75 /* data for playing the file */
81 COLORREF transparentColor
;
86 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
87 #define ANIMATE_COLOR_NONE 0xffffffff
89 static void ANIMATE_Notify(ANIMATE_INFO
* infoPtr
, UINT notif
)
91 SendMessageA(GetParent(infoPtr
->hWnd
), WM_COMMAND
,
92 MAKEWPARAM(GetDlgCtrlID(infoPtr
->hWnd
), notif
),
93 (LPARAM
)infoPtr
->hWnd
);
96 static BOOL
ANIMATE_LoadResA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInst
, LPSTR lpName
)
102 hrsrc
= FindResourceA(hInst
, lpName
, "AVI");
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
= (LPSTR
)lpAvi
;
117 mminfo
.cchBuffer
= SizeofResource(hInst
, hrsrc
);
118 infoPtr
->hMMio
= mmioOpenA(NULL
, &mminfo
, MMIO_READ
);
119 if (!infoPtr
->hMMio
) {
120 GlobalFree((HGLOBAL
)lpAvi
);
128 static BOOL
ANIMATE_LoadFileA(ANIMATE_INFO
*infoPtr
, LPSTR lpName
)
130 infoPtr
->hMMio
= mmioOpenA((LPSTR
)lpName
, NULL
,
131 MMIO_ALLOCBUF
| MMIO_READ
| MMIO_DENYWRITE
);
140 static LRESULT
ANIMATE_DoStop(ANIMATE_INFO
*infoPtr
)
142 EnterCriticalSection(&infoPtr
->cs
);
144 /* should stop playing */
145 if (infoPtr
->hThread
)
147 if (!TerminateThread(infoPtr
->hThread
,0))
148 WARN("could not destroy animation thread!\n");
149 infoPtr
->hThread
= 0;
151 if (infoPtr
->uTimer
) {
152 KillTimer(infoPtr
->hWnd
, infoPtr
->uTimer
);
156 LeaveCriticalSection(&infoPtr
->cs
);
158 ANIMATE_Notify(infoPtr
, ACN_STOP
);
164 static void ANIMATE_Free(ANIMATE_INFO
*infoPtr
)
166 if (infoPtr
->hMMio
) {
167 ANIMATE_DoStop(infoPtr
);
168 mmioClose(infoPtr
->hMMio
, 0);
170 FreeResource(infoPtr
->hRes
);
173 if (infoPtr
->lpIndex
) {
174 HeapFree(GetProcessHeap(), 0, infoPtr
->lpIndex
);
175 infoPtr
->lpIndex
= NULL
;
178 fnIC
.fnICClose(infoPtr
->hic
);
181 if (infoPtr
->inbih
) {
182 HeapFree(GetProcessHeap(), 0, infoPtr
->inbih
);
183 infoPtr
->inbih
= NULL
;
185 if (infoPtr
->outbih
) {
186 HeapFree(GetProcessHeap(), 0, infoPtr
->outbih
);
187 infoPtr
->outbih
= NULL
;
189 if( infoPtr
->indata
)
191 HeapFree(GetProcessHeap(), 0, infoPtr
->indata
);
192 infoPtr
->indata
= NULL
;
194 if( infoPtr
->outdata
)
196 HeapFree(GetProcessHeap(), 0, infoPtr
->outdata
);
197 infoPtr
->outdata
= NULL
;
199 if( infoPtr
->hbmPrevFrame
)
201 DeleteObject(infoPtr
->hbmPrevFrame
);
202 infoPtr
->hbmPrevFrame
= 0;
204 infoPtr
->indata
= infoPtr
->outdata
= NULL
;
208 memset(&infoPtr
->mah
, 0, sizeof(infoPtr
->mah
));
209 memset(&infoPtr
->ash
, 0, sizeof(infoPtr
->ash
));
210 infoPtr
->nFromFrame
= infoPtr
->nToFrame
= infoPtr
->nLoop
= infoPtr
->currFrame
= 0;
212 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
215 static void ANIMATE_TransparentBlt(ANIMATE_INFO
* infoPtr
, HDC hdcDest
, HDC hdcSource
)
221 /* create a transparency mask */
222 hdcMask
= CreateCompatibleDC(hdcDest
);
223 hbmMask
= CreateBitmap(infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, 1,1,NULL
);
224 hbmOld
= SelectObject(hdcMask
, hbmMask
);
226 SetBkColor(hdcSource
,infoPtr
->transparentColor
);
227 BitBlt(hdcMask
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCCOPY
);
229 /* mask the source bitmap */
230 SetBkColor(hdcSource
, RGB(0,0,0));
231 SetTextColor(hdcSource
, RGB(255,255,255));
232 BitBlt(hdcSource
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
234 /* mask the destination bitmap */
235 SetBkColor(hdcDest
, RGB(255,255,255));
236 SetTextColor(hdcDest
, RGB(0,0,0));
237 BitBlt(hdcDest
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
239 /* combine source and destination */
240 BitBlt(hdcDest
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCPAINT
);
242 SelectObject(hdcMask
, hbmOld
);
243 DeleteObject(hbmMask
);
247 static LRESULT
ANIMATE_PaintFrame(ANIMATE_INFO
* infoPtr
, HDC hDC
)
249 void* pBitmapData
= NULL
;
250 LPBITMAPINFO pBitmapInfo
= NULL
;
261 if (!hDC
|| !infoPtr
->inbih
)
266 pBitmapData
= infoPtr
->outdata
;
267 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->outbih
;
269 nWidth
= infoPtr
->outbih
->biWidth
;
270 nHeight
= infoPtr
->outbih
->biHeight
;
273 pBitmapData
= infoPtr
->indata
;
274 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->inbih
;
276 nWidth
= infoPtr
->inbih
->biWidth
;
277 nHeight
= infoPtr
->inbih
->biHeight
;
280 if(!infoPtr
->hbmPrevFrame
)
282 infoPtr
->hbmPrevFrame
=CreateCompatibleBitmap(hDC
, nWidth
,nHeight
);
285 SetDIBits(hDC
, infoPtr
->hbmPrevFrame
, 0, nHeight
, pBitmapData
, (LPBITMAPINFO
)pBitmapInfo
, DIB_RGB_COLORS
);
287 hdcMem
= CreateCompatibleDC(hDC
);
288 hbmOld
= SelectObject(hdcMem
, infoPtr
->hbmPrevFrame
);
291 * we need to get the transparent color even without ACS_TRANSPARENT,
292 * because the style can be changed later on and the color should always
293 * be obtained in the first frame
295 if(infoPtr
->transparentColor
== ANIMATE_COLOR_NONE
)
297 infoPtr
->transparentColor
= GetPixel(hdcMem
,0,0);
300 if(GetWindowLongA(infoPtr
->hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
302 HDC hdcFinal
= CreateCompatibleDC(hDC
);
303 HBITMAP hbmFinal
= CreateCompatibleBitmap(hDC
,nWidth
, nHeight
);
304 HBITMAP hbmOld2
= SelectObject(hdcFinal
, hbmFinal
);
310 rect
.bottom
= 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 (GetWindowLongA(infoPtr
->hWnd
, GWL_STYLE
) & ACS_CENTER
)
329 GetWindowRect(infoPtr
->hWnd
, &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 LRESULT
ANIMATE_DrawFrame(ANIMATE_INFO
* infoPtr
)
344 TRACE("Drawing frame %d (loop %d)\n", infoPtr
->currFrame
, infoPtr
->nLoop
);
346 EnterCriticalSection(&infoPtr
->cs
);
348 mmioSeek(infoPtr
->hMMio
, infoPtr
->lpIndex
[infoPtr
->currFrame
], SEEK_SET
);
349 mmioRead(infoPtr
->hMMio
, infoPtr
->indata
, infoPtr
->ash
.dwSuggestedBufferSize
);
352 fnIC
.fnICDecompress(infoPtr
->hic
, 0, infoPtr
->inbih
, infoPtr
->indata
,
353 infoPtr
->outbih
, infoPtr
->outdata
) != ICERR_OK
) {
354 LeaveCriticalSection(&infoPtr
->cs
);
355 WARN("Decompression error\n");
359 if ((hDC
= GetDC(infoPtr
->hWnd
)) != 0) {
360 ANIMATE_PaintFrame(infoPtr
, hDC
);
361 ReleaseDC(infoPtr
->hWnd
, hDC
);
364 if (infoPtr
->currFrame
++ >= infoPtr
->nToFrame
) {
365 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
366 if (infoPtr
->nLoop
!= -1) {
367 if (--infoPtr
->nLoop
== 0) {
368 ANIMATE_DoStop(infoPtr
);
372 LeaveCriticalSection(&infoPtr
->cs
);
377 static DWORD CALLBACK
ANIMATE_AnimationThread(LPVOID ptr_
)
379 ANIMATE_INFO
* infoPtr
= (ANIMATE_INFO
*)ptr_
;
384 WARN("animation structure undefined!\n");
390 if(GetWindowLongA(infoPtr
->hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
392 hDC
= GetDC(infoPtr
->hWnd
);
393 /* sometimes the animation window will be destroyed in between
394 * by the main program, so a ReleaseDC() error msg is possible */
395 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageA(GetParent(infoPtr
->hWnd
),
396 WM_CTLCOLORSTATIC
, (WPARAM
)hDC
,
397 (LPARAM
)infoPtr
->hWnd
);
398 ReleaseDC(infoPtr
->hWnd
,hDC
);
401 EnterCriticalSection(&infoPtr
->cs
);
402 ANIMATE_DrawFrame(infoPtr
);
403 LeaveCriticalSection(&infoPtr
->cs
);
405 /* time is in microseconds, we should convert it to milliseconds */
406 Sleep((infoPtr
->mah
.dwMicroSecPerFrame
+500)/1000);
411 static LRESULT
ANIMATE_Play(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
413 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
419 if (infoPtr
->hThread
|| infoPtr
->uTimer
) {
420 FIXME("Already playing ? what should I do ??\n");
421 ANIMATE_DoStop(infoPtr
);
424 infoPtr
->nFromFrame
= (INT
)LOWORD(lParam
);
425 infoPtr
->nToFrame
= (INT
)HIWORD(lParam
);
426 infoPtr
->nLoop
= (INT
)wParam
;
428 if (infoPtr
->nToFrame
== 0xFFFF)
429 infoPtr
->nToFrame
= infoPtr
->mah
.dwTotalFrames
- 1;
431 TRACE("(repeat=%d from=%d to=%d);\n",
432 infoPtr
->nLoop
, infoPtr
->nFromFrame
, infoPtr
->nToFrame
);
434 if (infoPtr
->nFromFrame
>= infoPtr
->nToFrame
||
435 infoPtr
->nToFrame
>= infoPtr
->mah
.dwTotalFrames
)
438 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
440 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TIMER
) {
441 TRACE("Using a timer\n");
442 /* create a timer to display AVI */
443 infoPtr
->uTimer
= SetTimer(hWnd
, 1, infoPtr
->mah
.dwMicroSecPerFrame
/ 1000, NULL
);
447 TRACE("Using an animation thread\n");
448 infoPtr
->hThread
= CreateThread(0,0,ANIMATE_AnimationThread
,(LPVOID
)infoPtr
, 0, &threadID
);
449 if(!infoPtr
->hThread
)
451 ERR("Could not create animation thread!\n");
457 ANIMATE_Notify(infoPtr
, ACN_START
);
463 static BOOL
ANIMATE_GetAviInfo(ANIMATE_INFO
*infoPtr
)
472 if (mmioDescend(infoPtr
->hMMio
, &ckMainRIFF
, NULL
, 0) != 0) {
473 WARN("Can't find 'RIFF' chunk\n");
477 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) ||
478 (ckMainRIFF
.fccType
!= mmioFOURCC('A', 'V', 'I', ' '))) {
479 WARN("Can't find 'AVI ' chunk\n");
483 mmckHead
.fccType
= mmioFOURCC('h', 'd', 'r', 'l');
484 if (mmioDescend(infoPtr
->hMMio
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
485 WARN("Can't find 'hdrl' list\n");
489 mmckInfo
.ckid
= mmioFOURCC('a', 'v', 'i', 'h');
490 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
491 WARN("Can't find 'avih' chunk\n");
495 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->mah
, sizeof(infoPtr
->mah
));
497 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr
->mah
.dwMicroSecPerFrame
);
498 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr
->mah
.dwMaxBytesPerSec
);
499 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr
->mah
.dwPaddingGranularity
);
500 TRACE("mah.dwFlags=%ld\n", infoPtr
->mah
.dwFlags
);
501 TRACE("mah.dwTotalFrames=%ld\n", infoPtr
->mah
.dwTotalFrames
);
502 TRACE("mah.dwInitialFrames=%ld\n", infoPtr
->mah
.dwInitialFrames
);
503 TRACE("mah.dwStreams=%ld\n", infoPtr
->mah
.dwStreams
);
504 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr
->mah
.dwSuggestedBufferSize
);
505 TRACE("mah.dwWidth=%ld\n", infoPtr
->mah
.dwWidth
);
506 TRACE("mah.dwHeight=%ld\n", infoPtr
->mah
.dwHeight
);
508 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
510 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
511 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0) {
512 WARN("Can't find 'strl' list\n");
516 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'h');
517 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
518 WARN("Can't find 'strh' chunk\n");
522 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->ash
, sizeof(infoPtr
->ash
));
524 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccType
)),
525 HIBYTE(LOWORD(infoPtr
->ash
.fccType
)),
526 LOBYTE(HIWORD(infoPtr
->ash
.fccType
)),
527 HIBYTE(HIWORD(infoPtr
->ash
.fccType
)));
528 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
529 HIBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
530 LOBYTE(HIWORD(infoPtr
->ash
.fccHandler
)),
531 HIBYTE(HIWORD(infoPtr
->ash
.fccHandler
)));
532 TRACE("ash.dwFlags=%ld\n", infoPtr
->ash
.dwFlags
);
533 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
534 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
535 TRACE("ash.dwInitialFrames=%ld\n", infoPtr
->ash
.dwInitialFrames
);
536 TRACE("ash.dwScale=%ld\n", infoPtr
->ash
.dwScale
);
537 TRACE("ash.dwRate=%ld\n", infoPtr
->ash
.dwRate
);
538 TRACE("ash.dwStart=%ld\n", infoPtr
->ash
.dwStart
);
539 TRACE("ash.dwLength=%ld\n", infoPtr
->ash
.dwLength
);
540 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr
->ash
.dwSuggestedBufferSize
);
541 TRACE("ash.dwQuality=%ld\n", infoPtr
->ash
.dwQuality
);
542 TRACE("ash.dwSampleSize=%ld\n", infoPtr
->ash
.dwSampleSize
);
543 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
544 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
546 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
548 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
549 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
550 WARN("Can't find 'strh' chunk\n");
554 infoPtr
->inbih
= HeapAlloc(GetProcessHeap(), 0, mmckInfo
.cksize
);
555 if (!infoPtr
->inbih
) {
556 WARN("Can't alloc input BIH\n");
560 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
562 TRACE("bih.biSize=%ld\n", infoPtr
->inbih
->biSize
);
563 TRACE("bih.biWidth=%ld\n", infoPtr
->inbih
->biWidth
);
564 TRACE("bih.biHeight=%ld\n", infoPtr
->inbih
->biHeight
);
565 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
566 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
567 TRACE("bih.biCompression=%ld\n", infoPtr
->inbih
->biCompression
);
568 TRACE("bih.biSizeImage=%ld\n", infoPtr
->inbih
->biSizeImage
);
569 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr
->inbih
->biXPelsPerMeter
);
570 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr
->inbih
->biYPelsPerMeter
);
571 TRACE("bih.biClrUsed=%ld\n", infoPtr
->inbih
->biClrUsed
);
572 TRACE("bih.biClrImportant=%ld\n", infoPtr
->inbih
->biClrImportant
);
574 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
576 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
579 /* an AVI has 0 or 1 video stream, and to be animated should not contain
580 * an audio stream, so only one strl is allowed
582 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
583 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
584 WARN("There should be a single 'strl' list\n");
589 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
591 /* no need to read optional JUNK chunk */
593 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
594 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
595 WARN("Can't find 'movi' list\n");
599 /* FIXME: should handle the 'rec ' LIST when present */
601 infoPtr
->lpIndex
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
602 infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
603 if (!infoPtr
->lpIndex
) {
604 WARN("Can't alloc index array\n");
608 numFrame
= insize
= 0;
609 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
610 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
611 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
612 if (insize
< mmckInfo
.cksize
)
613 insize
= mmckInfo
.cksize
;
615 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
617 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
) {
618 WARN("Found %ld frames (/%ld)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
621 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
) {
622 WARN("insize=%ld suggestedSize=%ld\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
623 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
626 infoPtr
->indata
= HeapAlloc(GetProcessHeap(), 0, infoPtr
->ash
.dwSuggestedBufferSize
);
627 if (!infoPtr
->indata
) {
628 WARN("Can't alloc input buffer\n");
636 static BOOL
ANIMATE_GetAviCodec(ANIMATE_INFO
*infoPtr
)
640 /* check uncompressed AVI */
641 if ((infoPtr
->ash
.fccHandler
== mmioFOURCC('D', 'I', 'B', ' ')) ||
642 (infoPtr
->ash
.fccHandler
== mmioFOURCC('R', 'L', 'E', ' ')) ||
643 (infoPtr
->ash
.fccHandler
== mmioFOURCC(0, 0, 0, 0)))
649 /* try to get a decompressor for that type */
650 infoPtr
->hic
= fnIC
.fnICOpen(ICTYPE_VIDEO
, infoPtr
->ash
.fccHandler
, ICMODE_DECOMPRESS
);
652 WARN("Can't load codec for the file\n");
656 outSize
= fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
657 (DWORD
)infoPtr
->inbih
, 0L);
659 infoPtr
->outbih
= HeapAlloc(GetProcessHeap(), 0, outSize
);
660 if (!infoPtr
->outbih
) {
661 WARN("Can't alloc output BIH\n");
665 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
666 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != outSize
) {
667 WARN("Can't get output BIH\n");
671 infoPtr
->outdata
= HeapAlloc(GetProcessHeap(), 0, infoPtr
->outbih
->biSizeImage
);
672 if (!infoPtr
->outdata
) {
673 WARN("Can't alloc output buffer\n");
677 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
678 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != ICERR_OK
) {
679 WARN("Can't begin decompression\n");
686 static LRESULT
ANIMATE_OpenA(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
688 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
689 HINSTANCE hInstance
= (HINSTANCE
)wParam
;
691 ANIMATE_Free(infoPtr
);
692 infoPtr
->hWnd
= hWnd
;
695 TRACE("Closing avi!\n");
696 /* installer of thebat! v1.62 requires FALSE here */
697 return (infoPtr
->hMMio
!= 0);
701 hInstance
= (HINSTANCE
)GetWindowLongA(hWnd
, GWL_HINSTANCE
);
703 if (HIWORD(lParam
)) {
704 TRACE("(\"%s\");\n", (LPSTR
)lParam
);
706 if (!ANIMATE_LoadResA(infoPtr
, hInstance
, (LPSTR
)lParam
)) {
707 TRACE("No AVI resource found!\n");
708 if (!ANIMATE_LoadFileA(infoPtr
, (LPSTR
)lParam
)) {
709 WARN("No AVI file found!\n");
714 TRACE("(%u);\n", (WORD
)LOWORD(lParam
));
716 if (!ANIMATE_LoadResA(infoPtr
, hInstance
,
717 MAKEINTRESOURCEA((INT
)lParam
))) {
718 WARN("No AVI resource found!\n");
723 if (!ANIMATE_GetAviInfo(infoPtr
)) {
724 WARN("Can't get AVI information\n");
725 ANIMATE_Free(infoPtr
);
729 if (!ANIMATE_GetAviCodec(infoPtr
)) {
730 WARN("Can't get AVI Codec\n");
731 ANIMATE_Free(infoPtr
);
735 if (!GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_CENTER
) {
736 SetWindowPos(hWnd
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
737 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
740 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_AUTOPLAY
) {
741 return ANIMATE_Play(hWnd
, -1, (LPARAM
)MAKELONG(0, infoPtr
->mah
.dwTotalFrames
-1));
748 /* << ANIMATE_Open32W >> */
750 static LRESULT
ANIMATE_Stop(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
752 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
758 ANIMATE_DoStop(infoPtr
);
763 static LRESULT
ANIMATE_Create(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
765 ANIMATE_INFO
* infoPtr
;
767 if (!fnIC
.hModule
) /* FIXME: not thread safe */
769 /* since there's a circular dep between msvfw32 and comctl32, we could either:
770 * - fix the build chain to allow this circular dep
771 * - handle it by hand
772 * AJ wants the latter :-(
774 fnIC
.hModule
= LoadLibraryA("msvfw32.dll");
775 if (!fnIC
.hModule
) return FALSE
;
777 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
778 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
779 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
780 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
783 /* allocate memory for info structure */
784 infoPtr
= (ANIMATE_INFO
*)Alloc(sizeof(ANIMATE_INFO
));
786 ERR("could not allocate info memory!\n");
790 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd
, GWL_STYLE
), (DWORD
)GetParent(hWnd
));
792 /* store crossref hWnd <-> info structure */
793 SetWindowLongA(hWnd
, 0, (DWORD
)infoPtr
);
794 infoPtr
->hWnd
= hWnd
;
795 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
796 infoPtr
->hbmPrevFrame
= 0;
798 InitializeCriticalSection(&infoPtr
->cs
);
804 static LRESULT
ANIMATE_Destroy(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
806 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
810 ANIMATE_Free(infoPtr
);
812 /* free animate info data */
814 SetWindowLongA(hWnd
, 0, 0);
820 static LRESULT
ANIMATE_EraseBackground(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
825 if(GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
827 hBrush
= (HBRUSH
)SendMessageA(GetParent(hWnd
),WM_CTLCOLORSTATIC
,
828 wParam
, (LPARAM
)hWnd
);
831 GetClientRect(hWnd
, &rect
);
832 FillRect((HDC
)wParam
, &rect
, hBrush
? hBrush
: GetCurrentObject((HDC
)wParam
, OBJ_BRUSH
));
837 static LRESULT WINAPI
ANIMATE_Size(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
839 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_CENTER
) {
840 InvalidateRect(hWnd
, NULL
, TRUE
);
845 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
847 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd
, uMsg
, wParam
, lParam
);
848 if (!ANIMATE_GetInfoPtr(hWnd
) && (uMsg
!= WM_NCCREATE
))
849 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
853 return ANIMATE_OpenA(hWnd
, wParam
, lParam
);
855 /* case ACM_OPEN32W: FIXME!! */
856 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
859 return ANIMATE_Play(hWnd
, wParam
, lParam
);
862 return ANIMATE_Stop(hWnd
, wParam
, lParam
);
865 ANIMATE_Create(hWnd
, wParam
, lParam
);
866 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
869 return HTTRANSPARENT
;
872 ANIMATE_Destroy(hWnd
, wParam
, lParam
);
873 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
876 ANIMATE_EraseBackground(hWnd
, wParam
, lParam
);
879 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
882 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
884 ANIMATE_INFO
* infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
885 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageA(GetParent(hWnd
),
887 wParam
, (LPARAM
)hWnd
);
889 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd
));
892 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd
));
897 ANIMATE_INFO
* infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
899 /* the animation isn't playing, don't paint */
900 if(!infoPtr
->uTimer
&& !infoPtr
->hThread
)
901 /* default paint handling */
902 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
904 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
905 infoPtr
->hbrushBG
= (HBRUSH
)SendMessageA(GetParent(hWnd
),
907 wParam
, (LPARAM
)hWnd
);
911 EnterCriticalSection(&infoPtr
->cs
);
912 ANIMATE_PaintFrame(infoPtr
, (HDC
)wParam
);
913 LeaveCriticalSection(&infoPtr
->cs
);
918 HDC hDC
= BeginPaint(hWnd
, &ps
);
920 EnterCriticalSection(&infoPtr
->cs
);
921 ANIMATE_PaintFrame(infoPtr
, hDC
);
922 LeaveCriticalSection(&infoPtr
->cs
);
930 ANIMATE_Size(hWnd
, wParam
, lParam
);
931 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
934 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
935 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
937 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
942 void ANIMATE_Register(void)
946 ZeroMemory(&wndClass
, sizeof(WNDCLASSA
));
947 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
948 wndClass
.lpfnWndProc
= (WNDPROC
)ANIMATE_WindowProc
;
949 wndClass
.cbClsExtra
= 0;
950 wndClass
.cbWndExtra
= sizeof(ANIMATE_INFO
*);
951 wndClass
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
952 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
953 wndClass
.lpszClassName
= ANIMATE_CLASSA
;
955 RegisterClassA(&wndClass
);
959 void ANIMATE_Unregister(void)
961 UnregisterClassA(ANIMATE_CLASSA
, NULL
);