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 BOOL CDECL EMFDRV_StretchBlt( PHYSDEV devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,
69 PHYSDEV devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, DWORD rop )
79 LPBITMAPINFOHEADER lpBmiH;
80 HBITMAP hBitmap = NULL;
83 if (devSrc->funcs == devDst->funcs) return FALSE; /* can't use a metafile DC as source */
85 if (widthSrc == widthDst && heightSrc == heightDst)
88 emrSize = sizeof(EMRBITBLT);
92 emrType = EMR_STRETCHBLT;
93 emrSize = sizeof(EMRSTRETCHBLT);
96 hBitmap = GetCurrentObject(devSrc->hdc, OBJ_BITMAP);
98 if(sizeof(BITMAP) != GetObjectW(hBitmap, sizeof(BITMAP), &BM))
101 nBPP = BM.bmPlanes * BM.bmBitsPixel;
102 if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */
103 bitsSize = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight;
104 bmiSize = sizeof(BITMAPINFOHEADER) +
105 (nBPP <= 8 ? 1 << nBPP : 0) * sizeof(RGBQUAD);
107 size = emrSize + bmiSize + bitsSize;
109 pEMR = HeapAlloc(GetProcessHeap(), 0, size);
110 if (!pEMR) return FALSE;
113 pEMR->emr.iType = emrType;
114 pEMR->emr.nSize = size;
115 pEMR->rclBounds.left = xDst;
116 pEMR->rclBounds.top = yDst;
117 pEMR->rclBounds.right = xDst + widthDst - 1;
118 pEMR->rclBounds.bottom = yDst + heightDst - 1;
121 pEMR->cxDest = widthDst;
122 pEMR->cyDest = heightDst;
126 GetWorldTransform(devSrc->hdc, &pEMR->xformSrc);
127 pEMR->crBkColorSrc = GetBkColor(devSrc->hdc);
128 pEMR->iUsageSrc = DIB_RGB_COLORS;
129 pEMR->offBmiSrc = emrSize;
130 pEMR->offBitsSrc = emrSize + bmiSize;
131 pEMR->cbBmiSrc = bmiSize;
132 pEMR->cbBitsSrc = bitsSize;
133 if (emrType == EMR_STRETCHBLT)
135 PEMRSTRETCHBLT pEMRStretch = (PEMRSTRETCHBLT)pEMR;
136 pEMRStretch->cxSrc = widthSrc;
137 pEMRStretch->cySrc = heightSrc;
140 /* Initialize BITMAPINFO structure */
141 lpBmiH = (LPBITMAPINFOHEADER)((BYTE*)pEMR + pEMR->offBmiSrc);
143 lpBmiH->biSize = sizeof(BITMAPINFOHEADER);
144 lpBmiH->biWidth = BM.bmWidth;
145 lpBmiH->biHeight = BM.bmHeight;
146 lpBmiH->biPlanes = BM.bmPlanes;
147 lpBmiH->biBitCount = nBPP;
148 /* Assume the bitmap isn't compressed and set the BI_RGB flag. */
149 lpBmiH->biCompression = BI_RGB;
150 lpBmiH->biSizeImage = bitsSize;
151 lpBmiH->biYPelsPerMeter = 0;
152 lpBmiH->biXPelsPerMeter = 0;
153 lpBmiH->biClrUsed = nBPP <= 8 ? 1 << nBPP : 0;
154 /* Set biClrImportant to 0, indicating that all of the
155 device colors are important. */
156 lpBmiH->biClrImportant = 0;
158 /* Initialize bitmap bits */
159 if (GetDIBits(devSrc->hdc, hBitmap, 0, (UINT)lpBmiH->biHeight,
160 (BYTE*)pEMR + pEMR->offBitsSrc,
161 (LPBITMAPINFO)lpBmiH, DIB_RGB_COLORS))
163 ret = EMFDRV_WriteRecord(devDst, (EMR*)pEMR);
164 if (ret) EMFDRV_UpdateBBox(devDst, &(pEMR->rclBounds));
169 HeapFree( GetProcessHeap(), 0, pEMR);
173 INT CDECL EMFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
174 INT heightDst, INT xSrc, INT ySrc,
175 INT widthSrc, INT heightSrc,
176 const void *bits, const BITMAPINFO *info,
177 UINT wUsage, DWORD dwRop )
179 EMRSTRETCHDIBITS *emr;
181 UINT bmi_size=0, bits_size, emr_size;
183 bits_size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
184 info->bmiHeader.biHeight,
185 info->bmiHeader.biBitCount);
187 /* calculate the size of the colour table */
188 bmi_size = bitmap_info_size(info, wUsage);
190 emr_size = sizeof (EMRSTRETCHDIBITS) + bmi_size + bits_size;
191 emr = HeapAlloc(GetProcessHeap(), 0, emr_size );
194 /* write a bitmap info header (with colours) to the record */
195 memcpy( &emr[1], info, bmi_size);
197 /* write bitmap bits to the record */
198 memcpy ( ( (BYTE *) (&emr[1]) ) + bmi_size, bits, bits_size);
200 /* fill in the EMR header at the front of our piece of memory */
201 emr->emr.iType = EMR_STRETCHDIBITS;
202 emr->emr.nSize = emr_size;
206 emr->cxDest = widthDst;
207 emr->cyDest = heightDst;
209 emr->xSrc = xSrc; /* FIXME: only save the piece of the bitmap needed */
212 emr->iUsageSrc = wUsage;
213 emr->offBmiSrc = sizeof (EMRSTRETCHDIBITS);
214 emr->cbBmiSrc = bmi_size;
215 emr->offBitsSrc = emr->offBmiSrc + bmi_size;
216 emr->cbBitsSrc = bits_size;
218 emr->cxSrc = widthSrc;
219 emr->cySrc = heightSrc;
221 emr->rclBounds.left = xDst;
222 emr->rclBounds.top = yDst;
223 emr->rclBounds.right = xDst + widthDst;
224 emr->rclBounds.bottom = yDst + heightDst;
226 /* save the record we just created */
227 ret = EMFDRV_WriteRecord( dev, &emr->emr );
229 EMFDRV_UpdateBBox( dev, &emr->rclBounds );
231 HeapFree(GetProcessHeap(), 0, emr);
233 return ret ? heightSrc : GDI_ERROR;
236 INT CDECL EMFDRV_SetDIBitsToDevice(
237 PHYSDEV dev, INT xDst, INT yDst, DWORD width, DWORD height,
238 INT xSrc, INT ySrc, UINT startscan, UINT lines,
239 LPCVOID bits, const BITMAPINFO *info, UINT wUsage )
241 EMRSETDIBITSTODEVICE* pEMR;
242 DWORD size, bmiSize, bitsSize;
244 bmiSize = bitmap_info_size(info, wUsage);
245 bitsSize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
246 info->bmiHeader.biHeight,
247 info->bmiHeader.biBitCount );
248 size = sizeof(EMRSETDIBITSTODEVICE) + bmiSize + bitsSize;
250 pEMR = HeapAlloc(GetProcessHeap(), 0, size);
253 pEMR->emr.iType = EMR_SETDIBITSTODEVICE;
254 pEMR->emr.nSize = size;
255 pEMR->rclBounds.left = xDst;
256 pEMR->rclBounds.top = yDst;
257 pEMR->rclBounds.right = xDst + width - 1;
258 pEMR->rclBounds.bottom = yDst + height - 1;
264 pEMR->cySrc = height;
265 pEMR->offBmiSrc = sizeof(EMRSETDIBITSTODEVICE);
266 pEMR->cbBmiSrc = bmiSize;
267 pEMR->offBitsSrc = sizeof(EMRSETDIBITSTODEVICE) + bmiSize;
268 pEMR->cbBitsSrc = bitsSize;
269 pEMR->iUsageSrc = wUsage;
270 pEMR->iStartScan = startscan;
271 pEMR->cScans = lines;
272 memcpy((BYTE*)pEMR + pEMR->offBmiSrc, info, bmiSize);
273 memcpy((BYTE*)pEMR + pEMR->offBitsSrc, bits, bitsSize);
275 if (EMFDRV_WriteRecord(dev, (EMR*)pEMR))
276 EMFDRV_UpdateBBox(dev, &(pEMR->rclBounds));
278 HeapFree( GetProcessHeap(), 0, pEMR);