]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/hw/vnc/tabletranstemplate.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / hw / vnc / tabletranstemplate.c
1 /*
2  * tabletranstemplate.c - template for translation using lookup tables.
3  *
4  * This file shouldn't be compiled.  It is included multiple times by
5  * translate.c, each time with different definitions of the macros IN and OUT.
6  *
7  * For each pair of values IN and OUT, this file defines two functions for
8  * translating a given rectangle of pixel data.  One uses a single lookup
9  * table, and the other uses three separate lookup tables for the red, green
10  * and blue values.
11  *
12  * I know this code isn't nice to read because of all the macros, but
13  * efficiency is important here.
14  */
15
16 /*
17  *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
18  *
19  *  This is free software; you can redistribute it and/or modify
20  *  it under the terms of the GNU General Public License as published by
21  *  the Free Software Foundation; either version 2 of the License, or
22  *  (at your option) any later version.
23  *
24  *  This software is distributed in the hope that it will be useful,
25  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  *  GNU General Public License for more details.
28  *
29  *  You should have received a copy of the GNU General Public License
30  *  along with this software; if not, write to the Free Software
31  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
32  *  USA.
33  */
34
35 #if !defined(IN) || !defined(OUT)
36 #error "This file shouldn't be compiled."
37 #error "It is included as part of translate.c"
38 #endif
39
40 #define IN_T CONCAT2E(CARD,IN)
41 #define OUT_T CONCAT2E(CARD,OUT)
42 #define rfbTranslateWithSingleTableINtoOUT \
43                                 CONCAT4E(rfbTranslateWithSingleTable,IN,to,OUT)
44 #define rfbTranslateWithRGBTablesINtoOUT \
45                                 CONCAT4E(rfbTranslateWithRGBTables,IN,to,OUT)
46
47 /*
48  * rfbTranslateWithSingleTableINtoOUT translates a rectangle of pixel data
49  * using a single lookup table.
50  */
51
52 static void
53 rfbTranslateWithSingleTableINtoOUT (char *table, rfbPixelFormat *in,
54                                     rfbPixelFormat *out,
55                                     char *iptr, char *optr,
56                                     int bytesBetweenInputLines,
57                                     int width, int height)
58 {
59     IN_T *ip = (IN_T *)iptr;
60     OUT_T *op = (OUT_T *)optr;
61     int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
62     OUT_T *opLineEnd;
63     OUT_T *t = (OUT_T *)table;
64
65     while (height > 0) {
66         opLineEnd = op + width;
67
68         while (op < opLineEnd) {
69             *(op++) = t[*(ip++)];
70         }
71
72         ip += ipextra;
73         height--;
74     }
75 }
76
77
78 /*
79  * rfbTranslateWithRGBTablesINtoOUT translates a rectangle of pixel data
80  * using three separate lookup tables for the red, green and blue values.
81  */
82
83 static void
84 rfbTranslateWithRGBTablesINtoOUT (char *table, rfbPixelFormat *in,
85                                   rfbPixelFormat *out,
86                                   char *iptr, char *optr,
87                                   int bytesBetweenInputLines,
88                                   int width, int height)
89 {
90     IN_T *ip = (IN_T *)iptr;
91     OUT_T *op = (OUT_T *)optr;
92     int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
93     OUT_T *opLineEnd;
94     OUT_T *redTable = (OUT_T *)table;
95     OUT_T *greenTable = redTable + in->redMax + 1;
96     OUT_T *blueTable = greenTable + in->greenMax + 1;
97
98     while (height > 0) {
99         opLineEnd = op + width;
100
101         while (op < opLineEnd) {
102             *(op++) = (redTable[(*ip >> in->redShift) & in->redMax] |
103                        greenTable[(*ip >> in->greenShift) & in->greenMax] |
104                        blueTable[(*ip >> in->blueShift) & in->blueMax]);
105             ip++;
106         }
107         ip += ipextra;
108         height--;
109     }
110 }
111
112 #undef IN_T
113 #undef OUT_T
114 #undef rfbTranslateWithSingleTableINtoOUT
115 #undef rfbTranslateWithRGBTablesINtoOUT