1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
5 * Copyright 1998, 1999 Eric Kohl
9 * I will only improve this control once in a while.
10 * Eric <ekohl@abo.rhein-zeitung.de>
13 * - check for the 'rec ' list in some AVI files
14 * - concurrent access to infoPtr
22 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(animate
);
28 HIC (WINAPI
*fnICOpen
)(DWORD
, DWORD
, UINT
);
29 LRESULT (WINAPI
*fnICClose
)(HIC
);
30 LRESULT (WINAPI
*fnICSendMessage
)(HIC
, UINT
, DWORD
, DWORD
);
31 DWORD (WINAPIV
*fnICDecompress
)(HIC
,DWORD
,LPBITMAPINFOHEADER
,LPVOID
,LPBITMAPINFOHEADER
,LPVOID
);
36 /* reference to input stream (file or resource) */
38 HMMIO hMMio
; /* handle to mmio stream */
40 /* information on the loaded AVI file */
43 LPBITMAPINFOHEADER inbih
;
45 /* data for the decompressor */
47 LPBITMAPINFOHEADER outbih
;
50 /* data for the background mechanism */
54 /* data for playing the file */
60 COLORREF transparentColor
;
65 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
66 #define ANIMATE_COLOR_NONE 0xffffffff
68 static void ANIMATE_Notify(ANIMATE_INFO
* infoPtr
, UINT notif
)
70 SendMessageA(GetParent(infoPtr
->hWnd
), WM_COMMAND
,
71 MAKEWPARAM(GetDlgCtrlID(infoPtr
->hWnd
), notif
),
72 (LPARAM
)infoPtr
->hWnd
);
75 static BOOL
ANIMATE_LoadResA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInst
, LPSTR lpName
)
81 hrsrc
= FindResourceA(hInst
, lpName
, "AVI");
85 infoPtr
->hRes
= LoadResource(hInst
, hrsrc
);
89 lpAvi
= LockResource(infoPtr
->hRes
);
93 memset(&mminfo
, 0, sizeof(mminfo
));
94 mminfo
.fccIOProc
= FOURCC_MEM
;
95 mminfo
.pchBuffer
= (LPSTR
)lpAvi
;
96 mminfo
.cchBuffer
= SizeofResource(hInst
, hrsrc
);
97 infoPtr
->hMMio
= mmioOpenA(NULL
, &mminfo
, MMIO_READ
);
98 if (!infoPtr
->hMMio
) {
99 GlobalFree((HGLOBAL
)lpAvi
);
107 static BOOL
ANIMATE_LoadFileA(ANIMATE_INFO
*infoPtr
, LPSTR lpName
)
109 infoPtr
->hMMio
= mmioOpenA((LPSTR
)lpName
, NULL
,
110 MMIO_ALLOCBUF
| MMIO_READ
| MMIO_DENYWRITE
);
119 static LRESULT
ANIMATE_DoStop(ANIMATE_INFO
*infoPtr
)
121 EnterCriticalSection(&infoPtr
->cs
);
123 /* should stop playing */
124 if (infoPtr
->hThread
)
126 if (!TerminateThread(infoPtr
->hThread
,0))
127 WARN("could not destroy animation thread!\n");
128 infoPtr
->hThread
= 0;
130 if (infoPtr
->uTimer
) {
131 KillTimer(infoPtr
->hWnd
, infoPtr
->uTimer
);
135 LeaveCriticalSection(&infoPtr
->cs
);
137 ANIMATE_Notify(infoPtr
, ACN_STOP
);
143 static void ANIMATE_Free(ANIMATE_INFO
*infoPtr
)
145 if (infoPtr
->hMMio
) {
146 ANIMATE_DoStop(infoPtr
);
147 mmioClose(infoPtr
->hMMio
, 0);
149 FreeResource(infoPtr
->hRes
);
152 if (infoPtr
->lpIndex
) {
153 HeapFree(GetProcessHeap(), 0, infoPtr
->lpIndex
);
154 infoPtr
->lpIndex
= NULL
;
157 fnIC
.fnICClose(infoPtr
->hic
);
160 if (infoPtr
->inbih
) {
161 HeapFree(GetProcessHeap(), 0, infoPtr
->inbih
);
162 infoPtr
->inbih
= NULL
;
164 if (infoPtr
->outbih
) {
165 HeapFree(GetProcessHeap(), 0, infoPtr
->outbih
);
166 infoPtr
->outbih
= NULL
;
168 if( infoPtr
->indata
)
170 HeapFree(GetProcessHeap(), 0, infoPtr
->indata
);
171 infoPtr
->indata
= NULL
;
173 if( infoPtr
->outdata
)
175 HeapFree(GetProcessHeap(), 0, infoPtr
->outdata
);
176 infoPtr
->outdata
= NULL
;
178 if( infoPtr
->hbmPrevFrame
)
180 DeleteObject(infoPtr
->hbmPrevFrame
);
181 infoPtr
->hbmPrevFrame
= 0;
183 infoPtr
->indata
= infoPtr
->outdata
= NULL
;
187 memset(&infoPtr
->mah
, 0, sizeof(infoPtr
->mah
));
188 memset(&infoPtr
->ash
, 0, sizeof(infoPtr
->ash
));
189 infoPtr
->nFromFrame
= infoPtr
->nToFrame
= infoPtr
->nLoop
= infoPtr
->currFrame
= 0;
191 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
194 static void ANIMATE_TransparentBlt(ANIMATE_INFO
* infoPtr
, HDC hdcDest
, HDC hdcSource
)
200 /* create a transparency mask */
201 hdcMask
= CreateCompatibleDC(hdcDest
);
202 hbmMask
= CreateBitmap(infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, 1,1,NULL
);
203 hbmOld
= SelectObject(hdcMask
, hbmMask
);
205 SetBkColor(hdcSource
,infoPtr
->transparentColor
);
206 BitBlt(hdcMask
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCCOPY
);
208 /* mask the source bitmap */
209 SetBkColor(hdcSource
, RGB(0,0,0));
210 SetTextColor(hdcSource
, RGB(255,255,255));
211 BitBlt(hdcSource
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
213 /* mask the destination bitmap */
214 SetBkColor(hdcDest
, RGB(255,255,255));
215 SetTextColor(hdcDest
, RGB(0,0,0));
216 BitBlt(hdcDest
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
218 /* combine source and destination */
219 BitBlt(hdcDest
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCPAINT
);
221 SelectObject(hdcMask
, hbmOld
);
222 DeleteObject(hbmMask
);
226 static LRESULT
ANIMATE_PaintFrame(ANIMATE_INFO
* infoPtr
, HDC hDC
)
228 void* pBitmapData
= NULL
;
229 LPBITMAPINFO pBitmapInfo
= NULL
;
240 if (!hDC
|| !infoPtr
->inbih
)
245 pBitmapData
= infoPtr
->outdata
;
246 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->outbih
;
248 nWidth
= infoPtr
->outbih
->biWidth
;
249 nHeight
= infoPtr
->outbih
->biHeight
;
252 pBitmapData
= infoPtr
->indata
;
253 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->inbih
;
255 nWidth
= infoPtr
->inbih
->biWidth
;
256 nHeight
= infoPtr
->inbih
->biHeight
;
259 if(!infoPtr
->hbmPrevFrame
)
261 infoPtr
->hbmPrevFrame
=CreateCompatibleBitmap(hDC
, nWidth
,nHeight
);
264 SetDIBits(hDC
, infoPtr
->hbmPrevFrame
, 0, nHeight
, pBitmapData
, (LPBITMAPINFO
)pBitmapInfo
, DIB_RGB_COLORS
);
266 hdcMem
= CreateCompatibleDC(hDC
);
267 hbmOld
= SelectObject(hdcMem
, infoPtr
->hbmPrevFrame
);
270 * we need to get the transparent color even without ACS_TRANSPARENT,
271 * because the style can be changed later on and the color should always
272 * be obtained in the first frame
274 if(infoPtr
->transparentColor
== ANIMATE_COLOR_NONE
)
276 infoPtr
->transparentColor
= GetPixel(hdcMem
,0,0);
279 if(GetWindowLongA(infoPtr
->hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
281 HDC hdcFinal
= CreateCompatibleDC(hDC
);
282 HBITMAP hbmFinal
= CreateCompatibleBitmap(hDC
,nWidth
, nHeight
);
283 HBITMAP hbmOld2
= SelectObject(hdcFinal
, hbmFinal
);
289 rect
.bottom
= nHeight
;
291 if(!infoPtr
->hbrushBG
)
292 infoPtr
->hbrushBG
= GetCurrentObject(hDC
, OBJ_BRUSH
);
294 FillRect(hdcFinal
, &rect
, infoPtr
->hbrushBG
);
295 ANIMATE_TransparentBlt(infoPtr
, hdcFinal
, hdcMem
);
297 SelectObject(hdcFinal
, hbmOld2
);
298 SelectObject(hdcMem
, hbmFinal
);
300 DeleteObject(infoPtr
->hbmPrevFrame
);
301 infoPtr
->hbmPrevFrame
= hbmFinal
;
304 if (GetWindowLongA(infoPtr
->hWnd
, GWL_STYLE
) & ACS_CENTER
)
308 GetWindowRect(infoPtr
->hWnd
, &rect
);
309 nOffsetX
= ((rect
.right
- rect
.left
) - nWidth
)/2;
310 nOffsetY
= ((rect
.bottom
- rect
.top
) - nHeight
)/2;
312 BitBlt(hDC
, nOffsetX
, nOffsetY
, nWidth
, nHeight
, hdcMem
, 0, 0, SRCCOPY
);
314 SelectObject(hdcMem
, hbmOld
);
319 static LRESULT
ANIMATE_DrawFrame(ANIMATE_INFO
* infoPtr
)
323 TRACE("Drawing frame %d (loop %d)\n", infoPtr
->currFrame
, infoPtr
->nLoop
);
325 EnterCriticalSection(&infoPtr
->cs
);
327 mmioSeek(infoPtr
->hMMio
, infoPtr
->lpIndex
[infoPtr
->currFrame
], SEEK_SET
);
328 mmioRead(infoPtr
->hMMio
, infoPtr
->indata
, infoPtr
->ash
.dwSuggestedBufferSize
);
331 fnIC
.fnICDecompress(infoPtr
->hic
, 0, infoPtr
->inbih
, infoPtr
->indata
,
332 infoPtr
->outbih
, infoPtr
->outdata
) != ICERR_OK
) {
333 LeaveCriticalSection(&infoPtr
->cs
);
334 WARN("Decompression error\n");
338 if ((hDC
= GetDC(infoPtr
->hWnd
)) != 0) {
339 ANIMATE_PaintFrame(infoPtr
, hDC
);
340 ReleaseDC(infoPtr
->hWnd
, hDC
);
343 if (infoPtr
->currFrame
++ >= infoPtr
->nToFrame
) {
344 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
345 if (infoPtr
->nLoop
!= -1) {
346 if (--infoPtr
->nLoop
== 0) {
347 ANIMATE_DoStop(infoPtr
);
351 LeaveCriticalSection(&infoPtr
->cs
);
356 static DWORD CALLBACK
ANIMATE_AnimationThread(LPVOID ptr_
)
358 ANIMATE_INFO
* infoPtr
= (ANIMATE_INFO
*)ptr_
;
363 WARN("animation structure undefined!\n");
369 if(GetWindowLongA(infoPtr
->hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
371 hDC
= GetDC(infoPtr
->hWnd
);
372 /* sometimes the animation window will be destroyed in between
373 * by the main program, so a ReleaseDC() error msg is possible */
374 infoPtr
->hbrushBG
= SendMessageA(GetParent(infoPtr
->hWnd
),WM_CTLCOLORSTATIC
,hDC
, infoPtr
->hWnd
);
375 ReleaseDC(infoPtr
->hWnd
,hDC
);
378 EnterCriticalSection(&infoPtr
->cs
);
379 ANIMATE_DrawFrame(infoPtr
);
380 LeaveCriticalSection(&infoPtr
->cs
);
382 /* time is in microseconds, we should convert it to milliseconds */
383 Sleep((infoPtr
->mah
.dwMicroSecPerFrame
+500)/1000);
388 static LRESULT
ANIMATE_Play(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
390 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
396 if (infoPtr
->hThread
|| infoPtr
->uTimer
) {
397 FIXME("Already playing ? what should I do ??\n");
398 ANIMATE_DoStop(infoPtr
);
401 infoPtr
->nFromFrame
= (INT
)LOWORD(lParam
);
402 infoPtr
->nToFrame
= (INT
)HIWORD(lParam
);
403 infoPtr
->nLoop
= (INT
)wParam
;
405 if (infoPtr
->nToFrame
== 0xFFFF)
406 infoPtr
->nToFrame
= infoPtr
->mah
.dwTotalFrames
- 1;
408 TRACE("(repeat=%d from=%d to=%d);\n",
409 infoPtr
->nLoop
, infoPtr
->nFromFrame
, infoPtr
->nToFrame
);
411 if (infoPtr
->nFromFrame
>= infoPtr
->nToFrame
||
412 infoPtr
->nToFrame
>= infoPtr
->mah
.dwTotalFrames
)
415 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
417 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TIMER
) {
418 TRACE("Using a timer\n");
419 /* create a timer to display AVI */
420 infoPtr
->uTimer
= SetTimer(hWnd
, 1, infoPtr
->mah
.dwMicroSecPerFrame
/ 1000, NULL
);
424 TRACE("Using an animation thread\n");
425 infoPtr
->hThread
= CreateThread(0,0,ANIMATE_AnimationThread
,(LPVOID
)infoPtr
,0,0 &threadID
);
426 if(!infoPtr
->hThread
)
428 ERR("Could not create animation thread!\n");
434 ANIMATE_Notify(infoPtr
, ACN_START
);
440 static BOOL
ANIMATE_GetAviInfo(ANIMATE_INFO
*infoPtr
)
449 if (mmioDescend(infoPtr
->hMMio
, &ckMainRIFF
, NULL
, 0) != 0) {
450 WARN("Can't find 'RIFF' chunk\n");
454 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) ||
455 (ckMainRIFF
.fccType
!= mmioFOURCC('A', 'V', 'I', ' '))) {
456 WARN("Can't find 'AVI ' chunk\n");
460 mmckHead
.fccType
= mmioFOURCC('h', 'd', 'r', 'l');
461 if (mmioDescend(infoPtr
->hMMio
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
462 WARN("Can't find 'hdrl' list\n");
466 mmckInfo
.ckid
= mmioFOURCC('a', 'v', 'i', 'h');
467 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
468 WARN("Can't find 'avih' chunk\n");
472 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->mah
, sizeof(infoPtr
->mah
));
474 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr
->mah
.dwMicroSecPerFrame
);
475 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr
->mah
.dwMaxBytesPerSec
);
476 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr
->mah
.dwPaddingGranularity
);
477 TRACE("mah.dwFlags=%ld\n", infoPtr
->mah
.dwFlags
);
478 TRACE("mah.dwTotalFrames=%ld\n", infoPtr
->mah
.dwTotalFrames
);
479 TRACE("mah.dwInitialFrames=%ld\n", infoPtr
->mah
.dwInitialFrames
);
480 TRACE("mah.dwStreams=%ld\n", infoPtr
->mah
.dwStreams
);
481 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr
->mah
.dwSuggestedBufferSize
);
482 TRACE("mah.dwWidth=%ld\n", infoPtr
->mah
.dwWidth
);
483 TRACE("mah.dwHeight=%ld\n", infoPtr
->mah
.dwHeight
);
485 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
487 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
488 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0) {
489 WARN("Can't find 'strl' list\n");
493 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'h');
494 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
495 WARN("Can't find 'strh' chunk\n");
499 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->ash
, sizeof(infoPtr
->ash
));
501 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccType
)),
502 HIBYTE(LOWORD(infoPtr
->ash
.fccType
)),
503 LOBYTE(HIWORD(infoPtr
->ash
.fccType
)),
504 HIBYTE(HIWORD(infoPtr
->ash
.fccType
)));
505 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
506 HIBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
507 LOBYTE(HIWORD(infoPtr
->ash
.fccHandler
)),
508 HIBYTE(HIWORD(infoPtr
->ash
.fccHandler
)));
509 TRACE("ash.dwFlags=%ld\n", infoPtr
->ash
.dwFlags
);
510 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
511 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
512 TRACE("ash.dwInitialFrames=%ld\n", infoPtr
->ash
.dwInitialFrames
);
513 TRACE("ash.dwScale=%ld\n", infoPtr
->ash
.dwScale
);
514 TRACE("ash.dwRate=%ld\n", infoPtr
->ash
.dwRate
);
515 TRACE("ash.dwStart=%ld\n", infoPtr
->ash
.dwStart
);
516 TRACE("ash.dwLength=%ld\n", infoPtr
->ash
.dwLength
);
517 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr
->ash
.dwSuggestedBufferSize
);
518 TRACE("ash.dwQuality=%ld\n", infoPtr
->ash
.dwQuality
);
519 TRACE("ash.dwSampleSize=%ld\n", infoPtr
->ash
.dwSampleSize
);
520 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
521 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
523 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
525 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
526 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
527 WARN("Can't find 'strh' chunk\n");
531 infoPtr
->inbih
= HeapAlloc(GetProcessHeap(), 0, mmckInfo
.cksize
);
532 if (!infoPtr
->inbih
) {
533 WARN("Can't alloc input BIH\n");
537 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
539 TRACE("bih.biSize=%ld\n", infoPtr
->inbih
->biSize
);
540 TRACE("bih.biWidth=%ld\n", infoPtr
->inbih
->biWidth
);
541 TRACE("bih.biHeight=%ld\n", infoPtr
->inbih
->biHeight
);
542 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
543 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
544 TRACE("bih.biCompression=%ld\n", infoPtr
->inbih
->biCompression
);
545 TRACE("bih.biSizeImage=%ld\n", infoPtr
->inbih
->biSizeImage
);
546 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr
->inbih
->biXPelsPerMeter
);
547 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr
->inbih
->biYPelsPerMeter
);
548 TRACE("bih.biClrUsed=%ld\n", infoPtr
->inbih
->biClrUsed
);
549 TRACE("bih.biClrImportant=%ld\n", infoPtr
->inbih
->biClrImportant
);
551 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
553 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
556 /* an AVI has 0 or 1 video stream, and to be animated should not contain
557 * an audio stream, so only one strl is allowed
559 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
560 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
561 WARN("There should be a single 'strl' list\n");
566 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
568 /* no need to read optional JUNK chunk */
570 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
571 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
572 WARN("Can't find 'movi' list\n");
576 /* FIXME: should handle the 'rec ' LIST when present */
578 infoPtr
->lpIndex
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
579 infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
580 if (!infoPtr
->lpIndex
) {
581 WARN("Can't alloc index array\n");
585 numFrame
= insize
= 0;
586 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
587 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
588 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
589 if (insize
< mmckInfo
.cksize
)
590 insize
= mmckInfo
.cksize
;
592 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
594 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
) {
595 WARN("Found %ld frames (/%ld)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
598 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
) {
599 WARN("insize=%ld suggestedSize=%ld\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
600 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
603 infoPtr
->indata
= HeapAlloc(GetProcessHeap(), 0, infoPtr
->ash
.dwSuggestedBufferSize
);
604 if (!infoPtr
->indata
) {
605 WARN("Can't alloc input buffer\n");
613 static BOOL
ANIMATE_GetAviCodec(ANIMATE_INFO
*infoPtr
)
617 /* check uncompressed AVI */
618 if ((infoPtr
->ash
.fccHandler
== mmioFOURCC('D', 'I', 'B', ' ')) ||
619 (infoPtr
->ash
.fccHandler
== mmioFOURCC('R', 'L', 'E', ' ')) ||
620 (infoPtr
->ash
.fccHandler
== mmioFOURCC(0, 0, 0, 0)))
626 /* try to get a decompressor for that type */
627 infoPtr
->hic
= fnIC
.fnICOpen(ICTYPE_VIDEO
, infoPtr
->ash
.fccHandler
, ICMODE_DECOMPRESS
);
629 WARN("Can't load codec for the file\n");
633 outSize
= fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
634 (DWORD
)infoPtr
->inbih
, 0L);
636 infoPtr
->outbih
= HeapAlloc(GetProcessHeap(), 0, outSize
);
637 if (!infoPtr
->outbih
) {
638 WARN("Can't alloc output BIH\n");
642 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
643 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != ICERR_OK
) {
644 WARN("Can't get output BIH\n");
648 infoPtr
->outdata
= HeapAlloc(GetProcessHeap(), 0, infoPtr
->outbih
->biSizeImage
);
649 if (!infoPtr
->outdata
) {
650 WARN("Can't alloc output buffer\n");
654 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
655 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != ICERR_OK
) {
656 WARN("Can't begin decompression\n");
663 static LRESULT
ANIMATE_OpenA(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
665 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
666 HINSTANCE hInstance
= (HINSTANCE
)wParam
;
668 ANIMATE_Free(infoPtr
);
669 infoPtr
->hWnd
= hWnd
;
672 TRACE("Closing avi!\n");
677 hInstance
= GetWindowLongA(hWnd
, GWL_HINSTANCE
);
679 if (HIWORD(lParam
)) {
680 TRACE("(\"%s\");\n", (LPSTR
)lParam
);
682 if (!ANIMATE_LoadResA(infoPtr
, hInstance
, (LPSTR
)lParam
)) {
683 TRACE("No AVI resource found!\n");
684 if (!ANIMATE_LoadFileA(infoPtr
, (LPSTR
)lParam
)) {
685 WARN("No AVI file found!\n");
690 TRACE("(%u);\n", (WORD
)LOWORD(lParam
));
692 if (!ANIMATE_LoadResA(infoPtr
, hInstance
,
693 MAKEINTRESOURCEA((INT
)lParam
))) {
694 WARN("No AVI resource found!\n");
699 if (!ANIMATE_GetAviInfo(infoPtr
)) {
700 WARN("Can't get AVI information\n");
701 ANIMATE_Free(infoPtr
);
705 if (!ANIMATE_GetAviCodec(infoPtr
)) {
706 WARN("Can't get AVI Codec\n");
707 ANIMATE_Free(infoPtr
);
711 if (!GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_CENTER
) {
712 SetWindowPos(hWnd
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
713 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
716 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_AUTOPLAY
) {
717 return ANIMATE_Play(hWnd
, -1, (LPARAM
)MAKELONG(0, infoPtr
->mah
.dwTotalFrames
-1));
724 /* << ANIMATE_Open32W >> */
726 static LRESULT
ANIMATE_Stop(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
728 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
734 ANIMATE_DoStop(infoPtr
);
739 static LRESULT
ANIMATE_Create(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
741 ANIMATE_INFO
* infoPtr
;
743 if (!fnIC
.hModule
) /* FIXME: not thread safe */
745 /* since there's a circular dep between msvfw32 and comctl32, we could either:
746 * - fix the build chain to allow this circular dep
747 * - handle it by hand
748 * AJ wants the latter :-(
750 fnIC
.hModule
= LoadLibraryA("msvfw32.dll");
751 if (!fnIC
.hModule
) return FALSE
;
753 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
754 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
755 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
756 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
759 /* allocate memory for info structure */
760 infoPtr
= (ANIMATE_INFO
*)COMCTL32_Alloc(sizeof(ANIMATE_INFO
));
762 ERR("could not allocate info memory!\n");
766 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd
, GWL_STYLE
), (DWORD
)GetParent(hWnd
));
768 /* store crossref hWnd <-> info structure */
769 SetWindowLongA(hWnd
, 0, (DWORD
)infoPtr
);
770 infoPtr
->hWnd
= hWnd
;
771 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
772 infoPtr
->hbmPrevFrame
= 0;
774 InitializeCriticalSection(&infoPtr
->cs
);
780 static LRESULT
ANIMATE_Destroy(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
782 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
786 ANIMATE_Free(infoPtr
);
788 /* free animate info data */
789 COMCTL32_Free(infoPtr
);
790 SetWindowLongA(hWnd
, 0, 0);
796 static LRESULT
ANIMATE_EraseBackground(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
801 if(GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
803 hBrush
= SendMessageA(GetParent(hWnd
),WM_CTLCOLORSTATIC
,(HDC
)wParam
, hWnd
);
806 GetClientRect(hWnd
, &rect
);
807 FillRect((HDC
)wParam
, &rect
, hBrush
? hBrush
: GetCurrentObject((HDC
)wParam
, OBJ_BRUSH
));
812 static LRESULT WINAPI
ANIMATE_Size(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
814 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_CENTER
) {
815 InvalidateRect(hWnd
, NULL
, TRUE
);
820 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
822 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hWnd
, uMsg
, wParam
, lParam
);
823 if (!ANIMATE_GetInfoPtr(hWnd
) && (uMsg
!= WM_NCCREATE
))
824 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
828 return ANIMATE_OpenA(hWnd
, wParam
, lParam
);
830 /* case ACM_OPEN32W: FIXME!! */
831 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
834 return ANIMATE_Play(hWnd
, wParam
, lParam
);
837 return ANIMATE_Stop(hWnd
, wParam
, lParam
);
840 ANIMATE_Create(hWnd
, wParam
, lParam
);
841 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
844 return HTTRANSPARENT
;
847 ANIMATE_Destroy(hWnd
, wParam
, lParam
);
848 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
851 ANIMATE_EraseBackground(hWnd
, wParam
, lParam
);
854 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
857 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
859 ANIMATE_INFO
* infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
860 infoPtr
->hbrushBG
= SendMessageA(GetParent(hWnd
),WM_CTLCOLORSTATIC
,(HDC
)wParam
, hWnd
);
862 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd
));
865 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd
));
870 ANIMATE_INFO
* infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
872 /* the animation isn't playing, don't paint */
873 if(!infoPtr
->uTimer
&& !infoPtr
->hThread
)
874 /* default paint handling */
875 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
877 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
878 infoPtr
->hbrushBG
= SendMessageA(GetParent(hWnd
), WM_CTLCOLORSTATIC
,
883 EnterCriticalSection(&infoPtr
->cs
);
884 ANIMATE_PaintFrame(infoPtr
, (HDC
)wParam
);
885 LeaveCriticalSection(&infoPtr
->cs
);
890 HDC hDC
= BeginPaint(hWnd
, &ps
);
892 EnterCriticalSection(&infoPtr
->cs
);
893 ANIMATE_PaintFrame(infoPtr
, hDC
);
894 LeaveCriticalSection(&infoPtr
->cs
);
902 ANIMATE_Size(hWnd
, wParam
, lParam
);
903 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
907 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
909 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
914 void ANIMATE_Register(void)
918 ZeroMemory(&wndClass
, sizeof(WNDCLASSA
));
919 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
920 wndClass
.lpfnWndProc
= (WNDPROC
)ANIMATE_WindowProc
;
921 wndClass
.cbClsExtra
= 0;
922 wndClass
.cbWndExtra
= sizeof(ANIMATE_INFO
*);
923 wndClass
.hCursor
= LoadCursorA(0, IDC_ARROWA
);
924 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
925 wndClass
.lpszClassName
= ANIMATE_CLASSA
;
927 RegisterClassA(&wndClass
);
931 void ANIMATE_Unregister(void)
933 UnregisterClassA(ANIMATE_CLASSA
, (HINSTANCE
)NULL
);