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
diff --git a/unix/x0vncserver/Image.h b/unix/x0vncserver/Image.h
index 43c0b0b..4cac8b4 100644
--- a/unix/x0vncserver/Image.h
+++ b/unix/x0vncserver/Image.h
@@ -64,7 +64,14 @@
   // 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 9140778..0c35c40 100644
--- a/unix/x0vncserver/PollingManager.cxx
+++ b/unix/x0vncserver/PollingManager.cxx
@@ -249,8 +249,6 @@
 
 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 @@
   }
 
   // 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 @@
     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++;