From 1c2e9e6a2262f45ad368a77bf35a4a9340f1aa90 Mon Sep 17 00:00:00 2001 From: george82 Date: Sun, 3 Dec 2006 12:46:54 +0000 Subject: [PATCH] Fixed the bug with very low quality of the remote desktop scaling. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2165 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- common/rfb/ScaleFilters.cxx | 18 ++++++++++-------- common/rfb/ScaleFilters.h | 4 ++-- common/rfb/ScaledPixelBuffer.cxx | 18 ++++++++---------- win/rfb_win32/ScaledDIBSectionBuffer.cxx | 8 ++++---- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/common/rfb/ScaleFilters.cxx b/common/rfb/ScaleFilters.cxx index e90e1e38..cd08f674 100644 --- a/common/rfb/ScaleFilters.cxx +++ b/common/rfb/ScaleFilters.cxx @@ -87,9 +87,10 @@ SFilter ScaleFilters::create(char *name_, double radius_, filter_func func_) { return filter; } -void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, SFilterWeightTab **pWeightTabs) { - double sx; - double ratio = double(dst_x) / src_x; +void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, double ratio, SFilterWeightTab **pWeightTabs) { + double sxc; + double offset = 0.5; + SFilter sFilter = filters[filter_id]; *pWeightTabs = new SFilterWeightTab[dst_x]; @@ -97,17 +98,18 @@ void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, SFilterWe // Make the weight tab for the each dest x position for (int x = 0; x < dst_x; x++) { - sx = double(x) / ratio; + sxc = (double(x)+offset) / ratio; // Calculate the scale filter interval, [i0, i1) - int i0 = int(__rfbmax(ceil(sx-sFilter.radius), 0)); - int i1 = int(__rfbmin(ceil(sx+sFilter.radius), src_x)); + int i0 = int(__rfbmax(sxc-sFilter.radius+0.5, 0)); + int i1 = int(__rfbmin(sxc+sFilter.radius+0.5, src_x)); + weightTabs[x].i0 = i0; weightTabs[x].i1 = i1; - weightTabs[x].weight = new float[i1-i0]; + weightTabs[x].weight = new double[i1-i0]; // Calculate the weight coeffs on the scale filter interval for (int ci = 0, i = i0; i < i1; i++) { - weightTabs[x].weight[ci++] = (float)sFilter.func(float(i)-sx); + weightTabs[x].weight[ci++] = (double)sFilter.func(double(i)-sxc+0.5); } } } diff --git a/common/rfb/ScaleFilters.h b/common/rfb/ScaleFilters.h index c2555a74..75b1e7f1 100644 --- a/common/rfb/ScaleFilters.h +++ b/common/rfb/ScaleFilters.h @@ -49,7 +49,7 @@ namespace rfb { // Scale filter weight table typedef struct { short int i0, i1; // Filter function interval, [i0..i1) - float *weight; // Weight coefficients on the filter function interval + double *weight; // Weight coefficients on the filter function interval } SFilterWeightTab; @@ -60,7 +60,7 @@ namespace rfb { SFilter &operator[](unsigned int filter_id); - void makeWeightTabs(int filter, int src_x, int dst_x, SFilterWeightTab **weightTabs); + void makeWeightTabs(int filter, int src_x, int dst_x, double ratio, SFilterWeightTab **weightTabs); protected: void initFilters(); diff --git a/common/rfb/ScaledPixelBuffer.cxx b/common/rfb/ScaledPixelBuffer.cxx index c38a2543..b5b3ea32 100644 --- a/common/rfb/ScaledPixelBuffer.cxx +++ b/common/rfb/ScaledPixelBuffer.cxx @@ -67,8 +67,8 @@ void ScaledPixelBuffer::setSourceBuffer(U8 **src_data_, int w, int h) { src_width = w; src_height = h; calculateScaledBufferSize(); - scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs); - scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs); + scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs); + scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs); } void ScaledPixelBuffer::setPF(const PixelFormat &pf_) { @@ -81,8 +81,8 @@ void ScaledPixelBuffer::setScaleRatio(double scale_ratio_) { freeWeightTabs(); scale_ratio = scale_ratio_; calculateScaledBufferSize(); - scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs); - scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs); + scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs); + scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs); } } @@ -111,8 +111,8 @@ inline U32 ScaledPixelBuffer::getSourcePixel(int x, int y) { void ScaledPixelBuffer::scaleRect(const Rect& rect) { Rect changed_rect; - U8 *ptr, *pxs, *px; - float rx, gx, bx, red, green, blue, *xweight, *yweight, xWeight, yWeight; + U8 *ptr; + double 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 @@ -126,7 +126,6 @@ void ScaledPixelBuffer::scaleRect(const Rect& rect) { for (int x = changed_rect.tl.x; x < changed_rect.br.x; x++) { ywi = 0; red = 0; green = 0; blue = 0; - pxs = &(*src_data)[(xWeightTabs[x].i0 + yWeightTabs[y].i0*src_width) * bytesPerPixel]; xweight = xWeightTabs[x].weight; // Calculate the scaled pixel value at (x, y) coordinates by @@ -136,14 +135,13 @@ void ScaledPixelBuffer::scaleRect(const Rect& rect) { // [(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++) { - xwi = 0; rx = 0; gx = 0; bx = 0; px = pxs; + xwi = 0; rx = 0; gx = 0; bx = 0; for (int xs = xWeightTabs[x].i0; xs < xWeightTabs[x].i1; xs++) { - rgbFromPixel(*(U32*)(px), r, g, b); + rgbFromPixel(getSourcePixel(xs, ys), r, g, b); xWeight = xweight[xwi++]; rx += r * xWeight; gx += g * xWeight; bx += b * xWeight; - px += bytesPerPixel; } yWeight = yweight[ywi++]; red += rx * yWeight; diff --git a/win/rfb_win32/ScaledDIBSectionBuffer.cxx b/win/rfb_win32/ScaledDIBSectionBuffer.cxx index aa52e078..1a287c06 100644 --- a/win/rfb_win32/ScaledDIBSectionBuffer.cxx +++ b/win/rfb_win32/ScaledDIBSectionBuffer.cxx @@ -50,8 +50,8 @@ void ScaledDIBSectionBuffer::setScaleRatio(double scale_ratio_) { // Calculate the scale weight tabs must be in the ScalePixelBuffer class freeWeightTabs(); calculateScaledBufferSize(); - scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs); - scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs); + scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs); + scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs); recreateBuffers(); } @@ -86,8 +86,8 @@ void ScaledDIBSectionBuffer::setSize(int src_width_, int src_height_) { // Calculate the scale weight tabs must be in the ScalePixelBuffer class freeWeightTabs(); calculateScaledBufferSize(); - scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, &xWeightTabs); - scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, &yWeightTabs); + scaleFilters.makeWeightTabs(scaleFilterID, src_width, scaled_width, scale_ratio, &xWeightTabs); + scaleFilters.makeWeightTabs(scaleFilterID, src_height, scaled_height, scale_ratio, &yWeightTabs); recreateBuffers(); } -- 2.39.5