X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=draw.c;h=20553e258bd8ba3521ac0ae6b16a8066a4919f7f;hb=8c8feabe34a974805b243ca3c9268e3ec296d6cb;hp=8f7b546afc6aed86a4a6f882bd3b46c161333135;hpb=1d141d619141de1c5ceb976683cf856eb58bba75;p=xboard.git diff --git a/draw.c b/draw.c index 8f7b546..20553e2 100644 --- a/draw.c +++ b/draw.c @@ -255,8 +255,8 @@ ConvertPixmap (int color, int piece) for(i=0; isize; i++) { for(j=0; jsize; j++) { @@ -299,6 +299,24 @@ ScaleOnePiece (char *name, int color, int piece) cairo_set_source_surface (cr, img, 0, 0); cairo_paint (cr); cairo_destroy (cr); + { // operate on bitmap to color it (king-size hack...) + int stride = cairo_image_surface_get_stride(cs)/4; + int *buf = (int *) cairo_image_surface_get_data(cs); + int i, j, p; + sscanf(color ? appData.blackPieceColor+1 : appData.whitePieceColor+1, "%x", &p); // replacement color + cairo_surface_flush(cs); + for(i=0; i> 24; r = c >> 16 & 255; // alpha and red, where red is the 'white' weight, since white is #FFFFCC in the source images + f = (color ? a - r : r)/255.; // fraction of black or white in the mix that has to be replaced + buf[i*stride + j] = c & 0xFF000000; // alpha channel is kept at same opacity + buf[i*stride + j] += ((int)(f*(p&0xFF0000)) & 0xFF0000) + ((int)(f*(p&0xFF00)) & 0xFF00) + (int)(f*(p&0xFF)); // add desired fraction of new color + if(color) buf[i*stride + j] += r | r << 8 | r << 16; // details on black pieces get their weight added in pure white + } + cairo_surface_mark_dirty(cs); + } } void