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 */
77 /* data for playing the file */
83 COLORREF transparentColor;
88 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongPtrW(hWnd, 0))
89 #define ANIMATE_COLOR_NONE 0xffffffff
91 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
93 SendMessageA(infoPtr->hwndNotify, WM_COMMAND,
94 MAKEWPARAM(GetDlgCtrlID(infoPtr->hwndSelf), notif),
95 (LPARAM)infoPtr->hwndSelf);
98 static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
104 hrsrc = FindResourceA(hInst, lpName, "AVI");
108 infoPtr->hRes = LoadResource(hInst, hrsrc);
112 lpAvi = LockResource(infoPtr->hRes);
116 memset(&mminfo, 0, sizeof(mminfo));
117 mminfo.fccIOProc = FOURCC_MEM;
118 mminfo.pchBuffer = (LPSTR)lpAvi;
119 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
120 infoPtr->hMMio = mmioOpenA(NULL, &mminfo, MMIO_READ);
121 if (!infoPtr->hMMio) {
122 FreeResource(infoPtr->hRes);
130 static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
132 infoPtr->hMMio = mmioOpenA((LPSTR)lpName, NULL,
133 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
142 static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
144 EnterCriticalSection(&infoPtr->cs);
146 /* should stop playing */
147 if (infoPtr->hThread)
149 HANDLE handle = infoPtr->hThread;
151 TRACE("stopping animation thread\n");
152 SetEvent( infoPtr->hStopEvent );
153 LeaveCriticalSection(&infoPtr->cs); /* leave it a chance to run */
154 WaitForSingleObject( handle, INFINITE );
155 TRACE("animation thread stopped\n");
156 EnterCriticalSection(&infoPtr->cs);
157 CloseHandle( infoPtr->hThread );
158 CloseHandle( infoPtr->hStopEvent );
159 infoPtr->hThread = 0;
161 if (infoPtr->uTimer) {
162 KillTimer(infoPtr->hwndSelf, infoPtr->uTimer);
166 LeaveCriticalSection(&infoPtr->cs);
168 ANIMATE_Notify(infoPtr, ACN_STOP);
174 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
176 if (infoPtr->hMMio) {
177 ANIMATE_DoStop(infoPtr);
178 mmioClose(infoPtr->hMMio, 0);
180 FreeResource(infoPtr->hRes);
183 if (infoPtr->lpIndex) {
184 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
185 infoPtr->lpIndex = NULL;
188 fnIC.fnICClose(infoPtr->hic);
191 if (infoPtr->inbih) {
192 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
193 infoPtr->inbih = NULL;
195 if (infoPtr->outbih) {
196 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
197 infoPtr->outbih = NULL;
199 if( infoPtr->indata )
201 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
202 infoPtr->indata = NULL;
204 if( infoPtr->outdata )
206 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
207 infoPtr->outdata = NULL;
209 if( infoPtr->hbmPrevFrame )
211 DeleteObject(infoPtr->hbmPrevFrame);
212 infoPtr->hbmPrevFrame = 0;
214 infoPtr->indata = infoPtr->outdata = NULL;
215 infoPtr->hwndSelf = 0;
218 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
219 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
220 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
222 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
225 static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
231 /* create a transparency mask */
232 hdcMask = CreateCompatibleDC(hdcDest);
233 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
234 hbmOld = SelectObject(hdcMask, hbmMask);
236 SetBkColor(hdcSource,infoPtr->transparentColor);
237 BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
239 /* mask the source bitmap */
240 SetBkColor(hdcSource, RGB(0,0,0));
241 SetTextColor(hdcSource, RGB(255,255,255));
242 BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
244 /* mask the destination bitmap */
245 SetBkColor(hdcDest, RGB(255,255,255));
246 SetTextColor(hdcDest, RGB(0,0,0));
247 BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
249 /* combine source and destination */
250 BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
252 SelectObject(hdcMask, hbmOld);
253 DeleteObject(hbmMask);
257 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
259 void* pBitmapData = NULL;
260 LPBITMAPINFO pBitmapInfo = NULL;
271 if (!hDC || !infoPtr->inbih)
276 pBitmapData = infoPtr->outdata;
277 pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
279 nWidth = infoPtr->outbih->biWidth;
280 nHeight = infoPtr->outbih->biHeight;
283 pBitmapData = infoPtr->indata;
284 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
286 nWidth = infoPtr->inbih->biWidth;
287 nHeight = infoPtr->inbih->biHeight;
290 if(!infoPtr->hbmPrevFrame)
292 infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
295 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
297 hdcMem = CreateCompatibleDC(hDC);
298 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
301 * we need to get the transparent color even without ACS_TRANSPARENT,
302 * because the style can be changed later on and the color should always
303 * be obtained in the first frame
305 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
307 infoPtr->transparentColor = GetPixel(hdcMem,0,0);
310 if(GetWindowLongA(infoPtr->hwndSelf, GWL_STYLE) & ACS_TRANSPARENT)
312 HDC hdcFinal = CreateCompatibleDC(hDC);
313 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
314 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
320 rect.bottom = nHeight;
322 if(!infoPtr->hbrushBG)
323 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
325 FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
326 ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
328 SelectObject(hdcFinal, hbmOld2);
329 SelectObject(hdcMem, hbmFinal);
331 DeleteObject(infoPtr->hbmPrevFrame);
332 infoPtr->hbmPrevFrame = hbmFinal;
335 if (GetWindowLongA(infoPtr->hwndSelf, GWL_STYLE) & ACS_CENTER)
339 GetWindowRect(infoPtr->hwndSelf, &rect);
340 nOffsetX = ((rect.right - rect.left) - nWidth)/2;
341 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
343 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
345 SelectObject(hdcMem, hbmOld);
350 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
354 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
356 EnterCriticalSection(&infoPtr->cs);
358 mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
359 mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
362 fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
363 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
364 LeaveCriticalSection(&infoPtr->cs);
365 WARN("Decompression error\n");
369 if ((hDC = GetDC(infoPtr->hwndSelf)) != 0) {
370 ANIMATE_PaintFrame(infoPtr, hDC);
371 ReleaseDC(infoPtr->hwndSelf, hDC);
374 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
375 infoPtr->currFrame = infoPtr->nFromFrame;
376 if (infoPtr->nLoop != -1) {
377 if (--infoPtr->nLoop == 0) {
378 ANIMATE_DoStop(infoPtr);
382 LeaveCriticalSection(&infoPtr->cs);
387 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
389 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
395 EnterCriticalSection(&infoPtr->cs);
396 ANIMATE_DrawFrame(infoPtr);
397 timeout = infoPtr->mah.dwMicroSecPerFrame;
398 event = infoPtr->hStopEvent;
399 LeaveCriticalSection(&infoPtr->cs);
401 /* time is in microseconds, we should convert it to milliseconds */
402 if (WaitForSingleObject( event, (timeout+500)/1000) == WAIT_OBJECT_0)
408 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
410 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
416 if (infoPtr->hThread || infoPtr->uTimer) {
417 TRACE("Already playing\n");
421 infoPtr->nFromFrame = (INT)LOWORD(lParam);
422 infoPtr->nToFrame = (INT)HIWORD(lParam);
423 infoPtr->nLoop = (INT)wParam;
425 if (infoPtr->nToFrame == 0xFFFF)
426 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
428 TRACE("(repeat=%d from=%d to=%d);\n",
429 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
431 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
432 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
435 infoPtr->currFrame = infoPtr->nFromFrame;
437 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
438 TRACE("Using a timer\n");
439 /* create a timer to display AVI */
440 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
444 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
446 infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
447 WM_CTLCOLORSTATIC, 0, (LPARAM)hWnd);
450 TRACE("Using an animation thread\n");
451 infoPtr->hStopEvent = CreateEventW( NULL, TRUE, FALSE, NULL );
452 infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr, 0, &threadID);
453 if(!infoPtr->hThread)
455 ERR("Could not create animation thread!\n");
461 ANIMATE_Notify(infoPtr, ACN_START);
467 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
476 if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
477 WARN("Can't find 'RIFF' chunk\n");
481 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
482 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
483 WARN("Can't find 'AVI ' chunk\n");
487 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
488 if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
489 WARN("Can't find 'hdrl' list\n");
493 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
494 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
495 WARN("Can't find 'avih' chunk\n");
499 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
501 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
502 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
503 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
504 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
505 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
506 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
507 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
508 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
509 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
510 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
512 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
514 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
515 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
516 WARN("Can't find 'strl' list\n");
520 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
521 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
522 WARN("Can't find 'strh' chunk\n");
526 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
528 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
529 HIBYTE(LOWORD(infoPtr->ash.fccType)),
530 LOBYTE(HIWORD(infoPtr->ash.fccType)),
531 HIBYTE(HIWORD(infoPtr->ash.fccType)));
532 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
533 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
534 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
535 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
536 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
537 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
538 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
539 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
540 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
541 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
542 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
543 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
544 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
545 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
546 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
547 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
548 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
550 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
552 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
553 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
554 WARN("Can't find 'strh' chunk\n");
558 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
559 if (!infoPtr->inbih) {
560 WARN("Can't alloc input BIH\n");
564 mmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
566 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
567 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
568 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
569 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
570 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
571 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
572 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
573 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
574 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
575 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
576 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
578 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
580 mmioAscend(infoPtr->hMMio, &mmckList, 0);
583 /* an AVI has 0 or 1 video stream, and to be animated should not contain
584 * an audio stream, so only one strl is allowed
586 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
587 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
588 WARN("There should be a single 'strl' list\n");
593 mmioAscend(infoPtr->hMMio, &mmckHead, 0);
595 /* no need to read optional JUNK chunk */
597 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
598 if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
599 WARN("Can't find 'movi' list\n");
603 /* FIXME: should handle the 'rec ' LIST when present */
605 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
606 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
607 if (!infoPtr->lpIndex) {
608 WARN("Can't alloc index array\n");
612 numFrame = insize = 0;
613 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
614 numFrame < infoPtr->mah.dwTotalFrames) {
615 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
616 if (insize < mmckInfo.cksize)
617 insize = mmckInfo.cksize;
619 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
621 if (numFrame != infoPtr->mah.dwTotalFrames) {
622 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
625 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
626 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
627 infoPtr->ash.dwSuggestedBufferSize = insize;
630 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
631 if (!infoPtr->indata) {
632 WARN("Can't alloc input buffer\n");
640 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
644 /* check uncompressed AVI */
645 if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
646 (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')) ||
647 (infoPtr->ash.fccHandler == mmioFOURCC(0, 0, 0, 0)))
653 /* try to get a decompressor for that type */
654 infoPtr->hic = fnIC.fnICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
656 WARN("Can't load codec for the file\n");
660 outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
661 (DWORD)infoPtr->inbih, 0L);
663 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
664 if (!infoPtr->outbih) {
665 WARN("Can't alloc output BIH\n");
669 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
670 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != outSize) {
671 WARN("Can't get output BIH\n");
675 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
676 if (!infoPtr->outdata) {
677 WARN("Can't alloc output buffer\n");
681 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
682 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
683 WARN("Can't begin decompression\n");
690 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
692 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
693 HINSTANCE hInstance = (HINSTANCE)wParam;
695 ANIMATE_Free(infoPtr);
696 infoPtr->hwndSelf = hWnd;
699 TRACE("Closing avi!\n");
700 /* installer of thebat! v1.62 requires FALSE here */
701 return (infoPtr->hMMio != 0);
705 hInstance = (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE);
707 if (HIWORD(lParam)) {
708 TRACE("(\"%s\");\n", (LPSTR)lParam);
710 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
711 TRACE("No AVI resource found!\n");
712 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
713 WARN("No AVI file found!\n");
718 TRACE("(%u);\n", (WORD)LOWORD(lParam));
720 if (!ANIMATE_LoadResA(infoPtr, hInstance,
721 MAKEINTRESOURCEA((INT)lParam))) {
722 WARN("No AVI resource found!\n");
727 if (!ANIMATE_GetAviInfo(infoPtr)) {
728 WARN("Can't get AVI information\n");
729 ANIMATE_Free(infoPtr);
733 if (!ANIMATE_GetAviCodec(infoPtr)) {
734 WARN("Can't get AVI Codec\n");
735 ANIMATE_Free(infoPtr);
739 if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
740 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
741 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
744 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
745 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
752 /* << ANIMATE_Open32W >> */
754 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
756 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
762 ANIMATE_DoStop(infoPtr);
767 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
769 ANIMATE_INFO* infoPtr;
771 if (!fnIC.hModule) /* FIXME: not thread safe */
773 /* since there's a circular dep between msvfw32 and comctl32, we could either:
774 * - fix the build chain to allow this circular dep
775 * - handle it by hand
776 * AJ wants the latter :-(
778 fnIC.hModule = LoadLibraryA("msvfw32.dll");
779 if (!fnIC.hModule) return FALSE;
781 fnIC.fnICOpen = (void*)GetProcAddress(fnIC.hModule, "ICOpen");
782 fnIC.fnICClose = (void*)GetProcAddress(fnIC.hModule, "ICClose");
783 fnIC.fnICSendMessage = (void*)GetProcAddress(fnIC.hModule, "ICSendMessage");
784 fnIC.fnICDecompress = (void*)GetProcAddress(fnIC.hModule, "ICDecompress");
787 /* allocate memory for info structure */
788 infoPtr = (ANIMATE_INFO *)Alloc(sizeof(ANIMATE_INFO));
790 ERR("could not allocate info memory!\n");
794 /* store crossref hWnd <-> info structure */
795 SetWindowLongPtrW(hWnd, 0, (DWORD_PTR)infoPtr);
796 infoPtr->hwndSelf = hWnd;
797 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
798 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
799 infoPtr->hbmPrevFrame = 0;
801 TRACE("Animate style=0x%08lx, parent=%p\n", GetWindowLongA(hWnd, GWL_STYLE), infoPtr->hwndNotify);
803 InitializeCriticalSection(&infoPtr->cs);
809 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
811 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
815 ANIMATE_Free(infoPtr);
817 /* free animate info data */
819 SetWindowLongPtrW(hWnd, 0, 0);
825 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
827 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
831 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
833 hBrush = (HBRUSH)SendMessageA(infoPtr->hwndNotify,WM_CTLCOLORSTATIC,
834 wParam, (LPARAM)hWnd);
837 GetClientRect(hWnd, &rect);
838 FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
843 static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
845 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
846 InvalidateRect(hWnd, NULL, TRUE);
851 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
853 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
854 if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
855 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
859 return ANIMATE_OpenA(hWnd, wParam, lParam);
862 FIXME("ACM_OPENW: stub!\n");
863 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
867 return ANIMATE_Play(hWnd, wParam, lParam);
870 return ANIMATE_Stop(hWnd, wParam, lParam);
873 return ANIMATE_Create(hWnd, wParam, lParam);
876 return HTTRANSPARENT;
879 return ANIMATE_Destroy(hWnd, wParam, lParam);
882 return ANIMATE_EraseBackground(hWnd, wParam, lParam);
884 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
887 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
889 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
890 infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
892 wParam, (LPARAM)hWnd);
894 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
898 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
900 /* the animation isn't playing, or has not decompressed
901 * (and displayed) the first frame yet, don't paint
903 if ((!infoPtr->uTimer && !infoPtr->hThread) ||
904 !infoPtr->hbmPrevFrame)
906 /* default paint handling */
907 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
910 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
911 infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
913 wParam, (LPARAM)hWnd);
917 EnterCriticalSection(&infoPtr->cs);
918 ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
919 LeaveCriticalSection(&infoPtr->cs);
924 HDC hDC = BeginPaint(hWnd, &ps);
926 EnterCriticalSection(&infoPtr->cs);
927 ANIMATE_PaintFrame(infoPtr, hDC);
928 LeaveCriticalSection(&infoPtr->cs);
936 return ANIMATE_Size(hWnd, wParam, lParam);
939 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
940 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
942 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
947 void ANIMATE_Register(void)
951 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
952 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
953 wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
954 wndClass.cbClsExtra = 0;
955 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
956 wndClass.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
957 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
958 wndClass.lpszClassName = ANIMATE_CLASSA;
960 RegisterClassA(&wndClass);
964 void ANIMATE_Unregister(void)
966 UnregisterClassA(ANIMATE_CLASSA, NULL);