I think there are similar meaningless codes also in ClientConnectionCoRRE.cpp, ClientConnectionRRE.cpp, xz.cpp and zrle.cpp regarding COLOR_FROM_PIXEL*_ADDRESS(). The return-values of COLOR_FROM_PIXEL*_ADDRESS() are never used.
The patch to remove all these meaningless codes is as follows.
Code: Select all
diff --git a/vncviewer/ClientConnection.h b/vncviewer/ClientConnection.h
index 15e983b..11efb5e 100755
--- a/vncviewer/ClientConnection.h
+++ b/vncviewer/ClientConnection.h
@@ -921,22 +921,6 @@ public:
(int) ((( *(CARD32 *)(p) >> gs) & gm) * 255 / gm), \
(int) ((( *(CARD32 *)(p) >> bs) & bm) * 255 / bm) ))
-// The following may be faster if you already have a pixel value of the appropriate size
-#define COLOR_FROM_PIXEL8(p) (PALETTERGB( \
- (int) (((p >> rs) & rm) * 255 / rm), \
- (int) (((p >> gs) & gm) * 255 / gm), \
- (int) (((p >> bs) & bm) * 255 / bm) ))
-
-#define COLOR_FROM_PIXEL16(p) (PALETTERGB( \
- (int) ((( p >> rs) & rm) * 255 / rm), \
- (int) ((( p >> gs) & gm) * 255 / gm), \
- (int) ((( p >> bs) & bm) * 255 / bm) ))
-
-#define COLOR_FROM_PIXEL32(p) (PALETTERGB( \
- (int) (((p >> rs) & rm) * 255 / rm), \
- (int) (((p >> gs) & gm) * 255 / gm), \
- (int) (((p >> bs) & bm) * 255 / bm) ))
-
#define SETPIXEL(b,x,y,c) SetPixelV((b),(x),(y),(c))
#define SETPIXELS(buffer, bpp, x, y, w, h) \
diff --git a/vncviewer/ClientConnectionCoRRE.cpp b/vncviewer/ClientConnectionCoRRE.cpp
index e05ad57..1de255b 100755
--- a/vncviewer/ClientConnectionCoRRE.cpp
+++ b/vncviewer/ClientConnectionCoRRE.cpp
@@ -45,19 +45,6 @@ void ClientConnection::ReadCoRRERect(rfbFramebufferUpdateRectHeader *pfburh)
prreh->nSubrects = Swap32IfLE(prreh->nSubrects);
- SETUP_COLOR_SHORTCUTS;
-
- COLORREF color;
- switch (m_myFormat.bitsPerPixel) {
- case 8:
- color = COLOR_FROM_PIXEL8_ADDRESS(pcolor); break;
- case 16:
- color = COLOR_FROM_PIXEL16_ADDRESS(pcolor); break;
- case 24:
- case 32:
- color = COLOR_FROM_PIXEL32_ADDRESS(pcolor); break;
- }
-
// Draw the background of the rectangle
FillSolidRect_ultra(pfburh->r.x, pfburh->r.y, pfburh->r.w, pfburh->r.h, m_myFormat.bitsPerPixel,pcolor);
@@ -84,16 +71,6 @@ void ClientConnection::ReadCoRRERect(rfbFramebufferUpdateRectHeader *pfburh)
pRect = (rfbCoRRERectangle *) (p + m_minPixelBytes);
- switch (m_myFormat.bitsPerPixel) {
- case 8:
- color = COLOR_FROM_PIXEL8_ADDRESS(p); break;
- case 16:
- color = COLOR_FROM_PIXEL16_ADDRESS(p); break;
- case 32:
- color = COLOR_FROM_PIXEL32_ADDRESS(p); break;
- };
-
- // color = COLOR_FROM_PIXEL8_ADDRESS(netbuf);
rect.x = pRect->x + pfburh->r.x;
rect.y = pRect->y + pfburh->r.y;
rect.w = pRect->w;
diff --git a/vncviewer/ClientConnectionCursor.cpp b/vncviewer/ClientConnectionCursor.cpp
index 86f3bc8..3d3b1a6 100755
--- a/vncviewer/ClientConnectionCursor.cpp
+++ b/vncviewer/ClientConnectionCursor.cpp
@@ -330,8 +330,6 @@ void ClientConnection::SoftCursorDraw() {
omni_mutex_lock l(m_bitmapdcMutex);
- SETUP_COLOR_SHORTCUTS;
-
for (y = 0; y < rcHeight; y++) {
y0 = rcCursorY - rcHotY + y;
if (y0 >= 0 && y0 < m_si.framebufferHeight) {
diff --git a/vncviewer/ClientConnectionHextile.cpp b/vncviewer/ClientConnectionHextile.cpp
index 9d43264..aea6612 100755
--- a/vncviewer/ClientConnectionHextile.cpp
+++ b/vncviewer/ClientConnectionHextile.cpp
@@ -46,7 +46,6 @@ void ClientConnection::ReadHextileRect(rfbFramebufferUpdateRectHeader *pfburh)
void ClientConnection::HandleHextileEncoding##bpp(int rx, int ry, int rw, int rh) \
{ \
CARD##bpp bg, fg; \
- COLORREF bgcolor, fgcolor; \
int i; \
CARD8 *ptr; \
int x, y, w, h; \
@@ -55,7 +54,6 @@ void ClientConnection::HandleHextileEncoding##bpp(int rx, int ry, int rw, int rh
CARD8 nSubrects; \
\
CheckBufferSize( 16 * 16 * bpp ); \
- SETUP_COLOR_SHORTCUTS; \
\
for (y = ry; y < ry+rh; y += 16) { \
omni_mutex_lock l(m_bitmapdcMutex); \
@@ -80,13 +78,11 @@ void ClientConnection::HandleHextileEncoding##bpp(int rx, int ry, int rw, int rh
\
if (subencoding & rfbHextileBackgroundSpecified) { \
ReadExact((char *)&bg, (bpp/8)); \
- bgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(&bg); \
} \
FillSolidRect_ultra(x,y,w,h, m_myFormat.bitsPerPixel,(BYTE*)&bg);\
\
if (subencoding & rfbHextileForegroundSpecified) { \
ReadExact((char *)&fg, (bpp/8)); \
- fgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(&fg); \
} \
\
if (!(subencoding & rfbHextileAnySubrects)) { \
@@ -106,7 +102,6 @@ void ClientConnection::HandleHextileEncoding##bpp(int rx, int ry, int rw, int rh
ReadExact( m_netbuf, nSubrects * (2 + (bpp / 8))); \
\
for (i = 0; i < nSubrects; i++) { \
- fgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(ptr); \
memcpy(&fg,ptr,bpp/8); \
ptr += (bpp/8); \
sx = *ptr >> 4; \
diff --git a/vncviewer/ClientConnectionRRE.cpp b/vncviewer/ClientConnectionRRE.cpp
index 43ba69e..ce23b35 100755
--- a/vncviewer/ClientConnectionRRE.cpp
+++ b/vncviewer/ClientConnectionRRE.cpp
@@ -42,18 +42,6 @@ void ClientConnection::ReadRRERect(rfbFramebufferUpdateRectHeader *pfburh)
prreh->nSubrects = Swap32IfLE(prreh->nSubrects);
- SETUP_COLOR_SHORTCUTS;
- COLORREF color;
- switch (m_myFormat.bitsPerPixel) {
- case 8:
- color = COLOR_FROM_PIXEL8_ADDRESS(pcolor); break;
- case 16:
- color = COLOR_FROM_PIXEL16_ADDRESS(pcolor); break;
- case 24:
- case 32:
- color = COLOR_FROM_PIXEL32_ADDRESS(pcolor); break;
- }
-
// No other threads can use bitmap DC
omni_mutex_lock l(m_bitmapdcMutex);
@@ -76,15 +64,6 @@ void ClientConnection::ReadRRERect(rfbFramebufferUpdateRectHeader *pfburh)
for (CARD32 i = 0; i < prreh->nSubrects; i++) {
pRect = (rfbRectangle *) (p + m_minPixelBytes);
- switch (m_myFormat.bitsPerPixel) {
- case 8:
- color = COLOR_FROM_PIXEL8_ADDRESS(p); break;
- case 16:
- color = COLOR_FROM_PIXEL16_ADDRESS(p); break;
- case 32:
- color = COLOR_FROM_PIXEL32_ADDRESS(p); break;
- };
-
rect.x = (CARD16) (Swap16IfLE(pRect->x) + pfburh->r.x);
rect.y = (CARD16) (Swap16IfLE(pRect->y) + pfburh->r.y);
rect.w = Swap16IfLE(pRect->w);
diff --git a/vncviewer/ClientConnectionZlib.cpp b/vncviewer/ClientConnectionZlib.cpp
index eda4c3f..21f240e 100755
--- a/vncviewer/ClientConnectionZlib.cpp
+++ b/vncviewer/ClientConnectionZlib.cpp
@@ -62,8 +62,6 @@ void ClientConnection::ReadZlibRect(rfbFramebufferUpdateRectHeader *pfburh, bool
if (ultraVncZlib->decompress(numCompBytes, numRawBytes, (unsigned char *)m_netbuf, m_zlibbuf, zstd) != Z_OK)
return;
- SETUP_COLOR_SHORTCUTS;
-
// No other threads can use bitmap DC
omni_mutex_lock l(m_bitmapdcMutex);
@@ -156,7 +154,6 @@ void ClientConnection::ReadQueueZip(rfbFramebufferUpdateRectHeader *pfburh,HRGN
SaveArea(rect);
if ( surh.encoding==rfbEncodingRaw) {
UINT numpixels = surh.r.w * surh.r.h;
- SETUP_COLOR_SHORTCUTS;
omni_mutex_lock l(m_bitmapdcMutex);
// This big switch is untidy but fast
diff --git a/vncviewer/ClientConnectionZlibHex.cpp b/vncviewer/ClientConnectionZlibHex.cpp
index 4148bb4..10878fa 100755
--- a/vncviewer/ClientConnectionZlibHex.cpp
+++ b/vncviewer/ClientConnectionZlibHex.cpp
@@ -60,8 +60,6 @@ void ClientConnection::ReadZlibHexRect(rfbFramebufferUpdateRectHeader *pfburh, b
}
}
-COLORREF bgcolor = 0;
-COLORREF fgcolor = 0;
BYTE pfgcolor[4];
BYTE pbgcolor[4];
@@ -74,7 +72,6 @@ void ClientConnection::HandleZlibHexEncoding##bpp(int rx, int ry, int rw, int rh
\
CheckBufferSize((( 16 * 16 + 2 ) * bpp / 8 ) + 20 ); \
CheckZlibBufferSize((( 16 * 16 + 2 ) * bpp / 8 ) + 20 ); \
- SETUP_COLOR_SHORTCUTS; \
\
for (y = ry; y < ry+rh; y += 16) { \
omni_mutex_lock l(m_bitmapdcMutex); \
@@ -135,18 +132,14 @@ void ClientConnection::HandleZlibHexSubencodingStream##bpp(int x, int y, int w,
int sx, sy, sw, sh; \
CARD8 nSubrects; \
\
- SETUP_COLOR_SHORTCUTS; \
- \
if (subencoding & rfbHextileBackgroundSpecified) { \
ReadExact((char *)&bg, (bpp/8)); \
- bgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(&bg); \
memcpy(pbgcolor,&bg,bpp/8); \
} \
FillSolidRect_ultra(x,y,w,h, m_myFormat.bitsPerPixel,(BYTE*)pbgcolor);\
\
if (subencoding & rfbHextileForegroundSpecified) { \
ReadExact((char *)&fg, (bpp/8)); \
- fgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(&fg); \
memcpy(pfgcolor,&fg,bpp/8); \
} \
\
@@ -163,7 +156,6 @@ void ClientConnection::HandleZlibHexSubencodingStream##bpp(int x, int y, int w,
ReadExact( m_netbuf, nSubrects * (2 + (bpp / 8))); \
\
for (i = 0; i < nSubrects; i++) { \
- fgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(ptr); \
memcpy(pfgcolor,ptr,bpp/8); \
ptr += (bpp/8); \
sx = *ptr >> 4; \
@@ -196,13 +188,10 @@ void ClientConnection::HandleZlibHexSubencodingBuf##bpp(int x, int y, int w, int
CARD8 nSubrects; \
int bufIndex = 0; \
\
- SETUP_COLOR_SHORTCUTS; \
- \
if (subencoding & rfbHextileBackgroundSpecified) { \
bg = *((CARD##bpp *)(buffer + bufIndex)); \
bufIndex += (bpp/8); \
/* ReadExact((char *)&bg, (bpp/8)); */ \
- bgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(&bg); \
memcpy(pbgcolor,&bg,bpp/8); \
} \
FillSolidRect_ultra(x,y,w,h, m_myFormat.bitsPerPixel,(BYTE*)pbgcolor);\
@@ -211,7 +200,6 @@ void ClientConnection::HandleZlibHexSubencodingBuf##bpp(int x, int y, int w, int
fg = *((CARD##bpp *)(buffer + bufIndex)); \
bufIndex += (bpp/8); \
/* ReadExact((char *)&fg, (bpp/8)); */ \
- fgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(&fg); \
memcpy(pfgcolor,&fg,bpp/8); \
} \
\
@@ -230,7 +218,6 @@ void ClientConnection::HandleZlibHexSubencodingBuf##bpp(int x, int y, int w, int
/* ReadExact( m_netbuf, nSubrects * (2 + (bpp / 8))); */ \
\
for (i = 0; i < nSubrects; i++) { \
- fgcolor = COLOR_FROM_PIXEL##bpp##_ADDRESS(ptr); \
memcpy(pfgcolor,ptr,bpp/8); \
ptr += (bpp/8); \
sx = *ptr >> 4; \
diff --git a/vncviewer/xz.cpp b/vncviewer/xz.cpp
index b8bdd2b..887f9ee 100755
--- a/vncviewer/xz.cpp
+++ b/vncviewer/xz.cpp
@@ -21,11 +21,8 @@
#define BPP 8
#define XZYW_ENDIAN ENDIAN_NO
#define IMAGE_RECT(x,y,w,h,data) \
- SETUP_COLOR_SHORTCUTS; \
SETPIXELS(m_netbuf,8,x,y,w,h)
#define FILL_RECT(x,y,w,h,pix) \
- SETUP_COLOR_SHORTCUTS; \
- COLORREF color = COLOR_FROM_PIXEL8_ADDRESS(&pix); \
FillSolidRect_ultra(x,y,w,h, m_myFormat.bitsPerPixel,(BYTE*)&pix)
#include <rfb/xzDecode.h>
@@ -37,11 +34,8 @@
#define BPP 16
#define XZYW_ENDIAN ENDIAN_LITTLE
#define IMAGE_RECT(x,y,w,h,data) \
- SETUP_COLOR_SHORTCUTS; \
SETPIXELS(m_netbuf,16,x,y,w,h)
#define FILL_RECT(x,y,w,h,pix) \
- SETUP_COLOR_SHORTCUTS; \
- COLORREF color = COLOR_FROM_PIXEL16_ADDRESS(&pix); \
FillSolidRect_ultra(x,y,w,h, m_myFormat.bitsPerPixel,(BYTE*)&pix)
#include <rfb/xzDecode.h>
@@ -56,11 +50,8 @@
#undef FILL_RECT
#define IMAGE_RECT(x,y,w,h,data) \
- SETUP_COLOR_SHORTCUTS; \
SETPIXELS(m_netbuf,32,x,y,w,h)
#define FILL_RECT(x,y,w,h,pix) \
- SETUP_COLOR_SHORTCUTS; \
- COLORREF color = COLOR_FROM_PIXEL32_ADDRESS(&pix); \
FillSolidRect_ultra(x,y,w,h, m_myFormat.bitsPerPixel,(BYTE*)&pix)
diff --git a/vncviewer/zrle.cpp b/vncviewer/zrle.cpp
index 988b823..eaa569b 100755
--- a/vncviewer/zrle.cpp
+++ b/vncviewer/zrle.cpp
@@ -21,11 +21,8 @@
#define BPP 8
#define ZYWRLE_ENDIAN ENDIAN_NO
#define IMAGE_RECT(x,y,w,h,data) \
- SETUP_COLOR_SHORTCUTS; \
SETPIXELS(m_netbuf,8,x,y,w,h)
#define FILL_RECT(x,y,w,h,pix) \
- SETUP_COLOR_SHORTCUTS; \
- COLORREF color = COLOR_FROM_PIXEL8_ADDRESS(&pix); \
FillSolidRect_ultra(x,y,w,h, m_myFormat.bitsPerPixel,(BYTE*)&pix)
#include <rfb/zrleDecode.h>
@@ -37,11 +34,8 @@
#define BPP 16
#define ZYWRLE_ENDIAN ENDIAN_LITTLE
#define IMAGE_RECT(x,y,w,h,data) \
- SETUP_COLOR_SHORTCUTS; \
SETPIXELS(m_netbuf,16,x,y,w,h)
#define FILL_RECT(x,y,w,h,pix) \
- SETUP_COLOR_SHORTCUTS; \
- COLORREF color = COLOR_FROM_PIXEL16_ADDRESS(&pix); \
FillSolidRect_ultra(x,y,w,h, m_myFormat.bitsPerPixel,(BYTE*)&pix)
#include <rfb/zrleDecode.h>
@@ -56,11 +50,8 @@
#undef FILL_RECT
#define IMAGE_RECT(x,y,w,h,data) \
- SETUP_COLOR_SHORTCUTS; \
SETPIXELS(m_netbuf,32,x,y,w,h)
#define FILL_RECT(x,y,w,h,pix) \
- SETUP_COLOR_SHORTCUTS; \
- COLORREF color = COLOR_FROM_PIXEL32_ADDRESS(&pix); \
FillSolidRect_ultra(x,y,w,h, m_myFormat.bitsPerPixel,(BYTE*)&pix)
I'm sorry for the content that has nothing to do with the main subject.