From: Constantin Kaplinsky Date: Tue, 4 Sep 2007 09:12:59 +0000 (+0000) Subject: Fixed a problem with copying discontinuous pixel data to IRIX JPEG ompressor. X-Git-Tag: v0.0.90~384^2~131 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=52eaa8c05517e5b52ed9f2d8271d0cbb038bd36b;p=tigervnc.git 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 6b763047..b3378a78 100644 --- a/common/rfb/IrixDMIC_RawToJpeg.cxx +++ b/common/rfb/IrixDMIC_RawToJpeg.cxx @@ -311,6 +311,32 @@ IrixDMIC_RawToJpeg::copyToBuffer(DMbuffer buf, const void *data, int dataSize) return true; } +// +// 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 33674bd3..b067e135 100644 --- a/common/rfb/IrixDMIC_RawToJpeg.h +++ b/common/rfb/IrixDMIC_RawToJpeg.h @@ -28,6 +28,8 @@ namespace rfb { 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 57e8aa80..dda059f8 100644 --- a/common/rfb/IrixDMJpegCompressor.cxx +++ b/common/rfb/IrixDMJpegCompressor.cxx @@ -79,8 +79,9 @@ IrixDMJpegCompressor::compress(const rdr::U32 *buf, 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; }