[4611] | 1 | /* -*- tab-width: 8; c-basic-offset: 4 -*- */
|
---|
| 2 | /*
|
---|
| 3 | * Animation control
|
---|
| 4 | *
|
---|
| 5 | * Copyright 1998, 1999 Eric Kohl
|
---|
[6709] | 6 | * 1999 Eric Pouech
|
---|
[4611] | 7 | *
|
---|
[8382] | 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.
|
---|
| 12 | *
|
---|
| 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.
|
---|
| 17 | *
|
---|
| 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
|
---|
| 21 | *
|
---|
[4611] | 22 | * NOTES
|
---|
| 23 | * I will only improve this control once in a while.
|
---|
| 24 | * Eric <ekohl@abo.rhein-zeitung.de>
|
---|
| 25 | *
|
---|
| 26 | * TODO:
|
---|
| 27 | * - check for the 'rec ' list in some AVI files
|
---|
| 28 | * - concurrent access to infoPtr
|
---|
| 29 | */
|
---|
| 30 |
|
---|
[10097] | 31 | #define COM_NO_WINDOWS_H
|
---|
[5630] | 32 | #include <string.h>
|
---|
[4611] | 33 | #include "winbase.h"
|
---|
| 34 | #include "commctrl.h"
|
---|
| 35 | #include "vfw.h"
|
---|
| 36 | #include "mmsystem.h"
|
---|
[8382] | 37 | #include "wine/debug.h"
|
---|
| 38 |
|
---|
| 39 | WINE_DEFAULT_DEBUG_CHANNEL(animate);
|
---|
| 40 |
|
---|
| 41 | static struct {
|
---|
| 42 | HMODULE hModule;
|
---|
[4627] | 43 | #ifdef __WIN32OS2__
|
---|
[8382] | 44 | HIC (* WINAPI fnICOpen)(DWORD, DWORD, UINT);
|
---|
| 45 | LRESULT (* WINAPI fnICClose)(HIC);
|
---|
| 46 | LRESULT (* WINAPI fnICSendMessage)(HIC, UINT, DWORD, DWORD);
|
---|
| 47 | DWORD (* WINAPIV fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
|
---|
| 48 | #else
|
---|
| 49 | HIC (WINAPI *fnICOpen)(DWORD, DWORD, UINT);
|
---|
| 50 | LRESULT (WINAPI *fnICClose)(HIC);
|
---|
| 51 | LRESULT (WINAPI *fnICSendMessage)(HIC, UINT, DWORD, DWORD);
|
---|
| 52 | DWORD (WINAPIV *fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
|
---|
[4627] | 53 | #endif
|
---|
[8382] | 54 | } fnIC;
|
---|
[4611] | 55 |
|
---|
| 56 | typedef struct
|
---|
| 57 | {
|
---|
| 58 | /* reference to input stream (file or resource) */
|
---|
[6709] | 59 | HGLOBAL hRes;
|
---|
| 60 | HMMIO hMMio; /* handle to mmio stream */
|
---|
| 61 | HWND hWnd;
|
---|
[4611] | 62 | /* information on the loaded AVI file */
|
---|
[6709] | 63 | MainAVIHeader mah;
|
---|
| 64 | AVIStreamHeader ash;
|
---|
| 65 | LPBITMAPINFOHEADER inbih;
|
---|
| 66 | LPDWORD lpIndex;
|
---|
[4611] | 67 | /* data for the decompressor */
|
---|
[6709] | 68 | HIC hic;
|
---|
| 69 | LPBITMAPINFOHEADER outbih;
|
---|
| 70 | LPVOID indata;
|
---|
| 71 | LPVOID outdata;
|
---|
[4611] | 72 | /* data for the background mechanism */
|
---|
[6709] | 73 | CRITICAL_SECTION cs;
|
---|
| 74 | HANDLE hThread;
|
---|
| 75 | UINT uTimer;
|
---|
[4611] | 76 | /* data for playing the file */
|
---|
[6709] | 77 | int nFromFrame;
|
---|
| 78 | int nToFrame;
|
---|
| 79 | int nLoop;
|
---|
| 80 | int currFrame;
|
---|
[4611] | 81 | /* tranparency info*/
|
---|
[10097] | 82 | COLORREF transparentColor;
|
---|
[6709] | 83 | HBRUSH hbrushBG;
|
---|
| 84 | HBITMAP hbmPrevFrame;
|
---|
[4611] | 85 | } ANIMATE_INFO;
|
---|
| 86 |
|
---|
| 87 | #define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongA(hWnd, 0))
|
---|
[6709] | 88 | #define ANIMATE_COLOR_NONE 0xffffffff
|
---|
[4611] | 89 |
|
---|
| 90 | static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
|
---|
| 91 | {
|
---|
[10097] | 92 | SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND,
|
---|
| 93 | MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif),
|
---|
[6709] | 94 | (LPARAM)infoPtr->hWnd);
|
---|
[4611] | 95 | }
|
---|
| 96 |
|
---|
| 97 | static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
|
---|
| 98 | {
|
---|
[6709] | 99 | HRSRC hrsrc;
|
---|
| 100 | MMIOINFO mminfo;
|
---|
| 101 | LPVOID lpAvi;
|
---|
[10097] | 102 |
|
---|
[4611] | 103 | hrsrc = FindResourceA(hInst, lpName, "AVI");
|
---|
| 104 | if (!hrsrc)
|
---|
[6709] | 105 | return FALSE;
|
---|
[10097] | 106 |
|
---|
[4611] | 107 | infoPtr->hRes = LoadResource(hInst, hrsrc);
|
---|
| 108 | if (!infoPtr->hRes)
|
---|
[6709] | 109 | return FALSE;
|
---|
[10097] | 110 |
|
---|
[4611] | 111 | lpAvi = LockResource(infoPtr->hRes);
|
---|
| 112 | if (!lpAvi)
|
---|
[6709] | 113 | return FALSE;
|
---|
[10097] | 114 |
|
---|
[4611] | 115 | memset(&mminfo, 0, sizeof(mminfo));
|
---|
| 116 | mminfo.fccIOProc = FOURCC_MEM;
|
---|
| 117 | mminfo.pchBuffer = (LPSTR)lpAvi;
|
---|
| 118 | mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
|
---|
[5630] | 119 | infoPtr->hMMio = mmioOpenA(NULL, &mminfo, MMIO_READ);
|
---|
[4611] | 120 | if (!infoPtr->hMMio) {
|
---|
[6709] | 121 | GlobalFree((HGLOBAL)lpAvi);
|
---|
| 122 | return FALSE;
|
---|
[4611] | 123 | }
|
---|
| 124 |
|
---|
| 125 | return TRUE;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
|
---|
| 130 | {
|
---|
[5630] | 131 | infoPtr->hMMio = mmioOpenA((LPSTR)lpName, NULL,
|
---|
[6709] | 132 | MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
|
---|
[10097] | 133 |
|
---|
[4611] | 134 | if (!infoPtr->hMMio)
|
---|
[6709] | 135 | return FALSE;
|
---|
[10097] | 136 |
|
---|
[4611] | 137 | return TRUE;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
|
---|
| 142 | {
|
---|
| 143 | EnterCriticalSection(&infoPtr->cs);
|
---|
| 144 |
|
---|
| 145 | /* should stop playing */
|
---|
[10097] | 146 | if (infoPtr->hThread)
|
---|
[4611] | 147 | {
|
---|
| 148 | if (!TerminateThread(infoPtr->hThread,0))
|
---|
| 149 | WARN("could not destroy animation thread!\n");
|
---|
[6709] | 150 | infoPtr->hThread = 0;
|
---|
[4611] | 151 | }
|
---|
| 152 | if (infoPtr->uTimer) {
|
---|
[6709] | 153 | KillTimer(infoPtr->hWnd, infoPtr->uTimer);
|
---|
| 154 | infoPtr->uTimer = 0;
|
---|
[4611] | 155 | }
|
---|
| 156 |
|
---|
| 157 | LeaveCriticalSection(&infoPtr->cs);
|
---|
| 158 |
|
---|
| 159 | ANIMATE_Notify(infoPtr, ACN_STOP);
|
---|
| 160 |
|
---|
| 161 | return TRUE;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
|
---|
| 166 | {
|
---|
| 167 | if (infoPtr->hMMio) {
|
---|
[6709] | 168 | ANIMATE_DoStop(infoPtr);
|
---|
| 169 | mmioClose(infoPtr->hMMio, 0);
|
---|
| 170 | if (infoPtr->hRes) {
|
---|
| 171 | FreeResource(infoPtr->hRes);
|
---|
| 172 | infoPtr->hRes = 0;
|
---|
| 173 | }
|
---|
| 174 | if (infoPtr->lpIndex) {
|
---|
| 175 | HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
|
---|
| 176 | infoPtr->lpIndex = NULL;
|
---|
| 177 | }
|
---|
| 178 | if (infoPtr->hic) {
|
---|
[8382] | 179 | fnIC.fnICClose(infoPtr->hic);
|
---|
[6709] | 180 | infoPtr->hic = 0;
|
---|
| 181 | }
|
---|
| 182 | if (infoPtr->inbih) {
|
---|
| 183 | HeapFree(GetProcessHeap(), 0, infoPtr->inbih);
|
---|
| 184 | infoPtr->inbih = NULL;
|
---|
| 185 | }
|
---|
| 186 | if (infoPtr->outbih) {
|
---|
| 187 | HeapFree(GetProcessHeap(), 0, infoPtr->outbih);
|
---|
| 188 | infoPtr->outbih = NULL;
|
---|
| 189 | }
|
---|
[4611] | 190 | if( infoPtr->indata )
|
---|
| 191 | {
|
---|
[6709] | 192 | HeapFree(GetProcessHeap(), 0, infoPtr->indata);
|
---|
[4611] | 193 | infoPtr->indata = NULL;
|
---|
| 194 | }
|
---|
[6709] | 195 | if( infoPtr->outdata )
|
---|
[4611] | 196 | {
|
---|
[6709] | 197 | HeapFree(GetProcessHeap(), 0, infoPtr->outdata);
|
---|
[4611] | 198 | infoPtr->outdata = NULL;
|
---|
| 199 | }
|
---|
[6709] | 200 | if( infoPtr->hbmPrevFrame )
|
---|
[4611] | 201 | {
|
---|
[6709] | 202 | DeleteObject(infoPtr->hbmPrevFrame);
|
---|
[4611] | 203 | infoPtr->hbmPrevFrame = 0;
|
---|
| 204 | }
|
---|
[6709] | 205 | infoPtr->indata = infoPtr->outdata = NULL;
|
---|
| 206 | infoPtr->hWnd = 0;
|
---|
| 207 | infoPtr->hMMio = 0;
|
---|
[10097] | 208 |
|
---|
[6709] | 209 | memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
|
---|
| 210 | memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
|
---|
| 211 | infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
|
---|
[4611] | 212 | }
|
---|
[10097] | 213 | infoPtr->transparentColor = ANIMATE_COLOR_NONE;
|
---|
[4611] | 214 | }
|
---|
| 215 |
|
---|
| 216 | static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
|
---|
[10097] | 217 | {
|
---|
[4611] | 218 | HDC hdcMask;
|
---|
| 219 | HBITMAP hbmMask;
|
---|
[10097] | 220 | HBITMAP hbmOld;
|
---|
| 221 |
|
---|
[4611] | 222 | /* create a transparency mask */
|
---|
| 223 | hdcMask = CreateCompatibleDC(hdcDest);
|
---|
[10097] | 224 | hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
|
---|
| 225 | hbmOld = SelectObject(hdcMask, hbmMask);
|
---|
[4611] | 226 |
|
---|
| 227 | SetBkColor(hdcSource,infoPtr->transparentColor);
|
---|
| 228 | BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
|
---|
[10097] | 229 |
|
---|
[4611] | 230 | /* mask the source bitmap */
|
---|
[10097] | 231 | SetBkColor(hdcSource, RGB(0,0,0));
|
---|
| 232 | SetTextColor(hdcSource, RGB(255,255,255));
|
---|
[4611] | 233 | BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
|
---|
| 234 |
|
---|
| 235 | /* mask the destination bitmap */
|
---|
[10097] | 236 | SetBkColor(hdcDest, RGB(255,255,255));
|
---|
| 237 | SetTextColor(hdcDest, RGB(0,0,0));
|
---|
[4611] | 238 | BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
|
---|
| 239 |
|
---|
| 240 | /* combine source and destination */
|
---|
| 241 | BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
|
---|
| 242 |
|
---|
| 243 | SelectObject(hdcMask, hbmOld);
|
---|
| 244 | DeleteObject(hbmMask);
|
---|
| 245 | DeleteDC(hdcMask);
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
|
---|
| 249 | {
|
---|
| 250 | void* pBitmapData = NULL;
|
---|
| 251 | LPBITMAPINFO pBitmapInfo = NULL;
|
---|
| 252 |
|
---|
| 253 | HDC hdcMem;
|
---|
| 254 | HBITMAP hbmOld;
|
---|
| 255 |
|
---|
| 256 | int nOffsetX = 0;
|
---|
| 257 | int nOffsetY = 0;
|
---|
| 258 |
|
---|
| 259 | int nWidth;
|
---|
| 260 | int nHeight;
|
---|
| 261 |
|
---|
| 262 | if (!hDC || !infoPtr->inbih)
|
---|
[6709] | 263 | return TRUE;
|
---|
[4611] | 264 |
|
---|
| 265 | if (infoPtr->hic )
|
---|
| 266 | {
|
---|
| 267 | pBitmapData = infoPtr->outdata;
|
---|
| 268 | pBitmapInfo = (LPBITMAPINFO)infoPtr->outbih;
|
---|
| 269 |
|
---|
| 270 | nWidth = infoPtr->outbih->biWidth;
|
---|
[10097] | 271 | nHeight = infoPtr->outbih->biHeight;
|
---|
[4611] | 272 | } else
|
---|
[10097] | 273 | {
|
---|
[4611] | 274 | pBitmapData = infoPtr->indata;
|
---|
| 275 | pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
|
---|
| 276 |
|
---|
| 277 | nWidth = infoPtr->inbih->biWidth;
|
---|
[10097] | 278 | nHeight = infoPtr->inbih->biHeight;
|
---|
| 279 | }
|
---|
[4611] | 280 |
|
---|
| 281 | if(!infoPtr->hbmPrevFrame)
|
---|
| 282 | {
|
---|
| 283 | infoPtr->hbmPrevFrame=CreateCompatibleBitmap(hDC, nWidth,nHeight );
|
---|
| 284 | }
|
---|
| 285 |
|
---|
[10097] | 286 | SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS);
|
---|
| 287 |
|
---|
[4611] | 288 | hdcMem = CreateCompatibleDC(hDC);
|
---|
| 289 | hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame);
|
---|
| 290 |
|
---|
[10097] | 291 | /*
|
---|
| 292 | * we need to get the transparent color even without ACS_TRANSPARENT,
|
---|
[4611] | 293 | * because the style can be changed later on and the color should always
|
---|
[10097] | 294 | * be obtained in the first frame
|
---|
[4611] | 295 | */
|
---|
| 296 | if(infoPtr->transparentColor == ANIMATE_COLOR_NONE)
|
---|
| 297 | {
|
---|
| 298 | infoPtr->transparentColor = GetPixel(hdcMem,0,0);
|
---|
[10097] | 299 | }
|
---|
[4611] | 300 |
|
---|
[10097] | 301 | if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
| 302 | {
|
---|
[4611] | 303 | HDC hdcFinal = CreateCompatibleDC(hDC);
|
---|
| 304 | HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
|
---|
| 305 | HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal);
|
---|
| 306 | RECT rect;
|
---|
[10097] | 307 |
|
---|
[4611] | 308 | rect.left = 0;
|
---|
| 309 | rect.top = 0;
|
---|
| 310 | rect.right = nWidth;
|
---|
| 311 | rect.bottom = nHeight;
|
---|
[10097] | 312 |
|
---|
[4611] | 313 | if(!infoPtr->hbrushBG)
|
---|
| 314 | infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH);
|
---|
| 315 |
|
---|
| 316 | FillRect(hdcFinal, &rect, infoPtr->hbrushBG);
|
---|
| 317 | ANIMATE_TransparentBlt(infoPtr, hdcFinal, hdcMem);
|
---|
| 318 |
|
---|
| 319 | SelectObject(hdcFinal, hbmOld2);
|
---|
| 320 | SelectObject(hdcMem, hbmFinal);
|
---|
| 321 | DeleteDC(hdcFinal);
|
---|
| 322 | DeleteObject(infoPtr->hbmPrevFrame);
|
---|
| 323 | infoPtr->hbmPrevFrame = hbmFinal;
|
---|
| 324 | }
|
---|
[10097] | 325 |
|
---|
| 326 | if (GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_CENTER)
|
---|
[4611] | 327 | {
|
---|
[10097] | 328 | RECT rect;
|
---|
[4611] | 329 |
|
---|
| 330 | GetWindowRect(infoPtr->hWnd, &rect);
|
---|
[10097] | 331 | nOffsetX = ((rect.right - rect.left) - nWidth)/2;
|
---|
| 332 | nOffsetY = ((rect.bottom - rect.top) - nHeight)/2;
|
---|
[4611] | 333 | }
|
---|
[10097] | 334 | BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
|
---|
[4611] | 335 |
|
---|
| 336 | SelectObject(hdcMem, hbmOld);
|
---|
| 337 | DeleteDC(hdcMem);
|
---|
| 338 | return TRUE;
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
|
---|
| 342 | {
|
---|
[6709] | 343 | HDC hDC;
|
---|
[4611] | 344 |
|
---|
| 345 | TRACE("Drawing frame %d (loop %d)\n", infoPtr->currFrame, infoPtr->nLoop);
|
---|
| 346 |
|
---|
| 347 | EnterCriticalSection(&infoPtr->cs);
|
---|
| 348 |
|
---|
[5630] | 349 | mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET);
|
---|
| 350 | mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize);
|
---|
[10097] | 351 |
|
---|
[4611] | 352 | if (infoPtr->hic &&
|
---|
[10097] | 353 | fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
|
---|
[6709] | 354 | infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
|
---|
| 355 | LeaveCriticalSection(&infoPtr->cs);
|
---|
| 356 | WARN("Decompression error\n");
|
---|
| 357 | return FALSE;
|
---|
[4611] | 358 | }
|
---|
| 359 |
|
---|
| 360 | if ((hDC = GetDC(infoPtr->hWnd)) != 0) {
|
---|
[6709] | 361 | ANIMATE_PaintFrame(infoPtr, hDC);
|
---|
| 362 | ReleaseDC(infoPtr->hWnd, hDC);
|
---|
[4611] | 363 | }
|
---|
| 364 |
|
---|
| 365 | if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
|
---|
[6709] | 366 | infoPtr->currFrame = infoPtr->nFromFrame;
|
---|
| 367 | if (infoPtr->nLoop != -1) {
|
---|
| 368 | if (--infoPtr->nLoop == 0) {
|
---|
| 369 | ANIMATE_DoStop(infoPtr);
|
---|
| 370 | }
|
---|
| 371 | }
|
---|
[4611] | 372 | }
|
---|
| 373 | LeaveCriticalSection(&infoPtr->cs);
|
---|
| 374 |
|
---|
| 375 | return TRUE;
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
|
---|
| 379 | {
|
---|
[6709] | 380 | ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_;
|
---|
[4611] | 381 | HDC hDC;
|
---|
[10097] | 382 |
|
---|
[4611] | 383 | if(!infoPtr)
|
---|
| 384 | {
|
---|
| 385 | WARN("animation structure undefined!\n");
|
---|
| 386 | return FALSE;
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | while(1)
|
---|
[10097] | 390 | {
|
---|
| 391 | if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
[4611] | 392 | {
|
---|
| 393 | hDC = GetDC(infoPtr->hWnd);
|
---|
[6709] | 394 | /* sometimes the animation window will be destroyed in between
|
---|
| 395 | * by the main program, so a ReleaseDC() error msg is possible */
|
---|
[10097] | 396 | infoPtr->hbrushBG = (HBRUSH)SendMessageA(GetParent(infoPtr->hWnd),
|
---|
| 397 | WM_CTLCOLORSTATIC, (WPARAM)hDC,
|
---|
| 398 | (LPARAM)infoPtr->hWnd);
|
---|
[4611] | 399 | ReleaseDC(infoPtr->hWnd,hDC);
|
---|
| 400 | }
|
---|
[10097] | 401 |
|
---|
[5630] | 402 | EnterCriticalSection(&infoPtr->cs);
|
---|
| 403 | ANIMATE_DrawFrame(infoPtr);
|
---|
| 404 | LeaveCriticalSection(&infoPtr->cs);
|
---|
[10097] | 405 |
|
---|
[4611] | 406 | /* time is in microseconds, we should convert it to milliseconds */
|
---|
| 407 | Sleep((infoPtr->mah.dwMicroSecPerFrame+500)/1000);
|
---|
[5630] | 408 | }
|
---|
[4611] | 409 | return TRUE;
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 | static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
| 413 | {
|
---|
| 414 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
| 415 |
|
---|
| 416 | /* nothing opened */
|
---|
| 417 | if (!infoPtr->hMMio)
|
---|
[6709] | 418 | return FALSE;
|
---|
[4611] | 419 |
|
---|
| 420 | if (infoPtr->hThread || infoPtr->uTimer) {
|
---|
[6709] | 421 | FIXME("Already playing ? what should I do ??\n");
|
---|
| 422 | ANIMATE_DoStop(infoPtr);
|
---|
[4611] | 423 | }
|
---|
| 424 |
|
---|
| 425 | infoPtr->nFromFrame = (INT)LOWORD(lParam);
|
---|
| 426 | infoPtr->nToFrame = (INT)HIWORD(lParam);
|
---|
| 427 | infoPtr->nLoop = (INT)wParam;
|
---|
| 428 |
|
---|
| 429 | if (infoPtr->nToFrame == 0xFFFF)
|
---|
[6709] | 430 | infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
|
---|
[4611] | 431 |
|
---|
[10097] | 432 | TRACE("(repeat=%d from=%d to=%d);\n",
|
---|
[6709] | 433 | infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame);
|
---|
[4611] | 434 |
|
---|
| 435 | if (infoPtr->nFromFrame >= infoPtr->nToFrame ||
|
---|
[6709] | 436 | infoPtr->nToFrame >= infoPtr->mah.dwTotalFrames)
|
---|
| 437 | return FALSE;
|
---|
[4611] | 438 |
|
---|
| 439 | infoPtr->currFrame = infoPtr->nFromFrame;
|
---|
| 440 |
|
---|
| 441 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
|
---|
[6709] | 442 | TRACE("Using a timer\n");
|
---|
| 443 | /* create a timer to display AVI */
|
---|
| 444 | infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
|
---|
[4611] | 445 | } else {
|
---|
| 446 | DWORD threadID;
|
---|
| 447 |
|
---|
[6709] | 448 | TRACE("Using an animation thread\n");
|
---|
[10097] | 449 | infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr, 0, &threadID);
|
---|
[4611] | 450 | if(!infoPtr->hThread)
|
---|
| 451 | {
|
---|
| 452 | ERR("Could not create animation thread!\n");
|
---|
| 453 | return FALSE;
|
---|
| 454 | }
|
---|
[10097] | 455 |
|
---|
[4611] | 456 | }
|
---|
[10097] | 457 |
|
---|
[4611] | 458 | ANIMATE_Notify(infoPtr, ACN_START);
|
---|
| 459 |
|
---|
| 460 | return TRUE;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 |
|
---|
| 464 | static BOOL ANIMATE_GetAviInfo(ANIMATE_INFO *infoPtr)
|
---|
| 465 | {
|
---|
[6709] | 466 | MMCKINFO ckMainRIFF;
|
---|
| 467 | MMCKINFO mmckHead;
|
---|
| 468 | MMCKINFO mmckList;
|
---|
| 469 | MMCKINFO mmckInfo;
|
---|
| 470 | DWORD numFrame;
|
---|
| 471 | DWORD insize;
|
---|
[4611] | 472 |
|
---|
[5630] | 473 | if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
|
---|
[6709] | 474 | WARN("Can't find 'RIFF' chunk\n");
|
---|
| 475 | return FALSE;
|
---|
[4611] | 476 | }
|
---|
| 477 |
|
---|
| 478 | if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
|
---|
[6709] | 479 | (ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
|
---|
| 480 | WARN("Can't find 'AVI ' chunk\n");
|
---|
| 481 | return FALSE;
|
---|
[4611] | 482 | }
|
---|
| 483 |
|
---|
| 484 | mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
|
---|
[5630] | 485 | if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
|
---|
[6709] | 486 | WARN("Can't find 'hdrl' list\n");
|
---|
| 487 | return FALSE;
|
---|
[4611] | 488 | }
|
---|
| 489 |
|
---|
| 490 | mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
|
---|
[5630] | 491 | if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
|
---|
[6709] | 492 | WARN("Can't find 'avih' chunk\n");
|
---|
| 493 | return FALSE;
|
---|
[4611] | 494 | }
|
---|
| 495 |
|
---|
[5630] | 496 | mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->mah, sizeof(infoPtr->mah));
|
---|
[4611] | 497 |
|
---|
[6709] | 498 | TRACE("mah.dwMicroSecPerFrame=%ld\n", infoPtr->mah.dwMicroSecPerFrame);
|
---|
| 499 | TRACE("mah.dwMaxBytesPerSec=%ld\n", infoPtr->mah.dwMaxBytesPerSec);
|
---|
| 500 | TRACE("mah.dwPaddingGranularity=%ld\n", infoPtr->mah.dwPaddingGranularity);
|
---|
| 501 | TRACE("mah.dwFlags=%ld\n", infoPtr->mah.dwFlags);
|
---|
| 502 | TRACE("mah.dwTotalFrames=%ld\n", infoPtr->mah.dwTotalFrames);
|
---|
| 503 | TRACE("mah.dwInitialFrames=%ld\n", infoPtr->mah.dwInitialFrames);
|
---|
| 504 | TRACE("mah.dwStreams=%ld\n", infoPtr->mah.dwStreams);
|
---|
| 505 | TRACE("mah.dwSuggestedBufferSize=%ld\n", infoPtr->mah.dwSuggestedBufferSize);
|
---|
| 506 | TRACE("mah.dwWidth=%ld\n", infoPtr->mah.dwWidth);
|
---|
| 507 | TRACE("mah.dwHeight=%ld\n", infoPtr->mah.dwHeight);
|
---|
[5630] | 508 |
|
---|
| 509 | mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
| 510 |
|
---|
[4611] | 511 | mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
|
---|
[5630] | 512 | if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
|
---|
[6709] | 513 | WARN("Can't find 'strl' list\n");
|
---|
| 514 | return FALSE;
|
---|
[4611] | 515 | }
|
---|
| 516 |
|
---|
| 517 | mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
|
---|
[5630] | 518 | if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
|
---|
[6709] | 519 | WARN("Can't find 'strh' chunk\n");
|
---|
| 520 | return FALSE;
|
---|
[4611] | 521 | }
|
---|
| 522 |
|
---|
[5630] | 523 | mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash));
|
---|
[4611] | 524 |
|
---|
[10097] | 525 | TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)),
|
---|
| 526 | HIBYTE(LOWORD(infoPtr->ash.fccType)),
|
---|
| 527 | LOBYTE(HIWORD(infoPtr->ash.fccType)),
|
---|
[6709] | 528 | HIBYTE(HIWORD(infoPtr->ash.fccType)));
|
---|
[10097] | 529 | TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)),
|
---|
| 530 | HIBYTE(LOWORD(infoPtr->ash.fccHandler)),
|
---|
| 531 | LOBYTE(HIWORD(infoPtr->ash.fccHandler)),
|
---|
[6709] | 532 | HIBYTE(HIWORD(infoPtr->ash.fccHandler)));
|
---|
| 533 | TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags);
|
---|
| 534 | TRACE("ash.wPriority=%d\n", infoPtr->ash.wPriority);
|
---|
| 535 | TRACE("ash.wLanguage=%d\n", infoPtr->ash.wLanguage);
|
---|
| 536 | TRACE("ash.dwInitialFrames=%ld\n", infoPtr->ash.dwInitialFrames);
|
---|
| 537 | TRACE("ash.dwScale=%ld\n", infoPtr->ash.dwScale);
|
---|
| 538 | TRACE("ash.dwRate=%ld\n", infoPtr->ash.dwRate);
|
---|
| 539 | TRACE("ash.dwStart=%ld\n", infoPtr->ash.dwStart);
|
---|
| 540 | TRACE("ash.dwLength=%ld\n", infoPtr->ash.dwLength);
|
---|
| 541 | TRACE("ash.dwSuggestedBufferSize=%ld\n", infoPtr->ash.dwSuggestedBufferSize);
|
---|
| 542 | TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality);
|
---|
| 543 | TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize);
|
---|
[10097] | 544 | TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left,
|
---|
[6709] | 545 | infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right);
|
---|
[5630] | 546 |
|
---|
| 547 | mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
| 548 |
|
---|
[4611] | 549 | mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
|
---|
[5630] | 550 | if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
|
---|
[6709] | 551 | WARN("Can't find 'strh' chunk\n");
|
---|
| 552 | return FALSE;
|
---|
[4611] | 553 | }
|
---|
| 554 |
|
---|
| 555 | infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
|
---|
| 556 | if (!infoPtr->inbih) {
|
---|
[6709] | 557 | WARN("Can't alloc input BIH\n");
|
---|
| 558 | return FALSE;
|
---|
[4611] | 559 | }
|
---|
| 560 |
|
---|
[5630] | 561 | mmioRead(infoPtr->hMMio, (LPSTR)infoPtr->inbih, mmckInfo.cksize);
|
---|
[4611] | 562 |
|
---|
[6709] | 563 | TRACE("bih.biSize=%ld\n", infoPtr->inbih->biSize);
|
---|
| 564 | TRACE("bih.biWidth=%ld\n", infoPtr->inbih->biWidth);
|
---|
| 565 | TRACE("bih.biHeight=%ld\n", infoPtr->inbih->biHeight);
|
---|
| 566 | TRACE("bih.biPlanes=%d\n", infoPtr->inbih->biPlanes);
|
---|
| 567 | TRACE("bih.biBitCount=%d\n", infoPtr->inbih->biBitCount);
|
---|
| 568 | TRACE("bih.biCompression=%ld\n", infoPtr->inbih->biCompression);
|
---|
| 569 | TRACE("bih.biSizeImage=%ld\n", infoPtr->inbih->biSizeImage);
|
---|
| 570 | TRACE("bih.biXPelsPerMeter=%ld\n", infoPtr->inbih->biXPelsPerMeter);
|
---|
| 571 | TRACE("bih.biYPelsPerMeter=%ld\n", infoPtr->inbih->biYPelsPerMeter);
|
---|
| 572 | TRACE("bih.biClrUsed=%ld\n", infoPtr->inbih->biClrUsed);
|
---|
| 573 | TRACE("bih.biClrImportant=%ld\n", infoPtr->inbih->biClrImportant);
|
---|
[4611] | 574 |
|
---|
[5630] | 575 | mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
| 576 |
|
---|
| 577 | mmioAscend(infoPtr->hMMio, &mmckList, 0);
|
---|
[10097] | 578 |
|
---|
[4611] | 579 | #if 0
|
---|
| 580 | /* an AVI has 0 or 1 video stream, and to be animated should not contain
|
---|
[10097] | 581 | * an audio stream, so only one strl is allowed
|
---|
[4611] | 582 | */
|
---|
| 583 | mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
|
---|
[5630] | 584 | if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
|
---|
[6709] | 585 | WARN("There should be a single 'strl' list\n");
|
---|
| 586 | return FALSE;
|
---|
[4611] | 587 | }
|
---|
| 588 | #endif
|
---|
| 589 |
|
---|
[5630] | 590 | mmioAscend(infoPtr->hMMio, &mmckHead, 0);
|
---|
[4611] | 591 |
|
---|
| 592 | /* no need to read optional JUNK chunk */
|
---|
| 593 |
|
---|
| 594 | mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
|
---|
[5630] | 595 | if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
|
---|
[6709] | 596 | WARN("Can't find 'movi' list\n");
|
---|
| 597 | return FALSE;
|
---|
[4611] | 598 | }
|
---|
| 599 |
|
---|
| 600 | /* FIXME: should handle the 'rec ' LIST when present */
|
---|
| 601 |
|
---|
[10097] | 602 | infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
---|
[6709] | 603 | infoPtr->mah.dwTotalFrames * sizeof(DWORD));
|
---|
[4611] | 604 | if (!infoPtr->lpIndex) {
|
---|
[6709] | 605 | WARN("Can't alloc index array\n");
|
---|
| 606 | return FALSE;
|
---|
[4611] | 607 | }
|
---|
| 608 |
|
---|
| 609 | numFrame = insize = 0;
|
---|
[10097] | 610 | while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
|
---|
[6709] | 611 | numFrame < infoPtr->mah.dwTotalFrames) {
|
---|
| 612 | infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
|
---|
| 613 | if (insize < mmckInfo.cksize)
|
---|
| 614 | insize = mmckInfo.cksize;
|
---|
| 615 | numFrame++;
|
---|
| 616 | mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
|
---|
[4611] | 617 | }
|
---|
| 618 | if (numFrame != infoPtr->mah.dwTotalFrames) {
|
---|
[6709] | 619 | WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
|
---|
| 620 | return FALSE;
|
---|
[4611] | 621 | }
|
---|
| 622 | if (insize > infoPtr->ash.dwSuggestedBufferSize) {
|
---|
[6709] | 623 | WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
|
---|
| 624 | infoPtr->ash.dwSuggestedBufferSize = insize;
|
---|
[4611] | 625 | }
|
---|
| 626 |
|
---|
| 627 | infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
|
---|
| 628 | if (!infoPtr->indata) {
|
---|
[6709] | 629 | WARN("Can't alloc input buffer\n");
|
---|
| 630 | return FALSE;
|
---|
[4611] | 631 | }
|
---|
| 632 |
|
---|
| 633 | return TRUE;
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 |
|
---|
| 637 | static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
|
---|
| 638 | {
|
---|
[6709] | 639 | DWORD outSize;
|
---|
[4611] | 640 |
|
---|
| 641 | /* check uncompressed AVI */
|
---|
| 642 | if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
|
---|
[8382] | 643 | (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')) ||
|
---|
| 644 | (infoPtr->ash.fccHandler == mmioFOURCC(0, 0, 0, 0)))
|
---|
[4611] | 645 | {
|
---|
[10097] | 646 | infoPtr->hic = 0;
|
---|
[6709] | 647 | return TRUE;
|
---|
[4611] | 648 | }
|
---|
| 649 |
|
---|
| 650 | /* try to get a decompressor for that type */
|
---|
[8382] | 651 | infoPtr->hic = fnIC.fnICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
|
---|
[4611] | 652 | if (!infoPtr->hic) {
|
---|
[6709] | 653 | WARN("Can't load codec for the file\n");
|
---|
| 654 | return FALSE;
|
---|
[4611] | 655 | }
|
---|
[10097] | 656 |
|
---|
| 657 | outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
|
---|
[6709] | 658 | (DWORD)infoPtr->inbih, 0L);
|
---|
[4611] | 659 |
|
---|
| 660 | infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
|
---|
| 661 | if (!infoPtr->outbih) {
|
---|
[6709] | 662 | WARN("Can't alloc output BIH\n");
|
---|
| 663 | return FALSE;
|
---|
[4611] | 664 | }
|
---|
| 665 |
|
---|
[10097] | 666 | if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
|
---|
| 667 | (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != outSize) {
|
---|
[6709] | 668 | WARN("Can't get output BIH\n");
|
---|
| 669 | return FALSE;
|
---|
[4611] | 670 | }
|
---|
| 671 |
|
---|
| 672 | infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
|
---|
| 673 | if (!infoPtr->outdata) {
|
---|
[6709] | 674 | WARN("Can't alloc output buffer\n");
|
---|
| 675 | return FALSE;
|
---|
[4611] | 676 | }
|
---|
| 677 |
|
---|
[10097] | 678 | if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
|
---|
[6709] | 679 | (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
|
---|
| 680 | WARN("Can't begin decompression\n");
|
---|
| 681 | return FALSE;
|
---|
[4611] | 682 | }
|
---|
| 683 |
|
---|
| 684 | return TRUE;
|
---|
| 685 | }
|
---|
| 686 |
|
---|
| 687 | static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
| 688 | {
|
---|
| 689 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
| 690 | HINSTANCE hInstance = (HINSTANCE)wParam;
|
---|
| 691 |
|
---|
| 692 | ANIMATE_Free(infoPtr);
|
---|
[8382] | 693 | infoPtr->hWnd = hWnd;
|
---|
[4611] | 694 |
|
---|
| 695 | if (!lParam) {
|
---|
[6709] | 696 | TRACE("Closing avi!\n");
|
---|
[10097] | 697 | /* installer of thebat! v1.62 requires FALSE here */
|
---|
| 698 | return (infoPtr->hMMio != 0);
|
---|
[4611] | 699 | }
|
---|
[10097] | 700 |
|
---|
[4611] | 701 | if (!hInstance)
|
---|
[10097] | 702 | hInstance = (HINSTANCE)GetWindowLongA(hWnd, GWL_HINSTANCE);
|
---|
[4611] | 703 |
|
---|
[4627] | 704 | if (HIWORD(lParam)) {
|
---|
[6709] | 705 | TRACE("(\"%s\");\n", (LPSTR)lParam);
|
---|
[5418] | 706 |
|
---|
[6709] | 707 | if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
|
---|
| 708 | TRACE("No AVI resource found!\n");
|
---|
| 709 | if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
|
---|
| 710 | WARN("No AVI file found!\n");
|
---|
| 711 | return FALSE;
|
---|
| 712 | }
|
---|
| 713 | }
|
---|
[4611] | 714 | } else {
|
---|
[6709] | 715 | TRACE("(%u);\n", (WORD)LOWORD(lParam));
|
---|
[4611] | 716 |
|
---|
[6709] | 717 | if (!ANIMATE_LoadResA(infoPtr, hInstance,
|
---|
| 718 | MAKEINTRESOURCEA((INT)lParam))) {
|
---|
| 719 | WARN("No AVI resource found!\n");
|
---|
| 720 | return FALSE;
|
---|
| 721 | }
|
---|
[4611] | 722 | }
|
---|
[8382] | 723 |
|
---|
[4611] | 724 | if (!ANIMATE_GetAviInfo(infoPtr)) {
|
---|
[6709] | 725 | WARN("Can't get AVI information\n");
|
---|
| 726 | ANIMATE_Free(infoPtr);
|
---|
| 727 | return FALSE;
|
---|
[4611] | 728 | }
|
---|
| 729 |
|
---|
| 730 | if (!ANIMATE_GetAviCodec(infoPtr)) {
|
---|
[6709] | 731 | WARN("Can't get AVI Codec\n");
|
---|
| 732 | ANIMATE_Free(infoPtr);
|
---|
| 733 | return FALSE;
|
---|
[4611] | 734 | }
|
---|
| 735 |
|
---|
| 736 | if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
|
---|
[6709] | 737 | SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
|
---|
| 738 | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
|
---|
[4611] | 739 | }
|
---|
| 740 |
|
---|
| 741 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
|
---|
[6709] | 742 | return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
|
---|
[4611] | 743 | }
|
---|
| 744 |
|
---|
| 745 | return TRUE;
|
---|
| 746 | }
|
---|
| 747 |
|
---|
| 748 |
|
---|
| 749 | /* << ANIMATE_Open32W >> */
|
---|
| 750 |
|
---|
| 751 | static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
| 752 | {
|
---|
| 753 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
| 754 |
|
---|
| 755 | /* nothing opened */
|
---|
| 756 | if (!infoPtr->hMMio)
|
---|
[6709] | 757 | return FALSE;
|
---|
[4611] | 758 |
|
---|
| 759 | ANIMATE_DoStop(infoPtr);
|
---|
| 760 | return TRUE;
|
---|
| 761 | }
|
---|
| 762 |
|
---|
| 763 |
|
---|
| 764 | static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
| 765 | {
|
---|
[6709] | 766 | ANIMATE_INFO* infoPtr;
|
---|
[4611] | 767 |
|
---|
[8382] | 768 | if (!fnIC.hModule) /* FIXME: not thread safe */
|
---|
| 769 | {
|
---|
| 770 | /* since there's a circular dep between msvfw32 and comctl32, we could either:
|
---|
| 771 | * - fix the build chain to allow this circular dep
|
---|
| 772 | * - handle it by hand
|
---|
| 773 | * AJ wants the latter :-(
|
---|
| 774 | */
|
---|
| 775 | fnIC.hModule = LoadLibraryA("msvfw32.dll");
|
---|
| 776 | if (!fnIC.hModule) return FALSE;
|
---|
| 777 |
|
---|
| 778 | fnIC.fnICOpen = (void*)GetProcAddress(fnIC.hModule, "ICOpen");
|
---|
| 779 | fnIC.fnICClose = (void*)GetProcAddress(fnIC.hModule, "ICClose");
|
---|
| 780 | fnIC.fnICSendMessage = (void*)GetProcAddress(fnIC.hModule, "ICSendMessage");
|
---|
| 781 | fnIC.fnICDecompress = (void*)GetProcAddress(fnIC.hModule, "ICDecompress");
|
---|
| 782 | }
|
---|
| 783 |
|
---|
[4611] | 784 | /* allocate memory for info structure */
|
---|
| 785 | infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
|
---|
| 786 | if (!infoPtr) {
|
---|
[6709] | 787 | ERR("could not allocate info memory!\n");
|
---|
| 788 | return 0;
|
---|
[4611] | 789 | }
|
---|
| 790 |
|
---|
| 791 | TRACE("Animate style=0x%08lx, parent=%08lx\n", GetWindowLongA(hWnd, GWL_STYLE), (DWORD)GetParent(hWnd));
|
---|
| 792 |
|
---|
| 793 | /* store crossref hWnd <-> info structure */
|
---|
| 794 | SetWindowLongA(hWnd, 0, (DWORD)infoPtr);
|
---|
| 795 | infoPtr->hWnd = hWnd;
|
---|
| 796 | infoPtr->transparentColor = ANIMATE_COLOR_NONE;
|
---|
| 797 | infoPtr->hbmPrevFrame = 0;
|
---|
| 798 |
|
---|
| 799 | InitializeCriticalSection(&infoPtr->cs);
|
---|
[10097] | 800 |
|
---|
[4611] | 801 | return 0;
|
---|
| 802 | }
|
---|
| 803 |
|
---|
| 804 |
|
---|
| 805 | static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
| 806 | {
|
---|
| 807 | ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
| 808 |
|
---|
| 809 |
|
---|
| 810 | /* free avi data */
|
---|
| 811 | ANIMATE_Free(infoPtr);
|
---|
| 812 |
|
---|
| 813 | /* free animate info data */
|
---|
| 814 | COMCTL32_Free(infoPtr);
|
---|
| 815 | SetWindowLongA(hWnd, 0, 0);
|
---|
| 816 |
|
---|
| 817 | return 0;
|
---|
| 818 | }
|
---|
| 819 |
|
---|
| 820 |
|
---|
| 821 | static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
| 822 | {
|
---|
| 823 | RECT rect;
|
---|
[10097] | 824 | HBRUSH hBrush = 0;
|
---|
[4611] | 825 |
|
---|
[10097] | 826 | if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
[4611] | 827 | {
|
---|
[10097] | 828 | hBrush = (HBRUSH)SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,
|
---|
| 829 | wParam, (LPARAM)hWnd);
|
---|
[4611] | 830 | }
|
---|
| 831 |
|
---|
| 832 | GetClientRect(hWnd, &rect);
|
---|
| 833 | FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
|
---|
| 834 |
|
---|
| 835 | return TRUE;
|
---|
| 836 | }
|
---|
| 837 |
|
---|
| 838 | static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
---|
| 839 | {
|
---|
| 840 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
|
---|
[6709] | 841 | InvalidateRect(hWnd, NULL, TRUE);
|
---|
[4611] | 842 | }
|
---|
| 843 | return TRUE;
|
---|
| 844 | }
|
---|
| 845 |
|
---|
| 846 | static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
| 847 | {
|
---|
[10097] | 848 | TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
|
---|
[4611] | 849 | if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
|
---|
[6709] | 850 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
[4611] | 851 | switch (uMsg)
|
---|
| 852 | {
|
---|
[5630] | 853 | case ACM_OPENA:
|
---|
[6709] | 854 | return ANIMATE_OpenA(hWnd, wParam, lParam);
|
---|
[10097] | 855 |
|
---|
[6709] | 856 | /* case ACM_OPEN32W: FIXME!! */
|
---|
| 857 | /* return ANIMATE_Open32W(hWnd, wParam, lParam); */
|
---|
[10097] | 858 |
|
---|
[4611] | 859 | case ACM_PLAY:
|
---|
[6709] | 860 | return ANIMATE_Play(hWnd, wParam, lParam);
|
---|
[10097] | 861 |
|
---|
[4611] | 862 | case ACM_STOP:
|
---|
[6709] | 863 | return ANIMATE_Stop(hWnd, wParam, lParam);
|
---|
[10097] | 864 |
|
---|
[4611] | 865 | case WM_NCCREATE:
|
---|
[6709] | 866 | ANIMATE_Create(hWnd, wParam, lParam);
|
---|
| 867 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
[10097] | 868 |
|
---|
[4611] | 869 | case WM_NCHITTEST:
|
---|
[6709] | 870 | return HTTRANSPARENT;
|
---|
[4611] | 871 |
|
---|
| 872 | case WM_DESTROY:
|
---|
[6709] | 873 | ANIMATE_Destroy(hWnd, wParam, lParam);
|
---|
| 874 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
[10097] | 875 |
|
---|
[4611] | 876 | case WM_ERASEBKGND:
|
---|
[6709] | 877 | ANIMATE_EraseBackground(hWnd, wParam, lParam);
|
---|
| 878 | break;
|
---|
[4611] | 879 |
|
---|
[6709] | 880 | /* case WM_STYLECHANGED: FIXME shall we do something ?? */
|
---|
[4611] | 881 |
|
---|
| 882 | case WM_TIMER:
|
---|
[6709] | 883 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
[4611] | 884 | {
|
---|
| 885 | ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
[10097] | 886 | infoPtr->hbrushBG = (HBRUSH)SendMessageA(GetParent(hWnd),
|
---|
| 887 | WM_CTLCOLORSTATIC,
|
---|
| 888 | wParam, (LPARAM)hWnd);
|
---|
[4611] | 889 | }
|
---|
[6709] | 890 | return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
|
---|
[10097] | 891 |
|
---|
[4611] | 892 | case WM_CLOSE:
|
---|
[6709] | 893 | ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd));
|
---|
| 894 | return TRUE;
|
---|
[4611] | 895 |
|
---|
| 896 | case WM_PAINT:
|
---|
| 897 | {
|
---|
| 898 | ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
|
---|
[10097] | 899 |
|
---|
[4611] | 900 | /* the animation isn't playing, don't paint */
|
---|
[6709] | 901 | if(!infoPtr->uTimer && !infoPtr->hThread)
|
---|
| 902 | /* default paint handling */
|
---|
| 903 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
[10097] | 904 |
|
---|
[4611] | 905 | if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
|
---|
[10097] | 906 | infoPtr->hbrushBG = (HBRUSH)SendMessageA(GetParent(hWnd),
|
---|
| 907 | WM_CTLCOLORSTATIC,
|
---|
| 908 | wParam, (LPARAM)hWnd);
|
---|
| 909 |
|
---|
[4611] | 910 | if (wParam)
|
---|
| 911 | {
|
---|
| 912 | EnterCriticalSection(&infoPtr->cs);
|
---|
| 913 | ANIMATE_PaintFrame(infoPtr, (HDC)wParam);
|
---|
| 914 | LeaveCriticalSection(&infoPtr->cs);
|
---|
| 915 | }
|
---|
| 916 | else
|
---|
| 917 | {
|
---|
[6709] | 918 | PAINTSTRUCT ps;
|
---|
| 919 | HDC hDC = BeginPaint(hWnd, &ps);
|
---|
[4611] | 920 |
|
---|
| 921 | EnterCriticalSection(&infoPtr->cs);
|
---|
| 922 | ANIMATE_PaintFrame(infoPtr, hDC);
|
---|
| 923 | LeaveCriticalSection(&infoPtr->cs);
|
---|
[10097] | 924 |
|
---|
[6709] | 925 | EndPaint(hWnd, &ps);
|
---|
| 926 | }
|
---|
[4611] | 927 | }
|
---|
[6709] | 928 | break;
|
---|
[4611] | 929 |
|
---|
| 930 | case WM_SIZE:
|
---|
[6709] | 931 | ANIMATE_Size(hWnd, wParam, lParam);
|
---|
| 932 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
[4611] | 933 |
|
---|
| 934 | default:
|
---|
[10097] | 935 | if ((uMsg >= WM_USER) && (uMsg < WM_APP))
|
---|
[6709] | 936 | ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
|
---|
[10097] | 937 |
|
---|
[6709] | 938 | return DefWindowProcA(hWnd, uMsg, wParam, lParam);
|
---|
[4611] | 939 | }
|
---|
| 940 | return 0;
|
---|
| 941 | }
|
---|
| 942 |
|
---|
| 943 | void ANIMATE_Register(void)
|
---|
| 944 | {
|
---|
| 945 | WNDCLASSA wndClass;
|
---|
| 946 |
|
---|
| 947 | ZeroMemory(&wndClass, sizeof(WNDCLASSA));
|
---|
| 948 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
|
---|
| 949 | wndClass.lpfnWndProc = (WNDPROC)ANIMATE_WindowProc;
|
---|
| 950 | wndClass.cbClsExtra = 0;
|
---|
| 951 | wndClass.cbWndExtra = sizeof(ANIMATE_INFO *);
|
---|
| 952 | wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
|
---|
| 953 | wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
---|
| 954 | wndClass.lpszClassName = ANIMATE_CLASSA;
|
---|
[10097] | 955 |
|
---|
[4611] | 956 | RegisterClassA(&wndClass);
|
---|
| 957 | }
|
---|
| 958 |
|
---|
| 959 |
|
---|
| 960 | void ANIMATE_Unregister(void)
|
---|
| 961 | {
|
---|
[10097] | 962 | UnregisterClassA(ANIMATE_CLASSA, NULL);
|
---|
[4611] | 963 | }
|
---|