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

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

cleaned up + dibsection fixes

File size: 9.5 KB
Line 
1/* $Id: dibitmap.cpp,v 1.1 2000-02-01 12:53:29 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 ULONG Pal[256];
113 char PalSize;
114 LOGPALETTE tmpPal = { 0x300,1,{0,0,0,0}};
115 HPALETTE hpalCur, hpalTmp;
116 DIBSection *dsect = new DIBSection((WINBITMAPINFOHEADER *)&pbmi->bmiHeader, iUsage, (DWORD)res, fFlip);
117
118 if(NULL!=dsect)
119 {
120 PalSize = dsect->GetBitCount();
121 if(PalSize<=8)
122 {
123 // Now get the current Palette from the DC
124 hpalTmp = CreatePalette(&tmpPal);
125 hpalCur = SelectPalette(hdc, hpalTmp, FALSE);
126
127 // and use it to set the DIBColorTable
128 GetPaletteEntries( hpalCur, 0, 1<<PalSize, (LPPALETTEENTRY)&Pal);
129 dsect->SetDIBColorTable(0, 1<< PalSize, (RGBQUAD*)&Pal);
130
131 // Restore the DC Palette
132 SelectPalette(hdc,hpalCur,FALSE);
133 DeleteObject(hpalTmp);
134 }
135//SvL: Shouldn't an app explicitely select the dib section into the hdc?
136// (RealPlayer does this)
137#if 0
138 // Set the hdc in the DIBSection so we can update the palete if a new
139 // Palette etc. gets selected into the DC.
140
141 dsect->SelectDIBObject(hdc);
142#endif
143
144 if(ppvBits!=NULL)
145 *ppvBits = dsect->GetDIBObject();
146
147 pbmi->bmiHeader.biWidth = iWidth;
148 pbmi->bmiHeader.biHeight = iHeight;
149
150 return(res);
151 }
152 }
153
154 /* Error. */
155 if (res)
156 DeleteObject(res);
157 *ppvBits = NULL;
158#ifdef DEBUG
159 dprintf(("GDI32: CreateDIBSection, error!\n"));
160 dprintf(("pbmi->biWidth %d", pbmi->bmiHeader.biWidth));
161 dprintf(("pbmi->biHeight %d", pbmi->bmiHeader.biHeight));
162 dprintf(("pbmi->biBitCount %d", pbmi->bmiHeader.biBitCount));
163#endif
164
165 return 0;
166}
167//******************************************************************************
168//******************************************************************************
169UINT WIN32API GetDIBColorTable( HDC hdc, UINT uStartIndex, UINT cEntries,
170 RGBQUAD *pColors)
171{
172 HPALETTE hpal = O32_GetCurrentObject(hdc, OBJ_PAL);
173 UINT rc;
174 int i;
175
176 rc = O32_GetPaletteEntries(hpal,
177 uStartIndex,
178 cEntries,
179 (PALETTEENTRY *)pColors);
180 for(i=0;
181 i<cEntries;
182 i++)
183 {
184 BYTE tmp;
185 tmp = pColors[i].rgbBlue;
186 pColors[i].rgbBlue = pColors[i].rgbRed;
187 pColors[i].rgbRed = tmp;
188 pColors[i].rgbReserved = 0;
189 }
190 dprintf(("GDI32: GetDIBColorTable returns %d\n", rc));
191 return(rc);
192}
193//******************************************************************************
194//******************************************************************************
195UINT WIN32API SetDIBColorTable(HDC hdc, UINT uStartIndex, UINT cEntries,
196 RGBQUAD *pColors)
197{
198 DIBSection *dsect = DIBSection::findHDC(hdc);
199
200 dprintf(("GDI32: SetDIBColorTable\n"));
201 if(dsect)
202 {
203 return(dsect->SetDIBColorTable(uStartIndex, cEntries, pColors));
204 }
205 else
206 return(0);
207}
208//******************************************************************************
209//******************************************************************************
210LONG WIN32API GetBitmapBits( HBITMAP arg1, LONG arg2, PVOID arg3)
211{
212 dprintf(("GDI32: GetBitmapBits"));
213 return O32_GetBitmapBits(arg1, arg2, arg3);
214}
215//******************************************************************************
216//******************************************************************************
217LONG WIN32API SetBitmapBits( HBITMAP arg1, LONG arg2, const VOID * arg3)
218{
219 dprintf(("GDI32: SetBitmapBits"));
220 return O32_SetBitmapBits(arg1, (DWORD)arg2, arg3);
221}
222//******************************************************************************
223//******************************************************************************
224BOOL WIN32API GetBitmapDimensionEx( HBITMAP arg1, PSIZE arg2)
225{
226 dprintf(("GDI32: GetBitmapDimensionEx"));
227 return O32_GetBitmapDimensionEx(arg1, arg2);
228}
229//******************************************************************************
230//******************************************************************************
231BOOL WIN32API SetBitmapDimensionEx( HBITMAP arg1, int arg2, int arg3, PSIZE arg4)
232{
233 dprintf(("GDI32: SetBitmapDimensionEx"));
234 return O32_SetBitmapDimensionEx(arg1, arg2, arg3, arg4);
235}
236//******************************************************************************
237//******************************************************************************
238int WIN32API GetDIBits(HDC hdc, HBITMAP hBitmap, UINT uStartScan, UINT cScanLines,
239 void *lpvBits, PBITMAPINFO lpbi, UINT uUsage)
240{
241 int rc;
242
243 rc = O32_GetDIBits(hdc, hBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage);
244 dprintf(("GDI32: GetDIBits %x %x %d %d %x %x %d returned %d", hdc, hBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage, rc));
245 return rc;
246}
247//******************************************************************************
248//******************************************************************************
249int WIN32API SetDIBits( HDC arg1, HBITMAP arg2, UINT arg3, UINT arg4, const VOID * arg5, const BITMAPINFO * arg6, UINT arg7)
250{
251 dprintf(("GDI32: SetDIBits %x %x %x %x %x %x %x\n", arg1, arg2, arg3, arg4, arg5, arg6, arg7));
252
253 if(DIBSection::getSection() != NULL) {
254 DIBSection *dsect;
255
256 dsect = DIBSection::find((DWORD)arg2);
257 if(dsect) {
258 return dsect->SetDIBits(arg1, arg2, arg3, arg4, arg5, (WINBITMAPINFOHEADER *)&arg6->bmiHeader, arg7);
259 }
260 }
261 return O32_SetDIBits(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
262}
263//******************************************************************************
264//******************************************************************************
Note: See TracBrowser for help on using the repository browser.