source: trunk/src/msvfw32/drawdib.c@ 6712

Last change on this file since 6712 was 6712, checked in by sandervl, 24 years ago

restored old version

File size: 12.1 KB
Line 
1/*
2 * Copyright 2000 Bradley Baetz
3 *
4 * Fixme: Some flags are ignored
5 *
6 * Handle palettes
7 */
8
9#include <string.h>
10#include "windef.h"
11#include "winbase.h"
12#include "wingdi.h"
13#include "winuser.h"
14#include "wine/winbase16.h"
15#include "debugtools.h"
16#include "vfw.h"
17#include "vfw16.h"
18#include "windef.h"
19
20DEFAULT_DEBUG_CHANNEL(msvideo);
21
22typedef struct {
23 HDC hdc;
24 INT dxDst;
25 INT dyDst;
26 LPBITMAPINFOHEADER lpbi;
27 INT dxSrc;
28 INT dySrc;
29 HPALETTE hpal; /* Palette to use for the DIB */
30 BOOL begun; /* DrawDibBegin has been called */
31 LPBITMAPINFOHEADER lpbiOut; /* Output format */
32 HIC hic; /* HIC for decompression */
33 HDC hMemDC; /* DC for buffering */
34 HBITMAP hOldDib; /* Original Dib */
35 HBITMAP hDib; /* DibSection */
36 LPVOID lpvbits; /* Buffer for holding decompressed dib */
37} WINE_HDD;
38
39#ifdef __WIN32OS2__
40#include <heapstring.h>
41
42#define GlobalAlloc16 GlobalAlloc
43#define GlobalLock16 GlobalLock
44#define GlobalUnlock16 GlobalUnlock
45#define GlobalFree16 GlobalFree
46
47#undef FIXME
48#undef TRACE
49#ifdef DEBUG
50#define TRACE WriteLog("MSVFW32: %s", __FUNCTION__); WriteLog
51#define FIXME WriteLog("FIXME MSVFW32: %s", __FUNCTION__); WriteLog
52#else
53#define TRACE 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
54#define FIXME 1 ? (void)0 : (void)((int (*)(char *, ...)) NULL)
55#endif
56
57#endif
58
59/***********************************************************************
60 * DrawDibOpen [MSVFW32.@]
61 */
62HDRAWDIB VFWAPI DrawDibOpen(void) {
63 HDRAWDIB hdd;
64
65 TRACE("(void)\n");
66 hdd = GlobalAlloc16(GHND,sizeof(WINE_HDD));
67 TRACE("=> %d\n",hdd);
68 return hdd;
69}
70
71/***********************************************************************
72 * DrawDibOpen [MSVIDEO.102]
73 */
74HDRAWDIB16 VFWAPI DrawDibOpen16(void) {
75 return (HDRAWDIB16)DrawDibOpen();
76}
77
78/***********************************************************************
79 * DrawDibClose [MSVFW32.@]
80 */
81BOOL VFWAPI DrawDibClose(HDRAWDIB hdd) {
82 WINE_HDD *whdd = GlobalLock16(hdd);
83
84 TRACE("(0x%08lx)\n",(DWORD)hdd);
85
86 if (!whdd)
87 return FALSE;
88
89 if (whdd->begun)
90 DrawDibEnd(hdd);
91
92 GlobalUnlock16(hdd);
93 GlobalFree16(hdd);
94 return TRUE;
95}
96
97/***********************************************************************
98 * DrawDibClose [MSVIDEO.103]
99 */
100BOOL16 VFWAPI DrawDibClose16(HDRAWDIB16 hdd) {
101 return DrawDibClose(hdd);
102}
103
104/***********************************************************************
105 * DrawDibEnd [MSVFW32.@]
106 */
107BOOL VFWAPI DrawDibEnd(HDRAWDIB hdd) {
108 BOOL ret = TRUE;
109 WINE_HDD *whdd = GlobalLock16(hdd);
110
111 TRACE("(0x%08lx)\n",(DWORD)hdd);
112
113 whdd->hpal = 0; /* Do not free this */
114 whdd->hdc = 0;
115 if (whdd->lpbi) {
116 HeapFree(GetProcessHeap(),0,whdd->lpbi);
117 whdd->lpbi = NULL;
118 }
119 if (whdd->lpbiOut) {
120 HeapFree(GetProcessHeap(),0,whdd->lpbiOut);
121 whdd->lpbiOut = NULL;
122 }
123
124 whdd->begun = FALSE;
125
126 /*if (whdd->lpvbits)
127 HeapFree(GetProcessHeap(),0,whdd->lpvbuf);*/
128
129 if (whdd->hMemDC) {
130 SelectObject(whdd->hMemDC,whdd->hOldDib);
131 DeleteDC(whdd->hMemDC);
132 }
133
134 if (whdd->hDib)
135 DeleteObject(whdd->hDib);
136
137 if (whdd->hic) {
138 ICDecompressEnd(whdd->hic);
139 ICClose(whdd->hic);
140 }
141
142 whdd->lpvbits = NULL;
143
144 GlobalUnlock16(hdd);
145 return ret;
146}
147
148/***********************************************************************
149 * DrawDibEnd [MSVIDEO.105]
150 */
151BOOL16 VFWAPI DrawDibEnd16(HDRAWDIB16 hdd) {
152 return DrawDibEnd(hdd);
153}
154
155/***********************************************************************
156 * DrawDibBegin [MSVFW32.@]
157 */
158BOOL VFWAPI DrawDibBegin(HDRAWDIB hdd,
159 HDC hdc,
160 INT dxDst,
161 INT dyDst,
162 LPBITMAPINFOHEADER lpbi,
163 INT dxSrc,
164 INT dySrc,
165 UINT wFlags) {
166 BOOL ret = TRUE;
167 WINE_HDD *whdd;
168
169 TRACE("(%d,0x%lx,%d,%d,%p,%d,%d,0x%08lx)\n",
170 hdd,(DWORD)hdc,dxDst,dyDst,lpbi,dxSrc,dySrc,(DWORD)wFlags
171 );
172 TRACE("lpbi: %ld,%ld/%ld,%d,%d,%ld,%ld,%ld,%ld,%ld,%ld\n",
173 lpbi->biSize, lpbi->biWidth, lpbi->biHeight, lpbi->biPlanes,
174 lpbi->biBitCount, lpbi->biCompression, lpbi->biSizeImage,
175 lpbi->biXPelsPerMeter, lpbi->biYPelsPerMeter, lpbi->biClrUsed,
176 lpbi->biClrImportant);
177
178 if (wFlags & ~(DDF_BUFFER))
179 FIXME("wFlags == 0x%08x not handled\n", wFlags & ~(DDF_BUFFER));
180
181 whdd = (WINE_HDD*)GlobalLock16(hdd);
182 if (!whdd) return FALSE;
183
184 if (whdd->begun)
185 DrawDibEnd(hdd);
186
187 if (lpbi->biCompression) {
188 DWORD size = 0;
189
190 whdd->hic = ICOpen(ICTYPE_VIDEO,lpbi->biCompression,ICMODE_DECOMPRESS);
191 if (!whdd->hic) {
192 WARN("Could not open IC. biCompression == 0x%08lx\n",lpbi->biCompression);
193 ret = FALSE;
194 }
195
196 if (ret) {
197 size = ICDecompressGetFormat(whdd->hic,lpbi,NULL);
198 if (size == ICERR_UNSUPPORTED) {
199 WARN("Codec doesn't support GetFormat, giving up.\n");
200 ret = FALSE;
201 }
202 }
203
204 if (ret) {
205 whdd->lpbiOut = HeapAlloc(GetProcessHeap(),0,size);
206
207 if (ICDecompressGetFormat(whdd->hic,lpbi,whdd->lpbiOut) != ICERR_OK)
208 ret = FALSE;
209 }
210
211 if (ret) {
212 /* FIXME: Use Ex functions if available? */
213 if (ICDecompressBegin(whdd->hic,lpbi,whdd->lpbiOut) != ICERR_OK)
214 ret = FALSE;
215
216 TRACE("biSizeImage == %ld\n",whdd->lpbiOut->biSizeImage);
217 TRACE("biCompression == %ld\n",whdd->lpbiOut->biCompression);
218 TRACE("biBitCount == %d\n",whdd->lpbiOut->biBitCount);
219 }
220 } else {
221 DWORD dwSize;
222 /* No compression */
223 TRACE("Not compressed!\n");
224 dwSize = lpbi->biSize + lpbi->biClrUsed*sizeof(RGBQUAD);
225 whdd->lpbiOut = HeapAlloc(GetProcessHeap(),0,dwSize);
226 memcpy(whdd->lpbiOut,lpbi,dwSize);
227 }
228
229 if (ret) {
230 /*whdd->lpvbuf = HeapAlloc(GetProcessHeap(),0,whdd->lpbiOut->biSizeImage);*/
231
232 whdd->hMemDC = CreateCompatibleDC(hdc);
233 TRACE("Creating: %ld,%p\n",whdd->lpbiOut->biSize,whdd->lpvbits);
234 whdd->hDib = CreateDIBSection(whdd->hMemDC,(BITMAPINFO *)whdd->lpbiOut,DIB_RGB_COLORS,&(whdd->lpvbits),0,0);
235 if (!whdd->hDib) {
236 TRACE("Error: %ld\n",GetLastError());
237 }
238 TRACE("Created: %d,%p\n",whdd->hDib,whdd->lpvbits);
239 whdd->hOldDib = SelectObject(whdd->hMemDC,whdd->hDib);
240 }
241
242 if (ret) {
243 whdd->hdc = hdc;
244 whdd->dxDst = dxDst;
245 whdd->dyDst = dyDst;
246 whdd->lpbi = HeapAlloc(GetProcessHeap(),0,lpbi->biSize);
247 memcpy(whdd->lpbi,lpbi,lpbi->biSize);
248 whdd->dxSrc = dxSrc;
249 whdd->dySrc = dySrc;
250 whdd->begun = TRUE;
251 whdd->hpal = 0;
252 } else {
253 if (whdd->hic)
254 ICClose(whdd->hic);
255 if (whdd->lpbiOut) {
256 HeapFree(GetProcessHeap(),0,whdd->lpbiOut);
257 whdd->lpbiOut = NULL;
258 }
259 }
260
261 GlobalUnlock16(hdd);
262
263 return ret;
264}
265
266/************************************************************************
267 * DrawDibBegin [MSVIDEO.104]
268 */
269BOOL16 VFWAPI DrawDibBegin16(HDRAWDIB16 hdd,
270 HDC16 hdc,
271 INT16 dxDst,
272 INT16 dyDst,
273 LPBITMAPINFOHEADER lpbi,
274 INT16 dxSrc,
275 INT16 dySrc,
276 UINT16 wFlags) {
277 return DrawDibBegin(hdd,hdc,dxDst,dyDst,lpbi,dxSrc,dySrc,wFlags);
278}
279
280/**********************************************************************
281 * DrawDibDraw [MSVFW32.@]
282 */
283BOOL VFWAPI DrawDibDraw(HDRAWDIB hdd, HDC hdc,
284 INT xDst, INT yDst, INT dxDst, INT dyDst,
285 LPBITMAPINFOHEADER lpbi,
286 LPVOID lpBits,
287 INT xSrc, INT ySrc, INT dxSrc, INT dySrc,
288 UINT wFlags
289) {
290 WINE_HDD *whdd;
291 BOOL ret = TRUE;
292
293 TRACE("(%d,0x%lx,%d,%d,%d,%d,%p,%p,%d,%d,%d,%d,0x%08lx)\n",
294 hdd,(DWORD)hdc,xDst,yDst,dxDst,dyDst,lpbi,lpBits,xSrc,ySrc,dxSrc,dySrc,(DWORD)wFlags
295 );
296
297 if (wFlags & ~(DDF_SAME_HDC | DDF_SAME_DRAW | DDF_NOTKEYFRAME |
298 DDF_UPDATE | DDF_DONTDRAW))
299 FIXME("wFlags == 0x%08lx not handled\n",(DWORD)wFlags);
300
301 if (!lpBits) {
302 /* Undocumented? */
303 lpBits = (LPSTR)lpbi + (WORD)(lpbi->biSize) + (WORD)(lpbi->biClrUsed*sizeof(RGBQUAD));
304 }
305
306 whdd = GlobalLock16(hdd);
307
308#define CHANGED(x) (whdd->x != x)
309
310 if ((!whdd->begun) || (!(wFlags & DDF_SAME_HDC) && CHANGED(hdc)) || (!(wFlags & DDF_SAME_DRAW) &&
311 (CHANGED(lpbi) || CHANGED(dxSrc) || CHANGED(dySrc) || CHANGED(dxDst) || CHANGED(dyDst)))) {
312 TRACE("Something changed!\n");
313 ret = DrawDibBegin(hdd,hdc,dxDst,dyDst,lpbi,dxSrc,dySrc,0);
314 }
315
316#undef CHANGED
317
318 if ((dxDst == -1) && (dyDst == -1)) {
319 dxDst = dxSrc;
320 dyDst = dySrc;
321 }
322
323 if (!(wFlags & DDF_UPDATE)) {
324 /* biSizeImage may be set to 0 for BI_RGB (uncompressed) bitmaps */
325 if ((lpbi->biCompression == BI_RGB) && (lpbi->biSizeImage == 0))
326 lpbi->biSizeImage = ((lpbi->biWidth * lpbi->biBitCount + 31) / 32) * 4 * lpbi->biHeight;
327
328 if (lpbi->biCompression) {
329 DWORD flags = 0;
330
331 TRACE("Compression == 0x%08lx\n",lpbi->biCompression);
332
333 if (wFlags & DDF_NOTKEYFRAME)
334 flags |= ICDECOMPRESS_NOTKEYFRAME;
335
336 ICDecompress(whdd->hic,flags,lpbi,lpBits,whdd->lpbiOut,whdd->lpvbits);
337 } else {
338 memcpy(whdd->lpvbits,lpBits,lpbi->biSizeImage);
339 }
340 }
341 if (!(wFlags & DDF_DONTDRAW) && whdd->hpal)
342 SelectPalette(hdc,whdd->hpal,FALSE);
343
344 if (!(StretchBlt(whdd->hdc,xDst,yDst,dxDst,dyDst,whdd->hMemDC,xSrc,ySrc,dxSrc,dySrc,SRCCOPY)))
345 ret = FALSE;
346
347 GlobalUnlock16(hdd);
348 return ret;
349}
350
351/**********************************************************************
352 * DrawDibDraw [MSVIDEO.106]
353 */
354BOOL16 VFWAPI DrawDibDraw16(HDRAWDIB16 hdd,
355 HDC16 hdc,
356 INT16 xDst,
357 INT16 yDst,
358 INT16 dxDst,
359 INT16 dyDst,
360 LPBITMAPINFOHEADER lpbi,
361 LPVOID lpBits,
362 INT16 xSrc,
363 INT16 ySrc,
364 INT16 dxSrc,
365 INT16 dySrc,
366 UINT16 wFlags) {
367 return DrawDibDraw(hdd,hdc,xDst,yDst,dxDst,dyDst,lpbi,lpBits,xSrc,ySrc,dxSrc,dySrc,wFlags);
368}
369
370/*************************************************************************
371 * DrawDibStart [MSVFW32.@]
372 */
373BOOL VFWAPI DrawDibStart(HDRAWDIB hdd, DWORD rate) {
374 FIXME("(0x%08lx,%ld), stub\n",(DWORD)hdd,rate);
375 return TRUE;
376}
377
378/*************************************************************************
379 * DrawDibStart [MSVIDEO.118]
380 */
381BOOL16 VFWAPI DrawDibStart16(HDRAWDIB16 hdd, DWORD rate) {
382 return DrawDibStart(hdd,rate);
383}
384
385/*************************************************************************
386 * DrawDibStop [MSVFW32.@]
387 */
388BOOL VFWAPI DrawDibStop(HDRAWDIB hdd) {
389 FIXME("(0x%08lx), stub\n",(DWORD)hdd);
390 return TRUE;
391}
392
393/*************************************************************************
394 * DrawDibStop [MSVIDEO.119]
395 */
396BOOL16 DrawDibStop16(HDRAWDIB16 hdd) {
397 return DrawDibStop(hdd);
398}
399
400/***********************************************************************
401 * DrawDibSetPalette [MSVFW32.@]
402 */
403BOOL VFWAPI DrawDibSetPalette(HDRAWDIB hdd, HPALETTE hpal) {
404 WINE_HDD *whdd;
405
406 TRACE("(0x%08lx,0x%08lx)\n",(DWORD)hdd,(DWORD)hpal);
407
408 whdd = GlobalLock16(hdd);
409 whdd->hpal = hpal;
410
411 if (whdd->begun) {
412 SelectPalette(whdd->hdc,hpal,0);
413 RealizePalette(whdd->hdc);
414 }
415 GlobalUnlock16(hdd);
416 return TRUE;
417}
418
419/***********************************************************************
420 * DrawDibSetPalette [MSVIDEO.110]
421 */
422BOOL16 VFWAPI DrawDibSetPalette16(HDRAWDIB16 hdd, HPALETTE16 hpal) {
423 return DrawDibSetPalette(hdd,hpal);
424}
425
426/***********************************************************************
427 * DrawDibGetPalette [MSVFW32.@]
428 */
429HPALETTE VFWAPI DrawDibGetPalette(HDRAWDIB hdd) {
430 WINE_HDD *whdd;
431 HPALETTE ret;
432
433 TRACE("(0x%08lx)\n",(DWORD)hdd);
434
435 whdd = GlobalLock16(hdd);
436 ret = whdd->hpal;
437 GlobalUnlock16(hdd);
438 return ret;
439}
440
441/***********************************************************************
442 * DrawDibGetPalette [MSVIDEO.108]
443 */
444HPALETTE16 VFWAPI DrawDibGetPalette16(HDRAWDIB16 hdd) {
445 return (HPALETTE16)DrawDibGetPalette(hdd);
446}
447
448/***********************************************************************
449 * DrawDibRealize [MSVFW32.@]
450 */
451UINT VFWAPI DrawDibRealize(HDRAWDIB hdd, HDC hdc, BOOL fBackground) {
452 WINE_HDD *whdd;
453 HPALETTE oldPal;
454 UINT ret = 0;
455
456 FIXME("(%d,0x%08lx,%d), stub\n",hdd,(DWORD)hdc,fBackground);
457
458 whdd = GlobalLock16(hdd);
459
460 if (!whdd || !(whdd->begun)) {
461 ret = 0;
462 goto out;
463 }
464
465 if (!whdd->hpal)
466 whdd->hpal = CreateHalftonePalette(hdc);
467
468 oldPal = SelectPalette(hdc,whdd->hpal,fBackground);
469 ret = RealizePalette(hdc);
470
471 out:
472 GlobalUnlock16(hdd);
473
474 TRACE("=> %u\n",ret);
475 return ret;
476}
477
478/***********************************************************************
479 * DrawDibRealize [MSVIDEO.112]
480 */
481UINT16 VFWAPI DrawDibRealize16(HDRAWDIB16 hdd, HDC16 hdc, BOOL16 fBackground) {
482 return (UINT16)DrawDibRealize(hdd,hdc,fBackground);
483}
Note: See TracBrowser for help on using the repository browser.