Fixed a problem with copying discontinuous pixel data to IRIX JPEG ompressor.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2335 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/rfb/IrixDMIC_RawToJpeg.cxx b/common/rfb/IrixDMIC_RawToJpeg.cxx
index 6b76304..b3378a7 100644
--- a/common/rfb/IrixDMIC_RawToJpeg.cxx
+++ b/common/rfb/IrixDMIC_RawToJpeg.cxx
@@ -312,6 +312,32 @@
 }
 
 //
+// Fill in a DMbuffer with data.
+//
+// NOTE: The caller must make sure that the buffer size is no less
+//       than (nRows * rowSize).
+//
+
+bool
+IrixDMIC_RawToJpeg::copyToBuffer(DMbuffer buf, const void *data,
+                                 int rowSize, int nRows, int stride)
+{
+  char *dataBytes = (char *)data;
+  char *bufPtr = (char *)dmBufferMapData(buf);
+  for (int i = 0; i < nRows; i++) {
+    memcpy(bufPtr, &dataBytes[i * stride], rowSize);
+    bufPtr += rowSize;
+  }
+
+  if (dmBufferSetSize(buf, nRows * rowSize) != DM_SUCCESS) {
+    reportError("dmBufferSetSize");
+    return false;
+  }
+
+  return true;
+}
+
+//
 // Map DMbuffer to physical memory.
 //
 
diff --git a/common/rfb/IrixDMIC_RawToJpeg.h b/common/rfb/IrixDMIC_RawToJpeg.h
index 33674bd..b067e13 100644
--- a/common/rfb/IrixDMIC_RawToJpeg.h
+++ b/common/rfb/IrixDMIC_RawToJpeg.h
@@ -28,6 +28,8 @@
 
     static bool allocBuffer(DMbuffer *pbuf, DMbufferpool pool);
     static bool copyToBuffer(DMbuffer buf, const void *data, int dataSize);
+    static bool copyToBuffer(DMbuffer buf, const void *data,
+                             int rowSize, int nRows, int stride);
     static int getBufferSize(DMbuffer buf);
     static void * mapBufferData(DMbuffer buf);
     static void freeBuffer(DMbuffer buf);
diff --git a/common/rfb/IrixDMJpegCompressor.cxx b/common/rfb/IrixDMJpegCompressor.cxx
index 57e8aa8..dda059f 100644
--- a/common/rfb/IrixDMJpegCompressor.cxx
+++ b/common/rfb/IrixDMJpegCompressor.cxx
@@ -79,8 +79,9 @@
   if (!m_ic.allocBuffer(&srcBuf, m_srcPool)) {
     return;
   }
-  // FIXME: Currently, copyToBuffer() copies parts of the image incorrectly.
-  if (!m_ic.copyToBuffer(srcBuf, buf, w * h * (fmt->bpp / 8))) {
+  int widthInBytes = w * (fmt->bpp / 8);
+  int strideInBytes = stride * (fmt->bpp / 8);
+  if (!m_ic.copyToBuffer(srcBuf, buf, widthInBytes, h, strideInBytes)) {
     m_ic.freeBuffer(srcBuf);
     return;
   }