Fixed wownt32.h to make it usable from inside Wine, and use it to
[wine] / dlls / msvideo / msvideo16.c
1 /*
2  * msvideo 16-bit functions
3  *
4  * Copyright 1998 Marcus Meissner
5  * Copyright 2000 Bradley Baetz
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "winbase.h"
23 #include "windef.h"
24 #include "vfw.h"
25 #include "vfw16.h"
26 #include "stackframe.h"
27 #include "wine/debug.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(msvideo);
30
31 /* handle16 --> handle conversions */
32 #define HDRAWDIB_32(h16)        ((HDRAWDIB)(ULONG_PTR)(h16))
33 #define HIC_32(h16)             ((HIC)(ULONG_PTR)(h16))
34
35 /* handle --> handle16 conversions */
36 #define HDRAWDIB_16(h32)        (LOWORD(h32))
37 #define HIC_16(h32)             (LOWORD(h32))
38
39
40 /***********************************************************************
41  *              DrawDibOpen             [MSVIDEO.102]
42  */
43 HDRAWDIB16 VFWAPI DrawDibOpen16(void)
44 {
45     return HDRAWDIB_16(DrawDibOpen());
46 }
47
48 /***********************************************************************
49  *              DrawDibClose            [MSVIDEO.103]
50  */
51 BOOL16 VFWAPI DrawDibClose16(HDRAWDIB16 hdd)
52 {
53     return DrawDibClose(HDRAWDIB_32(hdd));
54 }
55
56 /************************************************************************
57  *              DrawDibBegin            [MSVIDEO.104]
58  */
59 BOOL16 VFWAPI DrawDibBegin16(HDRAWDIB16 hdd, HDC16 hdc, INT16 dxDst,
60                              INT16 dyDst, LPBITMAPINFOHEADER lpbi, INT16 dxSrc,
61                              INT16 dySrc, UINT16 wFlags)
62 {
63     return DrawDibBegin(HDRAWDIB_32(hdd), HDC_32(hdc), dxDst, dyDst, lpbi,
64                         dxSrc, dySrc, wFlags);
65 }
66
67 /***********************************************************************
68  *              DrawDibEnd              [MSVIDEO.105]
69  */
70 BOOL16 VFWAPI DrawDibEnd16(HDRAWDIB16 hdd)
71 {
72     return DrawDibEnd(HDRAWDIB_32(hdd));
73 }
74
75 /**********************************************************************
76  *              DrawDibDraw             [MSVIDEO.106]
77  */
78 BOOL16 VFWAPI DrawDibDraw16(HDRAWDIB16 hdd, HDC16 hdc, INT16 xDst, INT16 yDst,
79                             INT16 dxDst, INT16 dyDst, LPBITMAPINFOHEADER lpbi,
80                             LPVOID lpBits, INT16 xSrc, INT16 ySrc, INT16 dxSrc,
81                             INT16 dySrc, UINT16 wFlags)
82 {
83     return DrawDibDraw(HDRAWDIB_32(hdd), HDC_32(hdc), xDst, yDst, dxDst,
84                        dyDst, lpbi, lpBits, xSrc, ySrc, dxSrc, dySrc, wFlags);
85 }
86
87 /***********************************************************************
88  *              DrawDibGetPalette       [MSVIDEO.108]
89  */
90 HPALETTE16 VFWAPI DrawDibGetPalette16(HDRAWDIB16 hdd)
91 {
92     return HPALETTE_16(DrawDibGetPalette(HDRAWDIB_32(hdd)));
93 }
94
95 /***********************************************************************
96  *              DrawDibSetPalette       [MSVIDEO.110]
97  */
98 BOOL16 VFWAPI DrawDibSetPalette16(HDRAWDIB16 hdd, HPALETTE16 hpal)
99 {
100     return DrawDibSetPalette(HDRAWDIB_32(hdd), HPALETTE_32(hpal));
101 }
102
103 /***********************************************************************
104  *              DrawDibRealize          [MSVIDEO.112]
105  */
106 UINT16 VFWAPI DrawDibRealize16(HDRAWDIB16 hdd, HDC16 hdc,
107                                BOOL16 fBackground)
108 {
109     return (UINT16) DrawDibRealize(HDRAWDIB_32(hdd), HDC_32(hdc), fBackground);
110 }
111
112 /*************************************************************************
113  *              DrawDibStart            [MSVIDEO.118]
114  */
115 BOOL16 VFWAPI DrawDibStart16(HDRAWDIB16 hdd, DWORD rate)
116 {
117     return DrawDibStart(HDRAWDIB_32(hdd), rate);
118 }
119
120 /*************************************************************************
121  *              DrawDibStop             [MSVIDEO.119]
122  */
123 BOOL16 DrawDibStop16(HDRAWDIB16 hdd)
124 {
125     return DrawDibStop(HDRAWDIB_32(hdd));
126 }
127
128 /***********************************************************************
129  *              ICOpen                          [MSVIDEO.203]
130  */
131 HIC16 VFWAPI ICOpen16(DWORD fccType, DWORD fccHandler, UINT16 wMode)
132 {
133     return HIC_16(ICOpen(fccType, fccHandler, wMode));
134 }
135
136 /***********************************************************************
137  *              ICClose                 [MSVIDEO.204]
138  */
139 LRESULT WINAPI ICClose16(HIC16 hic)
140 {
141     return ICClose(HIC_32(hic));
142 }
143
144 /***********************************************************************
145  *              _ICMessage                      [MSVIDEO.207]
146  */
147 LRESULT VFWAPIV ICMessage16(void)
148 {
149     HIC16 hic;
150     UINT16 msg;
151     UINT16 cb;
152     LPWORD lpData;
153     SEGPTR segData;
154     LRESULT ret;
155     UINT16 i;
156
157     VA_LIST16 valist;
158
159     VA_START16(valist);
160     hic = VA_ARG16(valist, HIC16);
161     msg = VA_ARG16(valist, UINT16);
162     cb = VA_ARG16(valist, UINT16);
163
164     lpData = HeapAlloc(GetProcessHeap(), 0, cb);
165
166     TRACE("0x%08lx, %u, %u, ...)\n", (DWORD) hic, msg, cb);
167
168     for (i = 0; i < cb / sizeof(WORD); i++) {
169         lpData[i] = VA_ARG16(valist, WORD);
170     }
171
172     VA_END16(valist);
173     segData = MapLS(lpData);
174     ret = ICSendMessage16(hic, msg, segData, (DWORD) cb);
175     UnMapLS(segData);
176     HeapFree(GetProcessHeap(), 0, lpData);
177     return ret;
178 }
179
180 /***********************************************************************
181  *              ICGetInfo                       [MSVIDEO.212]
182  */
183 LRESULT VFWAPI ICGetInfo16(HIC16 hic, ICINFO16 * picinfo, DWORD cb)
184 {
185     LRESULT ret;
186
187     TRACE("(0x%08lx,%p,%ld)\n", (DWORD) hic, picinfo, cb);
188     ret = ICSendMessage16(hic, ICM_GETINFO, (DWORD) picinfo, cb);
189     TRACE("     -> 0x%08lx\n", ret);
190     return ret;
191 }
192
193 /***********************************************************************
194  *              ICLocate                        [MSVIDEO.213]
195  */
196 HIC16 VFWAPI ICLocate16(DWORD fccType, DWORD fccHandler,
197                         LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut,
198                         WORD wFlags)
199 {
200     return HIC_16(ICLocate(fccType, fccHandler, lpbiIn, lpbiOut, wFlags));
201 }
202
203 /***********************************************************************
204  *              _ICCompress                     [MSVIDEO.224]
205  */
206 DWORD VFWAPIV ICCompress16(HIC16 hic, DWORD dwFlags,
207                            LPBITMAPINFOHEADER lpbiOutput, LPVOID lpData,
208                            LPBITMAPINFOHEADER lpbiInput, LPVOID lpBits,
209                            LPDWORD lpckid, LPDWORD lpdwFlags,
210                            LONG lFrameNum, DWORD dwFrameSize,
211                            DWORD dwQuality, LPBITMAPINFOHEADER lpbiPrev,
212                            LPVOID lpPrev)
213 {
214
215     DWORD ret;
216     ICCOMPRESS iccmp;
217     SEGPTR seg_iccmp;
218
219     TRACE("(0x%08lx,%ld,%p,%p,%p,%p,...)\n", (DWORD) hic, dwFlags,
220           lpbiOutput, lpData, lpbiInput, lpBits);
221
222     iccmp.dwFlags = dwFlags;
223
224     iccmp.lpbiOutput = lpbiOutput;
225     iccmp.lpOutput = lpData;
226     iccmp.lpbiInput = lpbiInput;
227     iccmp.lpInput = lpBits;
228
229     iccmp.lpckid = lpckid;
230     iccmp.lpdwFlags = lpdwFlags;
231     iccmp.lFrameNum = lFrameNum;
232     iccmp.dwFrameSize = dwFrameSize;
233     iccmp.dwQuality = dwQuality;
234     iccmp.lpbiPrev = lpbiPrev;
235     iccmp.lpPrev = lpPrev;
236     seg_iccmp = MapLS(&iccmp);
237     ret = ICSendMessage16(hic, ICM_COMPRESS, seg_iccmp, sizeof(ICCOMPRESS));
238     UnMapLS(seg_iccmp);
239     return ret;
240 }
241
242 /***********************************************************************
243  *              _ICDecompress                   [MSVIDEO.230]
244  */
245 DWORD VFWAPIV ICDecompress16(HIC16 hic, DWORD dwFlags,
246                              LPBITMAPINFOHEADER lpbiFormat, LPVOID lpData,
247                              LPBITMAPINFOHEADER lpbi, LPVOID lpBits)
248 {
249     ICDECOMPRESS icd;
250     SEGPTR segptr;
251     DWORD ret;
252
253     TRACE("(0x%08lx,%ld,%p,%p,%p,%p)\n", (DWORD) hic, dwFlags, lpbiFormat,
254           lpData, lpbi, lpBits);
255
256     icd.dwFlags = dwFlags;
257     icd.lpbiInput = lpbiFormat;
258     icd.lpInput = lpData;
259     icd.lpbiOutput = lpbi;
260     icd.lpOutput = lpBits;
261     icd.ckid = 0;
262     segptr = MapLS(&icd);
263     ret = ICSendMessage16(hic, ICM_DECOMPRESS, segptr, sizeof(ICDECOMPRESS));
264     UnMapLS(segptr);
265     return ret;
266 }
267
268 /***********************************************************************
269  *              _ICDrawBegin            [MSVIDEO.232]
270  */
271 DWORD VFWAPIV ICDrawBegin16(HIC16 hic,          /* [in] */
272                             DWORD dwFlags,      /* [in] flags */
273                             HPALETTE16 hpal,    /* [in] palette to draw with */
274                             HWND16 hwnd,        /* [in] window to draw to */
275                             HDC16 hdc,          /* [in] HDC to draw to */
276                             INT16 xDst,         /* [in] destination rectangle */
277                             INT16 yDst,         /* [in] */
278                             INT16 dxDst,        /* [in] */
279                             INT16 dyDst,        /* [in] */
280                             LPBITMAPINFOHEADER lpbi,    /* [in] format of frame to draw NOTE: SEGPTR */
281                             INT16 xSrc,         /* [in] source rectangle */
282                             INT16 ySrc,         /* [in] */
283                             INT16 dxSrc,        /* [in] */
284                             INT16 dySrc,        /* [in] */
285                             DWORD dwRate,       /* [in] frames/second = (dwRate/dwScale) */
286                             DWORD dwScale)      /* [in] */
287 {
288     DWORD ret;
289     ICDRAWBEGIN16 icdb;
290     SEGPTR seg_icdb;
291
292     TRACE ("(0x%08lx,%ld,0x%08lx,0x%08lx,0x%08lx,%u,%u,%u,%u,%p,%u,%u,%u,%u,%ld,%ld)\n",
293            (DWORD) hic, dwFlags, (DWORD) hpal, (DWORD) hwnd, (DWORD) hdc,
294            xDst, yDst, dxDst, dyDst, lpbi, xSrc, ySrc, dxSrc, dySrc, dwRate,
295            dwScale);
296
297     icdb.dwFlags = dwFlags;
298     icdb.hpal = hpal;
299     icdb.hwnd = hwnd;
300     icdb.hdc = hdc;
301     icdb.xDst = xDst;
302     icdb.yDst = yDst;
303     icdb.dxDst = dxDst;
304     icdb.dyDst = dyDst;
305     icdb.lpbi = lpbi;           /* Keep this as SEGPTR for the mapping code to deal with */
306     icdb.xSrc = xSrc;
307     icdb.ySrc = ySrc;
308     icdb.dxSrc = dxSrc;
309     icdb.dySrc = dySrc;
310     icdb.dwRate = dwRate;
311     icdb.dwScale = dwScale;
312     seg_icdb = MapLS(&icdb);
313     ret = (DWORD) ICSendMessage16(hic, ICM_DRAW_BEGIN, seg_icdb,
314                                   sizeof(ICDRAWBEGIN16));
315     UnMapLS(seg_icdb);
316     return ret;
317 }
318
319 /***********************************************************************
320  *              _ICDraw                 [MSVIDEO.234]
321  */
322 DWORD VFWAPIV ICDraw16(HIC16 hic, DWORD dwFlags,
323                        LPVOID lpFormat, /* [???] NOTE: SEGPTR */
324                        LPVOID lpData,   /* [???] NOTE: SEGPTR */
325                        DWORD cbData, LONG lTime)
326 {
327     DWORD ret;
328     ICDRAW icd;
329     SEGPTR seg_icd;
330
331     TRACE("(0x%08lx,0x%08lx,%p,%p,%ld,%ld)\n", (DWORD) hic, dwFlags,
332           lpFormat, lpData, cbData, lTime);
333     icd.dwFlags = dwFlags;
334     icd.lpFormat = lpFormat;
335     icd.lpData = lpData;
336     icd.cbData = cbData;
337     icd.lTime = lTime;
338     seg_icd = MapLS(&icd);
339     ret = ICSendMessage16(hic, ICM_DRAW, seg_icd, sizeof(ICDRAW));
340     UnMapLS(seg_icd);
341     return ret;
342 }
343
344 /***********************************************************************
345  *              ICGetDisplayFormat                      [MSVIDEO.239]
346  */
347 HIC16 VFWAPI ICGetDisplayFormat16(HIC16 hic, LPBITMAPINFOHEADER lpbiIn,
348                                   LPBITMAPINFOHEADER lpbiOut, INT16 depth,
349                                   INT16 dx, INT16 dy)
350 {
351     return HIC_16(ICGetDisplayFormat(HIC_32(hic), lpbiIn, lpbiOut, depth,
352                                      dx, dy));
353 }