widl: Strip last separator in append_namespaces if suffix is NULL.
[wine.git] / dlls / wing.dll16 / wing.c
blob98cee5654051eed3a38d83791be667f0a864f9c8
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 <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "wownt32.h"
27 #include "wine/wingdi16.h"
28 #include "wine/list.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wing);
33 struct dib_segptr_bits
35 struct list entry;
36 HBITMAP bmp;
37 WORD sel;
38 WORD count;
41 static struct list dib_segptr_list = LIST_INIT( dib_segptr_list );
43 /* remove saved bits for bitmaps that no longer exist */
44 static void cleanup_segptr_bits(void)
46 unsigned int i;
47 struct dib_segptr_bits *bits, *next;
49 LIST_FOR_EACH_ENTRY_SAFE( bits, next, &dib_segptr_list, struct dib_segptr_bits, entry )
51 if (GetObjectType( bits->bmp ) == OBJ_BITMAP) continue;
52 for (i = 0; i < bits->count; i++) FreeSelector16( bits->sel + (i << __AHSHIFT) );
53 list_remove( &bits->entry );
54 HeapFree( GetProcessHeap(), 0, bits );
58 static SEGPTR alloc_segptr_bits( HBITMAP bmp, void *bits32 )
60 DIBSECTION dib;
61 unsigned int i, size;
62 struct dib_segptr_bits *bits;
64 cleanup_segptr_bits();
66 if (!(bits = HeapAlloc( GetProcessHeap(), 0, sizeof(*bits) ))) return 0;
68 GetObjectW( bmp, sizeof(dib), &dib );
69 size = dib.dsBm.bmHeight * dib.dsBm.bmWidthBytes;
71 /* calculate number of sel's needed for size with 64K steps */
72 bits->bmp = bmp;
73 bits->count = (size + 0xffff) / 0x10000;
74 bits->sel = AllocSelectorArray16( bits->count );
76 for (i = 0; i < bits->count; i++)
78 SetSelectorBase(bits->sel + (i << __AHSHIFT), (DWORD)bits32 + i * 0x10000);
79 SetSelectorLimit16(bits->sel + (i << __AHSHIFT), size - 1); /* yep, limit is correct */
80 size -= 0x10000;
82 list_add_head( &dib_segptr_list, &bits->entry );
83 return MAKESEGPTR( bits->sel, 0 );
86 /*************************************************************************
87 * WING {WING}
89 * The Windows Game dll provides a number of functions designed to allow
90 * programmers to bypass Gdi and write directly to video memory. The intention
91 * was to bolster the use of Windows as a gaming platform and remove the
92 * need for Dos based games using 32 bit Dos extenders.
94 * This initial approach could not compete with the performance of Dos games
95 * (such as Doom and Warcraft) at the time, and so this dll was eventually
96 * superseded by DirectX. It should not be used by new applications, and is
97 * provided only for compatibility with older Windows programs.
100 typedef enum WING_DITHER_TYPE
102 WING_DISPERSED_4x4, WING_DISPERSED_8x8, WING_CLUSTERED_4x4
103 } WING_DITHER_TYPE;
105 /***********************************************************************
106 * WinGCreateDC (WING.1001)
108 * Create a new WinG device context.
110 * PARAMS
111 * None.
113 * RETURNS
114 * Success: A handle to the created device context.
115 * Failure: A NULL handle.
117 HDC16 WINAPI WinGCreateDC16(void)
119 TRACE("(void)\n");
120 return HDC_16( CreateCompatibleDC( 0 ));
123 /***********************************************************************
124 * WinGRecommendDIBFormat (WING.1002)
126 * Get the recommended format of bitmaps for the current display.
128 * PARAMS
129 * bmpi [O] Destination for format information
131 * RETURNS
132 * Success: TRUE. bmpi is filled with the best (fastest) bitmap format
133 * Failure: FALSE, if bmpi is NULL.
135 BOOL16 WINAPI WinGRecommendDIBFormat16(BITMAPINFO *bmpi)
137 TRACE("(%p)\n", bmpi);
139 if (!bmpi)
140 return FALSE;
142 bmpi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
143 bmpi->bmiHeader.biWidth = 320;
144 bmpi->bmiHeader.biHeight = -1;
145 bmpi->bmiHeader.biPlanes = 1;
146 bmpi->bmiHeader.biBitCount = 8;
147 bmpi->bmiHeader.biCompression = BI_RGB;
148 bmpi->bmiHeader.biSizeImage = 0;
149 bmpi->bmiHeader.biXPelsPerMeter = 0;
150 bmpi->bmiHeader.biYPelsPerMeter = 0;
151 bmpi->bmiHeader.biClrUsed = 0;
152 bmpi->bmiHeader.biClrImportant = 0;
154 return TRUE;
157 /***********************************************************************
158 * WinGCreateBitmap (WING.1003)
160 * Create a new WinG bitmap.
162 * PARAMS
163 * hdc [I] WinG device context
164 * bmpi [I] Information about the bitmap
165 * bits [I] Location of the bitmap image data
167 * RETURNS
168 * Success: A handle to the created bitmap.
169 * Failure: A NULL handle.
171 HBITMAP16 WINAPI WinGCreateBitmap16(HDC16 hdc, BITMAPINFO *bmpi, SEGPTR *bits)
173 LPVOID bits32;
174 HBITMAP hbitmap;
176 TRACE("(%d,%p,%p): create %dx%dx%d bitmap\n", hdc, bmpi, bits,
177 bmpi->bmiHeader.biWidth, bmpi->bmiHeader.biHeight, bmpi->bmiHeader.biPlanes);
179 hbitmap = CreateDIBSection( HDC_32(hdc), bmpi, DIB_RGB_COLORS, &bits32, 0, 0 );
180 if (hbitmap)
182 SEGPTR segptr = alloc_segptr_bits( hbitmap, bits32 );
183 if (bits) *bits = segptr;
185 return HBITMAP_16(hbitmap);
188 /***********************************************************************
189 * WinGGetDIBPointer (WING.1004)
191 SEGPTR WINAPI WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
193 struct dib_segptr_bits *bits;
195 if (bmpi) FIXME( "%04x %p: setting BITMAPINFO not supported\n", hWinGBitmap, bmpi );
197 LIST_FOR_EACH_ENTRY( bits, &dib_segptr_list, struct dib_segptr_bits, entry )
198 if (HBITMAP_16(bits->bmp) == hWinGBitmap) return MAKESEGPTR( bits->sel, 0 );
200 return 0;
203 /***********************************************************************
204 * WinGSetDIBColorTable (WING.1006)
206 * Set all or part of the color table for a WinG device context.
208 * PARAMS
209 * hdc [I] WinG device context
210 * start [I] Start color
211 * num [I] Number of entries to set
212 * colors [I] Array of color data
214 * RETURNS
215 * The number of entries set.
217 UINT16 WINAPI WinGSetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
219 TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
220 return SetDIBColorTable( HDC_32(hdc), start, num, colors );
223 /***********************************************************************
224 * WinGGetDIBColorTable (WING.1005)
226 * Get all or part of the color table for a WinG device context.
228 * PARAMS
229 * hdc [I] WinG device context
230 * start [I] Start color
231 * num [I] Number of entries to set
232 * colors [O] Destination for the array of color data
234 * RETURNS
235 * The number of entries retrieved.
237 UINT16 WINAPI WinGGetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
239 TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
240 return GetDIBColorTable( HDC_32(hdc), start, num, colors );
243 /***********************************************************************
244 * WinGCreateHalfTonePalette (WING.1007)
246 * Create a half tone palette.
248 * PARAMS
249 * None.
251 * RETURNS
252 * Success: A handle to the created palette.
253 * Failure: A NULL handle.
255 HPALETTE16 WINAPI WinGCreateHalfTonePalette16(void)
257 HDC hdc = CreateCompatibleDC(0);
258 HPALETTE16 ret = HPALETTE_16( CreateHalftonePalette( hdc ));
259 TRACE("(void)\n");
260 DeleteDC( hdc );
261 return ret;
264 /***********************************************************************
265 * WinGCreateHalfToneBrush (WING.1008)
267 * Create a half tone brush for a WinG device context.
269 * PARAMS
270 * winDC [I] WinG device context
271 * col [I] Color
272 * type [I] Desired dithering type.
274 * RETURNS
275 * Success: A handle to the created brush.
276 * Failure: A NULL handle.
278 HBRUSH16 WINAPI WinGCreateHalfToneBrush16(HDC16 winDC, COLORREF col,
279 WING_DITHER_TYPE type)
281 TRACE("(%d,%d,%d)\n", winDC, col, type);
282 return HBRUSH_16( CreateSolidBrush( col ));
285 /***********************************************************************
286 * WinGStretchBlt (WING.1009)
288 * See StretchBlt16.
290 BOOL16 WINAPI WinGStretchBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
291 INT16 widDest, INT16 heiDest,
292 HDC16 srcDC, INT16 xSrc, INT16 ySrc,
293 INT16 widSrc, INT16 heiSrc)
295 BOOL retval;
296 TRACE("(%d,%d,...)\n", destDC, srcDC);
297 SetStretchBltMode( HDC_32(destDC), COLORONCOLOR );
298 retval = StretchBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest,
299 HDC_32(srcDC), xSrc, ySrc, widSrc, heiSrc, SRCCOPY );
300 SetStretchBltMode( HDC_32(destDC), BLACKONWHITE );
301 return retval;
304 /***********************************************************************
305 * WinGBitBlt (WING.1010)
307 * See BitBlt16.
309 BOOL16 WINAPI WinGBitBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
310 INT16 widDest, INT16 heiDest, HDC16 srcDC,
311 INT16 xSrc, INT16 ySrc)
313 TRACE("(%d,%d,...)\n", destDC, srcDC);
314 return BitBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest, HDC_32(srcDC), xSrc, ySrc, SRCCOPY );