push b71aec5de911a58dd53fad5cd398b45da52121ed
[wine/hacks.git] / dlls / wing.dll16 / wing.c
blob750c8daec0415da38575ea2f848ae1325ac63028
1 /*
2 * WinG support
4 * Copyright (C) Robert Pouliot <krynos@clic.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "wownt32.h"
29 #include "wine/wingdi16.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wing);
34 /*************************************************************************
35 * WING {WING}
37 * The Windows Game dll provides a number of functions designed to allow
38 * programmers to bypass Gdi and write directly to video memory. The intention
39 * was to bolster the use of Windows as a gaming platform and remove the
40 * need for Dos based games using 32 bit Dos extenders.
42 * This initial approach could not compete with the performance of Dos games
43 * (such as Doom and Warcraft) at the time, and so this dll was eventually
44 * superseded by DirectX. It should not be used by new applications, and is
45 * provided only for compatibility with older Windows programs.
48 typedef enum WING_DITHER_TYPE
50 WING_DISPERSED_4x4, WING_DISPERSED_8x8, WING_CLUSTERED_4x4
51 } WING_DITHER_TYPE;
53 /***********************************************************************
54 * WinGCreateDC (WING.1001)
56 * Create a new WinG device context.
58 * PARAMS
59 * None.
61 * RETURNS
62 * Success: A handle to the created device context.
63 * Failure: A NULL handle.
65 HDC16 WINAPI WinGCreateDC16(void)
67 TRACE("(void)\n");
68 return HDC_16( CreateCompatibleDC( 0 ));
71 /***********************************************************************
72 * WinGRecommendDIBFormat (WING.1002)
74 * Get the recommended format of bitmaps for the current display.
76 * PARAMS
77 * bmpi [O] Destination for format information
79 * RETURNS
80 * Success: TRUE. bmpi is filled with the best (fastest) bitmap format
81 * Failure: FALSE, if bmpi is NULL.
83 BOOL16 WINAPI WinGRecommendDIBFormat16(BITMAPINFO *bmpi)
85 TRACE("(%p)\n", bmpi);
87 if (!bmpi)
88 return FALSE;
90 bmpi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
91 bmpi->bmiHeader.biWidth = 320;
92 bmpi->bmiHeader.biHeight = -1;
93 bmpi->bmiHeader.biPlanes = 1;
94 bmpi->bmiHeader.biBitCount = 8;
95 bmpi->bmiHeader.biCompression = BI_RGB;
96 bmpi->bmiHeader.biSizeImage = 0;
97 bmpi->bmiHeader.biXPelsPerMeter = 0;
98 bmpi->bmiHeader.biYPelsPerMeter = 0;
99 bmpi->bmiHeader.biClrUsed = 0;
100 bmpi->bmiHeader.biClrImportant = 0;
102 return TRUE;
105 /***********************************************************************
106 * WinGCreateBitmap (WING.1003)
108 * Create a new WinG bitmap.
110 * PARAMS
111 * hdc [I] WinG device context
112 * bmpi [I] Information about the bitmap
113 * bits [I] Location of the bitmap image data
115 * RETURNS
116 * Success: A handle to the created bitmap.
117 * Failure: A NULL handle.
119 HBITMAP16 WINAPI WinGCreateBitmap16(HDC16 hdc, BITMAPINFO *bmpi, SEGPTR *bits)
121 LPVOID bits32;
122 HBITMAP hbitmap;
124 TRACE("(%d,%p,%p): create %dx%dx%d bitmap\n", hdc, bmpi, bits,
125 bmpi->bmiHeader.biWidth, bmpi->bmiHeader.biHeight, bmpi->bmiHeader.biPlanes);
127 hbitmap = CreateDIBSection( HDC_32(hdc), bmpi, BI_RGB, &bits32, 0, 0 );
128 if (hbitmap)
130 DIBSECTION dib;
131 DWORD size;
132 WORD count, sel;
133 int i;
135 GetObjectW( hbitmap, sizeof(dib), &dib );
136 size = dib.dsBm.bmHeight * dib.dsBm.bmWidthBytes;
138 /* calculate number of sel's needed for size with 64K steps */
139 count = (size + 0xffff) / 0x10000;
140 sel = AllocSelectorArray16(count);
142 for (i = 0; i < count; i++)
144 SetSelectorBase(sel + (i << __AHSHIFT), (DWORD)bits32 + i * 0x10000);
145 SetSelectorLimit16(sel + (i << __AHSHIFT), size - 1); /* yep, limit is correct */
146 size -= 0x10000;
148 if (bits) *bits = MAKESEGPTR( sel, 0 );
150 return HBITMAP_16(hbitmap);
153 /***********************************************************************
154 * WinGGetDIBPointer (WING.1004)
156 SEGPTR WINAPI WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
158 FIXME("%x, %p: not supported\n", hWinGBitmap, bmpi );
159 return 0;
162 /***********************************************************************
163 * WinGSetDIBColorTable (WING.1006)
165 * Set all or part of the color table for a WinG device context.
167 * PARAMS
168 * hdc [I] WinG device context
169 * start [I] Start color
170 * num [I] Number of entries to set
171 * colors [I] Array of color data
173 * RETURNS
174 * The number of entries set.
176 UINT16 WINAPI WinGSetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
178 TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
179 return SetDIBColorTable( HDC_32(hdc), start, num, colors );
182 /***********************************************************************
183 * WinGGetDIBColorTable (WING.1005)
185 * Get all or part of the color table for a WinG device context.
187 * PARAMS
188 * hdc [I] WinG device context
189 * start [I] Start color
190 * num [I] Number of entries to set
191 * colors [O] Destination for the array of color data
193 * RETURNS
194 * The number of entries retrieved.
196 UINT16 WINAPI WinGGetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
198 TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
199 return GetDIBColorTable( HDC_32(hdc), start, num, colors );
202 /***********************************************************************
203 * WinGCreateHalfTonePalette (WING.1007)
205 * Create a half tone palette.
207 * PARAMS
208 * None.
210 * RETURNS
211 * Success: A handle to the created palette.
212 * Failure: A NULL handle.
214 HPALETTE16 WINAPI WinGCreateHalfTonePalette16(void)
216 HDC hdc = CreateCompatibleDC(0);
217 HPALETTE16 ret = HPALETTE_16( CreateHalftonePalette( hdc ));
218 TRACE("(void)\n");
219 DeleteDC( hdc );
220 return ret;
223 /***********************************************************************
224 * WinGCreateHalfToneBrush (WING.1008)
226 * Create a half tone brush for a WinG device context.
228 * PARAMS
229 * winDC [I] WinG device context
230 * col [I] Color
231 * type [I] Desired dithering type.
233 * RETURNS
234 * Success: A handle to the created brush.
235 * Failure: A NULL handle.
237 HBRUSH16 WINAPI WinGCreateHalfToneBrush16(HDC16 winDC, COLORREF col,
238 WING_DITHER_TYPE type)
240 TRACE("(%d,%d,%d)\n", winDC, col, type);
241 return HBRUSH_16( CreateSolidBrush( col ));
244 /***********************************************************************
245 * WinGStretchBlt (WING.1009)
247 * See StretchBlt16.
249 BOOL16 WINAPI WinGStretchBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
250 INT16 widDest, INT16 heiDest,
251 HDC16 srcDC, INT16 xSrc, INT16 ySrc,
252 INT16 widSrc, INT16 heiSrc)
254 BOOL retval;
255 TRACE("(%d,%d,...)\n", destDC, srcDC);
256 SetStretchBltMode( HDC_32(destDC), COLORONCOLOR );
257 retval = StretchBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest,
258 HDC_32(srcDC), xSrc, ySrc, widSrc, heiSrc, SRCCOPY );
259 SetStretchBltMode( HDC_32(destDC), BLACKONWHITE );
260 return retval;
263 /***********************************************************************
264 * WinGBitBlt (WING.1010)
266 * See BitBlt16.
268 BOOL16 WINAPI WinGBitBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
269 INT16 widDest, INT16 heiDest, HDC16 srcDC,
270 INT16 xSrc, INT16 ySrc)
272 TRACE("(%d,%d,...)\n", destDC, srcDC);
273 return BitBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest, HDC_32(srcDC), xSrc, ySrc, SRCCOPY );