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
23 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(animate);
29 /* pointer to msvideo functions. it's easier to put them here.
30 * to be correct, they should be defined on a per process basis, but
31 * this would required a per process storage. We're using a per object
32 * storage instead, which is not efficient on memory usage, but
33 * will lead to less bugs in the future
35 HIC WINAPI (*fnICOpen)(DWORD, DWORD, UINT);
36 LRESULT WINAPI (*fnICClose)(HIC);
37 LRESULT WINAPI (*fnICSendMessage)(HIC, UINT, DWORD, DWORD);
38 DWORD WINAPIV (*fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
40 HMMIO WINAPI (*fnmmioOpenA)(LPSTR,MMIOINFO*,DWORD);
41 MMRESULT WINAPI (*fnmmioClose)(HMMIO,UINT);
42 UINT WINAPI (*fnmmioAscend)(HMMIO,MMCKINFO*,UINT);
43 UINT WINAPI (*fnmmioDescend)(HMMIO,MMCKINFO*,const MMCKINFO*,UINT);
44 LONG WINAPI (*fnmmioSeek)(HMMIO,LONG,INT);
45 LONG WINAPI (*fnmmioRead)(HMMIO,HPSTR,LONG);
47 /* reference to input stream (file or resource) */
49 HMMIO hMMio; /* handle to mmio stream */
51 /* information on the loaded AVI file */
54 LPBITMAPINFOHEADER inbih;
56 /* data for the decompressor */
58 LPBITMAPINFOHEADER outbih;
61 /* data for the background mechanism */
65 /* data for playing the file */
71 COLORREF transparentColor;
76 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
77 #define ANIMATE_COLOR_NONE 0xffffffff
81 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
83 SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
84 MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
85 (LPARAM)infoPtr->hWnd);
88 static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
94 hrsrc = FindResourceA(hInst, lpName, "AVI");
98 infoPtr->hRes = LoadResource(hInst, hrsrc);
102 lpAvi = LockResource(infoPtr->hRes);
106 memset(&mminfo, 0, sizeof(mminfo));
107 mminfo.fccIOProc = FOURCC_MEM;
108 mminfo.pchBuffer = (LPSTR)lpAvi;
109 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
110 infoPtr->hMMio = infoPtr->fnmmioOpenA(NULL, &mminfo, MMIO_READ);
112 if (!infoPtr->hMMio) {
113 GlobalFree((HGLOBAL)lpAvi);
121 static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
123 infoPtr->hMMio = infoPtr->fnmmioOpenA((LPSTR)lpName, NULL,
124 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
133 static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
135 EnterCriticalSection(&infoPtr->cs);
137 /* should stop playing */
138 if (infoPtr->hThread)
140 if (!TerminateThread(infoPtr->hThread,0))
141 WARN("could not destroy animation thread!\n");
142 infoPtr->hThread = 0;
144 if (infoPtr->uTimer) {
145 KillTimer(infoPtr->hWnd, infoPtr->uTimer);
149 LeaveCriticalSection(&infoPtr->cs);
151 ANIMATE_Notify(infoPtr, ACN_STOP);
157 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
159 if (infoPtr->hMMio) {
160 ANIMATE_DoStop(infoPtr);
161 infoPtr->fnmmioClose(infoPtr->hMMio, 0);
163 FreeResource(infoPtr->hRes);
166 if (infoPtr->lpIndex) {
167 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
168 infoPtr->lpIndex = NULL;
171 (infoPtr->fnICClose)(infoPtr->hic);
174 if (infoPtr->inbih) {
175 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
176 infoPtr->inbih = NULL;
178 if (infoPtr->outbih) {
179 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
180 infoPtr->outbih = NULL;
182 if( infoPtr->indata )
184 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
185 infoPtr->indata = NULL;
187 if( infoPtr->outdata )
189 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
190 infoPtr->outdata = NULL;
192 if( infoPtr->hbmPrevFrame )
194 DeleteObject(infoPtr->hbmPrevFrame);
195 infoPtr->hbmPrevFrame = 0;
197 infoPtr->indata = infoPtr->outdata = NULL;
201 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
202 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
203 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
205 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
208 static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
214 /* create a transparency mask */
215 hdcMask = CreateCompatibleDC(hdcDest);
216 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
217 hbmOld = SelectObject(hdcMask, hbmMask);
219 SetBkColor(hdcSource,infoPtr->transparentColor);
220 BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
222 /* mask the source bitmap */
223 SetBkColor(hdcSource, RGB(0,0,0));
224 SetTextColor(hdcSource, RGB(255,255,255));
225 BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
227 /* mask the destination bitmap */
228 SetBkColor(hdcDest, RGB(255,255,255));
229 SetTextColor(hdcDest, RGB(0,0,0));
230 BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
232 /* combine source and destination */
233 BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
235 SelectObject(hdcMask, hbmOld);
236 DeleteObject(hbmMask);
240 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
242 void* pBitmapData = NULL;
243 LPBITMAPINFO pBitmapInfo = NULL;
254 if (!hDC || !infoPtr->inbih)
259 pBitmapData = infoPtr->outdata;
260 pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
262 nWidth = infoPtr->outbih->biWidth;
263 nHeight = infoPtr->outbih->biHeight;
266 pBitmapData = infoPtr->indata;
267 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
269 nWidth = infoPtr->inbih->biWidth;
270 nHeight = infoPtr->inbih->biHeight;
273 if(!infoPtr->hbmPrevFrame)
275 infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
278 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
280 hdcMem = CreateCompatibleDC(hDC);
281 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
284 * we need to get the transparent color even without ACS_TRANSPARENT,
285 * because the style can be changed later on and the color should always
286 * be obtained in the first frame
288 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
290 infoPtr->transparentColor = GetPixel(hdcMem,0,0);
293 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
295 HDC hdcFinal = CreateCompatibleDC(hDC);
296 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
297 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
303 rect.bottom = nHeight;
305 if(!infoPtr->hbrushBG)
306 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
308 FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
309 ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
311 SelectObject(hdcFinal, hbmOld2);
312 SelectObject(hdcMem, hbmFinal);
314 DeleteObject(infoPtr->hbmPrevFrame);
315 infoPtr->hbmPrevFrame = hbmFinal;
318 if (GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_CENTER)
322 GetWindowRect(infoPtr->hWnd, &rect);
323 nOffsetX = ((rect.right - rect.left) - nWidth)/2;
324 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
326 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
328 SelectObject(hdcMem, hbmOld);
333 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
337 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
339 EnterCriticalSection(&infoPtr->cs);
341 infoPtr->fnmmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
342 infoPtr->fnmmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
345 (infoPtr->fnICDecompress)(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
346 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
347 LeaveCriticalSection(&infoPtr->cs);
348 WARN("Decompression error\n");
352 if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
353 ANIMATE_PaintFrame(infoPtr, hDC);
354 ReleaseDC(infoPtr->hWnd, hDC);
357 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
358 infoPtr->currFrame = infoPtr->nFromFrame;
359 if (infoPtr->nLoop != -1) {
360 if (--infoPtr->nLoop == 0) {
361 ANIMATE_DoStop(infoPtr);
365 LeaveCriticalSection(&infoPtr->cs);
370 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
372 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
377 WARN("animation structure undefined!\n");
383 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
385 hDC = GetDC(infoPtr->hWnd);
386 infoPtr->hbrushBG = SendMessageA(GetParent(infoPtr->hWnd),WM_CTLCOLORSTATIC,hDC, infoPtr->hWnd);
387 ReleaseDC(infoPtr->hWnd,hDC);
390 EnterCriticalSection(&infoPtr->cs);
391 ANIMATE_DrawFrame(infoPtr);
392 LeaveCriticalSection(&infoPtr->cs);
394 /* time is in microseconds, we should convert it to milliseconds */
395 Sleep((infoPtr->mah.dwMicroSecPerFrame+500)/1000);
400 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
402 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
408 if (infoPtr->hThread || infoPtr->uTimer) {
409 FIXME("Already playing ? what should I do ??\n");
410 ANIMATE_DoStop(infoPtr);
413 infoPtr->nFromFrame = (INT)LOWORD(lParam);
414 infoPtr->nToFrame = (INT)HIWORD(lParam);
415 infoPtr->nLoop = (INT)wParam;
417 if (infoPtr->nToFrame == 0xFFFF)
418 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
420 TRACE("(repeat=%d from=%d to=%d);\n",
421 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
423 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
424 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
427 infoPtr->currFrame = infoPtr->nFromFrame;
429 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
430 TRACE("Using a timer\n");
431 /* create a timer to display AVI */
432 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
436 TRACE("Using an animation thread\n");
437 infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr,0,0 &threadID);
438 if(!infoPtr->hThread)
440 ERR("Could not create animation thread!\n");
446 ANIMATE_Notify(infoPtr, ACN_START);
452 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
461 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
462 WARN("Can't find 'RIFF' chunk\n");
466 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
467 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
468 WARN("Can't find 'AVI ' chunk\n");
472 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
473 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
474 WARN("Can't find 'hdrl' list\n");
478 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
479 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
480 WARN("Can't find 'avih' chunk\n");
484 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
485 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
486 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
487 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
488 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
489 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
490 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
491 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
492 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
493 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
494 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
495 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
497 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
498 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
499 WARN("Can't find 'strl' list\n");
503 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
504 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
505 WARN("Can't find 'strh' chunk\n");
509 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
510 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
511 HIBYTE(LOWORD(infoPtr->ash.fccType)),
512 LOBYTE(HIWORD(infoPtr->ash.fccType)),
513 HIBYTE(HIWORD(infoPtr->ash.fccType)));
514 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
515 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
516 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
517 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
518 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
519 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
520 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
521 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
522 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
523 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
524 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
525 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
526 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
527 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
528 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
529 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
530 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
531 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
533 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
534 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
535 WARN("Can't find 'strh' chunk\n");
539 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
540 if (!infoPtr->inbih) {
541 WARN("Can't alloc input BIH\n");
545 infoPtr->fnmmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
546 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
547 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
548 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
549 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
550 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
551 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
552 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
553 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
554 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
555 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
556 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
557 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
559 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckList, 0);
562 /* an AVI has 0 or 1 video stream, and to be animated should not contain
563 * an audio stream, so only one strl is allowed
565 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
566 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
567 WARN("There should be a single 'strl' list\n");
572 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckHead, 0);
574 /* no need to read optional JUNK chunk */
576 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
577 if (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
578 WARN("Can't find 'movi' list\n");
582 /* FIXME: should handle the 'rec ' LIST when present */
584 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
585 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
586 if (!infoPtr->lpIndex) {
587 WARN("Can't alloc index array\n");
591 numFrame = insize = 0;
592 while (infoPtr->fnmmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
593 numFrame < infoPtr->mah.dwTotalFrames) {
594 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
595 if (insize < mmckInfo.cksize)
596 insize = mmckInfo.cksize;
598 infoPtr->fnmmioAscend(infoPtr->hMMio, &mmckInfo, 0);
600 if (numFrame != infoPtr->mah.dwTotalFrames) {
601 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
604 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
605 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
606 infoPtr->ash.dwSuggestedBufferSize = insize;
609 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
610 if (!infoPtr->indata) {
611 WARN("Can't alloc input buffer\n");
619 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
623 /* check uncompressed AVI */
624 if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
625 (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')))
631 /* try to get a decompressor for that type */
632 infoPtr->hic = (infoPtr->fnICOpen)(ICTYPE_VIDEO,
633 infoPtr->ash.fccHandler,
636 WARN("Can't load codec for the file\n");
640 outSize = (infoPtr->fnICSendMessage)(infoPtr->hic,
641 ICM_DECOMPRESS_GET_FORMAT,
642 (DWORD)infoPtr->inbih, 0L);
643 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
644 if (!infoPtr->outbih) {
645 WARN("Can't alloc output BIH\n");
649 if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
650 (DWORD)infoPtr->inbih,
651 (DWORD)infoPtr->outbih) != ICERR_OK) {
652 WARN("Can't get output BIH\n");
656 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
657 if (!infoPtr->outdata) {
658 WARN("Can't alloc output buffer\n");
662 if ((infoPtr->fnICSendMessage)(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
663 (DWORD)infoPtr->inbih,
664 (DWORD)infoPtr->outbih) != ICERR_OK) {
665 WARN("Can't begin decompression\n");
672 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
674 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
675 HINSTANCE hInstance = (HINSTANCE)wParam;
677 ANIMATE_Free(infoPtr);
680 TRACE("Closing avi!\n");
685 hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);
687 if (HIWORD(lParam)) {
688 TRACE("(\"%s\");\n", (LPSTR)lParam);
690 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
691 TRACE("No AVI resource found!\n");
692 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
693 WARN("No AVI file found!\n");
698 TRACE("(%u);\n", (WORD)LOWORD(lParam));
700 if (!ANIMATE_LoadResA(infoPtr, hInstance,
701 MAKEINTRESOURCEA((INT)lParam))) {
702 WARN("No AVI resource found!\n");
707 if (!ANIMATE_GetAviInfo(infoPtr)) {
708 WARN("Can't get AVI information\n");
709 ANIMATE_Free(infoPtr);
713 if (!ANIMATE_GetAviCodec(infoPtr)) {
714 WARN("Can't get AVI Codec\n");
715 ANIMATE_Free(infoPtr);
719 if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
720 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
721 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
724 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
725 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
732 /* << ANIMATE_Open32W >> */
734 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
736 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
742 ANIMATE_DoStop(infoPtr);
747 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
749 ANIMATE_INFO* infoPtr;
750 HMODULE hModule = LoadLibraryA("msvfw32.dll");
755 /* allocate memory for info structure */
756 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
758 ERR("could not allocate info memory!\n");
762 /* Temporary hack until we get dllglue up and running */
763 infoPtr->fnICOpen = (void*)GetProcAddress(hModule, "ICOpen");
764 infoPtr->fnICClose = (void*)GetProcAddress(hModule, "ICClose");
765 infoPtr->fnICSendMessage = (void*)GetProcAddress(hModule, "ICSendMessage");
766 infoPtr->fnICDecompress = (void*)GetProcAddress(hModule, "ICDecompress");
768 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
770 /* store crossref hWnd <-> info structure */
771 SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
772 infoPtr->hWnd = hWnd;
773 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
774 infoPtr->hbmPrevFrame = 0;
775 hModWinmm = LoadLibraryA("WINMM");
777 infoPtr->fnmmioOpenA = (void*)GetProcAddress(hModWinmm, "mmioOpenA");
778 infoPtr->fnmmioClose = (void*)GetProcAddress(hModWinmm, "mmioClose");
779 infoPtr->fnmmioAscend = (void*)GetProcAddress(hModWinmm, "mmioAscend");
780 infoPtr->fnmmioDescend = (void*)GetProcAddress(hModWinmm, "mmioDescend");
781 infoPtr->fnmmioSeek = (void*)GetProcAddress(hModWinmm, "mmioSeek");
782 infoPtr->fnmmioRead = (void*)GetProcAddress(hModWinmm, "mmioRead");
784 InitializeCriticalSection(&infoPtr->cs);
790 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
792 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
796 ANIMATE_Free(infoPtr);
798 /* free animate info data */
799 COMCTL32_Free(infoPtr);
800 SetWindowLongA(hWnd, 0, 0);
802 FreeLibrary(hModWinmm);
807 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
812 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
814 hBrush = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
817 GetClientRect(hWnd, &rect);
818 FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
823 static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
825 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
826 InvalidateRect(hWnd, NULL, TRUE);
831 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
833 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
834 if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
835 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
839 return ANIMATE_OpenA(hWnd, wParam, lParam);
841 /* case ACM_OPEN32W: FIXME!! */
842 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
845 return ANIMATE_Play(hWnd, wParam, lParam);
848 return ANIMATE_Stop(hWnd, wParam, lParam);
851 ANIMATE_Create(hWnd, wParam, lParam);
852 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
855 return HTTRANSPARENT;
858 ANIMATE_Destroy(hWnd, wParam, lParam);
859 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
862 ANIMATE_EraseBackground(hWnd, wParam, lParam);
865 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
868 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
870 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
871 infoPtr->hbrushBG = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd);
873 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
876 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
881 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
883 /* the animation isn't playing, don't paint */
884 if(!infoPtr->uTimer && !infoPtr->hThread)
885 /* default paint handling */
886 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
888 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
889 infoPtr->hbrushBG = SendMessageA(GetParent(hWnd), WM_CTLCOLORSTATIC,
894 EnterCriticalSection(&infoPtr->cs);
895 ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
896 LeaveCriticalSection(&infoPtr->cs);
901 HDC hDC = BeginPaint(hWnd, &ps);
903 EnterCriticalSection(&infoPtr->cs);
904 ANIMATE_PaintFrame(infoPtr, hDC);
905 LeaveCriticalSection(&infoPtr->cs);
913 ANIMATE_Size(hWnd, wParam, lParam);
914 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
918 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
920 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
926 void ANIMATE_Register(void)
930 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
931 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
932 wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
933 wndClass.cbClsExtra = 0;
934 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
935 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
936 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
937 wndClass.lpszClassName = ANIMATE_CLASSA;
939 RegisterClassA(&wndClass);
943 void ANIMATE_Unregister(void)
945 UnregisterClassA(ANIMATE_CLASSA, (HINSTANCE)NULL);