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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "mfdrv/metafiledrv.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(metafile);
28 /***********************************************************************
31 BOOL CDECL MFDRV_PatBlt( PHYSDEV dev, INT left, INT top, INT width, INT height, DWORD rop )
33 MFDRV_MetaParam6( dev, META_PATBLT, left, top, width, height, HIWORD(rop), LOWORD(rop) );
38 /***********************************************************************
40 * this function contains TWO ways for processing StretchBlt in metafiles,
41 * decide between rdFunction values META_STRETCHBLT or META_DIBSTRETCHBLT
42 * via #define STRETCH_VIA_DIB
44 #define STRETCH_VIA_DIB
46 BOOL CDECL MFDRV_StretchBlt( PHYSDEV devDst, INT xDst, INT yDst, INT widthDst,
47 INT heightDst, PHYSDEV devSrc, INT xSrc, INT ySrc,
48 INT widthSrc, INT heightSrc, DWORD rop )
54 METAFILEDRV_PDEVICE *physDevSrc = (METAFILEDRV_PDEVICE *)devSrc;
55 #ifdef STRETCH_VIA_DIB
56 LPBITMAPINFOHEADER lpBMI;
59 HBITMAP hBitmap = GetCurrentObject(physDevSrc->hdc, OBJ_BITMAP);
61 if (GetObjectW(hBitmap, sizeof(BITMAP), &BM) != sizeof(BITMAP))
63 WARN("bad bitmap object %p passed for hdc %p\n", hBitmap, physDevSrc->hdc);
66 #ifdef STRETCH_VIA_DIB
67 nBPP = BM.bmPlanes * BM.bmBitsPixel;
68 if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */
69 len = sizeof(METARECORD) + 10 * sizeof(INT16)
70 + sizeof(BITMAPINFOHEADER) + (nBPP <= 8 ? 1 << nBPP: 0) * sizeof(RGBQUAD)
71 + DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight;
72 if (!(mr = HeapAlloc( GetProcessHeap(), 0, len)))
74 mr->rdFunction = META_DIBSTRETCHBLT;
75 lpBMI=(LPBITMAPINFOHEADER)(mr->rdParm+10);
76 lpBMI->biSize = sizeof(BITMAPINFOHEADER);
77 lpBMI->biWidth = BM.bmWidth;
78 lpBMI->biHeight = BM.bmHeight;
80 lpBMI->biBitCount = nBPP;
81 lpBMI->biSizeImage = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * lpBMI->biHeight;
82 lpBMI->biClrUsed = nBPP <= 8 ? 1 << nBPP : 0;
83 lpBMI->biCompression = BI_RGB;
84 lpBMI->biXPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSX),3937,100);
85 lpBMI->biYPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSY),3937,100);
86 lpBMI->biClrImportant = 0; /* 1 meter = 39.37 inch */
88 TRACE("MF_StretchBltViaDIB->len = %d rop=%x PixYPM=%d Caps=%d\n",
89 len,rop,lpBMI->biYPelsPerMeter,GetDeviceCaps(physDevSrc->hdc, LOGPIXELSY));
91 if (GetDIBits(physDevSrc->hdc, hBitmap, 0, (UINT)lpBMI->biHeight,
92 (LPSTR)lpBMI + bitmap_info_size( (BITMAPINFO *)lpBMI,
94 (LPBITMAPINFO)lpBMI, DIB_RGB_COLORS))
96 len = sizeof(METARECORD) + 15 * sizeof(INT16) + BM.bmWidthBytes * BM.bmHeight;
97 if (!(mr = HeapAlloc( GetProcessHeap(), 0, len )))
99 mr->rdFunction = META_STRETCHBLT;
100 *(mr->rdParm +10) = BM.bmWidth;
101 *(mr->rdParm +11) = BM.bmHeight;
102 *(mr->rdParm +12) = BM.bmWidthBytes;
103 *(mr->rdParm +13) = BM.bmPlanes;
104 *(mr->rdParm +14) = BM.bmBitsPixel;
105 TRACE("len = %ld rop=%lx\n", len, rop);
106 if (GetBitmapBits( hBitmap, BM.bmWidthBytes * BM.bmHeight, mr->rdParm + 15))
109 mr->rdSize = len / sizeof(INT16);
110 *(mr->rdParm) = LOWORD(rop);
111 *(mr->rdParm + 1) = HIWORD(rop);
112 *(mr->rdParm + 2) = heightSrc;
113 *(mr->rdParm + 3) = widthSrc;
114 *(mr->rdParm + 4) = ySrc;
115 *(mr->rdParm + 5) = xSrc;
116 *(mr->rdParm + 6) = heightDst;
117 *(mr->rdParm + 7) = widthDst;
118 *(mr->rdParm + 8) = yDst;
119 *(mr->rdParm + 9) = xDst;
120 ret = MFDRV_WriteRecord( devDst, mr, mr->rdSize * 2);
124 HeapFree( GetProcessHeap(), 0, mr);
129 /***********************************************************************
130 * MFDRV_StretchDIBits
132 INT CDECL MFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
133 INT heightDst, INT xSrc, INT ySrc, INT widthSrc,
134 INT heightSrc, const void *bits,
135 const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
137 DWORD len, infosize, imagesize;
140 infosize = bitmap_info_size(info, wUsage);
141 imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
142 info->bmiHeader.biHeight,
143 info->bmiHeader.biBitCount );
145 len = sizeof(METARECORD) + 10 * sizeof(WORD) + infosize + imagesize;
146 mr = HeapAlloc( GetProcessHeap(), 0, len );
149 mr->rdSize = len / 2;
150 mr->rdFunction = META_STRETCHDIB;
151 mr->rdParm[0] = LOWORD(dwRop);
152 mr->rdParm[1] = HIWORD(dwRop);
153 mr->rdParm[2] = wUsage;
154 mr->rdParm[3] = (INT16)heightSrc;
155 mr->rdParm[4] = (INT16)widthSrc;
156 mr->rdParm[5] = (INT16)ySrc;
157 mr->rdParm[6] = (INT16)xSrc;
158 mr->rdParm[7] = (INT16)heightDst;
159 mr->rdParm[8] = (INT16)widthDst;
160 mr->rdParm[9] = (INT16)yDst;
161 mr->rdParm[10] = (INT16)xDst;
162 memcpy(mr->rdParm + 11, info, infosize);
163 memcpy(mr->rdParm + 11 + infosize / 2, bits, imagesize);
164 MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
165 HeapFree( GetProcessHeap(), 0, mr );
170 /***********************************************************************
171 * MFDRV_SetDIBitsToDeivce
173 INT CDECL MFDRV_SetDIBitsToDevice( PHYSDEV dev, INT xDst, INT yDst, DWORD cx,
174 DWORD cy, INT xSrc, INT ySrc, UINT startscan,
175 UINT lines, LPCVOID bits, const BITMAPINFO *info,
179 DWORD len, infosize, imagesize;
182 infosize = bitmap_info_size(info, coloruse);
183 imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
184 info->bmiHeader.biHeight,
185 info->bmiHeader.biBitCount );
187 len = sizeof(METARECORD) + 8 * sizeof(WORD) + infosize + imagesize;
188 mr = HeapAlloc( GetProcessHeap(), 0, len );
191 mr->rdSize = len / 2;
192 mr->rdFunction = META_SETDIBTODEV;
193 mr->rdParm[0] = coloruse;
194 mr->rdParm[1] = lines;
195 mr->rdParm[2] = startscan;
196 mr->rdParm[3] = (INT16)ySrc;
197 mr->rdParm[4] = (INT16)xSrc;
198 mr->rdParm[5] = (INT16)cy;
199 mr->rdParm[6] = (INT16)cx;
200 mr->rdParm[7] = (INT16)yDst;
201 mr->rdParm[8] = (INT16)xDst;
202 memcpy(mr->rdParm + 9, info, infosize);
203 memcpy(mr->rdParm + 9 + infosize / 2, bits, imagesize);
204 MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
205 HeapFree( GetProcessHeap(), 0, mr );