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 * 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,
35 #if !defined(IN) || !defined(OUT)
36 #error "This file shouldn't be compiled."
37 #error "It is included as part of translate.c"
40 #define IN_T CONCAT2E(CARD,IN)
41 #define OUT_T CONCAT2E(CARD,OUT)
42 #define rfbTranslateWithSingleTableINtoOUT \
43 CONCAT4E(rfbTranslateWithSingleTable,IN,to,OUT)
44 #define rfbTranslateWithRGBTablesINtoOUT \
45 CONCAT4E(rfbTranslateWithRGBTables,IN,to,OUT)
48 * rfbTranslateWithSingleTableINtoOUT translates a rectangle of pixel data
49 * using a single lookup table.
53 rfbTranslateWithSingleTableINtoOUT (char *table, rfbPixelFormat *in,
55 char *iptr, char *optr,
56 int bytesBetweenInputLines,
57 int width, int height)
59 IN_T *ip = (IN_T *)iptr;
60 OUT_T *op = (OUT_T *)optr;
61 int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
63 OUT_T *t = (OUT_T *)table;
66 opLineEnd = op + width;
68 while (op < opLineEnd) {
79 * rfbTranslateWithRGBTablesINtoOUT translates a rectangle of pixel data
80 * using three separate lookup tables for the red, green and blue values.
84 rfbTranslateWithRGBTablesINtoOUT (char *table, rfbPixelFormat *in,
86 char *iptr, char *optr,
87 int bytesBetweenInputLines,
88 int width, int height)
90 IN_T *ip = (IN_T *)iptr;
91 OUT_T *op = (OUT_T *)optr;
92 int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
94 OUT_T *redTable = (OUT_T *)table;
95 OUT_T *greenTable = redTable + in->redMax + 1;
96 OUT_T *blueTable = greenTable + in->greenMax + 1;
99 opLineEnd = op + width;
101 while (op < opLineEnd) {
102 *(op++) = (redTable[(*ip >> in->redShift) & in->redMax] |
103 greenTable[(*ip >> in->greenShift) & in->greenMax] |
104 blueTable[(*ip >> in->blueShift) & in->blueMax]);
114 #undef rfbTranslateWithSingleTableINtoOUT
115 #undef rfbTranslateWithRGBTablesINtoOUT