Question

How can my Postscript draw a monochrome (black/white) image embedded from an EPS file such that the black parts of the image are displayed at 50% value?


I have a monochrome EPS file which looks like this:

enter image description here

This image is embedded into a Postscript file, which then draws it. When drawn, I want the image to print or display such that the black parts of the image are drawn as a 50% gray, like this:

enter image description here

The EPS is embedded into the Postscript using the technique shown in https://stackoverflow.com/a/16405528/238886:

/ImageData
currentfile
<< /Filter /SubFileDecode
   /DecodeParms << /EODString (*EOD*) >>
>> /ReusableStreamDecode filter
[-->PUT YOUR EPS HERE<--]
*EOD*
def

/IDForm
<< /FormType 1
   /BBox [154 321 441 521]
   /Matrix [ 1 0 0 1 0 0]
   /PaintProc
   { pop
       /ostate save def
         /showpage {} def
         /setpagedevice /pop load def
         ImageData 0 setfileposition ImageData cvx exec
       ostate restore
   } bind
>> def

And drawn like this:

gsave
IDForm execform
grestore

Is there anything I can wrap around the execform to cause the black/white image to be printed/displayed at 50% value?

Was it helpful?

Solution

It really depends on what operations are used inside the EPS file. You could redefine for example setgray like this:

/setgray_orig /setgray load def
/setgray { 0.9 gt {1.0}{0.5} ifelse setgray_orig  } bind def

and then on exit redefine it like so:

/setgray /setgray_orig load def

Now this depends on setgray being used its possible that your eps is using sethsbcolor, setrgbcolor, setcmykcolor etc. if so then you should wrap those too. Be careful with this stuff.

Please note it is not enough to define all gray as 0.5 since someone might be painting white to fill areas so that has to be accounted for too.

Ammendum: you could also just define the setgray inisde the /ostate save def and ostate restore directives then you don't need to separately unload the functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top