CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/vncdll/winvnc/tableinitcmtemplate.cpp
Views: 11780
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 OUTBPP.
7
* For each value of OUTBPP, 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
#if !defined(OUTBPP)
15
#error "This file shouldn't be compiled."
16
#error "It is included as part of translate.c"
17
#endif
18
19
#define OUT_T CONCAT2E(CARD,OUTBPP)
20
#define SwapOUT(x) CONCAT2E(Swap,OUTBPP) (x)
21
#define rfbInitColourMapSingleTableOUT \
22
CONCAT2E(rfbInitColourMapSingleTable,OUTBPP)
23
24
// THIS CODE HAS BEEN MODIFIED FROM THE ORIGINAL UNIX SOURCE
25
// TO WORK FOR WINVNC. THE PALETTE SHOULD REALLY BE RETRIEVED
26
// FROM THE VNCDESKTOP OBJECT, RATHER THAN FROM THE OS DIRECTLY
27
28
static void
29
rfbInitColourMapSingleTableOUT (char **table,
30
rfbPixelFormat *in,
31
rfbPixelFormat *out)
32
{
33
// ALLOCATE SPACE FOR COLOUR TABLE
34
35
int nEntries = 1 << in->bitsPerPixel;
36
37
// Allocate the table
38
if (*table) free(*table);
39
*table = (char *)malloc(nEntries * sizeof(OUT_T));
40
if (*table == NULL)
41
{
42
return;
43
}
44
45
// Obtain the system palette
46
HDC hDC = GetDC(NULL);
47
PALETTEENTRY palette[256];
48
if (GetSystemPaletteEntries(hDC,
49
0, 256, palette) == 0)
50
{
51
ReleaseDC(NULL, hDC);
52
return;
53
}
54
ReleaseDC(NULL, hDC);
55
56
// COLOUR TRANSLATION
57
58
// We now have the colour table intact. Map it into a translation table
59
int i, r, g, b;
60
OUT_T *t = (OUT_T *)*table;
61
62
for (i = 0; i < nEntries; i++)
63
{
64
// Split down the RGB data
65
r = palette[i].peRed;
66
g = palette[i].peGreen;
67
b = palette[i].peBlue;
68
69
// Now translate it
70
t[i] = ((((r * out->redMax + 127) / 255) << out->redShift) |
71
(((g * out->greenMax + 127) / 255) << out->greenShift) |
72
(((b * out->blueMax + 127) / 255) << out->blueShift));
73
#if (OUTBPP != 8)
74
if (out->bigEndian != in->bigEndian)
75
{
76
t[i] = SwapOUT(t[i]);
77
}
78
#endif
79
}
80
81
}
82
83
#undef OUT_T
84
#undef SwapOUT
85
#undef rfbInitColourMapSingleTableOUT
86
87