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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 * FIXME: Some flags are ignored
23 #define WIN32_NO_STATUS
25 #define COM_NO_WINDOWS_H
34 //#include "winuser.h"
37 #include <wine/debug.h>
39 WINE_DEFAULT_DEBUG_CHANNEL(msvideo
);
41 typedef struct tagWINE_HDD
{
45 LPBITMAPINFOHEADER lpbi
;
48 HPALETTE hpal
; /* Palette to use for the DIB */
49 BOOL begun
; /* DrawDibBegin has been called */
50 LPBITMAPINFOHEADER lpbiOut
; /* Output format */
51 HIC hic
; /* HIC for decompression */
52 HDC hMemDC
; /* DC for buffering */
53 HBITMAP hOldDib
; /* Original Dib */
54 HBITMAP hDib
; /* DibSection */
55 LPVOID lpvbits
; /* Buffer for holding decompressed dib */
57 struct tagWINE_HDD
* next
;
60 static int num_colours(const BITMAPINFOHEADER
*lpbi
)
63 return lpbi
->biClrUsed
;
64 if(lpbi
->biBitCount
<=8)
65 return 1<<lpbi
->biBitCount
;
69 static WINE_HDD
* HDD_FirstHdd
/* = NULL */;
71 static WINE_HDD
* MSVIDEO_GetHddPtr(HDRAWDIB hd
)
75 for (hdd
= HDD_FirstHdd
; hdd
!= NULL
&& hdd
->hSelf
!= hd
; hdd
= hdd
->next
);
79 static UINT_PTR HDD_HandleRef
= 1;
81 /***********************************************************************
82 * DrawDibOpen [MSVFW32.@]
84 HDRAWDIB VFWAPI
DrawDibOpen(void)
90 whdd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_HDD
));
91 TRACE("=> %p\n", whdd
);
93 while (MSVIDEO_GetHddPtr((HDRAWDIB
)HDD_HandleRef
) != NULL
) HDD_HandleRef
++;
94 whdd
->hSelf
= (HDRAWDIB
)HDD_HandleRef
++;
96 whdd
->next
= HDD_FirstHdd
;
102 /***********************************************************************
103 * DrawDibClose [MSVFW32.@]
105 BOOL VFWAPI
DrawDibClose(HDRAWDIB hdd
)
107 WINE_HDD
* whdd
= MSVIDEO_GetHddPtr(hdd
);
110 TRACE("(%p)\n", hdd
);
112 if (!whdd
) return FALSE
;
114 if (whdd
->begun
) DrawDibEnd(hdd
);
116 for (p
= &HDD_FirstHdd
; *p
!= NULL
; p
= &((*p
)->next
))
125 HeapFree(GetProcessHeap(), 0, whdd
);
130 /***********************************************************************
131 * DrawDibEnd [MSVFW32.@]
133 BOOL VFWAPI
DrawDibEnd(HDRAWDIB hdd
)
136 WINE_HDD
*whdd
= MSVIDEO_GetHddPtr(hdd
);
138 TRACE("(%p)\n", hdd
);
140 if (!whdd
) return FALSE
;
142 whdd
->hpal
= 0; /* Do not free this */
144 HeapFree(GetProcessHeap(), 0, whdd
->lpbi
);
146 HeapFree(GetProcessHeap(), 0, whdd
->lpbiOut
);
147 whdd
->lpbiOut
= NULL
;
152 HeapFree(GetProcessHeap(), 0, whdd->lpvbuf);*/
156 SelectObject(whdd
->hMemDC
, whdd
->hOldDib
);
157 DeleteDC(whdd
->hMemDC
);
161 if (whdd
->hDib
) DeleteObject(whdd
->hDib
);
166 ICDecompressEnd(whdd
->hic
);
171 whdd
->lpvbits
= NULL
;
176 /***********************************************************************
177 * DrawDibBegin [MSVFW32.@]
179 BOOL VFWAPI
DrawDibBegin(HDRAWDIB hdd
,
183 LPBITMAPINFOHEADER lpbi
,
191 TRACE("(%p,%p,%d,%d,%p,%d,%d,0x%08x)\n",
192 hdd
, hdc
, dxDst
, dyDst
, lpbi
, dxSrc
, dySrc
, wFlags
);
194 TRACE("lpbi: %d,%d/%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
195 lpbi
->biSize
, lpbi
->biWidth
, lpbi
->biHeight
, lpbi
->biPlanes
,
196 lpbi
->biBitCount
, lpbi
->biCompression
, lpbi
->biSizeImage
,
197 lpbi
->biXPelsPerMeter
, lpbi
->biYPelsPerMeter
, lpbi
->biClrUsed
,
198 lpbi
->biClrImportant
);
200 if (wFlags
& ~(DDF_BUFFER
))
201 FIXME("wFlags == 0x%08x not handled\n", wFlags
& ~(DDF_BUFFER
));
203 whdd
= MSVIDEO_GetHddPtr(hdd
);
204 if (!whdd
) return FALSE
;
206 if (whdd
->begun
) DrawDibEnd(hdd
);
208 if (lpbi
->biCompression
)
212 whdd
->hic
= ICOpen(ICTYPE_VIDEO
, lpbi
->biCompression
, ICMODE_DECOMPRESS
);
215 WARN("Could not open IC. biCompression == 0x%08x\n", lpbi
->biCompression
);
221 size
= ICDecompressGetFormat(whdd
->hic
, lpbi
, NULL
);
222 if (size
== ICERR_UNSUPPORTED
)
224 WARN("Codec doesn't support GetFormat, giving up.\n");
231 whdd
->lpbiOut
= HeapAlloc(GetProcessHeap(), 0, size
);
233 if (ICDecompressGetFormat(whdd
->hic
, lpbi
, whdd
->lpbiOut
) != ICERR_OK
)
239 /* FIXME: Use Ex functions if available? */
240 if (ICDecompressBegin(whdd
->hic
, lpbi
, whdd
->lpbiOut
) != ICERR_OK
)
243 TRACE("biSizeImage == %d\n", whdd
->lpbiOut
->biSizeImage
);
244 TRACE("biCompression == %d\n", whdd
->lpbiOut
->biCompression
);
245 TRACE("biBitCount == %d\n", whdd
->lpbiOut
->biBitCount
);
252 TRACE("Not compressed!\n");
253 dwSize
= lpbi
->biSize
+ num_colours(lpbi
)*sizeof(RGBQUAD
);
254 whdd
->lpbiOut
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
255 memcpy(whdd
->lpbiOut
, lpbi
, dwSize
);
260 /*whdd->lpvbuf = HeapAlloc(GetProcessHeap(), 0, whdd->lpbiOut->biSizeImage);*/
262 whdd
->hMemDC
= CreateCompatibleDC(hdc
);
263 TRACE("Creating: %d, %p\n", whdd
->lpbiOut
->biSize
, whdd
->lpvbits
);
264 whdd
->hDib
= CreateDIBSection(whdd
->hMemDC
, (BITMAPINFO
*)whdd
->lpbiOut
, DIB_RGB_COLORS
, &(whdd
->lpvbits
), 0, 0);
267 TRACE("Created: %p,%p\n", whdd
->hDib
, whdd
->lpvbits
);
272 TRACE("Error: %d\n", GetLastError());
274 whdd
->hOldDib
= SelectObject(whdd
->hMemDC
, whdd
->hDib
);
282 whdd
->lpbi
= HeapAlloc(GetProcessHeap(), 0, lpbi
->biSize
);
283 memcpy(whdd
->lpbi
, lpbi
, lpbi
->biSize
);
293 HeapFree(GetProcessHeap(), 0, whdd
->lpbiOut
);
294 whdd
->lpbiOut
= NULL
;
300 /**********************************************************************
301 * DrawDibDraw [MSVFW32.@]
303 BOOL VFWAPI
DrawDibDraw(HDRAWDIB hdd
, HDC hdc
,
304 INT xDst
, INT yDst
, INT dxDst
, INT dyDst
,
305 LPBITMAPINFOHEADER lpbi
,
307 INT xSrc
, INT ySrc
, INT dxSrc
, INT dySrc
,
313 TRACE("(%p,%p,%d,%d,%d,%d,%p,%p,%d,%d,%d,%d,0x%08x)\n",
314 hdd
, hdc
, xDst
, yDst
, dxDst
, dyDst
, lpbi
, lpBits
, xSrc
, ySrc
, dxSrc
, dySrc
, wFlags
);
316 whdd
= MSVIDEO_GetHddPtr(hdd
);
317 if (!whdd
) return FALSE
;
319 TRACE("whdd=%p\n", whdd
);
321 if (wFlags
& ~(DDF_SAME_HDC
| DDF_SAME_DRAW
| DDF_NOTKEYFRAME
| DDF_UPDATE
| DDF_DONTDRAW
| DDF_BACKGROUNDPAL
))
322 FIXME("wFlags == 0x%08x not handled\n", wFlags
);
327 lpBits
= (LPSTR
)lpbi
+ (WORD
)(lpbi
->biSize
) + (WORD
)(num_colours(lpbi
)*sizeof(RGBQUAD
));
331 #define CHANGED(x) (whdd->x != x)
333 if ((!whdd
->begun
) ||
334 (!(wFlags
& DDF_SAME_HDC
) && CHANGED(hdc
)) ||
335 (!(wFlags
& DDF_SAME_DRAW
) && (CHANGED(lpbi
) || CHANGED(dxSrc
) || CHANGED(dySrc
) || CHANGED(dxDst
) || CHANGED(dyDst
))))
337 TRACE("Something changed!\n");
338 ret
= DrawDibBegin(hdd
, hdc
, dxDst
, dyDst
, lpbi
, dxSrc
, dySrc
, 0);
343 if ((dxDst
== -1) && (dyDst
== -1))
349 if (!(wFlags
& DDF_UPDATE
))
351 DWORD biSizeImage
= lpbi
->biSizeImage
;
353 /* biSizeImage may be set to 0 for BI_RGB (uncompressed) bitmaps */
354 if ((lpbi
->biCompression
== BI_RGB
) && (biSizeImage
== 0))
355 biSizeImage
= ((lpbi
->biWidth
* lpbi
->biBitCount
+ 31) / 32) * 4 * lpbi
->biHeight
;
357 if (lpbi
->biCompression
)
361 TRACE("Compression == 0x%08x\n", lpbi
->biCompression
);
363 if (wFlags
& DDF_NOTKEYFRAME
)
364 flags
|= ICDECOMPRESS_NOTKEYFRAME
;
366 ICDecompress(whdd
->hic
, flags
, lpbi
, lpBits
, whdd
->lpbiOut
, whdd
->lpvbits
);
370 memcpy(whdd
->lpvbits
, lpBits
, biSizeImage
);
373 if (!(wFlags
& DDF_DONTDRAW
) && whdd
->hpal
)
375 if ((wFlags
& DDF_BACKGROUNDPAL
) && ! (wFlags
& DDF_SAME_HDC
))
376 SelectPalette(hdc
, whdd
->hpal
, TRUE
);
378 SelectPalette(hdc
, whdd
->hpal
, FALSE
);
381 if (!(StretchBlt(whdd
->hdc
, xDst
, yDst
, dxDst
, dyDst
, whdd
->hMemDC
, xSrc
, ySrc
, dxSrc
, dySrc
, SRCCOPY
)))
387 /*************************************************************************
388 * DrawDibStart [MSVFW32.@]
390 BOOL VFWAPI
DrawDibStart(HDRAWDIB hdd
, DWORD rate
) {
391 FIXME("(%p, %d), stub\n", hdd
, rate
);
395 /*************************************************************************
396 * DrawDibStop [MSVFW32.@]
398 BOOL VFWAPI
DrawDibStop(HDRAWDIB hdd
) {
399 FIXME("(%p), stub\n", hdd
);
403 /***********************************************************************
404 * DrawDibChangePalette [MSVFW32.@]
406 BOOL VFWAPI
DrawDibChangePalette(HDRAWDIB hdd
, int iStart
, int iLen
, LPPALETTEENTRY lppe
)
408 FIXME("(%p, 0x%08x, 0x%08x, %p), stub\n", hdd
, iStart
, iLen
, lppe
);
412 /***********************************************************************
413 * DrawDibSetPalette [MSVFW32.@]
415 BOOL VFWAPI
DrawDibSetPalette(HDRAWDIB hdd
, HPALETTE hpal
)
419 TRACE("(%p, %p)\n", hdd
, hpal
);
421 whdd
= MSVIDEO_GetHddPtr(hdd
);
422 if (!whdd
) return FALSE
;
428 SelectPalette(whdd
->hdc
, hpal
, 0);
429 RealizePalette(whdd
->hdc
);
435 /***********************************************************************
436 * DrawDibGetBuffer [MSVFW32.@]
438 LPVOID VFWAPI
DrawDibGetBuffer(HDRAWDIB hdd
, LPBITMAPINFOHEADER lpbi
, DWORD dwSize
, DWORD dwFlags
)
440 FIXME("(%p, %p, 0x%08x, 0x%08x), stub\n", hdd
, lpbi
, dwSize
, dwFlags
);
444 /***********************************************************************
445 * DrawDibGetPalette [MSVFW32.@]
447 HPALETTE VFWAPI
DrawDibGetPalette(HDRAWDIB hdd
)
451 TRACE("(%p)\n", hdd
);
453 whdd
= MSVIDEO_GetHddPtr(hdd
);
454 if (!whdd
) return FALSE
;
459 /***********************************************************************
460 * DrawDibRealize [MSVFW32.@]
462 UINT VFWAPI
DrawDibRealize(HDRAWDIB hdd
, HDC hdc
, BOOL fBackground
)
467 FIXME("(%p, %p, %d), stub\n", hdd
, hdc
, fBackground
);
469 whdd
= MSVIDEO_GetHddPtr(hdd
);
470 if (!whdd
) return FALSE
;
472 if (!whdd
|| !(whdd
->begun
))
479 whdd
->hpal
= CreateHalftonePalette(hdc
);
481 SelectPalette(hdc
, whdd
->hpal
, fBackground
);
482 ret
= RealizePalette(hdc
);
485 TRACE("=> %u\n", ret
);
489 /***********************************************************************
490 * DrawDibTime [MSVFW32.@]
492 BOOL VFWAPI
DrawDibTime(HDRAWDIB hdd
, LPDRAWDIBTIME lpddtime
)
494 FIXME("(%p, %p) stub\n", hdd
, lpddtime
);
498 /***********************************************************************
499 * DrawDibProfileDisplay [MSVFW32.@]
501 DWORD VFWAPI
DrawDibProfileDisplay(LPBITMAPINFOHEADER lpbi
)
503 FIXME("(%p) stub\n", lpbi
);
505 return PD_CAN_DRAW_DIB
;