@ -30,37 +30,19 @@
# include <rfb/rfb.h>
/*
* rreBefore Buf contains pixel data in the client ' s format .
* rreAfter Buf contains the RRE encoded version . If the RRE encoded version is
* larger than the raw data or if it exceeds rreAfter BufSize then
* cl- > beforeEnc Buf contains pixel data in the client ' s format .
* cl- > afterEnc Buf contains the RRE encoded version . If the RRE encoded version is
* larger than the raw data or if it exceeds cl- > afterEnc BufSize then
* raw encoding is used instead .
*/
static int rreBeforeBufSize = 0 ;
static char * rreBeforeBuf = NULL ;
static int rreAfterBufSize = 0 ;
static char * rreAfterBuf = NULL ;
static int rreAfterBufLen = 0 ;
static int subrectEncode8 ( uint8_t * data , int w , int h ) ;
static int subrectEncode16 ( uint16_t * data , int w , int h ) ;
static int subrectEncode32 ( uint32_t * data , int w , int h ) ;
static int subrectEncode8 ( rfbClientPtr cl , uint8_t * data , int w , int h ) ;
static int subrectEncode16 ( rfbClientPtr cl , uint16_t * data , int w , int h ) ;
static int subrectEncode32 ( rfbClientPtr cl , uint32_t * data , int w , int h ) ;
static uint32_t getBgColour ( char * data , int size , int bpp ) ;
static rfbBool rfbSendSmallRectEncodingCoRRE ( rfbClientPtr cl , int x , int y ,
int w , int h ) ;
void rfbCoRRECleanup ( rfbScreenInfoPtr screen )
{
if ( rreBeforeBufSize ) {
free ( rreBeforeBuf ) ;
rreBeforeBufSize = 0 ;
}
if ( rreAfterBufSize ) {
free ( rreAfterBuf ) ;
rreAfterBufSize = 0 ;
}
}
/*
* rfbSendRectEncodingCoRRE - send an arbitrary size rectangle using CoRRE
@ -114,35 +96,35 @@ rfbSendSmallRectEncodingCoRRE(rfbClientPtr cl,
int maxRawSize = ( cl - > scaledScreen - > width * cl - > scaledScreen - > height
* ( cl - > format . bitsPerPixel / 8 ) ) ;
if ( rreBefore BufSize < maxRawSize ) {
rreBefore BufSize = maxRawSize ;
if ( rreBefore Buf = = NULL )
rreBeforeBuf = ( char * ) malloc ( rreBefore BufSize) ;
if ( cl- > beforeEnc BufSize < maxRawSize ) {
cl- > beforeEnc BufSize = maxRawSize ;
if ( cl- > beforeEnc Buf = = NULL )
cl- > beforeEncBuf = ( char * ) malloc ( cl - > beforeEnc BufSize) ;
else
rreBeforeBuf = ( char * ) realloc ( rreBeforeBuf , rreBefore BufSize) ;
cl- > beforeEncBuf = ( char * ) realloc ( cl - > beforeEncBuf , cl - > beforeEnc BufSize) ;
}
if ( rreAfter BufSize < maxRawSize ) {
rreAfter BufSize = maxRawSize ;
if ( rreAfter Buf = = NULL )
rreAfterBuf = ( char * ) malloc ( rreAfter BufSize) ;
if ( cl- > afterEnc BufSize < maxRawSize ) {
cl- > afterEnc BufSize = maxRawSize ;
if ( cl- > afterEnc Buf = = NULL )
cl- > afterEncBuf = ( char * ) malloc ( cl - > afterEnc BufSize) ;
else
rreAfterBuf = ( char * ) realloc ( rreAfterBuf , rreAfter BufSize) ;
cl- > afterEncBuf = ( char * ) realloc ( cl - > afterEncBuf , cl - > afterEnc BufSize) ;
}
( * cl - > translateFn ) ( cl - > translateLookupTable , & ( cl - > screen - > serverFormat ) ,
& cl - > format , fbptr , rreBefore Buf,
& cl - > format , fbptr , cl- > beforeEnc Buf,
cl - > scaledScreen - > paddedWidthInBytes , w , h ) ;
switch ( cl - > format . bitsPerPixel ) {
case 8 :
nSubrects = subrectEncode8 ( ( uint8_t * ) rreBefore Buf, w , h ) ;
nSubrects = subrectEncode8 ( cl , ( uint8_t * ) cl - > beforeEnc Buf, w , h ) ;
break ;
case 16 :
nSubrects = subrectEncode16 ( ( uint16_t * ) rreBefore Buf, w , h ) ;
nSubrects = subrectEncode16 ( cl , ( uint16_t * ) cl - > beforeEnc Buf, w , h ) ;
break ;
case 32 :
nSubrects = subrectEncode32 ( ( uint32_t * ) rreBefore Buf, w , h ) ;
nSubrects = subrectEncode32 ( cl , ( uint32_t * ) cl - > beforeEnc Buf, w , h ) ;
break ;
default :
rfbLog ( " getBgColour: bpp %d? \n " , cl - > format . bitsPerPixel ) ;
@ -157,7 +139,7 @@ rfbSendSmallRectEncodingCoRRE(rfbClientPtr cl,
}
rfbStatRecordEncodingSent ( cl , rfbEncodingCoRRE ,
sz_rfbFramebufferUpdateRectHeader + sz_rfbRREHeader + rreAfter BufLen,
sz_rfbFramebufferUpdateRectHeader + sz_rfbRREHeader + cl- > afterEnc BufLen,
sz_rfbFramebufferUpdateRectHeader + w * h * ( cl - > format . bitsPerPixel / 8 ) ) ;
if ( cl - > ublen + sz_rfbFramebufferUpdateRectHeader + sz_rfbRREHeader
@ -182,15 +164,15 @@ rfbSendSmallRectEncodingCoRRE(rfbClientPtr cl,
memcpy ( & cl - > updateBuf [ cl - > ublen ] , ( char * ) & hdr , sz_rfbRREHeader ) ;
cl - > ublen + = sz_rfbRREHeader ;
for ( i = 0 ; i < rreAfter BufLen; ) {
for ( i = 0 ; i < cl- > afterEnc BufLen; ) {
int bytesToCopy = UPDATE_BUF_SIZE - cl - > ublen ;
if ( i + bytesToCopy > rreAfter BufLen) {
bytesToCopy = rreAfter BufLen - i ;
if ( i + bytesToCopy > cl- > afterEnc BufLen) {
bytesToCopy = cl- > afterEnc BufLen - i ;
}
memcpy ( & cl - > updateBuf [ cl - > ublen ] , & rreAfter Buf[ i ] , bytesToCopy ) ;
memcpy ( & cl - > updateBuf [ cl - > ublen ] , & cl- > afterEnc Buf[ i ] , bytesToCopy ) ;
cl - > ublen + = bytesToCopy ;
i + = bytesToCopy ;
@ -210,7 +192,7 @@ rfbSendSmallRectEncodingCoRRE(rfbClientPtr cl,
* subrectEncode ( ) encodes the given multicoloured rectangle as a background
* colour overwritten by single - coloured rectangles . It returns the number
* of subrectangles in the encoded buffer , or - 1 if subrect encoding won ' t
* fit in the buffer . It puts the encoded rectangles in rreAfter Buf. The
* fit in the buffer . It puts the encoded rectangles in cl- > afterEnc Buf. The
* single - colour rectangle partition is not optimal , but does find the biggest
* horizontal or vertical rectangle top - left anchored to each consecutive
* coordinate position .
@ -221,7 +203,7 @@ rfbSendSmallRectEncodingCoRRE(rfbClientPtr cl,
# define DEFINE_SUBRECT_ENCODE(bpp) \
static int \
subrectEncode # # bpp ( uint# # bpp # # _t * data , int w , int h ) { \
subrectEncode # # bpp ( rfbClientPtr client , uint# # bpp # # _t * data , int w , int h ) { \
uint # # bpp # # _t cl ; \
rfbCoRRERectangle subrect ; \
int x , y ; \
@ -236,9 +218,9 @@ subrectEncode##bpp(uint##bpp##_t *data, int w, int h) { \
int newLen ; \
uint # # bpp # # _t bg = ( uint # # bpp # # _t ) getBgColour ( ( char * ) data , w * h , bpp ) ; \
\
* ( ( uint # # bpp # # _t * ) rreAfter Buf) = bg ; \
* ( ( uint # # bpp # # _t * ) client- > afterEnc Buf) = bg ; \
\
rreAfter BufLen = ( bpp / 8 ) ; \
client- > afterEnc BufLen = ( bpp / 8 ) ; \
\
for ( y = 0 ; y < h ; y + + ) { \
line = data + ( y * w ) ; \
@ -283,15 +265,15 @@ subrectEncode##bpp(uint##bpp##_t *data, int w, int h) { \
subrect . w = thew ; \
subrect . h = theh ; \
\
newLen = rreAfter BufLen + ( bpp / 8 ) + sz_rfbCoRRERectangle ; \
if ( ( newLen > ( w * h * ( bpp / 8 ) ) ) | | ( newLen > rreAfter BufSize) ) \
newLen = client- > afterEnc BufLen + ( bpp / 8 ) + sz_rfbCoRRERectangle ; \
if ( ( newLen > ( w * h * ( bpp / 8 ) ) ) | | ( newLen > client- > afterEnc BufSize) ) \
return - 1 ; \
\
numsubs + = 1 ; \
* ( ( uint # # bpp # # _t * ) ( rreAfterBuf + rreAfter BufLen) ) = cl ; \
rreAfter BufLen + = ( bpp / 8 ) ; \
memcpy ( & rreAfterBuf[ rreAfter BufLen] , & subrect , sz_rfbCoRRERectangle ) ; \
rreAfter BufLen + = sz_rfbCoRRERectangle ; \
* ( ( uint # # bpp # # _t * ) ( client- > afterEncBuf + client - > afterEnc BufLen) ) = cl ; \
client- > afterEnc BufLen + = ( bpp / 8 ) ; \
memcpy ( & client- > afterEncBuf [ client - > afterEnc BufLen] , & subrect , sz_rfbCoRRERectangle ) ; \
client- > afterEnc BufLen + = sz_rfbCoRRERectangle ; \
\
/* \
* Now mark the subrect as done . \