From hpfloat!marysue Fri Dec  4 11:59 MST 1987
Received: by hpfclw.HP.COM; Fri, 4 Dec 87 11:58:59 mst
Received: from hpfloat.HP.COM by hpfclw.HP.COM; Fri, 4 Dec 87 11:58:39 mst
Received: by hpfloat.HP.COM; Fri, 4 Dec 87 11:56:34 mst
Date: Fri, 4 Dec 87 11:56:34 mst
From: Mary Sue Rowan <hpfloat!marysue>
Return-Path: <hpfloat!marysue>
Message-Id: <8712041856.AA10286@hpfloat.HP.COM>
To: hpfloat!bayes
Status: R


                   PaintJet COLOR RASTER DUMP UTILITY
                    External Reference Specification
                             Mary Sue Rowan
                                12/4/87 

     This report describes support for PaintJet (HP3630A) in BASIC 5.1.
It consists of a CSUB utility for doing a color raster dump.  It is a
color equivalent of the DUMP GRAPHICS functionality.  There is no
"re-rasterization" of the picture (re-sizing in memory), although it is
possible to scale the picture to a certain page size by redefining hard
clip limits with the VIEWPORT statement.

I.  Form

    The CSUB has the form of

    CSUB GDUMP_COLORED(FROM_DS, TO_DS, 
           OPTIONAL ROTATE$, INTEGER RESOLUTION, BACKGROUND$, ALGORITHM$)

    A.  Parameters

	1.  FROM_DS is the device whose frame buffer will be dumped.
	    There is no default value; it is a required parameter.  It
	    does not have to be the current "PLOTTER IS" device.

	2.  TO_DS is the device (HPIB or RS232) address of the printer.
	    There is no default value; it is a required parameter.

	3.  ROTATE$ is an optional string parameter that has the possible
	    values of "NORMAL" and "ROTATE".  It determines whether the
	    image is to be rotated on the printed page.  The default value
	    is "NORMAL", or unrotated, meaning that the top of the screen
	    is oriented to the top of the printed page.

	4.  RESOLUTION is an optional integer parameter that corresponds
	    to the possible values of dot resolution for the device.  The
	    default value is 180 dots per inch (dpi).  The other available
	    value is 90 dpi.  If the parameter passed is greater than 90,
	    then 180 is selected.  Otherwise the value is taken to be 90.

	5.  BACKGROUND$ is an optional string parameter with possible
	    values of "ON" or "OFF".  The default value is "ON", meaning
	    that for color dumps, the background color (that assigned for
	    PEN 0) will be dumped.  "OFF" causes PEN 0 color to be
	    assigned white, and thus it will not be dumped.  This means
	    that all PEN 0 pixels will now be assigned white, even those
	    that may be integral parts of the picture, so care must be
	    taken in using this option.  It has no effect for dumps from
	    monochrome crt's.

	6.  ALGORITHM$ is an optional string parameter with possible
	    values of "DITHER" or "ERRDIF".  The default value is
	    "DITHER", meaning that the algorithm used to create the dump
	    employs dithering in a 2x2 dither cell.  Each pixel expands to
	    4 dots on the printed page.  "ERRDIF" causes the error
	    diffusion algorithm to be employed.  Only one dot per pixel is
	    output, so pictures are 1/4 the size of those printed with the
	    dithered method.

           
    B.  Use

        1.  User access:
            The CSUB can be loaded with 
                        
                         LOADSUB ALL FROM "GDUMP_C"
        
        2.  and called by, for example, 
         
                         CALL GDUMP_COLORED(25,702)            ! interactively 

            or,          Gdump_colored(CRT,701,"ROTATE", 90)   ! from a program
        
        3.  and deleted by
          
                         DELSUB GDUMP_COLORED
    
    C.  The utility will appear on the UTIL2 utility disc, and will be 
        approximately 11 Kbytes in size.
 
    D.  Considerations

        1.  Basic RESET

	    When a dump is interrupted by a BASIC reset, there is no way
	    of sending an "end raster graphics" escape code to the
	    printer.  This means that if there is graphics data in
	    PaintJet's buffer, it will not get flushed until the next time
	    the printer tries to write, so it could appear on the next
	    printout.  A way to avoid this is to either allow a dump to
	    complete normally, and thus have the proper escape sequences
	    sent to the printer, OR to cycle power on the printer before
	    starting the next dump.

	2.  Color selection

            a.  Dither algorithm:

		The color dump works by translating one pixel into a 2X2
		dither cell, thus printing 4 dots for every pixel.  This
		means that there are only 5 different intensity levels for
		each of red, green, and blue.  This strategy yields a
		maximum of 125 different colors that the PaintJet will
		print.  In order for PaintJet to tell the difference
		between two different colors, they must differ in at least
		one of the rgb components so that they fall into different
		intensity intervals for that component.

		The intervals are 0-12%, 13-37%, 38-62%, 63-87%, and
		88-100%.  In other words, two reds with r=.90, g=0, b=0
		and r=.95, g=0, b=0 will look the same to the driver, but
		a third one with an r=.85 will look different, because one
		less dot in the dither cell will be "turned on".

            b.  Error diffusion:

		This is much more sensitive to shading differences, and
		the potential difficulty described above should not arise.
		The color of a dot depends partially on the colors of dots
		around it, not solely on its absolute DAC value.  By
		"diffusion", we mean that some fractional DAC value is
		propagated to neighboring dots.  For more information, see
		references to the Floyd-Steinberg error distribution
		algorithm in _Procedural Elements for Computer Graphics_,
		by David F.  Rogers, McGraw-Hill, 1985.

	    c.  Comparison:

		With the dither algorithm (default), slight differences in
		shading will likely be lost because of the dithering
		technique used.  Workaround:

		1)  Make sure that colors requiring differentiation are at
		    least 20% different in their DAC values in the red,
		    green, or blue dimension, so that the driver will
		    cause them to be printed differently, or arrange the
		    DAC values so that they fall in different intervals
		    (given earlier).

		2) Use the error diffusion algorithm.

        3.  Clipping of image:

	    Presently, the maximum resolution screen is 1280 X 1024 pixels
	    (high resolution Catseye).  With the dither algorithm (da),
	    this would mean a dump of 2560 x 2048 dots.  The maximum width
	    of the PaintJet is 1440 dots (at 180 dpi), so even a rotated
	    dump of this screen will have some clipping (608 dots or about
	    30%).  With the error diffusion algorithm (eda), one dot per
	    pixel would be output, so the 1280 x 1024 screen would all fit
	    on a page, regardless of orientation.

            Suggestions to avoid clipping:

	    a.  If using the da and a high resolution monitor, rotate the 
                picture to get as much as possible on the page.  At the '
                same time, arrange the picture to have the most vital 
                parts of it (such as a title) a little farther down on the 
                screen (away from the top).

            b.  Rotate the picture, and use the following clip limits:
                1) Monitor resolution=1024 x 768
                   Use  VIEWPORT 0,124,0,93
                   and specify "ROTATE", 180 dpi, and "DITHER" algorithm.

                2) Monitor resolution=1280 x 1024
                   Use  VIEWPORT 0,95,0,70
                   and specify "ROTATE", 180 dpi, and "DITHER" algorithm.
                   OR (if you want to just fill the page) specify 
                   "ROTATE",90 dpi, and "ERRDIF" algorithm.
                
                For monitors of other resolutions, experiment with the
                VIEWPORT statement to find the one that works best for
                that situation. 
                
            c.  Use the error diffusion algorithm at 180 dpi.
                
        4.  Algorithm choice:

            When choosing between algorithms, it is important to understand
            what the objectives are for the image.  

            The dither algorithm

                - does single pixel-wide lines extremely well,
                - can miss slight differences in shading,
                - will provide a smoother-grained texture, and
                - will clip a high resolution screen image.

            The error diffusion algorithm

                - will muddy single pixel-wide lines,
                - will pick up shading differences very well, 
                - will provide a coarser-grained texture, and
                - will not clip a high resolution screen image (at the default
                    printer resolution of 180 dpi).


	    If the image has critical parts consisting of single
	    pixel-wide lines, such as a slide or graph, choose dithering
	    and appropriate clip limits (see below).  If color variation
	    is important to the image, choose error diffusion.


    E.  Performance

        1.  Cost of the driver:

	    To estimate how much overhead the driver was costing, a
	    program was written in BASIC to put data directly out to the
	    printer, without actually trying to dump the display device.
	    The program put out exactly the number of dotrows of the
	    correct length to simulate various displays at various resolu-
            tions.  Then the driver was used to dump the display.  The 
            computer used was a 310.  Displays were of resolutions 
            512 x 400 (mr), and 1024 x 768 (hr).  Because the dither 
            algorithm puts out 4 dots/pixel, and the error diffusion 
            algorithm only 1 dot/pixel, an attempt to correct for that is 
            to print at 90 dpi (which quadruples the dots) for eda.  
            These are unrotated dumps, HPIB only.  The RS232 printer 
            performs significantly slower.

	    Dither algorithm at 180 dpi (printer resolution):

                          no driver   driver
             
                  hr       4:19        6:51
                  mr       1:30        1:56







            Error diffusion algorithm:  

                          no driver   driver
                  dpi     180   90   180   90
             
                  hr      1:27 3:22  2:24 3:23  
                  mr      0:35 1:20  0:44 1:23 


	    These results show that printing at 90 dpi is faster than
	    printing the same size picture at 180 dpi.  They also show
	    that the error diffusion algorithm has an advantage.
	    Primarily, they show that there is a penalty for the driver
	    paid in both cases, but as the resolution of the display
	    increases, the overhead decreases for the error diffusion,
	    indicating that the mechanical limits of the printer are being
	    approached.


        2.  Performance limiters:

	    SPU speed seems to be the main limiter in performance for the
	    da, while the printer seems to be so for the eda.  The
	    following table shows comparisons of different SPU's and the
	    eda vs the da.

                 \  algorithm    error diff     dither     notes
                  \  dpi          180    90      180
              SPU  \      
              9836               0:43   1:21    1:53        68010 proc
               310               0:44   1:23    1:56        mr monitor
               320               0:33   1:21    1:29        mr monitor
               310               2:24   3:23    6:51        hr monitor
               350               1:23   3:23    3:57        hr monitor
               




