]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfb8bit.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfb8bit.c
1 /* $XConsortium: cfb8bit.c,v 1.13 94/09/29 20:33:11 dpw Exp $ */
2 /*
3
4 Copyright (c) 1989, 1994  X Consortium
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
24
25 Except as contained in this notice, the name of the X Consortium shall
26 not be used in advertising or otherwise to promote the sale, use or
27 other dealings in this Software without prior written authorization
28 from the X Consortium.
29
30 */
31
32 /*
33  * cfb8bit.c
34  *
35  * 8 bit color frame buffer utility routines
36  */
37
38
39 #if PSZ == 8
40
41 #include        "X.h"
42 #include        "Xmd.h"
43 #include        "Xproto.h"
44 #include        "gcstruct.h"
45 #include        "windowstr.h"
46 #include        "scrnintstr.h"
47 #include        "pixmapstr.h"
48 #include        "regionstr.h"
49 #include        "cfb.h"
50 #include        "cfbmskbits.h"
51 #include        "cfb8bit.h"
52
53 PixelGroup cfb8StippleMasks[NUM_MASKS] = {
54 #if NUM_MASKS == 16
55     0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
56     0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
57     0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
58     0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
59 #else /* NUM_MASKS == 256 */
60     0x0000000000000000, 0x00000000000000ff,
61     0x000000000000ff00, 0x000000000000ffff,
62     0x0000000000ff0000, 0x0000000000ff00ff,
63     0x0000000000ffff00, 0x0000000000ffffff,
64     0x00000000ff000000, 0x00000000ff0000ff,
65     0x00000000ff00ff00, 0x00000000ff00ffff,
66     0x00000000ffff0000, 0x00000000ffff00ff,
67     0x00000000ffffff00, 0x00000000ffffffff,
68     0x000000ff00000000, 0x000000ff000000ff,
69     0x000000ff0000ff00, 0x000000ff0000ffff,
70     0x000000ff00ff0000, 0x000000ff00ff00ff,
71     0x000000ff00ffff00, 0x000000ff00ffffff,
72     0x000000ffff000000, 0x000000ffff0000ff,
73     0x000000ffff00ff00, 0x000000ffff00ffff,
74     0x000000ffffff0000, 0x000000ffffff00ff,
75     0x000000ffffffff00, 0x000000ffffffffff,
76     0x0000ff0000000000, 0x0000ff00000000ff,
77     0x0000ff000000ff00, 0x0000ff000000ffff,
78     0x0000ff0000ff0000, 0x0000ff0000ff00ff,
79     0x0000ff0000ffff00, 0x0000ff0000ffffff,
80     0x0000ff00ff000000, 0x0000ff00ff0000ff,
81     0x0000ff00ff00ff00, 0x0000ff00ff00ffff,
82     0x0000ff00ffff0000, 0x0000ff00ffff00ff,
83     0x0000ff00ffffff00, 0x0000ff00ffffffff,
84     0x0000ffff00000000, 0x0000ffff000000ff,
85     0x0000ffff0000ff00, 0x0000ffff0000ffff,
86     0x0000ffff00ff0000, 0x0000ffff00ff00ff,
87     0x0000ffff00ffff00, 0x0000ffff00ffffff,
88     0x0000ffffff000000, 0x0000ffffff0000ff,
89     0x0000ffffff00ff00, 0x0000ffffff00ffff,
90     0x0000ffffffff0000, 0x0000ffffffff00ff,
91     0x0000ffffffffff00, 0x0000ffffffffffff,
92     0x00ff000000000000, 0x00ff0000000000ff,
93     0x00ff00000000ff00, 0x00ff00000000ffff,
94     0x00ff000000ff0000, 0x00ff000000ff00ff,
95     0x00ff000000ffff00, 0x00ff000000ffffff,
96     0x00ff0000ff000000, 0x00ff0000ff0000ff,
97     0x00ff0000ff00ff00, 0x00ff0000ff00ffff,
98     0x00ff0000ffff0000, 0x00ff0000ffff00ff,
99     0x00ff0000ffffff00, 0x00ff0000ffffffff,
100     0x00ff00ff00000000, 0x00ff00ff000000ff,
101     0x00ff00ff0000ff00, 0x00ff00ff0000ffff,
102     0x00ff00ff00ff0000, 0x00ff00ff00ff00ff,
103     0x00ff00ff00ffff00, 0x00ff00ff00ffffff,
104     0x00ff00ffff000000, 0x00ff00ffff0000ff,
105     0x00ff00ffff00ff00, 0x00ff00ffff00ffff,
106     0x00ff00ffffff0000, 0x00ff00ffffff00ff,
107     0x00ff00ffffffff00, 0x00ff00ffffffffff,
108     0x00ffff0000000000, 0x00ffff00000000ff,
109     0x00ffff000000ff00, 0x00ffff000000ffff,
110     0x00ffff0000ff0000, 0x00ffff0000ff00ff,
111     0x00ffff0000ffff00, 0x00ffff0000ffffff,
112     0x00ffff00ff000000, 0x00ffff00ff0000ff,
113     0x00ffff00ff00ff00, 0x00ffff00ff00ffff,
114     0x00ffff00ffff0000, 0x00ffff00ffff00ff,
115     0x00ffff00ffffff00, 0x00ffff00ffffffff,
116     0x00ffffff00000000, 0x00ffffff000000ff,
117     0x00ffffff0000ff00, 0x00ffffff0000ffff,
118     0x00ffffff00ff0000, 0x00ffffff00ff00ff,
119     0x00ffffff00ffff00, 0x00ffffff00ffffff,
120     0x00ffffffff000000, 0x00ffffffff0000ff,
121     0x00ffffffff00ff00, 0x00ffffffff00ffff,
122     0x00ffffffffff0000, 0x00ffffffffff00ff,
123     0x00ffffffffffff00, 0x00ffffffffffffff,
124     0xff00000000000000, 0xff000000000000ff,
125     0xff0000000000ff00, 0xff0000000000ffff,
126     0xff00000000ff0000, 0xff00000000ff00ff,
127     0xff00000000ffff00, 0xff00000000ffffff,
128     0xff000000ff000000, 0xff000000ff0000ff,
129     0xff000000ff00ff00, 0xff000000ff00ffff,
130     0xff000000ffff0000, 0xff000000ffff00ff,
131     0xff000000ffffff00, 0xff000000ffffffff,
132     0xff0000ff00000000, 0xff0000ff000000ff,
133     0xff0000ff0000ff00, 0xff0000ff0000ffff,
134     0xff0000ff00ff0000, 0xff0000ff00ff00ff,
135     0xff0000ff00ffff00, 0xff0000ff00ffffff,
136     0xff0000ffff000000, 0xff0000ffff0000ff,
137     0xff0000ffff00ff00, 0xff0000ffff00ffff,
138     0xff0000ffffff0000, 0xff0000ffffff00ff,
139     0xff0000ffffffff00, 0xff0000ffffffffff,
140     0xff00ff0000000000, 0xff00ff00000000ff,
141     0xff00ff000000ff00, 0xff00ff000000ffff,
142     0xff00ff0000ff0000, 0xff00ff0000ff00ff,
143     0xff00ff0000ffff00, 0xff00ff0000ffffff,
144     0xff00ff00ff000000, 0xff00ff00ff0000ff,
145     0xff00ff00ff00ff00, 0xff00ff00ff00ffff,
146     0xff00ff00ffff0000, 0xff00ff00ffff00ff,
147     0xff00ff00ffffff00, 0xff00ff00ffffffff,
148     0xff00ffff00000000, 0xff00ffff000000ff,
149     0xff00ffff0000ff00, 0xff00ffff0000ffff,
150     0xff00ffff00ff0000, 0xff00ffff00ff00ff,
151     0xff00ffff00ffff00, 0xff00ffff00ffffff,
152     0xff00ffffff000000, 0xff00ffffff0000ff,
153     0xff00ffffff00ff00, 0xff00ffffff00ffff,
154     0xff00ffffffff0000, 0xff00ffffffff00ff,
155     0xff00ffffffffff00, 0xff00ffffffffffff,
156     0xffff000000000000, 0xffff0000000000ff,
157     0xffff00000000ff00, 0xffff00000000ffff,
158     0xffff000000ff0000, 0xffff000000ff00ff,
159     0xffff000000ffff00, 0xffff000000ffffff,
160     0xffff0000ff000000, 0xffff0000ff0000ff,
161     0xffff0000ff00ff00, 0xffff0000ff00ffff,
162     0xffff0000ffff0000, 0xffff0000ffff00ff,
163     0xffff0000ffffff00, 0xffff0000ffffffff,
164     0xffff00ff00000000, 0xffff00ff000000ff,
165     0xffff00ff0000ff00, 0xffff00ff0000ffff,
166     0xffff00ff00ff0000, 0xffff00ff00ff00ff,
167     0xffff00ff00ffff00, 0xffff00ff00ffffff,
168     0xffff00ffff000000, 0xffff00ffff0000ff,
169     0xffff00ffff00ff00, 0xffff00ffff00ffff,
170     0xffff00ffffff0000, 0xffff00ffffff00ff,
171     0xffff00ffffffff00, 0xffff00ffffffffff,
172     0xffffff0000000000, 0xffffff00000000ff,
173     0xffffff000000ff00, 0xffffff000000ffff,
174     0xffffff0000ff0000, 0xffffff0000ff00ff,
175     0xffffff0000ffff00, 0xffffff0000ffffff,
176     0xffffff00ff000000, 0xffffff00ff0000ff,
177     0xffffff00ff00ff00, 0xffffff00ff00ffff,
178     0xffffff00ffff0000, 0xffffff00ffff00ff,
179     0xffffff00ffffff00, 0xffffff00ffffffff,
180     0xffffffff00000000, 0xffffffff000000ff,
181     0xffffffff0000ff00, 0xffffffff0000ffff,
182     0xffffffff00ff0000, 0xffffffff00ff00ff,
183     0xffffffff00ffff00, 0xffffffff00ffffff,
184     0xffffffffff000000, 0xffffffffff0000ff,
185     0xffffffffff00ff00, 0xffffffffff00ffff,
186     0xffffffffffff0000, 0xffffffffffff00ff,
187     0xffffffffffffff00, 0xffffffffffffffff
188 #endif
189 };
190
191 int     cfb8StippleMode, cfb8StippleAlu, cfb8StippleRRop;
192 PixelGroup cfb8StippleFg, cfb8StippleBg, cfb8StipplePm;
193 PixelGroup cfb8StippleAnd[NUM_MASKS], cfb8StippleXor[NUM_MASKS];
194
195 int
196 cfb8SetStipple (alu, fg, planemask)
197 int             alu;
198 unsigned long   fg, planemask;
199 {
200     unsigned long   and, xor, rrop;
201     int s;
202     unsigned long   c;
203
204     cfb8StippleMode = FillStippled;
205     cfb8StippleAlu = alu;
206     cfb8StippleFg = fg & PMSK;
207     cfb8StipplePm = planemask & PMSK;
208     rrop = cfbReduceRasterOp (alu, fg, planemask, &and, &xor);
209     cfb8StippleRRop = rrop;
210     /*
211      * create the appropriate pixel-fill bits for current
212      * foreground
213      */
214     for (s = 0; s < NUM_MASKS; s++)
215     {
216         c = cfb8StippleMasks[s];
217         cfb8StippleAnd[s] = and | ~c;
218         cfb8StippleXor[s] = xor & c;
219     }
220     return TRUE;
221 }
222
223
224 int
225 cfb8SetOpaqueStipple (alu, fg, bg, planemask)
226 int             alu;
227 unsigned long   fg, bg, planemask;
228 {
229     unsigned long   andfg, xorfg, andbg, xorbg, rropfg, rropbg;
230     int s;
231     unsigned long   c;
232
233     cfb8StippleMode = FillOpaqueStippled;
234     cfb8StippleAlu = alu;
235     cfb8StippleFg = fg & PMSK;
236     cfb8StippleBg = bg & PMSK;
237     cfb8StipplePm = planemask & PMSK;
238     rropfg = cfbReduceRasterOp (alu, cfb8StippleFg, cfb8StipplePm, &andfg, &xorfg);
239     rropbg = cfbReduceRasterOp (alu, cfb8StippleBg, cfb8StipplePm, &andbg, &xorbg);
240     if (rropfg == rropbg)
241         cfb8StippleRRop = rropfg;
242     else
243         cfb8StippleRRop = GXset;
244     /*
245      * create the appropriate pixel-fill bits for current
246      * foreground
247      */
248     for (s = 0; s < NUM_MASKS; s++)
249     {
250         c = cfb8StippleMasks[s];
251         cfb8StippleAnd[s] = (andfg | ~c) & (andbg | c);
252         cfb8StippleXor[s] = (xorfg & c) | (xorbg & ~c);
253     }
254     return TRUE;
255 }
256
257 /*
258  * a grungy little routine.  This computes clip masks
259  * for partial character blts.  Returns rgnOUT if the
260  * entire character is clipped; returns rgnIN if the entire
261  * character is unclipped; returns rgnPART if a portion of
262  * the character is visible.  Computes clip masks for each
263  * longword of the character -- and those with the
264  * contents of the glyph to compute the visible bits.
265  */
266
267 #if PGSZ == 32
268 #if (BITMAP_BIT_ORDER == MSBFirst)
269 PixelGroup cfb8BitLenMasks[PGSZ] = {
270     0xffffffff, 0x7fffffff, 0x3fffffff, 0x1fffffff,
271     0x0fffffff, 0x07ffffff, 0x03ffffff, 0x01ffffff,
272     0x00ffffff, 0x007fffff, 0x003fffff, 0x001fffff,
273     0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff,
274     0x0000ffff, 0x00007fff, 0x00003fff, 0x00001fff,
275     0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff,
276     0x000000ff, 0x0000007f, 0x0000003f, 0x0000001f,
277     0x0000000f, 0x00000007, 0x00000003, 0x00000001,
278 };
279 #else
280 PixelGroup cfb8BitLenMasks[PGSZ] = {
281     0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8,
282     0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80,
283     0xffffff00, 0xfffffe00, 0xfffffc00, 0xfffff800,
284     0xfffff000, 0xffffe000, 0xffffc000, 0xffff8000,
285     0xffff0000, 0xfffe0000, 0xfffc0000, 0xfff80000,
286     0xfff00000, 0xffe00000, 0xffc00000, 0xff800000,
287     0xff000000, 0xfe000000, 0xfc000000, 0xf8000000,
288     0xf0000000, 0xe0000000, 0xc0000000, 0x80000000,
289 };
290 #endif /* BITMAP_BIT_ORDER */
291 #else /* PGSZ == 64 */
292 #if (BITMAP_BIT_ORDER == MSBFirst)
293 PixelGroup cfb8BitLenMasks[PGSZ] = {
294     0xffffffffffffffff,    0x7fffffffffffffff,
295     0x3fffffffffffffff,    0x1fffffffffffffff,
296     0x0fffffffffffffff,    0x07ffffffffffffff,
297     0x03ffffffffffffff,    0x01ffffffffffffff,
298     0x00ffffffffffffff,    0x007fffffffffffff,
299     0x003fffffffffffff,    0x001fffffffffffff,
300     0x000fffffffffffff,    0x0007ffffffffffff,
301     0x0003ffffffffffff,    0x0001ffffffffffff,
302     0x0000ffffffffffff,    0x00007fffffffffff,
303     0x00003fffffffffff,    0x00001fffffffffff,
304     0x00000fffffffffff,    0x000007ffffffffff,
305     0x000003ffffffffff,    0x000001ffffffffff,
306     0x000000ffffffffff,    0x0000007fffffffff,
307     0x0000003fffffffff,    0x0000001fffffffff,
308     0x0000000fffffffff,    0x00000007ffffffff,
309     0x00000003ffffffff,    0x00000001ffffffff,
310     0x00000000ffffffff,    0x000000007fffffff,
311     0x000000003fffffff,    0x000000001fffffff,
312     0x000000000fffffff,    0x0000000007ffffff,
313     0x0000000003ffffff,    0x0000000001ffffff,
314     0x0000000000ffffff,    0x00000000007fffff,
315     0x00000000003fffff,    0x00000000001fffff,
316     0x00000000000fffff,    0x000000000007ffff,
317     0x000000000003ffff,    0x000000000001ffff,
318     0x000000000000ffff,    0x0000000000007fff,
319     0x0000000000003fff,    0x0000000000001fff,
320     0x0000000000000fff,    0x00000000000007ff,
321     0x00000000000003ff,    0x00000000000001ff,
322     0x00000000000000ff,    0x000000000000007f,
323     0x000000000000003f,    0x000000000000001f,
324     0x000000000000000f,    0x0000000000000007,
325     0x0000000000000003,    0x0000000000000001
326 };
327 #else
328 PixelGroup cfb8BitLenMasks[PGSZ] = {
329     0xffffffffffffffff,    0xfffffffffffffffe,
330     0xfffffffffffffffc,    0xfffffffffffffff8,
331     0xfffffffffffffff0,    0xffffffffffffffe0,
332     0xffffffffffffffc0,    0xffffffffffffff80,
333     0xffffffffffffff00,    0xfffffffffffffe00,
334     0xfffffffffffffc00,    0xfffffffffffff800,
335     0xfffffffffffff000,    0xffffffffffffe000,
336     0xffffffffffffc000,    0xffffffffffff8000,
337     0xffffffffffff0000,    0xfffffffffffe0000,
338     0xfffffffffffc0000,    0xfffffffffff80000,
339     0xfffffffffff00000,    0xffffffffffe00000,
340     0xffffffffffc00000,    0xffffffffff800000,
341     0xffffffffff000000,    0xfffffffffe000000,
342     0xfffffffffc000000,    0xfffffffff8000000,
343     0xfffffffff0000000,    0xffffffffe0000000,
344     0xffffffffc0000000,    0xffffffff80000000,
345     0xffffffff00000000,    0xfffffffe00000000,
346     0xfffffffc00000000,    0xfffffff800000000,
347     0xfffffff000000000,    0xffffffe000000000,
348     0xffffffc000000000,    0xffffff8000000000,
349     0xffffff0000000000,    0xfffffe0000000000,
350     0xfffffc0000000000,    0xfffff80000000000,
351     0xfffff00000000000,    0xffffe00000000000,
352     0xffffc00000000000,    0xffff800000000000,
353     0xffff000000000000,    0xfffe000000000000,
354     0xfffc000000000000,    0xfff8000000000000,
355     0xfff0000000000000,    0xffe0000000000000,
356     0xffc0000000000000,    0xff80000000000000,
357     0xff00000000000000,    0xfe00000000000000,
358     0xfc00000000000000,    0xf800000000000000,
359     0xf000000000000000,    0xe000000000000000,
360     0xc000000000000000,    0x8000000000000000
361 };
362 #endif /* BITMAP_BIT_ORDER */
363 #endif /* PGSZ */
364
365
366
367 int
368 cfb8ComputeClipMasks32 (pBox, numRects, x, y, w, h, clips)
369     BoxPtr      pBox;
370     int         numRects;
371     int         x, y, w, h;
372     CARD32      *clips;
373 {
374     int     yBand, yBandBot;
375     int     ch;
376     unsigned long           clip;
377     int     partIN = FALSE, partOUT = FALSE;
378     int     result;
379
380     if (numRects == 0)
381         return rgnOUT;
382     while (numRects && pBox->y2 <= y)
383     {
384         --numRects;
385         ++pBox;
386     }
387     if (!numRects || pBox->y1 >= y + h)
388         return rgnOUT;
389     yBand = pBox->y1;
390     while (numRects && pBox->y1 == yBand && pBox->x2 <= x)
391     {
392         --numRects;
393         ++pBox;
394     }
395     if (!numRects || pBox->y1 >= y + h)
396         return rgnOUT;
397     if (numRects &&
398         x >= pBox->x1 &&
399         x + w <= pBox->x2 &&
400         y >= pBox->y1 &&
401         y + h <= pBox->y2)
402     {
403         return rgnIN;
404     }
405     ch = 0;
406     while (numRects && pBox->y1 < y + h)
407     {
408         yBand = pBox->y1;
409         yBandBot = pBox->y2;
410         while (ch < h && y + ch < yBand)
411         {
412             partOUT = TRUE;
413             clips[ch++] = 0;
414         }
415         if (ch >= h)
416             break;
417         while (numRects && pBox->y1 == yBand && pBox->x2 <= x)
418         {
419             --numRects;
420             ++pBox;
421         }
422         if (!numRects)
423             break;
424         clip = 0;
425         while (numRects && pBox->y1 == yBand && pBox->x1 < x + w)
426         {
427             if (x < pBox->x1)
428                 if (pBox->x2 < x + w)
429                     clip |= cfb8BitLenMasks[pBox->x1 - x] & ~cfb8BitLenMasks[pBox->x2 - x];
430                 else
431                     clip |= cfb8BitLenMasks[pBox->x1 - x];
432             else
433                 if (pBox->x2 < x + w)
434                     clip |= ~cfb8BitLenMasks[pBox->x2 - x];
435                 else
436                     clip = ~0;
437             --numRects;
438             ++pBox;
439         }
440         if (clip != 0)
441                 partIN = TRUE;
442         if (clip != ~0)
443                 partOUT = TRUE;
444         while (ch < h && y + ch < yBandBot)
445             clips[ch++] = clip;
446         while (numRects && pBox->y1 == yBand)
447         {
448             --numRects;
449             ++pBox;
450         }
451     }
452     while (ch < h)
453     {
454         partOUT = TRUE;
455         clips[ch++] = 0;
456     }
457     result = rgnOUT;
458     if (partIN)
459     {
460         if (partOUT)
461             result = rgnPART;
462         else
463             result = rgnIN;
464     }
465     return result;
466 }
467
468 #endif /* PSZ == 8 */