2 * tableinittctemplate.c - template for initialising lookup tables for
3 * truecolour to truecolour translation.
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 two functions for initialising
8 * lookup tables. One is for truecolour translation using a single lookup
9 * table, the other is for truecolour translation using three separate
10 * lookup tables for the red, green and blue values.
12 * I know this code isn't nice to read because of all the macros, but
13 * efficiency is important here.
17 * Copyright (C) 1999 AT&T Laboratories Cambridge. 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 CONCAT2E(CARD,OUT)
41 #define SwapOUT(x) CONCAT2E(Swap,OUT(x))
42 #define rfbInitTrueColourSingleTableOUT \
43 CONCAT2E(rfbInitTrueColourSingleTable,OUT)
44 #define rfbInitTrueColourRGBTablesOUT CONCAT2E(rfbInitTrueColourRGBTables,OUT)
45 #define rfbInitOneRGBTableOUT CONCAT2E(rfbInitOneRGBTable,OUT)
48 rfbInitOneRGBTableOUT (OUT_T *table, int inMax, int outMax, int outShift,
53 * rfbInitTrueColourSingleTable sets up a single lookup table for truecolour
58 rfbInitTrueColourSingleTableOUT (char **table, rfbPixelFormat *in,
62 int inRed, inGreen, inBlue, outRed, outGreen, outBlue;
64 int nEntries = 1 << in->bitsPerPixel;
66 if (*table) free(*table);
67 *table = (char *)malloc(nEntries * sizeof(OUT_T));
70 for (i = 0; i < nEntries; i++) {
71 inRed = (i >> in->redShift) & in->redMax;
72 inGreen = (i >> in->greenShift) & in->greenMax;
73 inBlue = (i >> in->blueShift) & in->blueMax;
75 outRed = (inRed * out->redMax + in->redMax / 2) / in->redMax;
76 outGreen = (inGreen * out->greenMax + in->greenMax / 2) / in->greenMax;
77 outBlue = (inBlue * out->blueMax + in->blueMax / 2) / in->blueMax;
79 t[i] = ((outRed << out->redShift) |
80 (outGreen << out->greenShift) |
81 (outBlue << out->blueShift));
83 if (out->bigEndian != in->bigEndian) {
92 * rfbInitTrueColourRGBTables sets up three separate lookup tables for the
93 * red, green and blue values.
97 rfbInitTrueColourRGBTablesOUT (char **table, rfbPixelFormat *in,
104 if (*table) free(*table);
105 *table = (char *)malloc((in->redMax + in->greenMax + in->blueMax + 3)
107 redTable = (OUT_T *)*table;
108 greenTable = redTable + in->redMax + 1;
109 blueTable = greenTable + in->greenMax + 1;
111 rfbInitOneRGBTableOUT (redTable, in->redMax, out->redMax,
112 out->redShift, (out->bigEndian != in->bigEndian));
113 rfbInitOneRGBTableOUT (greenTable, in->greenMax, out->greenMax,
114 out->greenShift, (out->bigEndian != in->bigEndian));
115 rfbInitOneRGBTableOUT (blueTable, in->blueMax, out->blueMax,
116 out->blueShift, (out->bigEndian != in->bigEndian));
120 rfbInitOneRGBTableOUT (OUT_T *table, int inMax, int outMax, int outShift,
124 int nEntries = inMax + 1;
126 for (i = 0; i < nEntries; i++) {
127 table[i] = ((i * outMax + inMax / 2) / inMax) << outShift;
130 table[i] = SwapOUT(table[i]);
138 #undef rfbInitTrueColourSingleTableOUT
139 #undef rfbInitTrueColourRGBTablesOUT
140 #undef rfbInitOneRGBTableOUT