diff options
Diffstat (limited to 'tk/generic/tkCanvPs.c')
-rw-r--r-- | tk/generic/tkCanvPs.c | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/tk/generic/tkCanvPs.c b/tk/generic/tkCanvPs.c index 18ffd3ab6fb..e950b8dc4d1 100644 --- a/tk/generic/tkCanvPs.c +++ b/tk/generic/tkCanvPs.c @@ -23,6 +23,20 @@ */ /* + * The following definition is used in generating postscript for images + * and windows. + */ + +typedef struct TkColormapData { /* Hold color information for a window */ + int separated; /* Whether to use separate color bands */ + int color; /* Whether window is color or black/white */ + int ncolors; /* Number of color values stored */ + XColor *colors; /* Pixel value -> RGB mappings */ + int red_mask, green_mask, blue_mask; /* Masks and shifts for each */ + int red_shift, green_shift, blue_shift; /* color band */ +} TkColormapData; + +/* * One of the following structures is created to keep track of Postscript * output being generated. It consists mostly of information provided on * the widget command line. @@ -458,12 +472,13 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) /* * Insert the prolog */ - Tcl_AppendResult(interp, Tcl_GetVar(interp,"::tk::ps_preamable",TCL_GLOBAL_ONLY), (char *) NULL); + Tcl_AppendResult(interp, Tcl_GetVar(interp,"::tk::ps_preamable", + TCL_GLOBAL_ONLY), (char *) NULL); + if (psInfo.chan != NULL) { Tcl_Write(psInfo.chan, Tcl_GetStringResult(interp), -1); Tcl_ResetResult(canvasPtr->interp); } - /* *----------------------------------------------------------- @@ -1098,6 +1113,12 @@ GetPostscriptPoints(interp, string, doublePtr) * data passed as an argument, and should work for all Visual * types. * + * This implementation is bogus on Windows because the colormap + * data is never filled in. Instead all postscript generated + * data coming through here is expected to be RGB color data. + * To handle lower bit-depth images properly, XQueryColors + * must be implemented for Windows. + * * Results: * Returns red, green, and blue color values in the range * 0 to 1. There are no error returns. @@ -1107,6 +1128,15 @@ GetPostscriptPoints(interp, string, doublePtr) * *-------------------------------------------------------------- */ +#ifdef WIN32 +#include <windows.h> + +/* + * We could just define these instead of pulling in windows.h. + #define GetRValue(rgb) ((BYTE)(rgb)) + #define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8)) + #define GetBValue(rgb) ((BYTE)((rgb)>>16)) +*/ static void TkImageGetColor(cdata, pixel, red, green, blue) @@ -1114,19 +1144,31 @@ TkImageGetColor(cdata, pixel, red, green, blue) unsigned long pixel; /* Pixel value to look up */ double *red, *green, *blue; /* Color data to return */ { + *red = (double) GetRValue(pixel) / 255.0; + *green = (double) GetGValue(pixel) / 255.0; + *blue = (double) GetBValue(pixel) / 255.0; +} +#else +static void +TkImageGetColor(cdata, pixel, red, green, blue) + TkColormapData *cdata; /* Colormap data */ + unsigned long pixel; /* Pixel value to look up */ + double *red, *green, *blue; /* Color data to return */ +{ if (cdata->separated) { int r = (pixel & cdata->red_mask) >> cdata->red_shift; int g = (pixel & cdata->green_mask) >> cdata->green_shift; int b = (pixel & cdata->blue_mask) >> cdata->blue_shift; - *red = cdata->colors[r].red / 65535.0; + *red = cdata->colors[r].red / 65535.0; *green = cdata->colors[g].green / 65535.0; - *blue = cdata->colors[b].blue / 65535.0; + *blue = cdata->colors[b].blue / 65535.0; } else { - *red = cdata->colors[pixel].red / 65535.0; + *red = cdata->colors[pixel].red / 65535.0; *green = cdata->colors[pixel].green / 65535.0; - *blue = cdata->colors[pixel].blue / 65535.0; + *blue = cdata->colors[pixel].blue / 65535.0; } } +#endif /* *-------------------------------------------------------------- @@ -1218,7 +1260,6 @@ TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) else cdata.color = 1; - XQueryColors(Tk_Display(tkwin), cmap, cdata.colors, ncolors); /* @@ -1241,8 +1282,7 @@ TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) * Postscript interpreter). */ - switch (level) - { + switch (level) { case 0: bytesPerLine = (width + 7) / 8; maxWidth = 240000; break; case 1: bytesPerLine = width; maxWidth = 60000; break; case 2: bytesPerLine = 3 * width; maxWidth = 20000; break; @@ -1323,9 +1363,7 @@ TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), &red, &green, &blue); sprintf(buffer, "%02X", (int) floor(0.5 + 255.0 * - (0.30 * red + - 0.59 * green + - 0.11 * blue))); + (0.30 * red + 0.59 * green + 0.11 * blue))); Tcl_AppendResult(interp, buffer, (char *) NULL); lineLen += 2; if (lineLen > 60) { @@ -1340,7 +1378,7 @@ TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) * Finally, color mode. Here, just output the red, green, * and blue values directly. */ - for (xx = x; xx < x+width; xx++) { + for (xx = x; xx < x+width; xx++) { TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), &red, &green, &blue); sprintf(buffer, "%02X%02X%02X", |