]> source.dussan.org Git - tigervnc.git/commitdiff
Minor code improvement: added Image::locatePixel(x, y) function to get rid of direct...
authorConstantin Kaplinsky <const@tightvnc.com>
Fri, 18 Jan 2008 15:23:11 +0000 (15:23 +0000)
committerConstantin Kaplinsky <const@tightvnc.com>
Fri, 18 Jan 2008 15:23:11 +0000 (15:23 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2411 3789f03b-4d11-0410-bbf8-ca57d06f2519

unix/x0vncserver/Image.h
unix/x0vncserver/PollingManager.cxx

index 43c0b0b5f52ae9324c6ae8c65e2752f46f6462f3..4cac8b417d7991261ac9f913ac24a0bb48e9a61a 100644 (file)
@@ -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:
 
index 914077840a9eac3ff78a407e7072f58079b57fe4..0c35c400eaf2cb38cb79682995fc00a1b44c92e8 100644 (file)
@@ -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++;