2 * tableinitcmtemplate.c - template for initialising lookup tables for
3 * translation from a colour map to true colour.
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.
10 * I know this code isn't nice to read because of all the macros, but
11 * efficiency is important here.
15 * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
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.
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.
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,
34 #error "This file shouldn't be compiled."
35 #error "It is included as part of translate.c"
38 #define OUT_T CONCAT2E(CARD,OUT)
39 #define SwapOUT(x) CONCAT2E(Swap,OUT(x))
40 #define rfbInitColourMapSingleTableOUT \
41 CONCAT2E(rfbInitColourMapSingleTable,OUT)
44 rfbInitColourMapSingleTableOUT (char **table, rfbPixelFormat *in,
50 int nEntries = 1 << in->bitsPerPixel;
52 if (*table) free(*table);
53 *table = (char *)malloc(nEntries * sizeof(OUT_T));
56 pent = (EntryPtr)&rfbInstalledColormap->red[0];
58 for (i = 0; i < nEntries; i++) {
60 r = pent->co.shco.red->color;
61 g = pent->co.shco.green->color;
62 b = pent->co.shco.blue->color;
64 r = pent->co.local.red;
65 g = pent->co.local.green;
66 b = pent->co.local.blue;
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));
72 if (out->bigEndian != in->bigEndian) {
82 #undef rfbInitColourMapSingleTableOUT