~ubuntu-branches/debian/lenny/italc/lenny

« back to all changes in this revision

Viewing changes to common/ivs/libvncserver/tableinitcmtemplate.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-06-17 13:46:54 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080617134654-cl0gi4u524cv1ici
Tags: 1:1.0.9~rc3-1
* Package new upstream version
  - upstream ported the code to qt4.4 (Closes: #481974)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
45
 
static void
46
 
rfbInitColourMapSingleTableOUT(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