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 #include "msvideo_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(msvideo
);
27 typedef struct tagWINE_HDD
{
31 LPBITMAPINFOHEADER lpbi
;
34 HPALETTE hpal
; /* Palette to use for the DIB */
35 BOOL begun
; /* DrawDibBegin has been called */
36 LPBITMAPINFOHEADER lpbiOut
; /* Output format */
37 HIC hic
; /* HIC for decompression */
38 HDC hMemDC
; /* DC for buffering */
39 HBITMAP hOldDib
; /* Original Dib */
40 HBITMAP hDib
; /* DibSection */
41 LPVOID lpvbits
; /* Buffer for holding decompressed dib */
43 struct tagWINE_HDD
* next
;
46 static int num_colours(const BITMAPINFOHEADER
*lpbi
)
49 return lpbi
->biClrUsed
;
50 if(lpbi
->biBitCount
<=8)
51 return 1<<lpbi
->biBitCount
;
55 static WINE_HDD
* HDD_FirstHdd
/* = NULL */;
57 static WINE_HDD
* MSVIDEO_GetHddPtr(HDRAWDIB hd
)
61 for (hdd
= HDD_FirstHdd
; hdd
!= NULL
&& hdd
->hSelf
!= hd
; hdd
= hdd
->next
);
65 static UINT_PTR HDD_HandleRef
= 1;
67 /***********************************************************************
68 * DrawDibOpen [MSVFW32.@]
70 HDRAWDIB VFWAPI
DrawDibOpen(void)
76 whdd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_HDD
));
77 TRACE("=> %p\n", whdd
);
79 while (MSVIDEO_GetHddPtr((HDRAWDIB
)HDD_HandleRef
) != NULL
) HDD_HandleRef
++;
80 whdd
->hSelf
= (HDRAWDIB
)HDD_HandleRef
++;
82 whdd
->next
= HDD_FirstHdd
;
88 /***********************************************************************
89 * DrawDibClose [MSVFW32.@]
91 BOOL VFWAPI
DrawDibClose(HDRAWDIB hdd
)
93 WINE_HDD
* whdd
= MSVIDEO_GetHddPtr(hdd
);
98 if (!whdd
) return FALSE
;
100 if (whdd
->begun
) DrawDibEnd(hdd
);
102 for (p
= &HDD_FirstHdd
; *p
!= NULL
; p
= &((*p
)->next
))
111 HeapFree(GetProcessHeap(), 0, whdd
);
116 /***********************************************************************
117 * DrawDibEnd [MSVFW32.@]
119 BOOL VFWAPI
DrawDibEnd(HDRAWDIB hdd
)
122 WINE_HDD
*whdd
= MSVIDEO_GetHddPtr(hdd
);
124 TRACE("(%p)\n", hdd
);
126 if (!whdd
) return FALSE
;
128 whdd
->hpal
= 0; /* Do not free this */
130 HeapFree(GetProcessHeap(), 0, whdd
->lpbi
);
132 HeapFree(GetProcessHeap(), 0, whdd
->lpbiOut
);
133 whdd
->lpbiOut
= NULL
;
138 HeapFree(GetProcessHeap(), 0, whdd->lpvbuf);*/
142 SelectObject(whdd
->hMemDC
, whdd
->hOldDib
);
143 DeleteDC(whdd
->hMemDC
);
147 if (whdd
->hDib
) DeleteObject(whdd
->hDib
);
152 ICDecompressEnd(whdd
->hic
);
157 whdd
->lpvbits
= NULL
;
162 /***********************************************************************
163 * DrawDibBegin [MSVFW32.@]
165 BOOL VFWAPI
DrawDibBegin(HDRAWDIB hdd
,
169 LPBITMAPINFOHEADER lpbi
,
177 TRACE("(%p,%p,%d,%d,%p,%d,%d,0x%08x)\n",
178 hdd
, hdc
, dxDst
, dyDst
, lpbi
, dxSrc
, dySrc
, wFlags
);
180 TRACE("lpbi: %d,%d/%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
181 lpbi
->biSize
, lpbi
->biWidth
, lpbi
->biHeight
, lpbi
->biPlanes
,
182 lpbi
->biBitCount
, lpbi
->biCompression
, lpbi
->biSizeImage
,
183 lpbi
->biXPelsPerMeter
, lpbi
->biYPelsPerMeter
, lpbi
->biClrUsed
,
184 lpbi
->biClrImportant
);
186 if (wFlags
& ~(DDF_BUFFER
))
187 FIXME("wFlags == 0x%08x not handled\n", wFlags
& ~(DDF_BUFFER
));
189 whdd
= MSVIDEO_GetHddPtr(hdd
);
190 if (!whdd
) return FALSE
;
192 if (whdd
->begun
) DrawDibEnd(hdd
);
194 if (lpbi
->biCompression
)
198 whdd
->hic
= ICOpen(ICTYPE_VIDEO
, lpbi
->biCompression
, ICMODE_DECOMPRESS
);
201 WARN("Could not open IC. biCompression == 0x%08x\n", lpbi
->biCompression
);
207 size
= ICDecompressGetFormat(whdd
->hic
, lpbi
, NULL
);
208 if (size
== ICERR_UNSUPPORTED
)
210 WARN("Codec doesn't support GetFormat, giving up.\n");
217 whdd
->lpbiOut
= HeapAlloc(GetProcessHeap(), 0, size
);
219 if (ICDecompressGetFormat(whdd
->hic
, lpbi
, whdd
->lpbiOut
) != ICERR_OK
)
225 /* FIXME: Use Ex functions if available? */
226 if (ICDecompressBegin(whdd
->hic
, lpbi
, whdd
->lpbiOut
) != ICERR_OK
)
229 TRACE("biSizeImage == %d\n", whdd
->lpbiOut
->biSizeImage
);
230 TRACE("biCompression == %d\n", whdd
->lpbiOut
->biCompression
);
231 TRACE("biBitCount == %d\n", whdd
->lpbiOut
->biBitCount
);
238 TRACE("Not compressed!\n");
239 if (lpbi
->biHeight
<= 0)
241 /* we don't draw inverted DIBs */
242 TRACE("detected inverted DIB\n");
247 dwSize
= lpbi
->biSize
+ num_colours(lpbi
)*sizeof(RGBQUAD
);
248 whdd
->lpbiOut
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
249 memcpy(whdd
->lpbiOut
, lpbi
, dwSize
);
255 /*whdd->lpvbuf = HeapAlloc(GetProcessHeap(), 0, whdd->lpbiOut->biSizeImage);*/
257 whdd
->hMemDC
= CreateCompatibleDC(hdc
);
258 TRACE("Creating: %d, %p\n", whdd
->lpbiOut
->biSize
, whdd
->lpvbits
);
259 whdd
->hDib
= CreateDIBSection(whdd
->hMemDC
, (BITMAPINFO
*)whdd
->lpbiOut
, DIB_RGB_COLORS
, &(whdd
->lpvbits
), 0, 0);
262 TRACE("Created: %p,%p\n", whdd
->hDib
, whdd
->lpvbits
);
267 TRACE("Error: %d\n", GetLastError());
269 whdd
->hOldDib
= SelectObject(whdd
->hMemDC
, whdd
->hDib
);
277 whdd
->lpbi
= HeapAlloc(GetProcessHeap(), 0, lpbi
->biSize
);
278 memcpy(whdd
->lpbi
, lpbi
, lpbi
->biSize
);
288 HeapFree(GetProcessHeap(), 0, whdd
->lpbiOut
);
289 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%08x)\n",
309 hdd
, hdc
, xDst
, yDst
, dxDst
, dyDst
, lpbi
, lpBits
, xSrc
, ySrc
, dxSrc
, dySrc
, wFlags
);
311 whdd
= MSVIDEO_GetHddPtr(hdd
);
312 if (!whdd
) return FALSE
;
314 TRACE("whdd=%p\n", whdd
);
316 if (wFlags
& ~(DDF_SAME_HDC
| DDF_SAME_DRAW
| DDF_NOTKEYFRAME
| DDF_UPDATE
| DDF_DONTDRAW
| DDF_BACKGROUNDPAL
))
317 FIXME("wFlags == 0x%08x not handled\n", wFlags
);
322 lpBits
= (LPSTR
)lpbi
+ (WORD
)(lpbi
->biSize
) + (WORD
)(num_colours(lpbi
)*sizeof(RGBQUAD
));
326 #define CHANGED(x) (whdd->x != x)
328 if ((!whdd
->begun
) ||
329 (!(wFlags
& DDF_SAME_HDC
) && CHANGED(hdc
)) ||
330 (!(wFlags
& DDF_SAME_DRAW
) && (CHANGED(lpbi
) || CHANGED(dxSrc
) || CHANGED(dySrc
) || CHANGED(dxDst
) || CHANGED(dyDst
))))
332 TRACE("Something changed!\n");
333 ret
= DrawDibBegin(hdd
, hdc
, dxDst
, dyDst
, lpbi
, dxSrc
, dySrc
, 0);
340 if ((dxDst
== -1) && (dyDst
== -1))
346 if (!(wFlags
& DDF_UPDATE
))
348 if (lpbi
->biCompression
)
352 TRACE("Compression == 0x%08x\n", lpbi
->biCompression
);
354 if (wFlags
& DDF_NOTKEYFRAME
)
355 flags
|= ICDECOMPRESS_NOTKEYFRAME
;
357 ICDecompress(whdd
->hic
, flags
, lpbi
, lpBits
, whdd
->lpbiOut
, whdd
->lpvbits
);
361 /* BI_RGB: lpbi->biSizeImage isn't reliable */
362 DWORD biSizeImage
= ((lpbi
->biWidth
* lpbi
->biBitCount
+ 31) / 32) * 4 * lpbi
->biHeight
;
363 memcpy(whdd
->lpvbits
, lpBits
, biSizeImage
);
366 if (!(wFlags
& DDF_DONTDRAW
) && whdd
->hpal
)
368 if ((wFlags
& DDF_BACKGROUNDPAL
) && ! (wFlags
& DDF_SAME_HDC
))
369 SelectPalette(hdc
, whdd
->hpal
, TRUE
);
371 SelectPalette(hdc
, whdd
->hpal
, FALSE
);
374 if (!(StretchBlt(whdd
->hdc
, xDst
, yDst
, dxDst
, dyDst
, whdd
->hMemDC
, xSrc
, ySrc
, dxSrc
, dySrc
, SRCCOPY
)))
380 /*************************************************************************
381 * DrawDibStart [MSVFW32.@]
383 BOOL VFWAPI
DrawDibStart(HDRAWDIB hdd
, DWORD rate
) {
384 FIXME("(%p, %d), stub\n", hdd
, rate
);
388 /*************************************************************************
389 * DrawDibStop [MSVFW32.@]
391 BOOL VFWAPI
DrawDibStop(HDRAWDIB hdd
) {
392 FIXME("(%p), stub\n", hdd
);
396 /***********************************************************************
397 * DrawDibChangePalette [MSVFW32.@]
399 BOOL VFWAPI
DrawDibChangePalette(HDRAWDIB hdd
, int iStart
, int iLen
, LPPALETTEENTRY lppe
)
401 FIXME("(%p, 0x%08x, 0x%08x, %p), stub\n", hdd
, iStart
, iLen
, lppe
);
405 /***********************************************************************
406 * DrawDibSetPalette [MSVFW32.@]
408 BOOL VFWAPI
DrawDibSetPalette(HDRAWDIB hdd
, HPALETTE hpal
)
412 TRACE("(%p, %p)\n", hdd
, hpal
);
414 whdd
= MSVIDEO_GetHddPtr(hdd
);
415 if (!whdd
) return FALSE
;
421 SelectPalette(whdd
->hdc
, hpal
, 0);
422 RealizePalette(whdd
->hdc
);
428 /***********************************************************************
429 * DrawDibGetBuffer [MSVFW32.@]
431 LPVOID VFWAPI
DrawDibGetBuffer(HDRAWDIB hdd
, LPBITMAPINFOHEADER lpbi
, DWORD dwSize
, DWORD dwFlags
)
433 FIXME("(%p, %p, 0x%08x, 0x%08x), stub\n", hdd
, lpbi
, dwSize
, dwFlags
);
437 /***********************************************************************
438 * DrawDibGetPalette [MSVFW32.@]
440 HPALETTE VFWAPI
DrawDibGetPalette(HDRAWDIB hdd
)
444 TRACE("(%p)\n", hdd
);
446 whdd
= MSVIDEO_GetHddPtr(hdd
);
447 if (!whdd
) return FALSE
;
452 /***********************************************************************
453 * DrawDibRealize [MSVFW32.@]
455 UINT VFWAPI
DrawDibRealize(HDRAWDIB hdd
, HDC hdc
, BOOL fBackground
)
460 FIXME("(%p, %p, %d), stub\n", hdd
, hdc
, fBackground
);
462 whdd
= MSVIDEO_GetHddPtr(hdd
);
463 if (!whdd
) return FALSE
;
465 if (!whdd
|| !(whdd
->begun
))
472 whdd
->hpal
= CreateHalftonePalette(hdc
);
474 SelectPalette(hdc
, whdd
->hpal
, fBackground
);
475 ret
= RealizePalette(hdc
);
478 TRACE("=> %u\n", ret
);
482 /***********************************************************************
483 * DrawDibTime [MSVFW32.@]
485 BOOL VFWAPI
DrawDibTime(HDRAWDIB hdd
, LPDRAWDIBTIME lpddtime
)
487 FIXME("(%p, %p) stub\n", hdd
, lpddtime
);
491 /***********************************************************************
492 * DrawDibProfileDisplay [MSVFW32.@]
494 DWORD VFWAPI
DrawDibProfileDisplay(LPBITMAPINFOHEADER lpbi
)
496 FIXME("(%p) stub\n", lpbi
);
498 return PD_CAN_DRAW_DIB
;