📄 vncencodezlibhex.cpp
字号:
continue; \
\
dest[rectoffset] |= rfbHextileAnySubrects; \
\
if (mono) \
{ \
if (!validFg || (newFg != fg)) \
{ \
validFg = TRUE; \
fg = newFg; \
dest[rectoffset] |= rfbHextileForegroundSpecified; \
PUT_PIXEL##bpp(fg); \
} \
} \
else \
{ \
validFg = FALSE; \
dest[rectoffset] |= rfbHextileSubrectsColoured; \
} \
\
encodedBytes = subrectEncode##bpp(clientPixelData, \
dest + destoffset, \
w, h, bg, fg, mono); \
\
if (encodedBytes == 0) \
{ \
\
/* hextile encoding was too large, use raw/zlib */ \
if ((w*h*(bpp/8)) > VNC_ENCODE_ZLIBHEX_MIN_COMP_SIZE) \
{ \
/* raw data large enough to use zlib */ \
validBg = FALSE; \
validFg = FALSE; \
destoffset = rectoffset; \
dest[destoffset++] = rfbHextileZlibRaw; \
\
Translate(source, (BYTE *) clientPixelData, hexrect); \
\
compressedSize = zlibCompress((BYTE *) clientPixelData, \
dest + destoffset + 2, \
(w*h*(bpp/8)), \
&compStreamRaw); \
\
\
card16ptr = (CARD16*) (dest + destoffset); \
*card16ptr = Swap16IfLE(compressedSize); \
destoffset += compressedSize + 2; \
\
} \
else \
{ \
/* raw size small enough, use directly */ \
validBg = FALSE; \
validFg = FALSE; \
destoffset = rectoffset; \
dest[destoffset++] = rfbHextileRaw; \
\
Translate(source, (dest + destoffset), hexrect); \
\
destoffset += (w*h*(bpp/8)); \
\
} \
} \
else /* when (encodedBytes != 0) */ \
{ \
/* Hextile encoding smaller than raw, compress further? */ \
/* Subencoded data harder to compress, need larger batch? */ \
if (encodedBytes > (VNC_ENCODE_ZLIBHEX_MIN_COMP_SIZE * 2)) \
{ \
/* hex encoded data large enough to use zlib */ \
subEncodedLen = (encodedBytes + destoffset - rectoffset - 1); \
destoffset = rectoffset + 1; \
memcpy( clientPixelData, (dest + destoffset), subEncodedLen); \
dest[rectoffset] |= rfbHextileZlibHex; \
\
compressedSize = zlibCompress((BYTE *) clientPixelData, \
dest + destoffset + 2, \
subEncodedLen, \
&compStreamEncoded); \
\
\
card16ptr = (CARD16*) (dest + destoffset); \
*card16ptr = Swap16IfLE(compressedSize); \
destoffset += compressedSize + 2; \
} \
else \
{ \
/* hex encoded data too small for zlib, send as is */ \
destoffset += encodedBytes; \
} \
} \
\
} \
\
if (destoffset > VNC_ENCODE_ZLIBHEX_MIN_DATAXFER) \
{ \
/* Send the encoded data as partial update */ \
outConn->SendQueued( (char *)dest, destoffset ); \
transmittedSize += destoffset; \
encodedSize += destoffset; \
destoffset = 0; \
\
} \
} \
transmittedSize += destoffset; \
encodedSize += destoffset; \
\
return destoffset; \
} \
\
static UINT \
subrectEncode##bpp(CARD##bpp *src, BYTE *dest, int w, int h, CARD##bpp bg, \
CARD##bpp fg, BOOL mono) \
{ \
CARD##bpp cl; \
int x,y; \
int i,j; \
int hx=0,hy,vx=0,vy; \
int hyflag; \
CARD##bpp *seg; \
CARD##bpp *line; \
int hw,hh,vw,vh; \
int thex,they,thew,theh; \
int numsubs = 0; \
int newLen; \
int rectoffset; \
int destoffset; \
\
destoffset = 0; \
rectoffset = destoffset; \
destoffset++; \
\
for (y=0; y<h; y++) \
{ \
line = src+(y*w); \
for (x=0; x<w; x++) \
{ \
if (line[x] != bg) \
{ \
cl = line[x]; \
hy = y-1; \
hyflag = 1; \
for (j=y; j<h; j++) \
{ \
seg = src+(j*w); \
if (seg[x] != cl) {break;} \
i = x; \
while ((seg[i] == cl) && (i < w)) i += 1; \
i -= 1; \
if (j == y) vx = hx = i; \
if (i < vx) vx = i; \
if ((hyflag > 0) && (i >= hx)) \
{ \
hy += 1; \
} \
else \
{ \
hyflag = 0; \
} \
} \
vy = j-1; \
\
/* We now have two possible subrects: (x,y,hx,hy) and \
* (x,y,vx,vy). We'll choose the bigger of the two. \
*/ \
hw = hx-x+1; \
hh = hy-y+1; \
vw = vx-x+1; \
vh = vy-y+1; \
\
thex = x; \
they = y; \
\
if ((hw*hh) > (vw*vh)) \
{ \
thew = hw; \
theh = hh; \
} \
else \
{ \
thew = vw; \
theh = vh; \
} \
\
if (mono) \
{ \
newLen = destoffset - rectoffset + 2; \
} \
else \
{ \
newLen = destoffset - rectoffset + bpp/8 + 2; \
} \
\
if (newLen > (w * h * (bpp/8))) \
return 0; \
\
numsubs += 1; \
\
if (!mono) PUT_PIXEL##bpp(cl); \
\
dest[destoffset++] = rfbHextilePackXY(thex,they); \
dest[destoffset++] = rfbHextilePackWH(thew,theh); \
\
/* \
* Now mark the subrect as done. \
*/ \
for (j=they; j < (they+theh); j++) \
{ \
for (i=thex; i < (thex+thew); i++) \
{ \
src[j*w+i] = bg; \
} \
} \
} \
} \
} \
\
dest[rectoffset] = numsubs; \
\
return destoffset; \
} \
\
\
/* \
* testColours() tests if there are one (solid), two (mono) or more \
* colours in a tile and gets a reasonable guess at the best background \
* pixel, and the foreground pixel for mono. \
*/ \
\
static void \
testColours##bpp(CARD##bpp *data, int size, \
BOOL *mono, BOOL *solid, \
CARD##bpp *bg, CARD##bpp *fg) \
{ \
CARD##bpp colour1, colour2; \
int n1 = 0, n2 = 0; \
*mono = TRUE; \
*solid = TRUE; \
\
for (; size > 0; size--, data++) \
{ \
\
if (n1 == 0) \
colour1 = *data; \
\
if (*data == colour1) \
{ \
n1++; \
continue; \
} \
\
if (n2 == 0) \
{ \
*solid = FALSE; \
colour2 = *data; \
} \
\
if (*data == colour2) \
{ \
n2++; \
continue; \
} \
\
*mono = FALSE; \
break; \
} \
\
if (n1 > n2) \
{ \
*bg = colour1; \
*fg = colour2; \
} \
else \
{ \
*bg = colour2; \
*fg = colour1; \
} \
}
DEFINE_SEND_HEXTILES(8)
DEFINE_SEND_HEXTILES(16)
DEFINE_SEND_HEXTILES(32)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -