I'm playing Wesnoth fullscreen on a 1920x1200 pixel display, and the
smaller maps do not look very good due to the use of nearest neighbor
image interpolation. This preliminary patch towards bilinear
interpolation helps. The patch basically works, except that a hex edge
tiling artifact is introduced. Comments appreciated.


TODO:

  * macrofy such that turning off fixed point arithmetic
    in util.hpp will not break scale_surface

  * find out what is causing the artifact and fix it



cd /ramdisk/home/knoppix/bar/wesnoth-1.0.2/
diff -u /ramdisk/home/knoppix/bar/wesnoth-1.0.2/src/sdl_utils.cpp.orig 
/ramdisk/home/knoppix/bar/wesnoth-1.0.2/src/sdl_utils.cpp
--- /ramdisk/home/knoppix/bar/wesnoth-1.0.2/src/sdl_utils.cpp.orig      
2005-12-13 15:47:57.718864120 -0500
+++ /ramdisk/home/knoppix/bar/wesnoth-1.0.2/src/sdl_utils.cpp   2005-12-13 
15:53:31.646099464 -0500
@@ -155,12 +155,35 @@
 
                fixed_t ysrc = ftofxp(0.0);
                for(int ydst = 0; ydst != h; ++ydst, ysrc += yratio) {
-                       fixed_t xsrc = ftofxp(0.0);
+                       fixed_t xsrc = ftofxp(0.0);
                        for(int xdst = 0; xdst != w; ++xdst, xsrc += xratio) {
                                const int xsrcint = fxptoi(xsrc);
                                const int ysrcint = fxptoi(ysrc);
-
-                               dst_pixels[ydst*dst->w + xdst] = 
src_pixels[ysrcint*src->w + xsrcint];
+                               Uint32* const src_word = src_pixels + 
ysrcint*src->w + xsrcint;
+                               Uint32* const dst_word = dst_pixels +    
ydst*dst->w + xdst;
+                               for (int byte=0; byte<4; byte++) {
+                                       Uint8* const dst_byte = 
(Uint8*)dst_word + byte;
+                                       Uint8* const src_byte = 
(Uint8*)src_word + byte;
+                                       int xfloor = fxptoi(xsrc);
+                                       int yfloor = fxptoi(ysrc);
+                                       const int dx = (xfloor + 1 < src->w) ? 
sizeof(Uint32) : 0;
+                                       const int dy = (yfloor + 1 < src->h) ? 
sizeof(Uint32) * src->w : 0;
+                                       Uint8* const ne = src_byte;
+                                       Uint8* const nw = src_byte + dx;
+                                       Uint8* const se = src_byte + dy;
+                                       Uint8* const sw = src_byte + dx + dy;
+                                       const fixed_t w = 0x000000FF & xsrc;
+                                       const fixed_t e = 0xFF - w;
+                                       const fixed_t s = 0x000000FF & ysrc;
+                                       const fixed_t n = 0xFF - s;
+                                       unsigned int val=0;
+                                       val += *ne * n * e;
+                                       val += *nw * n * w;
+                                       val += *sw * s * w;
+                                       val += *se * s * e;
+                                       val >>= 16;
+                                       *dst_byte = val;
+                               }
                        }
                }
        }

Reply via email to