1 /* 2 * tabletranstemplate.c - template for translation using lookup tables. 3 * 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. 6 * 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 10 * and blue values. 11 * 12 * I know this code isn't nice to read because of all the macros, but 13 * efficiency is important here. 14 */ 15 16 /* 17 * OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk (at) incompleteness.net>. 18 * Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge. 19 * All Rights Reserved. 20 * 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. 25 * 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. 30 * 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, 34 * USA. 35 */ 36 37 #if !defined(IN) || !defined(OUT) 38 #error "This file shouldn't be compiled." 39 #error "It is included as part of translate.c" 40 #endif 41 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) 48 49 /* 50 * rfbTranslateWithSingleTableINtoOUT translates a rectangle of pixel data 51 * using a single lookup table. 52 */ 53 54 static void 55 rfbTranslateWithSingleTableINtoOUT (char *table, rfbPixelFormat *in, 56 rfbPixelFormat *out, 57 char *iptr, char *optr, 58 int bytesBetweenInputLines, 59 int width, int height) 60 { 61 IN_T *ip = (IN_T *)iptr; 62 OUT_T *op = (OUT_T *)optr; 63 int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width; 64 OUT_T *opLineEnd; 65 OUT_T *t = (OUT_T *)table; 66 67 while (height > 0) { 68 opLineEnd = op + width; 69 70 while (op < opLineEnd) { 71 *(op++) = t[*(ip++)]; 72 } 73 74 ip += ipextra; 75 height--; 76 } 77 } 78 79 80 /* 81 * rfbTranslateWithRGBTablesINtoOUT translates a rectangle of pixel data 82 * using three separate lookup tables for the red, green and blue values. 83 */ 84 85 static void 86 rfbTranslateWithRGBTablesINtoOUT (char *table, rfbPixelFormat *in, 87 rfbPixelFormat *out, 88 char *iptr, char *optr, 89 int bytesBetweenInputLines, 90 int width, int height) 91 { 92 IN_T *ip = (IN_T *)iptr; 93 OUT_T *op = (OUT_T *)optr; 94 int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width; 95 OUT_T *opLineEnd; 96 OUT_T *redTable = (OUT_T *)table; 97 OUT_T *greenTable = redTable + in->redMax + 1; 98 OUT_T *blueTable = greenTable + in->greenMax + 1; 99 100 while (height > 0) { 101 opLineEnd = &op[width]; 102 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]); 107 ip++; 108 } 109 ip += ipextra; 110 height--; 111 } 112 } 113 114 #undef IN_T 115 #undef OUT_T 116 #undef rfbTranslateWithSingleTableINtoOUT 117 #undef rfbTranslateWithRGBTablesINtoOUT 118