4 * Copyright 1998 Ove Kåven (with some help from Marcus Meissner)
12 #include "interfaces.h"
16 static int dispdib_multi
= 0;
17 static IDirectDraw
*lpddraw
= NULL
;
18 static IDirectDrawSurface
*lpddsurf
;
19 static IDirectDrawPalette
*lpddpal
;
20 static DDSURFACEDESC sdesc
;
22 static WORD
DISPDIB_Begin(WORD wFlags
)
24 unsigned Xres
,Yres
,Depth
;
26 switch(wFlags
&DISPLAYDIB_MODE
) {
27 case DISPLAYDIB_MODE_DEFAULT
:
28 /* FIXME: is this supposed to autodetect? */
29 case DISPLAYDIB_MODE_320x200x8
:
30 Xres
=320; Yres
=200; Depth
=8; break;
31 case DISPLAYDIB_MODE_320x240x8
:
32 Xres
=320; Yres
=240; Depth
=8; break;
34 return DISPLAYDIB_NOTSUPPORTED
;
37 DirectDrawCreate(NULL
,&lpddraw
,NULL
);
39 ERR(ddraw
,"DirectDraw is not available\n");
40 return DISPLAYDIB_NOTSUPPORTED
;
42 if (lpddraw
->lpvtbl
->fnSetDisplayMode(lpddraw
,Xres
,Yres
,Depth
)) {
43 ERR(ddraw
,"DirectDraw does not support requested display mode\n");
44 lpddraw
->lpvtbl
->fnRelease(lpddraw
);
45 return DISPLAYDIB_NOTSUPPORTED
;
47 lpddraw
->lpvtbl
->fnCreatePalette(lpddraw
,0,NULL
,&lpddpal
,NULL
);
48 memset(&sdesc
,0,sizeof(sdesc
));
49 sdesc
.dwSize
=sizeof(sdesc
);
50 lpddraw
->lpvtbl
->fnCreateSurface(lpddraw
,&sdesc
,&lpddsurf
,NULL
);
52 return DISPLAYDIB_NOERROR
;
55 static void DISPDIB_End(void)
58 lpddsurf
->lpvtbl
->fnRelease(lpddsurf
);
59 lpddraw
->lpvtbl
->fnRelease(lpddraw
);
64 static void DISPDIB_Palette(LPBITMAPINFO lpbi
)
66 PALETTEENTRY pal
[256];
69 for (c
=0; c
<256; c
++) {
70 pal
[c
].peRed
=lpbi
->bmiColors
[c
].rgbRed
;
71 pal
[c
].peGreen
=lpbi
->bmiColors
[c
].rgbGreen
;
72 pal
[c
].peBlue
=lpbi
->bmiColors
[c
].rgbBlue
;
75 lpddpal
->lpvtbl
->fnSetEntries(lpddpal
,0,0,256,pal
);
76 lpddsurf
->lpvtbl
->fnSetPalette(lpddsurf
,lpddpal
);
79 static void DISPDIB_Show(LPBITMAPINFOHEADER lpbi
,LPSTR lpBits
,WORD uFlags
)
81 int Xofs
,Yofs
,Width
=lpbi
->biWidth
,Height
=lpbi
->biHeight
,Delta
;
82 unsigned Pitch
=(Width
+3)&~3;
85 if (lpddsurf
->lpvtbl
->fnLock(lpddsurf
,NULL
,&sdesc
,0,0)) {
86 ERR(ddraw
,"could not lock surface!\n");
89 /* size in sdesc.dwHeight, sdesc.dwWidth, pitch in sdesc.lPitch, ptr in sdesc.y.lpSurface */
92 Height
*=-Delta
; Pitch
*=Delta
;
94 if (uFlags
&DISPLAYDIB_NOCENTER
) {
97 Xofs
=(sdesc
.dwWidth
-Width
)/2;
98 Yofs
=(sdesc
.dwHeight
-Height
)/2;
100 surf
=(LPSTR
)sdesc
.y
.lpSurface
+ (Yofs
*sdesc
.lPitch
)+Xofs
;
101 if (Pitch
<0) lpBits
-=Pitch
*(Height
-1);
102 for (; Height
; Height
--,lpBits
+=Pitch
,surf
+=sdesc
.lPitch
) {
103 memcpy(surf
,lpBits
,Width
);
106 lpddsurf
->lpvtbl
->fnUnlock(lpddsurf
,sdesc
.y
.lpSurface
);
109 /*********************************************************************
110 * DisplayDib (DISPDIB.1)
112 * Disables GDI and takes over the VGA screen to show DIBs in full screen.
116 * DISPLAYDIB_NOPALETTE: don't change palette
117 * DISPLAYDIB_NOCENTER: don't center bitmap
118 * DISPLAYDIB_NOWAIT: don't wait (for keypress) before returning
119 * DISPLAYDIB_BEGIN: start of multiple calls (does not restore the screen)
120 * DISPLAYDIB_END: end of multiple calls (restores the screen)
121 * DISPLAYDIB_MODE_DEFAULT: default display mode
122 * DISPLAYDIB_MODE_320x200x8: Standard VGA 320x200 256 colors
123 * DISPLAYDIB_MODE_320x240x8: Tweaked VGA 320x240 256 colors
127 * DISPLAYDIB_NOERROR: success
128 * DISPLAYDIB_NOTSUPPORTED: function not supported
129 * DISPLAYDIB_INVALIDDIB: null or invalid DIB header
130 * DISPLAYDIB_INVALIDFORMAT: invalid DIB format
131 * DISPLAYDIB_INVALIDTASK: not called from current task
135 * Waiting for keypresses is not implemented.
137 WORD WINAPI
DisplayDib(
138 LPBITMAPINFO lpbi
, /* DIB header with resolution and palette */
139 LPSTR lpBits
, /* Bitmap bits to show */
145 if (wFlags
&DISPLAYDIB_END
) {
146 if (dispdib_multi
) DISPDIB_End();
148 return DISPLAYDIB_NOERROR
;
150 if (!dispdib_multi
) {
151 ret
=DISPDIB_Begin(wFlags
);
154 if (wFlags
&DISPLAYDIB_BEGIN
) dispdib_multi
= 1;
155 if (!(wFlags
&DISPLAYDIB_NOPALETTE
)) {
156 DISPDIB_Palette(lpbi
);
158 /* FIXME: not sure if it's valid to draw images in DISPLAYDIB_BEGIN, so... */
160 DISPDIB_Show(&(lpbi
->bmiHeader
),lpBits
,wFlags
);
162 if (!(wFlags
&DISPLAYDIB_NOWAIT
)) {
163 FIXME(ddraw
,"wait not implemented\n");
165 if (!dispdib_multi
) DISPDIB_End();
166 return DISPLAYDIB_NOERROR
;