home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / fontutils-0.6 / imageto / input-pbm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-14  |  1.8 KB  |  89 lines

  1. /* input-pbm.c: read PBM files.
  2.  
  3. Copyright (C) 1990, 1991, 19 19ANY WARRANTY; without even the implied warranty of
  4. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  5. GNU General Public License for more details.
  6.  
  7. You should have received a copy of the GNU General Public License
  8. along with this program; if not, write to the Free Software
  9. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  10.  
  11. #include "config.h"
  12.  
  13. #include "file-input.h"
  14.  
  15. #include "main.h"
  16. #include "image-header.h"
  17. #include "input-pbm.h"
  18.  
  19. #include "pbmplus.h"
  20. #include "pbm.h"
  21.  
  22.  
  23. /* Where the input comes from.  */
  24. static FILE *pbm_input_file;
  25. static string pbm_input_filename;
  26.  
  27.  
  28.  
  29. /* Only one file can be open at a time.  We do no path searching.  If
  30.    FILENAME can't be opened, we quit.  */
  31.  
  32. void
  33. pbm_open_input_file (string filename)
  34. {
  35.   assert (pbm_input_file == NULL);
  36.   
  37.   pbm_input_file = xfopen (filename, "r");
  38.   pbm_input_filename = filename;
  39. }
  40.  
  41.  
  42. /* Close the input file.  If it hasn't been opened, we quit.  */
  43.  
  44. void
  45. pbm_close_input_file ()
  46. {
  47.   assert (pbm_input_file != NULL);
  48.   
  49.   xfclose (pbm_input_file, pbm_input_filename);
  50.   pbm_input_file = NULL;
  51. }
  52.  
  53.  
  54.  
  55. /* Read the header information.
  56.    Modifies the global image_header in main.c.  */
  57.  
  58. void
  59. pbm_get_header ()
  60. {
  61.   int width, height, format;
  62.  
  63.   pbm_readpbminit (pbm_input_file, &width, &height, &format);
  64.   image_header.width = (two_bytes) width;
  65.   image_header.height = (two_bytes) height;
  66.   image_header.depth = 0;
  67.   image_header.format = (two_bytes) format;
  68. }
  69.  
  70.  
  71.  
  72. /* Read one scanline of the image.  */
  73.  
  74. boolean
  75. pbm_get_scanline (one_byte *line_in_bits)
  76. {
  77.   int c = getc (pbm_input_file);
  78.   
  79.   if (c == EOF)
  80.     return false;
  81.     
  82.   ungetc (c, pbm_input_file);
  83.   pbm_readpbmrow (pbm_input_file, line_in_bits, image_header.width, 
  84.           image_header.format);
  85.  
  86.   print_scanline (line_in_bits, image_header.width);
  87.   return true;
  88. }
  89.