2 * Copyright 2000 Bradley Baetz
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * FIXME: Some flags are ignored
24 #include "msvideo_private.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(msvideo);
33 typedef struct tagWINE_HDD {
37 LPBITMAPINFOHEADER lpbi;
40 HPALETTE hpal; /* Palette to use for the DIB */
41 BOOL begun; /* DrawDibBegin has been called */
42 LPBITMAPINFOHEADER lpbiOut; /* Output format */
43 HIC hic; /* HIC for decompression */
44 HDC hMemDC; /* DC for buffering */
45 HBITMAP hOldDib; /* Original Dib */
46 HBITMAP hDib; /* DibSection */
47 LPVOID lpvbits; /* Buffer for holding decompressed dib */
49 struct tagWINE_HDD* next;
52 int num_colours(LPBITMAPINFOHEADER lpbi)
55 return lpbi->biClrUsed;
56 if(lpbi->biBitCount<=8)
57 return 1<<lpbi->biBitCount;
61 static WINE_HDD* HDD_FirstHdd /* = NULL */;
63 static WINE_HDD* MSVIDEO_GetHddPtr(HDRAWDIB hd)
67 for (hdd = HDD_FirstHdd; hdd != NULL && hdd->hSelf != hd; hdd = hdd->next);
71 static DWORD HDD_HandleRef = 1;
73 /***********************************************************************
74 * DrawDibOpen [MSVFW32.@]
76 HDRAWDIB VFWAPI DrawDibOpen(void)
82 whdd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_HDD));
83 TRACE("=> %p\n", whdd);
85 while (MSVIDEO_GetHddPtr((HDRAWDIB)HDD_HandleRef) != NULL) HDD_HandleRef++;
86 whdd->hSelf = (HDRAWDIB)HDD_HandleRef++;
88 whdd->next = HDD_FirstHdd;
94 /***********************************************************************
95 * DrawDibClose [MSVFW32.@]
97 BOOL VFWAPI DrawDibClose(HDRAWDIB hdd)
99 WINE_HDD* whdd = MSVIDEO_GetHddPtr(hdd);
102 TRACE("(%p)\n", hdd);
104 if (!whdd) return FALSE;
106 if (whdd->begun) DrawDibEnd(hdd);
108 for (p = &HDD_FirstHdd; *p != NULL; p = &((*p)->next))
117 HeapFree(GetProcessHeap(), 0, whdd);
122 /***********************************************************************
123 * DrawDibEnd [MSVFW32.@]
125 BOOL VFWAPI DrawDibEnd(HDRAWDIB hdd)
128 WINE_HDD *whdd = MSVIDEO_GetHddPtr(hdd);
130 TRACE("(%p)\n", hdd);
132 whdd->hpal = 0; /* Do not free this */
136 HeapFree(GetProcessHeap(), 0, whdd->lpbi);
141 HeapFree(GetProcessHeap(), 0, whdd->lpbiOut);
142 whdd->lpbiOut = NULL;
148 HeapFree(GetProcessHeap(), 0, whdd->lpvbuf);*/
152 SelectObject(whdd->hMemDC, whdd->hOldDib);
153 DeleteDC(whdd->hMemDC);
157 if (whdd->hDib) DeleteObject(whdd->hDib);
162 ICDecompressEnd(whdd->hic);
167 whdd->lpvbits = NULL;
172 /***********************************************************************
173 * DrawDibBegin [MSVFW32.@]
175 BOOL VFWAPI DrawDibBegin(HDRAWDIB hdd,
179 LPBITMAPINFOHEADER lpbi,
187 TRACE("(%p,%p,%d,%d,%p,%d,%d,0x%08lx)\n",
188 hdd, hdc, dxDst, dyDst, lpbi, dxSrc, dySrc, (DWORD)wFlags);
190 TRACE("lpbi: %ld,%ld/%ld,%d,%d,%ld,%ld,%ld,%ld,%ld,%ld\n",
191 lpbi->biSize, lpbi->biWidth, lpbi->biHeight, lpbi->biPlanes,
192 lpbi->biBitCount, lpbi->biCompression, lpbi->biSizeImage,
193 lpbi->biXPelsPerMeter, lpbi->biYPelsPerMeter, lpbi->biClrUsed,
194 lpbi->biClrImportant);
196 if (wFlags & ~(DDF_BUFFER))
197 FIXME("wFlags == 0x%08x not handled\n", wFlags & ~(DDF_BUFFER));
199 whdd = MSVIDEO_GetHddPtr(hdd);
200 if (!whdd) return FALSE;
202 if (whdd->begun) DrawDibEnd(hdd);
204 if (lpbi->biCompression)
208 whdd->hic = ICOpen(ICTYPE_VIDEO, lpbi->biCompression, ICMODE_DECOMPRESS);
211 WARN("Could not open IC. biCompression == 0x%08lx\n", lpbi->biCompression);
217 size = ICDecompressGetFormat(whdd->hic, lpbi, NULL);
218 if (size == ICERR_UNSUPPORTED)
220 WARN("Codec doesn't support GetFormat, giving up.\n");
227 whdd->lpbiOut = HeapAlloc(GetProcessHeap(), 0, size);
229 if (ICDecompressGetFormat(whdd->hic, lpbi, whdd->lpbiOut) != ICERR_OK)
235 /* FIXME: Use Ex functions if available? */
236 if (ICDecompressBegin(whdd->hic, lpbi, whdd->lpbiOut) != ICERR_OK)
239 TRACE("biSizeImage == %ld\n", whdd->lpbiOut->biSizeImage);
240 TRACE("biCompression == %ld\n", whdd->lpbiOut->biCompression);
241 TRACE("biBitCount == %d\n", whdd->lpbiOut->biBitCount);
248 TRACE("Not compressed!\n");
249 dwSize = lpbi->biSize + num_colours(lpbi)*sizeof(RGBQUAD);
250 whdd->lpbiOut = HeapAlloc(GetProcessHeap(), 0, dwSize);
251 memcpy(whdd->lpbiOut, lpbi, dwSize);
256 /*whdd->lpvbuf = HeapAlloc(GetProcessHeap(), 0, whdd->lpbiOut->biSizeImage);*/
258 whdd->hMemDC = CreateCompatibleDC(hdc);
259 TRACE("Creating: %ld, %p\n", whdd->lpbiOut->biSize, whdd->lpvbits);
260 whdd->hDib = CreateDIBSection(whdd->hMemDC, (BITMAPINFO *)whdd->lpbiOut, DIB_RGB_COLORS, &(whdd->lpvbits), 0, 0);
263 TRACE("Error: %ld\n", GetLastError());
265 TRACE("Created: %p,%p\n", whdd->hDib, whdd->lpvbits);
266 whdd->hOldDib = SelectObject(whdd->hMemDC, whdd->hDib);
274 whdd->lpbi = HeapAlloc(GetProcessHeap(), 0, lpbi->biSize);
275 memcpy(whdd->lpbi, lpbi, lpbi->biSize);
287 HeapFree(GetProcessHeap(), 0, whdd->lpbiOut);
288 whdd->lpbiOut = NULL;
295 /**********************************************************************
296 * DrawDibDraw [MSVFW32.@]
298 BOOL VFWAPI DrawDibDraw(HDRAWDIB hdd, HDC hdc,
299 INT xDst, INT yDst, INT dxDst, INT dyDst,
300 LPBITMAPINFOHEADER lpbi,
302 INT xSrc, INT ySrc, INT dxSrc, INT dySrc,
308 TRACE("(%p,%p,%d,%d,%d,%d,%p,%p,%d,%d,%d,%d,0x%08lx)\n",
309 hdd, hdc, xDst, yDst, dxDst, dyDst, lpbi, lpBits, xSrc, ySrc, dxSrc, dySrc, (DWORD)wFlags);
311 whdd = MSVIDEO_GetHddPtr(hdd);
312 if (!whdd) return FALSE;
314 if (wFlags & ~(DDF_SAME_HDC | DDF_SAME_DRAW | DDF_NOTKEYFRAME | DDF_UPDATE | DDF_DONTDRAW))
315 FIXME("wFlags == 0x%08lx not handled\n", (DWORD)wFlags);
320 lpBits = (LPSTR)lpbi + (WORD)(lpbi->biSize) + (WORD)(num_colours(lpbi)*sizeof(RGBQUAD));
324 #define CHANGED(x) (whdd->x != x)
326 if ((!whdd->begun) ||
327 (!(wFlags & DDF_SAME_HDC) && CHANGED(hdc)) ||
328 (!(wFlags & DDF_SAME_DRAW) && (CHANGED(lpbi) || CHANGED(dxSrc) || CHANGED(dySrc) || CHANGED(dxDst) || CHANGED(dyDst))))
330 TRACE("Something changed!\n");
331 ret = DrawDibBegin(hdd, hdc, dxDst, dyDst, lpbi, dxSrc, dySrc, 0);
336 if ((dxDst == -1) && (dyDst == -1))
342 if (!(wFlags & DDF_UPDATE))
344 /* biSizeImage may be set to 0 for BI_RGB (uncompressed) bitmaps */
345 if ((lpbi->biCompression == BI_RGB) && (lpbi->biSizeImage == 0))
346 lpbi->biSizeImage = ((lpbi->biWidth * lpbi->biBitCount + 31) / 32) * 4 * lpbi->biHeight;
348 if (lpbi->biCompression)
352 TRACE("Compression == 0x%08lx\n", lpbi->biCompression);
354 if (wFlags & DDF_NOTKEYFRAME)
355 flags |= ICDECOMPRESS_NOTKEYFRAME;
357 ICDecompress(whdd->hic, flags, lpbi, lpBits, whdd->lpbiOut, whdd->lpvbits);
361 memcpy(whdd->lpvbits, lpBits, lpbi->biSizeImage);
364 if (!(wFlags & DDF_DONTDRAW) && whdd->hpal)
365 SelectPalette(hdc, whdd->hpal, FALSE);
367 if (!(StretchBlt(whdd->hdc, xDst, yDst, dxDst, dyDst, whdd->hMemDC, xSrc, ySrc, dxSrc, dySrc, SRCCOPY)))
373 /*************************************************************************
374 * DrawDibStart [MSVFW32.@]
376 BOOL VFWAPI DrawDibStart(HDRAWDIB hdd, DWORD rate) {
377 FIXME("(%p, %ld), stub\n", hdd, rate);
381 /*************************************************************************
382 * DrawDibStop [MSVFW32.@]
384 BOOL VFWAPI DrawDibStop(HDRAWDIB hdd) {
385 FIXME("(%p), stub\n", hdd);
389 /***********************************************************************
390 * DrawDibSetPalette [MSVFW32.@]
392 BOOL VFWAPI DrawDibSetPalette(HDRAWDIB hdd, HPALETTE hpal)
396 TRACE("(%p, %p)\n", hdd, hpal);
398 whdd = MSVIDEO_GetHddPtr(hdd);
399 if (!whdd) return FALSE;
405 SelectPalette(whdd->hdc, hpal, 0);
406 RealizePalette(whdd->hdc);
412 /***********************************************************************
413 * DrawDibGetPalette [MSVFW32.@]
415 HPALETTE VFWAPI DrawDibGetPalette(HDRAWDIB hdd)
419 TRACE("(%p)\n", hdd);
421 whdd = MSVIDEO_GetHddPtr(hdd);
422 if (!whdd) return FALSE;
427 /***********************************************************************
428 * DrawDibRealize [MSVFW32.@]
430 UINT VFWAPI DrawDibRealize(HDRAWDIB hdd, HDC hdc, BOOL fBackground)
436 FIXME("(%p, %p, %d), stub\n", hdd, hdc, fBackground);
438 whdd = MSVIDEO_GetHddPtr(hdd);
439 if (!whdd) return FALSE;
441 if (!whdd || !(whdd->begun))
448 whdd->hpal = CreateHalftonePalette(hdc);
450 oldPal = SelectPalette(hdc, whdd->hpal, fBackground);
451 ret = RealizePalette(hdc);
454 TRACE("=> %u\n", ret);
458 DWORD VFWAPI DrawDibProfileDisplay(LPBITMAPINFOHEADER lpbi)
460 FIXME("(%p) stub\n", lpbi);
462 return PD_CAN_DRAW_DIB;