WinG was written for 8bpp DIBs, so some apps assume that, so always
[wine] / dlls / gdi / wing.c
1 /*
2  * WinG support
3  *
4  * Started by Robert Pouliot <krynos@clic.net>
5  */
6
7 #include "config.h"
8
9 #ifndef X_DISPLAY_MISSING
10 #include "x11drv.h"
11 #endif /* !defined(X_DISPLAY_MISSING) */
12
13 #include "wine/winuser16.h"
14 #include "bitmap.h"
15 #include "debugtools.h"
16 #include "ldt.h"
17 #include "palette.h"
18 #include "windef.h"
19
20 DEFAULT_DEBUG_CHANNEL(wing);
21
22
23 typedef enum WING_DITHER_TYPE
24 {
25   WING_DISPERSED_4x4, WING_DISPERSED_8x8, WING_CLUSTERED_4x4
26 } WING_DITHER_TYPE;
27
28 /* 
29  * WinG DIB bitmaps can be selected into DC and then scribbled upon
30  * by GDI functions. They can also be changed directly. This gives us 
31  * three choices 
32  *      - use original WinG 16-bit DLL
33  *              requires working 16-bit driver interface
34  *      - implement DIB graphics driver from scratch
35  *              see wing.zip size
36  *      - use shared pixmaps
37  *              won't work with some videocards and/or videomodes
38  * 961208 - AK
39  */
40
41 /***********************************************************************
42  *          WinGCreateDC16      (WING.1001)
43  */
44 HDC16 WINAPI WinGCreateDC16(void)
45 {
46     TRACE("(void)\n");
47         return CreateCompatibleDC16(0);
48 }
49
50 /***********************************************************************
51  *  WinGRecommendDIBFormat16    (WING.1002)
52  */
53 BOOL16 WINAPI WinGRecommendDIBFormat16(BITMAPINFO *bmpi)
54 {
55     HDC hdc;
56     TRACE("(%p)\n", bmpi);
57     if (!bmpi)
58         return FALSE;
59
60     hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
61     bmpi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
62     bmpi->bmiHeader.biWidth = 320;
63     bmpi->bmiHeader.biHeight = -1;
64     bmpi->bmiHeader.biPlanes = 1;
65     bmpi->bmiHeader.biBitCount = 8;
66     bmpi->bmiHeader.biCompression = BI_RGB;
67     bmpi->bmiHeader.biSizeImage = 0;
68     bmpi->bmiHeader.biXPelsPerMeter = 0;
69     bmpi->bmiHeader.biYPelsPerMeter = 0;
70     bmpi->bmiHeader.biClrUsed = 0;
71     bmpi->bmiHeader.biClrImportant = 0;
72     DeleteDC(hdc);
73     return TRUE;
74 }
75
76 /***********************************************************************
77  *        WinGCreateBitmap16    (WING.1003)
78  */
79 HBITMAP16 WINAPI WinGCreateBitmap16(HDC16 hdc, BITMAPINFO *bmpi,
80                                     SEGPTR *bits)
81 {
82     TRACE("(%d,%p,%p)\n", hdc, bmpi, bits);
83     TRACE(": create %ldx%ldx%d bitmap\n", bmpi->bmiHeader.biWidth,
84           bmpi->bmiHeader.biHeight, bmpi->bmiHeader.biPlanes);
85     return CreateDIBSection16(hdc, bmpi, 0, bits, 0, 0);
86 }
87
88 /***********************************************************************
89  *  WinGGetDIBPointer   (WING.1004)
90  */
91 SEGPTR WINAPI WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
92 {
93   BITMAPOBJ*    bmp = (BITMAPOBJ *) GDI_GetObjPtr( hWinGBitmap, BITMAP_MAGIC );
94     SEGPTR res = 0;
95
96     TRACE("(%d,%p)\n", hWinGBitmap, bmpi);
97     if (!bmp) return (SEGPTR)NULL;
98
99     if (bmpi)
100         FIXME(": Todo - implement setting BITMAPINFO\n");
101
102 #ifndef X_DISPLAY_MISSING
103     res = PTR_SEG_OFF_TO_SEGPTR(((X11DRV_DIBSECTION *) bmp->dib)->selector, 0);
104 #endif /* !defined(X_DISPLAY_MISSING) */
105     
106     GDI_ReleaseObj( hWinGBitmap );
107     return res;
108 }
109
110 /***********************************************************************
111  *  WinGSetDIBColorTable   (WING.1004)
112  */
113 UINT16 WINAPI WinGSetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num,
114                                      RGBQUAD *colors)
115 {
116     TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
117     return SetDIBColorTable16(hdc, start, num, colors);
118 }
119
120 /***********************************************************************
121  *  WinGGetDIBColorTable16   (WING.1005)
122  */
123 UINT16 WINAPI WinGGetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num,
124                                      RGBQUAD *colors)
125 {
126     TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
127     return GetDIBColorTable16(hdc, start, num, colors);
128 }
129
130 /***********************************************************************
131  *  WinGCreateHalfTonePalette16   (WING.1007)
132  */
133 HPALETTE16 WINAPI WinGCreateHalfTonePalette16(void)
134 {
135     HDC hdc = CreateCompatibleDC(0);
136     HPALETTE16 ret = CreateHalftonePalette16(hdc);
137     TRACE("(void)\n");
138     DeleteDC(hdc);
139     return ret;
140 }
141
142 /***********************************************************************
143  *  WinGCreateHalfToneBrush16   (WING.1008)
144  */
145 HBRUSH16 WINAPI WinGCreateHalfToneBrush16(HDC16 winDC, COLORREF col,
146                                             WING_DITHER_TYPE type)
147 {
148     TRACE("(%d,%ld,%d)\n", winDC, col, type);
149     return CreateSolidBrush16(col);
150 }
151
152 /***********************************************************************
153  *  WinGStretchBlt16   (WING.1009)
154  */
155 BOOL16 WINAPI WinGStretchBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
156                                INT16 widDest, INT16 heiDest,
157                                HDC16 srcDC, INT16 xSrc, INT16 ySrc,
158                                INT16 widSrc, INT16 heiSrc)
159 {
160     BOOL16 retval;
161     TRACE("(%d,%d,...)\n", destDC, srcDC);
162     SetStretchBltMode16 ( destDC, COLORONCOLOR );
163     retval=StretchBlt16(destDC, xDest, yDest, widDest, heiDest, srcDC,
164                         xSrc, ySrc, widSrc, heiSrc, SRCCOPY);
165     SetStretchBltMode16 ( destDC, BLACKONWHITE );
166     return retval;
167 }
168
169 /***********************************************************************
170  *  WinGBitBlt16   (WING.1010)
171  */
172 BOOL16 WINAPI WinGBitBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
173                            INT16 widDest, INT16 heiDest, HDC16 srcDC,
174                            INT16 xSrc, INT16 ySrc)
175 {
176     TRACE("(%d,%d,...)\n", destDC, srcDC);
177     return BitBlt16(destDC, xDest, yDest, widDest, heiDest, srcDC,
178                     xSrc, ySrc, SRCCOPY);
179 }