1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
5 * Copyright 1998, 1999 Eric Kohl
9 * I will only improve this control once in a while.
10 * Eric <ekohl@abo.rhein-zeitung.de>
13 * - check for the 'rec ' list in some AVI files
14 * - concurrent access to infoPtr
22 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(animate);
28 /* pointer to msvideo functions. it's easier to put them here.
29 * to be correct, they should be defined on a per process basis, but
30 * this would required a per process storage. We're using a per object
31 * storage instead, which is not efficient on memory usage, but
32 * will lead to less bugs in the future
34 HIC WINAPI (*fnICOpen)(DWORD, DWORD, UINT);
35 LRESULT WINAPI (*fnICClose)(HIC);
36 LRESULT WINAPI (*fnICSendMessage)(HIC, UINT, DWORD, DWORD);
37 DWORD WINAPIV (*fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
39 HMMIO WINAPI (*fnmmioOpenA)(LPSTR,MMIOINFO*,DWORD);
40 MMRESULT WINAPI (*fnmmioClose)(HMMIO,UINT);
41 UINT WINAPI (*fnmmioAscend)(HMMIO,MMCKINFO*,UINT);
42 UINT WINAPI (*fnmmioDescend)(HMMIO,MMCKINFO*,const MMCKINFO*,UINT);
43 LONG WINAPI (*fnmmioSeek)(HMMIO,LONG,INT);
44 LONG WINAPI (*fnmmioRead)(HMMIO,HPSTR,LONG);
46 /* reference to input stream (file or resource) */
48 HMMIO hMMio; /* handle to mmio stream */
50 /* information on the loaded AVI file */
53 LPBITMAPINFOHEADER inbih;
55 /* data for the decompressor */
57 LPBITMAPINFOHEADER outbih;
60 /* data for the background mechanism */
64 /* data for playing the file */
70 COLORREF transparentColor;
75 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
76 #define ANIMATE_COLOR_NONE 0xffffffff
80 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
82 SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
83 MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
84 (LPARAM)infoPtr->hWnd);
87 static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
93 hrsrc = FindResourceA(hInst, lpName, "AVI");
97 infoPtr->hRes = LoadResource(hInst, hrsrc);
101 lpAvi = LockResource(infoPtr->hRes);
105 memset(&mminfo, 0, sizeof(mminfo));
106 mminfo.fccIOProc = FOURCC_MEM;
107 mminfo.pchBuffer = (LPSTR)lpAvi;
108 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
109 infoPtr->hMMio = infoPtr->fnmmioOpenA(NULL, &mminfo, MMIO_READ);
111 if (!infoPtr->hMMio) {
112 GlobalFree((HGLOBAL)lpAvi);
120 static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
122 infoPtr->hMMio = infoPtr->fnmmioOpenA((LPSTR)lpName, NULL,
123 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
132 static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
134 EnterCriticalSection(&infoPtr->cs);
136 /* should stop playing */
137 if (infoPtr->hThread)
139 if (!TerminateThread(infoPtr->hThread,0))
140 WARN("could not destroy animation thread!\n");
141 infoPtr->hThread = 0;
143 if (infoPtr->uTimer) {
144 KillTimer(infoPtr->hWnd, infoPtr->uTimer);
148 LeaveCriticalSection(&infoPtr->cs);
150 ANIMATE_Notify(infoPtr, ACN_STOP);
156 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
158 if (infoPtr->hMMio) {
159 ANIMATE_DoStop(infoPtr);
160 infoPtr->fnmmioClose(infoPtr->hMMio, 0);
162 FreeResource(infoPtr->hRes);
165 if (infoPtr->lpIndex) {
166 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
167 infoPtr->lpIndex = NULL;
170 (infoPtr->fnICClose)(infoPtr->hic);
173 if (infoPtr->inbih) {
174 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
175 infoPtr->inbih = NULL;
177 if (infoPtr->outbih) {
178 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
179 infoPtr->outbih = NULL;
181 if( infoPtr->indata )
183 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
184 infoPtr->indata = NULL;
186 if( infoPtr->outdata )
188 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
189 infoPtr->outdata = NULL;
191 if( infoPtr->hbmPrevFrame )
193 DeleteObject(infoPtr->hbmPrevFrame);
194 infoPtr->hbmPrevFrame = 0;
196 infoPtr->indata = infoPtr->outdata = NULL;
200 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
201 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
202 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
204 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
207 static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
213 /* create a transparency mask */
214 hdcMask = CreateCompatibleDC(hdcDest);
215 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
216 hbmOld = SelectObject(hdcMask, hbmMask);
218 SetBkColor(hdcSource,infoPtr->transparentColor);
219 BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
221 /* mask the source bitmap */
222 SetBkColor(hdcSource, RGB(0,0,0));
223 SetTextColor(hdcSource, RGB(255,255,255));
224 BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
226 /* mask the destination bitmap */
227 SetBkColor(hdcDest, RGB(255,255,255));
228 SetTextColor(hdcDest, RGB(0,0,0));
229 BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
231 /* combine source and destination */
232 BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
234 SelectObject(hdcMask, hbmOld);
235 DeleteObject(hbmMask);
239 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
241 void* pBitmapData = NULL;
242 LPBITMAPINFO pBitmapInfo = NULL;
253 if (!hDC || !infoPtr->inbih)
258 pBitmapData = infoPtr->outdata;
259 pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
261 nWidth = infoPtr->outbih->biWidth;
262 nHeight = infoPtr->outbih->biHeight;
265 pBitmapData = infoPtr->indata;
266 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
268 nWidth = infoPtr->inbih->biWidth;
269 nHeight = infoPtr->inbih->biHeight;
272 if(!infoPtr->hbmPrevFrame)
274 infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
277 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
279 hdcMem = CreateCompatibleDC(hDC);
280 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
283 * we need to get the transparent color even without ACS_TRANSPARENT,
284 * because the style can be changed later on and the color should always
285 * be obtained in the first frame
287 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
289 infoPtr->transparentColor = GetPixel(hdcMem,0,0);
292 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
294 HDC hdcFinal = CreateCompatibleDC(hDC);
295 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
296 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
302 rect.bottom = nHeight;
304 if(!infoPtr->hbrushBG)
305 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
307 FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
308 ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
310 SelectObject(hdcFinal, hbmOld2);
311 SelectObject(hdcMem, hbmFinal);
313 DeleteObject(infoPtr->hbmPrevFrame);
314 infoPtr->hbmPrevFrame = hbmFinal;
317 if (GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_CENTER)
321 GetWindowRect(infoPtr->hWnd, &rect);
322 nOffsetX = ((rect.right - rect.left) - nWidth)/2;
323 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
325 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
327 SelectObject(hdcMem, hbmOld);
332 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
336 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
338 EnterCriticalSection(&infoPtr->cs);
340 infoPtr->fnmmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
341 infoPtr->fnmmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
344 (infoPtr->fnICDecompress)(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
345 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
346 LeaveCriticalSection(&infoPtr->cs);
347 WARN("Decompression error\n");
351 if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
352 ANIMATE_PaintFrame(infoPtr, hDC);
353 ReleaseDC(infoPtr->hWnd, hDC);
356 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
357 infoPtr->currFrame = infoPtr->nFromFrame;
358 if (infoPtr->nLoop != -1) {
359 if (--infoPtr->nLoop == 0) {
360 ANIMATE_DoStop(infoPtr);
364 LeaveCriticalSection(&infoPtr->cs);
369 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
371 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
376 WARN("animation structure undefined!\n");
382 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
384 hDC = GetDC(infoPtr->hWnd);
385 infoPtr->hbrushBG = SendMessageA(GetParent(infoPtr->hWnd),WM_CTLCOLORSTATIC,hDC, infoPtr->hWnd);
386 ReleaseDC(infoPtr->hWnd,hDC);
389 EnterCriticalSection(&infoPtr->cs);
390 ANIMATE_DrawFrame(infoPtr);
391 LeaveCriticalSection(&infoPtr->cs);
393 /* time is in microseconds, we should convert it to milliseconds */
394 Sleep((infoPtr->mah.dwMicroSecPerFrame+500)/1000);
399 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
401 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
407 if (infoPtr->hThread || infoPtr->uTimer) {
408 FIXME("Already playing ? what should I do ??\n");
409 ANIMATE_DoStop(infoPtr);
412 infoPtr->nFromFrame = (INT)LOWORD(lParam);
413 infoPtr->nToFrame = (INT)HIWORD(lParam);
414 infoPtr->nLoop = (INT)wParam;
416 if (infoPtr->nToFrame == 0xFFFF)
417 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
419 TRACE("(repeat=%d from=%d to=%d);\n",
420 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
422 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
423 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
426 infoPtr->currFrame = infoPtr->nFromFrame;
428 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
429 TRACE("Using a timer\n");
430 /* create a timer to display AVI */
431 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
435 TRACE("Using an animation thread\n");
436 infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr,0,0 &threadID);
437 if(!infoPtr->hThread)
439 ERR("Could not create animation thread!\n");
445 ANIMATE_Notify(infoPtr, ACN_START);
451 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
460 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
461 WARN("Can't find 'RIFF' chunk\n");
465 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
466 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
467 WARN("Can't find 'AVI ' chunk\n");
471 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
472 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
473 WARN("Can't find 'hdrl' list\n");
477 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
478 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
479 WARN("Can't find 'avih' chunk\n");
483 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
484 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
485 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
486 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
487 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
488 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
489 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
490 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
491 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
492 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
493 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
494 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
496 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
497 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
498 WARN("Can't find 'strl' list\n");
502 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
503 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
504 WARN("Can't find 'strh' chunk\n");
508 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
509 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
510 HIBYTE(LOWORD(infoPtr->ash.fccType)),
511 LOBYTE(HIWORD(infoPtr->ash.fccType)),
512 HIBYTE(HIWORD(infoPtr->ash.fccType)));
513 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
514 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
515 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
516 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
517 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
518 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
519 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
520 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
521 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
522 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
523 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
524 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
525 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
526 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
527 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
528 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
529 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
530 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
532 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
533 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
534 WARN("Can't find 'strh' chunk\n");
538 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
539 if (!infoPtr->inbih) {
540 WARN("Can't alloc input BIH\n");
544 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
545 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
546 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
547 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
548 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
549 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
550 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
551 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
552 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
553 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
554 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
555 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
556 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
558 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckList, 0);
561 /* an AVI has 0 or 1 video stream, and to be animated should not contain
562 * an audio stream, so only one strl is allowed
564 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
565 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
566 WARN("There should be a single 'strl' list\n");
571 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckHead, 0);
573 /* no need to read optional JUNK chunk */
575 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
576 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
577 WARN("Can't find 'movi' list\n");
581 /* FIXME: should handle the 'rec ' LIST when present */
583 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
584 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
585 if (!infoPtr->lpIndex) {
586 WARN("Can't alloc index array\n");
590 numFrame = insize = 0;
591 while (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
592 numFrame < infoPtr->mah.dwTotalFrames) {
593 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
594 if (insize < mmckInfo.cksize)
595 insize = mmckInfo.cksize;
597 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
599 if (numFrame != infoPtr->mah.dwTotalFrames) {
600 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
603 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
604 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
605 infoPtr->ash.dwSuggestedBufferSize = insize;
608 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
609 if (!infoPtr->indata) {
610 WARN("Can't alloc input buffer\n");
618 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
622 /* check uncompressed AVI */
623 if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
624 (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')))
630 /* try to get a decompressor for that type */
631 infoPtr->hic = (infoPtr->fnICOpen)(ICTYPE_VIDEO,
632 infoPtr->ash.fccHandler,
635 WARN("Can't load codec for the file\n");
639 outSize = (infoPtr->fnICSendMessage)(infoPtr->hic,
640 ICM_DECOMPRESS_GET_FORMAT,
641 (DWORD)infoPtr->inbih, 0L);
642 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
643 if (!infoPtr->outbih) {
644 WARN("Can't alloc output BIH\n");
648 if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
649 (DWORD)infoPtr->inbih,
650 (DWORD)infoPtr->outbih) != ICERR_OK) {
651 WARN("Can't get output BIH\n");
655 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
656 if (!infoPtr->outdata) {
657 WARN("Can't alloc output buffer\n");
661 if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
662 (DWORD)infoPtr->inbih,
663 (DWORD)infoPtr->outbih) != ICERR_OK) {
664 WARN("Can't begin decompression\n");
671 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
673 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
674 HINSTANCE hInstance = (HINSTANCE)wParam;
676 ANIMATE_Free(infoPtr);
679 TRACE("Closing avi!\n");
684 hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);
686 if (HIWORD(lParam)) {
687 TRACE("(\"%s\");\n", (LPSTR)lParam);
689 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
690 TRACE("No AVI resource found!\n");
691 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
692 WARN("No AVI file found!\n");
697 TRACE("(%u);\n", (WORD)LOWORD(lParam));
699 if (!ANIMATE_LoadResA(infoPtr, hInstance,
700 MAKEINTRESOURCEA((INT)lParam))) {
701 WARN("No AVI resource found!\n");
706 if (!ANIMATE_GetAviInfo(infoPtr)) {
707 WARN("Can't get AVI information\n");
708 ANIMATE_Free(infoPtr);
712 if (!ANIMATE_GetAviCodec(infoPtr)) {
713 WARN("Can't get AVI Codec\n");
714 ANIMATE_Free(infoPtr);
718 if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
719 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
720 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
723 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
724 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
731 /* << ANIMATE_Open32W >> */
733 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
735 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
741 ANIMATE_DoStop(infoPtr);
746 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
748 ANIMATE_INFO* infoPtr;
749 HMODULE hModule = LoadLibraryA("msvfw32.dll");
754 /* allocate memory for info structure */
755 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
757 ERR("could not allocate info memory!\n");
761 /* Temporary hack until we get dllglue up and running */
762 infoPtr->fnICOpen = (void*)GetProcAddress(hModule, "ICOpen");
763 infoPtr->fnICClose = (void*)GetProcAddress(hModule, "ICClose");
764 infoPtr->fnICSendMessage = (void*)GetProcAddress(hModule, "ICSendMessage");
765 infoPtr->fnICDecompress = (void*)GetProcAddress(hModule, "ICDecompress");
767 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
769 /* store crossref hWnd <-> info structure */
770 SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
771 infoPtr->hWnd = hWnd;
772 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
773 infoPtr->hbmPrevFrame = 0;
774 hModWinmm = LoadLibraryA("WINMM");
776 infoPtr->fnmmioOpenA = (void*)GetProcAddress(hModWinmm, "mmioOpenA");
777 infoPtr->fnmmioClose = (void*)GetProcAddress(hModWinmm, "mmioClose");
778 infoPtr->fnmmioAscend = (void*)GetProcAddress(hModWinmm, "mmioAscend");
779 infoPtr->fnmmioDescend = (void*)GetProcAddress(hModWinmm, "mmioDescend");
780 infoPtr->fnmmioSeek = (void*)GetProcAddress(hModWinmm, "mmioSeek");
781 infoPtr->fnmmioRead = (void*)GetProcAddress(hModWinmm, "mmioRead");
783 InitializeCriticalSection(&infoPtr->cs);
789 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
791 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
795 ANIMATE_Free(infoPtr);
797 /* free animate info data */
798 COMCTL32_Free(infoPtr);
799 SetWindowLongA(hWnd, 0, 0);
801 FreeLibrary(hModWinmm);
806 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
811 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
813 hBrush = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
816 GetClientRect(hWnd, &rect);
817 FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
822 static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
824 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
825 InvalidateRect(hWnd, NULL, TRUE);
830 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
832 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
833 if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
834 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
838 return ANIMATE_OpenA(hWnd, wParam, lParam);
840 /* case ACM_OPEN32W: FIXME!! */
841 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
844 return ANIMATE_Play(hWnd, wParam, lParam);
847 return ANIMATE_Stop(hWnd, wParam, lParam);
850 ANIMATE_Create(hWnd, wParam, lParam);
851 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
854 return HTTRANSPARENT;
857 ANIMATE_Destroy(hWnd, wParam, lParam);
858 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
861 ANIMATE_EraseBackground(hWnd, wParam, lParam);
864 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
867 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
869 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
870 infoPtr->hbrushBG = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
872 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
875 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
880 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
882 /* the animation isn't playing, don't paint */
883 if(!infoPtr->uTimer && !infoPtr->hThread)
884 /* default paint handling */
885 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
887 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
888 infoPtr->hbrushBG = SendMessageA(GetParent(hWnd), WM_CTLCOLORSTATIC,
893 EnterCriticalSection(&infoPtr->cs);
894 ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
895 LeaveCriticalSection(&infoPtr->cs);
900 HDC hDC = BeginPaint(hWnd, &ps);
902 EnterCriticalSection(&infoPtr->cs);
903 ANIMATE_PaintFrame(infoPtr, hDC);
904 LeaveCriticalSection(&infoPtr->cs);
912 ANIMATE_Size(hWnd, wParam, lParam);
913 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
917 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
919 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
925 void ANIMATE_Register(void)
929 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
930 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
931 wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
932 wndClass.cbClsExtra = 0;
933 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
934 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
935 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
936 wndClass.lpszClassName = ANIMATE_CLASSA;
938 RegisterClassA(&wndClass);
942 void ANIMATE_Unregister(void)
944 UnregisterClassA(ANIMATE_CLASSA, (HINSTANCE)NULL);