Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!g.gp.cs.cmu.edu!fryd From: fryd@g.gp.cs.cmu.edu (Michael Fryd) Newsgroups: comp.lang.postscript Subject: Re: Thin line woes Message-ID: <10267@pt.cs.cmu.edu> Date: 16 Aug 90 14:40:22 GMT References: <10244@pt.cs.cmu.edu> Organization: Carnegie-Mellon University, CS/RI Lines: 75 In article <10244@pt.cs.cmu.edu> Tom Lane (tgl@zog.cs.cmu.edu) asks about the problems with line width variations and how to solve them. His example is that on a 300 dpi printer, a "0.12 setlinewidth" (1 /600th of an inch) sometimes results in lines which are 1 pixel thick, and sometimes results in lines which are two pixels thick. Common sense would lead one to believe that a request for a 1/2 pixel thick line would simply result in a 1 pixel thick line. The problem is PostScript's rendering algorithm. The algorithm works by computing the ideal (desired) image, and then turns on any pixel that is touched by the computed ideal image. (Some people feel that a better choice would have been to only turn on pixels that are more than half covered by the ideal image). If an ideal 1/2 pixel line lies completely in a line of pixels, then the printed page would have a 1 pixel thick line on it. If the ideal 1/2 pixel line happens to cover the boundary between two adjacent lines of pixels, then the printed page would have a 2 pixel line on it. Assuming a random distribution of line placement, a 1/2 pixel ideal line would print as a 1 pixel line half the time and a 2 pixel line half the time. The suggested solution in both "Real World PostScript" and the green book is to fine tune the positions of the ideal lines (by up to 1/2 pixel) to give a consistent relationship between line positions and the underlying device pixels. This consistent relationship insures that a particular line width will always image with consistent thickness. Various sources differ in suggesting exactly how to adjust the center of the ideal line to the device pixels. The common suggestions are: - align the ideal line to the center of the nearest pixel (.5) - align the ideal line to the nearest pixel boundary (.0) - align between the center and edge of the nearest pixel (.25) Each of these suggestions has advantages and disadvantages. If aligned to the center of the nearest pixel (.5) all lines will image at an odd number of pixels thick. The actual thickness will be the ideal thickness rounded up to the nearest odd number. ideal lines less than one pixel will image at exactly one pixel. Ideal lines from 1 to 3 will image at exactly 3 pixels. Assuming a random distribution of ideal line thickness, imaged lines will be about 1 pixel too big. If aligned to pixel boundaries (.0) all lines will image an even number of pixels thick. The actual thickness will be the ideal thickness rounded up to the nearest even number. Ideal lines less than 2 pixels thick will render at exactly 2 pixels. Ideal lines from 2.00001 to 4 will render at 4 pixels thick. Assuming a random distribution of ideal line thickness, imaged lines will be about 1 pixel too big. If aligned between the edge and center of the pixels, both odd and even thicknesses can be rendered. Ideal lines from 0 to .5 pixels will render at exactly one pixel. Ideal lines from .5 to 1.5 will render at 2 pixels thick, from 1.5 to 2.5 at 3 pixels, etc. The .25 method results the widest variety of line widths and the smallest maximum error (1.5 vs. 2 pixels), but it also results in the greatest minimum error (.5 vs. 0). I prefer the .25 solution because it allows a greater variety of line widths. If greater accuracy is desired, I suggest combining the .25 method with a patch to setlinewidth that reduces the requested line width by 1 pixel. The combination of the .25 method and the 1 pixel reduction results in: lines from 0 to 1.5 pixels image at 1 pixel. lines from 1.5 to 2.5 image at 2 pixels. lines from 2.5 to 3.5 image at 3, etc. Michael Fryd President Voice: (412) 751-5557 MEFCO, Inc. Fax: (412) 751-8403 2401 Coulter Road Email: Michael.Fryd@CS.CMU.EDU McKeesport, PA 15131-4251