source: trunk/src/gdi32/dibitmap.cpp@ 2600

Last change on this file since 2600 was 2600, checked in by sandervl, 26 years ago

RGB 555 conversion in SetDIBitsToDevice + quake 2 BitBlt fix

File size: 9.6 KB
Line 
1/* $Id: dibitmap.cpp,v 1.2 2000-02-02 23:45:06 sandervl Exp $ */
2
3/*
4 * GDI32 dib & bitmap code
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1998 Patrick Haller
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#include <os2win.h>
13#include <stdlib.h>
14#include <stdarg.h>
15#include <string.h>
16#include "misc.h"
17#include "dibsect.h"
18
19//******************************************************************************
20//******************************************************************************
21HBITMAP WIN32API CreateDIBitmap(HDC hdc, const BITMAPINFOHEADER *lpbmih,
22 DWORD fdwInit, const void *lpbInit,
23 const BITMAPINFO *lpbmi, UINT fuUsage)
24{
25 int iHeight;
26 HBITMAP rc;
27
28 //TEMPORARY HACK TO PREVENT CRASH IN OPEN32 (WSeB GA)
29
30 iHeight = lpbmih->biHeight;
31 if(lpbmih->biHeight < 0)
32 {
33 ((BITMAPINFOHEADER *)lpbmih)->biHeight = -lpbmih->biHeight;
34 }
35
36 rc = O32_CreateDIBitmap(hdc, lpbmih, fdwInit, lpbInit, lpbmi, fuUsage);
37
38 dprintf(("GDI32: CreateDIBitmap %x %x %x %x returned %x", hdc, fdwInit, lpbInit, fuUsage, rc));
39
40 ((BITMAPINFOHEADER *)lpbmih)->biHeight = iHeight;
41
42 return rc;
43}
44//******************************************************************************
45//******************************************************************************
46HBITMAP WIN32API CreateCompatibleBitmap( HDC arg1, int arg2, int arg3)
47{
48 dprintf(("GDI32: CreateCompatibleBitmap\n"));
49 return O32_CreateCompatibleBitmap(arg1, arg2, arg3);
50}
51//******************************************************************************
52//CreateDisardableBitmap is obsolete and can be replaced by CreateCompatibleBitmap
53//******************************************************************************
54HBITMAP WIN32API CreateDiscardableBitmap(HDC hDC, int nWidth, int nHeight)
55{
56 dprintf(("GDI32: CreateDisardableBitmap\n"));
57 return O32_CreateCompatibleBitmap(hDC, nWidth, nHeight);
58}
59//******************************************************************************
60//******************************************************************************
61HBITMAP WIN32API CreateBitmap(int nWidth, int nHeight, UINT cPlanes,
62 UINT cBitsPerPel, const void *lpvBits)
63{
64 HBITMAP rc;
65
66 rc = O32_CreateBitmap(nWidth, nHeight, cPlanes, cBitsPerPel, lpvBits);
67 dprintf(("GDI32: CreateBitmap (%d,%d) bps %d returned %d\n", nWidth, nHeight, cBitsPerPel, rc));
68 return(rc);
69}
70//******************************************************************************
71//******************************************************************************
72HBITMAP WIN32API CreateBitmapIndirect( const BITMAP * arg1)
73{
74 dprintf(("GDI32: CreateBitmapIndirect"));
75 return O32_CreateBitmapIndirect(arg1);
76}
77//******************************************************************************
78//*********************************************************************************
79HBITMAP WIN32API CreateDIBSection( HDC hdc, BITMAPINFO *pbmi, UINT iUsage,
80 VOID **ppvBits, HANDLE hSection, DWORD dwOffset)
81{
82 HBITMAP res = 0;
83 BOOL fFlip = 0;
84 int iHeight, iWidth;
85
86 dprintf(("GDI32: CreateDIBSection %x %x %x %x %d", hdc, iUsage, ppvBits, hSection, dwOffset));
87 if(hSection)
88 {
89 dprintf(("GDI32: CreateDIBSection, hSection != NULL, not supported!"));
90 return NULL;
91 }
92
93 //SvL: 13-9-98: StarCraft uses bitmap with negative height
94 iWidth = pbmi->bmiHeader.biWidth;
95 if(pbmi->bmiHeader.biWidth < 0)
96 {
97 dprintf(("CreateDIBSection: width %d", pbmi->bmiHeader.biWidth));
98 pbmi->bmiHeader.biWidth = -pbmi->bmiHeader.biWidth;
99 fFlip = FLIP_HOR;
100 }
101 iHeight = pbmi->bmiHeader.biHeight;
102 if(pbmi->bmiHeader.biHeight < 0)
103 {
104 dprintf(("CreateDIBSection: height %d", pbmi->bmiHeader.biHeight));
105 pbmi->bmiHeader.biHeight = -pbmi->bmiHeader.biHeight;
106 fFlip |= FLIP_VERT;
107 }
108
109 res = O32_CreateDIBitmap(hdc, &pbmi->bmiHeader, 0, NULL, pbmi, iUsage);
110 if (res)
111 {
112 char PalSize;
113 DIBSection *dsect = new DIBSection((BITMAPINFOHEADER_W *)&pbmi->bmiHeader, (char *)&pbmi->bmiColors, iUsage, (DWORD)res, fFlip);
114
115 if(dsect != NULL)
116 {
117 PalSize = dsect->GetBitCount();
118 if(PalSize <= 8)
119 {
120 ULONG Pal[256];
121 LOGPALETTE tmpPal = { 0x300,1,{0,0,0,0}};
122 HPALETTE hpalCur, hpalTmp;
123
124 // Now get the current Palette from the DC
125 hpalTmp = CreatePalette(&tmpPal);
126 hpalCur = SelectPalette(hdc, hpalTmp, FALSE);
127
128 // and use it to set the DIBColorTable
129 GetPaletteEntries( hpalCur, 0, 1<<PalSize, (LPPALETTEENTRY)&Pal);
130 dsect->SetDIBColorTable(0, 1<< PalSize, (RGBQUAD*)&Pal);
131
132 // Restore the DC Palette
133 SelectPalette(hdc,hpalCur,FALSE);
134 DeleteObject(hpalTmp);
135 }
136//SvL: Shouldn't an app explicitely select the dib section into the hdc?
137// (RealPlayer does this)
138#if 0
139 // Set the hdc in the DIBSection so we can update the palete if a new
140 // Palette etc. gets selected into the DC.
141
142 dsect->SelectDIBObject(hdc);
143#endif
144
145 if(ppvBits!=NULL)
146 *ppvBits = dsect->GetDIBObject();
147
148 pbmi->bmiHeader.biWidth = iWidth;
149 pbmi->bmiHeader.biHeight = iHeight;
150
151 return(res);
152 }
153 }
154
155 /* Error. */
156 if (res)
157 DeleteObject(res);
158 *ppvBits = NULL;
159#ifdef DEBUG
160 dprintf(("GDI32: CreateDIBSection, error!\n"));
161 dprintf(("pbmi->biWidth %d", pbmi->bmiHeader.biWidth));
162 dprintf(("pbmi->biHeight %d", pbmi->bmiHeader.biHeight));
163 dprintf(("pbmi->biBitCount %d", pbmi->bmiHeader.biBitCount));
164#endif
165
166 return 0;
167}
168//******************************************************************************
169//******************************************************************************
170UINT WIN32API GetDIBColorTable( HDC hdc, UINT uStartIndex, UINT cEntries,
171 RGBQUAD *pColors)
172{
173 HPALETTE hpal = GetCurrentObject(hdc, OBJ_PAL);
174 UINT rc;
175 int i;
176
177 rc = O32_GetPaletteEntries(hpal,
178 uStartIndex,
179 cEntries,
180 (PALETTEENTRY *)pColors);
181 for(i=0;
182 i<cEntries;
183 i++)
184 {
185 BYTE tmp;
186 tmp = pColors[i].rgbBlue;
187 pColors[i].rgbBlue = pColors[i].rgbRed;
188 pColors[i].rgbRed = tmp;
189 pColors[i].rgbReserved = 0;
190 }
191 dprintf(("GDI32: GetDIBColorTable returns %d\n", rc));
192 return(rc);
193}
194//******************************************************************************
195//******************************************************************************
196UINT WIN32API SetDIBColorTable(HDC hdc, UINT uStartIndex, UINT cEntries,
197 RGBQUAD *pColors)
198{
199 DIBSection *dsect = DIBSection::findHDC(hdc);
200
201 dprintf(("GDI32: SetDIBColorTable\n"));
202 if(dsect)
203 {
204 return(dsect->SetDIBColorTable(uStartIndex, cEntries, pColors));
205 }
206 else
207 return(0);
208}
209//******************************************************************************
210//******************************************************************************
211LONG WIN32API GetBitmapBits( HBITMAP hBitmap, LONG arg2, PVOID arg3)
212{
213 dprintf(("GDI32: GetBitmapBits %x", hBitmap));
214 return O32_GetBitmapBits(hBitmap, arg2, arg3);
215}
216//******************************************************************************
217//******************************************************************************
218LONG WIN32API SetBitmapBits( HBITMAP hBitmap, LONG arg2, const VOID * arg3)
219{
220 dprintf(("GDI32: SetBitmapBits %x", hBitmap));
221 return O32_SetBitmapBits(hBitmap, (DWORD)arg2, arg3);
222}
223//******************************************************************************
224//******************************************************************************
225BOOL WIN32API GetBitmapDimensionEx( HBITMAP hBitmap, PSIZE pSize)
226{
227 dprintf(("GDI32: GetBitmapDimensionEx %x (%d,%d)", hBitmap, pSize->cx, pSize->cy));
228 return O32_GetBitmapDimensionEx(hBitmap, pSize);
229}
230//******************************************************************************
231//******************************************************************************
232BOOL WIN32API SetBitmapDimensionEx( HBITMAP arg1, int arg2, int arg3, PSIZE arg4)
233{
234 dprintf(("GDI32: SetBitmapDimensionEx"));
235 return O32_SetBitmapDimensionEx(arg1, arg2, arg3, arg4);
236}
237//******************************************************************************
238//******************************************************************************
239int WIN32API GetDIBits(HDC hdc, HBITMAP hBitmap, UINT uStartScan, UINT cScanLines,
240 void *lpvBits, PBITMAPINFO lpbi, UINT uUsage)
241{
242 int rc;
243
244 rc = O32_GetDIBits(hdc, hBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage);
245 dprintf(("GDI32: GetDIBits %x %x %d %d %x %x %d returned %d", hdc, hBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage, rc));
246 return rc;
247}
248//******************************************************************************
249//******************************************************************************
250int WIN32API SetDIBits( HDC arg1, HBITMAP arg2, UINT arg3, UINT arg4, const VOID * arg5, const BITMAPINFO * arg6, UINT arg7)
251{
252 dprintf(("GDI32: SetDIBits %x %x %x %x %x %x %x\n", arg1, arg2, arg3, arg4, arg5, arg6, arg7));
253
254 if(DIBSection::getSection() != NULL)
255 {
256 DIBSection *dsect;
257
258 dsect = DIBSection::find((DWORD)arg2);
259 if(dsect) {
260 return dsect->SetDIBits(arg1, arg2, arg3, arg4, arg5, (BITMAPINFOHEADER_W *)&arg6->bmiHeader, arg7);
261 }
262 }
263 return O32_SetDIBits(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
264}
265//******************************************************************************
266//******************************************************************************
Note: See TracBrowser for help on using the repository browser.