source: trunk/src/testing/app/vnc/colour.cpp @ 4

Revision 4, 3.8 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1/************************************************************************
2 *
3 *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
4 *
5 *  This is free software; you can redistribute it and/or modify
6 *  it under the terms of the GNU General Public License as published by
7 *  the Free Software Foundation; either version 2 of the License, or
8 *  (at your option) any later version.
9 *
10 *  This software is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *  GNU General Public License for more details.
14 *
15 *  You should have received a copy of the GNU General Public License
16 *  along with this software; if not, write to the Free Software
17 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
18 *  USA.
19 ************************************************************************/
20 
21/*
22 * colour.c - functions to deal with colour - i.e. RFB pixel formats, X visuals
23 * and colormaps.  Thanks to Grant McDorman for some of the ideas used here.
24 */
25
26#include "vncviewer.h"
27#include <limits.h>
28
29
30#define INVALID_PIXEL 0xffffffff
31#define MAX_CMAP_SIZE 256
32
33/*
34 * SetVisualAndCmap() deals with the wonderful world of X "visuals" (which are
35 * equivalent to the RFB protocol's "pixel format").  Having decided on the
36 * best visual, it also creates a colormap if necessary, sets the appropriate
37 * resources on the toplevel widget, and sets up the myFormat structure to
38 * describe the pixel format in terms that the RFB server will be able to
39 * understand.
40 *
41 * The algorithm for deciding which visual to use is as follows:
42 *
43 * If forceOwnCmap is true then we try to use a PseudoColor visual - we first
44 * see if there's one of the same depth as the RFB server, followed by an 8-bit
45 * deep one.
46 *
47 * If forceTrueColour is true then we try to use a TrueColor visual - if
48 * requestedDepth is set then it must be of that depth, otherwise any depth
49 * will be used.
50 *
51 * Otherwise, we use the X server's default visual and colormap.  If this is
52 * TrueColor then we just ask the RFB server for this format.  If the default
53 * isn't TrueColor, or if useBGR233 is true, then we ask the RFB server for
54 * BGR233 pixel format and use a lookup table to translate to the nearest
55 * colours provided by the X server.
56 */
57
58void
59VNCViewer::SetVisualAndCmap()
60{
61    if (forceOwnCmap) {
62        if (!si.format.trueColour) {
63                //if (GetPseudoColorVisualAndCmap(si.format.depth))     return;
64        }
65            //if (GetPseudoColorVisualAndCmap(8)) return;
66        aLog("Couldn't find a matching PseudoColor visual.\n");
67    }
68
69    if (forceTrueColour) {
70            // if (GetTrueColorVisualAndCmap(appData.requestedDepth)) return;
71        aLog("Couldn't find a matching TrueColor visual.\n");
72    }
73
74        /* just use default visual and colormap */
75
76    if (!useBGR233)
77    {
78        myFormat.bitsPerPixel = 32;
79        myFormat.depth = 24;
80        myFormat.trueColour = 1;
81            //myFormat.bigEndian = (ImageByteOrder(dpy) == MSBFirst);
82        myFormat.bigEndian = 0;
83
84        myFormat.redShift = 0;
85        myFormat.greenShift = 8;
86        myFormat.blueShift = 16;
87        myFormat.redMax = 255;
88        myFormat.greenMax = 255;
89        myFormat.blueMax = 255;
90
91        aLog("Using default colormap which is TrueColor.  Pixel format:\n");
92        PrintPixelFormat(&myFormat);
93        return;
94    }
95
96    useBGR233 = True;
97
98    myFormat.bitsPerPixel = 8;
99    myFormat.depth = 8;
100    myFormat.trueColour = 1;
101    myFormat.bigEndian = 0;
102    myFormat.redMax = 7;
103    myFormat.greenMax = 7;
104    myFormat.blueMax = 3;
105    myFormat.redShift = 0;
106    myFormat.greenShift = 3;
107    myFormat.blueShift = 6;
108
109    aLog("Using default colormap and translating from BGR233.  Pixel format:\n");
110    PrintPixelFormat(&myFormat);
111}
Note: See TracBrowser for help on using the repository browser.