From d5dacda6a471a122ee289c8202f94be5ec534d04 Mon Sep 17 00:00:00 2001 From: george82 Date: Thu, 23 Nov 2006 10:12:50 +0000 Subject: [PATCH] Improved the performance of the scaling algorithm too much. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2125 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- common/rfb/ScaledPixelBuffer.cxx | 52 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/common/rfb/ScaledPixelBuffer.cxx b/common/rfb/ScaledPixelBuffer.cxx index d9a245bb..2bfb4e87 100644 --- a/common/rfb/ScaledPixelBuffer.cxx +++ b/common/rfb/ScaledPixelBuffer.cxx @@ -110,40 +110,44 @@ inline U32 ScaledPixelBuffer::getSourcePixel(int x, int y) { } void ScaledPixelBuffer::scaleRect(const Rect& rect) { - U8 *ptr; - static double c1_sub_dx, c1_sub_dy; Rect changed_rect; - float rx, gx, bx; - float red, green, blue; - int r, g, b; - + U8 *ptr; + U32 *px, *psrc_data = (U32*)(*src_data); + float rx, gx, bx, red, green, blue, *xweight, *yweight, xWeight, yWeight; + int r, g, b, xwi, ywi; // Calculate the changed pixel rect in the scaled image changed_rect = calculateScaleBoundary(rect); - int bytesPerPixel = pf.bpp/8; - int bytesPerRow = src_width * bytesPerPixel; - for (int y = changed_rect.tl.y; y < changed_rect.br.y; y++) { - ptr = &(*scaled_data)[(changed_rect.tl.x + y*scaled_width) * bytesPerPixel]; - + ptr = &(*scaled_data)[(changed_rect.tl.x + y*scaled_width) * 4]; + yweight = xWeightTabs[y].weight; + for (int x = changed_rect.tl.x; x < changed_rect.br.x; x++) { - - int ywi = 0; red = 0; green = 0; blue = 0; + ywi = 0; red = 0; green = 0; blue = 0; + px = &psrc_data[xWeightTabs[x].i0 + yWeightTabs[y].i0*src_width]; + xweight = xWeightTabs[x].weight; + + // Calculate the scaled pixel value at (x, y) coordinates by + // convolution the matrix from source image: + // [(xWeight.i0,yWeight.i0)......(xWeight.i1-1,yWeight.i0)] + // [......................................................] + // [(xWeight.i0,yWeight.i1-1)..(xWeight.i1-1,yWeight.i1-1)], + // where [i0, i1) is the scaled filter interval. for (int ys = yWeightTabs[y].i0; ys < yWeightTabs[y].i1; ys++) { - - int xwi = 0; rx = 0; gx = 0; bx = 0; + xwi = 0; rx = 0; gx = 0; bx = 0; for (int xs = xWeightTabs[x].i0; xs < xWeightTabs[x].i1; xs++) { - rgbFromPixel(getSourcePixel(xs, ys), r, g, b); - rx += r * xWeightTabs[x].weight[xwi]; - gx += g * xWeightTabs[x].weight[xwi]; - bx += b * xWeightTabs[x].weight[xwi]; - xwi++; + rgbFromPixel(px[xwi], r, g, b); + xWeight = xweight[xwi++]; + rx += r * xWeight; + gx += g * xWeight; + bx += b * xWeight; } - red += rx * yWeightTabs[y].weight[ywi]; - green += gx * yWeightTabs[y].weight[ywi]; - blue += bx * yWeightTabs[y].weight[ywi]; - ywi++; + yWeight = yweight[ywi++]; + red += rx * yWeight; + green += gx * yWeight; + blue += bx * yWeight; + px += src_width; } *ptr++ = U8(blue); *ptr++ = U8(green); -- 2.39.5