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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "enhmetafiledrv.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
33 BOOL EMFDRV_PatBlt( PHYSDEV dev, INT left, INT top,
34 INT width, INT height, DWORD rop )
39 emr.emr.iType = EMR_BITBLT;
40 emr.emr.nSize = sizeof(emr);
41 emr.rclBounds.left = left;
42 emr.rclBounds.top = top;
43 emr.rclBounds.right = left + width - 1;
44 emr.rclBounds.bottom = top + height - 1;
52 emr.xformSrc.eM11 = 1.0;
53 emr.xformSrc.eM12 = 0.0;
54 emr.xformSrc.eM21 = 0.0;
55 emr.xformSrc.eM22 = 1.0;
56 emr.xformSrc.eDx = 0.0;
57 emr.xformSrc.eDy = 0.0;
65 ret = EMFDRV_WriteRecord( dev, &emr.emr );
67 EMFDRV_UpdateBBox( dev, &emr.rclBounds );
71 /* Utilitarian function used by EMFDRV_BitBlt and EMFDRV_StretchBlt */
73 static BOOL EMFDRV_BitBlockTransfer(
74 PHYSDEV devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,
75 PHYSDEV devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, DWORD rop,
86 LPBITMAPINFOHEADER lpBmiH;
87 EMFDRV_PDEVICE* physDevSrc = (EMFDRV_PDEVICE*)devSrc;
88 HBITMAP hBitmap = GetCurrentObject(physDevSrc->hdc, OBJ_BITMAP);
90 if (emrType == EMR_BITBLT)
91 emrSize = sizeof(EMRBITBLT);
92 else if (emrType == EMR_STRETCHBLT)
93 emrSize = sizeof(EMRSTRETCHBLT);
97 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 */
102 bitsSize = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight;
103 bmiSize = sizeof(BITMAPINFOHEADER) +
104 (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 pEMR->xformSrc.eM11 = 1.0; /** FIXME: */
125 pEMR->xformSrc.eM12 = 0.0; /** Setting default */
126 pEMR->xformSrc.eM21 = 0.0; /** value. */
127 pEMR->xformSrc.eM22 = 1.0; /** Where should we */
128 pEMR->xformSrc.eDx = 0.0; /** get that info */
129 pEMR->xformSrc.eDy = 0.0; /** ???? */
130 pEMR->crBkColorSrc = GetBkColor(physDevSrc->hdc);
131 pEMR->iUsageSrc = DIB_RGB_COLORS;
132 pEMR->offBmiSrc = emrSize;
133 pEMR->cbBmiSrc = bmiSize;
134 pEMR->offBitsSrc = emrSize + bmiSize;
135 pEMR->cbBitsSrc = bitsSize;
136 if (emrType == EMR_STRETCHBLT)
138 PEMRSTRETCHBLT pEMRStretch = (PEMRSTRETCHBLT)pEMR;
139 pEMRStretch->cxSrc = widthSrc;
140 pEMRStretch->cySrc = heightSrc;
143 /* Initialize BITMAPINFO structure */
144 lpBmiH = (LPBITMAPINFOHEADER)((BYTE*)pEMR + pEMR->offBmiSrc);
146 lpBmiH->biSize = sizeof(BITMAPINFOHEADER);
147 lpBmiH->biWidth = BM.bmWidth;
148 lpBmiH->biHeight = BM.bmHeight;
149 lpBmiH->biPlanes = BM.bmPlanes;
150 lpBmiH->biBitCount = nBPP;
151 /* Assume the bitmap isn't compressed and set the BI_RGB flag. */
152 lpBmiH->biCompression = BI_RGB;
153 lpBmiH->biSizeImage = bitsSize;
154 lpBmiH->biYPelsPerMeter = /* 1 meter = 39.37 inch */
155 MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSX),3937,100);
156 lpBmiH->biXPelsPerMeter =
157 MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSY),3937,100);
158 lpBmiH->biClrUsed = nBPP <= 8 ? 1 << nBPP : 0;
159 /* Set biClrImportant to 0, indicating that all of the
160 device colors are important. */
161 lpBmiH->biClrImportant = 0;
163 /* Initiliaze bitmap bits */
164 if (GetDIBits(physDevSrc->hdc, hBitmap, 0, (UINT)lpBmiH->biHeight,
165 (BYTE*)pEMR + pEMR->offBitsSrc,
166 (LPBITMAPINFO)lpBmiH, DIB_RGB_COLORS))
168 ret = EMFDRV_WriteRecord(devDst, (EMR*)pEMR);
169 if (ret) EMFDRV_UpdateBBox(devDst, &(pEMR->rclBounds));
174 HeapFree( GetProcessHeap(), 0, pEMR);
179 PHYSDEV devDst, INT xDst, INT yDst, INT width, INT height,
180 PHYSDEV devSrc, INT xSrc, INT ySrc, DWORD rop)
182 return EMFDRV_BitBlockTransfer( devDst, xDst, yDst, width, height,
183 devSrc, xSrc, ySrc, width, height,
187 BOOL EMFDRV_StretchBlt(
188 PHYSDEV devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,
189 PHYSDEV devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, DWORD rop )
191 return EMFDRV_BitBlockTransfer( devDst, xDst, yDst, widthDst, heightDst,
192 devSrc, xSrc, ySrc, widthSrc, heightSrc,
193 rop, EMR_STRETCHBLT );
196 INT EMFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
197 INT heightDst, INT xSrc, INT ySrc,
198 INT widthSrc, INT heightSrc,
199 const void *bits, const BITMAPINFO *info,
200 UINT wUsage, DWORD dwRop )
202 EMRSTRETCHDIBITS *emr;
204 UINT bmi_size=0, bits_size, emr_size;
206 bits_size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
207 info->bmiHeader.biHeight,
208 info->bmiHeader.biBitCount);
210 /* calculate the size of the colour table */
211 bmi_size = DIB_BitmapInfoSize(info, wUsage);
213 emr_size = sizeof (EMRSTRETCHDIBITS) + bmi_size + bits_size;
214 emr = HeapAlloc(GetProcessHeap(), 0, emr_size );
217 /* write a bitmap info header (with colours) to the record */
218 memcpy( &emr[1], info, bmi_size);
220 /* write bitmap bits to the record */
221 memcpy ( ( (BYTE *) (&emr[1]) ) + bmi_size, bits, bits_size);
223 /* fill in the EMR header at the front of our piece of memory */
224 emr->emr.iType = EMR_STRETCHDIBITS;
225 emr->emr.nSize = emr_size;
229 emr->cxDest = widthDst;
230 emr->cyDest = heightDst;
232 emr->xSrc = xSrc; /* FIXME: only save the piece of the bitmap needed */
235 emr->iUsageSrc = wUsage;
236 emr->offBmiSrc = sizeof (EMRSTRETCHDIBITS);
237 emr->cbBmiSrc = bmi_size;
238 emr->offBitsSrc = emr->offBmiSrc + bmi_size;
239 emr->cbBitsSrc = bits_size;
241 emr->cxSrc = widthSrc;
242 emr->cySrc = heightSrc;
244 emr->rclBounds.left = xDst;
245 emr->rclBounds.top = yDst;
246 emr->rclBounds.right = xDst + widthDst;
247 emr->rclBounds.bottom = yDst + heightDst;
249 /* save the record we just created */
250 ret = EMFDRV_WriteRecord( dev, &emr->emr );
252 EMFDRV_UpdateBBox( dev, &emr->rclBounds );
254 HeapFree(GetProcessHeap(), 0, emr);
259 INT EMFDRV_SetDIBitsToDevice(
260 PHYSDEV dev, INT xDst, INT yDst, DWORD width, DWORD height,
261 INT xSrc, INT ySrc, UINT startscan, UINT lines,
262 LPCVOID bits, const BITMAPINFO *info, UINT wUsage )
264 EMRSETDIBITSTODEVICE* pEMR;
265 DWORD size, bmiSize, bitsSize;
267 bmiSize = DIB_BitmapInfoSize(info, wUsage);
268 bitsSize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
269 info->bmiHeader.biHeight,
270 info->bmiHeader.biBitCount );
271 size = sizeof(EMRSETDIBITSTODEVICE) + bmiSize + bitsSize;
273 pEMR = HeapAlloc(GetProcessHeap(), 0, size);
276 pEMR->emr.iType = EMR_SETDIBITSTODEVICE;
277 pEMR->emr.nSize = size;
278 pEMR->rclBounds.left = xDst;
279 pEMR->rclBounds.top = yDst;
280 pEMR->rclBounds.right = xDst + width - 1;
281 pEMR->rclBounds.bottom = yDst + height - 1;
287 pEMR->cySrc = height;
288 pEMR->offBmiSrc = sizeof(EMRSETDIBITSTODEVICE);
289 pEMR->cbBmiSrc = bmiSize;
290 pEMR->offBitsSrc = sizeof(EMRSETDIBITSTODEVICE) + bmiSize;
291 pEMR->cbBitsSrc = bitsSize;
292 pEMR->iUsageSrc = wUsage;
293 pEMR->iStartScan = startscan;
294 pEMR->cScans = lines;
295 memcpy((BYTE*)pEMR + pEMR->offBmiSrc, info, bmiSize);
296 memcpy((BYTE*)pEMR + pEMR->offBitsSrc, bits, bitsSize);
298 if (EMFDRV_WriteRecord(dev, (EMR*)pEMR))
299 EMFDRV_UpdateBBox(dev, &(pEMR->rclBounds));
301 HeapFree( GetProcessHeap(), 0, pEMR);