1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
5 * Copyright 1998, 1999 Eric Kohl
6 * Copyright 1999 Eric Pouech
7 * Copyright 2005 Dimitrie O. Paun
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Mar. 15, 2005, by Dimitrie O. Paun.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * - check for the 'rec ' list in some AVI files
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(animate);
53 HIC (WINAPI *fnICOpen)(DWORD, DWORD, UINT);
54 LRESULT (WINAPI *fnICClose)(HIC);
55 LRESULT (WINAPI *fnICSendMessage)(HIC, UINT, DWORD_PTR, DWORD_PTR);
56 DWORD (WINAPIV *fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
61 /* reference to input stream (file or resource) */
63 HMMIO hMMio; /* handle to mmio stream */
67 /* information on the loaded AVI file */
70 LPBITMAPINFOHEADER inbih;
72 /* data for the decompressor */
74 LPBITMAPINFOHEADER outbih;
77 /* data for the background mechanism */
83 /* data for playing the file */
88 /* transparency info*/
89 COLORREF transparentColor;
94 #define ANIMATE_COLOR_NONE 0xffffffff
96 static void ANIMATE_Notify(const ANIMATE_INFO *infoPtr, UINT notif)
98 SendMessageW(infoPtr->hwndNotify, WM_COMMAND,
99 MAKEWPARAM(GetDlgCtrlID(infoPtr->hwndSelf), notif),
100 (LPARAM)infoPtr->hwndSelf);
103 static BOOL ANIMATE_LoadResW(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPCWSTR lpName)
105 static const WCHAR aviW[] = { 'A', 'V', 'I', 0 };
110 hrsrc = FindResourceW(hInst, lpName, aviW);
114 infoPtr->hRes = LoadResource(hInst, hrsrc);
118 lpAvi = LockResource(infoPtr->hRes);
122 memset(&mminfo, 0, sizeof(mminfo));
123 mminfo.fccIOProc = FOURCC_MEM;
124 mminfo.pchBuffer = (LPSTR)lpAvi;
125 mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
126 infoPtr->hMMio = mmioOpenW(NULL, &mminfo, MMIO_READ);
129 FreeResource(infoPtr->hRes);
137 static BOOL ANIMATE_LoadFileW(ANIMATE_INFO *infoPtr, LPWSTR lpName)
139 infoPtr->hMMio = mmioOpenW(lpName, 0, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
141 if(!infoPtr->hMMio) return FALSE;
146 static BOOL ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
148 BOOL stopped = FALSE;
150 EnterCriticalSection(&infoPtr->cs);
152 /* should stop playing */
153 if (infoPtr->hThread)
155 HANDLE handle = infoPtr->hThread;
157 TRACE("stopping animation thread\n");
158 infoPtr->hThread = 0;
159 SetEvent( infoPtr->hStopEvent );
161 if (infoPtr->threadId != GetCurrentThreadId())
163 LeaveCriticalSection(&infoPtr->cs); /* leave it a chance to run */
164 MsgWaitForMultipleObjects( 1, &handle, FALSE, INFINITE, QS_ALLINPUT );
165 TRACE("animation thread stopped\n");
166 EnterCriticalSection(&infoPtr->cs);
169 CloseHandle( handle );
170 CloseHandle( infoPtr->hStopEvent );
171 infoPtr->hStopEvent = 0;
174 if (infoPtr->uTimer) {
175 KillTimer(infoPtr->hwndSelf, infoPtr->uTimer);
180 LeaveCriticalSection(&infoPtr->cs);
183 ANIMATE_Notify(infoPtr, ACN_STOP);
189 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
191 if (infoPtr->hMMio) {
192 ANIMATE_DoStop(infoPtr);
193 mmioClose(infoPtr->hMMio, 0);
195 FreeResource(infoPtr->hRes);
198 Free (infoPtr->lpIndex);
199 infoPtr->lpIndex = NULL;
201 fnIC.fnICClose(infoPtr->hic);
204 Free (infoPtr->inbih);
205 infoPtr->inbih = NULL;
206 Free (infoPtr->outbih);
207 infoPtr->outbih = NULL;
208 Free (infoPtr->indata);
209 infoPtr->indata = NULL;
210 Free (infoPtr->outdata);
211 infoPtr->outdata = NULL;
212 if( infoPtr->hbmPrevFrame )
214 DeleteObject(infoPtr->hbmPrevFrame);
215 infoPtr->hbmPrevFrame = 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 const *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 BOOL ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
259 void const *pBitmapData;
260 BITMAPINFO const *pBitmapInfo;
268 if (!hDC || !infoPtr->inbih)
273 pBitmapData = infoPtr->outdata;
274 pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
276 nWidth = infoPtr->outbih->biWidth;
277 nHeight = infoPtr->outbih->biHeight;
281 pBitmapData = infoPtr->indata;
282 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
284 nWidth = infoPtr->inbih->biWidth;
285 nHeight = infoPtr->inbih->biHeight;
288 if(!infoPtr->hbmPrevFrame)
290 infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
293 hdcMem = CreateCompatibleDC(hDC);
294 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
296 SetDIBits(hdcMem, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, pBitmapInfo, DIB_RGB_COLORS);
299 * we need to get the transparent color even without ACS_TRANSPARENT,
300 * because the style can be changed later on and the color should always
301 * be obtained in the first frame
303 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
305 infoPtr->transparentColor = GetPixel(hdcMem,0,0);
308 if(infoPtr->dwStyle & ACS_TRANSPARENT)
310 HDC hdcFinal = CreateCompatibleDC(hDC);
311 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
312 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
318 rect.bottom = nHeight;
320 if(!infoPtr->hbrushBG)
321 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
323 FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
324 ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
326 SelectObject(hdcFinal, hbmOld2);
327 SelectObject(hdcMem, hbmFinal);
329 DeleteObject(infoPtr->hbmPrevFrame);
330 infoPtr->hbmPrevFrame = hbmFinal;
333 if (infoPtr->dwStyle & ACS_CENTER)
337 GetWindowRect(infoPtr->hwndSelf, &rect);
338 nOffsetX = ((rect.right - rect.left) - nWidth)/2;
339 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
341 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
343 SelectObject(hdcMem, hbmOld);
348 static BOOL ANIMATE_DrawFrame(ANIMATE_INFO *infoPtr, HDC hDC)
350 TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
352 mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
353 mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
356 fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
357 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
358 WARN("Decompression error\n");
362 ANIMATE_PaintFrame(infoPtr, hDC);
364 if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
365 infoPtr->currFrame = infoPtr->nFromFrame;
366 if (infoPtr->nLoop != -1) {
367 if (--infoPtr->nLoop == 0) {
368 ANIMATE_DoStop(infoPtr);
376 static LRESULT ANIMATE_Timer(ANIMATE_INFO *infoPtr)
380 if ((hDC = GetDC(infoPtr->hwndSelf)) != 0)
382 if (infoPtr->dwStyle & ACS_TRANSPARENT)
383 infoPtr->hbrushBG = (HBRUSH)SendMessageW(infoPtr->hwndNotify,
385 (WPARAM)hDC, (LPARAM)infoPtr->hwndSelf);
386 EnterCriticalSection(&infoPtr->cs);
387 ANIMATE_DrawFrame(infoPtr, hDC);
388 LeaveCriticalSection(&infoPtr->cs);
390 ReleaseDC(infoPtr->hwndSelf, hDC);
396 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
398 ANIMATE_INFO *infoPtr = (ANIMATE_INFO *)ptr_;
404 HDC hDC = GetDC(infoPtr->hwndSelf);
406 if (infoPtr->dwStyle & ACS_TRANSPARENT)
407 infoPtr->hbrushBG = (HBRUSH)SendMessageW(infoPtr->hwndNotify,
409 (WPARAM)hDC, (LPARAM)infoPtr->hwndSelf);
410 EnterCriticalSection(&infoPtr->cs);
411 ANIMATE_DrawFrame(infoPtr, hDC);
412 timeout = infoPtr->mah.dwMicroSecPerFrame;
413 event = infoPtr->hStopEvent;
414 LeaveCriticalSection(&infoPtr->cs);
416 ReleaseDC(infoPtr->hwndSelf, hDC);
418 /* time is in microseconds, we should convert it to milliseconds */
419 if ((event == 0) || WaitForSingleObject( event, (timeout+500)/1000) == WAIT_OBJECT_0)
425 static LRESULT ANIMATE_Play(ANIMATE_INFO *infoPtr, UINT cRepeat, WORD wFrom, WORD wTo)
431 if (infoPtr->hThread || infoPtr->uTimer) {
432 TRACE("Already playing\n");
436 infoPtr->nFromFrame = wFrom;
437 infoPtr->nToFrame = wTo;
438 infoPtr->nLoop = cRepeat;
440 if (infoPtr->nToFrame == 0xFFFF)
441 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
443 TRACE("(repeat=%d from=%d to=%d);\n",
444 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
446 if (infoPtr->nFromFrame >= infoPtr->mah.dwTotalFrames &&
447 (SHORT)infoPtr->nFromFrame < 0)
448 infoPtr->nFromFrame = 0;
450 if (infoPtr->nFromFrame > infoPtr->nToFrame ||
451 infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
454 infoPtr->currFrame = infoPtr->nFromFrame;
456 /* seek - doesn't need to start a thread or set a timer and neither
457 * does it send a notification */
458 if (infoPtr->nFromFrame == infoPtr->nToFrame)
462 if ((hDC = GetDC(infoPtr->hwndSelf)) != 0)
464 if (infoPtr->dwStyle & ACS_TRANSPARENT)
465 infoPtr->hbrushBG = (HBRUSH)SendMessageW(infoPtr->hwndNotify,
467 (WPARAM)hDC, (LPARAM)infoPtr->hwndSelf);
468 ANIMATE_DrawFrame(infoPtr, hDC);
470 ReleaseDC(infoPtr->hwndSelf, hDC);
475 if (infoPtr->dwStyle & ACS_TIMER)
477 TRACE("Using a timer\n");
478 /* create a timer to display AVI */
479 infoPtr->uTimer = SetTimer(infoPtr->hwndSelf, 1,
480 infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
484 if(infoPtr->dwStyle & ACS_TRANSPARENT)
485 infoPtr->hbrushBG = (HBRUSH)SendMessageW(infoPtr->hwndNotify,
486 WM_CTLCOLORSTATIC, 0,
487 (LPARAM)infoPtr->hwndSelf);
489 TRACE("Using an animation thread\n");
490 infoPtr->hStopEvent = CreateEventW( NULL, TRUE, FALSE, NULL );
491 infoPtr->hThread = CreateThread(0, 0, ANIMATE_AnimationThread,
492 (LPVOID)infoPtr, 0, &infoPtr->threadId);
493 if(!infoPtr->hThread) return FALSE;
497 ANIMATE_Notify(infoPtr, ACN_START);
503 static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
512 if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
513 WARN("Can't find 'RIFF' chunk\n");
517 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
518 (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
519 WARN("Can't find 'AVI ' chunk\n");
523 mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
524 if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
525 WARN("Can't find 'hdrl' list\n");
529 mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
530 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
531 WARN("Can't find 'avih' chunk\n");
535 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
537 TRACE("mah.dwMicroSecPerFrame=%d\n", infoPtr->mah.dwMicroSecPerFrame);
538 TRACE("mah.dwMaxBytesPerSec=%d\n", infoPtr->mah.dwMaxBytesPerSec);
539 TRACE("mah.dwPaddingGranularity=%d\n", infoPtr->mah.dwPaddingGranularity);
540 TRACE("mah.dwFlags=%d\n", infoPtr->mah.dwFlags);
541 TRACE("mah.dwTotalFrames=%d\n", infoPtr->mah.dwTotalFrames);
542 TRACE("mah.dwInitialFrames=%d\n", infoPtr->mah.dwInitialFrames);
543 TRACE("mah.dwStreams=%d\n", infoPtr->mah.dwStreams);
544 TRACE("mah.dwSuggestedBufferSize=%d\n", infoPtr->mah.dwSuggestedBufferSize);
545 TRACE("mah.dwWidth=%d\n", infoPtr->mah.dwWidth);
546 TRACE("mah.dwHeight=%d\n", infoPtr->mah.dwHeight);
548 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
550 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
551 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
552 WARN("Can't find 'strl' list\n");
556 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
557 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
558 WARN("Can't find 'strh' chunk\n");
562 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
564 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
565 HIBYTE(LOWORD(infoPtr->ash.fccType)),
566 LOBYTE(HIWORD(infoPtr->ash.fccType)),
567 HIBYTE(HIWORD(infoPtr->ash.fccType)));
568 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
569 HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
570 LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
571 HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
572 TRACE("ash.dwFlags=%d\n", infoPtr->ash.dwFlags);
573 TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
574 TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
575 TRACE("ash.dwInitialFrames=%d\n", infoPtr->ash.dwInitialFrames);
576 TRACE("ash.dwScale=%d\n", infoPtr->ash.dwScale);
577 TRACE("ash.dwRate=%d\n", infoPtr->ash.dwRate);
578 TRACE("ash.dwStart=%d\n", infoPtr->ash.dwStart);
579 TRACE("ash.dwLength=%d\n", infoPtr->ash.dwLength);
580 TRACE("ash.dwSuggestedBufferSize=%d\n", infoPtr->ash.dwSuggestedBufferSize);
581 TRACE("ash.dwQuality=%d\n", infoPtr->ash.dwQuality);
582 TRACE("ash.dwSampleSize=%d\n", infoPtr->ash.dwSampleSize);
583 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
584 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
586 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
588 mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
589 if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
590 WARN("Can't find 'strh' chunk\n");
594 infoPtr->inbih = Alloc(mmckInfo.cksize);
595 if (!infoPtr->inbih) {
596 WARN("Can't alloc input BIH\n");
600 mmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
602 TRACE("bih.biSize=%d\n", infoPtr->inbih->biSize);
603 TRACE("bih.biWidth=%d\n", infoPtr->inbih->biWidth);
604 TRACE("bih.biHeight=%d\n", infoPtr->inbih->biHeight);
605 TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
606 TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
607 TRACE("bih.biCompression=%d\n", infoPtr->inbih->biCompression);
608 TRACE("bih.biSizeImage=%d\n", infoPtr->inbih->biSizeImage);
609 TRACE("bih.biXPelsPerMeter=%d\n", infoPtr->inbih->biXPelsPerMeter);
610 TRACE("bih.biYPelsPerMeter=%d\n", infoPtr->inbih->biYPelsPerMeter);
611 TRACE("bih.biClrUsed=%d\n", infoPtr->inbih->biClrUsed);
612 TRACE("bih.biClrImportant=%d\n", infoPtr->inbih->biClrImportant);
614 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
616 mmioAscend(infoPtr->hMMio, &mmckList, 0);
619 /* an AVI has 0 or 1 video stream, and to be animated should not contain
620 * an audio stream, so only one strl is allowed
622 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
623 if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
624 WARN("There should be a single 'strl' list\n");
629 mmioAscend(infoPtr->hMMio, &mmckHead, 0);
631 /* no need to read optional JUNK chunk */
633 mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
634 if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
635 WARN("Can't find 'movi' list\n");
639 /* FIXME: should handle the 'rec ' LIST when present */
641 infoPtr->lpIndex = Alloc(infoPtr->mah.dwTotalFrames * sizeof(DWORD));
642 if (!infoPtr->lpIndex)
645 numFrame = insize = 0;
646 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
647 numFrame < infoPtr->mah.dwTotalFrames) {
648 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
649 if (insize < mmckInfo.cksize)
650 insize = mmckInfo.cksize;
652 mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
654 if (numFrame != infoPtr->mah.dwTotalFrames) {
655 WARN("Found %d frames (/%d)\n", numFrame, infoPtr->mah.dwTotalFrames);
658 if (insize > infoPtr->ash.dwSuggestedBufferSize) {
659 WARN("insize=%d suggestedSize=%d\n", insize, infoPtr->ash.dwSuggestedBufferSize);
660 infoPtr->ash.dwSuggestedBufferSize = insize;
663 infoPtr->indata = Alloc(infoPtr->ash.dwSuggestedBufferSize);
664 if (!infoPtr->indata)
671 static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
675 /* check uncompressed AVI */
676 if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
677 (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')) ||
678 (infoPtr->ash.fccHandler == mmioFOURCC(0, 0, 0, 0)))
684 /* try to get a decompressor for that type */
685 infoPtr->hic = fnIC.fnICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
687 WARN("Can't load codec for the file\n");
691 outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
692 (DWORD_PTR)infoPtr->inbih, 0L);
694 infoPtr->outbih = Alloc(outSize);
695 if (!infoPtr->outbih)
698 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
699 (DWORD_PTR)infoPtr->inbih, (DWORD_PTR)infoPtr->outbih) != ICERR_OK)
701 WARN("Can't get output BIH\n");
705 infoPtr->outdata = Alloc(infoPtr->outbih->biSizeImage);
706 if (!infoPtr->outdata)
709 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
710 (DWORD_PTR)infoPtr->inbih, (DWORD_PTR)infoPtr->outbih) != ICERR_OK) {
711 WARN("Can't begin decompression\n");
719 static BOOL ANIMATE_OpenW(ANIMATE_INFO *infoPtr, HINSTANCE hInstance, LPWSTR lpszName)
721 ANIMATE_Free(infoPtr);
725 TRACE("Closing avi!\n");
726 /* installer of thebat! v1.62 requires FALSE here */
727 return (infoPtr->hMMio != 0);
731 hInstance = (HINSTANCE)GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_HINSTANCE);
733 TRACE("(%s)\n", debugstr_w(lpszName));
735 if (HIWORD(lpszName))
737 if (!ANIMATE_LoadResW(infoPtr, hInstance, lpszName))
739 TRACE("No AVI resource found!\n");
740 if (!ANIMATE_LoadFileW(infoPtr, lpszName))
742 WARN("No AVI file found!\n");
749 if (!ANIMATE_LoadResW(infoPtr, hInstance, lpszName))
751 WARN("No AVI resource found!\n");
756 if (!ANIMATE_GetAviInfo(infoPtr))
758 WARN("Can't get AVI information\n");
759 ANIMATE_Free(infoPtr);
763 if (!ANIMATE_GetAviCodec(infoPtr))
765 WARN("Can't get AVI Codec\n");
766 ANIMATE_Free(infoPtr);
770 if (!(infoPtr->dwStyle & ACS_CENTER))
771 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
772 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
774 if (infoPtr->dwStyle & ACS_AUTOPLAY)
775 return ANIMATE_Play(infoPtr, -1, 0, infoPtr->mah.dwTotalFrames - 1);
781 static BOOL ANIMATE_OpenA(ANIMATE_INFO *infoPtr, HINSTANCE hInstance, LPSTR lpszName)
787 if (!HIWORD(lpszName))
788 return ANIMATE_OpenW(infoPtr, hInstance, (LPWSTR)lpszName);
790 len = MultiByteToWideChar(CP_ACP, 0, lpszName, -1, NULL, 0);
791 lpwszName = Alloc(len * sizeof(WCHAR));
792 if (!lpwszName) return FALSE;
793 MultiByteToWideChar(CP_ACP, 0, lpszName, -1, lpwszName, len);
795 result = ANIMATE_OpenW(infoPtr, hInstance, lpwszName);
801 static BOOL ANIMATE_Stop(ANIMATE_INFO *infoPtr)
807 ANIMATE_DoStop(infoPtr);
812 static BOOL ANIMATE_Create(HWND hWnd, const CREATESTRUCTW *lpcs)
814 static const WCHAR msvfw32W[] = { 'm', 's', 'v', 'f', 'w', '3', '2', '.', 'd', 'l', 'l', 0 };
815 ANIMATE_INFO *infoPtr;
819 fnIC.hModule = LoadLibraryW(msvfw32W);
820 if (!fnIC.hModule) return FALSE;
822 fnIC.fnICOpen = (void*)GetProcAddress(fnIC.hModule, "ICOpen");
823 fnIC.fnICClose = (void*)GetProcAddress(fnIC.hModule, "ICClose");
824 fnIC.fnICSendMessage = (void*)GetProcAddress(fnIC.hModule, "ICSendMessage");
825 fnIC.fnICDecompress = (void*)GetProcAddress(fnIC.hModule, "ICDecompress");
828 /* allocate memory for info structure */
829 infoPtr = (ANIMATE_INFO *)Alloc(sizeof(ANIMATE_INFO));
830 if (!infoPtr) return FALSE;
832 /* store crossref hWnd <-> info structure */
833 SetWindowLongPtrW(hWnd, 0, (DWORD_PTR)infoPtr);
834 infoPtr->hwndSelf = hWnd;
835 infoPtr->hwndNotify = lpcs->hwndParent;
836 infoPtr->transparentColor = ANIMATE_COLOR_NONE;
837 infoPtr->hbmPrevFrame = 0;
838 infoPtr->dwStyle = lpcs->style;
840 TRACE("Animate style=0x%08x, parent=%p\n", infoPtr->dwStyle, infoPtr->hwndNotify);
842 InitializeCriticalSection(&infoPtr->cs);
843 infoPtr->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ANIMATE_INFO*->cs");
849 static LRESULT ANIMATE_Destroy(ANIMATE_INFO *infoPtr)
852 ANIMATE_Free(infoPtr);
854 /* free animate info data */
855 SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
857 infoPtr->cs.DebugInfo->Spare[0] = 0;
858 DeleteCriticalSection(&infoPtr->cs);
865 static BOOL ANIMATE_EraseBackground(ANIMATE_INFO const *infoPtr, HDC hdc)
870 if(infoPtr->dwStyle & ACS_TRANSPARENT)
872 hBrush = (HBRUSH)SendMessageW(infoPtr->hwndNotify, WM_CTLCOLORSTATIC,
873 (WPARAM)hdc, (LPARAM)infoPtr->hwndSelf);
876 GetClientRect(infoPtr->hwndSelf, &rect);
877 FillRect(hdc, &rect, hBrush ? hBrush : GetCurrentObject(hdc, OBJ_BRUSH));
883 static LRESULT ANIMATE_StyleChanged(ANIMATE_INFO *infoPtr, WPARAM wStyleType, const STYLESTRUCT *lpss)
885 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
886 wStyleType, lpss->styleOld, lpss->styleNew);
888 if (wStyleType != GWL_STYLE) return 0;
890 infoPtr->dwStyle = lpss->styleNew;
892 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
897 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
899 ANIMATE_INFO *infoPtr = (ANIMATE_INFO *)GetWindowLongPtrW(hWnd, 0);
901 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hWnd, uMsg, wParam, lParam);
902 if (!infoPtr && (uMsg != WM_NCCREATE))
903 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
907 return ANIMATE_OpenA(infoPtr, (HINSTANCE)wParam, (LPSTR)lParam);
910 return ANIMATE_OpenW(infoPtr, (HINSTANCE)wParam, (LPWSTR)lParam);
913 return ANIMATE_Play(infoPtr, (INT)wParam, LOWORD(lParam), HIWORD(lParam));
916 return ANIMATE_Stop(infoPtr);
919 ANIMATE_Free(infoPtr);
923 return ANIMATE_Create(hWnd, (LPCREATESTRUCTW)lParam);
926 return HTTRANSPARENT;
929 return ANIMATE_Destroy(infoPtr);
932 return ANIMATE_EraseBackground(infoPtr, (HDC)wParam);
934 case WM_STYLECHANGED:
935 return ANIMATE_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
938 return ANIMATE_Timer(infoPtr);
943 /* the animation has not decompressed
944 * (and displayed) the first frame yet, don't paint
946 if (!infoPtr->hbmPrevFrame)
948 /* default paint handling */
949 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
954 EnterCriticalSection(&infoPtr->cs);
955 ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
956 LeaveCriticalSection(&infoPtr->cs);
961 HDC hDC = BeginPaint(infoPtr->hwndSelf, &ps);
963 EnterCriticalSection(&infoPtr->cs);
964 ANIMATE_PaintFrame(infoPtr, hDC);
965 LeaveCriticalSection(&infoPtr->cs);
967 EndPaint(infoPtr->hwndSelf, &ps);
973 if (infoPtr->dwStyle & ACS_CENTER)
974 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
975 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
978 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
979 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg, wParam, lParam);
981 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
986 void ANIMATE_Register(void)
990 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
991 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
992 wndClass.lpfnWndProc = ANIMATE_WindowProc;
993 wndClass.cbClsExtra = 0;
994 wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
995 wndClass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
996 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
997 wndClass.lpszClassName = ANIMATE_CLASSW;
999 RegisterClassW(&wndClass);
1003 void ANIMATE_Unregister(void)
1005 UnregisterClassW(ANIMATE_CLASSW, NULL);