]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/hw/vnc/tableinitcmtemplate.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / hw / vnc / tableinitcmtemplate.c
1 /*
2  * tableinitcmtemplate.c - template for initialising lookup tables for
3  * translation from a colour map to true colour.
4  *
5  * This file shouldn't be compiled.  It is included multiple times by
6  * translate.c, each time with a different definition of the macro OUT.
7  * For each value of OUT, this file defines a function which allocates an
8  * appropriately sized lookup table and initialises it.
9  *
10  * I know this code isn't nice to read because of all the macros, but
11  * efficiency is important here.
12  */
13
14 /*
15  *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
16  *
17  *  This is free software; you can redistribute it and/or modify
18  *  it under the terms of the GNU General Public License as published by
19  *  the Free Software Foundation; either version 2 of the License, or
20  *  (at your option) any later version.
21  *
22  *  This software is distributed in the hope that it will be useful,
23  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  *  GNU General Public License for more details.
26  *
27  *  You should have received a copy of the GNU General Public License
28  *  along with this software; if not, write to the Free Software
29  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
30  *  USA.
31  */
32
33 #if !defined(OUT)
34 #error "This file shouldn't be compiled."
35 #error "It is included as part of translate.c"
36 #endif
37
38 #define OUT_T CONCAT2E(CARD,OUT)
39 #define SwapOUT(x) CONCAT2E(Swap,OUT(x))
40 #define rfbInitColourMapSingleTableOUT \
41                                 CONCAT2E(rfbInitColourMapSingleTable,OUT)
42
43 static void
44 rfbInitColourMapSingleTableOUT (char **table, rfbPixelFormat *in,
45                                 rfbPixelFormat *out)
46 {
47     int i, r, g, b;
48     OUT_T *t;
49     EntryPtr pent;
50     int nEntries = 1 << in->bitsPerPixel;
51
52     if (*table) free(*table);
53     *table = (char *)malloc(nEntries * sizeof(OUT_T));
54     t = (OUT_T *)*table;
55
56     pent = (EntryPtr)&rfbInstalledColormap->red[0];
57
58     for (i = 0; i < nEntries; i++) {
59         if (pent->fShared) {
60             r = pent->co.shco.red->color;
61             g = pent->co.shco.green->color;
62             b = pent->co.shco.blue->color;
63         } else {
64             r = pent->co.local.red;
65             g = pent->co.local.green;
66             b = pent->co.local.blue;
67         }
68         t[i] = ((((r * out->redMax + 32767) / 65535) << out->redShift) |
69                 (((g * out->greenMax + 32767) / 65535) << out->greenShift) |
70                 (((b * out->blueMax + 32767) / 65535) << out->blueShift));
71 #if (OUT != 8)
72         if (out->bigEndian != in->bigEndian) {
73             t[i] = SwapOUT(t[i]);
74         }
75 #endif
76         pent++;
77     }
78 }
79
80 #undef OUT_T
81 #undef SwapOUT
82 #undef rfbInitColourMapSingleTableOUT