From 801123d021628e413c6a3a1ce59d6c41daff2a38 Mon Sep 17 00:00:00 2001 From: Constantin Kaplinsky Date: Fri, 18 Jan 2008 15:23:11 +0000 Subject: [PATCH] Minor code improvement: added Image::locatePixel(x, y) function to get rid of direct pointer arithmetic. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2411 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- unix/x0vncserver/Image.h | 9 ++++++++- unix/x0vncserver/PollingManager.cxx | 13 +++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/unix/x0vncserver/Image.h b/unix/x0vncserver/Image.h index 43c0b0b5..4cac8b41 100644 --- a/unix/x0vncserver/Image.h +++ b/unix/x0vncserver/Image.h @@ -64,7 +64,14 @@ public: // Pointer to corresponding XImage, made public for efficiency. // NOTE: if this field is NULL, then no methods other than Init() // may be called. - XImage* xim; + XImage *xim; + + // Get a pointer to the data corresponding to the given coordinates. + inline char *locatePixel(int x, int y) const { + return (xim->data + + y * xim->bytes_per_line + + x * (xim->bits_per_pixel / 8)); + } protected: diff --git a/unix/x0vncserver/PollingManager.cxx b/unix/x0vncserver/PollingManager.cxx index 91407784..0c35c400 100644 --- a/unix/x0vncserver/PollingManager.cxx +++ b/unix/x0vncserver/PollingManager.cxx @@ -249,8 +249,6 @@ bool PollingManager::pollScreen() int PollingManager::checkRow(int x, int y, int w) { - int bytesPerLine = m_image->xim->bytes_per_line; - // If necessary, expand the row to the left, to the tile border. // In other words, x must be a multiple of 32. if (x % 32 != 0) { @@ -273,8 +271,7 @@ int PollingManager::checkRow(int x, int y, int w) } // Compute pointers to images to be compared. - // FIXME: Provide an inline function Image::locatePixel(x, y). - char *ptr_old = m_image->xim->data + y * bytesPerLine + x * m_bytesPerPixel; + char *ptr_old = m_image->locatePixel(x, y); char *ptr_new = m_rowImage->xim->data; // Compare pixels, raise corresponding elements of m_changeFlags[]. @@ -303,13 +300,9 @@ int PollingManager::checkColumn(int x, int y, int h, bool *pChangeFlags) if (!*pChangeFlags) { int tile_h = (h - nTile * 32 >= 32) ? 32 : h - nTile * 32; for (int i = 0; i < tile_h; i++) { - // FIXME: Provide an inline function Image::locatePixel(x, y). // FIXME: Do not compute these pointers in the inner cycle. - char *ptr_old = (m_image->xim->data + - (y + nTile * 32 + i) * m_image->xim->bytes_per_line + - x * m_bytesPerPixel); - char *ptr_new = (m_columnImage->xim->data + - (nTile * 32 + i) * m_columnImage->xim->bytes_per_line); + char *ptr_old = m_image->locatePixel(x, y + nTile * 32 + i); + char *ptr_new = m_columnImage->locatePixel(0, nTile * 32 + i); if (memcmp(ptr_old, ptr_new, m_bytesPerPixel)) { *pChangeFlags = true; nTilesChanged++; -- 2.39.5