Reputation: 1
I'm having a problem rendering a PS document to TIFF (or any raster format). Single pixels have a "shadow" rendered one pixel below. Is there any way to prevent this?
%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 0 0 10 10
<< /PageSize [10 10] >> setpagedevice
1 1 scale
/singlepx {
newpath
5 5 moveto
0 1 rlineto
1 0 rlineto
0 -1 rlineto
closepath
setrgbcolor
fill
} def
0.666 0.0 0.666 singlepx
Render command:
gs -dSAFER -dNOPAUSE -dBATCH -dFitPage -dGraphicsAlphaBits=4 \
-g10x10 -r600 -sDEVICE=tiffgray -sOutputFile=test.tif test.eps
The result is the same with the png and jpeg output devices.
EPS rendered in evince TIF produced by ghostscript
Upvotes: 0
Views: 265
Reputation: 31199
You've set GraphicsAlphaBits=4, this does 'anti-aliasing. The result of that is that every drawn object extends further out by several pixels, these pixels are composed with the background.
If you look closely at the Evince output you'll see that there is considerably more than a 'single pixel' rendered. The rectangulsr shape has a border around 3 sides, 1 pixel wide. The colour is the colour of the rectangle, 50% composed with the background. At the corners, these are composed twice, with the result that you get 25% of the colour.
If you want to draw to the pixel level you can't use GraphicsAlphaBits.
Note that you are not drawing to a single 'pixel' anyway. Your rectangle is one PostScript unit wide by 1 unit high. PostScript's units are 1/72 inch. So at 72 dpi yes, its 1 pixel, but rendered at 1440 dpi that's 20 pixels by 20 pixels.
[edit]
Well, I think the problem here is that you are using incompatible command line switches and PostScript controls. Firstly your EPS file isn't valid, because it contains a setpagedevice, that's not legal for an EPS.
Your command line sets the resolution to 600 dpi, and the output size to 10x10 pixels. At 600 dpi that makes the media size 1/60 inch square. However, you also set -dFitPage. What that does is intercept MediaSize requests from the incoming data stream, figures out what scale factor is needed to make the requested media fit on the actual media, and then scales the content so that it fits on the actual media size.
Because your 'EPS' sets a media size, Ghostscript is executing some scaling to make the requested 10x10 unit square fit into a 10x10 pixel square. Now both the -g and the -dFitPage are executing scaling operations, and there is a limit to the accuracy with which this is performed.
Further complicating the problem is the fact that the PostScript rendering rule is 'any part of pixel', so if the scaling/accuracy should happen to work out in such a way that the mapping from user space to device space doesn't precisely match the device space pixel grid, a pixel might be regarded as being (just barely) touched, and so will be rendered.
What is it you are actually trying to achieve ? It might be easier to address that than try to fix what you are currently doing.
Note that PostScript (unlike some other PDLs) doesn't let you address the device pixels at all, and you are (if I remember correctly) explicitly told that you can't reliably do so, either in the PLRM or one of the supporting books.
Upvotes: 1