Release 981025.
[wine/multimedia.git] / graphics / dispdib.c
blobb0779e8569df926ede20e2cff68d4da98edaa9aa
1 /*
2 * DISPDIB.dll
3 *
4 * Copyright 1998 Ove Kåven (with some help from Marcus Meissner)
6 */
8 #include <string.h>
9 #include "windows.h"
10 #include "dispdib.h"
11 #include "compobj.h"
12 #include "interfaces.h"
13 #include "ddraw.h"
14 #include "debug.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;
33 default:
34 return DISPLAYDIB_NOTSUPPORTED;
36 if (!lpddraw) {
37 DirectDrawCreate(NULL,&lpddraw,NULL);
38 if (!lpddraw) {
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)
57 if (lpddraw) {
58 lpddsurf->lpvtbl->fnRelease(lpddsurf);
59 lpddraw->lpvtbl->fnRelease(lpddraw);
60 lpddraw=NULL;
64 static void DISPDIB_Palette(LPBITMAPINFO lpbi)
66 PALETTEENTRY pal[256];
67 int c;
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;
73 pal[c].peFlags=0;
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;
83 LPSTR surf;
85 if (lpddsurf->lpvtbl->fnLock(lpddsurf,NULL,&sdesc,0,0)) {
86 ERR(ddraw,"could not lock surface!\n");
87 return;
89 /* size in sdesc.dwHeight, sdesc.dwWidth, pitch in sdesc.lPitch, ptr in sdesc.y.lpSurface */
91 Delta=(Height<0)*2-1;
92 Height*=-Delta; Pitch*=Delta;
94 if (uFlags&DISPLAYDIB_NOCENTER) {
95 Xofs=0; Yofs=0;
96 } else {
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.
114 * FLAGS
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
125 * RETURNS
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
133 * BUGS
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 */
140 WORD wFlags
143 WORD ret;
145 if (wFlags&DISPLAYDIB_END) {
146 if (dispdib_multi) DISPDIB_End();
147 dispdib_multi = 0;
148 return DISPLAYDIB_NOERROR;
150 if (!dispdib_multi) {
151 ret=DISPDIB_Begin(wFlags);
152 if (ret) return ret;
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... */
159 if (lpBits) {
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;