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
* OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
16
* Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.
17
* All Rights Reserved.
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.
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.
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,
36
#error "This file shouldn't be compiled."
37
#error "It is included as part of translate.c"
40
#define OUT_T CONCAT3E(uint,OUT,_t)
41
#define SwapOUT(x) CONCAT2E(Swap,OUT(x))
42
#define rfbInitColourMapSingleTableOUT \
43
CONCAT2E(rfbInitColourMapSingleTable,OUT)
46
rfbInitColourMapSingleTableOUT(char **table, rfbPixelFormat *in,
47
rfbPixelFormat *out,rfbColourMap* colourMap)
51
uint32_t nEntries = 1 << in->bitsPerPixel;
52
int shift = colourMap->is16?16:8;
54
if (*table) free(*table);
55
*table = (char *)malloc(nEntries * sizeof(OUT_T));
58
for (i = 0; i < nEntries; i++) {
60
if(i < colourMap->count) {
62
r = colourMap->data.shorts[3*i+0];
63
g = colourMap->data.shorts[3*i+1];
64
b = colourMap->data.shorts[3*i+2];
66
r = colourMap->data.bytes[3*i+0];
67
g = colourMap->data.bytes[3*i+1];
68
b = colourMap->data.bytes[3*i+2];
71
t[i] = ((((r * (1 + out->redMax)) >> shift) << out->redShift) |
72
(((g * (1 + out->greenMax)) >> shift) << out->greenShift) |
73
(((b * (1 + out->blueMax)) >> shift) << out->blueShift));
75
if (out->bigEndian != in->bigEndian) {
84
#undef rfbInitColourMapSingleTableOUT