1 | /* $Id: dibitmap.cpp,v 1.3 2000-02-10 00:36:10 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 | //******************************************************************************
|
---|
21 | HBITMAP 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 | //******************************************************************************
|
---|
46 | HBITMAP 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 | //******************************************************************************
|
---|
54 | HBITMAP WIN32API CreateDiscardableBitmap(HDC hDC, int nWidth, int nHeight)
|
---|
55 | {
|
---|
56 | dprintf(("GDI32: CreateDisardableBitmap\n"));
|
---|
57 | return O32_CreateCompatibleBitmap(hDC, nWidth, nHeight);
|
---|
58 | }
|
---|
59 | //******************************************************************************
|
---|
60 | //******************************************************************************
|
---|
61 | HBITMAP 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 | //******************************************************************************
|
---|
72 | HBITMAP WIN32API CreateBitmapIndirect( const BITMAP * arg1)
|
---|
73 | {
|
---|
74 | dprintf(("GDI32: CreateBitmapIndirect"));
|
---|
75 | return O32_CreateBitmapIndirect(arg1);
|
---|
76 | }
|
---|
77 | //******************************************************************************
|
---|
78 | //*********************************************************************************
|
---|
79 | HBITMAP 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 |
|
---|
88 | //SvL: 13-9-98: StarCraft uses bitmap with negative height
|
---|
89 | iWidth = pbmi->bmiHeader.biWidth;
|
---|
90 | if(pbmi->bmiHeader.biWidth < 0)
|
---|
91 | {
|
---|
92 | dprintf(("CreateDIBSection: width %d", pbmi->bmiHeader.biWidth));
|
---|
93 | pbmi->bmiHeader.biWidth = -pbmi->bmiHeader.biWidth;
|
---|
94 | fFlip = FLIP_HOR;
|
---|
95 | }
|
---|
96 | iHeight = pbmi->bmiHeader.biHeight;
|
---|
97 | if(pbmi->bmiHeader.biHeight < 0)
|
---|
98 | {
|
---|
99 | dprintf(("CreateDIBSection: height %d", pbmi->bmiHeader.biHeight));
|
---|
100 | pbmi->bmiHeader.biHeight = -pbmi->bmiHeader.biHeight;
|
---|
101 | fFlip |= FLIP_VERT;
|
---|
102 | }
|
---|
103 |
|
---|
104 | res = O32_CreateDIBitmap(hdc, &pbmi->bmiHeader, 0, NULL, pbmi, iUsage);
|
---|
105 | if (res)
|
---|
106 | {
|
---|
107 | char PalSize;
|
---|
108 | DIBSection *dsect;
|
---|
109 |
|
---|
110 | dsect = new DIBSection((BITMAPINFOHEADER_W *)&pbmi->bmiHeader, (char *)&pbmi->bmiColors, iUsage, hSection, dwOffset, (DWORD)res, fFlip);
|
---|
111 |
|
---|
112 | if(dsect != NULL)
|
---|
113 | {
|
---|
114 | PalSize = dsect->GetBitCount();
|
---|
115 | if(PalSize <= 8)
|
---|
116 | {
|
---|
117 | ULONG Pal[256];
|
---|
118 | LOGPALETTE tmpPal = { 0x300,1,{0,0,0,0}};
|
---|
119 | HPALETTE hpalCur, hpalTmp;
|
---|
120 |
|
---|
121 | // Now get the current Palette from the DC
|
---|
122 | hpalTmp = CreatePalette(&tmpPal);
|
---|
123 | hpalCur = SelectPalette(hdc, hpalTmp, FALSE);
|
---|
124 |
|
---|
125 | // and use it to set the DIBColorTable
|
---|
126 | GetPaletteEntries( hpalCur, 0, 1<<PalSize, (LPPALETTEENTRY)&Pal);
|
---|
127 | dsect->SetDIBColorTable(0, 1<< PalSize, (RGBQUAD*)&Pal);
|
---|
128 |
|
---|
129 | // Restore the DC Palette
|
---|
130 | SelectPalette(hdc,hpalCur,FALSE);
|
---|
131 | DeleteObject(hpalTmp);
|
---|
132 | }
|
---|
133 | //SvL: Shouldn't an app explicitely select the dib section into the hdc?
|
---|
134 | // (RealPlayer does this)
|
---|
135 | #if 0
|
---|
136 | // Set the hdc in the DIBSection so we can update the palete if a new
|
---|
137 | // Palette etc. gets selected into the DC.
|
---|
138 |
|
---|
139 | dsect->SelectDIBObject(hdc);
|
---|
140 | #endif
|
---|
141 |
|
---|
142 | if(ppvBits!=NULL)
|
---|
143 | *ppvBits = dsect->GetDIBObject();
|
---|
144 |
|
---|
145 | pbmi->bmiHeader.biWidth = iWidth;
|
---|
146 | pbmi->bmiHeader.biHeight = iHeight;
|
---|
147 |
|
---|
148 | return(res);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | /* Error. */
|
---|
153 | if (res)
|
---|
154 | DeleteObject(res);
|
---|
155 | *ppvBits = NULL;
|
---|
156 | #ifdef DEBUG
|
---|
157 | dprintf(("GDI32: CreateDIBSection, error!\n"));
|
---|
158 | dprintf(("pbmi->biWidth %d", pbmi->bmiHeader.biWidth));
|
---|
159 | dprintf(("pbmi->biHeight %d", pbmi->bmiHeader.biHeight));
|
---|
160 | dprintf(("pbmi->biBitCount %d", pbmi->bmiHeader.biBitCount));
|
---|
161 | #endif
|
---|
162 |
|
---|
163 | return 0;
|
---|
164 | }
|
---|
165 | //******************************************************************************
|
---|
166 | //******************************************************************************
|
---|
167 | UINT WIN32API GetDIBColorTable( HDC hdc, UINT uStartIndex, UINT cEntries,
|
---|
168 | RGBQUAD *pColors)
|
---|
169 | {
|
---|
170 | HPALETTE hpal = GetCurrentObject(hdc, OBJ_PAL);
|
---|
171 | UINT rc;
|
---|
172 | int i;
|
---|
173 |
|
---|
174 | rc = O32_GetPaletteEntries(hpal,
|
---|
175 | uStartIndex,
|
---|
176 | cEntries,
|
---|
177 | (PALETTEENTRY *)pColors);
|
---|
178 | for(i=0;
|
---|
179 | i<cEntries;
|
---|
180 | i++)
|
---|
181 | {
|
---|
182 | BYTE tmp;
|
---|
183 | tmp = pColors[i].rgbBlue;
|
---|
184 | pColors[i].rgbBlue = pColors[i].rgbRed;
|
---|
185 | pColors[i].rgbRed = tmp;
|
---|
186 | pColors[i].rgbReserved = 0;
|
---|
187 | }
|
---|
188 | dprintf(("GDI32: GetDIBColorTable returns %d\n", rc));
|
---|
189 | return(rc);
|
---|
190 | }
|
---|
191 | //******************************************************************************
|
---|
192 | //******************************************************************************
|
---|
193 | UINT WIN32API SetDIBColorTable(HDC hdc, UINT uStartIndex, UINT cEntries,
|
---|
194 | RGBQUAD *pColors)
|
---|
195 | {
|
---|
196 | DIBSection *dsect = DIBSection::findHDC(hdc);
|
---|
197 |
|
---|
198 | dprintf(("GDI32: SetDIBColorTable\n"));
|
---|
199 | if(dsect)
|
---|
200 | {
|
---|
201 | return(dsect->SetDIBColorTable(uStartIndex, cEntries, pColors));
|
---|
202 | }
|
---|
203 | else
|
---|
204 | return(0);
|
---|
205 | }
|
---|
206 | //******************************************************************************
|
---|
207 | //******************************************************************************
|
---|
208 | LONG WIN32API GetBitmapBits( HBITMAP hBitmap, LONG arg2, PVOID arg3)
|
---|
209 | {
|
---|
210 | dprintf(("GDI32: GetBitmapBits %x", hBitmap));
|
---|
211 | return O32_GetBitmapBits(hBitmap, arg2, arg3);
|
---|
212 | }
|
---|
213 | //******************************************************************************
|
---|
214 | //******************************************************************************
|
---|
215 | LONG WIN32API SetBitmapBits( HBITMAP hBitmap, LONG arg2, const VOID * arg3)
|
---|
216 | {
|
---|
217 | dprintf(("GDI32: SetBitmapBits %x", hBitmap));
|
---|
218 | return O32_SetBitmapBits(hBitmap, (DWORD)arg2, arg3);
|
---|
219 | }
|
---|
220 | //******************************************************************************
|
---|
221 | //******************************************************************************
|
---|
222 | BOOL WIN32API GetBitmapDimensionEx( HBITMAP hBitmap, PSIZE pSize)
|
---|
223 | {
|
---|
224 | dprintf(("GDI32: GetBitmapDimensionEx %x (%d,%d)", hBitmap, pSize->cx, pSize->cy));
|
---|
225 | return O32_GetBitmapDimensionEx(hBitmap, pSize);
|
---|
226 | }
|
---|
227 | //******************************************************************************
|
---|
228 | //******************************************************************************
|
---|
229 | BOOL WIN32API SetBitmapDimensionEx( HBITMAP arg1, int arg2, int arg3, PSIZE arg4)
|
---|
230 | {
|
---|
231 | dprintf(("GDI32: SetBitmapDimensionEx"));
|
---|
232 | return O32_SetBitmapDimensionEx(arg1, arg2, arg3, arg4);
|
---|
233 | }
|
---|
234 | //******************************************************************************
|
---|
235 | //******************************************************************************
|
---|
236 | int WIN32API GetDIBits(HDC hdc, HBITMAP hBitmap, UINT uStartScan, UINT cScanLines,
|
---|
237 | void *lpvBits, PBITMAPINFO lpbi, UINT uUsage)
|
---|
238 | {
|
---|
239 | int rc;
|
---|
240 |
|
---|
241 | rc = O32_GetDIBits(hdc, hBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage);
|
---|
242 | dprintf(("GDI32: GetDIBits %x %x %d %d %x %x %d returned %d", hdc, hBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage, rc));
|
---|
243 | return rc;
|
---|
244 | }
|
---|
245 | //******************************************************************************
|
---|
246 | //******************************************************************************
|
---|
247 | int WIN32API SetDIBits( HDC arg1, HBITMAP arg2, UINT arg3, UINT arg4, const VOID * arg5, const BITMAPINFO * arg6, UINT arg7)
|
---|
248 | {
|
---|
249 | dprintf(("GDI32: SetDIBits %x %x %x %x %x %x %x\n", arg1, arg2, arg3, arg4, arg5, arg6, arg7));
|
---|
250 |
|
---|
251 | if(DIBSection::getSection() != NULL)
|
---|
252 | {
|
---|
253 | DIBSection *dsect;
|
---|
254 |
|
---|
255 | dsect = DIBSection::find((DWORD)arg2);
|
---|
256 | if(dsect) {
|
---|
257 | return dsect->SetDIBits(arg1, arg2, arg3, arg4, arg5, (BITMAPINFOHEADER_W *)&arg6->bmiHeader, arg7);
|
---|
258 | }
|
---|
259 | }
|
---|
260 | return O32_SetDIBits(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
|
---|
261 | }
|
---|
262 | //******************************************************************************
|
---|
263 | //******************************************************************************
|
---|