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"
27 WINE_DEFAULT_DEBUG_CHANNEL(metafile);
29 /***********************************************************************
32 BOOL MFDRV_PatBlt( PHYSDEV dev, INT left, INT top, INT width, INT height, DWORD rop )
34 MFDRV_MetaParam6( dev, META_PATBLT, left, top, width, height, HIWORD(rop), LOWORD(rop) );
39 /***********************************************************************
42 BOOL MFDRV_BitBlt( PHYSDEV devDst, INT xDst, INT yDst, INT width, INT height,
43 PHYSDEV devSrc, INT xSrc, INT ySrc, DWORD rop )
45 return MFDRV_StretchBlt(devDst, xDst, yDst, width, height, devSrc,
46 xSrc, ySrc, width, height, rop);
51 /***********************************************************************
53 * this function contains TWO ways for procesing StretchBlt in metafiles,
54 * decide between rdFunction values META_STRETCHBLT or META_DIBSTRETCHBLT
55 * via #define STRETCH_VIA_DIB
57 #define STRETCH_VIA_DIB
59 BOOL MFDRV_StretchBlt( PHYSDEV devDst, INT xDst, INT yDst, INT widthDst,
60 INT heightDst, PHYSDEV devSrc, INT xSrc, INT ySrc,
61 INT widthSrc, INT heightSrc, DWORD rop )
67 METAFILEDRV_PDEVICE *physDevSrc = (METAFILEDRV_PDEVICE *)devSrc;
68 DC *dcSrc = physDevSrc->dc;
69 #ifdef STRETCH_VIA_DIB
70 LPBITMAPINFOHEADER lpBMI;
73 GetObjectA(dcSrc->hBitmap, sizeof(BITMAP), &BM);
74 #ifdef STRETCH_VIA_DIB
75 nBPP = BM.bmPlanes * BM.bmBitsPixel;
76 if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */
77 len = sizeof(METARECORD) + 10 * sizeof(INT16)
78 + sizeof(BITMAPINFOHEADER) + (nBPP <= 8 ? 1 << nBPP: 0) * sizeof(RGBQUAD)
79 + DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight;
80 if (!(mr = HeapAlloc( GetProcessHeap(), 0, len)))
82 mr->rdFunction = META_DIBSTRETCHBLT;
83 lpBMI=(LPBITMAPINFOHEADER)(mr->rdParm+10);
84 lpBMI->biSize = sizeof(BITMAPINFOHEADER);
85 lpBMI->biWidth = BM.bmWidth;
86 lpBMI->biHeight = BM.bmHeight;
88 lpBMI->biBitCount = nBPP;
89 lpBMI->biSizeImage = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * lpBMI->biHeight;
90 lpBMI->biClrUsed = nBPP <= 8 ? 1 << nBPP : 0;
91 lpBMI->biCompression = BI_RGB;
92 lpBMI->biXPelsPerMeter = MulDiv(GetDeviceCaps(dcSrc->hSelf,LOGPIXELSX),3937,100);
93 lpBMI->biYPelsPerMeter = MulDiv(GetDeviceCaps(dcSrc->hSelf,LOGPIXELSY),3937,100);
94 lpBMI->biClrImportant = 0; /* 1 meter = 39.37 inch */
96 TRACE("MF_StretchBltViaDIB->len = %ld rop=%lx PixYPM=%ld Caps=%d\n",
97 len,rop,lpBMI->biYPelsPerMeter,GetDeviceCaps(dcSrc->hSelf,
99 if (GetDIBits(dcSrc->hSelf,dcSrc->hBitmap,0,(UINT)lpBMI->biHeight,
100 (LPSTR)lpBMI + DIB_BitmapInfoSize( (BITMAPINFO *)lpBMI,
102 (LPBITMAPINFO)lpBMI, DIB_RGB_COLORS))
104 len = sizeof(METARECORD) + 15 * sizeof(INT16) + BM.bmWidthBytes * BM.bmHeight;
105 if (!(mr = HeapAlloc( GetProcessHeap(), 0, len )))
107 mr->rdFunction = META_STRETCHBLT;
108 *(mr->rdParm +10) = BM.bmWidth;
109 *(mr->rdParm +11) = BM.bmHeight;
110 *(mr->rdParm +12) = BM.bmWidthBytes;
111 *(mr->rdParm +13) = BM.bmPlanes;
112 *(mr->rdParm +14) = BM.bmBitsPixel;
113 TRACE("len = %ld rop=%lx \n",len,rop);
114 if (GetBitmapBits( dcSrc->hBitmap, BM.bmWidthBytes * BM.bmHeight,
118 mr->rdSize = len / sizeof(INT16);
119 *(mr->rdParm) = LOWORD(rop);
120 *(mr->rdParm + 1) = HIWORD(rop);
121 *(mr->rdParm + 2) = heightSrc;
122 *(mr->rdParm + 3) = widthSrc;
123 *(mr->rdParm + 4) = ySrc;
124 *(mr->rdParm + 5) = xSrc;
125 *(mr->rdParm + 6) = heightDst;
126 *(mr->rdParm + 7) = widthDst;
127 *(mr->rdParm + 8) = yDst;
128 *(mr->rdParm + 9) = xDst;
129 ret = MFDRV_WriteRecord( devDst, mr, mr->rdSize * 2);
133 HeapFree( GetProcessHeap(), 0, mr);
138 /***********************************************************************
139 * MFDRV_StretchDIBits
141 INT MFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
142 INT heightDst, INT xSrc, INT ySrc, INT widthSrc,
143 INT heightSrc, const void *bits,
144 const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
146 DWORD len, infosize, imagesize;
149 infosize = DIB_BitmapInfoSize(info, wUsage);
150 imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
151 info->bmiHeader.biHeight,
152 info->bmiHeader.biBitCount );
154 len = sizeof(METARECORD) + 10 * sizeof(WORD) + infosize + imagesize;
155 mr = (METARECORD *)HeapAlloc( GetProcessHeap(), 0, len );
158 mr->rdSize = len / 2;
159 mr->rdFunction = META_STRETCHDIB;
160 mr->rdParm[0] = LOWORD(dwRop);
161 mr->rdParm[1] = HIWORD(dwRop);
162 mr->rdParm[2] = wUsage;
163 mr->rdParm[3] = (INT16)heightSrc;
164 mr->rdParm[4] = (INT16)widthSrc;
165 mr->rdParm[5] = (INT16)ySrc;
166 mr->rdParm[6] = (INT16)xSrc;
167 mr->rdParm[7] = (INT16)heightDst;
168 mr->rdParm[8] = (INT16)widthDst;
169 mr->rdParm[9] = (INT16)yDst;
170 mr->rdParm[10] = (INT16)xDst;
171 memcpy(mr->rdParm + 11, info, infosize);
172 memcpy(mr->rdParm + 11 + infosize / 2, bits, imagesize);
173 MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
174 HeapFree( GetProcessHeap(), 0, mr );
179 /***********************************************************************
180 * MFDRV_SetDIBitsToDeivce
182 INT MFDRV_SetDIBitsToDevice( PHYSDEV dev, INT xDst, INT yDst, DWORD cx,
183 DWORD cy, INT xSrc, INT ySrc, UINT startscan,
184 UINT lines, LPCVOID bits, const BITMAPINFO *info,
188 DWORD len, infosize, imagesize;
191 infosize = DIB_BitmapInfoSize(info, coloruse);
192 imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
193 info->bmiHeader.biHeight,
194 info->bmiHeader.biBitCount );
196 len = sizeof(METARECORD) + 8 * sizeof(WORD) + infosize + imagesize;
197 mr = (METARECORD *)HeapAlloc( GetProcessHeap(), 0, len );
200 mr->rdSize = len / 2;
201 mr->rdFunction = META_SETDIBTODEV;
202 mr->rdParm[0] = coloruse;
203 mr->rdParm[1] = lines;
204 mr->rdParm[2] = startscan;
205 mr->rdParm[3] = (INT16)ySrc;
206 mr->rdParm[4] = (INT16)xSrc;
207 mr->rdParm[5] = (INT16)cy;
208 mr->rdParm[6] = (INT16)cx;
209 mr->rdParm[7] = (INT16)yDst;
210 mr->rdParm[8] = (INT16)xDst;
211 memcpy(mr->rdParm + 9, info, infosize);
212 memcpy(mr->rdParm + 9 + infosize / 2, bits, imagesize);
213 MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
214 HeapFree( GetProcessHeap(), 0, mr );