home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / dos / imdisp / doc / imgprog.doc < prev    next >
Encoding:
Text File  |  1994-04-28  |  36.6 KB  |  884 lines

  1.  
  2.  
  3.         PROGRAMMERS MANUAL FOR IMAGE DISPLAY AND I/O ROUTINES
  4.  
  5.  
  6.     IMDISP is written in a modular way so that it is easy to change it
  7. to work with different display devices or on other computers. The code
  8. can also easily be adapted for use in other application programs.  There
  9. are device dependent image display modules, general image display
  10. subroutines, image I/O routines, and image label and command line
  11. parsing routines.  The general purpose display routines can draw lines,
  12. write text with different fonts, manipulate a cursor, interactively
  13. adjust the palette, display histograms, etc. The IMDISP system is
  14. written in the "C" computer langauge.
  15.  
  16.             Model of Device Independent Image Display
  17.  
  18.     The image display is modeled as having coordinates ranging from 1 to
  19. "dispnl" from top to bottom and from 1 to "dispns" from left to right
  20. (i.e. a line-sample space).  There is one image plane that can take on
  21. "numDN" values.  There is assumed to be a lookup table to convert those
  22. DN values into voltages for the red, green, and blue guns in the
  23. monitor.  There are "numshades" shades of each primary color for a total
  24. of numshades**3 different colors.  The palette is a table of numDN
  25. entries, with each entry containing the three primary color intensities
  26. on a scale from 0 to 255.
  27.  
  28.     There are five global variables that define the display
  29. characteristics and are set in the DISPDRIV module:  dispnl, dispns,
  30. numDN, numshades, OneScreen.  There are two related contants: MAXDISPNL
  31. and MAXDISPNS.
  32.  
  33. The cursor, text, and font global variables are in the DISPUTIL module.
  34. The image control block constants and variables are in the IMAGEIO
  35. module.
  36.  
  37.                 Compiling and Linking Routines
  38.  
  39.     This document describes the "C" language version of the IMDISP
  40. system.  The routines are written in Microsoft C version 5.1 on an IBM
  41. AT compatible computer.  The large memory module is used.  There is one
  42. module (dispsub.asm) written in 8086 assembly language for reasons of
  43. execution speed.
  44.  
  45. The following commands are are used to compile and link the subroutines
  46. and programs.  They are contained in the COMPLINK.BAT file.
  47.  
  48. cl /AL /c dispio.c disputil.c fileio.c fileutil.c imageio.c imagutil.c
  49. imdisp.c labutil.c memutil.c
  50.  
  51. masm dispsub.asm;
  52.  
  53. link/NOE imdisp+dispsub+dispio+disputil+fileio+filesel+imagutil+
  54. imageio+labutil+memutil/stack:8000/exepack;
  55.  
  56.  
  57.              LIST OF PROGRAMS
  58.  
  59. IMDISP.C     - Main program, help, command drivers.
  60. DISPIO.C     - Display on/off, read/write lines, pixels, palette.
  61. DISPUTIL.C   - Font, cursor, text and palette routines.
  62. DISPSUB.ASM  - Assembly language routines for EGA/PGA display.
  63. FILEIO.C     - MSDOS and CDROM file input/output routines.
  64. FILEUTIL.C   - File menu and wild card routines.
  65. IMAGEIO.C    - Image open/close/read routines.
  66. IMAGUTIL.C   - Palette, histogram, profile and stretch routines.
  67. LABUTIL.C    - Label parsing routines.
  68. MEMUTIL.C    - Special memory allocation routines (malloc/free).
  69.  
  70. -----------------------------------------------------------------
  71.  
  72.           Routines for image display
  73.  
  74.     Device dependant routines:
  75.  
  76. Module: DISPIO
  77.  
  78.  DisplayOn
  79.  DisplayOff
  80.  WritePalette (palette)
  81.  WritePixel (line, sample, DNvalue)
  82.  ReadPixel (line, sample, DNvalue)
  83.  DisplayLine (buffer, line, samp, ns)
  84.  ClearDisplay (DNvalue)
  85.  PutRefresh (buffer, line, ss, ns)
  86.  GetRefresh (buffer, line, ss, ns)
  87.  
  88.     Device independant routines:
  89.  
  90. Module: DISPUTIL
  91.  
  92. InitDisplay
  93. ReadPalette (palette)
  94. DrawLine (line1, sample1, line2, sample2, DNvalue)
  95. DrawBox (line, samp, linesize, sampsize, DNvalue)
  96.  
  97. RemoveCursor
  98. PlaceCursor (line, sample, DNvalue)
  99. MoveCursor (line, sample)
  100.  
  101. Font (FontType)
  102. DrawText (text, line, sample, height, angle, DNvalue)
  103. LengthText (text, height, TextLength)
  104. TypeText (text)
  105. TypeTextLine (text)
  106. AcceptText (string)
  107. WriteText (text)
  108.  
  109. Module: FILEUTIL
  110.  
  111. int FileSel(selFilename)
  112. int Wildexp(argc, argv)
  113.  
  114. Module: IMAGUTIL
  115.  
  116. DiddlePalette (numcolors)
  117. DisplayHistogram (histbuffer, numbins, minDN, maxDN)
  118. Stretch (DNlow, DNhigh : Integer);
  119. Profile
  120.  
  121.          Routines for image I/O
  122.  
  123. Module: IMAGEIO
  124.  
  125. OpenImage (filename, unit, IOmode, nl, ns, bitsperpix, status)
  126. ReadLine (unit, buffer, line, ss, ns, status)
  127. WriteLine (unit, buffer, line, ss, ns, status)
  128. CloseImage (unit, status)
  129. CheckStatus (status)
  130. ConvertLine (inbuffer, outbuffer, inbits, outbits, ns, status)
  131.  
  132.  
  133. Module: LABUTIL
  134.  
  135. GetLabelInteger (LabelBuf, Len, Keyword, default, value, flag)
  136. GetLabelReal (LabelBuf, Len, Keyword, default, value, flag)
  137. GetLabelString (LabelBuf, Len, Keyword, default, value, flag)
  138. InterpretLabel (LabelBuf, Len, labelsize, nline, nsamp, bitsperpix,
  139.                                reclen, lineheadbytes, DetachedFilename)
  140. MakeLabel (LabelBuf, labelsize, nline, nsamp, bitsperpix, reclen)
  141. Function GetCommand (CommandString, CommandList)
  142. GetKeywordInteger (CommandString, Keyword, default, value, flag)
  143. GetKeywordReal (CommandString, Keyword, default, value, flag)
  144. GetKeywordString (CommandString, Keyword, default, value, flag)
  145.  
  146.  
  147.         Block I/O routines
  148.  
  149. Module: FILEIO
  150.  
  151. OpenFile (filename, unit, IOmode, blocksize, status)
  152. ReadBlocks (unit, buffer, StartBlock, NumBlocks, BlocksRead, status)
  153. WriteBlocks (unit, buffer, StartBlock, NumBlocks, status)
  154. CloseFile (unit, status)
  155. InitializeCD (status)
  156. ReadBlocksCD (buffer, StartBlock, NumBlocks, status)
  157.  
  158.  
  159.              SUMMARY AND USE OF SUBROUTINES
  160.  
  161. /***    Module:    DISPIO
  162.  
  163.       DISPIO contains the device dependent display routines for
  164.       the Color Graphics Adapter (CGA), the Enhanced Graphics Adapter (EGA),
  165.       the Professional Graphics Adapter (PGA), and the Video Graphics Array
  166.       (VGA).  The global variables that define the device are allocated and 
  167.       initialized here.
  168. ***/
  169.  
  170. DisplayOn()
  171. /***  DisplayOn figures out which display device is on the system and
  172.       then initializes for that device.  The device is turned on.
  173.       The global variables that define the display characteristics
  174.       and the default color palette are initialized.  The refresh
  175.       buffer is zeroed.
  176. ***/
  177.  
  178. DisplayOff()
  179. /***  DisplayOff turns off the display device returning the screen
  180.       to text mode.
  181. ***/
  182.  
  183. WritePalette (coltab)
  184. /***  WritePalette updates the display device palette with the
  185.       palette passed in coltab.  coltab must be of type Color.
  186. ***/
  187.  
  188. WritePixel (line, sample, DN)
  189. /***  WritePixel writes a pixel on the display screen.
  190.       Parameter   type       description
  191.         line     integer     The line coordinate of the pixel
  192.         sample   integer     The sample coordinate of the pixel
  193.         DN       integer     The DN value of the pixel
  194. ***/
  195.  
  196. ReadPixel (line, sample, p_DN)
  197. /***  ReadPixel read a pixel value from the display screen.
  198.       Parameter   type       description
  199.         line     integer     The line coordinate of the pixel
  200.         sample   integer     The sample coordinate of the pixel
  201.         p_DN     int ptr     The DN value of the pixel is returned
  202. ***/
  203.  
  204. DisplayLine (buffer, line, sample, ns)
  205. /***  DisplayLine writes a line of pixels on the display screen.
  206.       Parameter   type       description
  207.         buffer   char ptr    The array of pixel values
  208.         line     integer     The line coordinate of the first pixel
  209.         sample   integer     The sample coordinate of the first pixel
  210.         ns       integer     The number of pixels to display
  211. ***/
  212.  
  213. ClearDisplay (DN)
  214. /***  ClearDisplay sets the whole display to a particular value.
  215.       Parameter   type       description
  216.         DN       integer     The DN value to set (usually 0)
  217. ***/
  218.  
  219. PutRefresh (buffer, line, ss, ns)
  220. /***  PutRefresh stores a line of pixels in the refresh buffer.
  221.       Parameter   type       description
  222.         buffer   char ptr    The array of pixel values
  223.         line     integer     The line coordinate of the first pixel
  224.         sample   integer     The sample coordinate of the first pixel
  225.         ns       integer     The number of pixels to store
  226. ***/
  227.  
  228. GetRefresh (buffer, line, ss, ns)
  229. /***  GetRefresh reads a line of pixels from the refresh buffer.
  230.       Parameter   type       description
  231.         buffer   char ptr    The receiving array of pixel values
  232.         line     integer     The line coordinate of the first pixel
  233.         sample   integer     The sample coordinate of the first pixel
  234.         ns       integer     The number of pixels to read
  235. ***/
  236.  
  237. --------------------------------------------------------------------------
  238.  
  239. /***  Module: DISPUTIL
  240.       Device Independant General Purpose Graphics Routines
  241.  
  242.     Includes line drawing, text display, and cursor routines.
  243.  
  244. ***/
  245.  
  246. InitDisplay()
  247. /*** InitDisplay turns the display device on, loads the default palette,
  248.     initializes the global variables, and loads the font arrays.
  249. ***/
  250.  
  251. ReadPalette (coltab)
  252. /***  ReadPalette returns the current color palette in coltab.
  253.       coltab is of type Color.
  254. ***/
  255.  
  256. DrawLine (x1, y1, x2, y2, color)
  257. /***  DrawLine draws a line of pixels from the first point to the
  258.     second point with the desired DN value.  Clipping is not performed.
  259.  
  260.        Parameter  Type   Description
  261.          x1       int    the line coordinate of the first point
  262.          y1       int    the sample coordinate of the first point
  263.          x2       int    the line coordinate of the second point
  264.          y2       int    the sample coordinate of the second point
  265.          color    int    the DN value of the drawn pixels
  266. ***/
  267.  
  268. DrawBox (line, samp, lsize, ssize, color)
  269. /*** DrawBox draws a solid rectangle on the screen.
  270.    Used for erasing parts of the screen.
  271.  
  272.     Parameter   Type     Description
  273.      line       int      starting line coordinate of rectangle
  274.      samp       int      starting sample coordinate of rectangle
  275.      lsize      int      number of lines in rectangle
  276.      ssize      int      number of samples in rectangle
  277.      color      int      the DN value to draw the box
  278. ***/
  279.  
  280. Font (FontType)
  281. /***  Font reads in the font file for type FontType and fills the
  282.     font arrays appropriately.  If FontType = 0 the internal font file
  283.     is used instead.  FontType = 5 reads in font file 005.FNT, etc.
  284.     The global variable thefont is set to the font number.
  285.  
  286.     The format of a font file is a sequence of bytes.  The first byte
  287.     is the number of characters defined in the font.  For each
  288.     character there is the following:  the ascii code, the number of
  289.     line strokes, the character width, and then the list of line strokes.
  290.     Each line stroke consists of three bytes: the pen motion, and the
  291.     x and y coordinate.  The width, x, and y values are converted
  292.     back into character coordinates by subtracting 50 and dividing
  293.     by 100.  The pen is 2 for pen down, and 3 for pen up.
  294. ***/
  295.  
  296. DrawText (text, line, sample, height, angle, DNvalue)
  297. /***  DrawText draws a text string on the display using the
  298.     current font.
  299.  
  300.     Parameter  Type     Description
  301.      text     char ptr  text string to display
  302.      line     int       line coordinate of lower left of first char
  303.      sample   int       sample coordinate of lower left of first char
  304.      height   int       height of characters in pixels
  305.      angle    int       angle in degrees ccw from positive sample direction
  306.      DNvalue  int       the DN value to draw the pixels in with
  307. ***/
  308.  
  309. LengthText (text, height, p_TextLength)
  310. /*** LengthText finds the length in pixels of a given text string.
  311.  
  312.     Parameter       Type     Description
  313.      text          char ptr   text string to display
  314.      height         int       height of characters in pixels
  315.      p_TextLength  int ptr    where to return length of string
  316. ***/
  317.  
  318. TypeText (TypeString)
  319. /***  TypeText displays a line of text on the screen at the current
  320.     text location with a height of 15 pixels.  The area is first erased.
  321.     The text position is advanced to the next position after the last
  322.     character.
  323.      Parameter       Type     Description
  324.      TypeString    char ptr   text string to display
  325. ***/
  326.  
  327. TypeTextLine (TypeString)
  328. /***  TypeTextLine displays a line of text on the screen using TypeText.
  329.     The text position is advanced to the beginning of the next line.
  330.      Parameter       Type     Description
  331.      TypeString    char ptr   text string to display
  332. ***/
  333.  
  334. AcceptText (AcceptString)
  335. /***  AcceptString gets a string from the keyboard.  The characters
  336.     are echoed on the display screen using DrawText.  The string is
  337.     terminated with a return (ascii 13).  Backspace deleting is supported.
  338.     The text position is left at the beginning of the next line.
  339.      Parameter       Type      Description
  340.      AcceptString    char ptr  returned text string from user
  341. ***/
  342.  
  343. WriteText (text)
  344. /***  WriteText writes out a line of text to the user.  If there
  345.     is only one screen then the text is written on the image display.
  346.     Otherwise it is written to the terminal.
  347.      Parameter     Type     Description
  348.      text        char ptr   text string to display
  349. ***/
  350.  
  351. RemoveCursor()
  352. /***  RemoveCursor removes the cursor, if it is on, from the display
  353.     screen, replacing the original pixel values.
  354. ***/
  355.  
  356. PlaceCursor (line, sample, cursDN)
  357. /***  PlaceCursor puts the cursor, if it is not already on, on the
  358.     screen, while storing the original pixel values.
  359.      Parameter     Type     Description
  360.       line         int      the line coordinate to put the cursor at
  361.       sample       int      the sample coordinate to put the cursor at
  362.       cursDN       int      the DN value of the cursor
  363. ***/
  364.  
  365. MoveCursor (p_line, p_sample)
  366. /***  MoveCursor performs the cursor mode operation.
  367.     The user moves the cursor around using the numeric keypad.
  368.     The cursor moves in discrete steps whose size can be changed.
  369.     The final cursor position is returned.
  370.  
  371.      Parameter     Type      Description
  372.       p_line     int ptr     the cursor line coordinate
  373.       p_sample   int ptr     the cursor sample coordinate
  374. ***/
  375.  
  376. --------------------------------------------------------------------------
  377.  
  378. /***  Module: IMAGUTIL
  379.       Special Purpose Device Independant Display Routines
  380.  
  381.     Contains high level display routines such as interactive palette
  382.     adjustment, histogram display, and image profile drawing.
  383.  
  384. ***/
  385.  
  386. DiddlePalette (numdiddle)
  387. /***  DiddlePalette performs interactive adjustment of the color
  388.     palette.  A wedge of numdiddle DN values, from 0 to the maximum,
  389.     is displayed at the bottom of the screen, and the palette is
  390.     changed to have only numdiddle distinct shades.  Then a loop
  391.     for user input is entered.  The active color is the one in the
  392.     wedge with the small black box inside it.
  393.  
  394.     The following is a list of commands:
  395.        Character      Action
  396.          4 (6)      move to next lower (higher) color in wedge
  397.          r (R)      decrease (increase) amount of red one notch
  398.          g (G)      decrease (increase) amount of green one notch
  399.          b (B)      decrease (increase) amount of blue one notch
  400.          2 (8)      decrease (increase) amount of all colors one notch
  401.          .          exit from palette diddle mode
  402.  
  403.     The wedge is erased after the user exits.
  404.  
  405.     Parameter   Type   Description
  406.      numdiddle   int   number of colors in the wedge and resulting palette
  407. ***/
  408.  
  409. DisplayHistogram (histbuf, numbins, minDN, maxDN)
  410. /***  DisplayHistogram diplays the passed histogram on the screen.
  411.     The third highest bin in the histogram is used to scale the
  412.     plot.  The axes of the plot are labeled and annotated.  The
  413.     number in each bin is indicated by the length of the line
  414.     drawn vertically from the axis.
  415.  
  416.      Parameter  Type            Description
  417.       histbuf   long int array  the array of count values for each bin
  418.       numbins   int             the number of bins in the histogram
  419.       minDN     int             the minimum DN value in the histogram
  420.       maxDN     int             the maximum DN value in the histogram
  421. ***/
  422.  
  423. Stretch (DNlow, DNhigh)
  424. /***  Stretch applies a linear gray scale ramp to the palette
  425.     starting with 0 at Dnlow and proceeding to 255 at DNhigh.
  426.  
  427.      Parameter  Type   Description
  428.       DNlow     int    the starting DN value of the linear ramp
  429.       DNhigh    int    the ending DN value of the linear ramp
  430. ***/
  431.  
  432. Profile()
  433. /***  Profile plots a profile of the pixel values between two points
  434.     on the screen.  Cursor mode is used to select the two endpoints.
  435.     A line is drawn between the endpoints and a plot of DN value
  436.     versus distance along the line is made.
  437. ***/
  438.  
  439. --------------------------------------------------------------------------
  440.  
  441. /***  Module:  IMAGEIO
  442.      Image I/O routines for labeled images
  443.  
  444.      Includes routines for opening images, reading and writing
  445.      image lines, and converting pixel formats.
  446.  
  447. ***/
  448.  
  449. OpenImage (filename, unit, IOmode, p_nline, p_nsamp, p_bitsperpix, status)
  450. /***  OpenImage opens an image file either for reading or writing.
  451.       The size of the image and pixel format are returned if the file
  452.       is opened for reading.  If the file is opened for writing
  453.       then the passed number of lines and samples and pixel format are
  454.       used for the new image.  The unit number is used to refer to the
  455.       file in subsequent operations.  If the file is opened for input
  456.       then the label processing routines will parse Vicar2 and PDS
  457.       labels and will prompt for user info if the image is unlabeled.
  458.       PDS detached labels are handled transparently in this routine.
  459.       If the file is for writing then a PDS label will be output.
  460.       An error is returned if there is insufficient room to dynamically
  461.       allocate the image buffer, or if there is a file error.
  462.       For images with pixel sizes less than a byte, each line is assumed
  463.       to start with a new byte.
  464.  
  465.    Parameter    Type    In/out  Description
  466.  
  467.     filename  char ptr   in     Name of image file to open
  468.     unit        int      in     Unit number of image (0,1,2...)
  469.     IOmode    char ptr   in     Access mode of file
  470.                                   ("r..." for reading, "w..." for writing)
  471.     p_nline   int ptr  in/out   The number of lines in the image
  472.     p_nsamp   int ptr  in/out   The number of samples in the image
  473.  p_bitsperpix int ptr  in/out   The number of bits in a pixel (pixel format)
  474.                                   (16 for integer, 8 for byte,
  475.                                     4 for nibble,  1 for binary)
  476.     status    char ptr  out     Return string with error message
  477.                                   (0 length string if no error)
  478. ***/
  479.  
  480. ReadLine (unit, buffer, line, ss, ns, status)
  481. /***  ReadLine reads a line of pixels from the image into the user's
  482.     buffer.  The reading is completely random access, the lines may
  483.     be read in any order; it is more efficient, however, to read lines
  484.     sequentially.  Partial image lines may be read.  The output data
  485.     is in the same format as the file (the convert routine may be
  486.     used to convert pixel formats).
  487.  
  488.    Parameter Type   In/out  Description
  489.  
  490.     unit     int      in     Unit number of image (same as in open)
  491.     buffer  char ptr  out    Buffer to receive pixels
  492.     line     int      in     The number of the image line to read (1 is first)
  493.     ss       int      in     The starting sample in the line
  494.     ns       int      in     The number of samples to read into buffer
  495.     status  char ptr  out    Return string with error message
  496.                                   (0 length string if no error)
  497. ***/
  498.  
  499. WriteLine (unit, buffer, line, ss, ns, status)
  500. /***  WriteLine writes a line of pixels from the user buffer to the image.
  501.     Although the writing is buffered, completely random access will not
  502.     work; the image lines should be written sequentially.
  503.     Partial image lines may be written.  The input data must be in the
  504.     same format as the file (no conversion is performed).
  505.  
  506.    Parameter Type   In/out  Description
  507.  
  508.     unit     int      in     Unit number of image (same as in open)
  509.     buffer  char ptr  in     Buffer of image pixels
  510.     line     int      in     The number of the image line to write
  511.     ss       int      in     The starting sample in the line
  512.     ns       int      in     The number of samples to write from buffer
  513.     status  char ptr  out    Return string with error message
  514.                                   (0 length string if no error)
  515. ***/
  516.  
  517. CloseImage (unit, status)
  518. /***  CloseImage closes the image file.  If the image is opened for
  519.     writing then the image buffer is first flushed.
  520.  
  521.    Parameter Type   In/out  Description
  522.  
  523.     unit     int      in     Unit number of image (same as in open)
  524.     status  char ptr  out    Return string with error message
  525.                                   (0 length string if no error)
  526. ***/
  527.  
  528. CheckStatus (status)
  529. /***  CheckStatus checks the status string passed in.  If there
  530.     is no error the routine returns, otherwise the error message
  531.     is printed to the terminal and the program is aborted.
  532.  
  533. ***/
  534.  
  535. ConvertLine (inbuffer, outbuffer, inbits, outbits, ns, status)
  536. /***  ConvertLine converts a line of pixels into a different format.
  537.  
  538.    Parameter     Type   In/out  Description
  539.  
  540.     inbuffer   char ptr  in    The input buffer of pixels
  541.     outbuffer  char ptr  out   The output buffer of pixels
  542.     inbits      int      in    The pixel format of the input buffer
  543.     outbits     int      in    The pixel format of the output buffer
  544.     ns          int      in    The number of samples to convert
  545.     status     char ptr  out   Return string with error message
  546.  
  547.  
  548.    Conversions supported :        outbits
  549.                                 1  4  8  16
  550.                    inbits    1  .  -  .  .      . means supported
  551.                              4  -  .  .  .
  552.                              8  .  .  .  .
  553.                             16  .  .  .  .
  554. ***/
  555.  
  556. --------------------------------------------------------------------------
  557.  
  558. /***  Module: LABUTIL
  559.      Label Processing Routines
  560. ***/
  561.  
  562.  
  563. GetLabelInteger (LabelBuf, LabelBufLen, Keyword, defaul, p_value, p_flag)
  564. /***  GetLabelInteger returns the integer value following the keyword in the
  565.     label buffer.  If the keyword is not there then the default value
  566.     is returned.  The flag indicates whether the keyword is there.
  567.  
  568.    Parameter    Type    In/out   Description
  569.     LabelBuf  char ptr   in      The buffer containing the label
  570.     LabelBufLen  int     in      The length in bytes of the label buffer
  571.     Keyword   char ptr   in      The keyword string to match
  572.     defaul       int     in      The value to return if no keyword or value
  573.     p_value    int ptr   out     The returned value
  574.     p_flag     int ptr   out     The flag: -1 if no keyword match
  575.                                    0 if illegal value, 1 if keyword and value
  576. ***/
  577.  
  578.  
  579.  
  580. GetLabelReal (LabelBuf, LabelBufLen, Keyword, defaul, p_value, p_flag)
  581. /***  GetLabelReal returns the real value following the keyword in the
  582.     label buffer.  If the keyword is not there then the default value
  583.     is returned.  The flag indicates whether the keyword is there.
  584.  
  585.    Parameter    Type    In/out   Description
  586.     LabelBuf  char ptr   in      The buffer containing the label
  587.     LabelBufLen  int     in      The length in bytes of the label buffer
  588.     Keyword   char ptr   in      The keyword string to match
  589.     defaul      float    in      The value to return if no keyword or value
  590.     p_value   float ptr  out     The returned value
  591.     p_flag     int ptr   out     The flag: -1 if no keyword match
  592.                                    0 if illegal value, 1 if keyword and value
  593. ***/
  594.  
  595.  
  596.  
  597. GetLabelString (LabelBuf, LabelBufLen, Keyword, defaul, value, p_flag)
  598. /***  GetLabelString returns the string value following the keyword in the
  599.     label buffer.  If the keyword is not there then the default value
  600.     is returned.  The flag indicates whether the keyword is there.
  601.  
  602.    Parameter    Type    In/out   Description
  603.     LabelBuf  char ptr   in      The buffer containing the label
  604.     LabelBufLen  int     in      The length in bytes of the label buffer
  605.     Keyword   char ptr   in      The keyword string to match
  606.     defaul    char ptr   in      The value to return if no keyword or value
  607.     p_value   char ptr   out     The returned value
  608.     p_flag     int ptr   out     The flag: -1 if no keyword match
  609.                                    0 if illegal value, 1 if keyword and value
  610. ***/
  611.  
  612. InterpretLabel (buf, len, p_labelsize, p_nline, p_nsamp,
  613.                      p_bitsperpix, p_reclen, p_lineheadbytes,
  614.                        DetachedFileName)
  615. /***  InterpretLabel interprets the label in the buffer to extract
  616.     the image information.  First something is identified to determine
  617.     whether the image has a PDS label or a Vicar2 label or no label.
  618.     If the image is labeled then the appropriate keyword values are
  619.     extracted, otherwise the user is prompted for the into.
  620.  
  621.    Parameter    Type   In/out  Description
  622.     buf        char ptr  in    The label buffer
  623.     len          int     in    The length in bytes of the label buffer
  624.   p_labelsize   int ptr  out   The size of the label or header to skip
  625.   p_nline       int ptr  out   The number of lines in the image
  626.   p_nsamp       int ptr  out   The number of samples in the image
  627.   p_bitsperpix  int ptr  out   The pixel format (16,8,4,1)
  628.   p_reclen      int ptr  out   The record length in bytes
  629. p_lineheadbytes int ptr  out   The header bytes at beginning of each line
  630. DetachedFileName char ptr out  The name of the file of data
  631.                                    null string if no detached label
  632. ***/
  633.  
  634. MakeLabel (Buf, p_labelsize, nline, nsamp, bitsperpix, reclen)
  635. /***  MakeLabel creates a PDS label in the buffer, having the appropriate
  636.     image parameters.
  637.  
  638.    Parameter    Type   In/out  Description
  639.     Buf        char ptr  out   The label buffer
  640.   p_labelsize  int ptr   out   The size of the label
  641.     nline       int      out   The number of lines in the image
  642.     nsamp       int      out   The number of samples in the image
  643.     bitsperpix  int      out   The pixel format (16,8,4,1)
  644.     reclen      int      out   The record length in bytes
  645.  
  646. ***/
  647.  
  648. int GetCommand (CommandString, CommandList)
  649. /***  GetCommand is an integer function that returns the number of
  650.     the command that is in the beginning of the CommandString parameter.
  651.     The command is assigned a number according to the list of
  652.     commands in the CommandList string parameter.  The list of commands
  653.     should be in uppercase and have spaces between the commmand.
  654.  
  655. ***/
  656.  
  657. GetKeywordInteger (CommandString, Keyword, defaul, p_value, p_flag)
  658. /***  GetKeywordInteger scans the CommandString for the Keyword
  659.     and returns the value of the following integer.
  660.  
  661.    Parameter       Type      In/out   Description
  662.     CommandString  char ptr    in      The command string to scan thru
  663.     Keyword        char ptr    in      The keyword string to match
  664.     defaul          int        in      The default value to return if
  665.                                            no keyword or illegal value
  666.     p_value        int ptr     out     The returned value
  667.     p_flag         int ptr     out     The flag:  -1 for no keyword match
  668.                                            0 for keyword with no/bad value
  669.                                            1 for keyword and good value
  670. ***/
  671.  
  672. GetKeywordReal (CommandString, Keyword, defaul, p_value, p_flag)
  673. /***  GetKeywordReal scans the CommandString for the Keyword
  674.     and returns the value of the following real.
  675.  
  676.    Parameter       Type      In/out   Description
  677.     CommandString  char ptr    in      The command string to scan thru
  678.     Keyword        char ptr    in      The keyword string to match
  679.     defaul          float      in      The default value to return if
  680.                                            no keyword or illegal value
  681.     p_value        float ptr   out     The returned value
  682.     p_flag         int ptr     out     The flag:  -1 for no keyword match
  683.                                            0 for keyword with no/bad value
  684.                                            1 for keyword and good value
  685. ***/
  686.  
  687. GetKeywordString (CommandString, Keyword, defaul, value, p_flag)
  688. /***  GetKeywordString scans the CommandString for the Keyword
  689.     and returns the value of the following string.
  690.  
  691.    Parameter       Type      In/out   Description
  692.     CommandString  char ptr    in      The command string to scan thru
  693.     Keyword        char ptr    in      The keyword string to match
  694.     defaul         char ptr    in      The default value to return if
  695.                                            no keyword or illegal value
  696.     p_value        char ptr    out     The returned value
  697.     p_flag         int ptr     out     The flag:  -1 for no keyword match
  698.                                            0 for keyword with no/bad value
  699.                                            1 for keyword and good value
  700. ***/
  701.  
  702. --------------------------------------------------------------------------
  703.  
  704. /***  Module:  FILEIO
  705.      Contains block level I/O routines for MS-DOS files.
  706.  
  707. ***/
  708.  
  709. OpenFile (filename, unit, IOmode, p_blocksize, status)
  710. /***  OpenFile opens a file with the given file name.
  711.     The file may be open for reading or writing.
  712.     If the file name begins with "CD:" then it is assumed to be an
  713.     absolute CD-ROM file on a non-standard CD-ROM.  The file name is
  714.     of the form "CD:mm:ss:bb", where mm is the minute of the starting
  715.     sector, ss is the second, and bb is the block number within the second.
  716.     The logical blocksize to be used in the image I/O routines
  717.     is returned.
  718.  
  719.    Parameter    Type    In/out   Description
  720.     filename   char ptr  in      File name string
  721.     unit        int      in      Unit number (0,1,2...)
  722.     IOmode     char ptr  in      "r..." for reading, 'w...' for writing
  723.    p_blocksize  int ptr  out     The returned logical blocksize to use
  724.     status     char ptr  out     The error message string
  725.                                      (0 length for no error)
  726. ***/
  727.  
  728. ReadBlocks (unit, buffer, startblock, numblocks, p_blocksread, status)
  729. /***  ReadBlocks reads blocks from the file into the buffer.
  730.  
  731.    Parameter    Type    In/out   Description
  732.     unit        int      in      Unit number from open
  733.     buffer     char ptr  out     The output buffer of data
  734.     startblock long int  in      The starting logical block
  735.     numblocks   int      in      The number of blocks to read
  736.  p_blocksread  int ptr   out     The number of blocks actually read
  737.     status     char ptr  out     The error message string
  738.                                      (0 length for no error)
  739. ***/
  740.  
  741. WriteBlocks (unit, buffer, startblock, numblocks, status)
  742. /***  WriteBlocks writes blocks from the buffer to the file.
  743.  
  744.    Parameter    Type    In/out   Description
  745.     unit        int      in      Unit number from open
  746.     buffer     char ptr  in      The input buffer of data
  747.     startblock long int  in      The starting logical block
  748.     numblocks   int      in      The number of blocks to write
  749.     status     char ptr  out     The error message string
  750.                                      (0 length for no error)
  751. ***/
  752.  
  753. CloseFile (unit, status)
  754. /*** CloseFile closes the file.
  755.  
  756.    Parameter    Type    In/out   Description
  757.     unit        int      in      Unit number from open
  758.     status     char ptr  out     The error message string
  759.                                      (0 length for no error)
  760. ***/
  761.  
  762. --------------------------------------------------------------------------
  763.  
  764. InitializeCD (p_PB_size, status)
  765. /***  InitializeCD initializes the CD player and returns the
  766.     physical block size.
  767.  
  768.     Parameter   Type      Description
  769.     p_PB_size   int ptr   The size of the physical blocks for this driver.
  770.                           (in this case 2048 bytes)
  771.     status      char ptr  Error message string (0 length if no error)
  772.  
  773. ***/
  774.  
  775. ReadBlocksCD (buffer, StartPB, NumPB, status)
  776. /***  ReadBlocksCD reads blocks from the CD-ROM to the user's buffer.
  777.  
  778.    Parameter    Type      Description
  779.     buffer     char ptr   Buffer to receive data
  780.     StartPB    long int   The starting absolute physical block
  781.     NumPB      int        The number of physical blocks to read
  782.     status     char ptr   Error message string (0 length if no error)
  783.  
  784. ***/
  785. --------------------------------------------------------------------------
  786.  
  787.     Low Level Block I/O with MS-DOS for non-standard CD-ROM's
  788.  
  789. InitializeCD (p_PB_size, status)
  790. /***  InitializeCD initializes the CD player and returns the
  791.     physical block size.
  792.  
  793.     Parameter   Type      Description
  794.     p_PB_size   int ptr   The size of the physical blocks for this driver.
  795.                           (in this case 2048 bytes)
  796.     status      char ptr  Error message string (0 length if no error)
  797.  
  798. ***/
  799.  
  800. ReadBlocksCD (buffer, StartPB, NumPB, status)
  801. /***  ReadBlocksCD reads blocks from the CD-ROM to the user's buffer.
  802.  
  803.    Parameter    Type      Description
  804.     buffer     char ptr   Buffer to receive data
  805.     StartPB    long int   The starting absolute physical block
  806.     NumPB      int        The number of physical blocks to read
  807.     status     char ptr   Error message string (0 length if no error)
  808.  
  809. ***/
  810. --------------------------------------------------------------------
  811.  
  812. /***  Module:  FILEUTIL
  813.      Contains file selection and wildcard expansion routines.
  814. ***/
  815.  
  816. int FileSel(selFilename)
  817. /*** filesel -- allow user to browse directories and select image 
  818.                 files for display.  Returns selected file name.
  819.    Parameter    Type       Description 
  820.     selFilename char ptr   filename selected for processing.
  821. ***/
  822.  
  823. wildexp(oargcp, oargvp)
  824. /*** wildexp -- expand wildcard file name.  Returns array of pointers
  825.                 to filenames meeting wildcard specifications.
  826.    Parameter    Type       Description 
  827.     oargcp    int ptr      pointer to number of values in oargvp
  828.     oargvp char ptr ptr ptr pointers to text strings containing
  829.                            file names meeting wild card specification.
  830. ***/
  831.  
  832.                      Memory Allocation Procedures
  833.  
  834.              Willard Gersbacher  - CompuServe User ID: (76117,2611)
  835.  
  836. The procedures included in this archive provide functionally equivalent
  837. memory allocation procedures for the main memory procedures used in C.
  838. These procedures were written primarily because of a need to minimize
  839. memory usage for a large program under development.  The MSC 5.1 library
  840. procedures were not satisfactory for this application because they did
  841. not release memory back to the system when it was 'free'ed.
  842. Additionally, they tended to allocate too much memory under certain
  843. circumstances which lead to a reduction in space available for other
  844. programs and data which were currently active at the time.
  845.  
  846. These procedures should only be used with large data model programs
  847. (i.e., compact, large, and huge memory models).  No provision has been
  848. made for small or medium model programs.
  849.  
  850. /* The following routines from the ALLOC.ARC distribution file 
  851.    have all been incorporated in MEMUTIL.C */
  852.  
  853.    free.c       -  Functional equivalent to free.  Included in this
  854.                    file is an additional procedure _ffree which calls
  855.                    free.
  856.  
  857.    malloc.c     -  Functional equivalent of malloc.  This file also 
  858.                    contains the memory structures which are used to
  859.                    keep track of the blocks of memory allocated.  In
  860.                    addition, the procedure _fmalloc is defined which
  861.                    just makes a call to malloc.
  862.  
  863.    memutil.c    -  This file contains a set of procedures which are
  864.                    used by the main memory allocation procedures to
  865.                    maintain the memory structure used to keep track of
  866.                    the user allocations and frees.
  867.  
  868.    reduceal.c   -  This procedure may be called to reduce the memory
  869.                    allocated to a program.  It attempts to release back
  870.                    to DOS the memory not currently being used.
  871.  
  872.    reducedd.c   -  This procedure may be called to reduce the default
  873.                    data segment to the minimum size required.  Normally
  874.                    this should be called before any calls to memory
  875.                    allocation procedures.  Included in this file are
  876.                    dummy procedures for _nmalloc and _nfree.  These
  877.                    latter procedures were included because some
  878.                    of the MSC library uses the near heap for memory
  879.                    allocation (even though you may be using large
  880.                    data model programs).  Since this procedure does
  881.                    away with any space which might be used for near
  882.                    heap allocation, this forces the procedures which
  883.                    call them to use the 'far' heap.
  884.