From 7eb38fea596969878a33f30e36fe33b125f9c4bd Mon Sep 17 00:00:00 2001 From: dos-reis Date: Sun, 2 Sep 2007 21:56:58 +0000 Subject: * XSpadFill.c: New. Replace corresponding pamphlet. * XSpadFill.c.pamphlet: Remove. * XShade.c: New. Replace corresponding pamphlet. * XShade.c.pamphlet: Remove. * XDither.c: New. Replace corresponding pamphlet. * XDither.c.pamphlet: Remove. * wct.c: New. Replace corresponding pamphlet. * wct.c.pamphlet: Remove. * util.c: New. Replace corresponding pamphlet. * util.c.pamphlet: Remove. * spadcolors.c: New. Replace corresponding pamphlet. * spadcolors.c.pamphlet: Remove. * sockio-c.c: New. Replace corresponding pamphlet. * sockio-c.c.pamphlet: Remove. * prt.c: New. Replace corresponding pamphlet. * prt.c.pamphlet: Remove. * pixmap.c: New. Replace corresponding pamphlet. * pixmap.c.pamphlet: Remove. * openpty.c: New. Replace corresponding pamphlet. * openpty.c.pamphlet: Remove. * hash.c: New. Replace corresponding pamphlet. * hash.c.pamphlet: Remove. * halloc.c: New. Replace corresponding pamphlet. * halloc.c.pamphlet: Remove. * fnct_key.c: New. Replace corresponding pamphlet. * fnct_key.c.pamphlet: Remove. * edin.c: New. Replace corresponding pamphlet. * edin.c.pamphlet: Remove. * bsdsignal.c: New. Replace correponding pamphlet. * bsdsignal.c.pamphlet: Remove. * cursor.c: New. Replace corresponding pamphlet. * cursor.c.pamphlet: Remove. * cfuns-c.c: New. Replace corresponding pamphlet. * cfuns-c.c.pamphlet: Remove. --- src/lib/XSpadFill.c | 300 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+) create mode 100644 src/lib/XSpadFill.c (limited to 'src/lib/XSpadFill.c') diff --git a/src/lib/XSpadFill.c b/src/lib/XSpadFill.c new file mode 100644 index 00000000..71e6f16b --- /dev/null +++ b/src/lib/XSpadFill.c @@ -0,0 +1,300 @@ +/* + Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* + This file contains the routines needed in order to dither using the + spadcolors. The routines will have names such as XSpadFill, ... The user + simply gives the normal arguments as with the corresponding XFill routine, + with two additional arguments which choose the shade and the hue. + + The file will maintain twoGC's: stippleGC - will be used when stippling the + backgrounds. solidGC - will be used when the background should be solid + + The user should call XSpadInit to get everthing going. This routine has the + job of Initializing the dithering routines, and getting the colors all + into place. + + */ + + +#include "axiom-c-macros.h" +#ifndef MSYSplatform + +#include +#include + +#include +#include +#include +#include +#include + +#include "spadcolors.h" + +#include "XSpadFill.H1" +#include "XShade.H1" +#include "XDither.H1" +#include "spadcolors.H1" + +extern unsigned long *spadColors; +static GC stippleGC, solidGC; +Colormap cmap; +int SpadFillInit = 0; +long white, black; +int max_spad_shades; +extern Display *dsply; + +extern int totalHues; +extern int totalDithered; +extern int totalSolid; +extern int totalShades; +extern int totalColors; +extern int maxGreyShade; + +int +XInitSpadFill(Display *dsply, int scr, Colormap * mapOfColors, int * hues, + int *solid, int * dithered, int * shades) +{ + int maxDither; + XColor BlackColor, WhiteColor; + XColor retColor; + int maxSolid; + + SpadFillInit = 1; + + + /* + * First thing I should do is get the GC's + */ + stippleGC = XCreateGC(dsply, RootWindow(dsply, scr), 0, NULL); + solidGC = XCreateGC(dsply, RootWindow(dsply, scr), 0, NULL); + XSetArcMode(dsply, solidGC, ArcPieSlice); + XSetArcMode(dsply, stippleGC, ArcPieSlice); + + + cmap = DefaultColormap(dsply, scr); + *mapOfColors = cmap; + XAllocNamedColor(dsply, cmap, "Black", &BlackColor, &retColor); + XAllocNamedColor(dsply, cmap, "White", &WhiteColor, &retColor); + black = BlackColor.pixel; + white = WhiteColor.pixel; + + /* + * Now I check to see if I am on a monochrome display. If so then I + * simply set totalHues to be one, and total Shades to be 2. I also have + * to allocate balck and white colors. This I put into the first two + * memory locations of spadcolors. + * + * was if(DisplayPlanes(dsply, scr) < 2) changed temporarily to < 8 + * because of problems with screens with 4 planes . Now if we don't have + * 8 planes to play with we switch to monochrome + */ + + if (DisplayPlanes(dsply, scr) < 8) { + *dithered = totalDithered = maxGreyShade = XInitShades(dsply, scr); + maxDither = *dithered - 1; + spadColors = (unsigned long *) malloc(2 * sizeof(unsigned long)); + spadColors[0] = BlackColor.pixel; + spadColors[1] = WhiteColor.pixel; + *hues = totalHues = 1; + *solid = totalSolid = 2; + *shades = totalColors = totalShades = totalDithered; + return (totalColors); + } + + /* + * Now I have to get all the spad colors as every good spad program + * should Now I should initialize the dithering routines + */ + + *dithered = totalDithered = + XInitDither(dsply, scr, stippleGC, black, white); + maxDither = *dithered - 1; + + if ((maxSolid = makeColors(dsply, scr, &cmap, &spadColors, &totalSolid)) > 0) { + *solid = totalSolid + 2; + *hues = totalHues = maxSolid / totalSolid; + *shades = totalShades = (totalSolid + 1) * (totalDithered - 1) + 1; + totalColors = totalHues * totalShades; + return (totalColors); + } + else { + + /* + * makeColors managed to fail -- switch to mono + */ + *dithered = totalDithered = maxGreyShade = XInitShades(dsply, scr); + maxDither = *dithered - 1; + spadColors = (unsigned long *) malloc(2 * sizeof(unsigned long)); + spadColors[0] = BlackColor.pixel; + spadColors[1] = WhiteColor.pixel; + *hues = totalHues = 1; + *solid = totalSolid = 2; + *shades = totalColors = totalShades = totalDithered; + return (totalColors); + } +} + + +void +XSpadFillSetArcMode(Display *dsply, int mode) +{ + XSetArcMode(dsply, solidGC, mode); + XSetArcMode(dsply, stippleGC, mode); +} + +GC +SpadFillGC(Display *dsply,int hue, int theshade,char * fill_routine) +{ + int dither; + int color; + + + if (!SpadFillInit) { + fprintf(stderr, "Tried to use SpadFillGC before calling XInitSpadFill\n"); + exit(0); + } + + if (theshade >= totalShades) { + fprintf(stderr, "Shade %d out of range\n",theshade); + exit(-1); + } + if (hue >= totalHues) { + fprintf(stderr, "Error Hue %d is out of range\n",hue); + exit(-1); + } + dither = ((theshade) % (totalDithered - 1)); + if (dither != 0) { + XChangeDither(dsply, stippleGC, dither); + if (theshade < totalDithered) { /* Dither to black */ + color = totalSolid * hue; + XSetForeground(dsply, stippleGC, black); + XSetBackground(dsply, stippleGC, spadColors[color]); + } + else if (theshade > (totalShades - totalDithered)) { /* Dither to white */ + color = ((theshade) / (totalDithered - 1)) + totalSolid * hue - 1; + XSetForeground(dsply, stippleGC, spadColors[color]); + XSetBackground(dsply, stippleGC, white); + } + else { + color = ((theshade) / (totalDithered - 1)) + totalSolid * hue - 1; + XSetForeground(dsply, stippleGC, spadColors[color]); + XSetBackground(dsply, stippleGC, spadColors[color + 1]); + } + return (stippleGC); + } + else { + if (theshade == 0) + XSetForeground(dsply, solidGC, black); + else if (theshade == (totalShades - 1)) + XSetForeground(dsply, solidGC, white); + else { + color = ((theshade) / (totalDithered - 1)) + totalSolid * hue - 1; + XSetForeground(dsply, solidGC, spadColors[color]); + } + return (solidGC); + } + +} + +unsigned long +XSolidColor(int hue, int theshade) +{ + if (hue >= totalHues) + return -1; + if (theshade >= totalSolid) + return -1; + return (spadColors[hue * (totalSolid) + theshade]); +} + +void +XSpadFillRectangle(Display *dsply, Drawable drawable, int x, int y, + unsigned int width, unsigned int height, + int hue, int theshade) +{ + + XFillRectangle(dsply, drawable, + SpadFillGC(dsply, hue, theshade, "XSpadFillRectangle"), + x, y, width, height); + +} + + +void +XSpadFillRectangles(Display *dsply, Drawable drawable, + XRectangle * rectangles, int nrectangles, + int hue, int theshade) +{ + + + XFillRectangles(dsply, drawable, + SpadFillGC(dsply, hue, theshade, "XSpadFillRectangle"), + rectangles, nrectangles); + +} + + +void +XSpadFillPolygon(Display *dsply, Drawable drawable, XPoint * points, + int npoints, int shape, int mode, int hue, int theshade) +{ + XFillPolygon(dsply, drawable, + SpadFillGC(dsply, hue, theshade, "XSpadFillRectangle"), + points, npoints, shape, mode); + +} + +void +XSpadFillArc(Display *dsply, Drawable drawable, int x, int y, + unsigned int width, unsigned int height, + int angle1, int angle2, int hue, int theshade) +{ + + XFillArc(dsply, drawable, + SpadFillGC(dsply, hue, theshade, "XSpadFillRectangle"), + x, y, width, height, angle1, angle2); +} + + +void +XSpadFillArcs(Display *dsply, Drawable drawable,XArc *arcs, int narcs, + int hue, int theshade) +{ + XFillArcs(dsply, drawable, + SpadFillGC(dsply, hue, theshade, "XSpadFillArcs"), + arcs, narcs); +} + + +#endif /* MSYSplatform */ + -- cgit v1.2.3