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 * OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
18 * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.
19 * All Rights Reserved.
21 * This is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
26 * This software is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this software; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
38 #error "This file shouldn't be compiled."
39 #error "It is included as part of translate.c"
42 #define OUT_T CONCAT3E(uint,OUT,_t)
43 #define SwapOUT(x) CONCAT2E(Swap,OUT(x))
44 #define rfbInitTrueColourSingleTableOUT \
45 CONCAT2E(rfbInitTrueColourSingleTable,OUT)
46 #define rfbInitTrueColourRGBTablesOUT CONCAT2E(rfbInitTrueColourRGBTables,OUT)
47 #define rfbInitOneRGBTableOUT CONCAT2E(rfbInitOneRGBTable,OUT)
50 rfbInitOneRGBTableOUT (OUT_T *table, int inMax, int outMax, int outShift,
55 * rfbInitTrueColourSingleTable sets up a single lookup table for truecolour
60 rfbInitTrueColourSingleTableOUT (char **table, rfbPixelFormat *in,
64 int inRed, inGreen, inBlue, outRed, outGreen, outBlue;
66 int nEntries = 1 << in->bitsPerPixel;
68 if (*table) free(*table);
69 *table = (char *)malloc(nEntries * sizeof(OUT_T));
72 for (i = 0; i < nEntries; i++) {
73 inRed = (i >> in->redShift) & in->redMax;
74 inGreen = (i >> in->greenShift) & in->greenMax;
75 inBlue = (i >> in->blueShift) & in->blueMax;
77 outRed = (inRed * out->redMax + in->redMax / 2) / in->redMax;
78 outGreen = (inGreen * out->greenMax + in->greenMax / 2) / in->greenMax;
79 outBlue = (inBlue * out->blueMax + in->blueMax / 2) / in->blueMax;
81 t[i] = ((outRed << out->redShift) |
82 (outGreen << out->greenShift) |
83 (outBlue << out->blueShift));
85 if (out->bigEndian != in->bigEndian) {
94 * rfbInitTrueColourRGBTables sets up three separate lookup tables for the
95 * red, green and blue values.
99 rfbInitTrueColourRGBTablesOUT (char **table, rfbPixelFormat *in,
106 if (*table) free(*table);
107 *table = (char *)malloc((in->redMax + in->greenMax + in->blueMax + 3)
109 redTable = (OUT_T *)*table;
110 greenTable = redTable + in->redMax + 1;
111 blueTable = greenTable + in->greenMax + 1;
113 rfbInitOneRGBTableOUT (redTable, in->redMax, out->redMax,
114 out->redShift, (out->bigEndian != in->bigEndian));
115 rfbInitOneRGBTableOUT (greenTable, in->greenMax, out->greenMax,
116 out->greenShift, (out->bigEndian != in->bigEndian));
117 rfbInitOneRGBTableOUT (blueTable, in->blueMax, out->blueMax,
118 out->blueShift, (out->bigEndian != in->bigEndian));
122 rfbInitOneRGBTableOUT (OUT_T *table, int inMax, int outMax, int outShift,
126 int nEntries = inMax + 1;
128 for (i = 0; i < nEntries; i++) {
129 table[i] = ((i * outMax + inMax / 2) / inMax) << outShift;
132 table[i] = SwapOUT(table[i]);
140 #undef rfbInitTrueColourSingleTableOUT
141 #undef rfbInitTrueColourRGBTablesOUT
142 #undef rfbInitOneRGBTableOUT