From: Pierre Ossman Date: Wed, 22 Jan 2014 10:28:05 +0000 (+0100) Subject: Consistent use of stride vs pitch X-Git-Tag: v1.3.90~48^2~4 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a10d8fec7fdf860addbe2287cd345ad09b344478;p=tigervnc.git 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 7dbb7d94..c1ef3c7d 100644 --- a/common/rfb/JpegCompressor.cxx +++ b/common/rfb/JpegCompressor.cxx @@ -142,7 +142,7 @@ JpegCompressor::~JpegCompressor(void) 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 @@ void JpegCompressor::compress(const rdr::U8 *buf, int pitch, const Rect& r, } #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 @@ void JpegCompressor::compress(const rdr::U8 *buf, int pitch, const Rect& r, 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 503c030f..4d230eb8 100644 --- a/common/rfb/JpegDecompressor.cxx +++ b/common/rfb/JpegDecompressor.cxx @@ -139,12 +139,12 @@ JpegDecompressor::~JpegDecompressor(void) } 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 @@ void JpegDecompressor::decompress(const rdr::U8 *jpegBuf, int jpegBufLen, 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 @@ void JpegDecompressor::decompress(const rdr::U8 *jpegBuf, int jpegBufLen, 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 @@ void JpegDecompressor::decompress(const rdr::U8 *jpegBuf, int jpegBufLen, } 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 c70a1701..6a5fc96d 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, } 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 @@ void PixelFormat::bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, 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 @@ void PixelFormat::bufferFromRGB(rdr::U8 *dst, const rdr::U8* src, } } 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 pixels, Co 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 @@ void PixelFormat::rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, 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 @@ void PixelFormat::rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, } } 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 fdb829c9..a8408ddd 100644 --- a/common/rfb/PixelFormat.h +++ b/common/rfb/PixelFormat.h @@ -63,7 +63,7 @@ namespace rfb { 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 @@ namespace rfb { 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 fb39d996..06c84775 100644 --- a/common/rfb/tightDecode.h +++ b/common/rfb/tightDecode.h @@ -257,8 +257,7 @@ DECOMPRESS_JPEG_RECT(const Rect& r) // 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 6a59ba81..d5b2c660 100644 --- a/common/rfb/tightEncode.h +++ b/common/rfb/tightEncode.h @@ -412,7 +412,7 @@ void ENCODE_JPEG_RECT (PIXEL_T *buf, int stride, const Rect& r, 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());