includes: Fix alignment for 64-bits
[wine/wine64.git] / dlls / gdi32 / mfdrv / bitblt.c
blob85d4b167df0c676582140e535528fdcf6877d022
1 /*
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
21 #include <string.h>
23 #include "mfdrv/metafiledrv.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(metafile);
28 /***********************************************************************
29 * MFDRV_PatBlt
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) );
34 return TRUE;
38 /***********************************************************************
39 * MFDRV_BitBlt
41 BOOL CDECL MFDRV_BitBlt( PHYSDEV devDst, INT xDst, INT yDst, INT width, INT height,
42 PHYSDEV devSrc, INT xSrc, INT ySrc, DWORD rop )
44 return MFDRV_StretchBlt(devDst, xDst, yDst, width, height, devSrc,
45 xSrc, ySrc, width, height, rop);
50 /***********************************************************************
51 * MFDRV_StretchBlt
52 * this function contains TWO ways for processing StretchBlt in metafiles,
53 * decide between rdFunction values META_STRETCHBLT or META_DIBSTRETCHBLT
54 * via #define STRETCH_VIA_DIB
56 #define STRETCH_VIA_DIB
58 BOOL CDECL MFDRV_StretchBlt( PHYSDEV devDst, INT xDst, INT yDst, INT widthDst,
59 INT heightDst, PHYSDEV devSrc, INT xSrc, INT ySrc,
60 INT widthSrc, INT heightSrc, DWORD rop )
62 BOOL ret;
63 DWORD len;
64 METARECORD *mr;
65 BITMAP BM;
66 METAFILEDRV_PDEVICE *physDevSrc = (METAFILEDRV_PDEVICE *)devSrc;
67 #ifdef STRETCH_VIA_DIB
68 LPBITMAPINFOHEADER lpBMI;
69 WORD nBPP;
70 #endif
71 HBITMAP hBitmap = GetCurrentObject(physDevSrc->hdc, OBJ_BITMAP);
73 if (GetObjectW(hBitmap, sizeof(BITMAP), &BM) != sizeof(BITMAP))
75 WARN("bad bitmap object %p passed for hdc %p\n", hBitmap, physDevSrc->hdc);
76 return FALSE;
78 #ifdef STRETCH_VIA_DIB
79 nBPP = BM.bmPlanes * BM.bmBitsPixel;
80 if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */
81 len = sizeof(METARECORD) + 10 * sizeof(INT16)
82 + sizeof(BITMAPINFOHEADER) + (nBPP <= 8 ? 1 << nBPP: 0) * sizeof(RGBQUAD)
83 + DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight;
84 if (!(mr = HeapAlloc( GetProcessHeap(), 0, len)))
85 return FALSE;
86 mr->rdFunction = META_DIBSTRETCHBLT;
87 lpBMI=(LPBITMAPINFOHEADER)(mr->rdParm+10);
88 lpBMI->biSize = sizeof(BITMAPINFOHEADER);
89 lpBMI->biWidth = BM.bmWidth;
90 lpBMI->biHeight = BM.bmHeight;
91 lpBMI->biPlanes = 1;
92 lpBMI->biBitCount = nBPP;
93 lpBMI->biSizeImage = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * lpBMI->biHeight;
94 lpBMI->biClrUsed = nBPP <= 8 ? 1 << nBPP : 0;
95 lpBMI->biCompression = BI_RGB;
96 lpBMI->biXPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSX),3937,100);
97 lpBMI->biYPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSY),3937,100);
98 lpBMI->biClrImportant = 0; /* 1 meter = 39.37 inch */
100 TRACE("MF_StretchBltViaDIB->len = %d rop=%x PixYPM=%d Caps=%d\n",
101 len,rop,lpBMI->biYPelsPerMeter,GetDeviceCaps(physDevSrc->hdc, LOGPIXELSY));
103 if (GetDIBits(physDevSrc->hdc, hBitmap, 0, (UINT)lpBMI->biHeight,
104 (LPSTR)lpBMI + bitmap_info_size( (BITMAPINFO *)lpBMI,
105 DIB_RGB_COLORS ),
106 (LPBITMAPINFO)lpBMI, DIB_RGB_COLORS))
107 #else
108 len = sizeof(METARECORD) + 15 * sizeof(INT16) + BM.bmWidthBytes * BM.bmHeight;
109 if (!(mr = HeapAlloc( GetProcessHeap(), 0, len )))
110 return FALSE;
111 mr->rdFunction = META_STRETCHBLT;
112 *(mr->rdParm +10) = BM.bmWidth;
113 *(mr->rdParm +11) = BM.bmHeight;
114 *(mr->rdParm +12) = BM.bmWidthBytes;
115 *(mr->rdParm +13) = BM.bmPlanes;
116 *(mr->rdParm +14) = BM.bmBitsPixel;
117 TRACE("len = %ld rop=%lx\n", len, rop);
118 if (GetBitmapBits( hBitmap, BM.bmWidthBytes * BM.bmHeight, mr->rdParm + 15))
119 #endif
121 mr->rdSize = len / sizeof(INT16);
122 *(mr->rdParm) = LOWORD(rop);
123 *(mr->rdParm + 1) = HIWORD(rop);
124 *(mr->rdParm + 2) = heightSrc;
125 *(mr->rdParm + 3) = widthSrc;
126 *(mr->rdParm + 4) = ySrc;
127 *(mr->rdParm + 5) = xSrc;
128 *(mr->rdParm + 6) = heightDst;
129 *(mr->rdParm + 7) = widthDst;
130 *(mr->rdParm + 8) = yDst;
131 *(mr->rdParm + 9) = xDst;
132 ret = MFDRV_WriteRecord( devDst, mr, mr->rdSize * 2);
134 else
135 ret = FALSE;
136 HeapFree( GetProcessHeap(), 0, mr);
137 return ret;
141 /***********************************************************************
142 * MFDRV_StretchDIBits
144 INT CDECL MFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
145 INT heightDst, INT xSrc, INT ySrc, INT widthSrc,
146 INT heightSrc, const void *bits,
147 const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
149 DWORD len, infosize, imagesize;
150 METARECORD *mr;
152 infosize = bitmap_info_size(info, wUsage);
153 imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
154 info->bmiHeader.biHeight,
155 info->bmiHeader.biBitCount );
157 len = sizeof(METARECORD) + 10 * sizeof(WORD) + infosize + imagesize;
158 mr = HeapAlloc( GetProcessHeap(), 0, len );
159 if(!mr) return 0;
161 mr->rdSize = len / 2;
162 mr->rdFunction = META_STRETCHDIB;
163 mr->rdParm[0] = LOWORD(dwRop);
164 mr->rdParm[1] = HIWORD(dwRop);
165 mr->rdParm[2] = wUsage;
166 mr->rdParm[3] = (INT16)heightSrc;
167 mr->rdParm[4] = (INT16)widthSrc;
168 mr->rdParm[5] = (INT16)ySrc;
169 mr->rdParm[6] = (INT16)xSrc;
170 mr->rdParm[7] = (INT16)heightDst;
171 mr->rdParm[8] = (INT16)widthDst;
172 mr->rdParm[9] = (INT16)yDst;
173 mr->rdParm[10] = (INT16)xDst;
174 memcpy(mr->rdParm + 11, info, infosize);
175 memcpy(mr->rdParm + 11 + infosize / 2, bits, imagesize);
176 MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
177 HeapFree( GetProcessHeap(), 0, mr );
178 return heightSrc;
182 /***********************************************************************
183 * MFDRV_SetDIBitsToDeivce
185 INT CDECL MFDRV_SetDIBitsToDevice( PHYSDEV dev, INT xDst, INT yDst, DWORD cx,
186 DWORD cy, INT xSrc, INT ySrc, UINT startscan,
187 UINT lines, LPCVOID bits, const BITMAPINFO *info,
188 UINT coloruse )
191 DWORD len, infosize, imagesize;
192 METARECORD *mr;
194 infosize = bitmap_info_size(info, coloruse);
195 imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
196 info->bmiHeader.biHeight,
197 info->bmiHeader.biBitCount );
199 len = sizeof(METARECORD) + 8 * sizeof(WORD) + infosize + imagesize;
200 mr = HeapAlloc( GetProcessHeap(), 0, len );
201 if(!mr) return 0;
203 mr->rdSize = len / 2;
204 mr->rdFunction = META_SETDIBTODEV;
205 mr->rdParm[0] = coloruse;
206 mr->rdParm[1] = lines;
207 mr->rdParm[2] = startscan;
208 mr->rdParm[3] = (INT16)ySrc;
209 mr->rdParm[4] = (INT16)xSrc;
210 mr->rdParm[5] = (INT16)cy;
211 mr->rdParm[6] = (INT16)cx;
212 mr->rdParm[7] = (INT16)yDst;
213 mr->rdParm[8] = (INT16)xDst;
214 memcpy(mr->rdParm + 9, info, infosize);
215 memcpy(mr->rdParm + 9 + infosize / 2, bits, imagesize);
216 MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
217 HeapFree( GetProcessHeap(), 0, mr );
218 return lines;