home *** CD-ROM | disk | FTP | other *** search
- Producing Animations on IBM PC's and PS 2's
-
- by Viktor K. Decyk, Physics Department
- and Joan Slottow, OAC
-
- A. Introduction
-
- The ability to animate graphics on personal computers is an
- important visualization tool which can lead to new
- scientific insights and discoveries. Much of science
- involves dynamics in time and the human eye is a marvelous
- tool for recognizing patterns in time. When animating data,
- one sees details and patterns one never notices in the still
- pictures. Animation also allows a researcher to examine
- more data more quickly. To use animation as a discovery
- tool, it need not be fancy, just simple and easy to do. It
- is very handy to carry these movies around on diskettes and
- pop them into a PC to show someone. If needed, a videotape
- can be used to show the animation to a larger audience, such
- as a conference session. Such a videotape can easily be made of
- a computer animation using the equipment in UCLA's
- Visualization Demonstration Laboratory.
-
- Viktor Decyk, of the UCLA plasma physics simulation group, has
- created a library of Fortran subroutines that produce a file
- of compressed raster images, which may then be sent to a
- personal computer for rapid playback. Joan Slottow of OAC
- has added routines that allow existing raster images to be
- compressed and has added compressed raster image for the IBM
- PC to the output formats that can be produced by the CGM to
- Raster program, thus allowing graphics created by DISSPLA
- and SAS/GRAPH to be displayed as both stills and movies on
- IBM PCs.
-
- The software for playing these movies is written by the
- National Energy Supercomputer Center (NERSC) at Lawrence
- Livermore National Laboratory and currently runs on IBM PCs
- (Ref. 1,2). Versions for Suns and Macintoshes will be
- available soon. The IBM PC version supports three formats:
- 4-color CGA (320x200 pixels), monochrome EGA (640x350
- pixels), and 256-color VGA (320x200 pixels). We have given
- this program to the MIC for distribution along with the
- documentation from NERSC.
-
- There are several ways to create the compressed movie files:
-
- - One way is to use the portable Fortran graphics library
- described in a previous Perspective article (Ref. 3). This
- library contains nine general-purpose graphics subroutines,
- six of which are line drawing routines and three of which
- are contouring routines.
-
- - Alternatively, you could run DISSPLA or SAS/GRAPH, both
- of which are large graphics packages, and create your
- graphics in a CGM metafile. You could then run the
- program CGM to Raster to create the compressed movie
- file. CGM to Raster was described in (Ref. 4) and an
- update on it appears in this issue of Perspective.
-
- - If you happen to have raw raster images from another
- source, these can also be compressed into compressed
- movie files.
-
- - Finally, you can create a compressed movie file by rasterizing
- a file of Tektronix commands. Again, this allows you to use
- another software package to create the images, since
- many graphics packages, such as DISSPLA, can create
- Tektronix files as output (Ref. 5).
-
- The compressed movie file is sent from whatever computer it
- was created on (in this case the IBM 3090) to your PC for
- playback, using either Y-Term (which can be slow) or, if
- your PC is on the network, FTP. In either case you must use
- binary transfer mode.
-
- There is no limit to the length of the movie files you can
- create, because the software from NERSC that reads the movie
- files and displays the movies reads the frames from disk as
- it displays them. However, you might want to limit yourself
- to movies which will fit on a diskette, since that makes
- them easily transportable.
-
- When reading a compressed movie file from a hard disk,
- speeds of 18, 12, and 6 frames per second are typical for
- EGA, CGA, and VGA respectively, with slower speeds when
- reading directly from diskette.
-
- B. Calling the Routines in Viktor Decyk's Fortran Graphics Library
-
- This library of subroutines was initially developed for use
- in an interactive plasma simulation program. It includes six
- X-Y plotting subroutines: GRAF2, GRAF1, GRAF3, DISP, DISP1,
- and DISP2, and three contour-plotting subroutines: CONTUR,
- DISPCN, and DSPCN2. The subroutine library, as written by
- Viktor, supports numerous graphics output devices. The
- subroutine library as installed at OAC includes only IBM PC
- compressed movie output. Viktor distributes the entire
- library to interested parties. See Reference 3.
-
- The subroutines and their arguments are:
-
- CALL GRAF2( y, labely, x, labelx, n, chr, ncr, irc )
-
- Produces a line plot of Y versus X, which fills the maximum
- area of the display region.
-
- CALL GRAF1( y, labely, ymax, ymin, x, labelx, xmax, mxim, n,
- chr, ncr, irc )
-
- Produces a scattergram (point plot) of Y versus X with
- the maximum and minimum values of the display region
- given by YMAX, YMIN, XMAX, and XMIN.
-
- CALL GRAF3( f, labely, x, labelx, n, m, nv, chr, ncr, irc )
-
- Produces M line plots of subarrays of F versus X. Each
- plot contains N points. The total graphic fills the
- maximum area of the display region.
-
- CALL DISP( f, label, xmin, xmax, n, m, nv, isc, chr, ncr, irc )
-
- Produces M line plots of subarrays of F versus a
- linear function in x, where XMIN < x < XMAX. A common
- scale given by YMAX = 2**ISC, YMIN = -2**ISC is used
- for the Y-axis. If ABS(ISC) > 116, the program finds
- the minimum value of ISC which will contain the plots.
-
- CALL DISP1( f, label, xmin, xmax, n, m, nv, isc, ist, chr, ncr, irc )
-
- DISP1 is similar to DISP except that it includes an
- additional parameter IST. If IST > 0, then YMIN = 0 is
- used for the common scale, while if IST < 0, then YMAX
- = 0 is used for the common scale. If IST = 0, then
- DISP1 functions exactly as DISP.
-
- CALL DISP2( f, label, xv, xmin, xmax, n, m, nv, isc, chr, ncr, irc )
-
- DISP2 is similar to DISP, except that only two
- subarrays are plotted, the first as a line plot and
- the second as a set of small closed circles. In
- addition, a vertical line at location x = XV is drawn.
-
- CALL CONTUR( f, link, label, n, m, nc, nv, chr, ncr, irc )
-
- Produces a contour plot of the function F, for values
- of the first index in the range 1 < i < N, and of the
- second index 1 < j < M. NC contour intervals are
- chosen, spaced equally between the maximum and minimum
- values of F.
-
- CALL DISPCN( f, link, label, n, m, nc, nv, isc, chr, ncr, irc )
-
- DISPCN is similar to CONTUR, except that the NC contour
- intervals are chosen equally spaced between FMAX = 2**ISC
- and FMIN = -2**ISC. If ABS(ISC) > 116, then the program
- finds the minimum value of ISC which will contain the
- function values.
-
- CALL DSPCN2( f, link, label, xv, yv, n, m, nc, nv, isc, chr, ncr,
- irc )
-
- DSPCN2 is similar to DISPCN, except that a pair of
- vertical and horizontal lines are drawn at x = XV and
- y = YV, where the units are 0 < x < N and 0 < y < M.
-
- Where:
-
- Y, X, and F
-
- are real arrays of dimension:
-
- y( n ), x( n ), f( nv, m )
-
- LINK
-
- is a logical*1 array of dimension:
-
- link( 2, n, m )
-
- LABELY, LABELX, and LABEL
-
- are character*20 labels.
-
- CHR
-
- is a character*128 label, of which
- NCR characters are to be printed on
- the plot. When NCR = 0, none
- of the characters in CHR are printed.
-
- IRC
-
- is always returned to you as 0.
-
-
- Before the first plot, your program must initiate graphics with:
-
- CALL GOPEN
-
- In addition, a common block:
-
- COMMON /PLOTCM/ IPLOT, NPLOT, IDTYPE
-
- needs to be declared at the beginning of the main program,
- and you should set the variable NPLOT to the desired number
- of plots per frame of the movie. IPLOT is used to control
- the position of each individual plot in the frame, and is
- not usually set by the user.
-
- After the last plot, your program must terminate the graphics with:
-
- CALL GCLOSE
-
- Also, you must open a file on Fortran Logical Unit Number 19
- to contain the compressed movie. This must be allocated as a
- card-image dataset. You can use a DD statement such as the
- following to define this dataset:
-
- //GO.ddname DD DSN=aaaaiii.name,UNIT=DATA,DISP=(NEW,CATLG),
- // DCB=CARD,SPACE=(TRK,(p,s),RLSE)
-
- By default, the output is generated in the IBM PC VGA (256-color)
- format. To produce output in either the 4-color CGA or for monochrome
- EGA format, you have to provide an input parameter on SYSIN as
- follows:
-
- Format Input Parameter
- CGA 1
- EGA 2
- VGA 3
-
- For example, to get CGA mode code:
-
- //GO.SYSIN DD *
- 1
-
- Each execution of a call to one of the graphics subroutines
- produces a complete plot. It takes NPLOT calls to the
- subroutines to fill one frame of the movie.
-
- Example 1:
-
- This sample program makes a simple test movie of a traveling
- sine wave. The 250-frame movie created by this test program
- occupies 553K bytes in 4-color CGA mode, 667K bytes in
- monochrome EGA mode, and 757K bytes in 256 color VGA mode.
-
- PROGRAM MOVIET
- PARAMETER(NX=128)
- COMMON /PLOTCM/ IPLOT, NPLOT, IDTYPE
- CHARACTER*128 CHR
- CHARACTER*20 CHP
- DIMENSION F(NX)
- 91 FORMAT (8H TIME = ,F7.2)
- DATA NLOOP,NCURVE,ISC,NCR /250,1,0,15/
- DATA FREQ,DT /1.,.2/
- DATA CHP /' POTENTIAL'/
-
- C OPEN OUTPUT DEVICE FOR RASTER FILE
-
- OPEN(UNIT=19,FILE='MGRAPH',FORM='FORMATTED',STATUS='UNKNOWN')
-
- C CALCULATE CONTANTS
-
- DNX = 6.2831853/FLOAT(NX)
- XMIN = 0.
- XMAX = FLOAT(NX - 1)
-
- C NPLOT = NUMBER OF GRAPHS PER PAGE
-
- NPLOT = 1
-
- C OPEN GRAPHICS
-
- CALL GOPEN
-
- C MAIN TIME LOOP
-
- DO 20 I = 1, NLOOP
- TIME = DT*FLOAT(I - 1)
- WT = FREQ*TIME
-
- C CALCULATE NEW FUNCTION VALUES
-
- DO 10 J = 1, NX
- F(J) = COS(2.*DNX*FLOAT(J - 1) - WT)
- 10 CONTINUE
-
- C DISPLAY FUNCTION
-
- WRITE (CHR,91) TIME
- CALL DISP (F,CHP,XMIN,XMAX,NX,NCURVE,NX,ISC,CHR,NCR,IRC)
- IF (IRC.EQ.1) GO TO 30
-
- 20 CONTINUE
-
- C CLOSE GRAPHICS
-
- 30 CALL GCLOSE
- STOP
- END
-
- C. Creating a Movie from images in a CGM Clear Text Metafile
-
- The program CGM to Raster has been updated to allow you to specify
- CGA, EGA, or VGA as one of the output file types. See the article
- on CGM to Raster also appearing in this issue.
-
- D. Creating a Movie from Raw Raster Images
-
- You can call Subroutines in the Fortran Graphics library
- that create a compressed movie file from raw raster images.
- Such a movie can contain any number of frames.
-
- You can create a compressed movie file out of a single image
- for display on an IBM PC and then tell the Movie software
- from NERSC to single-step through the movie. You will see
- the image displayed until you press Return.
-
- The NERSC software allows you to control the speed at which movies
- are displayed so that you can play them slow or fast.
-
- Your raw-raster image should be placed in a CHARACTER*1 matrix:
-
- raster( x,y )
-
- Where x is the number of columns in the image and y is the number
- of rows.
-
- The raw-raster image must be of one of these three types:
-
- Type Description
- 1-bit Each pixel is represented in the low-order 1 bit of
- each character (byte) the 7 high-order bits are
- unused. A low-order 0 bit represents the background
- color. A low-order 1 bit represents the drawing
- color.
- 2-bits Each pixel is represented in the low-order 2 bits of
- each character (byte). The other 6 bits are unused.
- 00 represents the background color. 01, 10, and 11
- are the drawing colors.
- 8-bits All the bytes of each pixel are used, giving 256 colors
- from 0 through 255. An 8-bit raster can also be
- accompanied by a color lookup table (CLUT).
-
- If the PC display mode with which the movie is to be
- displayed has at least as many bits as the raw-raster
- images, the images are simply compressed into the movie
- file. If, however, the PC display mode with which the movie
- is to be displayed has fewer bits than the raw-raster
- images, the images are filtered to reduce the number of
- colors.
-
- IBM PC Format Number of bits
- CGA 2
- EGA 1
- VGA 8
-
- For example, an 8-bit raster image has to be filtered to be displayed
- on a CGA display; a 2-bit raster image does not.
-
- Four filters are:
-
- Filter Description
- 0 For EGA, the low-order 1 bit of each byte is used.
- For CGA, the low-order 2 bits of each byte are used.
- 1 All 0 pixels are mapped to the background color. All
- non-0 pixels are mapped to the drawing color.
- 2 Thresholding is used. For EGA, all pixel values less
- than (max-min)/2 are mapped to the background color.
- All other pixel values are mapped to the drawing color.
- Where max is the largest pixel value in the raster image
- and min is the smallest. For CGA, all pixel values falling
- within the lowest fourth are mapped to the background
- color, pixel values in the next fourth are mapped to
- magenta, in the next fourth to cyan, and in the highest
- fourth to white.
- 3 Dithering is used. Dithering is a process by which
- colors are replaced by dots. For a monochrome image,
- areas of darker color are replaced by densely clustered
- dots and areas of light color are replaced by sparse
- dots. For EGA, white dots on a black background result
- from the dithering process. For CGA, the result of
- dithering depends upon whether a CLUT is supplied
- by the user or if the default CLUT is used.
- Each pixel value is looked up on the CLUT to
- determine its red, green, and blue component.
- These are dithered and combined into a
- resultant picture with the following mapping:
- red is mapped to magenta
- green is mapped to cyan
- blue is mapped to cyan
- yellow is mapped to white
- magenta is mapped to magenta
- cyan is mapped to cyan
- white is mapped to white
- black is mapped to the background
- The default CLUT maps pixels values as follows:
- 0 black
- 1 blue
- 2 green
- 3 cyan
- 4 red
- 5 yellow
- 6 magenta
- 7 white
- 8-255 black
-
- Filters 0 and 1 work well when the raw-raster image contains a line
- drawing. Filters 2 and 3 work well for colored in images.
-
- The following CALLs are required to create a compressed movie file:
-
- CALL GMOPEN( iout, clut, ncolors )
-
- Initiates the graphics.
-
- CALL COMPRG( raster, nx, ny, ixdim, nbits, ifilter, iflip )
-
- Compresses a single raw-raster image as a frame of the movie.
-
- CALL GCLOSE
-
- Terminates the graphics.
-
- Where:
-
- IOUT
-
- should be set to 1 for CGA, 2 for EGA, or 3 for VGA output.
-
- CLUT
-
- is a CHARACTER*1 color lookup table of 0 to 256 entries.
- If you are not supplying a color lookup table, you must still
- provide some sort of dummy argument here. If you are supplying
- a color lookup table, dimension it as 3 times the number of
- entries (768 max), initialize it as follows: CLUT(1) = red value
- for the first entry, CLUT(2) = green value for the first
- entry, CLUT(3) = blue value for the first entry, CLUT(4) =
- red value for the second entry, etc. Each value should range
- form 0 (no color) to 255 (maximum color).
-
- NCOLORS
-
- should be set to the number of entries in CLUT. Set NCOLORS = 0
- if you are not supplying a color lookup table (and are supplying
- a dummy argument instead).
-
- RASTER
-
- is the CHARACTER*1 matrix of dimension:
-
- raster( ixdim, ny )
-
- containing the raw-raster image.
-
- IXDIM, NY
-
- are the dimensions of RASTER
-
- NX
-
- is the number of columns to select from the raster image.
- See the discussion of the raster image size below.
-
- NBITS
-
- is the number of significant bits in the raw-raster image:
- 1, 2, or 8.
-
- IFILTER
-
- is the filter you want to be used. If the output format, EGA,
- CGA, or VGA has at least as many bits as the raw-raster image
- (NBITS), IFILTER is ignored.
-
- IFLIP
-
- set IFLIP to 0 if the image is right side up in RASTER and
- to 1 if it is upside down.
-
- In addition, you must open a file on Fortran Logical Unit
- Number 19 to contain the compressed movie. This must be
- allocated as a card-image dataset.
-
- The maximum number of pixels that can be displayed on the IBM PC
- screen depends upon the display type:
-
- Type X Y
- EGA 640 350
- CGA 320 200
- VGA 320 200
-
- Images smaller than the display size are padded with the background
- color. Images larger than the display size are truncated on the
- right and the bottom.
-
- For images larger that the display size, you can use the
- RASTER, NX, NY, and IXDIM parameters to select a subsection
- of the image to compress into the movie file.
-
- For example when a specific 500x387 image is displayed on VGA,
- only the upper right portion is visable. However, since both the
- left and the top of the image contain a considerable amount of
- the background color, it is desired that a different portion of the
- image be displayed.
-
- CALL COMPRG( raster, 320, 387, 500, nbits, ifilter, iflip )
-
- This selects the leftmost 320 columns out of the 500 and is
- equivalent to what you would get by setting NX to 500 and
- allowing the image to be truncated.
-
- CALL COMPRG( raster(181,1), 320, 387, 500, nbits, ifilter, iflip )
-
- This selects the rightmost 320 columns starting with column 181.
-
- CALL COMPRG(raster(181,188), 320, 200, 500, nbits, ifilter, iflip)
-
- This selects the rightmost 320 columns and the bottommost 200
- rows.
-
- Example 2:
-
- This example reads in 30 raw raster images and a CLUT and generates
- a compressed movie file.
-
- program rmovie
- parameter( nx=259, ny=218 )
- character*1 raster( nx, ny )
- character*1 clut( 768 )
-
- * ***********************************
- * OPEN OUTPUT DEVICE FOR RASTER FILE
- * ***********************************
-
- OPEN(UNIT=19,FILE='MGRAPH',FORM='FORMATTED',STATUS='UNKNOWN')
-
- * ***********************************
- * read the clut
- * ***********************************
-
- read( 1, 1 ) clut
- 1 format( 200a1, 56a1 )
- CALL GMOPEN( 1, clut, 256 )
-
- * ***********************************
- * read the raster image
- * ***********************************
-
- do 5 i = 1, 30
- do 3 iy = 1, ny
- read( 2, 2 ) ( raster( ix,iy ), ix = 1, nx )
- 2 format( 200a1, 200a1, 100a1 )
- 3 continue
-
- * ***********************************
- * put out the image
- * ***********************************
-
- CALL COMPRG( raster, nx, ny, nx, 8, 1, 0 )
-
- * ***********************************
- * bump the dataset sequence number
- * ***********************************
-
- read( 2, 2,end=5 ) ( raster( ix,iy ), ix = 1, nx )
- 5 continue
-
- CALL GCLOSE
-
- STOP
- END
-
- E. JCL required to use the Fortran Graphics Library
-
- //aaaaiiic JOB job-parameters
- // EXEC FORTCG,LIBB='APP1.PCMOVIE.LOAD'
- (Fortran Program)
- //GO.ddname19 DD DISP=(NEW,CATLG),DSN=aaaaiii.cmf,
- // DCB=CARD,UNIT=DATA,SPACE=(TRK,(p,s),RLSE)
- //GO.ddname DD dd-parameters
- //GO.SYSIN DD *
- n
-
- Where:
-
- aaaaiii
- is your Userid.
-
- c
- is an optional character to make the jobname unique.
-
- ddname19
- is your ddname for Fortran Logical Unit 19.
-
- aaaaiii.cmf
- is the dataset to contain the compressed movie file.
-
- p and s
- are the primary and secondary space requests for this dataset.
-
- //GO.ddname DD dd-parameters
- are any additional DD statements required by your program
- including those necessary to read in a color lookup table and
- raster images, if any.
-
- //GO.SYSIN DD * and n
- is required only when you are calling the graphics routines
- in the Fortran Graphics Library and want something other than
- the default VGA output.
-
- F. Creating a Movie from Textronix Files
-
- If you have already saved Textronix Files from some other source,
- Viktor will be happy to give you access to his software.
-
- G. Test Movie Player for the IBM 3179s
-
- You can preview the frames in your compressed movie file on the
- IBM 3179 terminals before transfering it to the PC. Logon to
- TSO and enter:
-
- PCMOVIE dsname
-
- H. References
-
-
- 1. Jean Shuler, "Kinetic Output for Viewing Your Graphics
- Files Dynamically on Your PC," NMFECC Buffer, Vol. 12, No.
- 6, p. 6 (1988).
-
- 2. MOVIE Document
- National Energy Supercomputer Center
- Lawrence Livermore National Laboratory
-
- 3. V. K. Decyk, "A Portable Fortran Graphics Library,"
- UCLA-OAC Perspective, vol. 14, No. 2, p. 16 (1990).
-
- 4. OAC Writeup MVS: Visualizing Supercomputer Scientific Data on
- Macintoshes (SG22)
-
- 5. V. K. Decyk and L. Xu, "Transmission of Graphics by
- Electronic Mail," UCLA-OAC Perspective, Vol. 11, No. 4, p.
- 30 (1987).
-
-