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 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
191 infoPtr->lpIndex = NULL;
193 fnIC.fnICClose(infoPtr->hic);
196 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
197 infoPtr->inbih = NULL;
198 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
199 infoPtr->outbih = NULL;
200 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
201 infoPtr->indata = NULL;
202 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
203 infoPtr->outdata = NULL;
204 if( infoPtr->hbmPrevFrame )
206 DeleteObject(infoPtr->hbmPrevFrame);
207 infoPtr->hbmPrevFrame = 0;
209 infoPtr->indata = infoPtr->outdata = NULL;
210 infoPtr->hwndSelf = 0;
213 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
214 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
215 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
217 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
220 static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
226 /* create a transparency mask */
227 hdcMask = CreateCompatibleDC(hdcDest);
228 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
229 hbmOld = SelectObject(hdcMask, hbmMask);
231 SetBkColor(hdcSource,infoPtr->transparentColor);
232 BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
234 /* mask the source bitmap */
235 SetBkColor(hdcSource, RGB(0,0,0));
236 SetTextColor(hdcSource, RGB(255,255,255));
237 BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
239 /* mask the destination bitmap */
240 SetBkColor(hdcDest, RGB(255,255,255));
241 SetTextColor(hdcDest, RGB(0,0,0));
242 BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
244 /* combine source and destination */
245 BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
247 SelectObject(hdcMask, hbmOld);
248 DeleteObject(hbmMask);
252 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
254 void* pBitmapData = NULL;
255 LPBITMAPINFO pBitmapInfo = NULL;
266 if (!hDC || !infoPtr->inbih)
271 pBitmapData = infoPtr->outdata;
272 pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
274 nWidth = infoPtr->outbih->biWidth;
275 nHeight = infoPtr->outbih->biHeight;
278 pBitmapData = infoPtr->indata;
279 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
281 nWidth = infoPtr->inbih->biWidth;
282 nHeight = infoPtr->inbih->biHeight;
285 if(!infoPtr->hbmPrevFrame)
287 infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
290 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
292 hdcMem = CreateCompatibleDC(hDC);
293 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
296 * we need to get the transparent color even without ACS_TRANSPARENT,
297 * because the style can be changed later on and the color should always
298 * be obtained in the first frame
300 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
302 infoPtr->transparentColor = GetPixel(hdcMem,0,0);
305 if(GetWindowLongA(infoPtr->hwndSelf, GWL_STYLE) & ACS_TRANSPARENT)
307 HDC hdcFinal = CreateCompatibleDC(hDC);
308 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
309 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
315 rect.bottom = nHeight;
317 if(!infoPtr->hbrushBG)
318 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
320 FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
321 ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
323 SelectObject(hdcFinal, hbmOld2);
324 SelectObject(hdcMem, hbmFinal);
326 DeleteObject(infoPtr->hbmPrevFrame);
327 infoPtr->hbmPrevFrame = hbmFinal;
330 if (GetWindowLongA(infoPtr->hwndSelf, GWL_STYLE) & ACS_CENTER)
334 GetWindowRect(infoPtr->hwndSelf, &rect);
335 nOffsetX = ((rect.right - rect.left) - nWidth)/2;
336 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
338 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
340 SelectObject(hdcMem, hbmOld);
345 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
349 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
351 EnterCriticalSection(&infoPtr->cs);
353 mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
354 mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
357 fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
358 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
359 LeaveCriticalSection(&infoPtr->cs);
360 WARN("Decompression error\n");
364 if ((hDC = GetDC(infoPtr->hwndSelf)) != 0) {
365 ANIMATE_PaintFrame(infoPtr, hDC);
366 ReleaseDC(infoPtr->hwndSelf, hDC);
369 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
370 infoPtr->currFrame = infoPtr->nFromFrame;
371 if (infoPtr->nLoop != -1) {
372 if (--infoPtr->nLoop == 0) {
373 ANIMATE_DoStop(infoPtr);
377 LeaveCriticalSection(&infoPtr->cs);
382 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
384 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
390 EnterCriticalSection(&infoPtr->cs);
391 ANIMATE_DrawFrame(infoPtr);
392 timeout = infoPtr->mah.dwMicroSecPerFrame;
393 event = infoPtr->hStopEvent;
394 LeaveCriticalSection(&infoPtr->cs);
396 /* time is in microseconds, we should convert it to milliseconds */
397 if ((event == 0) || WaitForSingleObject( event, (timeout+500)/1000) == WAIT_OBJECT_0)
403 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
405 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
411 if (infoPtr->hThread || infoPtr->uTimer) {
412 TRACE("Already playing\n");
416 infoPtr->nFromFrame = (INT)LOWORD(lParam);
417 infoPtr->nToFrame = (INT)HIWORD(lParam);
418 infoPtr->nLoop = (INT)wParam;
420 if (infoPtr->nToFrame == 0xFFFF)
421 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
423 TRACE("(repeat=%d from=%d to=%d);\n",
424 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
426 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
427 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
430 infoPtr->currFrame = infoPtr->nFromFrame;
432 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
433 TRACE("Using a timer\n");
434 /* create a timer to display AVI */
435 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
437 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
439 infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
440 WM_CTLCOLORSTATIC, 0, (LPARAM)hWnd);
443 TRACE("Using an animation thread\n");
444 infoPtr->hStopEvent = CreateEventW( NULL, TRUE, FALSE, NULL );
445 infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr, 0, &infoPtr->threadId);
446 if(!infoPtr->hThread)
448 ERR("Could not create animation thread!\n");
454 ANIMATE_Notify(infoPtr, ACN_START);
460 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
469 if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
470 WARN("Can't find 'RIFF' chunk\n");
474 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
475 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
476 WARN("Can't find 'AVI ' chunk\n");
480 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
481 if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
482 WARN("Can't find 'hdrl' list\n");
486 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
487 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
488 WARN("Can't find 'avih' chunk\n");
492 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
494 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
495 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
496 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
497 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
498 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
499 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
500 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
501 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
502 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
503 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
505 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
507 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
508 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
509 WARN("Can't find 'strl' list\n");
513 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
514 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
515 WARN("Can't find 'strh' chunk\n");
519 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
521 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
522 HIBYTE(LOWORD(infoPtr->ash.fccType)),
523 LOBYTE(HIWORD(infoPtr->ash.fccType)),
524 HIBYTE(HIWORD(infoPtr->ash.fccType)));
525 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
526 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
527 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
528 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
529 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
530 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
531 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
532 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
533 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
534 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
535 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
536 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
537 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
538 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
539 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
540 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
541 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
543 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
545 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
546 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
547 WARN("Can't find 'strh' chunk\n");
551 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
552 if (!infoPtr->inbih) {
553 WARN("Can't alloc input BIH\n");
557 mmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
559 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
560 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
561 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
562 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
563 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
564 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
565 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
566 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
567 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
568 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
569 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
571 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
573 mmioAscend(infoPtr->hMMio, &mmckList, 0);
576 /* an AVI has 0 or 1 video stream, and to be animated should not contain
577 * an audio stream, so only one strl is allowed
579 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
580 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
581 WARN("There should be a single 'strl' list\n");
586 mmioAscend(infoPtr->hMMio, &mmckHead, 0);
588 /* no need to read optional JUNK chunk */
590 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
591 if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
592 WARN("Can't find 'movi' list\n");
596 /* FIXME: should handle the 'rec ' LIST when present */
598 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
599 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
600 if (!infoPtr->lpIndex) {
601 WARN("Can't alloc index array\n");
605 numFrame = insize = 0;
606 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
607 numFrame < infoPtr->mah.dwTotalFrames) {
608 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
609 if (insize < mmckInfo.cksize)
610 insize = mmckInfo.cksize;
612 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
614 if (numFrame != infoPtr->mah.dwTotalFrames) {
615 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
618 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
619 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
620 infoPtr->ash.dwSuggestedBufferSize = insize;
623 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
624 if (!infoPtr->indata) {
625 WARN("Can't alloc input buffer\n");
633 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
637 /* check uncompressed AVI */
638 if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
639 (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')) ||
640 (infoPtr->ash.fccHandler == mmioFOURCC(0, 0, 0, 0)))
646 /* try to get a decompressor for that type */
647 infoPtr->hic = fnIC.fnICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
649 WARN("Can't load codec for the file\n");
653 outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
654 (DWORD)infoPtr->inbih, 0L);
656 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
657 if (!infoPtr->outbih) {
658 WARN("Can't alloc output BIH\n");
662 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
663 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != outSize) {
664 WARN("Can't get output BIH\n");
668 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
669 if (!infoPtr->outdata) {
670 WARN("Can't alloc output buffer\n");
674 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
675 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
676 WARN("Can't begin decompression\n");
683 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
685 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
686 HINSTANCE hInstance = (HINSTANCE)wParam;
688 ANIMATE_Free(infoPtr);
689 infoPtr->hwndSelf = hWnd;
692 TRACE("Closing avi!\n");
693 /* installer of thebat! v1.62 requires FALSE here */
694 return (infoPtr->hMMio != 0);
698 hInstance = (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE);
700 if (HIWORD(lParam)) {
701 TRACE("(\"%s\");\n", (LPSTR)lParam);
703 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
704 TRACE("No AVI resource found!\n");
705 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
706 WARN("No AVI file found!\n");
711 TRACE("(%u);\n", (WORD)LOWORD(lParam));
713 if (!ANIMATE_LoadResA(infoPtr, hInstance,
714 MAKEINTRESOURCEA((INT)lParam))) {
715 WARN("No AVI resource found!\n");
720 if (!ANIMATE_GetAviInfo(infoPtr)) {
721 WARN("Can't get AVI information\n");
722 ANIMATE_Free(infoPtr);
726 if (!ANIMATE_GetAviCodec(infoPtr)) {
727 WARN("Can't get AVI Codec\n");
728 ANIMATE_Free(infoPtr);
732 if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
733 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
734 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
737 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
738 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
745 /* << ANIMATE_Open32W >> */
747 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
749 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
755 ANIMATE_DoStop(infoPtr);
760 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
762 ANIMATE_INFO* infoPtr;
764 if (!fnIC.hModule) /* FIXME: not thread safe */
766 /* since there's a circular dep between msvfw32 and comctl32, we could either:
767 * - fix the build chain to allow this circular dep
768 * - handle it by hand
769 * AJ wants the latter :-(
771 fnIC.hModule = LoadLibraryA("msvfw32.dll");
772 if (!fnIC.hModule) return FALSE;
774 fnIC.fnICOpen = (void*)GetProcAddress(fnIC.hModule, "ICOpen");
775 fnIC.fnICClose = (void*)GetProcAddress(fnIC.hModule, "ICClose");
776 fnIC.fnICSendMessage = (void*)GetProcAddress(fnIC.hModule, "ICSendMessage");
777 fnIC.fnICDecompress = (void*)GetProcAddress(fnIC.hModule, "ICDecompress");
780 /* allocate memory for info structure */
781 infoPtr = (ANIMATE_INFO *)Alloc(sizeof(ANIMATE_INFO));
783 ERR("could not allocate info memory!\n");
787 /* store crossref hWnd <-> info structure */
788 SetWindowLongPtrW(hWnd, 0, (DWORD_PTR)infoPtr);
789 infoPtr->hwndSelf = hWnd;
790 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
791 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
792 infoPtr->hbmPrevFrame = 0;
794 TRACE("Animate style=0x%08lx, parent=%p\n", GetWindowLongA(hWnd, GWL_STYLE), infoPtr->hwndNotify);
796 InitializeCriticalSection(&infoPtr->cs);
802 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
804 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
808 ANIMATE_Free(infoPtr);
810 /* free animate info data */
812 SetWindowLongPtrW(hWnd, 0, 0);
818 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
820 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
824 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
826 hBrush = (HBRUSH)SendMessageA(infoPtr->hwndNotify,WM_CTLCOLORSTATIC,
827 wParam, (LPARAM)hWnd);
830 GetClientRect(hWnd, &rect);
831 FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
836 static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
838 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
839 InvalidateRect(hWnd, NULL, TRUE);
844 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
846 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
847 if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
848 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
852 return ANIMATE_OpenA(hWnd, wParam, lParam);
855 FIXME("ACM_OPENW: stub!\n");
856 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
860 return ANIMATE_Play(hWnd, wParam, lParam);
863 return ANIMATE_Stop(hWnd, wParam, lParam);
866 return ANIMATE_Create(hWnd, wParam, lParam);
869 return HTTRANSPARENT;
872 return ANIMATE_Destroy(hWnd, wParam, lParam);
875 return ANIMATE_EraseBackground(hWnd, wParam, lParam);
877 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
880 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
882 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
883 infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
885 wParam, (LPARAM)hWnd);
887 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
891 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
893 /* the animation isn't playing, or has not decompressed
894 * (and displayed) the first frame yet, don't paint
896 if ((!infoPtr->uTimer && !infoPtr->hThread) ||
897 !infoPtr->hbmPrevFrame)
899 /* default paint handling */
900 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
903 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
904 infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
906 wParam, (LPARAM)hWnd);
910 EnterCriticalSection(&infoPtr->cs);
911 ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
912 LeaveCriticalSection(&infoPtr->cs);
917 HDC hDC = BeginPaint(hWnd, &ps);
919 EnterCriticalSection(&infoPtr->cs);
920 ANIMATE_PaintFrame(infoPtr, hDC);
921 LeaveCriticalSection(&infoPtr->cs);
929 return ANIMATE_Size(hWnd, wParam, lParam);
932 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
933 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
935 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
940 void ANIMATE_Register(void)
944 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
945 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
946 wndClass.lpfnWndProc = ANIMATE_WindowProc;
947 wndClass.cbClsExtra = 0;
948 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
949 wndClass.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
950 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
951 wndClass.lpszClassName = ANIMATE_CLASSA;
953 RegisterClassA(&wndClass);
957 void ANIMATE_Unregister(void)
959 UnregisterClassA(ANIMATE_CLASSA, NULL);