[comp.lang.postscript] Getting 255 Grey Levels

jmr@nada.kth.se (Jan Michael Rynning) (03/23/89)

In article <1597@murdu.oz> rab@murdu.oz (Richard Alan Brown) writes:
>Firstly, according to the PostScript book (reference manual), the
>LaserWriter should produce 255 grey levels with the image operator if the
>correct parameters have been supplied. With the default settings, it
>seems that in fact you can only get 32 grey levels, yet inspection of the
>output suggests that the printer should be able to do much better than
>this. Reading the red book, it seems that the actual rendering of grey
>levels is done via the setscreen operator, which determines how pixels
>are filled in to acheive various levels from black to white.
>
>Has anyone out there figured out how to modify the default setscreen
>parameters to get 255 grey levels?

The default screen frequency is 60 dots/inch on an Apple LaserWriter,
which has a resolution of 300 pixels/inch.  300/60=5, so each screen
dot has a maximum size of 5 by 5 pixels.  Making all those 25 pixels
black, gives you a black printout.  Making 0 of them black, gives you
a white printout.  That means you can achieve 26 grey levels at this
screen frequency.  If you want more grey levels, you will either have
to lower the frequency or use a printer with a higher resolution.  As
you need at least 16 by 16 pixels to get 256 grey levels, the screen
frequency to use on the Apple LaserWriter is 300/16=19.

If you want to try this on your Apple LaserWriter, add the following
line to your PostScript program to set the screen frequency to 19:

currentscreen 3 -1 roll pop 19 3 1 roll setscreen

Jan Michael Rynning,			jmr@nada.kth.se
Department of Numerical Analysis	If you can't fully handle domains:
  and Computing Science,		ARPA: jmr%nada.kth.se@uunet.uu.net
Royal Institute of Technology,		UUCP: {uunet,mcvax,...}!nada.kth.se!jmr
S-100 44 Stockholm,			BITNET: jmr@sekth
Sweden.					Phone: +46-8-7906288

ath@helios.prosys.se (Anders Thulin) (03/24/89)

In article <1597@murdu.oz> rab@murdu.oz (Richard Alan Brown) writes:
>[ ... ]
>Has anyone out there figured out how to modify the default setscreen
>parameters to get 255 grey levels?

Perhaps it should be added that 255 grey levels aren't very useful for
human 'consumtion' - the eye can't distinguish between more than about
30-50 levels of grey.
-- 
Anders Thulin			INET : ath@prosys.se
ProgramSystem AB		UUCP : ...!{uunet,mcvax}!enea!prosys!ath
Teknikringen 2A			PHONE: +46 (0)13 21 40 40
S-583 30 Linkoping, Sweden	FAX  : +46 (0)13 21 36 35

robert@shangri-la.gatech.edu.gatech.edu (Robert Viduya) (03/24/89)

> Perhaps it should be added that 255 grey levels aren't very useful for
> human 'consumtion' - the eye can't distinguish between more than about
> 30-50 levels of grey.

Try creating a completely white to a completely black fade effect using only
30 levels of grey.  This effect is known as a fountain and using only 30 levels
of grey produces an ugly banding instead of the desired smooth transition.

			robert

--
Robert Viduya					   robert@shangri-la.gatech.edu
Office of Computing Services
Georgia Institute of Technology					 (404) 894-6296
Atlanta, Georgia	30332-0275

nad@tegra.UUCP (Nancy Durgin) (03/25/89)

In article <854@draken.nada.kth.se> jmr@nada.kth.se (Jan Michael Rynning)
writes:
>The default screen frequency is 60 dots/inch on an Apple LaserWriter,
>which has a resolution of 300 pixels/inch.  300/60=5, so each screen
>dot has a maximum size of 5 by 5 pixels.  Making all those 25 pixels
>black, gives you a black printout.  Making 0 of them black, gives you
>a white printout.  That means you can achieve 26 grey levels at this
>screen frequency.  If you want more grey levels, you will either have
>to lower the frequency or use a printer with a higher resolution.  As
>you need at least 16 by 16 pixels to get 256 grey levels, the screen
>frequency to use on the Apple LaserWriter is 300/16=19.
>

Actually, that's not quite right...

The LaserWriter screen frequency of 60 dots/inch is quoted for a 45
degree screen, and is only approximate.  If you actually measure it,
you'll find that it is more like 53 (measured along the diagonal). 
Since this is for a 45 degree angle, divide by sqrt(2)/2, which gives
75dpi along the horizontal, 300/75=4, so each screen dot is a maximum of
4 by 4 pixels.  But, since there are actually two dots to each tile
(think of the 50% gray level, with a white dot and a black dot next to each
other), this is actually a 8x4 grid.  Or, it's actually easier to
visualize as an 8x8 grid, where you add 2 dots for each gray level:

       So the 50% gray             XXXXOOOO
       pattern would               XXXXOOOO
       look like this:             XXXXOOOO
                                   XXXXOOOO
                                   OOOOXXXX
                                   OOOOXXXX
                                   OOOOXXXX
                                   OOOOXXXX

Counting 0 for all white, and 32 for all black, we get a total of
33 gray levels.

A 16x16 grid will yield only 128 (actually, 129) gray levels, and would
give you a 300/16 * sqrt(2) = 26.5 dot/inch screen.

There's not really a clean way to get 256 gray levels for a 45 degree
screen, since you'd need to use approximately a 23x23 grid
(sqrt(512) = 22.6).  The reason the LaserWriter uses the default screen
that it uses (53 dots/inch, 45 degree screen) is because it is easy (and
fast) to implement with 8-bit grids.

==============================================================================
Nancy Durgin           | (Usual disclaimers    | Tegra-Varityper, Inc.
tegra!nad@ulowell.edu  |  apply...)            | Billerica, Massachusetts
==============================================================================

stew@endor.harvard.edu (Stew Rubenstein) (03/25/89)

In article <854@draken.nada.kth.se> jmr@nada.kth.se (Jan Michael Rynning) writes:
>In article <1597@murdu.oz> rab@murdu.oz (Richard Alan Brown) writes:
>>Has anyone out there figured out how to modify the default setscreen
>>parameters to get 255 grey levels?
>
>The default screen frequency is 60 dots/inch on an Apple LaserWriter,
>which has a resolution of 300 pixels/inch.  300/60=5, so each screen
>dot has a maximum size of 5 by 5 pixels.  Making all those 25 pixels
>black, gives you a black printout.  Making 0 of them black, gives you
>a white printout.  That means you can achieve 26 grey levels at this
>screen frequency.  If you want more grey levels, you will either have
>to lower the frequency or use a printer with a higher resolution.  As
>you need at least 16 by 16 pixels to get 256 grey levels, the screen
>frequency to use on the Apple LaserWriter is 300/16=19.
>
>If you want to try this on your Apple LaserWriter, add the following
>line to your PostScript program to set the screen frequency to 19:
>
>currentscreen 3 -1 roll pop 19 3 1 roll setscreen

Sorry, it's not that simple.  The default screen on the laserwriter
is not at 90 degrees, so it's not a simple 5x5 box.  In fact, the
default screen is at 45 degrees, and has 32 dots, so you get 33 gray
levels.

To get more gray levels, you need a coarser screen.  To make matters
more complicated, you don't generally get the exact frequency and
screen angle you request, because it has to take the closest values
which are possible given the limited resolution of the printer.  For a
good discussion of this, see chapter 10 of "Real Word PostScript",
Stephen F. Roth, ed., Addison-Wesley, 1988.

Stew Rubenstein
Cambridge Scientific Computing, Inc.
UUCPnet:    seismo!harvard!rubenstein            CompuServe: 76525,421
Internet:   rubenstein@harvard.harvard.edu       MCIMail:    CSC