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/tabletranstemplate.cpp
Views: 11780
1
/*
2
* tabletranstemplate.c - template for translation using lookup tables.
3
*
4
* This file shouldn't be compiled. It is included multiple times by
5
* translate.c, each time with different definitions of the macros INBPP and OUTBPP.
6
*
7
* For each pair of values INBPP and OUTBPP, this file defines two functions for
8
* translating a given rectangle of pixel data. One uses a single lookup
9
* table, and the other uses three separate lookup tables for the red, green
10
* and blue values.
11
*
12
* I know this code isn't nice to read because of all the macros, but
13
* efficiency is important here.
14
*/
15
16
#if !defined(INBPP) || !defined(OUTBPP)
17
#error "This file shouldn't be compiled."
18
#error "It is included as part of translate.c"
19
#endif
20
21
#define IN_T CONCAT2E(CARD,INBPP)
22
#define OUT_T CONCAT2E(CARD,OUTBPP)
23
#define rfbTranslateWithSingleTableINtoOUT \
24
CONCAT4E(rfbTranslateWithSingleTable,INBPP,to,OUTBPP)
25
#define rfbTranslateWithRGBTablesINtoOUT \
26
CONCAT4E(rfbTranslateWithRGBTables,INBPP,to,OUTBPP)
27
28
/*
29
* rfbTranslateWithSingleTableINtoOUT translates a rectangle of pixel data
30
* using a single lookup table.
31
*/
32
33
static void
34
rfbTranslateWithSingleTableINtoOUT (char *table, rfbPixelFormat *in,
35
rfbPixelFormat *out,
36
char *iptr, char *optr,
37
int bytesBetweenInputLines,
38
int width, int height)
39
{
40
IN_T *ip = (IN_T *)iptr;
41
OUT_T *op = (OUT_T *)optr;
42
int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
43
OUT_T *opLineEnd;
44
OUT_T *t = (OUT_T *)table;
45
46
while (height > 0) {
47
opLineEnd = op + width;
48
49
while (op < opLineEnd) {
50
*(op++) = t[*(ip++)];
51
}
52
53
ip += ipextra;
54
height--;
55
}
56
}
57
58
59
/*
60
* rfbTranslateWithRGBTablesINtoOUT translates a rectangle of pixel data
61
* using three separate lookup tables for the red, green and blue values.
62
*/
63
64
static void
65
rfbTranslateWithRGBTablesINtoOUT (char *table, rfbPixelFormat *in,
66
rfbPixelFormat *out,
67
char *iptr, char *optr,
68
int bytesBetweenInputLines,
69
int width, int height)
70
{
71
IN_T *ip = (IN_T *)iptr;
72
OUT_T *op = (OUT_T *)optr;
73
int ipextra = bytesBetweenInputLines / sizeof(IN_T) - width;
74
OUT_T *opLineEnd;
75
OUT_T *redTable = (OUT_T *)table;
76
OUT_T *greenTable = redTable + in->redMax + 1;
77
OUT_T *blueTable = greenTable + in->greenMax + 1;
78
IN_T in_pix;
79
OUT_T out_pix;
80
81
while (height > 0) {
82
opLineEnd = op + width;
83
84
while (op < opLineEnd) {
85
in_pix = *ip++;
86
out_pix = redTable[(in_pix >> in->redShift) & in->redMax];
87
out_pix |= greenTable[(in_pix >> in->greenShift) & in->greenMax];
88
out_pix |= blueTable[(in_pix >> in->blueShift) & in->blueMax];
89
*op++ = out_pix;
90
}
91
ip += ipextra;
92
height--;
93
}
94
}
95
96
#undef IN_T
97
#undef OUT_T
98
#undef rfbTranslateWithSingleTableINtoOUT
99
#undef rfbTranslateWithRGBTablesINtoOUT
100
101