1 | /* $Id: blit.cpp,v 1.1 2000-02-01 12:53:29 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * GDI32 blit 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 | static ULONG QueryPaletteSize(BITMAPINFOHEADER *pBHdr);
|
---|
20 | static ULONG CalcBitmapSize(ULONG cBits, LONG cx, LONG cy);
|
---|
21 |
|
---|
22 | //******************************************************************************
|
---|
23 | //******************************************************************************
|
---|
24 | BOOL WIN32API StretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest,
|
---|
25 | int nWidthDest, int nHeightDest,
|
---|
26 | HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
|
---|
27 | int nWidthSrc, int nHeightSrc, DWORD dwRop)
|
---|
28 | {
|
---|
29 | BOOL rc;
|
---|
30 |
|
---|
31 | dprintf(("GDI32: StretchBlt Dest: %x (%d, %d) size (%d, %d)\n",
|
---|
32 | hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest));
|
---|
33 | dprintf(("GDI32: StretchBlt Src : %x (%d, %d) size (%d, %d)\n",
|
---|
34 | hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc));
|
---|
35 | if(DIBSection::getSection() != NULL)
|
---|
36 | {
|
---|
37 | DIBSection *dsect = DIBSection::findHDC(hdcSrc);
|
---|
38 | if(dsect)
|
---|
39 | {
|
---|
40 | dprintf((" Do stretched DIB Blt\n"));
|
---|
41 | rc = dsect->BitBlt( hdcDest,
|
---|
42 | nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
|
---|
43 | nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
|
---|
44 | dwRop);
|
---|
45 | return rc;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | return O32_StretchBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, dwRop);
|
---|
49 | }
|
---|
50 | //******************************************************************************
|
---|
51 | //******************************************************************************
|
---|
52 | BOOL WIN32API BitBlt(HDC hdcDest, int arg2, int arg3, int arg4, int arg5, HDC hdcSrc, int arg7, int arg8, DWORD arg9)
|
---|
53 | {
|
---|
54 | BOOL rc;
|
---|
55 |
|
---|
56 | if(DIBSection::getSection() != NULL) {
|
---|
57 | DIBSection *dsect = DIBSection::findHDC(hdcSrc);
|
---|
58 | if(dsect) {
|
---|
59 | rc = dsect->BitBlt(hdcDest, arg2, arg3, arg4, arg5, arg7, arg8, arg4, arg5, arg9);
|
---|
60 | if(rc) {
|
---|
61 | BITMAPINFO bmpinfo = {0};
|
---|
62 | DIBSection *dest = DIBSection::findHDC(hdcDest);
|
---|
63 | if(dest) {
|
---|
64 | dprintf(("Sync dest DIB section"));
|
---|
65 | bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
---|
66 | GetDIBits(hdcDest, dest->GetBitmapHandle(), 0, 300, 0, &bmpinfo, dest->GetRGBUsage());
|
---|
67 | dprintf(("height %d", bmpinfo.bmiHeader.biHeight));
|
---|
68 | dprintf(("width %d", bmpinfo.bmiHeader.biWidth));
|
---|
69 | dprintf(("biBitCount %d", bmpinfo.bmiHeader.biBitCount));
|
---|
70 | GetDIBits(hdcDest, dest->GetBitmapHandle(), 0, 300, dest->GetDIBObject(), &bmpinfo, dest->GetRGBUsage());
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | dprintf(("GDI32: BitBlt to hdc %X from (%d,%d) to (%d,%d), (%d,%d) rop %X\n", hdcDest, arg7, arg8, arg2, arg3, arg4, arg5, arg9));
|
---|
76 | return O32_BitBlt(hdcDest, arg2, arg3, arg4, arg5, hdcSrc, arg7, arg8, arg9);
|
---|
77 | }
|
---|
78 | //******************************************************************************
|
---|
79 | //******************************************************************************
|
---|
80 | INT WIN32API SetDIBitsToDevice(HDC hdc, INT xDest, INT yDest, DWORD cx,
|
---|
81 | DWORD cy, INT xSrc, INT ySrc,
|
---|
82 | UINT startscan, UINT lines, LPCVOID bits,
|
---|
83 | const BITMAPINFO *info, UINT coloruse)
|
---|
84 | {
|
---|
85 | INT result, imgsize, palsize, height, width;
|
---|
86 | char *ptr;
|
---|
87 |
|
---|
88 | SetLastError(0);
|
---|
89 | if(info == NULL) {
|
---|
90 | goto invalid_parameter;
|
---|
91 | }
|
---|
92 | height = info->bmiHeader.biHeight;
|
---|
93 | width = info->bmiHeader.biWidth;
|
---|
94 |
|
---|
95 | if (height < 0) height = -height;
|
---|
96 | if (!lines || (startscan >= height)) {
|
---|
97 | goto invalid_parameter;
|
---|
98 | }
|
---|
99 | if (startscan + lines > height) lines = height - startscan;
|
---|
100 |
|
---|
101 | if (ySrc < startscan) ySrc = startscan;
|
---|
102 | else if (ySrc >= startscan + lines) goto invalid_parameter;
|
---|
103 |
|
---|
104 | if (xSrc >= width) goto invalid_parameter;
|
---|
105 |
|
---|
106 | if (ySrc + cy >= startscan + lines) cy = startscan + lines - ySrc;
|
---|
107 |
|
---|
108 | if (xSrc + cx >= width) cx = width - xSrc;
|
---|
109 |
|
---|
110 | if (!cx || !cy) goto invalid_parameter;
|
---|
111 |
|
---|
112 | // EB: ->>> Crazy. Nobody seen this Open32 bug ?
|
---|
113 | // Dont't like dirty pointers, but Open32 needs a bit help.
|
---|
114 | // Only tested with winmine.
|
---|
115 | palsize = QueryPaletteSize((BITMAPINFOHEADER*)&info->bmiHeader);
|
---|
116 | imgsize = CalcBitmapSize(info->bmiHeader.biBitCount,
|
---|
117 | info->bmiHeader.biWidth, info->bmiHeader.biHeight);
|
---|
118 | ptr = ((char *)info) + palsize + sizeof(BITMAPINFOHEADER);
|
---|
119 | if(bits >= ptr && bits < ptr + imgsize)
|
---|
120 | {
|
---|
121 | bits = (char *)bits - imgsize +
|
---|
122 | CalcBitmapSize(info->bmiHeader.biBitCount,
|
---|
123 | info->bmiHeader.biWidth, lines);
|
---|
124 | }
|
---|
125 | // EB: <<<-
|
---|
126 |
|
---|
127 | //SvL: Ignore BI_BITFIELDS type (SetDIBitsToDevice fails otherwise)
|
---|
128 | if(info->bmiHeader.biCompression == BI_BITFIELDS)
|
---|
129 | ((BITMAPINFO *)info)->bmiHeader.biCompression = 0;
|
---|
130 | if(info->bmiHeader.biHeight < 0)
|
---|
131 | ((BITMAPINFO *)info)->bmiHeader.biHeight = -info->bmiHeader.biHeight;
|
---|
132 |
|
---|
133 | // result = OSLibSetDIBitsToDevice(hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (PVOID) bits, (WINBITMAPINFOHEADER *)info, coloruse);
|
---|
134 | // result = 1;
|
---|
135 | result = O32_SetDIBitsToDevice(hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (PVOID) bits, (PBITMAPINFO)info, coloruse);
|
---|
136 | //SvL: Wrong Open32 return value
|
---|
137 | result = (result == TRUE) ? lines : 0;
|
---|
138 |
|
---|
139 | dprintf(("GDI32: SetDIBitsToDevice hdc:%X xDest:%d yDest:%d, cx:%d, cy:%d, xSrc:%d, ySrc:%d, startscan:%d, lines:%d \nGDI32: bits:%X, info%X, coloruse:%d returned %d",
|
---|
140 | hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (LPVOID) bits, (PBITMAPINFO)info, coloruse, result));
|
---|
141 | dprintf(("GDI32: SetDIBitsToDevice %d %d %d %d %x %d", info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biPlanes, info->bmiHeader.biBitCount, info->bmiHeader.biCompression, info->bmiHeader.biSizeImage));
|
---|
142 |
|
---|
143 | return result;
|
---|
144 |
|
---|
145 | invalid_parameter:
|
---|
146 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
147 | return 0;
|
---|
148 | }
|
---|
149 | //******************************************************************************
|
---|
150 | //******************************************************************************
|
---|
151 | BOOL WIN32API PatBlt(HDC hdc,int nXLeft,int nYLeft,int nWidth,int nHeight,DWORD dwRop)
|
---|
152 | {
|
---|
153 | BOOL rc;
|
---|
154 |
|
---|
155 | //CB: Open32 bug: negative width/height not supported!
|
---|
156 | if (nWidth < 0)
|
---|
157 | {
|
---|
158 | nXLeft += nWidth+1;
|
---|
159 | nWidth = -nWidth;
|
---|
160 | }
|
---|
161 | if (nHeight < 0)
|
---|
162 | {
|
---|
163 | nYLeft += nHeight+1;
|
---|
164 | nHeight = -nHeight;
|
---|
165 | }
|
---|
166 | rc = O32_PatBlt(hdc,nXLeft,nYLeft,nWidth,nHeight,dwRop);
|
---|
167 | dprintf(("GDI32: PatBlt (%d,%d) (%d,%d) returned %d\n",nXLeft,nYLeft,nWidth,nHeight,rc));
|
---|
168 | return(rc);
|
---|
169 | }
|
---|
170 | //******************************************************************************
|
---|
171 | //******************************************************************************
|
---|
172 | BOOL WIN32API MaskBlt( HDC arg1, int arg2, int arg3, int arg4, int arg5, HDC arg6, int arg7, int arg8, HBITMAP arg9, int arg10, int arg11, DWORD arg12)
|
---|
173 | {
|
---|
174 | dprintf(("GDI32: MaskBlt"));
|
---|
175 | return O32_MaskBlt(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
|
---|
176 | }
|
---|
177 | //******************************************************************************
|
---|
178 | //******************************************************************************
|
---|
179 | BOOL WIN32API PlgBlt(HDC hdcDest, CONST POINT *lpPoint, HDC hdcSrc, int nXSrc,
|
---|
180 | int nYSrc, int nWidth, int nHeight, HBITMAP hbmMask,
|
---|
181 | int xMast, int yMask)
|
---|
182 | {
|
---|
183 | dprintf(("GDI32: PlgBlt, not implemented\n"));
|
---|
184 | return(FALSE);
|
---|
185 | }
|
---|
186 | //******************************************************************************
|
---|
187 | //******************************************************************************
|
---|
188 | int WIN32API SetStretchBltMode( HDC arg1, int arg2)
|
---|
189 | {
|
---|
190 | dprintf(("GDI32: SetStretchBltMode 0x%08X, 0x%08X\n",arg1, arg2));
|
---|
191 |
|
---|
192 | if(DIBSection::getSection() != NULL)
|
---|
193 | {
|
---|
194 | DIBSection *dsect = DIBSection::findHDC(arg1);
|
---|
195 | if(dsect)
|
---|
196 | {
|
---|
197 | dprintf((" - DC is DIBSection\n"));
|
---|
198 | }
|
---|
199 | }
|
---|
200 | return O32_SetStretchBltMode(arg1, arg2);
|
---|
201 | }
|
---|
202 | //******************************************************************************
|
---|
203 | //******************************************************************************
|
---|
204 | int WIN32API GetStretchBltMode( HDC arg1)
|
---|
205 | {
|
---|
206 | dprintf(("GDI32: GetStretchBltMode"));
|
---|
207 | return O32_GetStretchBltMode(arg1);
|
---|
208 | }
|
---|
209 | //******************************************************************************
|
---|
210 | //******************************************************************************
|
---|
211 | static ULONG QueryPaletteSize(BITMAPINFOHEADER *pBHdr)
|
---|
212 | {
|
---|
213 | ULONG cbPalette;
|
---|
214 |
|
---|
215 | switch (pBHdr->biBitCount)
|
---|
216 | {
|
---|
217 | case 1:
|
---|
218 | case 4:
|
---|
219 | case 8:
|
---|
220 | cbPalette = (1 << pBHdr->biBitCount) * sizeof(RGBQUAD);
|
---|
221 | break;
|
---|
222 |
|
---|
223 | case 16:
|
---|
224 | case 24:
|
---|
225 | case 32:
|
---|
226 | cbPalette = 0;
|
---|
227 | break;
|
---|
228 |
|
---|
229 | default:
|
---|
230 | dprintf(("QueryPaletteSize: error pBHdr->biBitCount = %d", pBHdr->biBitCount));
|
---|
231 | cbPalette = -1;
|
---|
232 | }
|
---|
233 |
|
---|
234 | return cbPalette;
|
---|
235 | }
|
---|
236 | //******************************************************************************
|
---|
237 | //******************************************************************************
|
---|
238 | static ULONG CalcBitmapSize(ULONG cBits, LONG cx, LONG cy)
|
---|
239 | {
|
---|
240 | ULONG alignment;
|
---|
241 | ULONG factor;
|
---|
242 | BOOL flag = TRUE; //true: '*' false: '/'
|
---|
243 |
|
---|
244 | cy = cy < 0 ? -cy : cy;
|
---|
245 |
|
---|
246 | switch(cBits)
|
---|
247 | {
|
---|
248 | case 1:
|
---|
249 | factor = 8;
|
---|
250 | flag = FALSE;
|
---|
251 | break;
|
---|
252 |
|
---|
253 | case 4:
|
---|
254 | factor = 2;
|
---|
255 | flag = FALSE;
|
---|
256 | break;
|
---|
257 |
|
---|
258 | case 8:
|
---|
259 | factor = 1;
|
---|
260 | break;
|
---|
261 |
|
---|
262 | case 16:
|
---|
263 | factor = 2;
|
---|
264 | break;
|
---|
265 |
|
---|
266 | case 24:
|
---|
267 | factor = 3;
|
---|
268 | break;
|
---|
269 |
|
---|
270 | case 32:
|
---|
271 | return cx*cy;
|
---|
272 |
|
---|
273 | default:
|
---|
274 | return 0;
|
---|
275 | }
|
---|
276 |
|
---|
277 | if (flag)
|
---|
278 | alignment = (cx = (cx*factor)) % 4;
|
---|
279 | else
|
---|
280 | alignment = (cx = ((cx+factor-1)/factor)) % 4;
|
---|
281 |
|
---|
282 | if (alignment != 0)
|
---|
283 | cx += 4 - alignment;
|
---|
284 |
|
---|
285 | return cx*cy;
|
---|
286 | }
|
---|
287 | //******************************************************************************
|
---|
288 | //******************************************************************************
|
---|