6 * OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
7 * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.
10 * This is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This software is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this software; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 rfbInitOneRGBTable24 (uint8_t *table, int inMax, int outMax, int outShift,int swap);
31 rfbInitColourMapSingleTable24(char **table, rfbPixelFormat *in,
32 rfbPixelFormat *out,rfbColourMap* colourMap)
34 uint32_t i, r, g, b, outValue;
37 unsigned int nEntries = 1 << in->bitsPerPixel;
38 int shift = colourMap->is16?16:8;
40 if (*table) free(*table);
41 *table = (char *)malloc(nEntries * 3 + 1);
42 t = (uint8_t *)*table;
44 for (i = 0; i < nEntries; i++) {
46 if(i < colourMap->count) {
48 r = colourMap->data.shorts[3*i+0];
49 g = colourMap->data.shorts[3*i+1];
50 b = colourMap->data.shorts[3*i+2];
52 r = colourMap->data.bytes[3*i+0];
53 g = colourMap->data.bytes[3*i+1];
54 b = colourMap->data.bytes[3*i+2];
57 outValue = ((((r * (1 + out->redMax)) >> shift) << out->redShift) |
58 (((g * (1 + out->greenMax)) >> shift) << out->greenShift) |
59 (((b * (1 + out->blueMax)) >> shift) << out->blueShift));
60 *(uint32_t*)&t[3*i] = outValue;
62 memmove(t+3*i,t+3*i+1,3);
63 if (out->bigEndian != in->bigEndian) {
64 c = t[3*i]; t[3*i] = t[3*i+2]; t[3*i+2] = c;
70 * rfbInitTrueColourSingleTable sets up a single lookup table for truecolour
75 rfbInitTrueColourSingleTable24 (char **table, rfbPixelFormat *in,
79 int inRed, inGreen, inBlue, outRed, outGreen, outBlue;
82 int nEntries = 1 << in->bitsPerPixel;
84 if (*table) free(*table);
85 *table = (char *)malloc(nEntries * 3 + 1);
86 t = (uint8_t *)*table;
88 for (i = 0; i < nEntries; i++) {
89 inRed = (i >> in->redShift) & in->redMax;
90 inGreen = (i >> in->greenShift) & in->greenMax;
91 inBlue = (i >> in->blueShift) & in->blueMax;
93 outRed = (inRed * out->redMax + in->redMax / 2) / in->redMax;
94 outGreen = (inGreen * out->greenMax + in->greenMax / 2) / in->greenMax;
95 outBlue = (inBlue * out->blueMax + in->blueMax / 2) / in->blueMax;
97 outValue = ((outRed << out->redShift) |
98 (outGreen << out->greenShift) |
99 (outBlue << out->blueShift));
100 *(uint32_t*)&t[3*i] = outValue;
102 memmove(t+3*i,t+3*i+1,3);
103 if (out->bigEndian != in->bigEndian) {
104 c = t[3*i]; t[3*i] = t[3*i+2]; t[3*i+2] = c;
111 * rfbInitTrueColourRGBTables sets up three separate lookup tables for the
112 * red, green and blue values.
116 rfbInitTrueColourRGBTables24 (char **table, rfbPixelFormat *in,
123 if (*table) free(*table);
124 *table = (char *)malloc((in->redMax + in->greenMax + in->blueMax + 3)
126 redTable = (uint8_t *)*table;
127 greenTable = redTable + 3*(in->redMax + 1);
128 blueTable = greenTable + 3*(in->greenMax + 1);
130 rfbInitOneRGBTable24 (redTable, in->redMax, out->redMax,
131 out->redShift, (out->bigEndian != in->bigEndian));
132 rfbInitOneRGBTable24 (greenTable, in->greenMax, out->greenMax,
133 out->greenShift, (out->bigEndian != in->bigEndian));
134 rfbInitOneRGBTable24 (blueTable, in->blueMax, out->blueMax,
135 out->blueShift, (out->bigEndian != in->bigEndian));
139 rfbInitOneRGBTable24 (uint8_t *table, int inMax, int outMax, int outShift,
143 int nEntries = inMax + 1;
147 for (i = 0; i < nEntries; i++) {
148 outValue = ((i * outMax + inMax / 2) / inMax) << outShift;
149 *(uint32_t *)&table[3*i] = outValue;
151 memmove(table+3*i,table+3*i+1,3);
153 c = table[3*i]; table[3*i] = table[3*i+2];