home *** CD-ROM | disk | FTP | other *** search
/ GRIPS 2: Government Rast…rocessing Software & Data / GRIPS_2.cdr / dos / imdisp / source / refresh.c < prev    next >
C/C++ Source or Header  |  1990-12-31  |  3KB  |  115 lines

  1. /*************************************************************/
  2. /*  Copyright (C) 1989, California Institute of Technology   */
  3. /*  U. S. Government Sponsorship under NASA Contract         */
  4. /*  NAS7-918 is acknowledged.                                */
  5. /*************************************************************/
  6.  
  7. /***  IMDISP module REFRESH.C
  8.  
  9.         REFRESH contains all the routines for manipulating the refresh
  10.     buffer, which holds a copy of the last image displayed.  Created as
  11.     a separate module by A. Warnock, ST Systems Corp., NASA/GSFC, 5/90.
  12.  
  13. ***/
  14.  
  15. /* * * * INCLUDE files * * * */
  16.  
  17. #include <process.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include "imdef.h"
  21. #include "dispio.h"
  22.  
  23. /* * * * External functions * * * */
  24.  
  25. /* * * * Function declarations * * * */
  26.  
  27. int FreeRefresh (char *);
  28. int PutRefresh (unsigned char *, int, int, int);
  29. int GetRefresh (unsigned char *, int, int, int);
  30. int AllocRefresh (void);
  31.  
  32. /* * * * Global Variables * * * */
  33.  
  34. int           RefreshLines;
  35. unsigned int  segment;
  36. unsigned char *RefreshBuf[MAXDISPNL];
  37.  
  38.  
  39. int FreeRefresh(char * caller)
  40. /***  FreeRefresh releases one line of the refresh buffer back to DOS,
  41.       as long as there are allocated lines in the buffer.
  42. ***/
  43. {
  44.     if (RefreshLines > 0)
  45.     {
  46.        RefreshLines--;
  47.        free( RefreshBuf[RefreshLines] );
  48.     }
  49.  
  50.     if (RefreshLines == 0)
  51.     {
  52.        DisplayOff();
  53.        printf("Not enough memory in %s.",caller);
  54.        exit(1);
  55.     }
  56. }
  57.  
  58. int PutRefresh (unsigned char * buffer, int line, int ss, int ns)
  59.  
  60. /***  PutRefresh stores a line of pixels in the refresh buffer.
  61.       Parameter   type       description
  62.         buffer   char ptr    The array of pixel values
  63.         line     integer     The line coordinate of the first pixel
  64.         sample   integer     The sample coordinate of the first pixel
  65.         ns       integer     The number of pixels to store
  66. ***/
  67.  
  68. {
  69.     unsigned char *p;
  70.  
  71.     if (line <= RefreshLines)
  72.     {
  73.         p = &RefreshBuf[line-1][ss-1];
  74.         memcpy (p, buffer, ns);
  75.     }
  76.  
  77. }
  78.  
  79. int GetRefresh (unsigned char * buffer, int line, int ss, int ns)
  80.  
  81. /***  GetRefresh reads a line of pixels from the refresh buffer.
  82.       Parameter   type       description
  83.         buffer   char ptr    The receiving array of pixel values
  84.         line     integer     The line coordinate of the first pixel
  85.         sample   integer     The sample coordinate of the first pixel
  86.         ns       integer     The number of pixels to read
  87. ***/
  88.  
  89. {
  90.     unsigned char *p;
  91.  
  92.     if (line <= RefreshLines)
  93.     {
  94.         p = &RefreshBuf[line-1][ss-1];
  95.         memcpy (buffer, p, ns);
  96.     }
  97.     else
  98.         memset (buffer, 0, ns);
  99. }
  100. int AllocRefresh(void)
  101. {
  102.     int i;
  103.  
  104.     i = 0;
  105.  
  106.     while ( ((RefreshBuf[i] = (unsigned char *) calloc( dispns, sizeof(char)) ) != NULL)
  107.           && (i < dispnl) )  i++;
  108.     if (i == dispnl)
  109.        RefreshLines = i + 1;
  110.     else
  111.        RefreshLines = i;
  112.  
  113.     return(RefreshLines);
  114. }
  115.