Coverage Report

Created: 2026-01-10 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvncserver/src/libvncserver/tableinit24.c
Line
Count
Source
1
/*
2
  24 bit
3
 */
4
5
/*
6
 *  OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
7
 *  Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.  
8
 *  All Rights Reserved.
9
 *
10
 *  This is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  (at your option) any later version.
14
 *
15
 *  This software is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this software; if not, write to the Free Software
22
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
23
 *  USA.
24
 */
25
26
static void
27
rfbInitOneRGBTable24 (uint8_t *table, int inMax, int outMax, int outShift,int swap);
28
29
30
static void
31
rfbInitColourMapSingleTable24(char **table, rfbPixelFormat *in,
32
                            rfbPixelFormat *out,rfbColourMap* colourMap)
33
0
{
34
0
    uint32_t i, r, g, b, outValue;
35
0
    uint8_t *t;
36
0
    uint8_t c;
37
0
    unsigned int nEntries = 1 << in->bitsPerPixel;
38
0
    int shift = colourMap->is16?16:8;
39
40
0
    if (*table) free(*table);
41
0
    *table = (char *)malloc(nEntries * 3 + 1);
42
0
    t = (uint8_t *)*table;
43
44
0
    for (i = 0; i < nEntries; i++) {
45
0
        r = g = b = 0;
46
0
  if(i < colourMap->count) {
47
0
    if(colourMap->is16) {
48
0
      r = colourMap->data.shorts[3*i+0];
49
0
      g = colourMap->data.shorts[3*i+1];
50
0
      b = colourMap->data.shorts[3*i+2];
51
0
    } else {
52
0
      r = colourMap->data.bytes[3*i+0];
53
0
      g = colourMap->data.bytes[3*i+1];
54
0
      b = colourMap->data.bytes[3*i+2];
55
0
    }
56
0
  }
57
0
        outValue = ((((r * (1 + out->redMax)) >> shift) << out->redShift) |
58
0
                (((g * (1 + out->greenMax)) >> shift) << out->greenShift) |
59
0
                (((b * (1 + out->blueMax)) >> shift) << out->blueShift));
60
0
  *(uint32_t*)&t[3*i] = outValue;
61
0
  if(!rfbEndianTest)
62
0
    memmove(t+3*i,t+3*i+1,3);
63
0
        if (out->bigEndian != in->bigEndian) {
64
0
    c = t[3*i]; t[3*i] = t[3*i+2]; t[3*i+2] = c;
65
0
        }
66
0
    }
67
0
}
68
69
/*
70
 * rfbInitTrueColourSingleTable sets up a single lookup table for truecolour
71
 * translation.
72
 */
73
74
static void
75
rfbInitTrueColourSingleTable24 (char **table, rfbPixelFormat *in,
76
                                 rfbPixelFormat *out)
77
0
{
78
0
    int i,outValue;
79
0
    int inRed, inGreen, inBlue, outRed, outGreen, outBlue;
80
0
    uint8_t *t;
81
0
    uint8_t c;
82
0
    int nEntries = 1 << in->bitsPerPixel;
83
84
0
    if (*table) free(*table);
85
0
    *table = (char *)malloc(nEntries * 3 + 1);
86
0
    t = (uint8_t *)*table;
87
88
0
    for (i = 0; i < nEntries; i++) {
89
0
        inRed   = (i >> in->redShift)   & in->redMax;
90
0
        inGreen = (i >> in->greenShift) & in->greenMax;
91
0
        inBlue  = (i >> in->blueShift)  & in->blueMax;
92
93
0
        outRed   = (inRed   * out->redMax   + in->redMax / 2)   / in->redMax;
94
0
        outGreen = (inGreen * out->greenMax + in->greenMax / 2) / in->greenMax;
95
0
        outBlue  = (inBlue  * out->blueMax  + in->blueMax / 2)  / in->blueMax;
96
97
0
  outValue = ((outRed   << out->redShift)   |
98
0
                (outGreen << out->greenShift) |
99
0
                (outBlue  << out->blueShift));
100
0
  *(uint32_t*)&t[3*i] = outValue;
101
0
  if(!rfbEndianTest)
102
0
    memmove(t+3*i,t+3*i+1,3);
103
0
        if (out->bigEndian != in->bigEndian) {
104
0
    c = t[3*i]; t[3*i] = t[3*i+2]; t[3*i+2] = c;
105
0
        }
106
0
    }
107
0
}
108
109
110
/*
111
 * rfbInitTrueColourRGBTables sets up three separate lookup tables for the
112
 * red, green and blue values.
113
 */
114
115
static void
116
rfbInitTrueColourRGBTables24 (char **table, rfbPixelFormat *in,
117
                               rfbPixelFormat *out)
118
1.73k
{
119
1.73k
    uint8_t *redTable;
120
1.73k
    uint8_t *greenTable;
121
1.73k
    uint8_t *blueTable;
122
123
1.73k
    if (*table) free(*table);
124
1.73k
    *table = (char *)malloc((in->redMax + in->greenMax + in->blueMax + 3)
125
1.73k
                            * 3 + 1);
126
1.73k
    redTable = (uint8_t *)*table;
127
1.73k
    greenTable = redTable + 3*(in->redMax + 1);
128
1.73k
    blueTable = greenTable + 3*(in->greenMax + 1);
129
130
1.73k
    rfbInitOneRGBTable24 (redTable, in->redMax, out->redMax,
131
1.73k
                           out->redShift, (out->bigEndian != in->bigEndian));
132
1.73k
    rfbInitOneRGBTable24 (greenTable, in->greenMax, out->greenMax,
133
1.73k
                           out->greenShift, (out->bigEndian != in->bigEndian));
134
1.73k
    rfbInitOneRGBTable24 (blueTable, in->blueMax, out->blueMax,
135
1.73k
                           out->blueShift, (out->bigEndian != in->bigEndian));
136
1.73k
}
137
138
static void
139
rfbInitOneRGBTable24 (uint8_t *table, int inMax, int outMax, int outShift,
140
                       int swap)
141
5.21k
{
142
5.21k
    int i;
143
5.21k
    int nEntries = inMax + 1;
144
5.21k
    uint32_t outValue;
145
5.21k
    uint8_t c;
146
147
1.33M
    for (i = 0; i < nEntries; i++) {
148
1.33M
      outValue = ((i * outMax + inMax / 2) / inMax) << outShift;
149
1.33M
      *(uint32_t *)&table[3*i] = outValue;
150
1.33M
      if(!rfbEndianTest) {
151
0
  memmove(table+3*i,table+3*i+1,3);
152
0
      }
153
1.33M
      if (swap) {
154
1.32M
        c = table[3*i]; table[3*i] = table[3*i+2];
155
1.32M
        table[3*i+2] = c;
156
1.32M
      }
157
1.33M
    }
158
5.21k
}