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 /***********************************************************************
54 * DrawDibOpen [MSVFW32.@]
56 HDRAWDIB VFWAPI
DrawDibOpen(void) {
60 hdd
= GlobalAlloc16(GHND
,sizeof(WINE_HDD
));
65 /***********************************************************************
66 * DrawDibOpen [MSVIDEO.102]
68 HDRAWDIB16 VFWAPI
DrawDibOpen16(void) {
69 return (HDRAWDIB16
)DrawDibOpen();
72 /***********************************************************************
73 * DrawDibClose [MSVFW32.@]
75 BOOL VFWAPI
DrawDibClose(HDRAWDIB hdd
) {
76 WINE_HDD
*whdd
= GlobalLock16(hdd
);
78 TRACE("(0x%08lx)\n",(DWORD
)hdd
);
91 /***********************************************************************
92 * DrawDibClose [MSVIDEO.103]
94 BOOL16 VFWAPI
DrawDibClose16(HDRAWDIB16 hdd
) {
95 return DrawDibClose(hdd
);
98 /***********************************************************************
99 * DrawDibEnd [MSVFW32.@]
101 BOOL VFWAPI
DrawDibEnd(HDRAWDIB hdd
) {
103 WINE_HDD
*whdd
= GlobalLock16(hdd
);
105 TRACE("(0x%08lx)\n",(DWORD
)hdd
);
107 whdd
->hpal
= 0; /* Do not free this */
110 HeapFree(GetProcessHeap(),0,whdd
->lpbi
);
114 HeapFree(GetProcessHeap(),0,whdd
->lpbiOut
);
115 whdd
->lpbiOut
= NULL
;
121 HeapFree(GetProcessHeap(),0,whdd->lpvbuf);*/
124 SelectObject(whdd
->hMemDC
,whdd
->hOldDib
);
125 DeleteDC(whdd
->hMemDC
);
129 DeleteObject(whdd
->hDib
);
132 ICDecompressEnd(whdd
->hic
);
136 whdd
->lpvbits
= NULL
;
142 /***********************************************************************
143 * DrawDibEnd [MSVIDEO.105]
145 BOOL16 VFWAPI
DrawDibEnd16(HDRAWDIB16 hdd
) {
146 return DrawDibEnd(hdd
);
149 /***********************************************************************
150 * DrawDibBegin [MSVFW32.@]
152 BOOL VFWAPI
DrawDibBegin(HDRAWDIB hdd
,
156 LPBITMAPINFOHEADER lpbi
,
163 TRACE("(%d,0x%lx,%d,%d,%p,%d,%d,0x%08lx)\n",
164 hdd
,(DWORD
)hdc
,dxDst
,dyDst
,lpbi
,dxSrc
,dySrc
,(DWORD
)wFlags
166 TRACE("lpbi: %ld,%ld/%ld,%d,%d,%ld,%ld,%ld,%ld,%ld,%ld\n",
167 lpbi
->biSize
, lpbi
->biWidth
, lpbi
->biHeight
, lpbi
->biPlanes
,
168 lpbi
->biBitCount
, lpbi
->biCompression
, lpbi
->biSizeImage
,
169 lpbi
->biXPelsPerMeter
, lpbi
->biYPelsPerMeter
, lpbi
->biClrUsed
,
170 lpbi
->biClrImportant
);
172 if (wFlags
& ~(DDF_BUFFER
))
173 FIXME("wFlags == 0x%08x not handled\n", wFlags
& ~(DDF_BUFFER
));
175 whdd
= (WINE_HDD
*)GlobalLock16(hdd
);
176 if (!whdd
) return FALSE
;
181 if (lpbi
->biCompression
) {
184 whdd
->hic
= ICOpen(ICTYPE_VIDEO
,lpbi
->biCompression
,ICMODE_DECOMPRESS
);
186 WARN("Could not open IC. biCompression == 0x%08lx\n",lpbi
->biCompression
);
191 size
= ICDecompressGetFormat(whdd
->hic
,lpbi
,NULL
);
192 if (size
== ICERR_UNSUPPORTED
) {
193 WARN("Codec doesn't support GetFormat, giving up.\n");
199 whdd
->lpbiOut
= HeapAlloc(GetProcessHeap(),0,size
);
201 if (ICDecompressGetFormat(whdd
->hic
,lpbi
,whdd
->lpbiOut
) != ICERR_OK
)
206 /* FIXME: Use Ex functions if available? */
207 if (ICDecompressBegin(whdd
->hic
,lpbi
,whdd
->lpbiOut
) != ICERR_OK
)
210 TRACE("biSizeImage == %ld\n",whdd
->lpbiOut
->biSizeImage
);
211 TRACE("biCompression == %ld\n",whdd
->lpbiOut
->biCompression
);
212 TRACE("biBitCount == %d\n",whdd
->lpbiOut
->biBitCount
);
217 TRACE("Not compressed!\n");
218 dwSize
= lpbi
->biSize
+ lpbi
->biClrUsed
*sizeof(RGBQUAD
);
219 whdd
->lpbiOut
= HeapAlloc(GetProcessHeap(),0,dwSize
);
220 memcpy(whdd
->lpbiOut
,lpbi
,dwSize
);
224 /*whdd->lpvbuf = HeapAlloc(GetProcessHeap(),0,whdd->lpbiOut->biSizeImage);*/
226 whdd
->hMemDC
= CreateCompatibleDC(hdc
);
227 TRACE("Creating: %ld,%p\n",whdd
->lpbiOut
->biSize
,whdd
->lpvbits
);
228 whdd
->hDib
= CreateDIBSection(whdd
->hMemDC
,(BITMAPINFO
*)whdd
->lpbiOut
,DIB_RGB_COLORS
,&(whdd
->lpvbits
),0,0);
230 TRACE("Error: %ld\n",GetLastError());
232 TRACE("Created: %d,%p\n",whdd
->hDib
,whdd
->lpvbits
);
233 whdd
->hOldDib
= SelectObject(whdd
->hMemDC
,whdd
->hDib
);
240 whdd
->lpbi
= HeapAlloc(GetProcessHeap(),0,lpbi
->biSize
);
241 memcpy(whdd
->lpbi
,lpbi
,lpbi
->biSize
);
250 HeapFree(GetProcessHeap(),0,whdd
->lpbiOut
);
251 whdd
->lpbiOut
= NULL
;
260 /************************************************************************
261 * DrawDibBegin [MSVIDEO.104]
263 BOOL16 VFWAPI
DrawDibBegin16(HDRAWDIB16 hdd
,
267 LPBITMAPINFOHEADER lpbi
,
271 return DrawDibBegin(hdd
,hdc
,dxDst
,dyDst
,lpbi
,dxSrc
,dySrc
,wFlags
);
274 /**********************************************************************
275 * DrawDibDraw [MSVFW32.@]
277 BOOL VFWAPI
DrawDibDraw(HDRAWDIB hdd
, HDC hdc
,
278 INT xDst
, INT yDst
, INT dxDst
, INT dyDst
,
279 LPBITMAPINFOHEADER lpbi
,
281 INT xSrc
, INT ySrc
, INT dxSrc
, INT dySrc
,
287 TRACE("(%d,0x%lx,%d,%d,%d,%d,%p,%p,%d,%d,%d,%d,0x%08lx)\n",
288 hdd
,(DWORD
)hdc
,xDst
,yDst
,dxDst
,dyDst
,lpbi
,lpBits
,xSrc
,ySrc
,dxSrc
,dySrc
,(DWORD
)wFlags
291 if (wFlags
& ~(DDF_SAME_HDC
| DDF_SAME_DRAW
| DDF_NOTKEYFRAME
|
292 DDF_UPDATE
| DDF_DONTDRAW
))
293 FIXME("wFlags == 0x%08lx not handled\n",(DWORD
)wFlags
);
297 lpBits
= (LPSTR
)lpbi
+ (WORD
)(lpbi
->biSize
) + (WORD
)(lpbi
->biClrUsed
*sizeof(RGBQUAD
));
300 whdd
= GlobalLock16(hdd
);
302 #define CHANGED(x) (whdd->x != x)
304 if ((!whdd
->begun
) || (!(wFlags
& DDF_SAME_HDC
) && CHANGED(hdc
)) || (!(wFlags
& DDF_SAME_DRAW
) &&
305 (CHANGED(lpbi
) || CHANGED(dxSrc
) || CHANGED(dySrc
) || CHANGED(dxDst
) || CHANGED(dyDst
)))) {
306 TRACE("Something changed!\n");
307 ret
= DrawDibBegin(hdd
,hdc
,dxDst
,dyDst
,lpbi
,dxSrc
,dySrc
,0);
312 if ((dxDst
== -1) && (dyDst
== -1)) {
317 if (!(wFlags
& DDF_UPDATE
)) {
318 /* biSizeImage may be set to 0 for BI_RGB (uncompressed) bitmaps */
319 if ((lpbi
->biCompression
== BI_RGB
) && (lpbi
->biSizeImage
== 0))
320 lpbi
->biSizeImage
= ((lpbi
->biWidth
* lpbi
->biBitCount
+ 31) / 32) * 4 * lpbi
->biHeight
;
322 if (lpbi
->biCompression
) {
325 TRACE("Compression == 0x%08lx\n",lpbi
->biCompression
);
327 if (wFlags
& DDF_NOTKEYFRAME
)
328 flags
|= ICDECOMPRESS_NOTKEYFRAME
;
330 ICDecompress(whdd
->hic
,flags
,lpbi
,lpBits
,whdd
->lpbiOut
,whdd
->lpvbits
);
332 memcpy(whdd
->lpvbits
,lpBits
,lpbi
->biSizeImage
);
335 if (!(wFlags
& DDF_DONTDRAW
) && whdd
->hpal
)
336 SelectPalette(hdc
,whdd
->hpal
,FALSE
);
338 if (!(StretchBlt(whdd
->hdc
,xDst
,yDst
,dxDst
,dyDst
,whdd
->hMemDC
,xSrc
,ySrc
,dxSrc
,dySrc
,SRCCOPY
)))
345 /**********************************************************************
346 * DrawDibDraw [MSVIDEO.106]
348 BOOL16 VFWAPI
DrawDibDraw16(HDRAWDIB16 hdd
,
354 LPBITMAPINFOHEADER lpbi
,
361 return DrawDibDraw(hdd
,hdc
,xDst
,yDst
,dxDst
,dyDst
,lpbi
,lpBits
,xSrc
,ySrc
,dxSrc
,dySrc
,wFlags
);
364 /*************************************************************************
365 * DrawDibStart [MSVFW32.@]
367 BOOL VFWAPI
DrawDibStart(HDRAWDIB hdd
, DWORD rate
) {
368 FIXME("(0x%08lx,%ld), stub\n",(DWORD
)hdd
,rate
);
372 /*************************************************************************
373 * DrawDibStart [MSVIDEO.118]
375 BOOL16 VFWAPI
DrawDibStart16(HDRAWDIB16 hdd
, DWORD rate
) {
376 return DrawDibStart(hdd
,rate
);
379 /*************************************************************************
380 * DrawDibStop [MSVFW32.@]
382 BOOL VFWAPI
DrawDibStop(HDRAWDIB hdd
) {
383 FIXME("(0x%08lx), stub\n",(DWORD
)hdd
);
387 /*************************************************************************
388 * DrawDibStop [MSVIDEO.119]
390 BOOL16
DrawDibStop16(HDRAWDIB16 hdd
) {
391 return DrawDibStop(hdd
);
394 /***********************************************************************
395 * DrawDibSetPalette [MSVFW32.@]
397 BOOL VFWAPI
DrawDibSetPalette(HDRAWDIB hdd
, HPALETTE hpal
) {
400 TRACE("(0x%08lx,0x%08lx)\n",(DWORD
)hdd
,(DWORD
)hpal
);
402 whdd
= GlobalLock16(hdd
);
406 SelectPalette(whdd
->hdc
,hpal
,0);
407 RealizePalette(whdd
->hdc
);
413 /***********************************************************************
414 * DrawDibSetPalette [MSVIDEO.110]
416 BOOL16 VFWAPI
DrawDibSetPalette16(HDRAWDIB16 hdd
, HPALETTE16 hpal
) {
417 return DrawDibSetPalette(hdd
,hpal
);
420 /***********************************************************************
421 * DrawDibGetPalette [MSVFW32.@]
423 HPALETTE VFWAPI
DrawDibGetPalette(HDRAWDIB hdd
) {
427 TRACE("(0x%08lx)\n",(DWORD
)hdd
);
429 whdd
= GlobalLock16(hdd
);
435 /***********************************************************************
436 * DrawDibGetPalette [MSVIDEO.108]
438 HPALETTE16 VFWAPI
DrawDibGetPalette16(HDRAWDIB16 hdd
) {
439 return (HPALETTE16
)DrawDibGetPalette(hdd
);
442 /***********************************************************************
443 * DrawDibRealize [MSVFW32.@]
445 UINT VFWAPI
DrawDibRealize(HDRAWDIB hdd
, HDC hdc
, BOOL fBackground
) {
450 FIXME("(%d,0x%08lx,%d), stub\n",hdd
,(DWORD
)hdc
,fBackground
);
452 whdd
= GlobalLock16(hdd
);
454 if (!whdd
|| !(whdd
->begun
)) {
460 whdd
->hpal
= CreateHalftonePalette(hdc
);
462 oldPal
= SelectPalette(hdc
,whdd
->hpal
,fBackground
);
463 ret
= RealizePalette(hdc
);
468 TRACE("=> %u\n",ret
);
472 /***********************************************************************
473 * DrawDibRealize [MSVIDEO.112]
475 UINT16 VFWAPI
DrawDibRealize16(HDRAWDIB16 hdd
, HDC16 hdc
, BOOL16 fBackground
) {
476 return (UINT16
)DrawDibRealize(hdd
,hdc
,fBackground
);