~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/lib/X11/XRGB.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: XRGB.c,v 1.3 2000/08/17 19:45:04 cpqbld Exp $ */
 
2
 
 
3
/*
 
4
 * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
 
5
 *      All Rights Reserved
 
6
 * 
 
7
 * This file is a component of an X Window System-specific implementation
 
8
 * of Xcms based on the TekColor Color Management System.  Permission is
 
9
 * hereby granted to use, copy, modify, sell, and otherwise distribute this
 
10
 * software and its documentation for any purpose and without fee, provided
 
11
 * that this copyright, permission, and disclaimer notice is reproduced in
 
12
 * all copies of this software and in supporting documentation.  TekColor
 
13
 * is a trademark of Tektronix, Inc.
 
14
 * 
 
15
 * Tektronix makes no representation about the suitability of this software
 
16
 * for any purpose.  It is provided "as is" and with all faults.
 
17
 * 
 
18
 * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
 
19
 * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 
20
 * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
 
21
 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 
22
 * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
 
23
 * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 
24
 * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
 
25
 *
 
26
 *
 
27
 *      NAME
 
28
 *              XcmsRtoX.c
 
29
 *
 
30
 *      DESCRIPTION
 
31
 *              Convert color specifications in XcmsRGB format in one array of
 
32
 *              XcmsColor structures to RGB in an array of XColor structures.
 
33
 *
 
34
 *
 
35
 */
 
36
/* $XFree86: xc/lib/X11/XRGB.c,v 3.3 2001/07/29 05:01:11 tsi Exp $ */
 
37
 
 
38
#include "Xlibint.h"
 
39
#include "Xcmsint.h"
 
40
 
 
41
/*
 
42
 *      LOCAL VARIABLES
 
43
 */
 
44
 
 
45
static unsigned short const MASK[17] = {
 
46
    0x0000,     /*  0 bitsPerRGB */
 
47
    0x8000,     /*  1 bitsPerRGB */
 
48
    0xc000,     /*  2 bitsPerRGB */
 
49
    0xe000,     /*  3 bitsPerRGB */
 
50
    0xf000,     /*  4 bitsPerRGB */
 
51
    0xf800,     /*  5 bitsPerRGB */
 
52
    0xfc00,     /*  6 bitsPerRGB */
 
53
    0xfe00,     /*  7 bitsPerRGB */
 
54
    0xff00,     /*  8 bitsPerRGB */
 
55
    0xff80,     /*  9 bitsPerRGB */
 
56
    0xffc0,     /* 10 bitsPerRGB */
 
57
    0xffe0,     /* 11 bitsPerRGB */
 
58
    0xfff0,     /* 12 bitsPerRGB */
 
59
    0xfff8,     /* 13 bitsPerRGB */
 
60
    0xfffc,     /* 14 bitsPerRGB */
 
61
    0xfffe,     /* 15 bitsPerRGB */
 
62
    0xffff      /* 16 bitsPerRGB */
 
63
};
 
64
 
 
65
 
 
66
 
 
67
/************************************************************************
 
68
 *                                                                      *
 
69
 *                      API PRIVATE ROUTINES                            *
 
70
 *                                                                      *
 
71
 ************************************************************************/
 
72
 
 
73
/*
 
74
 *      NAME
 
75
 *              _XcmsRGB_to_XColor - 
 
76
 *
 
77
 *      SYNOPSIS
 
78
 */
 
79
void
 
80
_XcmsRGB_to_XColor(pColors, pXColors, nColors)
 
81
    XcmsColor *pColors;
 
82
    XColor *pXColors;
 
83
    unsigned int nColors;
 
84
/*
 
85
 *      DESCRIPTION
 
86
 *          Translates a color specification in XcmsRGBFormat in a XcmsColor
 
87
 *          structure to an XColor structure.
 
88
 *
 
89
 *      RETURNS
 
90
 *              void.
 
91
 */
 
92
{
 
93
    for (; nColors--; pXColors++, pColors++) {
 
94
        pXColors->pixel = pColors->pixel;
 
95
        pXColors->red = pColors->spec.RGB.red;
 
96
        pXColors->green = pColors->spec.RGB.green;
 
97
        pXColors->blue  = pColors->spec.RGB.blue;
 
98
        pXColors->flags = (DoRed | DoGreen | DoBlue);
 
99
    }
 
100
}
 
101
 
 
102
 
 
103
/*
 
104
 *      NAME
 
105
 *              _XColor_to_XcmsRGB
 
106
 *
 
107
 *      SYNOPSIS
 
108
 */
 
109
void
 
110
_XColor_to_XcmsRGB(ccc, pXColors, pColors, nColors)
 
111
    XcmsCCC ccc;
 
112
    XColor *pXColors;
 
113
    XcmsColor *pColors;
 
114
    unsigned int nColors;
 
115
/*
 
116
 *      DESCRIPTION
 
117
 *              Translates an RGB color specification in an XColor
 
118
 *              structure to an XcmsRGB structure.
 
119
 *
 
120
 *              IMPORTANT NOTE:  Bit replication that may have been caused
 
121
 *              with ResolveColor() routine in the X Server is undone
 
122
 *              here if requested!  For example, if red = 0xcaca and the
 
123
 *              bits_per_rgb is 8, then spec.RGB.red will be 0xca00.
 
124
 *
 
125
 *      RETURNS
 
126
 *              void
 
127
 */
 
128
{
 
129
    int bits_per_rgb = ccc->visual->bits_per_rgb;
 
130
 
 
131
    for (; nColors--; pXColors++, pColors++) {
 
132
        pColors->spec.RGB.red = (pXColors->red & MASK[bits_per_rgb]);
 
133
        pColors->spec.RGB.green = (pXColors->green & MASK[bits_per_rgb]);
 
134
        pColors->spec.RGB.blue = (pXColors->blue & MASK[bits_per_rgb]);
 
135
        pColors->format = XcmsRGBFormat;
 
136
        pColors->pixel = pXColors->pixel;
 
137
    }
 
138
}
 
139
 
 
140
 
 
141
/*
 
142
 *      NAME
 
143
 *              _XcmsResolveColor
 
144
 *
 
145
 *      SYNOPSIS
 
146
 */
 
147
void
 
148
_XcmsResolveColor(ccc, pXcmsColor)
 
149
    XcmsCCC ccc;
 
150
    XcmsColor *pXcmsColor;
 
151
/*
 
152
 *      DESCRIPTION
 
153
 *          Uses the X Server ResolveColor() algorithm to
 
154
 *          modify values to closest values supported by hardware.
 
155
 *          Old algorithm simply masked low-order bits.  The new algorithm
 
156
 *          has the effect of replicating significant bits into lower order
 
157
 *          bits in order to stretch the hardware value into all 16 bits.
 
158
 *
 
159
 *          On a display with N-bit DACs, the "hardware" color is computed as:
 
160
 *
 
161
 *          ((unsignedlong)(ClientValue >> (16-N)) * 0xFFFF) / ((1 << N) - 1)
 
162
 *              
 
163
 *
 
164
 *      RETURNS
 
165
 *              void.
 
166
 */
 
167
{
 
168
    int shift;
 
169
    int max_color;
 
170
 
 
171
    shift = 16 - ccc->visual->bits_per_rgb;
 
172
    max_color = (1 << ccc->visual->bits_per_rgb) - 1;
 
173
 
 
174
 
 
175
    pXcmsColor->spec.RGB.red =
 
176
            ((unsigned long)(pXcmsColor->spec.RGB.red >> shift) * 0xFFFF)
 
177
            / max_color;
 
178
    pXcmsColor->spec.RGB.green =
 
179
            ((unsigned long)(pXcmsColor->spec.RGB.green >> shift) * 0xFFFF)
 
180
            / max_color;
 
181
    pXcmsColor->spec.RGB.blue =
 
182
            ((unsigned long)(pXcmsColor->spec.RGB.blue  >> shift) * 0xFFFF)
 
183
            / max_color;
 
184
}
 
185
 
 
186
 
 
187
/*
 
188
 *      NAME
 
189
 *              _XcmsUnresolveColor
 
190
 *
 
191
 *      SYNOPSIS
 
192
 */
 
193
void
 
194
_XcmsUnresolveColor(ccc, pColor)
 
195
    XcmsCCC ccc;
 
196
    XcmsColor *pColor;
 
197
/*
 
198
 *      DESCRIPTION
 
199
 *              Masks out insignificant bits.
 
200
 *
 
201
 *      RETURNS
 
202
 *              void.
 
203
 *
 
204
 *      ASSUMPTIONS
 
205
 *              format == XcmsRGBFormat
 
206
 */
 
207
{
 
208
    int bits_per_rgb = ccc->visual->bits_per_rgb;
 
209
 
 
210
    pColor->spec.RGB.red &= MASK[bits_per_rgb];
 
211
    pColor->spec.RGB.green &= MASK[bits_per_rgb];
 
212
    pColor->spec.RGB.blue &= MASK[bits_per_rgb];
 
213
}
 
214
 
 
215
 
 
216
/*
 
217
 *      NAME
 
218
 *              _XUnresolveColor
 
219
 *
 
220
 *      SYNOPSIS
 
221
 */
 
222
void
 
223
_XUnresolveColor(ccc, pXColor)
 
224
    XcmsCCC ccc;
 
225
    XColor *pXColor;
 
226
/*
 
227
 *      DESCRIPTION
 
228
 *              Masks out insignificant bits.
 
229
 *
 
230
 *      RETURNS
 
231
 *              void.
 
232
 */
 
233
{
 
234
    int bits_per_rgb = ccc->visual->bits_per_rgb;
 
235
 
 
236
    pXColor->red &= MASK[bits_per_rgb];
 
237
    pXColor->green &= MASK[bits_per_rgb];
 
238
    pXColor->blue &= MASK[bits_per_rgb];
 
239
}
 
240