From 38a6be484babd3a67e07e22c6fdd95e1c99fbe0c Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 25 Mar 2009 12:26:41 +0000 Subject: [PATCH] A quick optimisation of the common 32-bit to 24-bit pixel conversion. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3719 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- common/rfb/PixelFormat.cxx | 41 ++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/common/rfb/PixelFormat.cxx b/common/rfb/PixelFormat.cxx index fa7064fe..4221e448 100644 --- a/common/rfb/PixelFormat.cxx +++ b/common/rfb/PixelFormat.cxx @@ -209,17 +209,36 @@ void PixelFormat::rgbFromBuffer(rdr::U16* dst, const rdr::U8* src, int pixels, C void PixelFormat::rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int pixels, ColourMap* cm) const { - Pixel p; - rdr::U8 r, g, b; - - while (pixels--) { - p = pixelFromBuffer(src); - src += bpp/8; - - rgbFromPixel(p, cm, &r, &g, &b); - *(dst++) = r; - *(dst++) = g; - *(dst++) = b; + if (is888()) { + // Optimised common case + const rdr::U8 *r, *g, *b; + + r = src + redShift/8; + g = src + greenShift/8; + b = src + blueShift/8; + + while (pixels--) { + *(dst++) = *r; + *(dst++) = *g; + *(dst++) = *b; + r += 4; + g += 4; + b += 4; + } + } else { + // Generic code + Pixel p; + rdr::U8 r, g, b; + + while (pixels--) { + p = pixelFromBuffer(src); + src += bpp/8; + + rgbFromPixel(p, cm, &r, &g, &b); + *(dst++) = r; + *(dst++) = g; + *(dst++) = b; + } } } -- 2.39.5