]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfbimage.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfbimage.c
1 /***********************************************************
2
3 Copyright (c) 1987  X Consortium
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
25
26
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28
29                         All Rights Reserved
30
31 Permission to use, copy, modify, and distribute this software and its 
32 documentation for any purpose and without fee is hereby granted, 
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in 
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.  
38
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 SOFTWARE.
46
47 ******************************************************************/
48 /* $XConsortium: cfbimage.c,v 1.18 94/04/17 20:28:52 dpw Exp $ */
49
50 #include "X.h"
51 #include "windowstr.h"
52 #include "pixmapstr.h"
53 #include "scrnintstr.h"
54 #include "gcstruct.h"
55 #include "cfb.h"
56 #include "cfbmskbits.h"
57 #include "servermd.h"
58
59 void
60 cfbPutImage(pDraw, pGC, depth, x, y, w, h, leftPad, format, pImage)
61     DrawablePtr pDraw;
62     GCPtr       pGC;
63     int         depth, x, y, w, h;
64     int         leftPad;
65     int         format;
66     char        *pImage;
67 {
68     int         bitsPerPixel;
69     PixmapPtr   pPixmap;
70
71     if ((w == 0) || (h == 0))
72         return;
73
74     if (format != XYPixmap)
75     {
76         pPixmap = GetScratchPixmapHeader(pDraw->pScreen, w+leftPad, h, depth,
77                       BitsPerPixel(depth), PixmapBytePad(w+leftPad, depth),
78                       (pointer)pImage);
79         if (!pPixmap)
80             return;
81         
82         cfbGetGCPrivate(pGC)->fExpose = FALSE;
83         if (format == ZPixmap)
84             (void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, pDraw, pGC,
85                                         leftPad, 0, w, h, x, y);
86         else
87             (void)(*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, pDraw, pGC,
88                                          leftPad, 0, w, h, x, y, 1);
89         cfbGetGCPrivate(pGC)->fExpose = TRUE;
90         FreeScratchPixmapHeader(pPixmap);
91     }
92     else
93     {
94         unsigned long   oldFg, oldBg;
95         XID             gcv[3];
96         unsigned long   oldPlanemask;
97         unsigned long   i;
98         long            bytesPer;
99
100         depth = pGC->depth;
101         oldPlanemask = pGC->planemask;
102         oldFg = pGC->fgPixel;
103         oldBg = pGC->bgPixel;
104         gcv[0] = ~0L;
105         gcv[1] = 0;
106         DoChangeGC(pGC, GCForeground | GCBackground, gcv, 0);
107         bytesPer = (long)h * BitmapBytePad(w + leftPad);
108
109         for (i = 1 << (depth-1); i != 0; i >>= 1, pImage += bytesPer)
110         {
111             if (i & oldPlanemask)
112             {
113                 gcv[0] = i;
114                 DoChangeGC(pGC, GCPlaneMask, gcv, 0);
115                 ValidateGC(pDraw, pGC);
116                 (*pGC->ops->PutImage)(pDraw, pGC, 1, x, y, w, h, leftPad,
117                                  XYBitmap, pImage);
118             }
119         }
120         gcv[0] = oldPlanemask;
121         gcv[1] = oldFg;
122         gcv[2] = oldBg;
123         DoChangeGC(pGC, GCPlaneMask | GCForeground | GCBackground, gcv, 0);
124     }
125 }
126
127 void
128 cfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine)
129     DrawablePtr pDrawable;
130     int         sx, sy, w, h;
131     unsigned int format;
132     unsigned long planeMask;
133     char        *pdstLine;
134 {
135     BoxRec box;
136     DDXPointRec ptSrc;
137     RegionRec rgnDst;
138     ScreenPtr pScreen;
139     PixmapPtr pPixmap;
140
141     if ((w == 0) || (h == 0))
142         return;
143     if (pDrawable->bitsPerPixel == 1)
144     {
145         mfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
146         return;
147     }
148     pScreen = pDrawable->pScreen;
149     if (format == ZPixmap)
150     {
151         pPixmap = GetScratchPixmapHeader(pScreen, w, h, 
152                         pDrawable->depth, pDrawable->bitsPerPixel,
153                         PixmapBytePad(w,pDrawable->depth), (pointer)pdstLine);
154         if (!pPixmap)
155             return;
156         if ((planeMask & PMSK) != PMSK)
157             bzero((char *)pdstLine, pPixmap->devKind * h);
158         ptSrc.x = sx + pDrawable->x;
159         ptSrc.y = sy + pDrawable->y;
160         box.x1 = 0;
161         box.y1 = 0;
162         box.x2 = w;
163         box.y2 = h;
164         REGION_INIT(pScreen, &rgnDst, &box, 1);
165         cfbDoBitblt(pDrawable, (DrawablePtr)pPixmap, GXcopy, &rgnDst,
166                     &ptSrc, planeMask);
167         REGION_UNINIT(pScreen, &rgnDst);
168         FreeScratchPixmapHeader(pPixmap);
169     }
170     else
171     {
172 #if PSZ == 8
173         pPixmap = GetScratchPixmapHeader(pScreen, w, h,  /*depth*/ 1,
174                         /*bpp*/ 1, BitmapBytePad(w), (pointer)pdstLine);
175         if (!pPixmap)
176             return;
177
178         ptSrc.x = sx + pDrawable->x;
179         ptSrc.y = sy + pDrawable->y;
180         box.x1 = 0;
181         box.y1 = 0;
182         box.x2 = w;
183         box.y2 = h;
184         REGION_INIT(pScreen, &rgnDst, &box, 1);
185         cfbCopyImagePlane (pDrawable, (DrawablePtr)pPixmap, GXcopy, &rgnDst,
186                     &ptSrc, planeMask);
187         REGION_UNINIT(pScreen, &rgnDst);
188         FreeScratchPixmapHeader(pPixmap);
189 #else
190         miGetImage (pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
191 #endif
192     }
193 }