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
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(animate);
48 HIC (WINAPI *fnICOpen)(DWORD, DWORD, UINT);
49 LRESULT (WINAPI *fnICClose)(HIC);
50 LRESULT (WINAPI *fnICSendMessage)(HIC, UINT, DWORD, DWORD);
51 DWORD (WINAPIV *fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
56 /* reference to input stream (file or resource) */
58 HMMIO hMMio; /* handle to mmio stream */
60 /* information on the loaded AVI file */
63 LPBITMAPINFOHEADER inbih;
65 /* data for the decompressor */
67 LPBITMAPINFOHEADER outbih;
70 /* data for the background mechanism */
74 /* data for playing the file */
80 COLORREF transparentColor;
85 #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
86 #define ANIMATE_COLOR_NONE 0xffffffff
88 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
90 SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
91 MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
92 (LPARAM)infoPtr->hWnd);
95 static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
101 hrsrc = FindResourceA(hInst, lpName, "AVI");
105 infoPtr->hRes = LoadResource(hInst, hrsrc);
109 lpAvi = LockResource(infoPtr->hRes);
113 memset(&mminfo, 0, sizeof(mminfo));
114 mminfo.fccIOProc = FOURCC_MEM;
115 mminfo.pchBuffer = (LPSTR)lpAvi;
116 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
117 infoPtr->hMMio = mmioOpenA(NULL, &mminfo, MMIO_READ);
118 if (!infoPtr->hMMio) {
119 GlobalFree((HGLOBAL)lpAvi);
127 static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
129 infoPtr->hMMio = mmioOpenA((LPSTR)lpName, NULL,
130 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
139 static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
141 EnterCriticalSection(&infoPtr->cs);
143 /* should stop playing */
144 if (infoPtr->hThread)
146 if (!TerminateThread(infoPtr->hThread,0))
147 WARN("could not destroy animation thread!\n");
148 infoPtr->hThread = 0;
150 if (infoPtr->uTimer) {
151 KillTimer(infoPtr->hWnd, infoPtr->uTimer);
155 LeaveCriticalSection(&infoPtr->cs);
157 ANIMATE_Notify(infoPtr, ACN_STOP);
163 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
165 if (infoPtr->hMMio) {
166 ANIMATE_DoStop(infoPtr);
167 mmioClose(infoPtr->hMMio, 0);
169 FreeResource(infoPtr->hRes);
172 if (infoPtr->lpIndex) {
173 HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
174 infoPtr->lpIndex = NULL;
177 fnIC.fnICClose(infoPtr->hic);
180 if (infoPtr->inbih) {
181 HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
182 infoPtr->inbih = NULL;
184 if (infoPtr->outbih) {
185 HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
186 infoPtr->outbih = NULL;
188 if( infoPtr->indata )
190 HeapFree(GetProcessHeap(), 0, infoPtr->indata);
191 infoPtr->indata = NULL;
193 if( infoPtr->outdata )
195 HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
196 infoPtr->outdata = NULL;
198 if( infoPtr->hbmPrevFrame )
200 DeleteObject(infoPtr->hbmPrevFrame);
201 infoPtr->hbmPrevFrame = 0;
203 infoPtr->indata = infoPtr->outdata = NULL;
207 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
208 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
209 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
211 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
214 static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
220 /* create a transparency mask */
221 hdcMask = CreateCompatibleDC(hdcDest);
222 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
223 hbmOld = SelectObject(hdcMask, hbmMask);
225 SetBkColor(hdcSource,infoPtr->transparentColor);
226 BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
228 /* mask the source bitmap */
229 SetBkColor(hdcSource, RGB(0,0,0));
230 SetTextColor(hdcSource, RGB(255,255,255));
231 BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
233 /* mask the destination bitmap */
234 SetBkColor(hdcDest, RGB(255,255,255));
235 SetTextColor(hdcDest, RGB(0,0,0));
236 BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
238 /* combine source and destination */
239 BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
241 SelectObject(hdcMask, hbmOld);
242 DeleteObject(hbmMask);
246 static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
248 void* pBitmapData = NULL;
249 LPBITMAPINFO pBitmapInfo = NULL;
260 if (!hDC || !infoPtr->inbih)
265 pBitmapData = infoPtr->outdata;
266 pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
268 nWidth = infoPtr->outbih->biWidth;
269 nHeight = infoPtr->outbih->biHeight;
272 pBitmapData = infoPtr->indata;
273 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
275 nWidth = infoPtr->inbih->biWidth;
276 nHeight = infoPtr->inbih->biHeight;
279 if(!infoPtr->hbmPrevFrame)
281 infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
284 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
286 hdcMem = CreateCompatibleDC(hDC);
287 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
290 * we need to get the transparent color even without ACS_TRANSPARENT,
291 * because the style can be changed later on and the color should always
292 * be obtained in the first frame
294 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
296 infoPtr->transparentColor = GetPixel(hdcMem,0,0);
299 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
301 HDC hdcFinal = CreateCompatibleDC(hDC);
302 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
303 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
309 rect.bottom = nHeight;
311 if(!infoPtr->hbrushBG)
312 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
314 FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
315 ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
317 SelectObject(hdcFinal, hbmOld2);
318 SelectObject(hdcMem, hbmFinal);
320 DeleteObject(infoPtr->hbmPrevFrame);
321 infoPtr->hbmPrevFrame = hbmFinal;
324 if (GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_CENTER)
328 GetWindowRect(infoPtr->hWnd, &rect);
329 nOffsetX = ((rect.right - rect.left) - nWidth)/2;
330 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
332 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
334 SelectObject(hdcMem, hbmOld);
339 static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
343 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
345 EnterCriticalSection(&infoPtr->cs);
347 mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
348 mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
351 fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
352 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
353 LeaveCriticalSection(&infoPtr->cs);
354 WARN("Decompression error\n");
358 if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
359 ANIMATE_PaintFrame(infoPtr, hDC);
360 ReleaseDC(infoPtr->hWnd, hDC);
363 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
364 infoPtr->currFrame = infoPtr->nFromFrame;
365 if (infoPtr->nLoop != -1) {
366 if (--infoPtr->nLoop == 0) {
367 ANIMATE_DoStop(infoPtr);
371 LeaveCriticalSection(&infoPtr->cs);
376 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
378 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
383 WARN("animation structure undefined!\n");
389 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
391 hDC = GetDC(infoPtr->hWnd);
392 /* sometimes the animation window will be destroyed in between
393 * by the main program, so a ReleaseDC() error msg is possible */
394 infoPtr->hbrushBG = (HBRUSH)SendMessageA(GetParent(infoPtr->hWnd),
395 WM_CTLCOLORSTATIC, (WPARAM)hDC,
396 (LPARAM)infoPtr->hWnd);
397 ReleaseDC(infoPtr->hWnd,hDC);
400 EnterCriticalSection(&infoPtr->cs);
401 ANIMATE_DrawFrame(infoPtr);
402 LeaveCriticalSection(&infoPtr->cs);
404 /* time is in microseconds, we should convert it to milliseconds */
405 Sleep((infoPtr->mah.dwMicroSecPerFrame+500)/1000);
410 static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
412 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
418 if (infoPtr->hThread || infoPtr->uTimer) {
419 FIXME("Already playing ? what should I do ??\n");
420 ANIMATE_DoStop(infoPtr);
423 infoPtr->nFromFrame = (INT)LOWORD(lParam);
424 infoPtr->nToFrame = (INT)HIWORD(lParam);
425 infoPtr->nLoop = (INT)wParam;
427 if (infoPtr->nToFrame == 0xFFFF)
428 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
430 TRACE("(repeat=%d from=%d to=%d);\n",
431 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
433 if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
434 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
437 infoPtr->currFrame = infoPtr->nFromFrame;
439 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
440 TRACE("Using a timer\n");
441 /* create a timer to display AVI */
442 infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
446 TRACE("Using an animation thread\n");
447 infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr, 0, &threadID);
448 if(!infoPtr->hThread)
450 ERR("Could not create animation thread!\n");
456 ANIMATE_Notify(infoPtr, ACN_START);
462 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
471 if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
472 WARN("Can't find 'RIFF' chunk\n");
476 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
477 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
478 WARN("Can't find 'AVI ' chunk\n");
482 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
483 if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
484 WARN("Can't find 'hdrl' list\n");
488 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
489 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
490 WARN("Can't find 'avih' chunk\n");
494 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
496 TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
497 TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
498 TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
499 TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
500 TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
501 TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
502 TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
503 TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
504 TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
505 TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
507 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
509 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
510 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
511 WARN("Can't find 'strl' list\n");
515 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
516 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
517 WARN("Can't find 'strh' chunk\n");
521 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
523 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
524 HIBYTE(LOWORD(infoPtr->ash.fccType)),
525 LOBYTE(HIWORD(infoPtr->ash.fccType)),
526 HIBYTE(HIWORD(infoPtr->ash.fccType)));
527 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
528 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
529 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
530 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
531 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
532 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
533 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
534 TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
535 TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
536 TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
537 TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
538 TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
539 TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
540 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
541 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
542 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
543 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
545 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
547 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
548 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
549 WARN("Can't find 'strh' chunk\n");
553 infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
554 if (!infoPtr->inbih) {
555 WARN("Can't alloc input BIH\n");
559 mmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
561 TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
562 TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
563 TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
564 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
565 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
566 TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
567 TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
568 TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
569 TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
570 TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
571 TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
573 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
575 mmioAscend(infoPtr->hMMio, &mmckList, 0);
578 /* an AVI has 0 or 1 video stream, and to be animated should not contain
579 * an audio stream, so only one strl is allowed
581 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
582 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
583 WARN("There should be a single 'strl' list\n");
588 mmioAscend(infoPtr->hMMio, &mmckHead, 0);
590 /* no need to read optional JUNK chunk */
592 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
593 if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
594 WARN("Can't find 'movi' list\n");
598 /* FIXME: should handle the 'rec ' LIST when present */
600 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
601 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
602 if (!infoPtr->lpIndex) {
603 WARN("Can't alloc index array\n");
607 numFrame = insize = 0;
608 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
609 numFrame < infoPtr->mah.dwTotalFrames) {
610 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
611 if (insize < mmckInfo.cksize)
612 insize = mmckInfo.cksize;
614 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
616 if (numFrame != infoPtr->mah.dwTotalFrames) {
617 WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
620 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
621 WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
622 infoPtr->ash.dwSuggestedBufferSize = insize;
625 infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
626 if (!infoPtr->indata) {
627 WARN("Can't alloc input buffer\n");
635 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
639 /* check uncompressed AVI */
640 if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
641 (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')) ||
642 (infoPtr->ash.fccHandler == mmioFOURCC(0, 0, 0, 0)))
648 /* try to get a decompressor for that type */
649 infoPtr->hic = fnIC.fnICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
651 WARN("Can't load codec for the file\n");
655 outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
656 (DWORD)infoPtr->inbih, 0L);
658 infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
659 if (!infoPtr->outbih) {
660 WARN("Can't alloc output BIH\n");
664 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
665 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != outSize) {
666 WARN("Can't get output BIH\n");
670 infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
671 if (!infoPtr->outdata) {
672 WARN("Can't alloc output buffer\n");
676 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
677 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
678 WARN("Can't begin decompression\n");
685 static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
687 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
688 HINSTANCE hInstance = (HINSTANCE)wParam;
690 ANIMATE_Free(infoPtr);
691 infoPtr->hWnd = hWnd;
694 TRACE("Closing avi!\n");
695 /* installer of thebat! v1.62 requires FALSE here */
696 return (infoPtr->hMMio != 0);
700 hInstance = (HINSTANCE)GetWindowLongA(hWnd, GWL_HINSTANCE);
702 if (HIWORD(lParam)) {
703 TRACE("(\"%s\");\n", (LPSTR)lParam);
705 if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
706 TRACE("No AVI resource found!\n");
707 if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
708 WARN("No AVI file found!\n");
713 TRACE("(%u);\n", (WORD)LOWORD(lParam));
715 if (!ANIMATE_LoadResA(infoPtr, hInstance,
716 MAKEINTRESOURCEA((INT)lParam))) {
717 WARN("No AVI resource found!\n");
722 if (!ANIMATE_GetAviInfo(infoPtr)) {
723 WARN("Can't get AVI information\n");
724 ANIMATE_Free(infoPtr);
728 if (!ANIMATE_GetAviCodec(infoPtr)) {
729 WARN("Can't get AVI Codec\n");
730 ANIMATE_Free(infoPtr);
734 if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
735 SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
736 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
739 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
740 return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
747 /* << ANIMATE_Open32W >> */
749 static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
751 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
757 ANIMATE_DoStop(infoPtr);
762 static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
764 ANIMATE_INFO* infoPtr;
766 if (!fnIC.hModule) /* FIXME: not thread safe */
768 /* since there's a circular dep between msvfw32 and comctl32, we could either:
769 * - fix the build chain to allow this circular dep
770 * - handle it by hand
771 * AJ wants the latter :-(
773 fnIC.hModule = LoadLibraryA("msvfw32.dll");
774 if (!fnIC.hModule) return FALSE;
776 fnIC.fnICOpen = (void*)GetProcAddress(fnIC.hModule, "ICOpen");
777 fnIC.fnICClose = (void*)GetProcAddress(fnIC.hModule, "ICClose");
778 fnIC.fnICSendMessage = (void*)GetProcAddress(fnIC.hModule, "ICSendMessage");
779 fnIC.fnICDecompress = (void*)GetProcAddress(fnIC.hModule, "ICDecompress");
782 /* allocate memory for info structure */
783 infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
785 ERR("could not allocate info memory!\n");
789 TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
791 /* store crossref hWnd <-> info structure */
792 SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
793 infoPtr->hWnd = hWnd;
794 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
795 infoPtr->hbmPrevFrame = 0;
797 InitializeCriticalSection(&infoPtr->cs);
803 static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
805 ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
809 ANIMATE_Free(infoPtr);
811 /* free animate info data */
812 COMCTL32_Free(infoPtr);
813 SetWindowLongA(hWnd, 0, 0);
819 static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
824 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
826 hBrush = (HBRUSH)SendMessageA(GetParent(hWnd),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);
854 /* case ACM_OPEN32W: FIXME!! */
855 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
858 return ANIMATE_Play(hWnd, wParam, lParam);
861 return ANIMATE_Stop(hWnd, wParam, lParam);
864 ANIMATE_Create(hWnd, wParam, lParam);
865 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
868 return HTTRANSPARENT;
871 ANIMATE_Destroy(hWnd, wParam, lParam);
872 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
875 ANIMATE_EraseBackground(hWnd, wParam, lParam);
878 /* case WM_STYLECHANGED: FIXME shall we do something ?? */
881 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
883 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
884 infoPtr->hbrushBG = (HBRUSH)SendMessageA(GetParent(hWnd),
886 wParam, (LPARAM)hWnd);
888 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
891 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
896 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
898 /* the animation isn't playing, don't paint */
899 if(!infoPtr->uTimer && !infoPtr->hThread)
900 /* default paint handling */
901 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
903 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
904 infoPtr->hbrushBG = (HBRUSH)SendMessageA(GetParent(hWnd),
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 ANIMATE_Size(hWnd, wParam, lParam);
930 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
933 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
934 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
936 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
941 void ANIMATE_Register(void)
945 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
946 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
947 wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
948 wndClass.cbClsExtra = 0;
949 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
950 wndClass.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
951 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
952 wndClass.lpszClassName = ANIMATE_CLASSA;
954 RegisterClassA(&wndClass);
958 void ANIMATE_Unregister(void)
960 UnregisterClassA(ANIMATE_CLASSA, NULL);