From a7395b43aa2a987286f027b7a729136b773ad6e1 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Thu, 21 Apr 2016 23:11:25 +0200 Subject: [PATCH] Limit prefilling with color to textures with alpha channel When loading and preparing a texture we now test the format, and if the image has an alpha channel we stay on the save side, and always color the squares before drawing the texture. Only when the format is not ARGB32 we skip the color fill. (And the default textures do not have an alpha channel, so at least there no time will be wasted on pointless color fills.) --- draw.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/draw.c b/draw.c index 5eb6baa..1d17314 100644 --- a/draw.c +++ b/draw.c @@ -269,7 +269,7 @@ ExposeRedraw (Option *graph, int x, int y, int w, int h) cairo_destroy(cr); } -static int modV[2], modH[2]; +static int modV[2], modH[2], transparency[2]; static void CreatePNGBoard (char *s, int kind) @@ -288,6 +288,7 @@ CreatePNGBoard (char *s, int 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); + transparency[kind] = cairo_image_surface_get_format (img) == CAIRO_FORMAT_ARGB32; n[kind] = 1.; modV[kind] = modH[kind] = -1; while((q = strchr(p+1, '-'))) p = q; // find last '-' if(strlen(p) < 11 && sscanf(p, "-%dx%d.pn%c", &f, &r, &c) == 3 && c == 'g') { @@ -754,11 +755,12 @@ DrawLogo (Option *opt, void *logo) static void BlankSquare (cairo_surface_t *dest, int x, int y, int color, ChessSquare piece, int fac) { // [HGM] extra param 'fac' for forcing destination to (0,0) for copying to animation buffer - int x0, y0; + int x0, y0, texture = (useTexture & color+1) && CutOutSquare(x, y, &x0, &y0, color); cairo_t *cr; cr = cairo_create (dest); + if(!texture || transparency[color]) // draw color also (as background) when texture could be transparent { // evenly colored squares char *col = NULL; switch (color) { @@ -772,7 +774,7 @@ BlankSquare (cairo_surface_t *dest, int x, int y, int color, ChessSquare piece, cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); cairo_fill (cr); } - if ((useTexture & color+1) && CutOutSquare(x, y, &x0, &y0, color)) { + if (texture) { cairo_set_source_surface (cr, pngBoardBitmap[color], x*fac - x0, y*fac - y0); cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); cairo_rectangle (cr, x*fac, y*fac, squareSize, squareSize); -- 1.7.0.4