2 * Enhanced MetaFile driver BitBlt functions
4 * Copyright 2002 Huw D M Davies for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "enhmetafiledrv.h"
28 #include "wine/debug.h"
30 BOOL CDECL
EMFDRV_PatBlt( PHYSDEV dev
, INT left
, INT top
,
31 INT width
, INT height
, DWORD rop
)
36 emr
.emr
.iType
= EMR_BITBLT
;
37 emr
.emr
.nSize
= sizeof(emr
);
38 emr
.rclBounds
.left
= left
;
39 emr
.rclBounds
.top
= top
;
40 emr
.rclBounds
.right
= left
+ width
- 1;
41 emr
.rclBounds
.bottom
= top
+ height
- 1;
49 emr
.xformSrc
.eM11
= 1.0;
50 emr
.xformSrc
.eM12
= 0.0;
51 emr
.xformSrc
.eM21
= 0.0;
52 emr
.xformSrc
.eM22
= 1.0;
53 emr
.xformSrc
.eDx
= 0.0;
54 emr
.xformSrc
.eDy
= 0.0;
62 ret
= EMFDRV_WriteRecord( dev
, &emr
.emr
);
64 EMFDRV_UpdateBBox( dev
, &emr
.rclBounds
);
68 /* Utilitarian function used by EMFDRV_BitBlt and EMFDRV_StretchBlt */
70 static BOOL
EMFDRV_BitBlockTransfer(
71 PHYSDEV devDst
, INT xDst
, INT yDst
, INT widthDst
, INT heightDst
,
72 PHYSDEV devSrc
, INT xSrc
, INT ySrc
, INT widthSrc
, INT heightSrc
, DWORD rop
,
83 LPBITMAPINFOHEADER lpBmiH
;
84 EMFDRV_PDEVICE
* physDevSrc
= (EMFDRV_PDEVICE
*)devSrc
;
85 HBITMAP hBitmap
= NULL
;
87 if (emrType
== EMR_BITBLT
)
88 emrSize
= sizeof(EMRBITBLT
);
89 else if (emrType
== EMR_STRETCHBLT
)
90 emrSize
= sizeof(EMRSTRETCHBLT
);
94 hBitmap
= GetCurrentObject(physDevSrc
->hdc
, OBJ_BITMAP
);
96 if(sizeof(BITMAP
) != GetObjectW(hBitmap
, sizeof(BITMAP
), &BM
))
99 nBPP
= BM
.bmPlanes
* BM
.bmBitsPixel
;
100 if(nBPP
> 8) nBPP
= 24; /* FIXME Can't get 16bpp to work for some reason */
101 bitsSize
= DIB_GetDIBWidthBytes(BM
.bmWidth
, nBPP
) * BM
.bmHeight
;
102 bmiSize
= sizeof(BITMAPINFOHEADER
) +
103 (nBPP
<= 8 ? 1 << nBPP
: 0) * sizeof(RGBQUAD
);
105 size
= emrSize
+ bmiSize
+ bitsSize
;
107 pEMR
= HeapAlloc(GetProcessHeap(), 0, size
);
108 if (!pEMR
) return FALSE
;
111 pEMR
->emr
.iType
= emrType
;
112 pEMR
->emr
.nSize
= size
;
113 pEMR
->rclBounds
.left
= xDst
;
114 pEMR
->rclBounds
.top
= yDst
;
115 pEMR
->rclBounds
.right
= xDst
+ widthDst
- 1;
116 pEMR
->rclBounds
.bottom
= yDst
+ heightDst
- 1;
119 pEMR
->cxDest
= widthDst
;
120 pEMR
->cyDest
= heightDst
;
124 GetWorldTransform(physDevSrc
->hdc
, &pEMR
->xformSrc
);
125 pEMR
->crBkColorSrc
= GetBkColor(physDevSrc
->hdc
);
126 pEMR
->iUsageSrc
= DIB_RGB_COLORS
;
127 pEMR
->offBmiSrc
= emrSize
;
128 pEMR
->offBitsSrc
= emrSize
+ bmiSize
;
129 pEMR
->cbBmiSrc
= bmiSize
;
130 pEMR
->cbBitsSrc
= bitsSize
;
131 if (emrType
== EMR_STRETCHBLT
)
133 PEMRSTRETCHBLT pEMRStretch
= (PEMRSTRETCHBLT
)pEMR
;
134 pEMRStretch
->cxSrc
= widthSrc
;
135 pEMRStretch
->cySrc
= heightSrc
;
138 /* Initialize BITMAPINFO structure */
139 lpBmiH
= (LPBITMAPINFOHEADER
)((BYTE
*)pEMR
+ pEMR
->offBmiSrc
);
141 lpBmiH
->biSize
= sizeof(BITMAPINFOHEADER
);
142 lpBmiH
->biWidth
= BM
.bmWidth
;
143 lpBmiH
->biHeight
= BM
.bmHeight
;
144 lpBmiH
->biPlanes
= BM
.bmPlanes
;
145 lpBmiH
->biBitCount
= nBPP
;
146 /* Assume the bitmap isn't compressed and set the BI_RGB flag. */
147 lpBmiH
->biCompression
= BI_RGB
;
148 lpBmiH
->biSizeImage
= bitsSize
;
149 lpBmiH
->biYPelsPerMeter
= 0;
150 lpBmiH
->biXPelsPerMeter
= 0;
151 lpBmiH
->biClrUsed
= nBPP
<= 8 ? 1 << nBPP
: 0;
152 /* Set biClrImportant to 0, indicating that all of the
153 device colors are important. */
154 lpBmiH
->biClrImportant
= 0;
156 /* Initialize bitmap bits */
157 if (GetDIBits(physDevSrc
->hdc
, hBitmap
, 0, (UINT
)lpBmiH
->biHeight
,
158 (BYTE
*)pEMR
+ pEMR
->offBitsSrc
,
159 (LPBITMAPINFO
)lpBmiH
, DIB_RGB_COLORS
))
161 ret
= EMFDRV_WriteRecord(devDst
, (EMR
*)pEMR
);
162 if (ret
) EMFDRV_UpdateBBox(devDst
, &(pEMR
->rclBounds
));
167 HeapFree( GetProcessHeap(), 0, pEMR
);
171 BOOL CDECL
EMFDRV_BitBlt(
172 PHYSDEV devDst
, INT xDst
, INT yDst
, INT width
, INT height
,
173 PHYSDEV devSrc
, INT xSrc
, INT ySrc
, DWORD rop
)
175 return EMFDRV_BitBlockTransfer( devDst
, xDst
, yDst
, width
, height
,
176 devSrc
, xSrc
, ySrc
, width
, height
,
180 BOOL CDECL
EMFDRV_StretchBlt(
181 PHYSDEV devDst
, INT xDst
, INT yDst
, INT widthDst
, INT heightDst
,
182 PHYSDEV devSrc
, INT xSrc
, INT ySrc
, INT widthSrc
, INT heightSrc
, DWORD rop
)
184 return EMFDRV_BitBlockTransfer( devDst
, xDst
, yDst
, widthDst
, heightDst
,
185 devSrc
, xSrc
, ySrc
, widthSrc
, heightSrc
,
186 rop
, EMR_STRETCHBLT
);
189 INT CDECL
EMFDRV_StretchDIBits( PHYSDEV dev
, INT xDst
, INT yDst
, INT widthDst
,
190 INT heightDst
, INT xSrc
, INT ySrc
,
191 INT widthSrc
, INT heightSrc
,
192 const void *bits
, const BITMAPINFO
*info
,
193 UINT wUsage
, DWORD dwRop
)
195 EMRSTRETCHDIBITS
*emr
;
197 UINT bmi_size
=0, bits_size
, emr_size
;
199 bits_size
= DIB_GetDIBImageBytes(info
->bmiHeader
.biWidth
,
200 info
->bmiHeader
.biHeight
,
201 info
->bmiHeader
.biBitCount
);
203 /* calculate the size of the colour table */
204 bmi_size
= bitmap_info_size(info
, wUsage
);
206 emr_size
= sizeof (EMRSTRETCHDIBITS
) + bmi_size
+ bits_size
;
207 emr
= HeapAlloc(GetProcessHeap(), 0, emr_size
);
210 /* write a bitmap info header (with colours) to the record */
211 memcpy( &emr
[1], info
, bmi_size
);
213 /* write bitmap bits to the record */
214 memcpy ( ( (BYTE
*) (&emr
[1]) ) + bmi_size
, bits
, bits_size
);
216 /* fill in the EMR header at the front of our piece of memory */
217 emr
->emr
.iType
= EMR_STRETCHDIBITS
;
218 emr
->emr
.nSize
= emr_size
;
222 emr
->cxDest
= widthDst
;
223 emr
->cyDest
= heightDst
;
225 emr
->xSrc
= xSrc
; /* FIXME: only save the piece of the bitmap needed */
228 emr
->iUsageSrc
= wUsage
;
229 emr
->offBmiSrc
= sizeof (EMRSTRETCHDIBITS
);
230 emr
->cbBmiSrc
= bmi_size
;
231 emr
->offBitsSrc
= emr
->offBmiSrc
+ bmi_size
;
232 emr
->cbBitsSrc
= bits_size
;
234 emr
->cxSrc
= widthSrc
;
235 emr
->cySrc
= heightSrc
;
237 emr
->rclBounds
.left
= xDst
;
238 emr
->rclBounds
.top
= yDst
;
239 emr
->rclBounds
.right
= xDst
+ widthDst
;
240 emr
->rclBounds
.bottom
= yDst
+ heightDst
;
242 /* save the record we just created */
243 ret
= EMFDRV_WriteRecord( dev
, &emr
->emr
);
245 EMFDRV_UpdateBBox( dev
, &emr
->rclBounds
);
247 HeapFree(GetProcessHeap(), 0, emr
);
249 return ret
? heightSrc
: GDI_ERROR
;
252 INT CDECL
EMFDRV_SetDIBitsToDevice(
253 PHYSDEV dev
, INT xDst
, INT yDst
, DWORD width
, DWORD height
,
254 INT xSrc
, INT ySrc
, UINT startscan
, UINT lines
,
255 LPCVOID bits
, const BITMAPINFO
*info
, UINT wUsage
)
257 EMRSETDIBITSTODEVICE
* pEMR
;
258 DWORD size
, bmiSize
, bitsSize
;
260 bmiSize
= bitmap_info_size(info
, wUsage
);
261 bitsSize
= DIB_GetDIBImageBytes( info
->bmiHeader
.biWidth
,
262 info
->bmiHeader
.biHeight
,
263 info
->bmiHeader
.biBitCount
);
264 size
= sizeof(EMRSETDIBITSTODEVICE
) + bmiSize
+ bitsSize
;
266 pEMR
= HeapAlloc(GetProcessHeap(), 0, size
);
269 pEMR
->emr
.iType
= EMR_SETDIBITSTODEVICE
;
270 pEMR
->emr
.nSize
= size
;
271 pEMR
->rclBounds
.left
= xDst
;
272 pEMR
->rclBounds
.top
= yDst
;
273 pEMR
->rclBounds
.right
= xDst
+ width
- 1;
274 pEMR
->rclBounds
.bottom
= yDst
+ height
- 1;
280 pEMR
->cySrc
= height
;
281 pEMR
->offBmiSrc
= sizeof(EMRSETDIBITSTODEVICE
);
282 pEMR
->cbBmiSrc
= bmiSize
;
283 pEMR
->offBitsSrc
= sizeof(EMRSETDIBITSTODEVICE
) + bmiSize
;
284 pEMR
->cbBitsSrc
= bitsSize
;
285 pEMR
->iUsageSrc
= wUsage
;
286 pEMR
->iStartScan
= startscan
;
287 pEMR
->cScans
= lines
;
288 memcpy((BYTE
*)pEMR
+ pEMR
->offBmiSrc
, info
, bmiSize
);
289 memcpy((BYTE
*)pEMR
+ pEMR
->offBitsSrc
, bits
, bitsSize
);
291 if (EMFDRV_WriteRecord(dev
, (EMR
*)pEMR
))
292 EMFDRV_UpdateBBox(dev
, &(pEMR
->rclBounds
));
294 HeapFree( GetProcessHeap(), 0, pEMR
);