Merged _all_ lpClipper into common_surface.
[wine] / graphics / dispdib.c
1 /*
2  * DISPDIB.dll
3  * 
4  * Copyright 1998 Ove Kåven (with some help from Marcus Meissner)
5  *
6  */
7
8 #include <string.h>
9 #include "miscemu.h"
10 #include "dispdib.h"
11 #include "vga.h"
12 #include "debugtools.h"
13 #include "wine/wingdi16.h"
14
15 DEFAULT_DEBUG_CHANNEL(ddraw)
16
17 static int dispdib_multi = 0;
18
19 static WORD DISPDIB_Begin(WORD wFlags)
20 {
21     unsigned Xres,Yres,Depth;
22
23     switch(wFlags&DISPLAYDIB_MODE) {
24         case DISPLAYDIB_MODE_DEFAULT:
25             /* FIXME: is this supposed to autodetect? */
26         case DISPLAYDIB_MODE_320x200x8:
27             Xres=320; Yres=200; Depth=8; break;
28         case DISPLAYDIB_MODE_320x240x8:
29             Xres=320; Yres=240; Depth=8; break;
30         default:
31             return DISPLAYDIB_NOTSUPPORTED;
32     }
33     /* more or less dummy calls to Death/Resurrection, for completeness */
34     /* FIXME: what arguments should they get? */
35     Death16(0);
36     if (VGA_SetMode(Xres,Yres,Depth)) {
37          Resurrection16(0,0,0,0,0,0,0);
38          return DISPLAYDIB_NOTSUPPORTED;
39     }
40     return DISPLAYDIB_NOERROR;
41 }
42
43 static void DISPDIB_End(void)
44 {
45     Resurrection16(0,0,0,0,0,0,0); /* FIXME: arguments */
46     VGA_Exit();
47 }
48
49 static void DISPDIB_Palette(LPBITMAPINFO lpbi)
50 {
51     VGA_SetQuadPalette(lpbi->bmiColors,0,256);
52 }
53
54 static void DISPDIB_Show(LPBITMAPINFOHEADER lpbi,LPSTR lpBits,WORD uFlags)
55 {
56     int Xofs,Yofs,Width=lpbi->biWidth,Height=lpbi->biHeight,Delta;
57     unsigned Pitch=(Width+3)&~3,sPitch,sWidth,sHeight;
58     LPSTR surf = DOSMEM_MapDosToLinear(0xa0000);
59
60     if (VGA_GetMode(&sHeight,&sWidth,NULL)) return;
61     sPitch=320;
62
63     Delta=(Height<0)*2-1;
64     Height*=-Delta; Pitch*=Delta;
65
66     if (uFlags&DISPLAYDIB_NOCENTER) {
67         Xofs=0; Yofs=0;
68     } else {
69         Xofs=(sWidth-Width)/2;
70         Yofs=(sHeight-Height)/2;
71     }
72     surf += (Yofs*sPitch)+Xofs;
73     if (Pitch<0) lpBits-=Pitch*(Height-1);
74     for (; Height; Height--,lpBits+=Pitch,surf+=sPitch) {
75         memcpy(surf,lpBits,Width);
76     }
77
78     VGA_Poll(0);
79 }
80
81 /*********************************************************************
82  *      DisplayDib      (DISPDIB.1)
83  *
84  *  Disables GDI and takes over the VGA screen to show DIBs in full screen.
85  *
86  * FLAGS
87  *
88  *  DISPLAYDIB_NOPALETTE: don't change palette
89  *  DISPLAYDIB_NOCENTER: don't center bitmap
90  *  DISPLAYDIB_NOWAIT: don't wait (for keypress) before returning
91  *  DISPLAYDIB_BEGIN: start of multiple calls (does not restore the screen)
92  *  DISPLAYDIB_END: end of multiple calls (restores the screen)
93  *  DISPLAYDIB_MODE_DEFAULT: default display mode
94  *  DISPLAYDIB_MODE_320x200x8: Standard VGA 320x200 256 colors
95  *  DISPLAYDIB_MODE_320x240x8: Tweaked VGA 320x240 256 colors
96  *
97  * RETURNS
98  *
99  *  DISPLAYDIB_NOERROR: success
100  *  DISPLAYDIB_NOTSUPPORTED: function not supported
101  *  DISPLAYDIB_INVALIDDIB: null or invalid DIB header
102  *  DISPLAYDIB_INVALIDFORMAT: invalid DIB format
103  *  DISPLAYDIB_INVALIDTASK: not called from current task
104  *
105  * BUGS
106  *
107  *  Waiting for keypresses is not implemented.
108  */
109 WORD WINAPI DisplayDib(
110                 LPBITMAPINFO lpbi, /* DIB header with resolution and palette */
111                 LPSTR lpBits, /* Bitmap bits to show */
112                 WORD wFlags
113         )
114 {
115     WORD ret;
116
117     if (wFlags&DISPLAYDIB_END) {
118         if (dispdib_multi) DISPDIB_End();
119         dispdib_multi = 0;
120         return DISPLAYDIB_NOERROR;
121     }
122     if (!dispdib_multi) {
123         ret=DISPDIB_Begin(wFlags);
124         if (ret) return ret;
125     }
126     if (wFlags&DISPLAYDIB_BEGIN) dispdib_multi = 1;
127     if (!(wFlags&DISPLAYDIB_NOPALETTE)) {
128         DISPDIB_Palette(lpbi);
129     }
130     /* FIXME: not sure if it's valid to draw images in DISPLAYDIB_BEGIN, so... */
131     if (lpBits) {
132         DISPDIB_Show(&(lpbi->bmiHeader),lpBits,wFlags);
133     }
134     if (!(wFlags&DISPLAYDIB_NOWAIT)) {
135         FIXME("wait not implemented\n");
136     }
137     if (!dispdib_multi) DISPDIB_End();
138     return DISPLAYDIB_NOERROR;
139 }