~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/gdi32/enhmfdrv/bitblt.c

Version: ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Enhanced MetaFile driver BitBlt functions
  3  *
  4  * Copyright 2002 Huw D M Davies for CodeWeavers
  5  *
  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.
 10  *
 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.
 15  *
 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
 19  */
 20 
 21 #include <stdarg.h>
 22 #include <string.h>
 23 
 24 #include "windef.h"
 25 #include "winbase.h"
 26 #include "wingdi.h"
 27 #include "enhmetafiledrv.h"
 28 #include "wine/debug.h"
 29 
 30 BOOL EMFDRV_PatBlt( PHYSDEV dev, INT left, INT top,
 31                     INT width, INT height, DWORD rop )
 32 {
 33     EMRBITBLT emr;
 34     BOOL ret;
 35 
 36     emr.emr.iType = EMR_BITBLT;
 37     emr.emr.nSize = sizeof(emr);
 38     emr.rclBounds.left = left;
 39     emr.rclBounds.top = top;
 40     emr.rclBounds.right = left + width - 1;
 41     emr.rclBounds.bottom = top + height - 1;
 42     emr.xDest = left;
 43     emr.yDest = top;
 44     emr.cxDest = width;
 45     emr.cyDest = height;
 46     emr.dwRop = rop;
 47     emr.xSrc = 0;
 48     emr.ySrc = 0;
 49     emr.xformSrc.eM11 = 1.0;
 50     emr.xformSrc.eM12 = 0.0;
 51     emr.xformSrc.eM21 = 0.0;
 52     emr.xformSrc.eM22 = 1.0;
 53     emr.xformSrc.eDx = 0.0;
 54     emr.xformSrc.eDy = 0.0;
 55     emr.crBkColorSrc = 0;
 56     emr.iUsageSrc = 0;
 57     emr.offBmiSrc = 0;
 58     emr.cbBmiSrc = 0;
 59     emr.offBitsSrc = 0;
 60     emr.cbBitsSrc = 0;
 61 
 62     ret = EMFDRV_WriteRecord( dev, &emr.emr );
 63     if(ret)
 64         EMFDRV_UpdateBBox( dev, &emr.rclBounds );
 65     return ret;
 66 }
 67 
 68 /* Utilitarian function used by EMFDRV_BitBlt and EMFDRV_StretchBlt */
 69 
 70 static BOOL EMFDRV_BitBlockTransfer( 
 71     PHYSDEV devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,  
 72     PHYSDEV devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, DWORD rop,
 73     DWORD emrType)
 74 {
 75     BOOL ret;
 76     PEMRBITBLT pEMR;
 77     UINT emrSize;
 78     UINT bmiSize;
 79     UINT bitsSize;
 80     UINT size;
 81     BITMAP  BM;
 82     WORD nBPP;
 83     LPBITMAPINFOHEADER lpBmiH;
 84     EMFDRV_PDEVICE* physDevSrc = (EMFDRV_PDEVICE*)devSrc;
 85     HBITMAP hBitmap = GetCurrentObject(physDevSrc->hdc, OBJ_BITMAP);
 86 
 87     if (emrType == EMR_BITBLT)
 88         emrSize = sizeof(EMRBITBLT);
 89     else if (emrType == EMR_STRETCHBLT)
 90         emrSize = sizeof(EMRSTRETCHBLT);
 91     else
 92         return FALSE;
 93 
 94     if(sizeof(BITMAP) != GetObjectW(hBitmap, sizeof(BITMAP), &BM))
 95         return FALSE;
 96 
 97     nBPP = BM.bmPlanes * BM.bmBitsPixel;
 98     if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */
 99 
100     bitsSize = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight;
101     bmiSize = sizeof(BITMAPINFOHEADER) + 
102         (nBPP <= 8 ? 1 << nBPP : 0) * sizeof(RGBQUAD);
103     size = emrSize + bmiSize + bitsSize;
104 
105     pEMR = HeapAlloc(GetProcessHeap(), 0, size);
106     if (!pEMR) return FALSE;
107 
108     /* Initialize EMR */
109     pEMR->emr.iType = emrType;
110     pEMR->emr.nSize = size;
111     pEMR->rclBounds.left = xDst;
112     pEMR->rclBounds.top = yDst;
113     pEMR->rclBounds.right = xDst + widthDst - 1;
114     pEMR->rclBounds.bottom = yDst + heightDst - 1;
115     pEMR->xDest = xDst;
116     pEMR->yDest = yDst;
117     pEMR->cxDest = widthDst;
118     pEMR->cyDest = heightDst;
119     pEMR->dwRop = rop;
120     pEMR->xSrc = xSrc;
121     pEMR->ySrc = ySrc;
122     pEMR->xformSrc.eM11 = 1.0;  /** FIXME:           */
123     pEMR->xformSrc.eM12 = 0.0;  /** Setting default  */
124     pEMR->xformSrc.eM21 = 0.0;  /** value.           */
125     pEMR->xformSrc.eM22 = 1.0;  /** Where should we  */
126     pEMR->xformSrc.eDx = 0.0;   /** get that info    */
127     pEMR->xformSrc.eDy = 0.0;   /** ????             */
128     pEMR->crBkColorSrc = GetBkColor(physDevSrc->hdc);
129     pEMR->iUsageSrc = DIB_RGB_COLORS;
130     pEMR->offBmiSrc = emrSize;
131     pEMR->cbBmiSrc = bmiSize;
132     pEMR->offBitsSrc = emrSize + bmiSize;
133     pEMR->cbBitsSrc = bitsSize;
134     if (emrType == EMR_STRETCHBLT) 
135     {
136         PEMRSTRETCHBLT pEMRStretch = (PEMRSTRETCHBLT)pEMR;
137         pEMRStretch->cxSrc = widthSrc;
138         pEMRStretch->cySrc = heightSrc;
139     }
140 
141     /* Initialize BITMAPINFO structure */
142     lpBmiH = (LPBITMAPINFOHEADER)((BYTE*)pEMR + pEMR->offBmiSrc);
143 
144     lpBmiH->biSize = sizeof(BITMAPINFOHEADER); 
145     lpBmiH->biWidth =  BM.bmWidth;
146     lpBmiH->biHeight = BM.bmHeight;
147     lpBmiH->biPlanes = BM.bmPlanes;
148     lpBmiH->biBitCount = nBPP;
149     /* Assume the bitmap isn't compressed and set the BI_RGB flag. */
150     lpBmiH->biCompression = BI_RGB;
151     lpBmiH->biSizeImage = bitsSize;
152     lpBmiH->biYPelsPerMeter = /* 1 meter  = 39.37 inch */
153         MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSX),3937,100);
154     lpBmiH->biXPelsPerMeter = 
155         MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSY),3937,100);
156     lpBmiH->biClrUsed   = nBPP <= 8 ? 1 << nBPP : 0;
157     /* Set biClrImportant to 0, indicating that all of the 
158        device colors are important. */
159     lpBmiH->biClrImportant = 0; 
160 
161     /* Initialize bitmap bits */
162     if (GetDIBits(physDevSrc->hdc, hBitmap, 0, (UINT)lpBmiH->biHeight,
163                   (BYTE*)pEMR + pEMR->offBitsSrc,
164                   (LPBITMAPINFO)lpBmiH, DIB_RGB_COLORS))
165     {
166         ret = EMFDRV_WriteRecord(devDst, (EMR*)pEMR);
167         if (ret) EMFDRV_UpdateBBox(devDst, &(pEMR->rclBounds));
168     } 
169     else
170         ret = FALSE;
171 
172     HeapFree( GetProcessHeap(), 0, pEMR);
173     return ret;
174 }
175 
176 BOOL EMFDRV_BitBlt( 
177     PHYSDEV devDst, INT xDst, INT yDst, INT width, INT height,
178     PHYSDEV devSrc, INT xSrc, INT ySrc, DWORD rop)
179 {
180     return EMFDRV_BitBlockTransfer( devDst, xDst, yDst, width, height,  
181                                     devSrc, xSrc, ySrc, width, height, 
182                                     rop, EMR_BITBLT );
183 }
184 
185 BOOL EMFDRV_StretchBlt( 
186     PHYSDEV devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,  
187     PHYSDEV devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, DWORD rop )
188 {
189     return EMFDRV_BitBlockTransfer( devDst, xDst, yDst, widthDst, heightDst,  
190                                     devSrc, xSrc, ySrc, widthSrc, heightSrc, 
191                                     rop, EMR_STRETCHBLT );
192 }
193 
194 INT EMFDRV_StretchDIBits( PHYSDEV dev, INT xDst, INT yDst, INT widthDst,
195                                       INT heightDst, INT xSrc, INT ySrc,
196                                       INT widthSrc, INT heightSrc,
197                                       const void *bits, const BITMAPINFO *info,
198                                       UINT wUsage, DWORD dwRop )
199 {
200     EMRSTRETCHDIBITS *emr;
201     BOOL ret;
202     UINT bmi_size=0, bits_size, emr_size;
203     
204     bits_size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
205                                      info->bmiHeader.biHeight,
206                                      info->bmiHeader.biBitCount);
207 
208     /* calculate the size of the colour table */
209     bmi_size = bitmap_info_size(info, wUsage);
210 
211     emr_size = sizeof (EMRSTRETCHDIBITS) + bmi_size + bits_size;
212     emr = HeapAlloc(GetProcessHeap(), 0, emr_size );
213     if (!emr) return 0;
214 
215     /* write a bitmap info header (with colours) to the record */
216     memcpy( &emr[1], info, bmi_size);
217 
218     /* write bitmap bits to the record */
219     memcpy ( ( (BYTE *) (&emr[1]) ) + bmi_size, bits, bits_size);
220 
221     /* fill in the EMR header at the front of our piece of memory */
222     emr->emr.iType = EMR_STRETCHDIBITS;
223     emr->emr.nSize = emr_size;
224 
225     emr->xDest     = xDst;
226     emr->yDest     = yDst;
227     emr->cxDest    = widthDst;
228     emr->cyDest    = heightDst;
229     emr->dwRop     = dwRop;
230     emr->xSrc      = xSrc; /* FIXME: only save the piece of the bitmap needed */
231     emr->ySrc      = ySrc;
232 
233     emr->iUsageSrc    = wUsage;
234     emr->offBmiSrc    = sizeof (EMRSTRETCHDIBITS);
235     emr->cbBmiSrc     = bmi_size;
236     emr->offBitsSrc   = emr->offBmiSrc + bmi_size; 
237     emr->cbBitsSrc    = bits_size;
238 
239     emr->cxSrc = widthSrc;
240     emr->cySrc = heightSrc;
241 
242     emr->rclBounds.left   = xDst;
243     emr->rclBounds.top    = yDst;
244     emr->rclBounds.right  = xDst + widthDst;
245     emr->rclBounds.bottom = yDst + heightDst;
246 
247     /* save the record we just created */
248     ret = EMFDRV_WriteRecord( dev, &emr->emr );
249     if(ret)
250         EMFDRV_UpdateBBox( dev, &emr->rclBounds );
251 
252     HeapFree(GetProcessHeap(), 0, emr);
253 
254     return ret ? heightSrc : GDI_ERROR;
255 }
256 
257 INT EMFDRV_SetDIBitsToDevice( 
258     PHYSDEV dev, INT xDst, INT yDst, DWORD width, DWORD height,
259     INT xSrc, INT ySrc, UINT startscan, UINT lines,
260     LPCVOID bits, const BITMAPINFO *info, UINT wUsage )
261 {
262     EMRSETDIBITSTODEVICE* pEMR;
263     DWORD size, bmiSize, bitsSize;
264 
265     bmiSize = bitmap_info_size(info, wUsage);
266     bitsSize = DIB_GetDIBImageBytes( info->bmiHeader.biWidth,
267                                      info->bmiHeader.biHeight,
268                                      info->bmiHeader.biBitCount );
269     size = sizeof(EMRSETDIBITSTODEVICE) + bmiSize + bitsSize;
270 
271     pEMR = HeapAlloc(GetProcessHeap(), 0, size);
272     if (!pEMR) return 0;
273 
274     pEMR->emr.iType = EMR_SETDIBITSTODEVICE;
275     pEMR->emr.nSize = size;
276     pEMR->rclBounds.left = xDst;
277     pEMR->rclBounds.top = yDst;
278     pEMR->rclBounds.right = xDst + width - 1;
279     pEMR->rclBounds.bottom = yDst + height - 1;
280     pEMR->xDest = xDst;
281     pEMR->yDest = yDst;
282     pEMR->xSrc = xSrc;
283     pEMR->ySrc = ySrc;
284     pEMR->cxSrc = width;
285     pEMR->cySrc = height;
286     pEMR->offBmiSrc = sizeof(EMRSETDIBITSTODEVICE);
287     pEMR->cbBmiSrc = bmiSize;
288     pEMR->offBitsSrc = sizeof(EMRSETDIBITSTODEVICE) + bmiSize;
289     pEMR->cbBitsSrc = bitsSize;
290     pEMR->iUsageSrc = wUsage;
291     pEMR->iStartScan = startscan;
292     pEMR->cScans = lines;
293     memcpy((BYTE*)pEMR + pEMR->offBmiSrc, info, bmiSize);
294     memcpy((BYTE*)pEMR + pEMR->offBitsSrc, bits, bitsSize);
295 
296     if (EMFDRV_WriteRecord(dev, (EMR*)pEMR))
297         EMFDRV_UpdateBBox(dev, &(pEMR->rclBounds));
298 
299     HeapFree( GetProcessHeap(), 0, pEMR);
300     return lines;
301 }
302 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.