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
28 #include "wine/winbase16.h"
29 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvideo);
40 LPBITMAPINFOHEADER lpbi;
43 HPALETTE hpal; /* Palette to use for the DIB */
44 BOOL begun; /* DrawDibBegin has been called */
45 LPBITMAPINFOHEADER lpbiOut; /* Output format */
46 HIC hic; /* HIC for decompression */
47 HDC hMemDC; /* DC for buffering */
48 HBITMAP hOldDib; /* Original Dib */
49 HBITMAP hDib; /* DibSection */
50 LPVOID lpvbits; /* Buffer for holding decompressed dib */
53 int num_colours(LPBITMAPINFOHEADER lpbi)
56 return lpbi->biClrUsed;
57 if(lpbi->biBitCount<=8)
58 return 1<<lpbi->biBitCount;
62 /***********************************************************************
63 * DrawDibOpen [MSVFW32.@]
65 HDRAWDIB VFWAPI DrawDibOpen(void) {
69 hdd = GlobalAlloc16(GHND,sizeof(WINE_HDD));
74 /***********************************************************************
75 * DrawDibOpen [MSVIDEO.102]
77 HDRAWDIB16 VFWAPI DrawDibOpen16(void) {
78 return (HDRAWDIB16)DrawDibOpen();
81 /***********************************************************************
82 * DrawDibClose [MSVFW32.@]
84 BOOL VFWAPI DrawDibClose(HDRAWDIB hdd) {
85 WINE_HDD *whdd = GlobalLock16(hdd);
87 TRACE("(0x%08lx)\n",(DWORD)hdd);
100 /***********************************************************************
101 * DrawDibClose [MSVIDEO.103]
103 BOOL16 VFWAPI DrawDibClose16(HDRAWDIB16 hdd) {
104 return DrawDibClose(hdd);
107 /***********************************************************************
108 * DrawDibEnd [MSVFW32.@]
110 BOOL VFWAPI DrawDibEnd(HDRAWDIB hdd) {
112 WINE_HDD *whdd = GlobalLock16(hdd);
114 TRACE("(0x%08lx)\n",(DWORD)hdd);
116 whdd->hpal = 0; /* Do not free this */
119 HeapFree(GetProcessHeap(),0,whdd->lpbi);
123 HeapFree(GetProcessHeap(),0,whdd->lpbiOut);
124 whdd->lpbiOut = NULL;
130 HeapFree(GetProcessHeap(),0,whdd->lpvbuf);*/
133 SelectObject(whdd->hMemDC,whdd->hOldDib);
134 DeleteDC(whdd->hMemDC);
138 DeleteObject(whdd->hDib);
141 ICDecompressEnd(whdd->hic);
145 whdd->lpvbits = NULL;
151 /***********************************************************************
152 * DrawDibEnd [MSVIDEO.105]
154 BOOL16 VFWAPI DrawDibEnd16(HDRAWDIB16 hdd) {
155 return DrawDibEnd(hdd);
158 /***********************************************************************
159 * DrawDibBegin [MSVFW32.@]
161 BOOL VFWAPI DrawDibBegin(HDRAWDIB hdd,
165 LPBITMAPINFOHEADER lpbi,
172 TRACE("(%d,0x%lx,%d,%d,%p,%d,%d,0x%08lx)\n",
173 hdd,(DWORD)hdc,dxDst,dyDst,lpbi,dxSrc,dySrc,(DWORD)wFlags
175 TRACE("lpbi: %ld,%ld/%ld,%d,%d,%ld,%ld,%ld,%ld,%ld,%ld\n",
176 lpbi->biSize, lpbi->biWidth, lpbi->biHeight, lpbi->biPlanes,
177 lpbi->biBitCount, lpbi->biCompression, lpbi->biSizeImage,
178 lpbi->biXPelsPerMeter, lpbi->biYPelsPerMeter, lpbi->biClrUsed,
179 lpbi->biClrImportant);
181 if (wFlags & ~(DDF_BUFFER))
182 FIXME("wFlags == 0x%08x not handled\n", wFlags & ~(DDF_BUFFER));
184 whdd = (WINE_HDD*)GlobalLock16(hdd);
185 if (!whdd) return FALSE;
190 if (lpbi->biCompression) {
193 whdd->hic = ICOpen(ICTYPE_VIDEO,lpbi->biCompression,ICMODE_DECOMPRESS);
195 WARN("Could not open IC. biCompression == 0x%08lx\n",lpbi->biCompression);
200 size = ICDecompressGetFormat(whdd->hic,lpbi,NULL);
201 if (size == ICERR_UNSUPPORTED) {
202 WARN("Codec doesn't support GetFormat, giving up.\n");
208 whdd->lpbiOut = HeapAlloc(GetProcessHeap(),0,size);
210 if (ICDecompressGetFormat(whdd->hic,lpbi,whdd->lpbiOut) != ICERR_OK)
215 /* FIXME: Use Ex functions if available? */
216 if (ICDecompressBegin(whdd->hic,lpbi,whdd->lpbiOut) != ICERR_OK)
219 TRACE("biSizeImage == %ld\n",whdd->lpbiOut->biSizeImage);
220 TRACE("biCompression == %ld\n",whdd->lpbiOut->biCompression);
221 TRACE("biBitCount == %d\n",whdd->lpbiOut->biBitCount);
226 TRACE("Not compressed!\n");
227 dwSize = lpbi->biSize + num_colours(lpbi)*sizeof(RGBQUAD);
228 whdd->lpbiOut = HeapAlloc(GetProcessHeap(),0,dwSize);
229 memcpy(whdd->lpbiOut,lpbi,dwSize);
233 /*whdd->lpvbuf = HeapAlloc(GetProcessHeap(),0,whdd->lpbiOut->biSizeImage);*/
235 whdd->hMemDC = CreateCompatibleDC(hdc);
236 TRACE("Creating: %ld,%p\n",whdd->lpbiOut->biSize,whdd->lpvbits);
237 whdd->hDib = CreateDIBSection(whdd->hMemDC,(BITMAPINFO *)whdd->lpbiOut,DIB_RGB_COLORS,&(whdd->lpvbits),0,0);
239 TRACE("Error: %ld\n",GetLastError());
241 TRACE("Created: %d,%p\n",whdd->hDib,whdd->lpvbits);
242 whdd->hOldDib = SelectObject(whdd->hMemDC,whdd->hDib);
249 whdd->lpbi = HeapAlloc(GetProcessHeap(),0,lpbi->biSize);
250 memcpy(whdd->lpbi,lpbi,lpbi->biSize);
259 HeapFree(GetProcessHeap(),0,whdd->lpbiOut);
260 whdd->lpbiOut = NULL;
269 /************************************************************************
270 * DrawDibBegin [MSVIDEO.104]
272 BOOL16 VFWAPI DrawDibBegin16(HDRAWDIB16 hdd,
276 LPBITMAPINFOHEADER lpbi,
280 return DrawDibBegin(hdd,hdc,dxDst,dyDst,lpbi,dxSrc,dySrc,wFlags);
283 /**********************************************************************
284 * DrawDibDraw [MSVFW32.@]
286 BOOL VFWAPI DrawDibDraw(HDRAWDIB hdd, HDC hdc,
287 INT xDst, INT yDst, INT dxDst, INT dyDst,
288 LPBITMAPINFOHEADER lpbi,
290 INT xSrc, INT ySrc, INT dxSrc, INT dySrc,
296 TRACE("(%d,0x%lx,%d,%d,%d,%d,%p,%p,%d,%d,%d,%d,0x%08lx)\n",
297 hdd,(DWORD)hdc,xDst,yDst,dxDst,dyDst,lpbi,lpBits,xSrc,ySrc,dxSrc,dySrc,(DWORD)wFlags
300 if (wFlags & ~(DDF_SAME_HDC | DDF_SAME_DRAW | DDF_NOTKEYFRAME |
301 DDF_UPDATE | DDF_DONTDRAW))
302 FIXME("wFlags == 0x%08lx not handled\n",(DWORD)wFlags);
306 lpBits = (LPSTR)lpbi + (WORD)(lpbi->biSize) + (WORD)(num_colours(lpbi)*sizeof(RGBQUAD));
309 whdd = GlobalLock16(hdd);
311 #define CHANGED(x) (whdd->x != x)
313 if ((!whdd->begun) || (!(wFlags & DDF_SAME_HDC) && CHANGED(hdc)) || (!(wFlags & DDF_SAME_DRAW) &&
314 (CHANGED(lpbi) || CHANGED(dxSrc) || CHANGED(dySrc) || CHANGED(dxDst) || CHANGED(dyDst)))) {
315 TRACE("Something changed!\n");
316 ret = DrawDibBegin(hdd,hdc,dxDst,dyDst,lpbi,dxSrc,dySrc,0);
321 if ((dxDst == -1) && (dyDst == -1)) {
326 if (!(wFlags & DDF_UPDATE)) {
327 /* biSizeImage may be set to 0 for BI_RGB (uncompressed) bitmaps */
328 if ((lpbi->biCompression == BI_RGB) && (lpbi->biSizeImage == 0))
329 lpbi->biSizeImage = ((lpbi->biWidth * lpbi->biBitCount + 31) / 32) * 4 * lpbi->biHeight;
331 if (lpbi->biCompression) {
334 TRACE("Compression == 0x%08lx\n",lpbi->biCompression);
336 if (wFlags & DDF_NOTKEYFRAME)
337 flags |= ICDECOMPRESS_NOTKEYFRAME;
339 ICDecompress(whdd->hic,flags,lpbi,lpBits,whdd->lpbiOut,whdd->lpvbits);
341 memcpy(whdd->lpvbits,lpBits,lpbi->biSizeImage);
344 if (!(wFlags & DDF_DONTDRAW) && whdd->hpal)
345 SelectPalette(hdc,whdd->hpal,FALSE);
347 if (!(StretchBlt(whdd->hdc,xDst,yDst,dxDst,dyDst,whdd->hMemDC,xSrc,ySrc,dxSrc,dySrc,SRCCOPY)))
354 /**********************************************************************
355 * DrawDibDraw [MSVIDEO.106]
357 BOOL16 VFWAPI DrawDibDraw16(HDRAWDIB16 hdd,
363 LPBITMAPINFOHEADER lpbi,
370 return DrawDibDraw(hdd,hdc,xDst,yDst,dxDst,dyDst,lpbi,lpBits,xSrc,ySrc,dxSrc,dySrc,wFlags);
373 /*************************************************************************
374 * DrawDibStart [MSVFW32.@]
376 BOOL VFWAPI DrawDibStart(HDRAWDIB hdd, DWORD rate) {
377 FIXME("(0x%08lx,%ld), stub\n",(DWORD)hdd,rate);
381 /*************************************************************************
382 * DrawDibStart [MSVIDEO.118]
384 BOOL16 VFWAPI DrawDibStart16(HDRAWDIB16 hdd, DWORD rate) {
385 return DrawDibStart(hdd,rate);
388 /*************************************************************************
389 * DrawDibStop [MSVFW32.@]
391 BOOL VFWAPI DrawDibStop(HDRAWDIB hdd) {
392 FIXME("(0x%08lx), stub\n",(DWORD)hdd);
396 /*************************************************************************
397 * DrawDibStop [MSVIDEO.119]
399 BOOL16 DrawDibStop16(HDRAWDIB16 hdd) {
400 return DrawDibStop(hdd);
403 /***********************************************************************
404 * DrawDibSetPalette [MSVFW32.@]
406 BOOL VFWAPI DrawDibSetPalette(HDRAWDIB hdd, HPALETTE hpal) {
409 TRACE("(0x%08lx,0x%08lx)\n",(DWORD)hdd,(DWORD)hpal);
411 whdd = GlobalLock16(hdd);
415 SelectPalette(whdd->hdc,hpal,0);
416 RealizePalette(whdd->hdc);
422 /***********************************************************************
423 * DrawDibSetPalette [MSVIDEO.110]
425 BOOL16 VFWAPI DrawDibSetPalette16(HDRAWDIB16 hdd, HPALETTE16 hpal) {
426 return DrawDibSetPalette(hdd,hpal);
429 /***********************************************************************
430 * DrawDibGetPalette [MSVFW32.@]
432 HPALETTE VFWAPI DrawDibGetPalette(HDRAWDIB hdd) {
436 TRACE("(0x%08lx)\n",(DWORD)hdd);
438 whdd = GlobalLock16(hdd);
444 /***********************************************************************
445 * DrawDibGetPalette [MSVIDEO.108]
447 HPALETTE16 VFWAPI DrawDibGetPalette16(HDRAWDIB16 hdd) {
448 return (HPALETTE16)DrawDibGetPalette(hdd);
451 /***********************************************************************
452 * DrawDibRealize [MSVFW32.@]
454 UINT VFWAPI DrawDibRealize(HDRAWDIB hdd, HDC hdc, BOOL fBackground) {
459 FIXME("(%d,0x%08lx,%d), stub\n",hdd,(DWORD)hdc,fBackground);
461 whdd = GlobalLock16(hdd);
463 if (!whdd || !(whdd->begun)) {
469 whdd->hpal = CreateHalftonePalette(hdc);
471 oldPal = SelectPalette(hdc,whdd->hpal,fBackground);
472 ret = RealizePalette(hdc);
477 TRACE("=> %u\n",ret);
481 /***********************************************************************
482 * DrawDibRealize [MSVIDEO.112]
484 UINT16 VFWAPI DrawDibRealize16(HDRAWDIB16 hdd, HDC16 hdc, BOOL16 fBackground) {
485 return (UINT16)DrawDibRealize(hdd,hdc,fBackground);