PageRenderTime 354ms CodeModel.GetById 160ms app.highlight 6ms RepoModel.GetById 186ms app.codeStats 0ms

/apps/desktop/libvncserver/tableinitcmtemplate.c

http://ftk.googlecode.com/
C | 84 lines | 45 code | 7 blank | 32 comment | 8 complexity | 5b291add26ee0b6fbc795804ebe5e015 MD5 | raw file
 1/*
 2 * tableinitcmtemplate.c - template for initialising lookup tables for
 3 * translation from a colour map to true colour.
 4 *
 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 a function which allocates an
 8 * appropriately sized lookup table and initialises it.
 9 *
10 * I know this code isn't nice to read because of all the macros, but
11 * efficiency is important here.
12 */
13
14/*
15 *  OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
16 *  Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.  
17 *  All Rights Reserved.
18 *
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.
23 *
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.
28 *
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,
32 *  USA.
33 */
34
35#if !defined(OUT)
36#error "This file shouldn't be compiled."
37#error "It is included as part of translate.c"
38#endif
39
40#define OUT_T CONCAT3E(uint,OUT,_t)
41#define SwapOUT(x) CONCAT2E(Swap,OUT(x))
42#define rfbInitColourMapSingleTableOUT \
43                                CONCAT2E(rfbInitColourMapSingleTable,OUT)
44
45static void
46rfbInitColourMapSingleTableOUT(char **table, rfbPixelFormat *in,
47                            rfbPixelFormat *out,rfbColourMap* colourMap)
48{
49    uint32_t i, r, g, b;
50    OUT_T *t;
51    uint32_t nEntries = 1 << in->bitsPerPixel;
52    int shift = colourMap->is16?16:8;
53
54    if (*table) free(*table);
55    *table = (char *)malloc(nEntries * sizeof(OUT_T));
56    t = (OUT_T *)*table;
57
58    for (i = 0; i < nEntries; i++) {
59        r = g = b = 0;
60	if(i < colourMap->count) {
61	  if(colourMap->is16) {
62	    r = colourMap->data.shorts[3*i+0];
63	    g = colourMap->data.shorts[3*i+1];
64	    b = colourMap->data.shorts[3*i+2];
65	  } else {
66	    r = colourMap->data.bytes[3*i+0];
67	    g = colourMap->data.bytes[3*i+1];
68	    b = colourMap->data.bytes[3*i+2];
69	  }
70	}
71        t[i] = ((((r * (1 + out->redMax)) >> shift) << out->redShift) |
72                (((g * (1 + out->greenMax)) >> shift) << out->greenShift) |
73                (((b * (1 + out->blueMax)) >> shift) << out->blueShift));
74#if (OUT != 8)
75        if (out->bigEndian != in->bigEndian) {
76            t[i] = SwapOUT(t[i]);
77        }
78#endif
79    }
80}
81
82#undef OUT_T
83#undef SwapOUT
84#undef rfbInitColourMapSingleTableOUT