Consistent use of stride vs pitch
Consistently use the term stride rather than pitch. Also
consistently represent the stride in number of pixels rather
than number of bytes. There is so much code that assumes
proper alignment already that we do not need the extra resolution.
diff --git a/common/rfb/JpegCompressor.cxx b/common/rfb/JpegCompressor.cxx
index 7dbb7d9..c1ef3c7 100644
--- a/common/rfb/JpegCompressor.cxx
+++ b/common/rfb/JpegCompressor.cxx
@@ -142,7 +142,7 @@
delete cinfo;
}
-void JpegCompressor::compress(const rdr::U8 *buf, int pitch, const Rect& r,
+void JpegCompressor::compress(const rdr::U8 *buf, int stride, const Rect& r,
const PixelFormat& pf, int quality, int subsamp)
{
int w = r.width();
@@ -196,13 +196,14 @@
}
#endif
- if (pitch == 0) pitch = w * pf.bpp / 8;
+ if (stride == 0)
+ stride = w;
if (cinfo->in_color_space == JCS_RGB) {
srcBuf = new rdr::U8[w * h * pixelsize];
srcBufIsTemp = true;
- pf.rgbFromBuffer(srcBuf, (const rdr::U8 *)buf, w, pitch, h);
- pitch = w * pixelsize;
+ pf.rgbFromBuffer(srcBuf, (const rdr::U8 *)buf, w, stride, h);
+ stride = w;
}
cinfo->input_components = pixelsize;
@@ -238,7 +239,7 @@
rowPointer = new JSAMPROW[h];
for (int dy = 0; dy < h; dy++)
- rowPointer[dy] = (JSAMPROW)(&srcBuf[dy * pitch]);
+ rowPointer[dy] = (JSAMPROW)(&srcBuf[dy * stride * pixelsize]);
jpeg_start_compress(cinfo, TRUE);
while (cinfo->next_scanline < cinfo->image_height)
diff --git a/common/rfb/JpegDecompressor.cxx b/common/rfb/JpegDecompressor.cxx
index 503c030..4d230eb 100644
--- a/common/rfb/JpegDecompressor.cxx
+++ b/common/rfb/JpegDecompressor.cxx
@@ -139,12 +139,12 @@
}
void JpegDecompressor::decompress(const rdr::U8 *jpegBuf, int jpegBufLen,
- rdr::U8 *buf, int pitch, const Rect& r, const PixelFormat& pf)
+ rdr::U8 *buf, int stride, const Rect& r, const PixelFormat& pf)
{
int w = r.width();
int h = r.height();
int pixelsize;
- int dstBufPitch;
+ int dstBufStride;
rdr::U8 *dstBuf = NULL;
bool dstBufIsTemp = false;
JSAMPROW *rowPointer = NULL;
@@ -163,8 +163,9 @@
jpeg_read_header(dinfo, TRUE);
dinfo->out_color_space = JCS_RGB;
pixelsize = 3;
- if (pitch == 0) pitch = w * pf.bpp / 8;
- dstBufPitch = pitch;
+ if (stride == 0)
+ stride = w;
+ dstBufStride = stride;
#ifdef JCS_EXTENSIONS
// Try to have libjpeg output directly to our native format
@@ -201,12 +202,12 @@
if (dinfo->out_color_space == JCS_RGB) {
dstBuf = new rdr::U8[w * h * pixelsize];
dstBufIsTemp = true;
- dstBufPitch = w * pixelsize;
+ dstBufStride = w;
}
rowPointer = new JSAMPROW[h];
for (int dy = 0; dy < h; dy++)
- rowPointer[dy] = (JSAMPROW)(&dstBuf[dy * dstBufPitch]);
+ rowPointer[dy] = (JSAMPROW)(&dstBuf[dy * dstBufStride * pixelsize]);
jpeg_start_decompress(dinfo);
@@ -225,7 +226,7 @@
}
if (dinfo->out_color_space == JCS_RGB)
- pf.bufferFromRGB((rdr::U8*)buf, dstBuf, w, pitch, h);
+ pf.bufferFromRGB((rdr::U8*)buf, dstBuf, w, stride, h);
jpeg_finish_decompress(dinfo);
diff --git a/common/rfb/PixelFormat.cxx b/common/rfb/PixelFormat.cxx
index c70a170..6a5fc96 100644
--- a/common/rfb/PixelFormat.cxx
+++ b/common/rfb/PixelFormat.cxx
@@ -180,7 +180,7 @@
}
void PixelFormat::bufferFromRGB(rdr::U8 *dst, const rdr::U8* src,
- int w, int pitch, int h, ColourMap* cm) const
+ int w, int stride, int h, ColourMap* cm) const
{
if (is888()) {
// Optimised common case
@@ -198,7 +198,7 @@
x = dst + (48 - redShift - greenShift - blueShift)/8;
}
- int dstPad = pitch - w * 4;
+ int dstPad = (stride - w) * 4;
while (h--) {
int w_ = w;
while (w_--) {
@@ -218,7 +218,7 @@
}
} else {
// Generic code
- int dstPad = pitch - w * 4;
+ int dstPad = (stride - w) * 4;
while (h--) {
int w_ = w;
while (w_--) {
@@ -295,7 +295,7 @@
void PixelFormat::rgbFromBuffer(rdr::U8* dst, const rdr::U8* src,
- int w, int pitch, int h, ColourMap* cm) const
+ int w, int stride, int h, ColourMap* cm) const
{
if (is888()) {
// Optimised common case
@@ -311,7 +311,7 @@
b = src + blueShift/8;
}
- int srcPad = pitch - w * 4;
+ int srcPad = (stride - w) * 4;
while (h--) {
int w_ = w;
while (w_--) {
@@ -328,7 +328,7 @@
}
} else {
// Generic code
- int srcPad = pitch - w * bpp/8;
+ int srcPad = (stride - w) * bpp/8;
while (h--) {
int w_ = w;
while (w_--) {
diff --git a/common/rfb/PixelFormat.h b/common/rfb/PixelFormat.h
index fdb829c..a8408dd 100644
--- a/common/rfb/PixelFormat.h
+++ b/common/rfb/PixelFormat.h
@@ -63,7 +63,7 @@
inline Pixel pixelFromRGB(rdr::U8 red, rdr::U8 green, rdr::U8 blue, ColourMap* cm=0) const;
void bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
- void bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, int w, int pitch,
+ void bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, int w, int stride,
int h, ColourMap* cm=0) const;
void rgbFromPixel(Pixel pix, ColourMap* cm, Colour* rgb) const;
@@ -71,7 +71,7 @@
inline void rgbFromPixel(Pixel pix, ColourMap* cm, rdr::U8 *r, rdr::U8 *g, rdr::U8 *b) const;
void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int pixels, ColourMap* cm=0) const;
- void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int w, int pitch,
+ void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int w, int stride,
int h, ColourMap* cm=0) const;
void print(char* str, int len) const;
diff --git a/common/rfb/tightDecode.h b/common/rfb/tightDecode.h
index fb39d99..06c8477 100644
--- a/common/rfb/tightDecode.h
+++ b/common/rfb/tightDecode.h
@@ -257,8 +257,7 @@
// We always use direct decoding with JPEG images
int stride;
rdr::U8 *buf = handler->getRawBufferRW(r, &stride);
- jd.decompress(netbuf, compressedLen, buf, stride * clientpf.bpp / 8, r,
- clientpf);
+ jd.decompress(netbuf, compressedLen, buf, stride, r, clientpf);
handler->releaseRawBuffer(r);
delete [] netbuf;
diff --git a/common/rfb/tightEncode.h b/common/rfb/tightEncode.h
index 6a59ba8..d5b2c66 100644
--- a/common/rfb/tightEncode.h
+++ b/common/rfb/tightEncode.h
@@ -412,7 +412,7 @@
rdr::OutStream *os)
{
jc.clear();
- jc.compress((rdr::U8 *)buf, stride * clientpf.bpp / 8, r, clientpf,
+ jc.compress((rdr::U8 *)buf, stride, r, clientpf,
jpegQuality, jpegSubsampling);
os->writeU8(0x09 << 4);
os->writeCompactLength(jc.length());