/* 
 * CSBwraps.psw
 *
 * (c) Copyright 1993-1994 Adobe Systems Incorporated.
 * All rights reserved.
 * 
 * Permission to use, copy, modify, distribute, and sublicense this software
 * and its documentation for any purpose and without fee is hereby granted,
 * provided that the above copyright notices appear in all copies and that
 * both those copyright notices and this permission notice appear in
 * supporting documentation and that the name of Adobe Systems Incorporated
 * not be used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.  No trademark license
 * to use the Adobe trademarks is hereby granted.  If the Adobe trademark
 * "Display PostScript"(tm) is used to describe this software, its
 * functionality or for any other purpose, such use shall be limited to a
 * statement that this software works in conjunction with the Display
 * PostScript system.  Proper trademark attribution to reflect Adobe's
 * ownership of the trademark shall be given whenever any such reference to
 * the Display PostScript system is made.
 * 
 * ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
 * ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
 * ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NON- INFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO EVENT SHALL ADOBE BE LIABLE
 * TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  ADOBE WILL NOT
 * PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
 * 
 * Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
 * Incorporated which may be registered in certain jurisdictions
 * 
 * Author:  Adobe Systems Incorporated
 */

defineps _DPSCColormapMatch(DPSContext ctxt; int colormap | boolean *match)
    currentXgcdrawablecolor	% gc draw x y [....colormap...]
    10 get colormap eq match    % gc draw x y
    pop pop pop pop
endps

defineps _DPSCTriangle(DPSContext ctxt; double h, w)
    newpath
    0 0 moveto
    w 0 rlineto
    0 h rlineto
    closepath
    fill
endps

defineps _DPSCShowFillMe(DPSContext ctxt; char *str)
    /Helvetica-Bold 12 selectfont
    2 5 moveto
    0 setgray
    (str) show
endps

defineps _DPSCShowMessage(DPSContext ctxt; char *str)
    1 setgray
    0 0 1000 1000 rectfill
    /Helvetica-Bold 12 selectfont
    10 2 moveto
    0 setgray
    (str) show
endps

defineps _DPSCRGBBlend(DPSContext ctxt; double x, y, width, height;
		       char *function; int steps)
    gsave
    x y translate
    width steps div
    0 1 steps 1 sub {
	steps div (function) cvx exec setrgbcolor
	dup 0 0 3 -1 roll height rectfill
	dup 0 translate
    } for
    pop
    grestore
endps

defineps _DPSCHSBBlend(DPSContext ctxt; double x, y, width, height;
		       char *function; int steps)
    gsave
    x y translate
    width steps div
    0 1 steps 1 sub {
	steps div (function) cvx exec sethsbcolor
	dup 0 0 3 -1 roll height rectfill
	dup 0 translate
    } for
    pop
    grestore
endps

defineps _DPSCCMYKBlend(DPSContext ctxt; double x, y, width, height;
			char *function; int steps)
    gsave
    x y translate
    width steps div
    0 1 steps 1 sub {
	steps div (function) cvx exec setcmykcolor
	dup 0 0 3 -1 roll height rectfill
	dup 0 translate
    } for
    pop
    grestore
endps

defineps _DPSCGrayBlend(DPSContext ctxt; double x, y, width, height;
			char *function; int steps)
    gsave
    x y translate
    width steps div
    0 1 steps 1 sub {
	steps div (function) cvx exec setgray
	dup 0 0 3 -1 roll height rectfill
	dup 0 translate
    } for
    pop
    grestore
endps

defineps _DPSCGetInvCTM(DPSContext ctxt; | float invctm[6])
    matrix currentmatrix matrix invertmatrix invctm
endps

defineps _DPSCDoRGBColorPalette(DPSContext ctxt; char *func;
				double red, green, blue; double width, height;
				int steps | boolean *success)
    mark {
	gsave
	0 0 translate
	width steps div
	0 1 steps 1 sub {
	    steps div red green blue 4 -1 roll func setrgbcolor
	    dup 0 0 3 -1 roll height rectfill
	    dup 0 translate
	} for
	pop
	grestore
    } stopped not success cleartomark
endps

defineps _DPSCDoCMYKColorPalette(DPSContext ctxt; char *func;
				 double cyan, magenta, yellow, black;
				 double width, height;
				 int steps | boolean *success)
    mark {
	gsave
	0 0 translate
	width steps div
	0 1 steps 1 sub {
	    steps div cyan magenta yellow black 5 -1 roll func setcmykcolor
	    dup 0 0 3 -1 roll height rectfill
	    dup 0 translate
	} for
	pop
	grestore
    } stopped not success cleartomark
endps

defineps _DPSCDoHSBColorPalette(DPSContext ctxt; char *func;
				double hue, sat, bright;
				double width, height;
				int steps | boolean *success)
    mark {
	gsave
	0 0 translate
	width steps div
	0 1 steps 1 sub {
	    steps div hue sat bright 4 -1 roll func sethsbcolor
	    dup 0 0 3 -1 roll height rectfill
	    dup 0 translate
	} for
	pop
	grestore
    } stopped not success cleartomark
endps

defineps _DPSCDoGrayColorPalette(DPSContext ctxt; char *func;
				 double gray; double width, height;
				 int steps | boolean *success)
    mark {
	gsave
	0 0 translate
	width steps div
	0 1 steps 1 sub {
	    steps div gray exch func setgray
	    dup 0 0 3 -1 roll height rectfill
	    dup 0 translate
	} for
	pop
	grestore
    } stopped not success cleartomark
endps


defineps _DPSCDoRGBPalette(DPSContext ctxt; char *func;
			   double width, height;
			   int steps | boolean *success)
    mark {
	gsave
	0 0 translate
	width steps div
	0 1 steps 1 sub {
	    steps div func setrgbcolor
	    dup 0 0 3 -1 roll height rectfill
	    dup 0 translate
	} for
	pop
	grestore
    } stopped not success cleartomark
endps

defineps _DPSCDoCMYKPalette(DPSContext ctxt; char *func;
			    double width, height;
			    int steps | boolean *success)
    mark {
	gsave
	0 0 translate
	width steps div
	0 1 steps 1 sub {
	    steps div func setcmykcolor
	    dup 0 0 3 -1 roll height rectfill
	    dup 0 translate
	} for
	pop
	grestore
    } stopped not success cleartomark
endps

defineps _DPSCDoHSBPalette(DPSContext ctxt; char *func;
			   double width, height;
			   int steps | boolean *success)
    mark {
	gsave
	0 0 translate
	width steps div
	0 1 steps 1 sub {
	    steps div func sethsbcolor
	    dup 0 0 3 -1 roll height rectfill
	    dup 0 translate
	} for
	pop
	grestore
    } stopped not success cleartomark
endps

defineps _DPSCDoGrayPalette(DPSContext ctxt; char *func;
			    double width, height;
			    int steps | boolean *success)
    mark {
	gsave
	0 0 translate
	width steps div
	0 1 steps 1 sub {
	    steps div func setgray
	    dup 0 0 3 -1 roll height rectfill
	    dup 0 translate
	} for
	pop
	grestore
    } stopped not success cleartomark
endps

defineps _DPSCQueryRGBColorPalette(DPSContext ctxt; char *func;
				   double pct, red, green, blue; |
				   float *redOut, *greenOut, *blueOut;
				   boolean *success)
    mark {
	red green blue pct func
    } stopped dup not success {0 0 0} if
    blueOut greenOut redOut cleartomark
endps

defineps _DPSCQueryCMYKColorPalette(DPSContext ctxt; char *func;
				    double pct, cyan, magenta, yellow, black; |
				    float *cyanOut, *magentaOut, *yellowOut,
				    *blackOut; boolean *success)
    mark {
	cyan magenta yellow black pct func
    } stopped dup not success {0 0 0 0} if
    blackOut yellowOut magentaOut cyanOut cleartomark
endps

defineps _DPSCQueryHSBColorPalette(DPSContext ctxt; char *func;
				   double pct, hue, sat, bright; |
				   float *hueOut, *satOut, *brightOut;
				   boolean *success)
    mark {
	hue sat bright pct func
    } stopped dup not success {0 0 0} if
    brightOut satOut hueOut cleartomark
endps

defineps _DPSCQueryGrayColorPalette(DPSContext ctxt; char *func;
				    double pct, gray; |
				    float *grayOut; boolean *success)
    mark {
	gray pct func
    } stopped dup not success {0} if
    grayOut cleartomark
endps


defineps _DPSCQueryRGBPalette(DPSContext ctxt; char *func; double pct; |
			      float *redOut, *greenOut, *blueOut;
			      boolean *success)
    mark {
	pct func
    } stopped dup not success {0 0 0} if
    blueOut greenOut redOut cleartomark
endps

defineps _DPSCQueryCMYKPalette(DPSContext ctxt; char *func; double pct; |
			       float *cyanOut, *magentaOut, *yellowOut,
			       *blackOut; boolean *success)
    mark {
	pct func 
    } stopped dup not success {0 0 0 0} if
    blackOut yellowOut magentaOut cyanOut cleartomark
endps

defineps _DPSCQueryHSBPalette(DPSContext ctxt; char *func; double pct; |
			      float *hueOut, *satOut, *brightOut;
			      boolean *success)
    mark {
	pct func
    } stopped dup not success {0 0 0} if
    brightOut satOut hueOut cleartomark
endps

defineps _DPSCQueryGrayPalette(DPSContext ctxt; char *func; double pct; |
			       float *grayOut; boolean *success)
    mark {
	pct func
    } stopped dup not success {0} if
    grayOut cleartomark
endps

