gdi32: Graphics driver functions no longer need to be CDECL.
[wine/wine-gecko.git] / dlls / gdi32 / mfdrv / bitblt.c
blobfa56ecf5ba64ef8bf3ca1d071e4358daf6843d17
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 MFDRV_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
33 MFDRV_MetaParam6( dev, META_PATBLT, dst->log_x, dst->log_y, dst->log_width, dst->log_height,
34 HIWORD(rop), LOWORD(rop) );
35 return TRUE;
39 /***********************************************************************
40 * MFDRV_StretchBlt
41 * this function contains TWO ways for processing StretchBlt in metafiles,
42 * decide between rdFunction values META_STRETCHBLT or META_DIBSTRETCHBLT
43 * via #define STRETCH_VIA_DIB
45 #define STRETCH_VIA_DIB
47 BOOL MFDRV_StretchBlt( PHYSDEV devDst, struct bitblt_coords *dst,
48 PHYSDEV devSrc, struct bitblt_coords *src, DWORD rop )
50 BOOL ret;
51 DWORD len;
52 METARECORD *mr;
53 BITMAP BM;
54 #ifdef STRETCH_VIA_DIB
55 LPBITMAPINFOHEADER lpBMI;
56 WORD nBPP;
57 #endif
58 HBITMAP hBitmap = GetCurrentObject(devSrc->hdc, OBJ_BITMAP);
60 if (devSrc->funcs == devDst->funcs) return FALSE; /* can't use a metafile DC as source */
62 if (GetObjectW(hBitmap, sizeof(BITMAP), &BM) != sizeof(BITMAP))
64 WARN("bad bitmap object %p passed for hdc %p\n", hBitmap, devSrc->hdc);
65 return FALSE;
67 #ifdef STRETCH_VIA_DIB
68 nBPP = BM.bmPlanes * BM.bmBitsPixel;
69 if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */
70 len = sizeof(METARECORD) + 10 * sizeof(INT16)
71 + sizeof(BITMAPINFOHEADER) + (nBPP <= 8 ? 1 << nBPP: 0) * sizeof(RGBQUAD)
72 + DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight;
73 if (!(mr = HeapAlloc( GetProcessHeap(), 0, len)))
74 return FALSE;
75 mr->rdFunction = META_DIBSTRETCHBLT;
76 lpBMI=(LPBITMAPINFOHEADER)(mr->rdParm+10);
77 lpBMI->biSize = sizeof(BITMAPINFOHEADER);
78 lpBMI->biWidth = BM.bmWidth;
79 lpBMI->biHeight = BM.bmHeight;
80 lpBMI->biPlanes = 1;
81 lpBMI->biBitCount = nBPP;
82 lpBMI->biSizeImage = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * lpBMI->biHeight;
83 lpBMI->biClrUsed = nBPP <= 8 ? 1 << nBPP : 0;
84 lpBMI->biCompression = BI_RGB;
85 lpBMI->biXPelsPerMeter = MulDiv(GetDeviceCaps(devSrc->hdc,LOGPIXELSX),3937,100);
86 lpBMI->biYPelsPerMeter = MulDiv(GetDeviceCaps(devSrc->hdc,LOGPIXELSY),3937,100);
87 lpBMI->biClrImportant = 0; /* 1 meter = 39.37 inch */
89 TRACE("MF_StretchBltViaDIB->len = %d rop=%x PixYPM=%d Caps=%d\n",
90 len,rop,lpBMI->biYPelsPerMeter,GetDeviceCaps(devSrc->hdc, LOGPIXELSY));
92 if (GetDIBits(devSrc->hdc, hBitmap, 0, (UINT)lpBMI->biHeight,
93 (LPSTR)lpBMI + bitmap_info_size( (BITMAPINFO *)lpBMI,
94 DIB_RGB_COLORS ),
95 (LPBITMAPINFO)lpBMI, DIB_RGB_COLORS))
96 #else
97 len = sizeof(METARECORD) + 15 * sizeof(INT16) + BM.bmWidthBytes * BM.bmHeight;
98 if (!(mr = HeapAlloc( GetProcessHeap(), 0, len )))
99 return FALSE;
100 mr->rdFunction = META_STRETCHBLT;
101 *(mr->rdParm +10) = BM.bmWidth;
102 *(mr->rdParm +11) = BM.bmHeight;
103 *(mr->rdParm +12) = BM.bmWidthBytes;
104 *(mr->rdParm +13) = BM.bmPlanes;
105 *(mr->rdParm +14) = BM.bmBitsPixel;
106 TRACE("len = %ld rop=%lx\n", len, rop);
107 if (GetBitmapBits( hBitmap, BM.bmWidthBytes * BM.bmHeight, mr->rdParm + 15))
108 #endif
110 mr->rdSize = len / sizeof(INT16);
111 *(mr->rdParm) = LOWORD(rop);
112 *(mr->rdParm + 1) = HIWORD(rop);
113 *(mr->rdParm + 2) = src->log_height;
114 *(mr->rdParm + 3) = src->log_width;
115 *(mr->rdParm + 4) = src->log_y;
116 *(mr->rdParm + 5) = src->log_x;
117 *(mr->rdParm + 6) = dst->log_height;
118 *(mr->rdParm + 7) = dst->log_width;
119 *(mr->rdParm + 8) = dst->log_y;
120 *(mr->rdParm + 9) = dst->log_x;
121 ret = MFDRV_WriteRecord( devDst, mr, mr->rdSize * 2);
123 else
124 ret = FALSE;
125 HeapFree( GetProcessHeap(), 0, mr);
126 return ret;
130 /***********************************************************************
131 * MFDRV_StretchDIBits
133 INT MFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
134 INT heightDst, INT xSrc, INT ySrc, INT widthSrc,
135 INT heightSrc, const void *bits,
136 const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
138 DWORD len, infosize, imagesize;
139 METARECORD *mr;
141 infosize = bitmap_info_size(info, wUsage);
142 imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
143 info->bmiHeader.biHeight,
144 info->bmiHeader.biBitCount );
146 len = sizeof(METARECORD) + 10 * sizeof(WORD) + infosize + imagesize;
147 mr = HeapAlloc( GetProcessHeap(), 0, len );
148 if(!mr) return 0;
150 mr->rdSize = len / 2;
151 mr->rdFunction = META_STRETCHDIB;
152 mr->rdParm[0] = LOWORD(dwRop);
153 mr->rdParm[1] = HIWORD(dwRop);
154 mr->rdParm[2] = wUsage;
155 mr->rdParm[3] = (INT16)heightSrc;
156 mr->rdParm[4] = (INT16)widthSrc;
157 mr->rdParm[5] = (INT16)ySrc;
158 mr->rdParm[6] = (INT16)xSrc;
159 mr->rdParm[7] = (INT16)heightDst;
160 mr->rdParm[8] = (INT16)widthDst;
161 mr->rdParm[9] = (INT16)yDst;
162 mr->rdParm[10] = (INT16)xDst;
163 memcpy(mr->rdParm + 11, info, infosize);
164 memcpy(mr->rdParm + 11 + infosize / 2, bits, imagesize);
165 MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
166 HeapFree( GetProcessHeap(), 0, mr );
167 return heightSrc;
171 /***********************************************************************
172 * MFDRV_SetDIBitsToDeivce
174 INT MFDRV_SetDIBitsToDevice( PHYSDEV dev, INT xDst, INT yDst, DWORD cx,
175 DWORD cy, INT xSrc, INT ySrc, UINT startscan,
176 UINT lines, LPCVOID bits, const BITMAPINFO *info,
177 UINT coloruse )
180 DWORD len, infosize, imagesize;
181 METARECORD *mr;
183 infosize = bitmap_info_size(info, coloruse);
184 imagesize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
185 info->bmiHeader.biHeight,
186 info->bmiHeader.biBitCount );
188 len = sizeof(METARECORD) + 8 * sizeof(WORD) + infosize + imagesize;
189 mr = HeapAlloc( GetProcessHeap(), 0, len );
190 if(!mr) return 0;
192 mr->rdSize = len / 2;
193 mr->rdFunction = META_SETDIBTODEV;
194 mr->rdParm[0] = coloruse;
195 mr->rdParm[1] = lines;
196 mr->rdParm[2] = startscan;
197 mr->rdParm[3] = (INT16)ySrc;
198 mr->rdParm[4] = (INT16)xSrc;
199 mr->rdParm[5] = (INT16)cy;
200 mr->rdParm[6] = (INT16)cx;
201 mr->rdParm[7] = (INT16)yDst;
202 mr->rdParm[8] = (INT16)xDst;
203 memcpy(mr->rdParm + 9, info, infosize);
204 memcpy(mr->rdParm + 9 + infosize / 2, bits, imagesize);
205 MFDRV_WriteRecord( dev, mr, mr->rdSize * 2 );
206 HeapFree( GetProcessHeap(), 0, mr );
207 return lines;