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

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

Added new logging feature

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