]> source.dussan.org Git - tigervnc.git/commitdiff
Fixed the bug with very low quality of the remote desktop
authorgeorge82 <george82@3789f03b-4d11-0410-bbf8-ca57d06f2519>
Sun, 3 Dec 2006 12:46:54 +0000 (12:46 +0000)
committergeorge82 <george82@3789f03b-4d11-0410-bbf8-ca57d06f2519>
Sun, 3 Dec 2006 12:46:54 +0000 (12:46 +0000)
scaling.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2165 3789f03b-4d11-0410-bbf8-ca57d06f2519

common/rfb/ScaleFilters.cxx
common/rfb/ScaleFilters.h
common/rfb/ScaledPixelBuffer.cxx
win/rfb_win32/ScaledDIBSectionBuffer.cxx

index e90e1e38173acc96fdf9a0d78e2f67ac711a0cd5..cd08f674f6549a7b5444f51e550f06d34449c36c 100644 (file)
@@ -87,9 +87,10 @@ SFilter ScaleFilters::create(char *name_, double radius_, filter_func func_) {
   return filter;\r
 }\r
 \r
-void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, SFilterWeightTab **pWeightTabs) {\r
-  double sx;\r
-  double ratio = double(dst_x) / src_x;\r
+void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, double ratio, SFilterWeightTab **pWeightTabs) {\r
+  double sxc;\r
+  double offset = 0.5;\r
+\r
   SFilter sFilter = filters[filter_id];\r
   \r
   *pWeightTabs = new SFilterWeightTab[dst_x];\r
@@ -97,17 +98,18 @@ void ScaleFilters::makeWeightTabs(int filter_id, int src_x, int dst_x, SFilterWe
 \r
   // Make the weight tab for the each dest x position\r
   for (int x = 0; x < dst_x; x++) {\r
-    sx = double(x) / ratio;\r
+    sxc = (double(x)+offset) / ratio;\r
 \r
     // Calculate the scale filter interval, [i0, i1)\r
-    int i0 = int(__rfbmax(ceil(sx-sFilter.radius), 0));\r
-    int i1 = int(__rfbmin(ceil(sx+sFilter.radius), src_x));\r
+    int i0 = int(__rfbmax(sxc-sFilter.radius+0.5, 0));\r
+    int i1 = int(__rfbmin(sxc+sFilter.radius+0.5, src_x));\r
+\r
     weightTabs[x].i0 = i0; weightTabs[x].i1 = i1;\r
-    weightTabs[x].weight = new float[i1-i0];\r
+    weightTabs[x].weight = new double[i1-i0];\r
 \r
     // Calculate the weight coeffs on the scale filter interval\r
     for (int ci = 0, i = i0; i < i1; i++) {\r
-      weightTabs[x].weight[ci++] = (float)sFilter.func(float(i)-sx);\r
+      weightTabs[x].weight[ci++] = (double)sFilter.func(double(i)-sxc+0.5);\r
     }\r
   }\r
 }\r
index c2555a74d258471b404578f663f3efa33ca4cd13..75b1e7f175d4dc6678afbe50fa3ec7e984d4240c 100644 (file)
@@ -49,7 +49,7 @@ namespace rfb {
   // Scale filter weight table\r
   typedef struct {\r
     short int i0, i1;  // Filter function interval, [i0..i1)\r
-    float *weight;     // Weight coefficients on the filter function interval\r
+    double *weight;    // Weight coefficients on the filter function interval\r
   } SFilterWeightTab;\r
 \r
 \r
@@ -60,7 +60,7 @@ namespace rfb {
 \r
     SFilter &operator[](unsigned int filter_id);\r
 \r
-    void makeWeightTabs(int filter, int src_x, int dst_x, SFilterWeightTab **weightTabs);\r
+    void makeWeightTabs(int filter, int src_x, int dst_x, double ratio, SFilterWeightTab **weightTabs);\r
 \r
   protected:\r
     void initFilters();\r
index c38a2543bb698147d0b2847255b87f37041c27a9..b5b3ea327be4e62edb52e3bc843ae0a88a8aa1ab 100644 (file)
@@ -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;
index aa52e07875891b95d59ca5f4be55685782c6a7b0..1a287c063a7a7a86aa4ab137f69270e2f702781d 100644 (file)
@@ -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();
 }