Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setgray and color

Status
Not open for further replies.

flash3433

Programmer
Mar 16, 2004
18
First question:

I know how to use setgray to print a dim or lightweight version of a word, but how can I do the same lightweight effect for a color word? Using setgray ignores the color and makes it gray.

Thanks

Philip Levine
 
There are lots of color operators. The two simplest are setrgbcolor and setcmykcolor.

"setrgbcolor" needs three numbers on the stack, each a decimal between 0 and 1, representing the Red, Green and Blue components.

"setcmykcolor" needs four numbers on the stack, each a decimal between 0 and 1, representning the Cyan, Magenta, Yellow, and Black components.

There are other color models corresponding to other color theories.

If you want solid, "100% red", you would perform:

1 0 0 setrgbcolor

then if you wanted "50% red" you would perform:

.5 0 0 setrgbcolor

And of course you mix the colors in any ratio to create any shade or tone:

.4 .4 1 setrgbcolor = Tek-Tips blue!



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Thanks. That seemed so obvious I wondered why I never thought of it.

However, when I tried it, the results were that the lower I made my number (say .30 0.0 0.0 setrgbcolor) the darker and muddier the color got. The opposite of what I was looking for.

I am looking for greater transparency, just as a .8 setgray gives.
 
It depends on the color model/theory. RGB refers to transmitted light. The more light you transmit (a number closer to 1) the "brighter" the color. If you transmit a very small amount of light, then the darker the color. Transmit nothing, you get black.

1 1 1 setrgbcolor = white.

The CMYK color model is built on the idea of reflected/absorbed light off of a white substrate. So if you have 0 0 0 0 setcmykcolor, you aren't absorbing any light, so it all gets reflected, leaving you with "white".

1 1 1 1 setcmykcolor = black (full absorption).



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
So is there any way to control actual opacity/transparency using postscript?

Obviously there must be if Mac OS X has transparent windows and uses postscript.
 
No, PostScript does not support transparency.

.8 setgray does NOT create "80% opacity". It creates a completely opaque ink that is a mixture of 20 parts white to 80 parts black.

Any application that prints a page with overlapping boxes where the colors appear transparent is creating the effect of transparency by laying down solid colors. An optical illusion, if you will.

In regard to OS X, I found this description "Native MacOS X applications use Quartz, which provides the basic PostScript imaging model plus transparency."

PDF 1.4 supports alpha transparency, so perhaps we'll see this work itself backwards into PostScript.



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
If I cannot use opacity can I use a dot pattern fill easily to simulate it like setgray does?

How can I setrgbcolor and then fill with colored dots?

I tried looking first and got nowhere.

Thanks
 
Ok, maybe I misled you with my description of ".8 setgray".

All colors in PostScript are completely solid, 100% opaque colors. If you lay down a solid red, and then print an "80% gray" rectangle on top of it, you will NOT see any red "showing through" the gray. The gray is a single solid color of a shade that is 80% black.

How the output device chooses to build a color that is 80% of a solid black tint is up to the output device. Most achieve a grayscale effect by altering, not the number of dots printed, but the size of them. And if the PostScript interpreter sees that a red patch is covered by a gray patch, it won't even render the "underlying" red patch.

All of that said, PostScript DOES have both a Pattern fill mechanism and a mask/stencil mechanism. Look up the "imagemask" operator and "Pattern Dictionary" in the PostScript Language Reference Manual.

But the key point here is that colors are solid. If you want to mix red and green to produce yellow, then use

"1 1 0 setrgbolor"

You are specifying SOLID 100% yellow, and if the ouput device is a CMYK device, as most are, it will use big yellow dots to render it. If viewing on a monitor, it will alternate shooting red and green light at the tube to create the optical illusion of yellow... but to PostScript, it's just a single solid color.

If you want a lighter shade, then you could do ".5 .5 0 setrbgcolor", or any other combination to create any other color.



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top