2 * tabletranstemplate.c - template for translation using lookup tables.
4 * This file shouldn't be compiled. It is included multiple times by
5 * translate.c, each time with different definitions of the macros IN and OUT.
7 * For each pair of values IN and OUT, this file defines two functions for
8 * translating a given rectangle of pixel data. One uses a single lookup
9 * table, and the other uses three separate lookup tables for the red, green
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,
37 #if !defined(IN) || !defined(OUT)
38 #error "This file shouldn't be compiled."
39 #error "It is included as part of translate.c"
42 #define IN_T CONCAT3E(uint,IN,_t)
43 #define OUT_T CONCAT3E(uint,OUT,_t)
44 #define rfbTranslateWithSingleTableINtoOUT \
45 CONCAT4E(rfbTranslateWithSingleTable,IN,to,OUT)
46 #define rfbTranslateWithRGBTablesINtoOUT \
47 CONCAT4E(rfbTranslateWithRGBTables,IN,to,OUT)
50 * rfbTranslateWithSingleTableINtoOUT translates a rectangle of pixel data
51 * using a single lookup table.
55 rfbTranslateWithSingleTableINtoOUT (char *table, rfbPixelFormat *in,
57 char *iptr, char *optr,
58 int bytesBetweenInputLines,
59 int width, int height)
61 IN_T *ip = (IN_T *)iptr;
62 OUT_T *op = (OUT_T *)optr;
63 int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
65 OUT_T *t = (OUT_T *)table;
68 opLineEnd = op + width;
70 while (op < opLineEnd) {
81 * rfbTranslateWithRGBTablesINtoOUT translates a rectangle of pixel data
82 * using three separate lookup tables for the red, green and blue values.
86 rfbTranslateWithRGBTablesINtoOUT (char *table, rfbPixelFormat *in,
88 char *iptr, char *optr,
89 int bytesBetweenInputLines,
90 int width, int height)
92 IN_T *ip = (IN_T *)iptr;
93 OUT_T *op = (OUT_T *)optr;
94 int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
96 OUT_T *redTable = (OUT_T *)table;
97 OUT_T *greenTable = redTable + in->redMax + 1;
98 OUT_T *blueTable = greenTable + in->greenMax + 1;
101 opLineEnd = &op[width];
103 while (op < opLineEnd) {
104 *(op++) = (redTable[(*ip >> in->redShift) & in->redMax] |
105 greenTable[(*ip >> in->greenShift) & in->greenMax] |
106 blueTable[(*ip >> in->blueShift) & in->blueMax]);
116 #undef rfbTranslateWithSingleTableINtoOUT
117 #undef rfbTranslateWithRGBTablesINtoOUT