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
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(animate
);
42 HIC (WINAPI
*fnICOpen
)(DWORD
, DWORD
, UINT
);
43 LRESULT (WINAPI
*fnICClose
)(HIC
);
44 LRESULT (WINAPI
*fnICSendMessage
)(HIC
, UINT
, DWORD
, DWORD
);
45 DWORD (WINAPIV
*fnICDecompress
)(HIC
,DWORD
,LPBITMAPINFOHEADER
,LPVOID
,LPBITMAPINFOHEADER
,LPVOID
);
50 /* reference to input stream (file or resource) */
52 HMMIO hMMio
; /* handle to mmio stream */
54 /* information on the loaded AVI file */
57 LPBITMAPINFOHEADER inbih
;
59 /* data for the decompressor */
61 LPBITMAPINFOHEADER outbih
;
64 /* data for the background mechanism */
68 /* data for playing the file */
74 COLORREF transparentColor
;
79 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
80 #define ANIMATE_COLOR_NONE 0xffffffff
82 static void ANIMATE_Notify(ANIMATE_INFO
* infoPtr
, UINT notif
)
84 SendMessageA(GetParent(infoPtr
->hWnd
), WM_COMMAND
,
85 MAKEWPARAM(GetDlgCtrlID(infoPtr
->hWnd
), notif
),
86 (LPARAM
)infoPtr
->hWnd
);
89 static BOOL
ANIMATE_LoadResA(ANIMATE_INFO
*infoPtr
, HINSTANCE hInst
, LPSTR lpName
)
95 hrsrc
= FindResourceA(hInst
, lpName
, "AVI");
99 infoPtr
->hRes
= LoadResource(hInst
, hrsrc
);
103 lpAvi
= LockResource(infoPtr
->hRes
);
107 memset(&mminfo
, 0, sizeof(mminfo
));
108 mminfo
.fccIOProc
= FOURCC_MEM
;
109 mminfo
.pchBuffer
= (LPSTR
)lpAvi
;
110 mminfo
.cchBuffer
= SizeofResource(hInst
, hrsrc
);
111 infoPtr
->hMMio
= mmioOpenA(NULL
, &mminfo
, MMIO_READ
);
112 if (!infoPtr
->hMMio
) {
113 GlobalFree((HGLOBAL
)lpAvi
);
121 static BOOL
ANIMATE_LoadFileA(ANIMATE_INFO
*infoPtr
, LPSTR lpName
)
123 infoPtr
->hMMio
= mmioOpenA((LPSTR
)lpName
, NULL
,
124 MMIO_ALLOCBUF
| MMIO_READ
| MMIO_DENYWRITE
);
133 static LRESULT
ANIMATE_DoStop(ANIMATE_INFO
*infoPtr
)
135 EnterCriticalSection(&infoPtr
->cs
);
137 /* should stop playing */
138 if (infoPtr
->hThread
)
140 if (!TerminateThread(infoPtr
->hThread
,0))
141 WARN("could not destroy animation thread!\n");
142 infoPtr
->hThread
= 0;
144 if (infoPtr
->uTimer
) {
145 KillTimer(infoPtr
->hWnd
, infoPtr
->uTimer
);
149 LeaveCriticalSection(&infoPtr
->cs
);
151 ANIMATE_Notify(infoPtr
, ACN_STOP
);
157 static void ANIMATE_Free(ANIMATE_INFO
*infoPtr
)
159 if (infoPtr
->hMMio
) {
160 ANIMATE_DoStop(infoPtr
);
161 mmioClose(infoPtr
->hMMio
, 0);
163 FreeResource(infoPtr
->hRes
);
166 if (infoPtr
->lpIndex
) {
167 HeapFree(GetProcessHeap(), 0, infoPtr
->lpIndex
);
168 infoPtr
->lpIndex
= NULL
;
171 fnIC
.fnICClose(infoPtr
->hic
);
174 if (infoPtr
->inbih
) {
175 HeapFree(GetProcessHeap(), 0, infoPtr
->inbih
);
176 infoPtr
->inbih
= NULL
;
178 if (infoPtr
->outbih
) {
179 HeapFree(GetProcessHeap(), 0, infoPtr
->outbih
);
180 infoPtr
->outbih
= NULL
;
182 if( infoPtr
->indata
)
184 HeapFree(GetProcessHeap(), 0, infoPtr
->indata
);
185 infoPtr
->indata
= NULL
;
187 if( infoPtr
->outdata
)
189 HeapFree(GetProcessHeap(), 0, infoPtr
->outdata
);
190 infoPtr
->outdata
= NULL
;
192 if( infoPtr
->hbmPrevFrame
)
194 DeleteObject(infoPtr
->hbmPrevFrame
);
195 infoPtr
->hbmPrevFrame
= 0;
197 infoPtr
->indata
= infoPtr
->outdata
= NULL
;
201 memset(&infoPtr
->mah
, 0, sizeof(infoPtr
->mah
));
202 memset(&infoPtr
->ash
, 0, sizeof(infoPtr
->ash
));
203 infoPtr
->nFromFrame
= infoPtr
->nToFrame
= infoPtr
->nLoop
= infoPtr
->currFrame
= 0;
205 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
208 static void ANIMATE_TransparentBlt(ANIMATE_INFO
* infoPtr
, HDC hdcDest
, HDC hdcSource
)
214 /* create a transparency mask */
215 hdcMask
= CreateCompatibleDC(hdcDest
);
216 hbmMask
= CreateBitmap(infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, 1,1,NULL
);
217 hbmOld
= SelectObject(hdcMask
, hbmMask
);
219 SetBkColor(hdcSource
,infoPtr
->transparentColor
);
220 BitBlt(hdcMask
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCCOPY
);
222 /* mask the source bitmap */
223 SetBkColor(hdcSource
, RGB(0,0,0));
224 SetTextColor(hdcSource
, RGB(255,255,255));
225 BitBlt(hdcSource
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
227 /* mask the destination bitmap */
228 SetBkColor(hdcDest
, RGB(255,255,255));
229 SetTextColor(hdcDest
, RGB(0,0,0));
230 BitBlt(hdcDest
, 0, 0, infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
, hdcMask
, 0, 0, SRCAND
);
232 /* combine source and destination */
233 BitBlt(hdcDest
,0,0,infoPtr
->inbih
->biWidth
, infoPtr
->inbih
->biHeight
,hdcSource
,0,0,SRCPAINT
);
235 SelectObject(hdcMask
, hbmOld
);
236 DeleteObject(hbmMask
);
240 static LRESULT
ANIMATE_PaintFrame(ANIMATE_INFO
* infoPtr
, HDC hDC
)
242 void* pBitmapData
= NULL
;
243 LPBITMAPINFO pBitmapInfo
= NULL
;
254 if (!hDC
|| !infoPtr
->inbih
)
259 pBitmapData
= infoPtr
->outdata
;
260 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->outbih
;
262 nWidth
= infoPtr
->outbih
->biWidth
;
263 nHeight
= infoPtr
->outbih
->biHeight
;
266 pBitmapData
= infoPtr
->indata
;
267 pBitmapInfo
= (LPBITMAPINFO
)infoPtr
->inbih
;
269 nWidth
= infoPtr
->inbih
->biWidth
;
270 nHeight
= infoPtr
->inbih
->biHeight
;
273 if(!infoPtr
->hbmPrevFrame
)
275 infoPtr
->hbmPrevFrame
=CreateCompatibleBitmap(hDC
, nWidth
,nHeight
);
278 SetDIBits(hDC
, infoPtr
->hbmPrevFrame
, 0, nHeight
, pBitmapData
, (LPBITMAPINFO
)pBitmapInfo
, DIB_RGB_COLORS
);
280 hdcMem
= CreateCompatibleDC(hDC
);
281 hbmOld
= SelectObject(hdcMem
, infoPtr
->hbmPrevFrame
);
284 * we need to get the transparent color even without ACS_TRANSPARENT,
285 * because the style can be changed later on and the color should always
286 * be obtained in the first frame
288 if(infoPtr
->transparentColor
== ANIMATE_COLOR_NONE
)
290 infoPtr
->transparentColor
= GetPixel(hdcMem
,0,0);
293 if(GetWindowLongA(infoPtr
->hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
295 HDC hdcFinal
= CreateCompatibleDC(hDC
);
296 HBITMAP hbmFinal
= CreateCompatibleBitmap(hDC
,nWidth
, nHeight
);
297 HBITMAP hbmOld2
= SelectObject(hdcFinal
, hbmFinal
);
303 rect
.bottom
= nHeight
;
305 if(!infoPtr
->hbrushBG
)
306 infoPtr
->hbrushBG
= GetCurrentObject(hDC
, OBJ_BRUSH
);
308 FillRect(hdcFinal
, &rect
, infoPtr
->hbrushBG
);
309 ANIMATE_TransparentBlt(infoPtr
, hdcFinal
, hdcMem
);
311 SelectObject(hdcFinal
, hbmOld2
);
312 SelectObject(hdcMem
, hbmFinal
);
314 DeleteObject(infoPtr
->hbmPrevFrame
);
315 infoPtr
->hbmPrevFrame
= hbmFinal
;
318 if (GetWindowLongA(infoPtr
->hWnd
, GWL_STYLE
) & ACS_CENTER
)
322 GetWindowRect(infoPtr
->hWnd
, &rect
);
323 nOffsetX
= ((rect
.right
- rect
.left
) - nWidth
)/2;
324 nOffsetY
= ((rect
.bottom
- rect
.top
) - nHeight
)/2;
326 BitBlt(hDC
, nOffsetX
, nOffsetY
, nWidth
, nHeight
, hdcMem
, 0, 0, SRCCOPY
);
328 SelectObject(hdcMem
, hbmOld
);
333 static LRESULT
ANIMATE_DrawFrame(ANIMATE_INFO
* infoPtr
)
337 TRACE("Drawing frame %d (loop %d)\n", infoPtr
->currFrame
, infoPtr
->nLoop
);
339 EnterCriticalSection(&infoPtr
->cs
);
341 mmioSeek(infoPtr
->hMMio
, infoPtr
->lpIndex
[infoPtr
->currFrame
], SEEK_SET
);
342 mmioRead(infoPtr
->hMMio
, infoPtr
->indata
, infoPtr
->ash
.dwSuggestedBufferSize
);
345 fnIC
.fnICDecompress(infoPtr
->hic
, 0, infoPtr
->inbih
, infoPtr
->indata
,
346 infoPtr
->outbih
, infoPtr
->outdata
) != ICERR_OK
) {
347 LeaveCriticalSection(&infoPtr
->cs
);
348 WARN("Decompression error\n");
352 if ((hDC
= GetDC(infoPtr
->hWnd
)) != 0) {
353 ANIMATE_PaintFrame(infoPtr
, hDC
);
354 ReleaseDC(infoPtr
->hWnd
, hDC
);
357 if (infoPtr
->currFrame
++ >= infoPtr
->nToFrame
) {
358 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
359 if (infoPtr
->nLoop
!= -1) {
360 if (--infoPtr
->nLoop
== 0) {
361 ANIMATE_DoStop(infoPtr
);
365 LeaveCriticalSection(&infoPtr
->cs
);
370 static DWORD CALLBACK
ANIMATE_AnimationThread(LPVOID ptr_
)
372 ANIMATE_INFO
* infoPtr
= (ANIMATE_INFO
*)ptr_
;
377 WARN("animation structure undefined!\n");
383 if(GetWindowLongA(infoPtr
->hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
385 hDC
= GetDC(infoPtr
->hWnd
);
386 /* sometimes the animation window will be destroyed in between
387 * by the main program, so a ReleaseDC() error msg is possible */
388 infoPtr
->hbrushBG
= SendMessageA(GetParent(infoPtr
->hWnd
),
389 WM_CTLCOLORSTATIC
, hDC
,
390 (LPARAM
)infoPtr
->hWnd
);
391 ReleaseDC(infoPtr
->hWnd
,hDC
);
394 EnterCriticalSection(&infoPtr
->cs
);
395 ANIMATE_DrawFrame(infoPtr
);
396 LeaveCriticalSection(&infoPtr
->cs
);
398 /* time is in microseconds, we should convert it to milliseconds */
399 Sleep((infoPtr
->mah
.dwMicroSecPerFrame
+500)/1000);
404 static LRESULT
ANIMATE_Play(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
406 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
412 if (infoPtr
->hThread
|| infoPtr
->uTimer
) {
413 FIXME("Already playing ? what should I do ??\n");
414 ANIMATE_DoStop(infoPtr
);
417 infoPtr
->nFromFrame
= (INT
)LOWORD(lParam
);
418 infoPtr
->nToFrame
= (INT
)HIWORD(lParam
);
419 infoPtr
->nLoop
= (INT
)wParam
;
421 if (infoPtr
->nToFrame
== 0xFFFF)
422 infoPtr
->nToFrame
= infoPtr
->mah
.dwTotalFrames
- 1;
424 TRACE("(repeat=%d from=%d to=%d);\n",
425 infoPtr
->nLoop
, infoPtr
->nFromFrame
, infoPtr
->nToFrame
);
427 if (infoPtr
->nFromFrame
>= infoPtr
->nToFrame
||
428 infoPtr
->nToFrame
>= infoPtr
->mah
.dwTotalFrames
)
431 infoPtr
->currFrame
= infoPtr
->nFromFrame
;
433 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TIMER
) {
434 TRACE("Using a timer\n");
435 /* create a timer to display AVI */
436 infoPtr
->uTimer
= SetTimer(hWnd
, 1, infoPtr
->mah
.dwMicroSecPerFrame
/ 1000, NULL
);
440 TRACE("Using an animation thread\n");
441 infoPtr
->hThread
= CreateThread(0,0,ANIMATE_AnimationThread
,(LPVOID
)infoPtr
,0,0 &threadID
);
442 if(!infoPtr
->hThread
)
444 ERR("Could not create animation thread!\n");
450 ANIMATE_Notify(infoPtr
, ACN_START
);
456 static BOOL
ANIMATE_GetAviInfo(ANIMATE_INFO
*infoPtr
)
465 if (mmioDescend(infoPtr
->hMMio
, &ckMainRIFF
, NULL
, 0) != 0) {
466 WARN("Can't find 'RIFF' chunk\n");
470 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) ||
471 (ckMainRIFF
.fccType
!= mmioFOURCC('A', 'V', 'I', ' '))) {
472 WARN("Can't find 'AVI ' chunk\n");
476 mmckHead
.fccType
= mmioFOURCC('h', 'd', 'r', 'l');
477 if (mmioDescend(infoPtr
->hMMio
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
478 WARN("Can't find 'hdrl' list\n");
482 mmckInfo
.ckid
= mmioFOURCC('a', 'v', 'i', 'h');
483 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
484 WARN("Can't find 'avih' chunk\n");
488 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->mah
, sizeof(infoPtr
->mah
));
490 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr
->mah
.dwMicroSecPerFrame
);
491 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr
->mah
.dwMaxBytesPerSec
);
492 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr
->mah
.dwPaddingGranularity
);
493 TRACE("mah.dwFlags=%ld\n", infoPtr
->mah
.dwFlags
);
494 TRACE("mah.dwTotalFrames=%ld\n", infoPtr
->mah
.dwTotalFrames
);
495 TRACE("mah.dwInitialFrames=%ld\n", infoPtr
->mah
.dwInitialFrames
);
496 TRACE("mah.dwStreams=%ld\n", infoPtr
->mah
.dwStreams
);
497 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr
->mah
.dwSuggestedBufferSize
);
498 TRACE("mah.dwWidth=%ld\n", infoPtr
->mah
.dwWidth
);
499 TRACE("mah.dwHeight=%ld\n", infoPtr
->mah
.dwHeight
);
501 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
503 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
504 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0) {
505 WARN("Can't find 'strl' list\n");
509 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'h');
510 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
511 WARN("Can't find 'strh' chunk\n");
515 mmioRead(infoPtr
->hMMio
, (LPSTR
)&infoPtr
->ash
, sizeof(infoPtr
->ash
));
517 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccType
)),
518 HIBYTE(LOWORD(infoPtr
->ash
.fccType
)),
519 LOBYTE(HIWORD(infoPtr
->ash
.fccType
)),
520 HIBYTE(HIWORD(infoPtr
->ash
.fccType
)));
521 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
522 HIBYTE(LOWORD(infoPtr
->ash
.fccHandler
)),
523 LOBYTE(HIWORD(infoPtr
->ash
.fccHandler
)),
524 HIBYTE(HIWORD(infoPtr
->ash
.fccHandler
)));
525 TRACE("ash.dwFlags=%ld\n", infoPtr
->ash
.dwFlags
);
526 TRACE("ash.wPriority=%d\n", infoPtr
->ash
.wPriority
);
527 TRACE("ash.wLanguage=%d\n", infoPtr
->ash
.wLanguage
);
528 TRACE("ash.dwInitialFrames=%ld\n", infoPtr
->ash
.dwInitialFrames
);
529 TRACE("ash.dwScale=%ld\n", infoPtr
->ash
.dwScale
);
530 TRACE("ash.dwRate=%ld\n", infoPtr
->ash
.dwRate
);
531 TRACE("ash.dwStart=%ld\n", infoPtr
->ash
.dwStart
);
532 TRACE("ash.dwLength=%ld\n", infoPtr
->ash
.dwLength
);
533 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr
->ash
.dwSuggestedBufferSize
);
534 TRACE("ash.dwQuality=%ld\n", infoPtr
->ash
.dwQuality
);
535 TRACE("ash.dwSampleSize=%ld\n", infoPtr
->ash
.dwSampleSize
);
536 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr
->ash
.rcFrame
.top
, infoPtr
->ash
.rcFrame
.left
,
537 infoPtr
->ash
.rcFrame
.bottom
, infoPtr
->ash
.rcFrame
.right
);
539 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
541 mmckInfo
.ckid
= mmioFOURCC('s', 't', 'r', 'f');
542 if (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, MMIO_FINDCHUNK
) != 0) {
543 WARN("Can't find 'strh' chunk\n");
547 infoPtr
->inbih
= HeapAlloc(GetProcessHeap(), 0, mmckInfo
.cksize
);
548 if (!infoPtr
->inbih
) {
549 WARN("Can't alloc input BIH\n");
553 mmioRead(infoPtr
->hMMio
, (LPSTR
)infoPtr
->inbih
, mmckInfo
.cksize
);
555 TRACE("bih.biSize=%ld\n", infoPtr
->inbih
->biSize
);
556 TRACE("bih.biWidth=%ld\n", infoPtr
->inbih
->biWidth
);
557 TRACE("bih.biHeight=%ld\n", infoPtr
->inbih
->biHeight
);
558 TRACE("bih.biPlanes=%d\n", infoPtr
->inbih
->biPlanes
);
559 TRACE("bih.biBitCount=%d\n", infoPtr
->inbih
->biBitCount
);
560 TRACE("bih.biCompression=%ld\n", infoPtr
->inbih
->biCompression
);
561 TRACE("bih.biSizeImage=%ld\n", infoPtr
->inbih
->biSizeImage
);
562 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr
->inbih
->biXPelsPerMeter
);
563 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr
->inbih
->biYPelsPerMeter
);
564 TRACE("bih.biClrUsed=%ld\n", infoPtr
->inbih
->biClrUsed
);
565 TRACE("bih.biClrImportant=%ld\n", infoPtr
->inbih
->biClrImportant
);
567 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
569 mmioAscend(infoPtr
->hMMio
, &mmckList
, 0);
572 /* an AVI has 0 or 1 video stream, and to be animated should not contain
573 * an audio stream, so only one strl is allowed
575 mmckList
.fccType
= mmioFOURCC('s', 't', 'r', 'l');
576 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) == 0) {
577 WARN("There should be a single 'strl' list\n");
582 mmioAscend(infoPtr
->hMMio
, &mmckHead
, 0);
584 /* no need to read optional JUNK chunk */
586 mmckList
.fccType
= mmioFOURCC('m', 'o', 'v', 'i');
587 if (mmioDescend(infoPtr
->hMMio
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
588 WARN("Can't find 'movi' list\n");
592 /* FIXME: should handle the 'rec ' LIST when present */
594 infoPtr
->lpIndex
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
595 infoPtr
->mah
.dwTotalFrames
* sizeof(DWORD
));
596 if (!infoPtr
->lpIndex
) {
597 WARN("Can't alloc index array\n");
601 numFrame
= insize
= 0;
602 while (mmioDescend(infoPtr
->hMMio
, &mmckInfo
, &mmckList
, 0) == 0 &&
603 numFrame
< infoPtr
->mah
.dwTotalFrames
) {
604 infoPtr
->lpIndex
[numFrame
] = mmckInfo
.dwDataOffset
;
605 if (insize
< mmckInfo
.cksize
)
606 insize
= mmckInfo
.cksize
;
608 mmioAscend(infoPtr
->hMMio
, &mmckInfo
, 0);
610 if (numFrame
!= infoPtr
->mah
.dwTotalFrames
) {
611 WARN("Found %ld frames (/%ld)\n", numFrame
, infoPtr
->mah
.dwTotalFrames
);
614 if (insize
> infoPtr
->ash
.dwSuggestedBufferSize
) {
615 WARN("insize=%ld suggestedSize=%ld\n", insize
, infoPtr
->ash
.dwSuggestedBufferSize
);
616 infoPtr
->ash
.dwSuggestedBufferSize
= insize
;
619 infoPtr
->indata
= HeapAlloc(GetProcessHeap(), 0, infoPtr
->ash
.dwSuggestedBufferSize
);
620 if (!infoPtr
->indata
) {
621 WARN("Can't alloc input buffer\n");
629 static BOOL
ANIMATE_GetAviCodec(ANIMATE_INFO
*infoPtr
)
633 /* check uncompressed AVI */
634 if ((infoPtr
->ash
.fccHandler
== mmioFOURCC('D', 'I', 'B', ' ')) ||
635 (infoPtr
->ash
.fccHandler
== mmioFOURCC('R', 'L', 'E', ' ')) ||
636 (infoPtr
->ash
.fccHandler
== mmioFOURCC(0, 0, 0, 0)))
642 /* try to get a decompressor for that type */
643 infoPtr
->hic
= fnIC
.fnICOpen(ICTYPE_VIDEO
, infoPtr
->ash
.fccHandler
, ICMODE_DECOMPRESS
);
645 WARN("Can't load codec for the file\n");
649 outSize
= fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
650 (DWORD
)infoPtr
->inbih
, 0L);
652 infoPtr
->outbih
= HeapAlloc(GetProcessHeap(), 0, outSize
);
653 if (!infoPtr
->outbih
) {
654 WARN("Can't alloc output BIH\n");
658 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_GET_FORMAT
,
659 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != ICERR_OK
) {
660 WARN("Can't get output BIH\n");
664 infoPtr
->outdata
= HeapAlloc(GetProcessHeap(), 0, infoPtr
->outbih
->biSizeImage
);
665 if (!infoPtr
->outdata
) {
666 WARN("Can't alloc output buffer\n");
670 if (fnIC
.fnICSendMessage(infoPtr
->hic
, ICM_DECOMPRESS_BEGIN
,
671 (DWORD
)infoPtr
->inbih
, (DWORD
)infoPtr
->outbih
) != ICERR_OK
) {
672 WARN("Can't begin decompression\n");
679 static LRESULT
ANIMATE_OpenA(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
681 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
682 HINSTANCE hInstance
= (HINSTANCE
)wParam
;
684 ANIMATE_Free(infoPtr
);
685 infoPtr
->hWnd
= hWnd
;
688 TRACE("Closing avi!\n");
693 hInstance
= GetWindowLongA(hWnd
, GWL_HINSTANCE
);
695 if (HIWORD(lParam
)) {
696 TRACE("(\"%s\");\n", (LPSTR
)lParam
);
698 if (!ANIMATE_LoadResA(infoPtr
, hInstance
, (LPSTR
)lParam
)) {
699 TRACE("No AVI resource found!\n");
700 if (!ANIMATE_LoadFileA(infoPtr
, (LPSTR
)lParam
)) {
701 WARN("No AVI file found!\n");
706 TRACE("(%u);\n", (WORD
)LOWORD(lParam
));
708 if (!ANIMATE_LoadResA(infoPtr
, hInstance
,
709 MAKEINTRESOURCEA((INT
)lParam
))) {
710 WARN("No AVI resource found!\n");
715 if (!ANIMATE_GetAviInfo(infoPtr
)) {
716 WARN("Can't get AVI information\n");
717 ANIMATE_Free(infoPtr
);
721 if (!ANIMATE_GetAviCodec(infoPtr
)) {
722 WARN("Can't get AVI Codec\n");
723 ANIMATE_Free(infoPtr
);
727 if (!GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_CENTER
) {
728 SetWindowPos(hWnd
, 0, 0, 0, infoPtr
->mah
.dwWidth
, infoPtr
->mah
.dwHeight
,
729 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
732 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_AUTOPLAY
) {
733 return ANIMATE_Play(hWnd
, -1, (LPARAM
)MAKELONG(0, infoPtr
->mah
.dwTotalFrames
-1));
740 /* << ANIMATE_Open32W >> */
742 static LRESULT
ANIMATE_Stop(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
744 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
750 ANIMATE_DoStop(infoPtr
);
755 static LRESULT
ANIMATE_Create(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
757 ANIMATE_INFO
* infoPtr
;
759 if (!fnIC
.hModule
) /* FIXME: not thread safe */
761 /* since there's a circular dep between msvfw32 and comctl32, we could either:
762 * - fix the build chain to allow this circular dep
763 * - handle it by hand
764 * AJ wants the latter :-(
766 fnIC
.hModule
= LoadLibraryA("msvfw32.dll");
767 if (!fnIC
.hModule
) return FALSE
;
769 fnIC
.fnICOpen
= (void*)GetProcAddress(fnIC
.hModule
, "ICOpen");
770 fnIC
.fnICClose
= (void*)GetProcAddress(fnIC
.hModule
, "ICClose");
771 fnIC
.fnICSendMessage
= (void*)GetProcAddress(fnIC
.hModule
, "ICSendMessage");
772 fnIC
.fnICDecompress
= (void*)GetProcAddress(fnIC
.hModule
, "ICDecompress");
775 /* allocate memory for info structure */
776 infoPtr
= (ANIMATE_INFO
*)COMCTL32_Alloc(sizeof(ANIMATE_INFO
));
778 ERR("could not allocate info memory!\n");
782 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd
, GWL_STYLE
), (DWORD
)GetParent(hWnd
));
784 /* store crossref hWnd <-> info structure */
785 SetWindowLongA(hWnd
, 0, (DWORD
)infoPtr
);
786 infoPtr
->hWnd
= hWnd
;
787 infoPtr
->transparentColor
= ANIMATE_COLOR_NONE
;
788 infoPtr
->hbmPrevFrame
= 0;
790 InitializeCriticalSection(&infoPtr
->cs
);
796 static LRESULT
ANIMATE_Destroy(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
798 ANIMATE_INFO
*infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
802 ANIMATE_Free(infoPtr
);
804 /* free animate info data */
805 COMCTL32_Free(infoPtr
);
806 SetWindowLongA(hWnd
, 0, 0);
812 static LRESULT
ANIMATE_EraseBackground(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
817 if(GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
819 hBrush
= SendMessageA(GetParent(hWnd
),WM_CTLCOLORSTATIC
,(HDC
)wParam
,
823 GetClientRect(hWnd
, &rect
);
824 FillRect((HDC
)wParam
, &rect
, hBrush
? hBrush
: GetCurrentObject((HDC
)wParam
, OBJ_BRUSH
));
829 static LRESULT WINAPI
ANIMATE_Size(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
831 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_CENTER
) {
832 InvalidateRect(hWnd
, NULL
, TRUE
);
837 static LRESULT WINAPI
ANIMATE_WindowProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
839 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hWnd
, uMsg
, wParam
, lParam
);
840 if (!ANIMATE_GetInfoPtr(hWnd
) && (uMsg
!= WM_NCCREATE
))
841 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
845 return ANIMATE_OpenA(hWnd
, wParam
, lParam
);
847 /* case ACM_OPEN32W: FIXME!! */
848 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
851 return ANIMATE_Play(hWnd
, wParam
, lParam
);
854 return ANIMATE_Stop(hWnd
, wParam
, lParam
);
857 ANIMATE_Create(hWnd
, wParam
, lParam
);
858 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
861 return HTTRANSPARENT
;
864 ANIMATE_Destroy(hWnd
, wParam
, lParam
);
865 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
868 ANIMATE_EraseBackground(hWnd
, wParam
, lParam
);
871 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
874 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
876 ANIMATE_INFO
* infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
877 infoPtr
->hbrushBG
= SendMessageA(GetParent(hWnd
), WM_CTLCOLORSTATIC
,
878 (HDC
)wParam
, (LPARAM
)hWnd
);
880 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd
));
883 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd
));
888 ANIMATE_INFO
* infoPtr
= ANIMATE_GetInfoPtr(hWnd
);
890 /* the animation isn't playing, don't paint */
891 if(!infoPtr
->uTimer
&& !infoPtr
->hThread
)
892 /* default paint handling */
893 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
895 if (GetWindowLongA(hWnd
, GWL_STYLE
) & ACS_TRANSPARENT
)
896 infoPtr
->hbrushBG
= SendMessageA(GetParent(hWnd
), WM_CTLCOLORSTATIC
,
897 (HDC
)wParam
, (LPARAM
)hWnd
);
901 EnterCriticalSection(&infoPtr
->cs
);
902 ANIMATE_PaintFrame(infoPtr
, (HDC
)wParam
);
903 LeaveCriticalSection(&infoPtr
->cs
);
908 HDC hDC
= BeginPaint(hWnd
, &ps
);
910 EnterCriticalSection(&infoPtr
->cs
);
911 ANIMATE_PaintFrame(infoPtr
, hDC
);
912 LeaveCriticalSection(&infoPtr
->cs
);
920 ANIMATE_Size(hWnd
, wParam
, lParam
);
921 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
924 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
925 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
927 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
932 void ANIMATE_Register(void)
936 ZeroMemory(&wndClass
, sizeof(WNDCLASSA
));
937 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
938 wndClass
.lpfnWndProc
= (WNDPROC
)ANIMATE_WindowProc
;
939 wndClass
.cbClsExtra
= 0;
940 wndClass
.cbWndExtra
= sizeof(ANIMATE_INFO
*);
941 wndClass
.hCursor
= LoadCursorA(0, IDC_ARROWA
);
942 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
943 wndClass
.lpszClassName
= ANIMATE_CLASSA
;
945 RegisterClassA(&wndClass
);
949 void ANIMATE_Unregister(void)
951 UnregisterClassA(ANIMATE_CLASSA
, (HINSTANCE
)NULL
);