X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=draw.c;h=3bd646552e80df25d7e42d9e9af002d76eb86bc6;hb=54fc63f1e8ea41966f47d2b60b616db0a9c5010d;hp=8f7b546afc6aed86a4a6f882bd3b46c161333135;hpb=1d141d619141de1c5ceb976683cf856eb58bba75;p=xboard.git diff --git a/draw.c b/draw.c index 8f7b546..3bd6465 100644 --- a/draw.c +++ b/draw.c @@ -111,6 +111,7 @@ extern char *getenv(); #define OUTLINE 1 Boolean cairoAnimate; static cairo_surface_t *csBoardWindow, *csBoardBackup, *csDualBoard; +static cairo_surface_t *pngPieceImages[2][(int)BlackPawn+4]; // png 256 x 256 images 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 cairo_surface_t *pngBoardBitmap[2]; @@ -255,8 +256,8 @@ ConvertPixmap (int color, int piece) for(i=0; isize; i++) { for(j=0; jsize; j++) { @@ -277,7 +278,6 @@ ScaleOnePiece (char *name, int color, int piece) char buf[MSG_SIZ]; cairo_surface_t *img, *cs; cairo_t *cr; - static cairo_surface_t *pngPieceImages[2][(int)BlackPawn+4]; // png 256 x 256 images if((img = pngPieceImages[color][piece]) == NULL) { // if PNG file for this piece was not yet read, read it now and store it if(!*appData.pngDirectory) img = ConvertPixmap(color, piece); else { @@ -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 @@ -321,9 +339,15 @@ CreateAnyPieces () } void -InitDrawingParams () +InitDrawingParams (int reloadPieces) { + int i, p; MakeColors(); + if(reloadPieces) + for(i=0; i<2; i++) for(p=0; p