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 */
78 /* data for playing the file */
84 COLORREF transparentColor;
89 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongPtrW(hWnd, 0))
90 #define ANIMATE_COLOR_NONE 0xffffffff
92 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
94 SendMessageA(infoPtr->hwndNotify, WM_COMMAND,
95 MAKEWPARAM(GetDlgCtrlID(infoPtr->hwndSelf), notif),
96 (LPARAM)infoPtr->hwndSelf);
99 static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
105 hrsrc = FindResourceA(hInst, lpName, "AVI");
109 infoPtr->hRes = LoadResource(hInst, hrsrc);
113 lpAvi = LockResource(infoPtr->hRes);
117 memset(&mminfo, 0, sizeof(mminfo));
118 mminfo.fccIOProc = FOURCC_MEM;
119 mminfo.pchBuffer = (LPSTR)lpAvi;
120 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
121 infoPtr->hMMio = mmioOpenA(NULL, &mminfo, MMIO_READ);
122 if (!infoPtr->hMMio) {
123 FreeResource(infoPtr->hRes);
131 static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
133 infoPtr->hMMio = mmioOpenA((LPSTR)lpName, NULL,
134 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
143 static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
145 EnterCriticalSection(&infoPtr->cs);
147 /* should stop playing */
148 if (infoPtr->hThread)
150 HANDLE handle = infoPtr->hThread;
152 TRACE("stopping animation thread\n");
153 infoPtr->hThread = 0;
154 SetEvent( infoPtr->hStopEvent );
156 if (infoPtr->threadId != GetCurrentThreadId())
158 LeaveCriticalSection(&infoPtr->cs); /* leave it a chance to run */
159 WaitForSingleObject( handle, INFINITE );
160 TRACE("animation thread stopped\n");
161 EnterCriticalSection(&infoPtr->cs);
164 CloseHandle( handle );
165 CloseHandle( infoPtr->hStopEvent );
166 infoPtr->hStopEvent = 0;
168 if (infoPtr->uTimer) {
169 KillTimer(infoPtr->hwndSelf, infoPtr->uTimer);
173 LeaveCriticalSection(&infoPtr->cs);
175 ANIMATE_Notify(infoPtr, ACN_STOP);
181 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
183 if (infoPtr->hMMio) {
184 ANIMATE_DoStop(infoPtr);
185 mmioClose(infoPtr->hMMio, 0);
187 FreeResource(infoPtr->hRes);
190 if (infoPtr->lpIndex) {
191 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
192 infoPtr->lpIndex = NULL;
195 fnIC.fnICClose(infoPtr->hic);
198 if (infoPtr->inbih) {
199 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
200 infoPtr->inbih = NULL;
202 if (infoPtr->outbih) {
203 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
204 infoPtr->outbih = NULL;
206 if( infoPtr->indata )
208 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
209 infoPtr->indata = NULL;
211 if( infoPtr->outdata )
213 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
214 infoPtr->outdata = NULL;
216 if( infoPtr->hbmPrevFrame )
218 DeleteObject(infoPtr->hbmPrevFrame);
219 infoPtr->hbmPrevFrame = 0;
221 infoPtr->indata = infoPtr->outdata = NULL;
222 infoPtr->hwndSelf = 0;
225 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
226 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
227 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
229 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
232 static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
238 /* create a transparency mask */
239 hdcMask = CreateCompatibleDC(hdcDest);
240 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
241 hbmOld = SelectObject(hdcMask, hbmMask);
243 SetBkColor(hdcSource,infoPtr->transparentColor);
244 BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
246 /* mask the source bitmap */
247 SetBkColor(hdcSource, RGB(0,0,0));
248 SetTextColor(hdcSource, RGB(255,255,255));
249 BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
251 /* mask the destination bitmap */
252 SetBkColor(hdcDest, RGB(255,255,255));
253 SetTextColor(hdcDest, RGB(0,0,0));
254 BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
256 /* combine source and destination */
257 BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
259 SelectObject(hdcMask, hbmOld);
260 DeleteObject(hbmMask);
264 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
266 void* pBitmapData = NULL;
267 LPBITMAPINFO pBitmapInfo = NULL;
278 if (!hDC || !infoPtr->inbih)
283 pBitmapData = infoPtr->outdata;
284 pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
286 nWidth = infoPtr->outbih->biWidth;
287 nHeight = infoPtr->outbih->biHeight;
290 pBitmapData = infoPtr->indata;
291 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
293 nWidth = infoPtr->inbih->biWidth;
294 nHeight = infoPtr->inbih->biHeight;
297 if(!infoPtr->hbmPrevFrame)
299 infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
302 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
304 hdcMem = CreateCompatibleDC(hDC);
305 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
308 * we need to get the transparent color even without ACS_TRANSPARENT,
309 * because the style can be changed later on and the color should always
310 * be obtained in the first frame
312 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
314 infoPtr->transparentColor = GetPixel(hdcMem,0,0);
317 if(GetWindowLongA(infoPtr->hwndSelf, GWL_STYLE) & ACS_TRANSPARENT)
319 HDC hdcFinal = CreateCompatibleDC(hDC);
320 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
321 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
327 rect.bottom = nHeight;
329 if(!infoPtr->hbrushBG)
330 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
332 FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
333 ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
335 SelectObject(hdcFinal, hbmOld2);
336 SelectObject(hdcMem, hbmFinal);
338 DeleteObject(infoPtr->hbmPrevFrame);
339 infoPtr->hbmPrevFrame = hbmFinal;
342 if (GetWindowLongA(infoPtr->hwndSelf, GWL_STYLE) & ACS_CENTER)
346 GetWindowRect(infoPtr->hwndSelf, &rect);
347 nOffsetX = ((rect.right - rect.left) - nWidth)/2;
348 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
350 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
352 SelectObject(hdcMem, hbmOld);
357 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
361 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
363 EnterCriticalSection(&infoPtr->cs);
365 mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
366 mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
369 fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
370 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
371 LeaveCriticalSection(&infoPtr->cs);
372 WARN("Decompression error\n");
376 if ((hDC = GetDC(infoPtr->hwndSelf)) != 0) {
377 ANIMATE_PaintFrame(infoPtr, hDC);
378 ReleaseDC(infoPtr->hwndSelf, hDC);
381 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
382 infoPtr->currFrame = infoPtr->nFromFrame;
383 if (infoPtr->nLoop != -1) {
384 if (--infoPtr->nLoop == 0) {
385 ANIMATE_DoStop(infoPtr);
389 LeaveCriticalSection(&infoPtr->cs);
394 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
396 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
402 EnterCriticalSection(&infoPtr->cs);
403 ANIMATE_DrawFrame(infoPtr);
404 timeout = infoPtr->mah.dwMicroSecPerFrame;
405 event = infoPtr->hStopEvent;
406 LeaveCriticalSection(&infoPtr->cs);
408 /* time is in microseconds, we should convert it to milliseconds */
409 if ((event == 0) || WaitForSingleObject( event, (timeout+500)/1000) == WAIT_OBJECT_0)
415 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
417 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
423 if (infoPtr->hThread || infoPtr->uTimer) {
424 TRACE("Already playing\n");
428 infoPtr->nFromFrame = (INT)LOWORD(lParam);
429 infoPtr->nToFrame = (INT)HIWORD(lParam);
430 infoPtr->nLoop = (INT)wParam;
432 if (infoPtr->nToFrame == 0xFFFF)
433 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
435 TRACE("(repeat=%d from=%d to=%d);\n",
436 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
438 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
439 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
442 infoPtr->currFrame = infoPtr->nFromFrame;
444 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
445 TRACE("Using a timer\n");
446 /* create a timer to display AVI */
447 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
449 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
451 infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
452 WM_CTLCOLORSTATIC, 0, (LPARAM)hWnd);
455 TRACE("Using an animation thread\n");
456 infoPtr->hStopEvent = CreateEventW( NULL, TRUE, FALSE, NULL );
457 infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr, 0, &infoPtr->threadId);
458 if(!infoPtr->hThread)
460 ERR("Could not create animation thread!\n");
466 ANIMATE_Notify(infoPtr, ACN_START);
472 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
481 if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
482 WARN("Can't find 'RIFF' chunk\n");
486 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
487 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
488 WARN("Can't find 'AVI ' chunk\n");
492 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
493 if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
494 WARN("Can't find 'hdrl' list\n");
498 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
499 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
500 WARN("Can't find 'avih' chunk\n");
504 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
506 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
507 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
508 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
509 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
510 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
511 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
512 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
513 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
514 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
515 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
517 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
519 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
520 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
521 WARN("Can't find 'strl' list\n");
525 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
526 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
527 WARN("Can't find 'strh' chunk\n");
531 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
533 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
534 HIBYTE(LOWORD(infoPtr->ash.fccType)),
535 LOBYTE(HIWORD(infoPtr->ash.fccType)),
536 HIBYTE(HIWORD(infoPtr->ash.fccType)));
537 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
538 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
539 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
540 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
541 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
542 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
543 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
544 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
545 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
546 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
547 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
548 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
549 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
550 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
551 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
552 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
553 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
555 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
557 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
558 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
559 WARN("Can't find 'strh' chunk\n");
563 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
564 if (!infoPtr->inbih) {
565 WARN("Can't alloc input BIH\n");
569 mmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
571 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
572 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
573 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
574 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
575 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
576 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
577 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
578 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
579 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
580 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
581 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
583 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
585 mmioAscend(infoPtr->hMMio, &mmckList, 0);
588 /* an AVI has 0 or 1 video stream, and to be animated should not contain
589 * an audio stream, so only one strl is allowed
591 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
592 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
593 WARN("There should be a single 'strl' list\n");
598 mmioAscend(infoPtr->hMMio, &mmckHead, 0);
600 /* no need to read optional JUNK chunk */
602 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
603 if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
604 WARN("Can't find 'movi' list\n");
608 /* FIXME: should handle the 'rec ' LIST when present */
610 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
611 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
612 if (!infoPtr->lpIndex) {
613 WARN("Can't alloc index array\n");
617 numFrame = insize = 0;
618 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
619 numFrame < infoPtr->mah.dwTotalFrames) {
620 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
621 if (insize < mmckInfo.cksize)
622 insize = mmckInfo.cksize;
624 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
626 if (numFrame != infoPtr->mah.dwTotalFrames) {
627 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
630 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
631 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
632 infoPtr->ash.dwSuggestedBufferSize = insize;
635 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
636 if (!infoPtr->indata) {
637 WARN("Can't alloc input buffer\n");
645 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
649 /* check uncompressed AVI */
650 if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
651 (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')) ||
652 (infoPtr->ash.fccHandler == mmioFOURCC(0, 0, 0, 0)))
658 /* try to get a decompressor for that type */
659 infoPtr->hic = fnIC.fnICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
661 WARN("Can't load codec for the file\n");
665 outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
666 (DWORD)infoPtr->inbih, 0L);
668 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
669 if (!infoPtr->outbih) {
670 WARN("Can't alloc output BIH\n");
674 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
675 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != outSize) {
676 WARN("Can't get output BIH\n");
680 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
681 if (!infoPtr->outdata) {
682 WARN("Can't alloc output buffer\n");
686 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
687 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
688 WARN("Can't begin decompression\n");
695 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
697 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
698 HINSTANCE hInstance = (HINSTANCE)wParam;
700 ANIMATE_Free(infoPtr);
701 infoPtr->hwndSelf = hWnd;
704 TRACE("Closing avi!\n");
705 /* installer of thebat! v1.62 requires FALSE here */
706 return (infoPtr->hMMio != 0);
710 hInstance = (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE);
712 if (HIWORD(lParam)) {
713 TRACE("(\"%s\");\n", (LPSTR)lParam);
715 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
716 TRACE("No AVI resource found!\n");
717 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
718 WARN("No AVI file found!\n");
723 TRACE("(%u);\n", (WORD)LOWORD(lParam));
725 if (!ANIMATE_LoadResA(infoPtr, hInstance,
726 MAKEINTRESOURCEA((INT)lParam))) {
727 WARN("No AVI resource found!\n");
732 if (!ANIMATE_GetAviInfo(infoPtr)) {
733 WARN("Can't get AVI information\n");
734 ANIMATE_Free(infoPtr);
738 if (!ANIMATE_GetAviCodec(infoPtr)) {
739 WARN("Can't get AVI Codec\n");
740 ANIMATE_Free(infoPtr);
744 if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
745 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
746 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
749 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
750 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
757 /* << ANIMATE_Open32W >> */
759 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
761 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
767 ANIMATE_DoStop(infoPtr);
772 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
774 ANIMATE_INFO* infoPtr;
776 if (!fnIC.hModule) /* FIXME: not thread safe */
778 /* since there's a circular dep between msvfw32 and comctl32, we could either:
779 * - fix the build chain to allow this circular dep
780 * - handle it by hand
781 * AJ wants the latter :-(
783 fnIC.hModule = LoadLibraryA("msvfw32.dll");
784 if (!fnIC.hModule) return FALSE;
786 fnIC.fnICOpen = (void*)GetProcAddress(fnIC.hModule, "ICOpen");
787 fnIC.fnICClose = (void*)GetProcAddress(fnIC.hModule, "ICClose");
788 fnIC.fnICSendMessage = (void*)GetProcAddress(fnIC.hModule, "ICSendMessage");
789 fnIC.fnICDecompress = (void*)GetProcAddress(fnIC.hModule, "ICDecompress");
792 /* allocate memory for info structure */
793 infoPtr = (ANIMATE_INFO *)Alloc(sizeof(ANIMATE_INFO));
795 ERR("could not allocate info memory!\n");
799 /* store crossref hWnd <-> info structure */
800 SetWindowLongPtrW(hWnd, 0, (DWORD_PTR)infoPtr);
801 infoPtr->hwndSelf = hWnd;
802 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
803 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
804 infoPtr->hbmPrevFrame = 0;
806 TRACE("Animate style=0x%08lx, parent=%p\n", GetWindowLongA(hWnd, GWL_STYLE), infoPtr->hwndNotify);
808 InitializeCriticalSection(&infoPtr->cs);
814 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
816 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
820 ANIMATE_Free(infoPtr);
822 /* free animate info data */
824 SetWindowLongPtrW(hWnd, 0, 0);
830 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
832 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
836 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
838 hBrush = (HBRUSH)SendMessageA(infoPtr->hwndNotify,WM_CTLCOLORSTATIC,
839 wParam, (LPARAM)hWnd);
842 GetClientRect(hWnd, &rect);
843 FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
848 static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
850 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
851 InvalidateRect(hWnd, NULL, TRUE);
856 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
858 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
859 if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
860 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
864 return ANIMATE_OpenA(hWnd, wParam, lParam);
867 FIXME("ACM_OPENW: stub!\n");
868 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
872 return ANIMATE_Play(hWnd, wParam, lParam);
875 return ANIMATE_Stop(hWnd, wParam, lParam);
878 return ANIMATE_Create(hWnd, wParam, lParam);
881 return HTTRANSPARENT;
884 return ANIMATE_Destroy(hWnd, wParam, lParam);
887 return ANIMATE_EraseBackground(hWnd, wParam, lParam);
889 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
892 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
894 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
895 infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
897 wParam, (LPARAM)hWnd);
899 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
903 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
905 /* the animation isn't playing, or has not decompressed
906 * (and displayed) the first frame yet, don't paint
908 if ((!infoPtr->uTimer && !infoPtr->hThread) ||
909 !infoPtr->hbmPrevFrame)
911 /* default paint handling */
912 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
915 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
916 infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
918 wParam, (LPARAM)hWnd);
922 EnterCriticalSection(&infoPtr->cs);
923 ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
924 LeaveCriticalSection(&infoPtr->cs);
929 HDC hDC = BeginPaint(hWnd, &ps);
931 EnterCriticalSection(&infoPtr->cs);
932 ANIMATE_PaintFrame(infoPtr, hDC);
933 LeaveCriticalSection(&infoPtr->cs);
941 return ANIMATE_Size(hWnd, wParam, lParam);
944 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
945 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
947 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
952 void ANIMATE_Register(void)
956 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
957 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
958 wndClass.lpfnWndProc = ANIMATE_WindowProc;
959 wndClass.cbClsExtra = 0;
960 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
961 wndClass.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
962 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
963 wndClass.lpszClassName = ANIMATE_CLASSA;
965 RegisterClassA(&wndClass);
969 void ANIMATE_Unregister(void)
971 UnregisterClassA(ANIMATE_CLASSA, NULL);