From 58829f360dca7d929444d8f3748bae8a37be7ad0 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Wed, 17 Sep 2014 09:44:15 +0200 Subject: [PATCH] Scale texture bitmaps that are not large enough Texture bitmaps are now sized up by an integer factor to be at least as large as the board (if they seem intended for a full XQ board, which is assumed when they are larger than 256x256) or the square. This necessitated the textures to be re-initialized in InitDrawingSizes whenever the window size changes. --- draw.c | 35 ++++++++++++++++++++++++++++------- draw.h | 2 +- gtk/xboard.c | 2 +- xaw/xboard.c | 2 +- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/draw.c b/draw.c index 930b02c..9e0fae3 100644 --- a/draw.c +++ b/draw.c @@ -109,7 +109,7 @@ static cairo_surface_t *pngPieceImages[2][(int)BlackPawn+4]; // png 256 x 256 static cairo_surface_t *pngPieceBitmaps[2][(int)BlackPawn]; // scaled pieces as used static cairo_surface_t *pngPieceBitmaps2[2][(int)BlackPawn+4]; // scaled pieces in store static RsvgHandle *svgPieces[2][(int)BlackPawn+4]; // vector pieces in store -static cairo_surface_t *pngBoardBitmap[2]; +static cairo_surface_t *pngBoardBitmap[2], *pngOriginalBoardBitmap[2]; int useTexture, textureW[2], textureH[2]; #define pieceToSolid(piece) &pieceBitmap[SOLID][(piece) % (int)BlackPawn] @@ -202,6 +202,7 @@ InitDrawingSizes (BoardSize boardSize, int flags) oldWidth = boardWidth; oldHeight = boardHeight; CreateGrid(); + CreateAnyPieces(0); // redo texture scaling /* * Inhibit shell resizing. @@ -237,13 +238,33 @@ ExposeRedraw (Option *graph, int x, int y, int w, int h) static void CreatePNGBoard (char *s, int kind) { + float w, h; + static float n=1.; if(!appData.useBitmaps || s == NULL || *s == 0 || *s == '*') { useTexture &= ~(kind+1); return; } if(strstr(s, ".png")) { cairo_surface_t *img = cairo_image_surface_create_from_png (s); if(img) { - useTexture |= kind + 1; pngBoardBitmap[kind] = img; - textureW[kind] = cairo_image_surface_get_width (img); - textureH[kind] = cairo_image_surface_get_height (img); + if(pngOriginalBoardBitmap[kind]) cairo_surface_destroy(pngOriginalBoardBitmap[kind]); + if(n != 1.) cairo_surface_destroy(pngBoardBitmap[kind]); + useTexture |= kind + 1; pngOriginalBoardBitmap[kind] = img; + w = textureW[kind] = cairo_image_surface_get_width (img); + h = textureH[kind] = cairo_image_surface_get_height (img); + n = 1; + if(w > 256 & h > 256) { // full-board image? + while(squareSize*9 > n*w || squareSize*10 > n*h) n++; + } else { + while(squareSize > n*w || squareSize > n*h) n++; + } + if(n == 1.) pngBoardBitmap[kind] = img; else { + // create scaled-up copy of the raw png image when it was too small + cairo_surface_t *cs = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, n*w, n*h); + cairo_t *cr = cairo_create(cs); + pngBoardBitmap[kind] = cs; textureW[kind] *= n; textureH[kind] *= n; + cairo_scale(cr, n, n); + cairo_set_source_surface (cr, img, 0, 0); + cairo_paint (cr); + cairo_destroy (cr); + } } } } @@ -381,9 +402,9 @@ CreatePNGPieces () } void -CreateAnyPieces () +CreateAnyPieces (int p) { // [HGM] taken out of main - CreatePNGPieces(); + if(p) CreatePNGPieces(); CreatePNGBoard(appData.liteBackTextureFile, 1); CreatePNGBoard(appData.darkBackTextureFile, 0); } @@ -399,7 +420,7 @@ InitDrawingParams (int reloadPieces) if(svgPieces[i][p]) rsvg_handle_close(svgPieces[i][p], NULL); svgPieces[i][p] = NULL; } - CreateAnyPieces(); + CreateAnyPieces(1); } // [HGM] seekgraph: some low-level drawing routines (by JC, mostly) diff --git a/draw.h b/draw.h index 517e067..537cb1b 100644 --- a/draw.h +++ b/draw.h @@ -61,7 +61,7 @@ extern int lineGap, squareSize; // defined in draw.c void CreateGCs P((int redo)); -void CreateAnyPieces P((void)); +void CreateAnyPieces P((int p)); void CreatePNGPieces P((void)); void CreateGrid P((void)); void DrawSegment P((int x, int y, int *lastX, int *lastY, int p)); diff --git a/gtk/xboard.c b/gtk/xboard.c index 4daec27..40e41c8 100644 --- a/gtk/xboard.c +++ b/gtk/xboard.c @@ -1182,7 +1182,7 @@ main (int argc, char **argv) marginH = h - a.height - hc; // subtract current clock height, so it can be added back dynamically } - CreateAnyPieces(); + CreateAnyPieces(1); CreateGrid(); if(appData.logoSize) diff --git a/xaw/xboard.c b/xaw/xboard.c index b9fb0e1..a557b41 100644 --- a/xaw/xboard.c +++ b/xaw/xboard.c @@ -1288,7 +1288,7 @@ main (int argc, char **argv) CatchDeleteWindow(shellWidget, "QuitProc"); - CreateAnyPieces(); + CreateAnyPieces(1); CreateGrid(); if(appData.logoSize) -- 1.7.0.4