Notes for Week 7

Our distribution uses lprng for printing, and the following is based on that. Another alternative for printing is CUPS.

  1. Print spooling is handled by lpd, the "line printer daemon". The sequence of events in printing is typically:

    1. A user sends print output (usually either postscript or plain text) to the print queue using the lpr command. The output, as well as a small control file, are placed in the queue directory (ie., /var/spool/lpd/lp for the queue named lp).
    2. lpd periodically scans the queue directory for work to do; when it finds some, it spawns a copy of itself to print the "job" and then terminate.
    3. The spawned lpd examines the print output, and filters it using the appropriate filter for the type of output it is and the type of printer it's destined for. For instance, a postscript file to a postscript printer needs no filtering, while a postscript file to a non-postscript printer must be filtered, usually by gs (ghostscript). A plain text file might need to be filtered if the file contains only newline characters and the printer requires line feed-carriage return pairs to start a new line at the leftmost column of the next line on the page (if this is not done, the output may be "stair-stepped"). The output of the filter is then passed to the appropriate driver:

      • local (parallel or USB) printer driver
      • TCP print protocol stack for a remote TCP printer
      • SMB protocol stack for a Windows print share
      • SPX protocol stack for a Novell print server
    4. The control and spooled data files are removed from the queue directory.
    The print queues are manipulated using the lpq (query), lpc (control) and lprm (remove) commands.
    Note that once a print job is sent to a networked printer, it often cannot be controlled from the host. This is especially irritating when the printer malfunctions.
  2. Both postscript and pdf (portable document format) files are text files whose contents contain a description of the print output using a device-independent programming language. Postscript files may be viewed before printing using gsview (ghostview), in order to verify WYSIWYG (What You See Is What You Get). pdf files may be viewed using xpdf.

    Note that emacs can print a file using postscript instead of plain text, and that the results are far superior to plain text printing.

  3. Printer Configuration - options of interest

      /etc/printcap (mandatory entries are asterisked)
      parametermeaningdefault value
      afaccounting file name (must be created manually)
      filterfilter script name
      filter_optionsfilter options(see man page)
      ldprinter initialization string
      lp*printer device name / remote print queue
      mcmaximum copies1
      mlminimum printable characters32
      mxmaximum job size in 1K blocks0 (unlimited)
      plpage length in lines66
      pwpage width in characters80
      rgrestrict users to these groups
      sd*spool directory (must be created manually)
      shsuppress headers / bannersfalse
      trprinter termination string
      All file and directory names should be fully qualified. Each printer must have a separate spool directory.

    • /etc/lpd/lpd.perms
      parametermeaning
      REJECT NOT SERVERdo not accept remote print jobs
      ACCEPT SERVICE=X REMOTEIP=(IP address)accept remote print jobs from this IP address
    • gs options (asterisked options are mandatory when used as an lpd filter)
      parametermeaning
      -_*read from stdin (must be last)
      -dBATCH*exit when finished
      -dNOPAUSE*do not pause between pages
      -dNOPROMPT*noninteractive use
      -dPARANOIDSAFER*do not allow access to anything but stdin and libraries
      -dQUIET*no status messages
      -hhelp - displays known devices
      -r(x pixels/inch)x(y pixels per inch)resolution
      -sDEVICE=*specify printer driver
      -sOutputFile=-*output to stdout
      -sPAPERSIZE=paper size name
    A sample printcap file and its associated filters might be:
    text
       :af=/var/spool/lpd/text/acct.log
       :filter=/root/bin/crlf
       :lp=lp@192.168.1.3
       :mc=0
       :mx=0
       :sd=/var/spool/lpd/text
       :sh
    
    ps
       :af=/var/spool/lpd/ps/acct.log
       :filter=/root/bin/post
       :lp=lp@192.168.1.3
       :mc=0
       :mx=0
       :sd=/var/spool/lpd/ps
       :sh
    

    #!/bin/sh
    #/root/bin/crlf
    awk 'BEGIN { ORS="\n\r" } { print }'
    

    #!/bin/sh
    #/root/bin/post
    gs -dBATCH -dNOPAUSE -dNOPROMPT -dPARANOIDSAFER -dQUIET -sDEVICE=ljet4 -r300x300 -sOutputFile=- -_
    
    A local printer would have a printcap entry such as ":lp=/dev/lp0".

    "gs -help" will display the available printer drivers.

  4. You should always use non-proprietary, industry standard formats for files to be shared with others. This means:
    for text, always use ASCII-encoded HTML (HyperText Markup Language) 3.2 or lower (not all browsers support higher level standards);

    for still images, use JPEG (Joint Picture Experts Group) - you can adjust the quality when you save the file, or you can use TIFF (Tagged Image File Format) or uncompressed GIF (Graphics Interchange Format) for line drawings if the JPEG artifacts get you down (compressed GIF is a proprietary format);

    for audio, use MP3 (MPEG Layer III Audio) - use 192 Kbps if quality is a concern; and

    for video, use MPEG (Motion Picture Experts Group) with a standard codec such as MPEG-1 (used for VCDs), MPEG-2 (used for DVDs) or MPEG-4.

    Endeavour2 has an image browser which is useful for viewing image files. For image manipulation you definitely have to try gimp.

    mplayer can be used to play virtually any format of sound or video, provided that it has been built for the specific format you're interested in. For movie viewing, the option "vo=x11" is nice. "mplayer --help" will display the basic key bindings available to control playback.

    There is a small problem with mplayer that prohibits the playing of video. We will fix this prpoblem in week 9.
  5. In order to compare file formats, a 26 second video was recorded and the following files prepared:

    • poem.avi (Audio Visual Interleave - 36629132 bytes) using the mjpeg (motion jpeg) codec at 29.97 frames per second and 320x240 (24 bits per pixel) resolution, with 11024 audio samples per second in 8 bit mono; avi files are essentially raw audio and video, and have a 2GB size limit;
    • poem.mpg (5988352 bytes) from the avi file, using the mpeg2 codec; output file size is highly dependent on both scene content and noise levels; processing time is roughly proportional to video length (approximately 8 times longer for mjpeg denoising and encoding to mpeg2 on an Athlon 2400+);
    • poem.wav (2292904 bytes) using 44100 samples per second in 8 bit stereo (16 bit stereo is considered CD quality); wav files are essentially raw pcm (pulse code modulation) with headers; note that the sound quality is not improved: you cannot make a silk purse out of a sow's ear;
      Several steps are necessary if you wish to use mplayer in the lab to play any of the audio files mentioned here:

      1. Download and run snddevices.in.
      2. modprobe snd-intel8x0
      3. Run alsamixer, un-muting the master volume and setting the volume.
    • poem.mp3 (416288 bytes) from the wav file, at 128K bits per second data rate; output file size and processing time are proportional to audio length;
    A still image of the poet was captured from the video and stored in a variety of formats:

    • poet.tiff (230692 bytes), essentially the uncompressed raw image at 24 bits per pixel; again note that this image comes from a jpeg original, and so the tiff quality is no better;
    • poet.jpg (12745 bytes), compressed at the default quality of 85%;
    • poet.gif (54358 bytes); notice the artifacts with enlargement;
    • poet.png (Portable Network Graphics - 112638 bytes);
    The poems themselves can be stored in a variety of ways:

    • poem.html (312 bytes) as ASCII-encoded text;
    • poem.ps (32733 bytes of postscript) as output using mozilla;
    • poem.pdf (7811 bytes) converted from the postscript;
    • poem.tiff (206554 bytes) captured at 72 pixels per square inch and 24 bits per pixel resolution;
    • poem.jpg (19632 bytes); notice the artifacts on enlargement;
    • poem.gif (5290 bytes);
    • poem.png (8096 bytes).
    Note that all of the compressed formats use lossy compression (some data is lost). Also note that by far the most efficient storage method is plain text.

  6. EXERCISES for Week 7:

    1. Implement the text print queue above in order to be able to print plain text files without "stair-stepping". Allow only the networking group members to print to it. Test it using "ls -1 | lpr -Ptext". Monitor the print job using 'lpq -a' and examine the accounting file after it has printed.


©2005, Kenneth R. Koehler. All Rights Reserved. This document may be freely reproduced provided that this copyright notice is included.

Please send comments or suggestions to the author.