2 * GDI bit-blit operations
4 * Copyright 1993, 1994 Alexandre Julliard
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
24 #include "mfdrv/metafiledrv.h"
25 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(metafile);
30 /***********************************************************************
33 BOOL MFDRV_PatBlt( PHYSDEV dev, INT left, INT top, INT width, INT height, DWORD rop )
35 MFDRV_MetaParam6( dev, META_PATBLT, left, top, width, height, HIWORD(rop), LOWORD(rop) );
40 /***********************************************************************
43 BOOL MFDRV_BitBlt( PHYSDEV devDst, INT xDst, INT yDst, INT width, INT height,
44 PHYSDEV devSrc, INT xSrc, INT ySrc, DWORD rop )
46 return MFDRV_StretchBlt(devDst, xDst, yDst, width, height, devSrc,
47 xSrc, ySrc, width, height, rop);
52 /***********************************************************************
54 * this function contains TWO ways for procesing StretchBlt in metafiles,
55 * decide between rdFunction values META_STRETCHBLT or META_DIBSTRETCHBLT
56 * via #define STRETCH_VIA_DIB
58 #define STRETCH_VIA_DIB
60 BOOL MFDRV_StretchBlt( PHYSDEV devDst, INT xDst, INT yDst, INT widthDst,
61 INT heightDst, PHYSDEV devSrc, INT xSrc, INT ySrc,
62 INT widthSrc, INT heightSrc, DWORD rop )
68 METAFILEDRV_PDEVICE *physDevSrc = (METAFILEDRV_PDEVICE *)devSrc;
69 DC *dcSrc = physDevSrc->dc;
70 #ifdef STRETCH_VIA_DIB
71 LPBITMAPINFOHEADER lpBMI;
74 GetObjectA(dcSrc->hBitmap, sizeof(BITMAP), &BM);
75 #ifdef STRETCH_VIA_DIB
76 nBPP = BM.bmPlanes * BM.bmBitsPixel;
77 if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */
78 len = sizeof(METARECORD) + 10 * sizeof(INT16)
79 + sizeof(BITMAPINFOHEADER) + (nBPP <= 8 ? 1 << nBPP: 0) * sizeof(RGBQUAD)
80 + DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight;
81 if (!(mr = HeapAlloc( GetProcessHeap(), 0, len)))
83 mr->rdFunction = META_DIBSTRETCHBLT;
84 lpBMI=(LPBITMAPINFOHEADER)(mr->rdParm+10);
85 lpBMI->biSize = sizeof(BITMAPINFOHEADER);
86 lpBMI->biWidth = BM.bmWidth;
87 lpBMI->biHeight = BM.bmHeight;
89 lpBMI->biBitCount = nBPP;
90 lpBMI->biSizeImage = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * lpBMI->biHeight;
91 lpBMI->biClrUsed = nBPP <= 8 ? 1 << nBPP : 0;
92 lpBMI->biCompression = BI_RGB;
93 lpBMI->biXPelsPerMeter = MulDiv(GetDeviceCaps(dcSrc->hSelf,LOGPIXELSX),3937,100);
94 lpBMI->biYPelsPerMeter = MulDiv(GetDeviceCaps(dcSrc->hSelf,LOGPIXELSY),3937,100);
95 lpBMI->biClrImportant = 0; /* 1 meter = 39.37 inch */
97 TRACE("MF_StretchBltViaDIB->len = %ld rop=%lx PixYPM=%ld Caps=%d\n",
98 len,rop,lpBMI->biYPelsPerMeter,GetDeviceCaps(dcSrc->hSelf,
100 if (GetDIBits(dcSrc->hSelf,dcSrc->hBitmap,0,(UINT)lpBMI->biHeight,
101 (LPSTR)lpBMI + DIB_BitmapInfoSize( (BITMAPINFO *)lpBMI,
103 (LPBITMAPINFO)lpBMI, DIB_RGB_COLORS))
105 len = sizeof(METARECORD) + 15 * sizeof(INT16) + BM.bmWidthBytes * BM.bmHeight;
106 if (!(mr = HeapAlloc( GetProcessHeap(), 0, len )))
108 mr->rdFunction = META_STRETCHBLT;
109 *(mr->rdParm +10) = BM.bmWidth;
110 *(mr->rdParm +11) = BM.bmHeight;
111 *(mr->rdParm +12) = BM.bmWidthBytes;
112 *(mr->rdParm +13) = BM.bmPlanes;
113 *(mr->rdParm +14) = BM.bmBitsPixel;
114 TRACE("len = %ld rop=%lx \n",len,rop);
115 if (GetBitmapBits( dcSrc->hBitmap, BM.bmWidthBytes * BM.bmHeight,
119 mr->rdSize = len / sizeof(INT16);
120 *(mr->rdParm) = LOWORD(rop);
121 *(mr->rdParm + 1) = HIWORD(rop);
122 *(mr->rdParm + 2) = heightSrc;
123 *(mr->rdParm + 3) = widthSrc;
124 *(mr->rdParm + 4) = ySrc;
125 *(mr->rdParm + 5) = xSrc;
126 *(mr->rdParm + 6) = heightDst;
127 *(mr->rdParm + 7) = widthDst;
128 *(mr->rdParm + 8) = yDst;
129 *(mr->rdParm + 9) = xDst;
130 ret = MFDRV_WriteRecord( devDst, mr, mr->rdSize * 2);
134 HeapFree( GetProcessHeap(), 0, mr);
139 /***********************************************************************
140 * MFDRV_StretchDIBits
142 INT MFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
143 INT heightDst, INT xSrc, INT ySrc, INT widthSrc,
144 INT heightSrc, const void *bits,
145 const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
147 DWORD len, infosize, imagesize;
150 infosize = DIB_BitmapInfoSize(info, wUsage);
151 imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
152 info->bmiHeader.biHeight,
153 info->bmiHeader.biBitCount );
155 len = sizeof(METARECORD) + 10 * sizeof(WORD) + infosize + imagesize;
156 mr = (METARECORD *)HeapAlloc( GetProcessHeap(), 0, len );
159 mr->rdSize = len / 2;
160 mr->rdFunction = META_STRETCHDIB;
161 mr->rdParm[0] = LOWORD(dwRop);
162 mr->rdParm[1] = HIWORD(dwRop);
163 mr->rdParm[2] = wUsage;
164 mr->rdParm[3] = (INT16)heightSrc;
165 mr->rdParm[4] = (INT16)widthSrc;
166 mr->rdParm[5] = (INT16)ySrc;
167 mr->rdParm[6] = (INT16)xSrc;
168 mr->rdParm[7] = (INT16)heightDst;
169 mr->rdParm[8] = (INT16)widthDst;
170 mr->rdParm[9] = (INT16)yDst;
171 mr->rdParm[10] = (INT16)xDst;
172 memcpy(mr->rdParm + 11, info, infosize);
173 memcpy(mr->rdParm + 11 + infosize / 2, bits, imagesize);
174 MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
175 HeapFree( GetProcessHeap(), 0, mr );
180 /***********************************************************************
181 * MFDRV_SetDIBitsToDeivce
183 INT MFDRV_SetDIBitsToDevice( PHYSDEV dev, INT xDst, INT yDst, DWORD cx,
184 DWORD cy, INT xSrc, INT ySrc, UINT startscan,
185 UINT lines, LPCVOID bits, const BITMAPINFO *info,
189 DWORD len, infosize, imagesize;
192 infosize = DIB_BitmapInfoSize(info, coloruse);
193 imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
194 info->bmiHeader.biHeight,
195 info->bmiHeader.biBitCount );
197 len = sizeof(METARECORD) + 8 * sizeof(WORD) + infosize + imagesize;
198 mr = (METARECORD *)HeapAlloc( GetProcessHeap(), 0, len );
201 mr->rdSize = len / 2;
202 mr->rdFunction = META_SETDIBTODEV;
203 mr->rdParm[0] = coloruse;
204 mr->rdParm[1] = lines;
205 mr->rdParm[2] = startscan;
206 mr->rdParm[3] = (INT16)ySrc;
207 mr->rdParm[4] = (INT16)xSrc;
208 mr->rdParm[5] = (INT16)cy;
209 mr->rdParm[6] = (INT16)cx;
210 mr->rdParm[7] = (INT16)yDst;
211 mr->rdParm[8] = (INT16)xDst;
212 memcpy(mr->rdParm + 9, info, infosize);
213 memcpy(mr->rdParm + 9 + infosize / 2, bits, imagesize);
214 MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
215 HeapFree( GetProcessHeap(), 0, mr );