Fix rounding when sizing 1x1 textures
authorH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 22 Apr 2016 07:33:23 +0000 (09:33 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 22 Apr 2016 07:33:23 +0000 (09:33 +0200)
When 1x1 textures were sized to the actual square size, this could lead
to bitmaps that were 1 pixel too small, presumably because of rounding.
We now add 0.99 pixel to the desired size of the texture image before
calculating the scaling factor (in floating arithmetic) that has to be
passed to the cairo scaling routine, and this seems to solve the problem.

draw.c

diff --git a/draw.c b/draw.c
index 1d17314..3b4ddec 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -295,7 +295,7 @@ CreatePNGBoard (char *s, int kind)
                if(f == 0 || r == 0) f = BOARD_WIDTH, r = BOARD_HEIGHT; // 0x0 means 'fits any', so make it fit
                textureW[kind] = (w*BOARD_WIDTH)/f; // sync cutting locations with square pattern
                textureH[kind] = (h*BOARD_HEIGHT)/r;
-               n[kind] = r*squareSize/h; // scale to make it fit exactly vertically
+               n[kind] = (r*squareSize + 0.99)/h;  // scale to make it fit exactly vertically
                modV[kind] = r; modH[kind] = f;
            } else
            if((p = strstr(s, "xq")) && (p == s || p[-1] == '/')) { // assume full-board image for Xiangqi