wing.c 8.17 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/*
Alexandre Julliard's avatar
Alexandre Julliard committed
2
 * WinG support
Alexandre Julliard's avatar
Alexandre Julliard committed
3
 *
4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * Copyright (C) Robert Pouliot <krynos@clic.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
Alexandre Julliard's avatar
Alexandre Julliard committed
19 20
 */

21 22
#include "config.h"

23 24
#include <stdarg.h>

25
#include "windef.h"
26 27
#include "winbase.h"
#include "wingdi.h"
Michael Stefaniuc's avatar
Michael Stefaniuc committed
28
#include "wownt32.h"
29
#include "wine/wingdi16.h"
30
#include "wine/debug.h"
31

32
WINE_DEFAULT_DEBUG_CHANNEL(wing);
33

Jon Griffiths's avatar
Jon Griffiths committed
34 35 36 37 38 39 40 41 42 43
/*************************************************************************
 * WING {WING}
 *
 * The Windows Game dll provides a number of functions designed to allow
 * programmers to bypass Gdi and write directly to video memory. The intention
 * was to bolster the use of Windows as a gaming platform and remove the
 * need for Dos based games using 32 bit Dos extenders.
 *
 * This initial approach could not compete with the performance of Dos games
 * (such as Doom and Warcraft) at the time, and so this dll was eventually
Francois Gouget's avatar
Francois Gouget committed
44 45
 * superseded by DirectX. It should not be used by new applications, and is
 * provided only for compatibility with older Windows programs.
Jon Griffiths's avatar
Jon Griffiths committed
46
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
47

Alexandre Julliard's avatar
Alexandre Julliard committed
48 49 50 51 52
typedef enum WING_DITHER_TYPE
{
  WING_DISPERSED_4x4, WING_DISPERSED_8x8, WING_CLUSTERED_4x4
} WING_DITHER_TYPE;

Alexandre Julliard's avatar
Alexandre Julliard committed
53
/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
54
 *          WinGCreateDC	(WING.1001)
Jon Griffiths's avatar
Jon Griffiths committed
55 56 57 58 59 60 61 62 63
 *
 * Create a new WinG device context.
 *
 * PARAMS
 *  None.
 *
 * RETURNS
 *  Success: A handle to the created device context.
 *  Failure: A NULL handle.
Alexandre Julliard's avatar
Alexandre Julliard committed
64
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
65
HDC16 WINAPI WinGCreateDC16(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
66
{
67
    TRACE("(void)\n");
68
    return HDC_16( CreateCompatibleDC( 0 ));
Alexandre Julliard's avatar
Alexandre Julliard committed
69
}
Alexandre Julliard's avatar
Alexandre Julliard committed
70 71

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
72
 *  WinGRecommendDIBFormat    (WING.1002)
Jon Griffiths's avatar
Jon Griffiths committed
73 74 75 76 77 78 79 80 81
 *
 * Get the recommended format of bitmaps for the current display.
 *
 * PARAMS
 *  bmpi [O] Destination for format information
 *
 * RETURNS
 *  Success: TRUE. bmpi is filled with the best (fastest) bitmap format
 *  Failure: FALSE, if bmpi is NULL.
Alexandre Julliard's avatar
Alexandre Julliard committed
82
 */
Brad Pepers's avatar
Brad Pepers committed
83
BOOL16 WINAPI WinGRecommendDIBFormat16(BITMAPINFO *bmpi)
Alexandre Julliard's avatar
Alexandre Julliard committed
84
{
85
    TRACE("(%p)\n", bmpi);
86

Brad Pepers's avatar
Brad Pepers committed
87 88 89 90 91 92
    if (!bmpi)
	return FALSE;

    bmpi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmpi->bmiHeader.biWidth = 320;
    bmpi->bmiHeader.biHeight = -1;
93 94
    bmpi->bmiHeader.biPlanes = 1;
    bmpi->bmiHeader.biBitCount = 8;
Brad Pepers's avatar
Brad Pepers committed
95 96 97 98 99 100
    bmpi->bmiHeader.biCompression = BI_RGB;
    bmpi->bmiHeader.biSizeImage = 0;
    bmpi->bmiHeader.biXPelsPerMeter = 0;
    bmpi->bmiHeader.biYPelsPerMeter = 0;
    bmpi->bmiHeader.biClrUsed = 0;
    bmpi->bmiHeader.biClrImportant = 0;
101

Alexandre Julliard's avatar
Alexandre Julliard committed
102
    return TRUE;
103
}
Alexandre Julliard's avatar
Alexandre Julliard committed
104 105

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
106
 *        WinGCreateBitmap    (WING.1003)
Jon Griffiths's avatar
Jon Griffiths committed
107 108 109 110 111 112 113 114 115 116 117
 *
 * Create a new WinG bitmap.
 *
 * PARAMS
 *  hdc  [I] WinG device context
 *  bmpi [I] Information about the bitmap
 *  bits [I] Location of the bitmap image data
 *
 * RETURNS
 *  Success: A handle to the created bitmap.
 *  Failure: A NULL handle.
Alexandre Julliard's avatar
Alexandre Julliard committed
118
 */
119
HBITMAP16 WINAPI WinGCreateBitmap16(HDC16 hdc, BITMAPINFO *bmpi, SEGPTR *bits)
Alexandre Julliard's avatar
Alexandre Julliard committed
120
{
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
    LPVOID bits32;
    HBITMAP hbitmap;

    TRACE("(%d,%p,%p): create %dx%dx%d bitmap\n", hdc, bmpi, bits,
          bmpi->bmiHeader.biWidth, bmpi->bmiHeader.biHeight, bmpi->bmiHeader.biPlanes);

    hbitmap = CreateDIBSection( HDC_32(hdc), bmpi, BI_RGB, &bits32, 0, 0 );
    if (hbitmap)
    {
        DIBSECTION dib;
        DWORD size;
        WORD count, sel;
        int i;

        GetObjectW( hbitmap, sizeof(dib), &dib );
        size = dib.dsBm.bmHeight * dib.dsBm.bmWidthBytes;

        /* calculate number of sel's needed for size with 64K steps */
        count = (size + 0xffff) / 0x10000;
        sel = AllocSelectorArray16(count);

        for (i = 0; i < count; i++)
        {
            SetSelectorBase(sel + (i << __AHSHIFT), (DWORD)bits32 + i * 0x10000);
            SetSelectorLimit16(sel + (i << __AHSHIFT), size - 1); /* yep, limit is correct */
            size -= 0x10000;
        }
        if (bits) *bits = MAKESEGPTR( sel, 0 );
    }
    return HBITMAP_16(hbitmap);
151
}
Alexandre Julliard's avatar
Alexandre Julliard committed
152

Alexandre Julliard's avatar
Alexandre Julliard committed
153
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
154
 *  WinGGetDIBPointer   (WING.1004)
Alexandre Julliard's avatar
Alexandre Julliard committed
155
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
156
SEGPTR WINAPI WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
Alexandre Julliard's avatar
Alexandre Julliard committed
157
{
158 159
    FIXME("%x, %p: not supported\n", hWinGBitmap, bmpi );
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
160 161 162
}

/***********************************************************************
163
 *  WinGSetDIBColorTable   (WING.1006)
Jon Griffiths's avatar
Jon Griffiths committed
164 165 166 167 168 169 170 171 172 173 174
 *
 * Set all or part of the color table for a WinG device context.
 *
 * PARAMS
 *  hdc    [I] WinG device context
 *  start  [I] Start color
 *  num    [I] Number of entries to set
 *  colors [I] Array of color data
 *
 * RETURNS
 *  The number of entries set.
Alexandre Julliard's avatar
Alexandre Julliard committed
175
 */
176
UINT16 WINAPI WinGSetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
Alexandre Julliard's avatar
Alexandre Julliard committed
177
{
178
    TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
179
    return SetDIBColorTable( HDC_32(hdc), start, num, colors );
Alexandre Julliard's avatar
Alexandre Julliard committed
180 181 182
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
183
 *  WinGGetDIBColorTable   (WING.1005)
Jon Griffiths's avatar
Jon Griffiths committed
184 185 186 187 188 189 190 191 192 193 194
 *
 * Get all or part of the color table for a WinG device context.
 *
 * PARAMS
 *  hdc    [I] WinG device context
 *  start  [I] Start color
 *  num    [I] Number of entries to set
 *  colors [O] Destination for the array of color data
 *
 * RETURNS
 *  The number of entries retrieved.
Alexandre Julliard's avatar
Alexandre Julliard committed
195
 */
196
UINT16 WINAPI WinGGetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
Alexandre Julliard's avatar
Alexandre Julliard committed
197
{
198
    TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
199
    return GetDIBColorTable( HDC_32(hdc), start, num, colors );
Alexandre Julliard's avatar
Alexandre Julliard committed
200 201
}

Alexandre Julliard's avatar
Alexandre Julliard committed
202
/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
203
 *  WinGCreateHalfTonePalette   (WING.1007)
Jon Griffiths's avatar
Jon Griffiths committed
204 205 206 207 208 209 210 211 212
 *
 * Create a half tone palette.
 *
 * PARAMS
 *  None.
 *
 * RETURNS
 *  Success: A handle to the created palette.
 *  Failure: A NULL handle.
Alexandre Julliard's avatar
Alexandre Julliard committed
213
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
214
HPALETTE16 WINAPI WinGCreateHalfTonePalette16(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
215
{
216 217
    HDC hdc = CreateCompatibleDC(0);
    HPALETTE16 ret = HPALETTE_16( CreateHalftonePalette( hdc ));
218
    TRACE("(void)\n");
219
    DeleteDC( hdc );
220
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
221 222 223
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
224
 *  WinGCreateHalfToneBrush   (WING.1008)
Jon Griffiths's avatar
Jon Griffiths committed
225 226 227 228 229 230 231 232 233 234 235
 *
 * Create a half tone brush for a WinG device context.
 *
 * PARAMS
 *  winDC [I] WinG device context
 *  col   [I] Color
 *  type  [I] Desired dithering type.
 *
 * RETURNS
 *  Success: A handle to the created brush.
 *  Failure: A NULL handle.
Alexandre Julliard's avatar
Alexandre Julliard committed
236
 */
Brad Pepers's avatar
Brad Pepers committed
237
HBRUSH16 WINAPI WinGCreateHalfToneBrush16(HDC16 winDC, COLORREF col,
Alexandre Julliard's avatar
Alexandre Julliard committed
238
                                            WING_DITHER_TYPE type)
Alexandre Julliard's avatar
Alexandre Julliard committed
239
{
240
    TRACE("(%d,%d,%d)\n", winDC, col, type);
241
    return HBRUSH_16( CreateSolidBrush( col ));
Alexandre Julliard's avatar
Alexandre Julliard committed
242 243
}

Alexandre Julliard's avatar
Alexandre Julliard committed
244
/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
245
 *  WinGStretchBlt   (WING.1009)
Jon Griffiths's avatar
Jon Griffiths committed
246 247
 *
 * See StretchBlt16.
Alexandre Julliard's avatar
Alexandre Julliard committed
248
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
249 250 251 252
BOOL16 WINAPI WinGStretchBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
                               INT16 widDest, INT16 heiDest,
                               HDC16 srcDC, INT16 xSrc, INT16 ySrc,
                               INT16 widSrc, INT16 heiSrc)
Alexandre Julliard's avatar
Alexandre Julliard committed
253
{
254
    BOOL retval;
255
    TRACE("(%d,%d,...)\n", destDC, srcDC);
256 257 258 259
    SetStretchBltMode( HDC_32(destDC), COLORONCOLOR );
    retval = StretchBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest,
                         HDC_32(srcDC), xSrc, ySrc, widSrc, heiSrc, SRCCOPY );
    SetStretchBltMode( HDC_32(destDC), BLACKONWHITE );
Peter Ganten's avatar
Peter Ganten committed
260
    return retval;
Alexandre Julliard's avatar
Alexandre Julliard committed
261 262 263
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
264
 *  WinGBitBlt   (WING.1010)
Jon Griffiths's avatar
Jon Griffiths committed
265 266
 *
 * See BitBlt16.
Alexandre Julliard's avatar
Alexandre Julliard committed
267
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
268 269 270
BOOL16 WINAPI WinGBitBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
                           INT16 widDest, INT16 heiDest, HDC16 srcDC,
                           INT16 xSrc, INT16 ySrc)
Alexandre Julliard's avatar
Alexandre Julliard committed
271
{
272
    TRACE("(%d,%d,...)\n", destDC, srcDC);
273
    return BitBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest, HDC_32(srcDC), xSrc, ySrc, SRCCOPY );
Alexandre Julliard's avatar
Alexandre Julliard committed
274
}